summaryrefslogtreecommitdiff
path: root/target/linux/ubicom32/patches-2.6.28/100-ubicom32_support.patch
blob: 2eceb7ccd49f207ce1a26c9e28270f8b18d06ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
39864
39865
39866
39867
39868
39869
39870
39871
39872
39873
39874
39875
39876
39877
39878
39879
39880
39881
39882
39883
39884
39885
39886
39887
39888
39889
39890
39891
39892
39893
39894
39895
39896
39897
39898
39899
39900
39901
39902
39903
39904
39905
39906
39907
39908
39909
39910
39911
39912
39913
39914
39915
39916
39917
39918
39919
39920
39921
39922
39923
39924
39925
39926
39927
39928
39929
39930
39931
39932
39933
39934
39935
39936
39937
39938
39939
39940
39941
39942
39943
39944
39945
39946
39947
39948
39949
39950
39951
39952
39953
39954
39955
39956
39957
39958
39959
39960
39961
39962
39963
39964
39965
39966
39967
39968
39969
39970
39971
39972
39973
39974
39975
39976
39977
39978
39979
39980
39981
39982
39983
39984
39985
39986
39987
39988
39989
39990
39991
39992
39993
39994
39995
39996
39997
39998
39999
40000
40001
40002
40003
40004
40005
40006
40007
40008
40009
40010
40011
40012
40013
40014
40015
40016
40017
40018
40019
40020
40021
40022
40023
40024
40025
40026
40027
40028
40029
40030
40031
40032
40033
40034
40035
40036
40037
40038
40039
40040
40041
40042
40043
40044
40045
40046
40047
40048
40049
40050
40051
40052
40053
40054
40055
40056
40057
40058
40059
40060
40061
40062
40063
40064
40065
40066
40067
40068
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093
40094
40095
40096
40097
40098
40099
40100
40101
40102
40103
40104
40105
40106
40107
40108
40109
40110
40111
40112
40113
40114
40115
40116
40117
40118
40119
40120
40121
40122
40123
40124
40125
40126
40127
40128
40129
40130
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150
40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165
40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178
40179
40180
40181
40182
40183
40184
40185
40186
40187
40188
40189
40190
40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220
40221
40222
40223
40224
40225
40226
40227
40228
40229
40230
40231
40232
40233
40234
40235
40236
40237
40238
40239
40240
40241
40242
40243
40244
40245
40246
40247
40248
40249
40250
40251
40252
40253
40254
40255
40256
40257
40258
40259
40260
40261
40262
40263
40264
40265
40266
40267
40268
40269
40270
40271
40272
40273
40274
40275
40276
40277
40278
40279
40280
40281
40282
40283
40284
40285
40286
40287
40288
40289
40290
40291
40292
40293
40294
40295
40296
40297
40298
40299
40300
40301
40302
40303
40304
40305
40306
40307
40308
40309
40310
40311
40312
40313
40314
40315
40316
40317
40318
40319
40320
40321
40322
40323
40324
40325
40326
40327
40328
40329
40330
40331
40332
40333
40334
40335
40336
40337
40338
40339
40340
40341
40342
40343
40344
40345
40346
40347
40348
40349
40350
40351
40352
40353
40354
40355
40356
40357
40358
40359
40360
40361
40362
40363
40364
40365
40366
40367
40368
40369
40370
40371
40372
40373
40374
40375
40376
40377
40378
40379
40380
40381
40382
40383
40384
40385
40386
40387
40388
40389
40390
40391
40392
40393
40394
40395
40396
40397
40398
40399
40400
40401
40402
40403
40404
40405
40406
40407
40408
40409
40410
40411
40412
40413
40414
40415
40416
40417
40418
40419
40420
40421
40422
40423
40424
40425
40426
40427
40428
40429
40430
40431
40432
40433
40434
40435
40436
40437
40438
40439
40440
40441
40442
40443
40444
40445
40446
40447
40448
40449
40450
40451
40452
40453
40454
40455
40456
40457
40458
40459
40460
40461
40462
40463
40464
40465
40466
40467
40468
40469
40470
40471
40472
40473
40474
40475
40476
40477
40478
40479
40480
40481
40482
40483
40484
40485
40486
40487
40488
40489
40490
40491
40492
40493
40494
40495
40496
40497
40498
40499
40500
40501
40502
40503
40504
40505
40506
40507
40508
40509
40510
40511
40512
40513
40514
40515
40516
40517
40518
40519
40520
40521
40522
40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542
40543
40544
40545
40546
40547
40548
40549
40550
40551
40552
40553
40554
40555
40556
40557
40558
40559
40560
40561
40562
40563
40564
40565
40566
40567
40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40634
40635
40636
40637
40638
40639
40640
40641
40642
40643
40644
40645
40646
40647
40648
40649
40650
40651
40652
40653
40654
40655
40656
40657
40658
40659
40660
40661
40662
40663
40664
40665
40666
40667
40668
40669
40670
40671
40672
40673
40674
40675
40676
40677
40678
40679
40680
40681
40682
40683
40684
40685
40686
40687
40688
40689
40690
40691
40692
40693
40694
40695
40696
40697
40698
40699
40700
40701
40702
40703
40704
40705
40706
40707
40708
40709
40710
40711
40712
40713
40714
40715
40716
40717
40718
40719
40720
40721
40722
40723
40724
40725
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740
40741
40742
40743
40744
40745
40746
40747
40748
40749
40750
40751
40752
40753
40754
40755
40756
40757
40758
40759
40760
40761
40762
40763
40764
40765
40766
40767
40768
40769
40770
40771
40772
40773
40774
40775
40776
40777
40778
40779
40780
40781
40782
40783
40784
40785
40786
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801
40802
40803
40804
40805
40806
40807
40808
40809
40810
40811
40812
40813
40814
40815
40816
40817
40818
40819
40820
40821
40822
40823
40824
40825
40826
40827
40828
40829
40830
40831
40832
40833
40834
40835
40836
40837
40838
40839
40840
40841
40842
40843
40844
40845
40846
40847
40848
40849
40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866
40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878
40879
40880
40881
40882
40883
40884
40885
40886
40887
40888
40889
40890
40891
40892
40893
40894
40895
40896
40897
40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
40950
40951
40952
40953
40954
40955
40956
40957
40958
40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
40973
40974
40975
40976
40977
40978
40979
40980
40981
40982
40983
40984
40985
40986
40987
40988
40989
40990
40991
40992
40993
40994
40995
40996
40997
40998
40999
41000
41001
41002
41003
41004
41005
41006
41007
41008
41009
41010
41011
41012
41013
41014
41015
41016
41017
41018
41019
41020
41021
41022
41023
41024
41025
41026
41027
41028
41029
41030
41031
41032
41033
41034
41035
41036
41037
41038
41039
41040
41041
41042
41043
41044
41045
41046
41047
41048
41049
41050
41051
41052
41053
41054
41055
41056
41057
41058
41059
41060
41061
41062
41063
41064
41065
41066
41067
41068
41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080
41081
41082
41083
41084
41085
41086
41087
41088
41089
41090
41091
41092
41093
41094
41095
41096
41097
41098
41099
41100
41101
41102
41103
41104
41105
41106
41107
41108
41109
41110
41111
41112
41113
41114
41115
41116
41117
41118
41119
41120
41121
41122
41123
41124
41125
41126
41127
41128
41129
41130
41131
41132
41133
41134
41135
41136
41137
41138
41139
41140
41141
41142
41143
41144
41145
41146
41147
41148
41149
41150
41151
41152
41153
41154
41155
41156
41157
41158
41159
41160
41161
41162
41163
41164
41165
41166
41167
41168
41169
41170
41171
41172
41173
41174
41175
41176
41177
41178
41179
41180
41181
41182
41183
41184
41185
41186
41187
41188
41189
41190
41191
41192
41193
41194
41195
41196
41197
41198
41199
41200
41201
41202
41203
41204
41205
41206
41207
41208
41209
41210
41211
41212
41213
41214
41215
41216
41217
41218
41219
41220
41221
41222
41223
41224
41225
41226
41227
41228
41229
41230
41231
41232
41233
41234
41235
41236
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254
41255
41256
41257
41258
41259
41260
41261
41262
41263
41264
41265
41266
41267
41268
41269
41270
41271
41272
41273
41274
41275
41276
41277
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302
41303
41304
41305
41306
41307
41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325
41326
41327
41328
41329
41330
41331
41332
41333
41334
41335
41336
41337
41338
41339
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352
41353
41354
41355
41356
41357
41358
41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375
41376
41377
41378
41379
41380
41381
41382
41383
41384
41385
41386
41387
41388
41389
41390
41391
41392
41393
41394
41395
41396
41397
41398
41399
41400
41401
41402
41403
41404
41405
41406
41407
41408
41409
41410
41411
41412
41413
41414
41415
41416
41417
41418
41419
41420
41421
41422
41423
41424
41425
41426
41427
41428
41429
41430
41431
41432
41433
41434
41435
41436
41437
41438
41439
41440
41441
41442
41443
41444
41445
41446
41447
41448
41449
41450
41451
41452
41453
41454
41455
41456
41457
41458
41459
41460
41461
41462
41463
41464
41465
41466
41467
41468
41469
41470
41471
41472
41473
41474
41475
41476
41477
41478
41479
41480
41481
41482
41483
41484
41485
41486
41487
41488
41489
41490
41491
41492
41493
41494
41495
41496
41497
41498
41499
41500
41501
41502
41503
41504
41505
41506
41507
41508
41509
41510
41511
41512
41513
41514
41515
41516
41517
41518
41519
41520
41521
41522
41523
41524
41525
41526
41527
41528
41529
41530
41531
41532
41533
41534
41535
41536
41537
41538
41539
41540
41541
41542
41543
41544
41545
41546
41547
41548
41549
41550
41551
41552
41553
41554
41555
41556
41557
41558
41559
41560
41561
41562
41563
41564
41565
41566
41567
41568
41569
41570
41571
41572
41573
41574
41575
41576
41577
41578
41579
41580
41581
41582
41583
41584
41585
41586
41587
41588
41589
41590
41591
41592
41593
41594
41595
41596
41597
41598
41599
41600
41601
41602
41603
41604
41605
41606
41607
41608
41609
41610
41611
41612
41613
41614
41615
41616
41617
41618
41619
41620
41621
41622
41623
41624
41625
41626
41627
41628
41629
41630
41631
41632
41633
41634
41635
41636
41637
41638
41639
41640
41641
41642
41643
41644
41645
41646
41647
41648
41649
41650
41651
41652
41653
41654
41655
41656
41657
41658
41659
41660
41661
41662
41663
41664
41665
41666
41667
41668
41669
41670
41671
41672
41673
41674
41675
41676
41677
41678
41679
41680
41681
41682
41683
41684
41685
41686
41687
41688
41689
41690
41691
41692
41693
41694
41695
41696
41697
41698
41699
41700
41701
41702
41703
41704
41705
41706
41707
41708
41709
41710
41711
41712
41713
41714
41715
41716
41717
41718
41719
41720
41721
41722
41723
41724
41725
41726
41727
41728
41729
41730
41731
41732
41733
41734
41735
41736
41737
41738
41739
41740
41741
41742
41743
41744
41745
41746
41747
41748
41749
41750
41751
41752
41753
41754
41755
41756
41757
41758
41759
41760
41761
41762
41763
41764
41765
41766
41767
41768
41769
41770
41771
41772
41773
41774
41775
41776
41777
41778
41779
41780
41781
41782
41783
41784
41785
41786
41787
41788
41789
41790
41791
41792
41793
41794
41795
41796
41797
41798
41799
41800
41801
41802
41803
41804
41805
41806
41807
41808
41809
41810
41811
41812
41813
41814
41815
41816
41817
41818
41819
41820
41821
41822
41823
41824
41825
41826
41827
41828
41829
41830
41831
41832
41833
41834
41835
41836
41837
41838
41839
41840
41841
41842
41843
41844
41845
41846
41847
41848
41849
41850
41851
41852
41853
41854
41855
41856
41857
41858
41859
41860
41861
41862
41863
41864
41865
41866
41867
41868
41869
41870
41871
41872
41873
41874
41875
41876
41877
41878
41879
41880
41881
41882
41883
41884
41885
41886
41887
41888
41889
41890
41891
41892
41893
41894
41895
41896
41897
41898
41899
41900
41901
41902
41903
41904
41905
41906
41907
41908
41909
41910
41911
41912
41913
41914
41915
41916
41917
41918
41919
41920
41921
41922
41923
41924
41925
41926
41927
41928
41929
41930
41931
41932
41933
41934
41935
41936
41937
41938
41939
41940
41941
41942
41943
41944
41945
41946
41947
41948
41949
41950
41951
41952
41953
41954
41955
41956
41957
41958
41959
41960
41961
41962
41963
41964
41965
41966
41967
41968
41969
41970
41971
41972
41973
41974
41975
41976
41977
41978
41979
41980
41981
41982
41983
41984
41985
41986
41987
41988
41989
41990
41991
41992
41993
41994
41995
41996
41997
41998
41999
42000
42001
42002
42003
42004
42005
42006
42007
42008
42009
42010
42011
42012
42013
42014
42015
42016
42017
42018
42019
42020
42021
42022
42023
42024
42025
42026
42027
42028
42029
42030
42031
42032
42033
42034
42035
42036
42037
42038
42039
42040
42041
42042
42043
42044
42045
42046
42047
42048
42049
42050
42051
42052
42053
42054
42055
42056
42057
42058
42059
42060
42061
42062
42063
42064
42065
42066
42067
42068
42069
42070
42071
42072
42073
42074
42075
42076
42077
42078
42079
42080
42081
42082
42083
42084
42085
42086
42087
42088
42089
42090
42091
42092
42093
42094
42095
42096
42097
42098
42099
42100
42101
42102
42103
42104
42105
42106
42107
42108
42109
42110
42111
42112
42113
42114
42115
42116
42117
42118
42119
42120
42121
42122
42123
42124
42125
42126
42127
42128
42129
42130
42131
42132
42133
42134
42135
42136
42137
42138
42139
42140
42141
42142
42143
42144
42145
42146
42147
42148
42149
42150
42151
42152
42153
42154
42155
42156
42157
42158
42159
42160
42161
42162
42163
42164
42165
42166
42167
42168
42169
42170
42171
42172
42173
42174
42175
42176
42177
42178
42179
42180
42181
42182
42183
42184
42185
42186
42187
42188
42189
42190
42191
42192
42193
42194
42195
42196
42197
42198
42199
42200
42201
42202
42203
42204
42205
42206
42207
42208
42209
42210
42211
42212
42213
42214
42215
42216
42217
42218
42219
42220
42221
42222
42223
42224
42225
42226
42227
42228
42229
42230
42231
42232
42233
42234
42235
42236
42237
42238
42239
42240
42241
42242
42243
42244
42245
42246
42247
42248
42249
42250
42251
42252
42253
42254
42255
42256
42257
42258
42259
42260
42261
42262
42263
42264
42265
42266
42267
42268
42269
42270
42271
42272
42273
42274
42275
42276
42277
42278
42279
42280
42281
42282
42283
42284
42285
42286
42287
42288
42289
42290
42291
42292
42293
42294
42295
42296
42297
42298
42299
42300
42301
42302
42303
42304
42305
42306
42307
42308
42309
42310
42311
42312
42313
42314
42315
42316
42317
42318
42319
42320
42321
42322
42323
42324
42325
42326
42327
42328
42329
42330
42331
42332
42333
42334
42335
42336
42337
42338
42339
42340
42341
42342
42343
42344
42345
42346
42347
42348
42349
42350
42351
42352
42353
42354
42355
42356
42357
42358
42359
42360
42361
42362
42363
42364
42365
42366
42367
42368
42369
42370
42371
42372
42373
42374
42375
42376
42377
42378
42379
42380
42381
42382
42383
42384
42385
42386
42387
42388
42389
42390
42391
42392
42393
42394
42395
42396
42397
42398
42399
42400
42401
42402
42403
42404
42405
42406
42407
42408
42409
42410
42411
42412
42413
42414
42415
42416
42417
42418
42419
42420
42421
42422
42423
42424
42425
42426
42427
42428
42429
42430
42431
42432
42433
42434
42435
42436
42437
42438
42439
42440
42441
42442
42443
42444
42445
42446
42447
42448
42449
42450
42451
42452
42453
42454
42455
42456
42457
42458
42459
42460
42461
42462
42463
42464
42465
42466
42467
42468
42469
42470
42471
42472
42473
42474
42475
42476
42477
42478
42479
42480
42481
42482
42483
42484
42485
42486
42487
42488
42489
42490
42491
42492
42493
42494
42495
42496
42497
42498
42499
42500
42501
42502
42503
42504
42505
42506
42507
42508
42509
42510
42511
42512
42513
42514
42515
42516
42517
42518
42519
42520
42521
42522
42523
42524
42525
42526
42527
42528
42529
42530
42531
42532
42533
42534
42535
42536
42537
42538
42539
42540
42541
42542
42543
42544
42545
42546
42547
42548
42549
42550
42551
42552
42553
42554
42555
42556
42557
42558
42559
42560
42561
42562
42563
42564
42565
42566
42567
42568
42569
42570
42571
42572
42573
42574
42575
42576
42577
42578
42579
42580
42581
42582
42583
42584
42585
42586
42587
42588
42589
42590
42591
42592
42593
42594
42595
42596
42597
42598
42599
42600
42601
42602
42603
42604
42605
42606
42607
42608
42609
42610
42611
42612
42613
42614
42615
42616
42617
42618
42619
42620
42621
42622
42623
42624
42625
42626
42627
42628
42629
42630
42631
42632
42633
42634
42635
42636
42637
42638
42639
42640
42641
42642
42643
42644
42645
42646
42647
42648
42649
42650
42651
42652
42653
42654
42655
42656
42657
42658
42659
42660
42661
42662
42663
42664
42665
42666
42667
42668
42669
42670
42671
42672
42673
42674
42675
42676
42677
42678
42679
42680
42681
42682
42683
42684
42685
42686
42687
42688
42689
42690
42691
42692
42693
42694
42695
42696
42697
42698
42699
42700
42701
42702
42703
42704
42705
42706
42707
42708
42709
42710
42711
42712
42713
42714
42715
42716
42717
42718
42719
42720
42721
42722
42723
42724
42725
42726
42727
42728
42729
42730
42731
42732
42733
42734
42735
42736
42737
42738
42739
42740
42741
42742
42743
42744
42745
42746
42747
42748
42749
42750
42751
42752
42753
42754
42755
42756
42757
42758
42759
42760
42761
42762
42763
42764
42765
42766
42767
42768
42769
42770
42771
42772
42773
42774
42775
42776
42777
42778
42779
42780
42781
42782
42783
42784
42785
42786
42787
42788
42789
42790
42791
42792
42793
42794
42795
42796
42797
42798
42799
42800
42801
42802
42803
42804
42805
42806
42807
42808
42809
42810
42811
42812
42813
42814
42815
42816
42817
42818
42819
42820
42821
42822
42823
42824
42825
42826
42827
42828
42829
42830
42831
42832
42833
42834
42835
42836
42837
42838
42839
42840
42841
42842
42843
42844
42845
42846
42847
42848
42849
42850
42851
42852
42853
42854
42855
42856
42857
42858
42859
42860
42861
42862
42863
42864
42865
42866
42867
42868
42869
42870
42871
42872
42873
42874
42875
42876
42877
42878
42879
42880
42881
42882
42883
42884
42885
42886
42887
42888
42889
42890
42891
42892
42893
42894
42895
42896
42897
42898
42899
42900
42901
42902
42903
42904
42905
42906
42907
42908
42909
42910
42911
42912
42913
42914
42915
42916
42917
42918
42919
42920
42921
42922
42923
42924
42925
42926
42927
42928
42929
42930
42931
42932
42933
42934
42935
42936
42937
42938
42939
42940
42941
42942
42943
42944
42945
42946
42947
42948
42949
42950
42951
42952
42953
42954
42955
42956
42957
42958
42959
42960
42961
42962
42963
42964
42965
42966
42967
42968
42969
42970
42971
42972
42973
42974
42975
42976
42977
42978
42979
42980
42981
42982
42983
42984
42985
42986
42987
42988
42989
42990
42991
42992
42993
42994
42995
42996
42997
42998
42999
43000
43001
43002
43003
43004
43005
43006
43007
43008
43009
43010
43011
43012
43013
43014
43015
43016
43017
43018
43019
43020
43021
43022
43023
43024
43025
43026
43027
43028
43029
43030
43031
43032
43033
43034
43035
43036
43037
43038
43039
43040
43041
43042
43043
43044
43045
43046
43047
43048
43049
43050
43051
43052
43053
43054
43055
43056
43057
43058
43059
43060
43061
43062
43063
43064
43065
43066
43067
43068
43069
43070
43071
43072
43073
43074
43075
43076
43077
43078
43079
43080
43081
43082
43083
43084
43085
43086
43087
43088
43089
43090
43091
43092
43093
43094
43095
43096
43097
43098
43099
43100
43101
43102
43103
43104
43105
43106
43107
43108
43109
43110
43111
43112
43113
43114
43115
43116
43117
43118
43119
43120
43121
43122
43123
43124
43125
43126
43127
43128
43129
43130
43131
43132
43133
43134
43135
43136
43137
43138
43139
43140
43141
43142
43143
43144
43145
43146
43147
43148
43149
43150
43151
43152
43153
43154
43155
43156
43157
43158
43159
43160
43161
43162
43163
43164
43165
43166
43167
43168
43169
43170
43171
43172
43173
43174
43175
43176
43177
43178
43179
43180
43181
43182
43183
43184
43185
43186
43187
43188
43189
43190
43191
43192
43193
43194
43195
43196
43197
43198
43199
43200
43201
43202
43203
43204
43205
43206
43207
43208
43209
43210
43211
43212
43213
43214
43215
43216
43217
43218
43219
43220
43221
43222
43223
43224
43225
43226
43227
43228
43229
43230
43231
43232
43233
43234
43235
43236
43237
43238
43239
43240
43241
43242
43243
43244
43245
43246
43247
43248
43249
43250
43251
43252
43253
43254
43255
43256
43257
43258
43259
43260
43261
43262
43263
43264
43265
43266
43267
43268
43269
43270
43271
43272
43273
43274
43275
43276
43277
43278
43279
43280
43281
43282
43283
43284
43285
43286
43287
43288
43289
43290
43291
43292
43293
43294
43295
43296
43297
43298
43299
43300
43301
43302
43303
43304
43305
43306
43307
43308
43309
43310
43311
43312
43313
43314
43315
43316
43317
43318
43319
43320
43321
43322
43323
43324
43325
43326
43327
43328
43329
43330
43331
43332
43333
43334
43335
43336
43337
43338
43339
43340
43341
43342
43343
43344
43345
43346
43347
43348
43349
43350
43351
43352
43353
43354
43355
43356
43357
43358
43359
43360
43361
43362
43363
43364
43365
43366
43367
43368
43369
43370
43371
43372
43373
43374
43375
43376
43377
43378
43379
43380
43381
43382
43383
43384
43385
43386
43387
43388
43389
43390
43391
43392
43393
43394
43395
43396
43397
43398
43399
43400
43401
43402
43403
43404
43405
43406
43407
43408
43409
43410
43411
43412
43413
43414
43415
43416
43417
43418
43419
43420
43421
43422
43423
43424
43425
43426
43427
43428
43429
43430
43431
43432
43433
43434
43435
43436
43437
43438
43439
43440
43441
43442
43443
43444
43445
43446
43447
43448
43449
43450
43451
43452
43453
43454
43455
43456
43457
43458
43459
43460
43461
43462
43463
43464
43465
43466
43467
43468
43469
43470
43471
43472
43473
43474
43475
43476
43477
43478
43479
43480
43481
43482
43483
43484
43485
43486
43487
43488
43489
43490
43491
43492
43493
43494
43495
43496
43497
43498
43499
43500
43501
43502
43503
43504
43505
43506
43507
43508
43509
43510
43511
43512
43513
43514
43515
43516
43517
43518
43519
43520
43521
43522
43523
43524
43525
43526
43527
43528
43529
43530
43531
43532
43533
43534
43535
43536
43537
43538
43539
43540
43541
43542
43543
43544
43545
43546
43547
43548
43549
43550
43551
43552
43553
43554
43555
43556
43557
43558
43559
43560
43561
43562
43563
43564
43565
43566
43567
43568
43569
43570
43571
43572
43573
43574
43575
43576
43577
43578
43579
43580
43581
43582
43583
43584
43585
43586
43587
43588
43589
43590
43591
43592
43593
43594
43595
43596
43597
43598
43599
43600
43601
43602
43603
43604
43605
43606
43607
43608
43609
43610
43611
43612
43613
43614
43615
43616
43617
43618
43619
43620
43621
43622
43623
43624
43625
43626
43627
43628
43629
43630
43631
43632
43633
43634
43635
43636
43637
43638
43639
43640
43641
43642
43643
43644
43645
43646
43647
43648
43649
43650
43651
43652
43653
43654
43655
43656
43657
43658
43659
43660
43661
43662
43663
43664
43665
43666
43667
43668
43669
43670
43671
43672
43673
43674
43675
43676
43677
43678
43679
43680
43681
43682
43683
43684
43685
43686
43687
43688
43689
43690
43691
43692
43693
43694
43695
43696
43697
43698
43699
43700
43701
43702
43703
43704
43705
43706
43707
43708
43709
43710
43711
43712
43713
43714
43715
43716
43717
43718
43719
43720
43721
43722
43723
43724
43725
43726
43727
43728
43729
43730
43731
43732
43733
43734
43735
43736
43737
43738
43739
43740
43741
43742
43743
43744
43745
43746
43747
43748
43749
43750
43751
43752
43753
43754
43755
43756
43757
43758
43759
43760
43761
43762
43763
43764
43765
43766
43767
43768
43769
43770
43771
43772
43773
43774
43775
43776
43777
43778
43779
43780
43781
43782
43783
43784
43785
43786
43787
43788
43789
43790
43791
43792
43793
43794
43795
43796
43797
43798
43799
43800
43801
43802
43803
43804
43805
43806
43807
43808
43809
43810
43811
43812
43813
43814
43815
43816
43817
43818
43819
43820
43821
43822
43823
43824
43825
43826
43827
43828
43829
43830
43831
43832
43833
43834
43835
43836
43837
43838
43839
43840
43841
43842
43843
43844
43845
43846
43847
43848
43849
43850
43851
43852
43853
43854
43855
43856
43857
43858
43859
43860
43861
43862
43863
43864
43865
43866
43867
43868
43869
43870
43871
43872
43873
43874
43875
43876
43877
43878
43879
43880
43881
43882
43883
43884
43885
43886
43887
43888
43889
43890
43891
43892
43893
43894
43895
43896
43897
43898
43899
43900
43901
43902
43903
43904
43905
43906
43907
43908
43909
43910
43911
43912
43913
43914
43915
43916
43917
43918
43919
43920
43921
43922
43923
43924
43925
43926
43927
43928
43929
43930
43931
43932
43933
43934
43935
43936
43937
43938
43939
43940
43941
43942
43943
43944
43945
43946
43947
43948
43949
43950
43951
43952
43953
43954
43955
43956
43957
43958
43959
43960
43961
43962
43963
43964
43965
43966
43967
43968
43969
43970
43971
43972
43973
43974
43975
43976
43977
43978
43979
43980
43981
43982
43983
43984
43985
43986
43987
43988
43989
43990
43991
43992
43993
43994
43995
43996
43997
43998
43999
44000
44001
44002
44003
44004
44005
44006
44007
44008
44009
44010
44011
44012
44013
44014
44015
44016
44017
44018
44019
44020
44021
44022
44023
44024
44025
44026
44027
44028
44029
44030
44031
44032
44033
44034
44035
44036
44037
44038
44039
44040
44041
44042
44043
44044
44045
44046
44047
44048
44049
44050
44051
44052
44053
44054
44055
44056
44057
44058
44059
44060
44061
44062
44063
44064
44065
44066
44067
44068
44069
44070
44071
44072
44073
44074
44075
44076
44077
44078
44079
44080
44081
44082
44083
44084
44085
44086
44087
44088
44089
44090
44091
44092
44093
44094
44095
44096
44097
44098
44099
44100
44101
44102
44103
44104
44105
44106
44107
44108
44109
44110
44111
44112
44113
44114
44115
44116
44117
44118
44119
44120
44121
44122
44123
44124
44125
44126
44127
44128
44129
44130
44131
44132
44133
44134
44135
44136
44137
44138
44139
44140
44141
44142
44143
44144
44145
44146
44147
44148
44149
44150
44151
44152
44153
44154
44155
44156
44157
44158
44159
44160
44161
44162
44163
44164
44165
44166
44167
44168
44169
44170
44171
44172
44173
44174
44175
44176
44177
44178
44179
44180
44181
44182
44183
44184
44185
44186
44187
44188
44189
44190
44191
44192
44193
44194
44195
44196
44197
44198
44199
44200
44201
44202
44203
44204
44205
44206
44207
44208
44209
44210
44211
44212
44213
44214
44215
44216
44217
44218
44219
44220
44221
44222
44223
44224
44225
44226
44227
44228
44229
44230
44231
44232
44233
44234
44235
44236
44237
44238
44239
44240
44241
44242
44243
44244
44245
44246
44247
44248
44249
44250
44251
44252
44253
44254
44255
44256
44257
44258
44259
44260
44261
44262
44263
44264
44265
44266
44267
44268
44269
44270
44271
44272
44273
44274
44275
44276
44277
44278
44279
44280
44281
44282
44283
44284
44285
44286
44287
44288
44289
44290
44291
44292
44293
44294
44295
44296
44297
44298
44299
44300
44301
44302
44303
44304
44305
44306
44307
44308
44309
44310
44311
44312
44313
44314
44315
44316
44317
44318
44319
44320
44321
44322
44323
44324
44325
44326
44327
44328
44329
44330
44331
44332
44333
44334
44335
44336
44337
44338
44339
44340
44341
44342
44343
44344
44345
44346
44347
44348
44349
44350
44351
44352
44353
44354
44355
44356
44357
44358
44359
44360
44361
44362
44363
44364
44365
44366
44367
44368
44369
44370
44371
44372
44373
44374
44375
44376
44377
44378
44379
44380
44381
44382
44383
44384
44385
44386
44387
44388
44389
44390
44391
44392
44393
44394
44395
44396
44397
44398
44399
44400
44401
44402
44403
44404
44405
44406
44407
44408
44409
44410
44411
44412
44413
44414
44415
44416
44417
44418
44419
44420
44421
44422
44423
44424
44425
44426
44427
44428
44429
44430
44431
44432
44433
44434
44435
44436
44437
44438
44439
44440
44441
44442
44443
44444
44445
44446
44447
44448
44449
44450
44451
44452
44453
44454
44455
44456
44457
44458
44459
44460
44461
44462
44463
44464
44465
44466
44467
44468
44469
44470
44471
44472
44473
44474
44475
44476
44477
44478
44479
44480
44481
44482
44483
44484
44485
44486
44487
44488
44489
44490
44491
44492
44493
44494
44495
44496
44497
44498
44499
44500
44501
44502
44503
44504
44505
44506
44507
44508
44509
44510
44511
44512
44513
44514
44515
44516
44517
44518
44519
44520
44521
44522
44523
44524
44525
44526
44527
44528
44529
44530
44531
44532
44533
44534
44535
44536
44537
44538
44539
44540
44541
44542
44543
44544
44545
44546
44547
44548
44549
44550
44551
44552
44553
44554
44555
44556
44557
44558
44559
44560
44561
44562
44563
44564
44565
44566
44567
44568
44569
44570
44571
44572
44573
44574
44575
44576
44577
44578
44579
44580
44581
44582
44583
44584
44585
44586
44587
44588
44589
44590
44591
44592
44593
44594
44595
44596
44597
44598
44599
44600
44601
44602
44603
44604
44605
44606
44607
44608
44609
44610
44611
44612
44613
44614
44615
44616
44617
44618
44619
44620
44621
44622
44623
44624
44625
44626
44627
44628
44629
44630
44631
44632
44633
44634
44635
44636
44637
44638
44639
44640
44641
44642
44643
44644
44645
44646
44647
44648
44649
44650
44651
44652
44653
44654
44655
44656
44657
44658
44659
44660
44661
44662
44663
44664
44665
44666
44667
44668
44669
44670
44671
44672
44673
44674
44675
44676
44677
44678
44679
44680
44681
44682
44683
44684
44685
44686
44687
44688
44689
44690
44691
44692
44693
44694
44695
44696
44697
44698
44699
44700
44701
44702
44703
44704
44705
44706
44707
44708
44709
44710
44711
44712
44713
44714
44715
44716
44717
44718
44719
44720
44721
44722
44723
44724
44725
44726
44727
44728
44729
44730
44731
44732
44733
44734
44735
44736
44737
44738
44739
44740
44741
44742
44743
44744
44745
44746
44747
44748
44749
44750
44751
44752
44753
44754
44755
44756
44757
44758
44759
44760
44761
44762
44763
44764
44765
44766
44767
44768
44769
44770
44771
44772
44773
44774
44775
44776
44777
44778
44779
44780
44781
44782
44783
44784
44785
44786
44787
44788
44789
44790
44791
44792
44793
44794
44795
44796
44797
44798
44799
44800
44801
44802
44803
44804
44805
44806
44807
44808
44809
44810
44811
44812
44813
44814
44815
44816
44817
44818
44819
44820
44821
44822
44823
44824
44825
44826
44827
44828
44829
44830
44831
44832
44833
44834
44835
44836
44837
44838
44839
44840
44841
44842
44843
44844
44845
44846
44847
44848
44849
44850
44851
44852
44853
44854
44855
44856
44857
44858
44859
44860
44861
44862
44863
44864
44865
44866
44867
44868
44869
44870
44871
44872
44873
44874
44875
44876
44877
44878
44879
44880
44881
44882
44883
44884
44885
44886
44887
44888
44889
44890
44891
44892
44893
44894
44895
44896
44897
44898
44899
44900
44901
44902
44903
44904
44905
44906
44907
44908
44909
44910
44911
44912
44913
44914
44915
44916
44917
44918
44919
44920
44921
44922
44923
44924
44925
44926
44927
44928
44929
44930
44931
44932
44933
44934
44935
44936
44937
44938
44939
44940
44941
44942
44943
44944
44945
44946
44947
44948
44949
44950
44951
44952
44953
44954
44955
44956
44957
44958
44959
44960
44961
44962
44963
44964
44965
44966
44967
44968
44969
44970
44971
44972
44973
44974
44975
44976
44977
44978
44979
44980
44981
44982
44983
44984
44985
44986
44987
44988
44989
44990
44991
44992
44993
44994
44995
44996
44997
44998
44999
45000
45001
45002
45003
45004
45005
45006
45007
45008
45009
45010
45011
45012
45013
45014
45015
45016
45017
45018
45019
45020
45021
45022
45023
45024
45025
45026
45027
45028
45029
45030
45031
45032
45033
45034
45035
45036
45037
45038
45039
45040
45041
45042
45043
45044
45045
45046
45047
45048
45049
45050
45051
45052
45053
45054
45055
45056
45057
45058
45059
45060
45061
45062
45063
45064
45065
45066
45067
45068
45069
45070
45071
45072
45073
45074
45075
45076
45077
45078
45079
45080
45081
45082
45083
45084
45085
45086
45087
45088
45089
45090
45091
45092
45093
45094
45095
45096
45097
45098
45099
45100
45101
45102
45103
45104
45105
45106
45107
45108
45109
45110
45111
45112
45113
45114
45115
45116
45117
45118
45119
45120
45121
45122
45123
45124
45125
45126
45127
45128
45129
45130
45131
45132
45133
45134
45135
45136
45137
45138
45139
45140
45141
45142
45143
45144
45145
45146
45147
45148
45149
45150
45151
45152
45153
45154
45155
45156
45157
45158
45159
45160
45161
45162
45163
45164
45165
45166
45167
45168
45169
45170
45171
45172
45173
45174
45175
45176
45177
45178
45179
45180
45181
45182
45183
45184
45185
45186
45187
45188
45189
45190
45191
45192
45193
45194
45195
45196
45197
45198
45199
45200
45201
45202
45203
45204
45205
45206
45207
45208
45209
45210
45211
45212
45213
45214
45215
45216
45217
45218
45219
45220
45221
45222
45223
45224
45225
45226
45227
45228
45229
45230
45231
45232
45233
45234
45235
45236
45237
45238
45239
45240
45241
45242
45243
45244
45245
45246
45247
45248
45249
45250
45251
45252
45253
45254
45255
45256
45257
45258
45259
45260
45261
45262
45263
45264
45265
45266
45267
45268
45269
45270
45271
45272
45273
45274
45275
45276
45277
45278
45279
45280
45281
45282
45283
45284
45285
45286
45287
45288
45289
45290
45291
45292
45293
45294
45295
45296
45297
45298
45299
45300
45301
45302
45303
45304
45305
45306
45307
45308
45309
45310
45311
45312
45313
45314
45315
45316
45317
45318
45319
45320
45321
45322
45323
45324
45325
45326
45327
45328
45329
45330
45331
45332
45333
45334
45335
45336
45337
45338
45339
45340
45341
45342
45343
45344
45345
45346
45347
45348
45349
45350
45351
45352
45353
45354
45355
45356
45357
45358
45359
45360
45361
45362
45363
45364
45365
45366
45367
45368
45369
45370
45371
45372
45373
45374
45375
45376
45377
45378
45379
45380
45381
45382
45383
45384
45385
45386
45387
45388
45389
45390
45391
45392
45393
45394
45395
45396
45397
45398
45399
45400
45401
45402
45403
45404
45405
45406
45407
45408
45409
45410
45411
45412
45413
45414
45415
45416
45417
45418
45419
45420
45421
45422
45423
45424
45425
45426
45427
45428
45429
45430
45431
45432
45433
45434
45435
45436
45437
45438
45439
45440
45441
45442
45443
45444
45445
45446
45447
45448
45449
45450
45451
45452
45453
45454
45455
45456
45457
45458
45459
45460
45461
45462
45463
45464
45465
45466
45467
45468
45469
45470
45471
45472
45473
45474
45475
45476
45477
45478
45479
45480
45481
45482
45483
45484
45485
45486
45487
45488
45489
45490
45491
45492
45493
45494
45495
45496
45497
45498
45499
45500
45501
45502
45503
45504
45505
45506
45507
45508
45509
45510
45511
45512
45513
45514
45515
45516
45517
45518
45519
45520
45521
45522
45523
45524
45525
45526
45527
45528
45529
45530
45531
45532
45533
45534
45535
45536
45537
45538
45539
45540
45541
45542
45543
45544
45545
45546
45547
45548
45549
45550
45551
45552
45553
45554
45555
45556
45557
45558
45559
45560
45561
45562
45563
45564
45565
45566
45567
45568
45569
45570
45571
45572
45573
45574
45575
45576
45577
45578
45579
45580
45581
45582
45583
45584
45585
45586
45587
45588
45589
45590
45591
45592
45593
45594
45595
45596
45597
45598
45599
45600
45601
45602
45603
45604
45605
45606
45607
45608
45609
45610
45611
45612
45613
45614
45615
45616
45617
45618
45619
45620
45621
45622
45623
45624
45625
45626
45627
45628
45629
45630
45631
45632
45633
45634
45635
45636
45637
45638
45639
45640
45641
45642
45643
45644
45645
45646
45647
45648
45649
45650
45651
45652
45653
45654
45655
45656
45657
45658
45659
45660
45661
45662
45663
45664
45665
45666
45667
45668
45669
45670
45671
45672
45673
45674
45675
45676
45677
45678
45679
45680
45681
45682
45683
45684
45685
45686
45687
45688
45689
45690
45691
45692
45693
45694
45695
45696
45697
45698
45699
45700
45701
45702
45703
45704
45705
45706
45707
45708
45709
45710
45711
45712
45713
45714
45715
45716
45717
45718
45719
45720
45721
45722
45723
45724
45725
45726
45727
45728
45729
45730
45731
45732
45733
45734
45735
45736
45737
45738
45739
45740
45741
45742
45743
45744
45745
45746
45747
45748
45749
45750
45751
45752
45753
45754
45755
45756
45757
45758
45759
45760
45761
45762
45763
45764
45765
45766
45767
45768
45769
45770
45771
45772
45773
45774
45775
45776
45777
45778
45779
45780
45781
45782
45783
45784
45785
45786
45787
45788
45789
45790
45791
45792
45793
45794
45795
45796
45797
45798
45799
45800
45801
45802
45803
45804
45805
45806
45807
45808
45809
45810
45811
45812
45813
45814
45815
45816
45817
45818
45819
45820
45821
45822
45823
45824
45825
45826
45827
45828
45829
45830
45831
45832
45833
45834
45835
45836
45837
45838
45839
45840
45841
45842
45843
45844
45845
45846
45847
45848
45849
45850
45851
45852
45853
45854
45855
45856
45857
45858
45859
45860
45861
45862
45863
45864
45865
45866
45867
45868
45869
45870
45871
45872
45873
45874
45875
45876
45877
45878
45879
45880
45881
45882
45883
45884
45885
45886
45887
45888
45889
45890
45891
45892
45893
45894
45895
45896
45897
45898
45899
45900
45901
45902
45903
45904
45905
45906
45907
45908
45909
45910
45911
45912
45913
45914
45915
45916
45917
45918
45919
45920
45921
45922
45923
45924
45925
45926
45927
45928
45929
45930
45931
45932
45933
45934
45935
45936
45937
45938
45939
45940
45941
45942
45943
45944
45945
45946
45947
45948
45949
45950
45951
45952
45953
45954
45955
45956
45957
45958
45959
45960
45961
45962
45963
45964
45965
45966
45967
45968
45969
45970
45971
45972
45973
45974
45975
45976
45977
45978
45979
45980
45981
45982
45983
45984
45985
45986
45987
45988
45989
45990
45991
45992
45993
45994
45995
45996
45997
45998
45999
46000
46001
46002
46003
46004
46005
46006
46007
46008
46009
46010
46011
46012
46013
46014
46015
46016
46017
46018
46019
46020
46021
46022
46023
46024
46025
46026
46027
46028
46029
46030
46031
46032
46033
46034
46035
46036
46037
46038
46039
46040
46041
46042
46043
46044
46045
46046
46047
46048
46049
46050
46051
46052
46053
46054
46055
46056
46057
46058
46059
46060
46061
46062
46063
46064
46065
46066
46067
46068
46069
46070
46071
46072
46073
46074
46075
46076
46077
46078
46079
46080
46081
46082
46083
46084
46085
46086
46087
46088
46089
46090
46091
46092
46093
46094
46095
46096
46097
46098
46099
46100
46101
46102
46103
46104
46105
46106
46107
46108
46109
46110
46111
46112
46113
46114
46115
46116
46117
46118
46119
46120
46121
46122
46123
46124
46125
46126
46127
46128
46129
46130
46131
46132
46133
46134
46135
46136
46137
46138
46139
46140
46141
46142
46143
46144
46145
46146
46147
46148
46149
46150
46151
46152
46153
46154
46155
46156
46157
46158
46159
46160
46161
46162
46163
46164
46165
46166
46167
46168
46169
46170
46171
46172
46173
46174
46175
46176
46177
46178
46179
46180
46181
46182
46183
46184
46185
46186
46187
46188
46189
46190
46191
46192
46193
46194
46195
46196
46197
46198
46199
46200
46201
46202
46203
46204
46205
46206
46207
46208
46209
46210
46211
46212
46213
46214
46215
46216
46217
46218
46219
46220
46221
46222
46223
46224
46225
46226
46227
46228
46229
46230
46231
46232
46233
46234
46235
46236
46237
46238
46239
46240
46241
46242
46243
46244
46245
46246
46247
46248
46249
46250
46251
46252
46253
46254
46255
46256
46257
46258
46259
46260
46261
46262
46263
46264
46265
46266
46267
46268
46269
46270
46271
46272
46273
46274
46275
46276
46277
46278
46279
46280
46281
46282
46283
46284
46285
46286
46287
46288
46289
46290
46291
46292
46293
46294
46295
46296
46297
46298
46299
46300
46301
46302
46303
46304
46305
46306
46307
46308
46309
46310
46311
46312
46313
46314
46315
46316
46317
46318
46319
46320
46321
46322
46323
46324
46325
46326
46327
46328
46329
46330
46331
46332
46333
46334
46335
46336
46337
46338
46339
46340
46341
46342
46343
46344
46345
46346
46347
46348
46349
46350
46351
46352
46353
46354
46355
46356
46357
46358
46359
46360
46361
46362
46363
46364
46365
46366
46367
46368
46369
46370
46371
46372
46373
46374
46375
46376
46377
46378
46379
46380
46381
46382
46383
46384
46385
46386
46387
46388
46389
46390
46391
46392
46393
46394
46395
46396
46397
46398
46399
46400
46401
46402
46403
46404
46405
46406
46407
46408
46409
46410
46411
46412
46413
46414
46415
46416
46417
46418
46419
46420
46421
46422
46423
46424
46425
46426
46427
46428
46429
46430
46431
46432
46433
46434
46435
46436
46437
46438
46439
46440
46441
46442
46443
46444
46445
46446
46447
46448
46449
46450
46451
46452
46453
46454
46455
46456
46457
46458
46459
46460
46461
46462
46463
46464
46465
46466
46467
46468
46469
46470
46471
46472
46473
46474
46475
46476
46477
46478
46479
46480
46481
46482
46483
46484
46485
46486
46487
46488
46489
46490
46491
46492
46493
46494
46495
46496
46497
46498
46499
46500
46501
46502
46503
46504
46505
46506
46507
46508
46509
46510
46511
46512
46513
46514
46515
46516
46517
46518
46519
46520
46521
46522
46523
46524
46525
46526
46527
46528
46529
46530
46531
46532
46533
46534
46535
46536
46537
46538
46539
46540
46541
46542
46543
46544
46545
46546
46547
46548
46549
46550
46551
46552
46553
46554
46555
46556
46557
46558
46559
46560
46561
46562
46563
46564
46565
46566
46567
46568
46569
46570
46571
46572
46573
46574
46575
46576
46577
46578
46579
46580
46581
46582
46583
46584
46585
46586
46587
46588
46589
46590
46591
46592
46593
46594
46595
46596
46597
46598
46599
46600
46601
46602
46603
46604
46605
46606
46607
46608
46609
46610
46611
46612
46613
46614
46615
46616
46617
46618
46619
46620
46621
46622
46623
46624
46625
46626
46627
46628
46629
46630
46631
46632
46633
46634
46635
46636
46637
46638
46639
46640
46641
46642
46643
46644
46645
46646
46647
46648
46649
46650
46651
46652
46653
46654
46655
46656
46657
46658
46659
46660
46661
46662
46663
46664
46665
46666
46667
46668
46669
46670
46671
46672
46673
46674
46675
46676
46677
46678
46679
46680
46681
46682
46683
46684
46685
46686
46687
46688
46689
46690
46691
46692
46693
46694
46695
46696
46697
46698
46699
46700
46701
46702
46703
46704
46705
46706
46707
46708
46709
46710
46711
46712
46713
46714
46715
46716
46717
46718
46719
46720
46721
46722
46723
46724
46725
46726
46727
46728
46729
46730
46731
46732
46733
46734
46735
46736
46737
46738
46739
46740
46741
46742
46743
46744
46745
46746
46747
46748
46749
46750
46751
46752
46753
46754
46755
46756
46757
46758
46759
46760
46761
46762
46763
46764
46765
46766
46767
46768
46769
46770
46771
46772
46773
46774
46775
46776
46777
46778
46779
46780
46781
46782
46783
46784
46785
46786
46787
46788
46789
46790
46791
46792
46793
46794
46795
46796
46797
46798
46799
46800
46801
46802
46803
46804
46805
46806
46807
46808
46809
46810
46811
46812
46813
46814
46815
46816
46817
46818
46819
46820
46821
46822
46823
46824
46825
46826
46827
46828
46829
46830
46831
46832
46833
46834
46835
46836
46837
46838
46839
46840
46841
46842
46843
46844
46845
46846
46847
46848
46849
46850
46851
46852
46853
46854
46855
46856
46857
46858
46859
46860
46861
46862
46863
46864
46865
46866
46867
46868
46869
46870
46871
46872
46873
46874
46875
46876
46877
46878
46879
46880
46881
46882
46883
46884
46885
46886
46887
46888
46889
46890
46891
46892
46893
46894
46895
46896
46897
46898
46899
46900
46901
46902
46903
46904
46905
46906
46907
46908
46909
46910
46911
46912
46913
46914
46915
46916
46917
46918
46919
46920
46921
46922
46923
46924
46925
46926
46927
46928
46929
46930
46931
46932
46933
46934
46935
46936
46937
46938
46939
46940
46941
46942
46943
46944
46945
46946
46947
46948
46949
46950
46951
46952
46953
46954
46955
46956
46957
46958
46959
46960
46961
46962
46963
46964
46965
46966
46967
46968
46969
46970
46971
46972
46973
46974
46975
46976
46977
46978
46979
46980
46981
46982
46983
46984
46985
46986
46987
46988
46989
46990
46991
46992
46993
46994
46995
46996
46997
46998
46999
47000
47001
47002
47003
47004
47005
47006
47007
47008
47009
47010
47011
47012
47013
47014
47015
47016
47017
47018
47019
47020
47021
47022
47023
47024
47025
47026
47027
47028
47029
47030
47031
47032
47033
47034
47035
47036
47037
47038
47039
47040
47041
47042
47043
47044
47045
47046
47047
47048
47049
47050
47051
47052
47053
47054
47055
47056
47057
47058
47059
47060
47061
47062
47063
47064
47065
47066
47067
47068
47069
47070
47071
47072
47073
47074
47075
47076
47077
47078
47079
47080
47081
47082
47083
47084
47085
47086
47087
47088
47089
47090
47091
47092
47093
47094
47095
47096
47097
47098
47099
47100
47101
47102
47103
47104
47105
47106
47107
47108
47109
47110
47111
47112
47113
47114
47115
47116
47117
47118
47119
47120
47121
47122
47123
47124
47125
47126
47127
47128
47129
47130
47131
47132
47133
47134
47135
47136
47137
47138
47139
47140
47141
47142
47143
47144
47145
47146
47147
47148
47149
47150
47151
47152
47153
47154
47155
47156
47157
47158
47159
47160
47161
47162
47163
47164
47165
47166
47167
47168
47169
47170
47171
47172
47173
47174
47175
47176
47177
47178
47179
47180
47181
47182
47183
47184
47185
47186
47187
47188
47189
47190
47191
47192
47193
47194
47195
47196
47197
47198
47199
47200
47201
47202
47203
47204
47205
47206
47207
47208
47209
47210
47211
47212
47213
47214
47215
47216
47217
47218
47219
47220
47221
47222
47223
47224
47225
47226
47227
47228
47229
47230
47231
47232
47233
47234
47235
47236
47237
47238
47239
47240
47241
47242
47243
47244
47245
47246
47247
47248
47249
47250
47251
47252
47253
47254
47255
47256
47257
47258
47259
47260
47261
47262
47263
47264
47265
47266
47267
47268
47269
47270
47271
47272
47273
47274
47275
47276
47277
47278
47279
47280
47281
47282
47283
47284
47285
47286
47287
47288
47289
47290
47291
47292
47293
47294
47295
47296
47297
47298
47299
47300
47301
47302
47303
47304
47305
47306
47307
47308
47309
47310
47311
47312
47313
47314
47315
47316
47317
47318
47319
47320
47321
47322
47323
47324
47325
47326
47327
47328
47329
47330
47331
47332
47333
47334
47335
47336
47337
47338
47339
47340
47341
47342
47343
47344
47345
47346
47347
47348
47349
47350
47351
47352
47353
47354
47355
47356
47357
47358
47359
47360
47361
47362
47363
47364
47365
47366
47367
47368
47369
47370
47371
47372
47373
47374
47375
47376
47377
47378
47379
47380
47381
47382
47383
47384
47385
47386
47387
47388
47389
47390
47391
47392
47393
47394
47395
47396
47397
47398
47399
47400
47401
47402
47403
47404
47405
47406
47407
47408
47409
47410
47411
47412
47413
47414
47415
47416
47417
47418
47419
47420
47421
47422
47423
47424
47425
47426
47427
47428
47429
47430
47431
47432
47433
47434
47435
47436
47437
47438
47439
47440
47441
47442
47443
47444
47445
47446
47447
47448
47449
47450
47451
47452
47453
47454
47455
47456
47457
47458
47459
47460
47461
47462
47463
47464
47465
47466
47467
47468
47469
47470
47471
47472
47473
47474
47475
47476
47477
47478
47479
47480
47481
47482
47483
47484
47485
47486
47487
47488
47489
47490
47491
47492
47493
47494
47495
47496
47497
47498
47499
47500
47501
47502
47503
47504
47505
47506
47507
47508
47509
47510
47511
47512
47513
47514
47515
47516
47517
47518
47519
47520
47521
47522
47523
47524
47525
47526
47527
47528
47529
47530
47531
47532
47533
47534
47535
47536
47537
47538
47539
47540
47541
47542
47543
47544
47545
47546
47547
47548
47549
47550
47551
47552
47553
47554
47555
47556
47557
47558
47559
47560
47561
47562
47563
47564
47565
47566
47567
47568
47569
47570
47571
47572
47573
47574
47575
47576
47577
47578
47579
47580
47581
47582
47583
47584
47585
47586
47587
47588
47589
47590
47591
47592
47593
47594
47595
47596
47597
47598
47599
47600
47601
47602
47603
47604
47605
47606
47607
47608
47609
47610
47611
47612
47613
47614
47615
47616
47617
47618
47619
47620
47621
47622
47623
47624
47625
47626
47627
47628
47629
47630
47631
47632
47633
47634
47635
47636
47637
47638
47639
47640
47641
47642
47643
47644
47645
47646
47647
47648
47649
47650
47651
47652
47653
47654
47655
47656
47657
47658
47659
47660
47661
47662
47663
47664
47665
47666
47667
47668
47669
47670
47671
47672
47673
47674
47675
47676
47677
47678
47679
47680
47681
47682
47683
47684
47685
47686
47687
47688
47689
47690
47691
47692
47693
47694
47695
47696
47697
47698
47699
47700
47701
47702
47703
47704
47705
47706
47707
47708
47709
47710
47711
47712
47713
47714
47715
47716
47717
47718
47719
47720
47721
47722
47723
47724
47725
47726
47727
47728
47729
47730
47731
47732
47733
47734
47735
47736
47737
47738
47739
47740
47741
47742
47743
47744
47745
47746
47747
47748
47749
47750
47751
47752
47753
47754
47755
47756
47757
47758
47759
47760
47761
47762
47763
47764
47765
47766
47767
47768
47769
47770
47771
47772
47773
47774
47775
47776
47777
47778
47779
47780
47781
47782
47783
47784
47785
47786
47787
47788
47789
47790
47791
47792
47793
47794
47795
47796
47797
47798
47799
47800
47801
47802
47803
47804
47805
47806
47807
47808
47809
47810
47811
47812
47813
47814
47815
47816
47817
47818
47819
47820
47821
47822
47823
47824
47825
47826
47827
47828
47829
47830
47831
47832
47833
47834
47835
47836
47837
47838
47839
47840
47841
47842
47843
47844
47845
47846
47847
47848
47849
47850
47851
47852
47853
47854
47855
47856
47857
47858
47859
47860
47861
47862
47863
47864
47865
47866
47867
47868
47869
47870
47871
47872
47873
47874
47875
47876
47877
47878
47879
47880
47881
47882
47883
47884
47885
47886
47887
47888
47889
47890
47891
47892
47893
47894
47895
47896
47897
47898
47899
47900
47901
47902
47903
47904
47905
47906
47907
47908
47909
47910
47911
47912
47913
47914
47915
47916
47917
47918
47919
47920
47921
47922
47923
47924
47925
47926
47927
47928
47929
47930
47931
47932
47933
47934
47935
47936
47937
47938
47939
47940
47941
47942
47943
47944
47945
47946
47947
47948
47949
47950
47951
47952
47953
47954
47955
47956
47957
47958
47959
47960
47961
47962
47963
47964
47965
47966
47967
47968
47969
47970
47971
47972
47973
47974
47975
47976
47977
47978
47979
47980
47981
47982
47983
47984
47985
47986
47987
47988
47989
47990
47991
47992
47993
47994
47995
47996
47997
47998
47999
48000
48001
48002
48003
48004
48005
48006
48007
48008
48009
48010
48011
48012
48013
48014
48015
48016
48017
48018
48019
48020
48021
48022
48023
48024
48025
48026
48027
48028
48029
48030
48031
48032
48033
48034
48035
48036
48037
48038
48039
48040
48041
48042
48043
48044
48045
48046
48047
48048
48049
48050
48051
48052
48053
48054
48055
48056
48057
48058
48059
48060
48061
48062
48063
48064
48065
48066
48067
48068
48069
48070
48071
48072
48073
48074
48075
48076
48077
48078
48079
48080
48081
48082
48083
48084
48085
48086
48087
48088
48089
48090
48091
48092
48093
48094
48095
48096
48097
48098
48099
48100
48101
48102
48103
48104
48105
48106
48107
48108
48109
48110
48111
48112
48113
48114
48115
48116
48117
48118
48119
48120
48121
48122
48123
48124
48125
48126
48127
48128
48129
48130
48131
48132
48133
48134
48135
48136
48137
48138
48139
48140
48141
48142
48143
48144
48145
48146
48147
48148
48149
48150
48151
48152
48153
48154
48155
48156
48157
48158
48159
48160
48161
48162
48163
48164
48165
48166
48167
48168
48169
48170
48171
48172
48173
48174
48175
48176
48177
48178
48179
48180
48181
48182
48183
48184
48185
48186
48187
48188
48189
48190
48191
48192
48193
48194
48195
48196
48197
48198
48199
48200
48201
48202
48203
48204
48205
48206
48207
48208
48209
48210
48211
48212
48213
48214
48215
48216
48217
48218
48219
48220
48221
48222
48223
48224
48225
48226
48227
48228
48229
48230
48231
48232
48233
48234
48235
48236
48237
48238
48239
48240
48241
48242
48243
48244
48245
48246
48247
48248
48249
48250
48251
48252
48253
48254
48255
48256
48257
48258
48259
48260
48261
48262
48263
48264
48265
48266
48267
48268
48269
48270
48271
48272
48273
48274
48275
48276
48277
48278
48279
48280
48281
48282
48283
48284
48285
48286
48287
48288
48289
48290
48291
48292
48293
48294
48295
48296
48297
48298
48299
48300
48301
48302
48303
48304
48305
48306
48307
48308
48309
48310
48311
48312
48313
48314
48315
48316
48317
48318
48319
48320
48321
48322
48323
48324
48325
48326
48327
48328
48329
48330
48331
48332
48333
48334
48335
48336
48337
48338
48339
48340
48341
48342
48343
48344
48345
48346
48347
48348
48349
48350
48351
48352
48353
48354
48355
48356
48357
48358
48359
48360
48361
48362
48363
48364
48365
48366
48367
48368
48369
48370
48371
48372
48373
48374
48375
48376
48377
48378
48379
48380
48381
48382
48383
48384
48385
48386
48387
48388
48389
48390
48391
48392
48393
48394
48395
48396
48397
48398
48399
48400
48401
48402
48403
48404
48405
48406
48407
48408
48409
48410
48411
48412
48413
48414
48415
48416
48417
48418
48419
48420
48421
48422
48423
48424
48425
48426
48427
48428
48429
48430
48431
48432
48433
48434
48435
48436
48437
48438
48439
48440
48441
48442
48443
48444
48445
48446
48447
48448
48449
48450
48451
48452
48453
48454
48455
48456
48457
48458
48459
48460
48461
48462
48463
48464
48465
48466
48467
48468
48469
48470
48471
48472
48473
48474
48475
48476
48477
48478
48479
48480
48481
48482
48483
48484
48485
48486
48487
48488
48489
48490
48491
48492
48493
48494
48495
48496
48497
48498
48499
48500
48501
48502
48503
48504
48505
48506
48507
48508
48509
48510
48511
48512
48513
48514
48515
48516
48517
48518
48519
48520
48521
48522
48523
48524
48525
48526
48527
48528
48529
48530
48531
48532
48533
48534
48535
48536
48537
48538
48539
48540
48541
48542
48543
48544
48545
48546
48547
48548
48549
48550
48551
48552
48553
48554
48555
48556
48557
48558
48559
48560
48561
48562
48563
48564
48565
48566
48567
48568
48569
48570
48571
48572
48573
48574
48575
48576
48577
48578
48579
48580
48581
48582
48583
48584
48585
48586
48587
48588
48589
48590
48591
48592
48593
48594
48595
48596
48597
48598
48599
48600
48601
48602
48603
48604
48605
48606
48607
48608
48609
48610
48611
48612
48613
48614
48615
48616
48617
48618
48619
48620
48621
48622
48623
48624
48625
48626
48627
48628
48629
48630
48631
48632
48633
48634
48635
48636
48637
48638
48639
48640
48641
48642
48643
48644
48645
48646
48647
48648
48649
48650
48651
48652
48653
48654
48655
48656
48657
48658
48659
48660
48661
48662
48663
48664
48665
48666
48667
48668
48669
48670
48671
48672
48673
48674
48675
48676
48677
48678
48679
48680
48681
48682
48683
48684
48685
48686
48687
48688
48689
48690
48691
48692
48693
48694
48695
48696
48697
48698
48699
48700
48701
48702
48703
48704
48705
48706
48707
48708
48709
48710
48711
48712
48713
48714
48715
48716
48717
48718
48719
48720
48721
48722
48723
48724
48725
48726
48727
48728
48729
48730
48731
48732
48733
48734
48735
48736
48737
48738
48739
48740
48741
48742
48743
48744
48745
48746
48747
48748
48749
48750
--- /dev/null
+++ b/arch/ubicom32/crypto/aes_ubicom32.c
@@ -0,0 +1,458 @@
+/*
+ * arch/ubicom32/crypto/aes_ubicom32.c
+ *   Ubicom32 implementation of the AES Cipher Algorithm.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <crypto/aes.h>
+#include <crypto/algapi.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/spinlock.h>
+#include "crypto_ubicom32.h"
+#include <asm/linkage.h>
+
+struct ubicom32_aes_ctx {
+	u8 key[AES_MAX_KEY_SIZE];
+	u32 ctrl;
+	int key_len;
+};
+
+static inline void aes_hw_set_key(const u8 *key, u8 key_len)
+{
+	/*
+	 * switch case has more overhead than 4 move.4 instructions, so just copy 256 bits
+	 */
+	SEC_SET_KEY_256(key);
+}
+
+static inline void aes_hw_set_iv(const u8 *iv)
+{
+	SEC_SET_IV_4W(iv);
+}
+
+static inline void aes_hw_cipher(u8 *out, const u8 *in)
+{
+	SEC_SET_INPUT_4W(in);
+
+	asm volatile (                                                
+	"	; start AES by writing 0x40(SECURITY_BASE)	\n\t" 
+	"	move.4 0x40(%0), #0x01				\n\t" 
+	"	pipe_flush 0                                    \n\t" 
+	"							\n\t" 
+	"	; wait for the module to calculate the output	\n\t" 
+	"	btst 0x04(%0), #0				\n\t" 
+	"	jmpne.f .-4					\n\t" 
+		:                                                             
+		: "a" (SEC_BASE)				                      
+		: "cc"
+	);
+	
+	SEC_GET_OUTPUT_4W(out);
+}
+
+static int __ocm_text aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
+		       unsigned int key_len)
+{
+	struct ubicom32_aes_ctx *uctx = crypto_tfm_ctx(tfm);
+
+	uctx->key_len = key_len;
+	memcpy(uctx->key, in_key, key_len);
+
+	/*
+  	 * leave out HASH_ALG (none = 0), CBC (no = 0), DIR (unknown) yet
+  	 */
+	switch (uctx->key_len) {
+	case 16:
+		uctx->ctrl = SEC_KEY_128_BITS | SEC_ALG_AES;
+		break;
+	case 24:
+		uctx->ctrl = SEC_KEY_192_BITS | SEC_ALG_AES;
+		break;
+	case 32:
+		uctx->ctrl = SEC_KEY_256_BITS | SEC_ALG_AES;
+		break;
+	}
+
+	return 0;
+}
+
+static inline void aes_cipher(struct crypto_tfm *tfm, u8 *out, const u8 *in, u32 extra_flags)
+{
+	const struct ubicom32_aes_ctx *uctx = crypto_tfm_ctx(tfm);
+
+	hw_crypto_lock();
+	hw_crypto_check();
+	hw_crypto_set_ctrl(uctx->ctrl | extra_flags);
+
+	aes_hw_set_key(uctx->key, uctx->key_len);
+	aes_hw_cipher(out, in);
+
+	hw_crypto_unlock();	
+}
+
+static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+{
+	aes_cipher(tfm, out, in, SEC_DIR_ENCRYPT);
+}
+
+static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+{
+	aes_cipher(tfm, out, in, SEC_DIR_DECRYPT);
+}
+
+static struct crypto_alg aes_alg = {
+	.cra_name		=	"aes",
+	.cra_driver_name	=	"aes-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER, 
+	.cra_blocksize		=	AES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_aes_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(aes_alg.cra_list),
+	.cra_u			=	{
+		.cipher = {
+			.cia_min_keysize	=	AES_MIN_KEY_SIZE,
+			.cia_max_keysize	=	AES_MAX_KEY_SIZE,
+			.cia_setkey		=	aes_set_key,
+			.cia_encrypt		=	aes_encrypt,
+			.cia_decrypt		=	aes_decrypt,
+		}
+	}
+};
+
+static void __ocm_text ecb_aes_crypt_loop(u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		aes_hw_cipher(out, in);
+		out += AES_BLOCK_SIZE;
+		in += AES_BLOCK_SIZE;
+		n -= AES_BLOCK_SIZE;
+	}
+}
+
+static int __ocm_text ecb_aes_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, 
+			 struct scatterlist *src, unsigned int nbytes, u32 extra_flags)
+{
+	const struct ubicom32_aes_ctx *uctx = crypto_blkcipher_ctx(desc->tfm);
+	int ret;
+	
+	struct blkcipher_walk walk;
+	blkcipher_walk_init(&walk, dst, src, nbytes);
+	ret = blkcipher_walk_virt(desc, &walk);
+        if (ret) {
+                return ret;
+        }
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+        hw_crypto_set_ctrl(uctx->ctrl | extra_flags);
+        aes_hw_set_key(uctx->key, uctx->key_len);
+	
+	while (likely((nbytes = walk.nbytes))) {
+		/* only use complete blocks */
+		unsigned int n = nbytes & ~(AES_BLOCK_SIZE - 1);
+		u8 *out = walk.dst.virt.addr;
+		u8 *in = walk.src.virt.addr;
+
+		/* finish n/16 blocks */
+		ecb_aes_crypt_loop(out, in, n);
+		
+		nbytes &= AES_BLOCK_SIZE - 1;
+		ret = blkcipher_walk_done(desc, &walk, nbytes);
+	}
+
+	hw_crypto_unlock();
+	return ret;
+}
+
+static int ecb_aes_encrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return ecb_aes_crypt(desc, dst, src, nbytes, SEC_DIR_ENCRYPT);
+}
+
+static int ecb_aes_decrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return ecb_aes_crypt(desc, dst, src, nbytes, SEC_DIR_DECRYPT);
+}
+
+static struct crypto_alg ecb_aes_alg = {
+	.cra_name		=	"ecb(aes)",
+	.cra_driver_name	=	"ecb-aes-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER, 
+	.cra_blocksize		=	AES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_aes_ctx),
+	.cra_alignmask          =       CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(ecb_aes_alg.cra_list),
+	.cra_u			=	{
+		.blkcipher = {
+			.min_keysize		=	AES_MIN_KEY_SIZE,
+			.max_keysize		=	AES_MAX_KEY_SIZE,
+			.setkey			=	aes_set_key,
+			.encrypt		=	ecb_aes_encrypt,
+			.decrypt		=	ecb_aes_decrypt,
+		}
+	}
+};
+
+#if CRYPTO_UBICOM32_LOOP_ASM 
+void __ocm_text cbc_aes_encrypt_loop(u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	asm volatile (
+	"; set init. iv 4w			\n\t"
+	"	move.4 0x50(%0), 0x0(%3)	\n\t"
+	"	move.4 0x54(%0), 0x4(%3)	\n\t"
+	"	move.4 0x58(%0), 0x8(%3)	\n\t"
+	"	move.4 0x5c(%0), 0xc(%3)	\n\t"
+	"					\n\t"
+	"; we know n > 0, so we can always	\n\t"
+	"; load the first block			\n\t"
+	"; set input 4w				\n\t"
+	"	move.4 0x30(%0), 0x0(%2)	\n\t"
+	"	move.4 0x34(%0), 0x4(%2)	\n\t"
+	"	move.4 0x38(%0), 0x8(%2)	\n\t"
+	"	move.4 0x3c(%0), 0xc(%2)	\n\t"
+	"					\n\t"
+	"; kickoff hw				\n\t"
+	"	move.4 0x40(%0), %2		\n\t"
+	"					\n\t"
+	"; update n & flush			\n\t"
+	"	add.4 %4, #-16, %4		\n\t"
+	"	pipe_flush 0			\n\t"
+	"					\n\t"
+	"; while (n):  work on 2nd block	\n\t"
+	" 1:	lsl.4 d15, %4, #0x0		\n\t"
+	"	jmpeq.f 5f			\n\t"
+	"					\n\t"
+	"; set input 4w	(2nd)			\n\t"
+	"	move.4 0x30(%0), 0x10(%2)	\n\t"
+	"	move.4 0x34(%0), 0x14(%2)	\n\t"
+	"	move.4 0x38(%0), 0x18(%2)	\n\t"
+	"	move.4 0x3c(%0), 0x1c(%2)	\n\t"
+	"					\n\t"
+	"; update n/in asap while waiting	\n\t"
+	"	add.4 %4, #-16, %4		\n\t"
+	"	move.4 d15, 16(%2)++		\n\t"
+	"					\n\t"
+	"; wait for the previous output		\n\t"
+	"	btst 0x04(%0), #0		\n\t"
+	"	jmpne.f -4			\n\t"
+	"					\n\t"
+	"; read previous output			\n\t"
+	"	move.4 0x0(%1), 0x50(%0)	\n\t"
+	"	move.4 0x4(%1), 0x54(%0)	\n\t"
+	"	move.4 0x8(%1), 0x58(%0)	\n\t"
+	"	move.4 0xc(%1), 0x5c(%0)	\n\t"
+	"					\n\t"
+	"; kick off hw for 2nd input		\n\t"
+	"	move.4 0x40(%0), %2		\n\t"
+	"					\n\t"
+	"; update out asap			\n\t"
+	"	move.4 d15, 16(%1)++		\n\t"
+	"					\n\t"
+	"; go back to loop			\n\t"
+	"	jmpt 1b				\n\t"
+	"					\n\t"
+	"; wait for last output			\n\t" 
+	" 5:	btst 0x04(%0), #0               \n\t"
+        "       jmpne.f -4                      \n\t"
+        "                                       \n\t"
+	"; read last output			\n\t"
+	"	move.4 0x0(%1), 0x50(%0)	\n\t"
+	"	move.4 0x4(%1), 0x54(%0)	\n\t"
+	"	move.4 0x8(%1), 0x58(%0)	\n\t"
+	"	move.4 0xc(%1), 0x5c(%0)	\n\t"
+        "                                       \n\t"
+	"; copy out iv				\n\t"
+	"	move.4 0x0(%3), 0x50(%0)	\n\t"
+	"	move.4 0x4(%3), 0x54(%0)	\n\t"
+	"	move.4 0x8(%3), 0x58(%0)	\n\t"
+	"	move.4 0xc(%3), 0x5c(%0)	\n\t"
+        "                                       \n\t"
+		:
+		: "a" (SEC_BASE), "a" (out), "a" (in), "a" (iv), "d" (n)
+		: "d15", "cc"
+	);
+}
+
+#else
+
+static void __ocm_text cbc_aes_encrypt_loop(u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	aes_hw_set_iv(iv);
+	while (likely(n)) {
+		aes_hw_cipher(out, in);
+		out += AES_BLOCK_SIZE;
+		in += AES_BLOCK_SIZE;
+		n -= AES_BLOCK_SIZE;	
+	}
+	SEC_COPY_4W(iv, out - AES_BLOCK_SIZE);
+}
+
+#endif
+
+static void __ocm_text cbc_aes_decrypt_loop(u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+        while (likely(n)) {
+                aes_hw_set_iv(iv);
+		SEC_COPY_4W(iv, in);
+                aes_hw_cipher(out, in);
+                out += AES_BLOCK_SIZE;
+                in += AES_BLOCK_SIZE;
+                n -= AES_BLOCK_SIZE;
+        }
+}
+
+static int __ocm_text cbc_aes_crypt(struct blkcipher_desc *desc, 
+                           struct scatterlist *dst, struct scatterlist *src,
+                           unsigned int nbytes, u32 extra_flags)
+{
+	struct ubicom32_aes_ctx *uctx = crypto_blkcipher_ctx(desc->tfm);
+	int ret;
+
+        struct blkcipher_walk walk;
+        blkcipher_walk_init(&walk, dst, src, nbytes);
+	ret = blkcipher_walk_virt(desc, &walk);
+	if (unlikely(ret)) {
+		return ret;
+	}
+	
+        hw_crypto_lock();
+	hw_crypto_check();
+
+        hw_crypto_set_ctrl(uctx->ctrl | extra_flags);
+        aes_hw_set_key(uctx->key, uctx->key_len);
+
+	while (likely((nbytes = walk.nbytes))) {
+                /* only use complete blocks */
+                unsigned int n = nbytes & ~(AES_BLOCK_SIZE - 1);
+		if (likely(n)) {
+	                u8 *out = walk.dst.virt.addr;
+        	        u8 *in = walk.src.virt.addr;
+
+			if (extra_flags & SEC_DIR_ENCRYPT) {
+				cbc_aes_encrypt_loop(out, in, walk.iv, n);
+			} else {
+				cbc_aes_decrypt_loop(out, in, walk.iv, n);
+			}
+		}
+
+		nbytes &= AES_BLOCK_SIZE - 1;
+                ret = blkcipher_walk_done(desc, &walk, nbytes);
+	}
+	hw_crypto_unlock();
+
+	return ret;
+}
+
+static int __ocm_text cbc_aes_encrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return cbc_aes_crypt(desc, dst, src, nbytes, SEC_DIR_ENCRYPT | SEC_CBC_SET);
+}
+
+static int __ocm_text cbc_aes_decrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return cbc_aes_crypt(desc, dst, src, nbytes, SEC_DIR_DECRYPT | SEC_CBC_SET);
+}
+
+static struct crypto_alg cbc_aes_alg = {
+	.cra_name		=	"cbc(aes)",
+	.cra_driver_name	=	"cbc-aes-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER, 
+	.cra_blocksize		=	AES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_aes_ctx),
+	.cra_alignmask          =       CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(cbc_aes_alg.cra_list),
+	.cra_u			=	{
+		.blkcipher = {
+			.min_keysize		=	AES_MIN_KEY_SIZE,
+			.max_keysize		=	AES_MAX_KEY_SIZE,
+			.ivsize			=	AES_BLOCK_SIZE,
+			.setkey			=	aes_set_key,
+			.encrypt		=	cbc_aes_encrypt,
+			.decrypt		=	cbc_aes_decrypt,
+		}
+	}
+};
+
+static int __init aes_init(void)
+{
+	int ret;
+
+	hw_crypto_init();
+
+	ret = crypto_register_alg(&aes_alg);
+	if (ret)
+		goto aes_err;
+
+	ret = crypto_register_alg(&ecb_aes_alg);
+	if (ret)
+		goto ecb_aes_err;
+
+	ret = crypto_register_alg(&cbc_aes_alg);
+	if (ret)
+		goto cbc_aes_err;
+
+out:
+	return ret;
+
+cbc_aes_err:
+	crypto_unregister_alg(&ecb_aes_alg);
+ecb_aes_err:
+	crypto_unregister_alg(&aes_alg);
+aes_err:
+	goto out;
+}
+
+static void __exit aes_fini(void)
+{
+	crypto_unregister_alg(&cbc_aes_alg);
+	crypto_unregister_alg(&ecb_aes_alg);
+	crypto_unregister_alg(&aes_alg);
+}
+
+module_init(aes_init);
+module_exit(aes_fini);
+
+MODULE_ALIAS("aes");
+
+MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/arch/ubicom32/crypto/crypto_des.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/crypto/crypto_des.h
+ *   Function for checking keys for the DES and Triple DES Encryption
+ *   algorithms.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef __CRYPTO_DES_H__
+#define __CRYPTO_DES_H__
+
+extern int crypto_des_check_key(const u8*, unsigned int, u32*);
+
+#endif /* __CRYPTO_DES_H__ */
--- /dev/null
+++ b/arch/ubicom32/crypto/crypto_ubicom32.c
@@ -0,0 +1,50 @@
+/*
+ * arch/ubicom32/crypto/crypto_ubicom32.c
+ *   Generic code to support ubicom32 hardware crypto accelerator
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include "crypto_ubicom32.h"
+
+spinlock_t crypto_ubicom32_lock;
+bool crypto_ubicom32_inited = false;
+volatile bool crypto_ubicom32_on = false;
+volatile unsigned long crypto_ubicom32_last_use;
+
+struct timer_list crypto_ubicom32_ps_timer;
+void crypto_ubicom32_ps_check(unsigned long data)
+{
+	unsigned long idle_time = msecs_to_jiffies(HW_CRYPTO_PS_MAX_IDLE_MS);
+
+	BUG_ON(!crypto_ubicom32_on);
+
+	if (((jiffies - crypto_ubicom32_last_use) > idle_time) && spin_trylock_bh(&crypto_ubicom32_lock)) {
+                hw_crypto_turn_off();
+                spin_unlock_bh(&crypto_ubicom32_lock);
+		return;
+	}
+
+	/* keep monitoring */
+	hw_crypto_ps_start();
+}
--- /dev/null
+++ b/arch/ubicom32/crypto/crypto_ubicom32.h
@@ -0,0 +1,346 @@
+/*
+ * arch/ubicom32/crypto/crypto_ubicom32.h
+ *   Support for Ubicom32 cryptographic instructions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _CRYPTO_ARCH_UBICOM32_CRYPT_H
+#define _CRYPTO_ARCH_UBICOM32_CRYPT_H
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/jiffies.h>
+#include <linux/timer.h>
+#include <linux/spinlock.h>
+#include <asm/errno.h>
+#include <asm/io.h>
+#include <asm/ip5000.h>
+
+#define CRYPTO_UBICOM32_LOOP_ASM 1
+#define CRYPTO_UBICOM32_ALIGNMENT 4
+#define SEC_ALIGNED(p) (((u32)p & 3) == 0)
+
+#define SEC_BASE		SECURITY_BASE
+#define SEC_KEY_OFFSET		SECURITY_KEY_VALUE(0)
+#define SEC_INPUT_OFFSET	SECURITY_KEY_IN(0)
+#define SEC_OUTPUT_OFFSET	SECURITY_KEY_OUT(0)
+#define SEC_HASH_OFFSET		SECURITY_KEY_HASH(0)
+
+#define SEC_KEY_128_BITS	SECURITY_CTRL_KEY_SIZE(0)
+#define SEC_KEY_192_BITS	SECURITY_CTRL_KEY_SIZE(1)
+#define SEC_KEY_256_BITS	SECURITY_CTRL_KEY_SIZE(2)
+
+#define SEC_HASH_NONE		SECURITY_CTRL_HASH_ALG_NONE
+#define SEC_HASH_MD5		SECURITY_CTRL_HASH_ALG_MD5
+#define SEC_HASH_SHA1		SECURITY_CTRL_HASH_ALG_SHA1
+
+#define SEC_CBC_SET		SECURITY_CTRL_CBC
+#define SEC_CBC_NONE		0
+
+#define SEC_ALG_AES		SECURITY_CTRL_CIPHER_ALG_AES
+#define SEC_ALG_NONE		SECURITY_CTRL_CIPHER_ALG_NONE
+#define SEC_ALG_DES		SECURITY_CTRL_CIPHER_ALG_DES
+#define SEC_ALG_3DES		SECURITY_CTRL_CIPHER_ALG_3DES
+
+#define SEC_DIR_ENCRYPT		SECURITY_CTRL_ENCIPHER
+#define SEC_DIR_DECRYPT		0
+
+#define CRYPTO_UBICOM32_PRIORITY 300
+#define CRYPTO_UBICOM32_COMPOSITE_PRIORITY 400
+
+#define HW_CRYPTO_PS_MAX_IDLE_MS 100    /* idle time (ms) before shuting down sm */
+
+extern spinlock_t crypto_ubicom32_lock;
+extern bool crypto_ubicom32_inited;
+extern volatile bool crypto_ubicom32_on;
+extern volatile unsigned long crypto_ubicom32_last_use;
+extern struct timer_list crypto_ubicom32_ps_timer;
+extern void crypto_ubicom32_ps_check(unsigned long data);
+
+#define SEC_COPY_2W(t, s)				\
+	asm volatile (					\
+	"	move.4 0(%0), 0(%1)		\n\t"	\
+	"	move.4 4(%0), 4(%1)		\n\t"	\
+							\
+		:					\
+		: "a" (t), "a" (s)			\
+	)
+
+#define SEC_COPY_4W(t, s)				\
+	asm volatile (					\
+	"	move.4 0(%0), 0(%1)		\n\t"	\
+	"	move.4 4(%0), 4(%1)		\n\t"	\
+	"	move.4 8(%0), 8(%1)		\n\t"	\
+	"	move.4 12(%0), 12(%1)		\n\t"	\
+		:					\
+		: "a" (t), "a" (s)			\
+	)
+
+#define SEC_COPY_5W(t, s)				\
+	asm volatile (					\
+	"	move.4 0(%0), 0(%1)		\n\t"	\
+	"	move.4 4(%0), 4(%1)		\n\t"	\
+	"	move.4 8(%0), 8(%1)		\n\t"	\
+	"	move.4 12(%0), 12(%1)		\n\t"	\
+	"	move.4 16(%0), 16(%1)		\n\t"	\
+		:					\
+		: "a" (t), "a" (s)			\
+	)
+
+#define SEC_SET_KEY_2W(x)				\
+	asm volatile (					\
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x10(%0), 0(%1)		\n\t"	\
+	"	move.4 0x14(%0), 4(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_SET_KEY_4W(x) \
+	asm volatile ( \
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x10(%0), 0(%1)		\n\t"	\
+	"	move.4 0x14(%0), 4(%1)		\n\t"	\
+	"	move.4 0x18(%0), 8(%1)		\n\t"	\
+	"	move.4 0x1c(%0), 12(%1)		\n\t"	\
+		:					\
+		: "a"(SECURITY_BASE), "a"(x)		\
+	)
+
+#define SEC_SET_KEY_6W(x)				\
+	asm volatile (					\
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x10(%0), 0(%1)		\n\t"	\
+	"	move.4 0x14(%0), 4(%1)		\n\t"	\
+	"	move.4 0x18(%0), 8(%1)		\n\t"	\
+	"	move.4 0x1c(%0), 12(%1)		\n\t"	\
+	"	move.4 0x20(%0), 16(%1)		\n\t"	\
+	"	move.4 0x24(%0), 20(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_SET_KEY_8W(x)				\
+	asm volatile (					\
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x10(%0), 0(%1)		\n\t"	\
+	"	move.4 0x14(%0), 4(%1)		\n\t"	\
+	"	move.4 0x18(%0), 8(%1)		\n\t"	\
+	"	move.4 0x1c(%0), 12(%1)		\n\t"	\
+	"	move.4 0x20(%0), 16(%1)		\n\t"	\
+	"	move.4 0x24(%0), 20(%1)		\n\t"	\
+	"	move.4 0x28(%0), 24(%1)		\n\t"	\
+	"	move.4 0x2c(%0), 28(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_SET_KEY_64(k)	SEC_SET_KEY_2W(k)
+#define SEC_SET_KEY_128(k)	SEC_SET_KEY_4W(k)
+#define SEC_SET_KEY_192(k)	SEC_SET_KEY_6W(k)
+#define SEC_SET_KEY_256(k)	SEC_SET_KEY_8W(k)
+
+#define DES_SET_KEY(x) 		SEC_SET_KEY_64(x) 
+#define DES3_SET_KEY(x) 	SEC_SET_KEY_192(x)
+
+#define SEC_SET_INPUT_2W(x)				\
+	asm volatile (					\
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x30(%0), 0(%1)		\n\t"	\
+	"	move.4 0x34(%0), 4(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_GET_OUTPUT_2W(x)				\
+	asm volatile (					\
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0(%1), 0x50(%0)		\n\t"	\
+	"	move.4 4(%1), 0x54(%0)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_SET_INPUT_4W(x) \
+	asm volatile ( \
+	"	; write key to Security Keyblock \n\t"	\
+	"	move.4 0x30(%0), 0(%1)		\n\t"	\
+	"	move.4 0x34(%0), 4(%1)		\n\t"	\
+	"	move.4 0x38(%0), 8(%1)		\n\t"	\
+	"	move.4 0x3c(%0), 12(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_GET_OUTPUT_4W(x)				\
+	asm volatile (					\
+	"	; read output from Security Keyblock \n\t" \
+	"	move.4 0(%1), 0x50(%0)		\n\t"	\
+	"	move.4 4(%1), 0x54(%0)		\n\t"	\
+	"	move.4 8(%1), 0x58(%0)		\n\t"	\
+	"	move.4 12(%1), 0x5c(%0)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_SET_IV_4W(x)				\
+	asm volatile (					\
+	"	; write IV to Security Keyblock  \n\t"	\
+	"	move.4 0x50(%0), 0(%1)		\n\t"	\
+	"	move.4 0x54(%0), 4(%1)		\n\t"	\
+	"	move.4 0x58(%0), 8(%1)		\n\t"	\
+	"	move.4 0x5c(%0), 12(%1)		\n\t"	\
+		:					\
+		: "a" (SECURITY_BASE), "a" (x)		\
+	)
+
+#define SEC_PIPE_FLUSH() asm volatile ( " pipe_flush 0 \n\t" )
+
+static inline void hw_crypto_set_ctrl(uint32_t c)
+{
+	asm volatile ( 					
+	"	move.4	0(%0), %1		\n\t"	
+		:					
+		: "a" (SECURITY_BASE + SECURITY_CTRL), "d" (c)	
+	);
+}
+
+static inline void hw_crypto_ps_start(void)
+{
+	crypto_ubicom32_ps_timer.expires = jiffies + msecs_to_jiffies(HW_CRYPTO_PS_MAX_IDLE_MS >> 1);
+	add_timer(&crypto_ubicom32_ps_timer);
+}
+
+static inline void hw_crypto_turn_on(void)
+{
+	asm volatile (				  
+	"	moveai  A4, %0			\n\t" 
+	"	bset    0x0(A4), 0x0(A4), %1	\n\t"
+	"	cycles 11			\n\t" 
+		:						
+		: "i" (OCP_BASE >> 7), "i" (GEN_CLK_PLL_SECURITY_BIT_NO) 
+		: "a4", "cc"
+	);
+	crypto_ubicom32_on = true;
+}
+
+static inline void hw_crypto_turn_off(void)
+{
+	asm volatile (				  
+	"	moveai  A4, %0			\n\t" 
+	"	bclr    0x0(A4), 0x0(A4), %1	\n\t" 
+		:						
+		: "i" (OCP_BASE >> 7), "i" (GEN_CLK_PLL_SECURITY_BIT_NO)    
+		: "a4", "cc"
+	);
+	crypto_ubicom32_on = false;
+}
+
+/*
+ * hw_crypto_check
+ * 	Most probably hw crypto is called in clusters and it makes no sense to turn it off
+ * 	and on and waster 13 cycles every time.
+ */
+static inline void hw_crypto_check(void)
+{
+	if (likely(crypto_ubicom32_on)) {
+		return;
+	}
+	crypto_ubicom32_last_use = jiffies;
+	hw_crypto_turn_on();
+	hw_crypto_ps_start();
+}
+
+/*
+ * hw_crypto_ps_init
+ * 	Init power save timer
+ */
+static inline void hw_crypto_ps_init(void)
+{
+	init_timer_deferrable(&crypto_ubicom32_ps_timer);
+	crypto_ubicom32_ps_timer.function = crypto_ubicom32_ps_check;
+	crypto_ubicom32_ps_timer.data = 0;
+}
+
+/*
+ * hw_crypto_init()
+ *      Initialize OCP security module lock and disables its clock.
+ */
+static inline void hw_crypto_init(void)
+{
+	if (!crypto_ubicom32_inited) {
+		crypto_ubicom32_inited = true;
+		spin_lock_init(&crypto_ubicom32_lock);
+		hw_crypto_ps_init();
+		hw_crypto_turn_off();
+	}
+}
+
+/*
+ * hw_crypto_lock()
+ *      Locks the OCP security module and enables its clock.
+ */
+static inline void hw_crypto_lock(void)
+{
+	spin_lock_bh(&crypto_ubicom32_lock);
+}
+
+/*
+ * hw_crypto_unlock()
+ *      Unlocks the OCP security module and disables its clock.
+ */
+static inline void hw_crypto_unlock(void)
+{
+	crypto_ubicom32_last_use = jiffies;
+	spin_unlock_bh(&crypto_ubicom32_lock);
+}
+
+#define CONFIG_CRYPTO_UBICOM32_DEBUG 1
+
+#ifdef CONFIG_CRYPTO_UBICOM32_DEBUG
+static inline void hex_dump(void *buf, int b_size, const char *msg)
+{
+	u8 *b = (u8 *)buf;
+	int i;
+	if (msg) {
+		printk("%s:\t", msg);
+	}
+
+	for (i=0; i < b_size; i++) {
+		printk("%02x ", b[i]);
+		if ((i & 3) == 3) {
+			printk(" ");
+		}
+		if ((i & 31) == 31) {
+			printk("\n");
+		}
+	}
+	printk("\n");
+}
+#define UBICOM32_SEC_DUMP(a, b, c) hex_dump(a, b, c)
+#else
+#define UBICOM32_SEC_DUMP(a, b, c)
+#endif
+
+#endif	/* _CRYPTO_ARCH_UBICOM32_CRYPT_H */
--- /dev/null
+++ b/arch/ubicom32/crypto/des_check_key.c
@@ -0,0 +1,148 @@
+/*
+ * arch/ubicom32/crypto/des_check_key.c
+ *   Ubicom32 architecture function for checking keys for the DES and
+ *   Tripple DES Encryption algorithms.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * Originally released as descore by Dana L. How <how@isl.stanford.edu>.
+ * Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel.
+ * Derived from Cryptoapi and Nettle implementations, adapted for in-place
+ * scatterlist interface.  Changed LGPL to GPL per section 3 of the LGPL.
+ *
+ * s390 Version:
+ *   Copyright IBM Corp. 2003
+ *   Author(s): Thomas Spatzier
+ *		Jan Glauber (jan.glauber@de.ibm.com)
+ *
+ * Derived from "crypto/des.c"
+ *   Copyright (c) 1992 Dana L. How.
+ *   Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de>
+ *   Copyright (c) Gisle Sflensminde <gisle@ii.uib.no>
+ *   Copyright (C) 2001 Niels Mvller.
+ *   Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/crypto.h>
+#include "crypto_des.h"
+
+#define ROR(d,c,o)	((d) = (d) >> (c) | (d) << (o))
+
+static const u8 parity[] = {
+	8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3,
+	0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
+	0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
+	8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
+	0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
+	8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
+	8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
+	4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8,
+};
+
+/*
+ * RFC2451: Weak key checks SHOULD be performed.
+ */
+int
+crypto_des_check_key(const u8 *key, unsigned int keylen, u32 *flags)
+{
+	u32 n, w;
+
+	n  = parity[key[0]]; n <<= 4;
+	n |= parity[key[1]]; n <<= 4;
+	n |= parity[key[2]]; n <<= 4;
+	n |= parity[key[3]]; n <<= 4;
+	n |= parity[key[4]]; n <<= 4;
+	n |= parity[key[5]]; n <<= 4;
+	n |= parity[key[6]]; n <<= 4;
+	n |= parity[key[7]];
+	w = 0x88888888L;
+
+	if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY)
+	    && !((n - (w >> 3)) & w)) {  /* 1 in 10^10 keys passes this test */
+		if (n < 0x41415151) {
+			if (n < 0x31312121) {
+				if (n < 0x14141515) {
+					/* 01 01 01 01 01 01 01 01 */
+					if (n == 0x11111111) goto weak;
+					/* 01 1F 01 1F 01 0E 01 0E */
+					if (n == 0x13131212) goto weak;
+				} else {
+					/* 01 E0 01 E0 01 F1 01 F1 */
+					if (n == 0x14141515) goto weak;
+					/* 01 FE 01 FE 01 FE 01 FE */
+					if (n == 0x16161616) goto weak;
+				}
+			} else {
+				if (n < 0x34342525) {
+					/* 1F 01 1F 01 0E 01 0E 01 */
+					if (n == 0x31312121) goto weak;
+					/* 1F 1F 1F 1F 0E 0E 0E 0E (?) */
+					if (n == 0x33332222) goto weak;
+				} else {
+					/* 1F E0 1F E0 0E F1 0E F1 */
+					if (n == 0x34342525) goto weak;
+					/* 1F FE 1F FE 0E FE 0E FE */
+					if (n == 0x36362626) goto weak;
+				}
+			}
+		} else {
+			if (n < 0x61616161) {
+				if (n < 0x44445555) {
+					/* E0 01 E0 01 F1 01 F1 01 */
+					if (n == 0x41415151) goto weak;
+					/* E0 1F E0 1F F1 0E F1 0E */
+					if (n == 0x43435252) goto weak;
+				} else {
+					/* E0 E0 E0 E0 F1 F1 F1 F1 (?) */
+					if (n == 0x44445555) goto weak;
+					/* E0 FE E0 FE F1 FE F1 FE */
+					if (n == 0x46465656) goto weak;
+				}
+			} else {
+				if (n < 0x64646565) {
+					/* FE 01 FE 01 FE 01 FE 01 */
+					if (n == 0x61616161) goto weak;
+					/* FE 1F FE 1F FE 0E FE 0E */
+					if (n == 0x63636262) goto weak;
+				} else {
+					/* FE E0 FE E0 FE F1 FE F1 */
+					if (n == 0x64646565) goto weak;
+					/* FE FE FE FE FE FE FE FE */
+					if (n == 0x66666666) goto weak;
+				}
+			}
+		}
+	}
+	return 0;
+weak:
+	*flags |= CRYPTO_TFM_RES_WEAK_KEY;
+	return -EINVAL;
+}
+
+EXPORT_SYMBOL(crypto_des_check_key);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Key Check function for DES &  DES3 Cipher Algorithms");
--- /dev/null
+++ b/arch/ubicom32/crypto/des_ubicom32.c
@@ -0,0 +1,761 @@
+/*
+ * arch/ubicom32/crypto/des_ubicom32.c
+ *   Ubicom32 implementation of the DES Cipher Algorithm.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <crypto/algapi.h>
+#include <linux/init.h>
+#include <linux/module.h>
+
+#include "crypto_ubicom32.h"
+extern int crypto_des_check_key(const u8 *key, unsigned int keylen, u32 *flags);
+
+#define DES_BLOCK_SIZE 8
+#define DES_KEY_SIZE 8
+
+#define DES3_192_KEY_SIZE	(3 * DES_KEY_SIZE)
+#define DES3_192_BLOCK_SIZE	DES_BLOCK_SIZE
+
+#define DES3_SUB_KEY(key, i) 	(((u8 *)key) + (i * DES_KEY_SIZE))
+
+enum des_ops {
+	DES_ENCRYPT,
+	DES_DECRYPT,
+
+	DES3_EDE_ENCRYPT,
+	DES3_EDE_DECRYPT,
+
+#ifdef DES3_EEE
+	DES3_EEE_ENCRYPT,
+	DES3_EEE_DECRYPT,
+#endif
+};
+
+struct ubicom32_des_ctx {
+	u8 key[3 * DES_KEY_SIZE];
+	u32 ctrl;
+	int key_len;
+};
+
+static inline void des_hw_set_key(const u8 *key, u8 key_len)
+{
+	/*
+	 * HW 3DES is not tested yet, use DES just as ipOS
+	 */
+	DES_SET_KEY(key);
+}
+
+static inline void des_hw_cipher(u8 *out, const u8 *in)
+{
+	SEC_SET_INPUT_2W(in);
+
+	asm volatile (
+	"	; start DES by writing 0x38(SECURITY_BASE)	\n\t" 
+	"	move.4 0x38(%0), #0x01				\n\t" 
+	"	pipe_flush 0					\n\t" 
+	"							\n\t" 
+	"	; wait for the module to calculate the output	\n\t" 
+	"	btst 0x04(%0), #0				\n\t" 
+	"	jmpne.f .-4					\n\t" 
+		:
+		: "a" (SEC_BASE)
+		: "cc"
+	);
+	
+	SEC_GET_OUTPUT_2W(out);
+}
+
+
+static void inline des3_hw_ede_encrypt(u8 *keys, u8 *out, const u8 *in)
+{
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 0), DES_KEY_SIZE);
+	des_hw_cipher(out, in);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 1), DES_KEY_SIZE);
+	des_hw_cipher(out, out);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 2), DES_KEY_SIZE);
+	des_hw_cipher(out, out);
+}
+
+static void inline des3_hw_ede_decrypt(u8 *keys, u8 *out, const u8 *in)
+{
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 2), DES_KEY_SIZE);
+	des_hw_cipher(out, in);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 1), DES_KEY_SIZE);
+	des_hw_cipher(out, out);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 0), DES_KEY_SIZE);
+	des_hw_cipher(out, out);
+}
+
+#ifdef DES3_EEE
+static void inline des3_hw_eee_encrypt(u8 *keys, u8 *out, const u8 *in)
+{
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 0), 2);
+	des_hw_cipher(out, in);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 1), 2);
+	des_hw_cipher(out, out);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 2), 2);
+	des_hw_cipher(out, out);
+}
+
+static void inline des3_hw_eee_decrypt(u8 *keys, u8 *out, const u8 *in)
+{
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 2), 2);
+	des_hw_cipher(out, in);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 1), 2);
+	des_hw_cipher(out, out);
+
+	hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+	des_hw_set_key(DES3_SUB_KEY(keys, 0), 2);
+	des_hw_cipher(out, out);
+}
+#endif
+
+static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
+		      unsigned int keylen)
+{
+	struct ubicom32_des_ctx *dctx = crypto_tfm_ctx(tfm);
+	u32 *flags = &tfm->crt_flags;
+	int ret;
+
+	/* test if key is valid (not a weak key) */
+	ret = crypto_des_check_key(key, keylen, flags);
+	if (ret == 0) {
+		memcpy(dctx->key, key, keylen);
+		dctx->key_len = keylen;
+		//dctx->ctrl = (keylen == DES_KEY_SIZE) ? SEC_ALG_DES : SEC_ALG_3DES
+		/* 2DES and 3DES are both implemented with DES hw function */
+		dctx->ctrl = SEC_ALG_DES;
+	}
+	return ret;
+}
+
+static inline void des_cipher_1b(struct crypto_tfm *tfm, u8 *out, const u8 *in, u32 extra_flags)
+{
+	const struct ubicom32_des_ctx *uctx = crypto_tfm_ctx(tfm);
+
+	hw_crypto_lock();
+	hw_crypto_check();
+	hw_crypto_set_ctrl(uctx->ctrl | extra_flags);
+
+	des_hw_set_key(uctx->key, uctx->key_len);
+	des_hw_cipher(out, in);
+
+	hw_crypto_unlock();	
+}
+
+static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+{
+	des_cipher_1b(tfm, out, in, SEC_DIR_ENCRYPT);
+}
+
+static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+{
+	des_cipher_1b(tfm, out, in, SEC_DIR_DECRYPT);
+}
+
+static struct crypto_alg des_alg = {
+	.cra_name		=	"des",
+	.cra_driver_name	=	"des-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
+	.cra_blocksize		=	DES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(des_alg.cra_list),
+	.cra_u			= {
+		.cipher = {
+			.cia_min_keysize	=	DES_KEY_SIZE,
+			.cia_max_keysize	=	DES_KEY_SIZE,
+			.cia_setkey		=	des_setkey,
+			.cia_encrypt		=	des_encrypt,
+			.cia_decrypt		=	des_decrypt,
+		}
+	}
+};
+
+static void ecb_des_ciper_loop(u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		des_hw_cipher(out, in);
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void ecb_des3_ede_encrypt_loop(u8 *keys, u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		des3_hw_ede_encrypt(keys, out, in);
+		
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void ecb_des3_ede_decrypt_loop(u8 *keys, u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		des3_hw_ede_decrypt(keys, out, in);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+#ifdef DES3_EEE
+static void ecb_des3_eee_encrypt_loop(u8 *keys, u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		des3_hw_eee_encrypt(keys, out, in);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void ecb_des3_eee_decrypt_loop(u8 *keys, u8 *out, u8 *in, unsigned int n)
+{
+	while (likely(n)) {
+		des3_hw_eee_decrypt(keys, out, in);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+#endif
+
+static inline void ecb_des_cipher_n(struct ubicom32_des_ctx *uctx, enum des_ops op, u8 *out, u8 *in, unsigned int n)
+{
+	switch (op) {
+	case DES_ENCRYPT:
+	case DES_DECRYPT:
+		/* set the right algo, direction and key once */
+		hw_crypto_set_ctrl(SEC_ALG_DES | (op == DES_ENCRYPT ? SEC_DIR_ENCRYPT : 0));
+		des_hw_set_key(uctx->key, uctx->key_len);
+		ecb_des_ciper_loop(out, in, n);
+		break;
+
+	case DES3_EDE_ENCRYPT:
+		ecb_des3_ede_encrypt_loop(uctx->key, out, in, n);
+		break;
+
+	case DES3_EDE_DECRYPT:
+		ecb_des3_ede_decrypt_loop(uctx->key, out, in, n);
+		break;
+
+#ifdef DES3_EEE
+	case DES3_EEE_ENCRYPT:
+		ecb_des3_eee_encrypt_loop(uctx->key, out, in, n);
+		break;
+
+	case DES3_EEE_DECRYPT:
+		ecb_des3_eee_decrypt_loop(uctx->key, out, in, n);
+		break;
+#endif
+	}
+}
+
+static inline void des_xor_2w(u32 *data, u32 *iv)
+{
+	data[0] ^= iv[0];
+	data[1] ^= iv[1];
+}
+
+static void cbc_des_encrypt_loop(u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	while (likely(n)) {
+		des_xor_2w((u32 *)in, (u32 *)iv);
+		des_hw_cipher(out, in);
+		SEC_COPY_2W(iv, out);
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void cbc_des_decrypt_loop(u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	u8 next_iv[DES_BLOCK_SIZE];
+	while (likely(n)) {
+		SEC_COPY_2W(next_iv, in);
+		des_hw_cipher(out, in);
+		des_xor_2w((u32 *)out, (u32 *)iv);
+		SEC_COPY_2W(iv, next_iv);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void cbc_des3_ede_encrypt_loop(u8 *keys, u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	while (likely(n)) {
+		des_xor_2w((u32 *)in, (u32 *)iv);
+		des3_hw_ede_encrypt(keys, out, in);
+		SEC_COPY_2W(iv, out);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void cbc_des3_ede_decrypt_loop(u8 *keys, u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	u8 next_iv[DES_BLOCK_SIZE];
+	while (likely(n)) {
+		SEC_COPY_2W(next_iv, in);
+		des3_hw_ede_decrypt(keys, out, in);
+		des_xor_2w((u32 *)out, (u32 *)iv);
+		SEC_COPY_2W(iv, next_iv);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+#ifdef DES3_EEE
+static void cbc_des3_eee_encrypt_loop(u8 *keys, u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	while (likely(n)) {
+		des_xor_2w((u32 *)in, (u32 *)iv);
+		des3_hw_eee_encrypt(keys, out, in);
+		SEC_COPY_2W(iv, out);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+
+static void cbc_des3_eee_decrypt_loop(u8 *keys, u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	u8 next_iv[DES_BLOCK_SIZE];
+	while (likely(n)) {
+		SEC_COPY_2W(next_iv, in);
+		des3_hw_eee_decrypt(keys, out, in);
+		des_xor_2w((u32 *)out, (u32 *)iv);
+		SEC_COPY_2W(iv, next_iv);
+
+		out += DES_BLOCK_SIZE;
+		in += DES_BLOCK_SIZE;
+		n -= DES_BLOCK_SIZE;
+	}
+}
+#endif
+
+static inline void cbc_des_cipher_n(struct ubicom32_des_ctx *uctx, enum des_ops op, u8 *out, u8 *in, u8 *iv, unsigned int n)
+{
+	switch (op) {
+	case DES_ENCRYPT:
+		hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_ENCRYPT);
+		des_hw_set_key(uctx->key, uctx->key_len);
+		cbc_des_encrypt_loop(out, in, iv, n);
+		break;
+		
+	case DES_DECRYPT:
+		/* set the right algo, direction and key once */
+		hw_crypto_set_ctrl(SEC_ALG_DES | SEC_DIR_DECRYPT);
+		des_hw_set_key(uctx->key, uctx->key_len);
+		cbc_des_decrypt_loop(out, in, iv, n);
+		break;
+
+	case DES3_EDE_ENCRYPT:
+		cbc_des3_ede_encrypt_loop(uctx->key, out, in, iv, n);
+		break;
+
+	case DES3_EDE_DECRYPT:
+		cbc_des3_ede_decrypt_loop(uctx->key, out, in, iv, n);
+		break;
+
+#ifdef DES3_EEE
+	case DES3_EEE_ENCRYPT:
+		cbc_des3_eee_encrypt_loop(uctx->key, out, in, iv, n);
+		break;
+
+	case DES3_EEE_DECRYPT:
+		cbc_des3_eee_decrypt_loop(uctx->key, out, in, iv, n);
+		break;
+#endif
+	}
+}
+
+static int des_cipher(struct blkcipher_desc *desc, struct scatterlist *dst, 
+		      struct scatterlist *src, unsigned int nbytes, u32 extra_flags, enum des_ops op)
+{
+	struct ubicom32_des_ctx *uctx = crypto_blkcipher_ctx(desc->tfm);
+	int ret;
+	
+	struct blkcipher_walk walk;
+	blkcipher_walk_init(&walk, dst, src, nbytes);
+	ret = blkcipher_walk_virt(desc, &walk);
+	if (ret) {
+		return ret;
+	}
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+	while ((nbytes = walk.nbytes)) {
+		/* only use complete blocks */
+		unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1);
+		u8 *out = walk.dst.virt.addr;
+		u8 *in = walk.src.virt.addr;
+
+		/* finish n/16 blocks */
+		if (extra_flags & SEC_CBC_SET) {
+			cbc_des_cipher_n(uctx, op, out, in, walk.iv, n);
+		} else {
+			ecb_des_cipher_n(uctx, op, out, in, n);
+		}
+
+		nbytes &= DES_BLOCK_SIZE - 1;
+		ret = blkcipher_walk_done(desc, &walk, nbytes);
+	}
+
+	hw_crypto_unlock();
+	return ret;
+}
+
+static int ecb_des_encrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_NONE, DES_ENCRYPT);
+}
+
+static int ecb_des_decrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_NONE, DES_DECRYPT);
+}
+
+static struct crypto_alg ecb_des_alg = {
+	.cra_name		=	"ecb(des)",
+	.cra_driver_name	=	"ecb-des-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER,
+	.cra_blocksize		=	DES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(ecb_des_alg.cra_list),
+	.cra_u			= {
+		.blkcipher = {
+			.min_keysize		=	DES_KEY_SIZE,
+			.max_keysize		=	DES_KEY_SIZE,
+			.setkey			=	des_setkey,
+			.encrypt		=	ecb_des_encrypt,
+			.decrypt		=	ecb_des_decrypt,
+		}
+	}
+};
+
+static int cbc_des_encrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_SET, DES_ENCRYPT);
+}
+
+static int cbc_des_decrypt(struct blkcipher_desc *desc,
+			   struct scatterlist *dst, struct scatterlist *src,
+			   unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_SET, DES_DECRYPT);
+}
+
+static struct crypto_alg cbc_des_alg = {
+	.cra_name		=	"cbc(des)",
+	.cra_driver_name	=	"cbc-des-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER,
+	.cra_blocksize		=	DES_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(cbc_des_alg.cra_list),
+	.cra_u			= {
+		.blkcipher = {
+			.min_keysize		=	DES_KEY_SIZE,
+			.max_keysize		=	DES_KEY_SIZE,
+			.ivsize			=	DES_BLOCK_SIZE,
+			.setkey			=	des_setkey,
+			.encrypt		=	cbc_des_encrypt,
+			.decrypt		=	cbc_des_decrypt,
+		}
+	}
+};
+
+/*
+ * RFC2451:
+ *
+ *   For DES-EDE3, there is no known need to reject weak or
+ *   complementation keys.  Any weakness is obviated by the use of
+ *   multiple keys.
+ *
+ *   However, if the first two or last two independent 64-bit keys are
+ *   equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
+ *   same as DES.  Implementers MUST reject keys that exhibit this
+ *   property.
+ *
+ */
+static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
+			   unsigned int keylen)
+{
+	int i, ret;
+	struct ubicom32_des_ctx *dctx = crypto_tfm_ctx(tfm);
+	const u8 *temp_key = key;
+	u32 *flags = &tfm->crt_flags;
+
+	if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
+	    memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
+		   DES_KEY_SIZE))) {
+
+		*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
+		return -EINVAL;
+	}
+	for (i = 0; i < 3; i++, temp_key += DES_KEY_SIZE) {
+		ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags);
+		if (ret < 0)
+			return ret;
+	}
+	memcpy(dctx->key, key, keylen);
+	dctx->ctrl = SEC_ALG_DES;	//hw 3DES not working yet
+	dctx->key_len = keylen;
+	return 0;
+}
+
+static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+	struct ubicom32_des_ctx *uctx = crypto_tfm_ctx(tfm);
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+	des3_hw_ede_encrypt(uctx->key, dst, src);
+
+	hw_crypto_unlock();	
+}
+
+static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+	struct ubicom32_des_ctx *uctx = crypto_tfm_ctx(tfm);
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+	des3_hw_ede_decrypt(uctx->key, dst, src);
+
+	hw_crypto_unlock();	
+}
+
+static struct crypto_alg des3_192_alg = {
+	.cra_name		=	"des3_ede",
+	.cra_driver_name	=	"des3_ede-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
+	.cra_blocksize		=	DES3_192_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(des3_192_alg.cra_list),
+	.cra_u			= {
+		.cipher = {
+			.cia_min_keysize	=	DES3_192_KEY_SIZE,
+			.cia_max_keysize	=	DES3_192_KEY_SIZE,
+			.cia_setkey		=	des3_192_setkey,
+			.cia_encrypt		=	des3_192_encrypt,
+			.cia_decrypt		=	des3_192_decrypt,
+		}
+	}
+};
+
+static int ecb_des3_192_encrypt(struct blkcipher_desc *desc,
+				struct scatterlist *dst,
+				struct scatterlist *src, unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_NONE, DES3_EDE_ENCRYPT);
+}
+
+static int ecb_des3_192_decrypt(struct blkcipher_desc *desc,
+				struct scatterlist *dst,
+				struct scatterlist *src, unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_NONE, DES3_EDE_DECRYPT);
+}
+
+static struct crypto_alg ecb_des3_192_alg = {
+	.cra_name		=	"ecb(des3_ede)",
+	.cra_driver_name	=	"ecb-des3_ede-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER,
+	.cra_blocksize		=	DES3_192_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(
+						ecb_des3_192_alg.cra_list),
+	.cra_u			= {
+		.blkcipher = {
+			.min_keysize		=	DES3_192_KEY_SIZE,
+			.max_keysize		=	DES3_192_KEY_SIZE,
+			.setkey			=	des3_192_setkey,
+			.encrypt		=	ecb_des3_192_encrypt,
+			.decrypt		=	ecb_des3_192_decrypt,
+		}
+	}
+};
+
+static int cbc_des3_192_encrypt(struct blkcipher_desc *desc,
+				struct scatterlist *dst,
+				struct scatterlist *src, unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_SET, DES3_EDE_ENCRYPT);
+}
+
+static int cbc_des3_192_decrypt(struct blkcipher_desc *desc,
+				struct scatterlist *dst,
+				struct scatterlist *src, unsigned int nbytes)
+{
+	return des_cipher(desc, dst, src, nbytes, SEC_CBC_SET, DES3_EDE_DECRYPT);
+}
+
+static struct crypto_alg cbc_des3_192_alg = {
+	.cra_name		=	"cbc(des3_ede)",
+	.cra_driver_name	=	"cbc-des3_ede-ubicom32",
+	.cra_priority		=	CRYPTO_UBICOM32_COMPOSITE_PRIORITY,
+	.cra_flags		=	CRYPTO_ALG_TYPE_BLKCIPHER,
+	.cra_blocksize		=	DES3_192_BLOCK_SIZE,
+	.cra_ctxsize		=	sizeof(struct ubicom32_des_ctx),
+	.cra_alignmask		=	CRYPTO_UBICOM32_ALIGNMENT - 1,
+	.cra_type		=	&crypto_blkcipher_type,
+	.cra_module		=	THIS_MODULE,
+	.cra_list		=	LIST_HEAD_INIT(
+						cbc_des3_192_alg.cra_list),
+	.cra_u			= {
+		.blkcipher = {
+			.min_keysize		=	DES3_192_KEY_SIZE,
+			.max_keysize		=	DES3_192_KEY_SIZE,
+			.ivsize			=	DES3_192_BLOCK_SIZE,
+			.setkey			=	des3_192_setkey,
+			.encrypt		=	cbc_des3_192_encrypt,
+			.decrypt		=	cbc_des3_192_decrypt,
+		}
+	}
+};
+
+static int init(void)
+{
+	int ret = 0;
+
+	hw_crypto_init();
+
+	ret = crypto_register_alg(&des_alg);
+	if (ret)
+		goto des_err;
+	ret = crypto_register_alg(&ecb_des_alg);
+	if (ret)
+		goto ecb_des_err;
+	ret = crypto_register_alg(&cbc_des_alg);
+	if (ret)
+		goto cbc_des_err;
+
+	ret = crypto_register_alg(&des3_192_alg);
+	if (ret)
+		goto des3_192_err;
+	ret = crypto_register_alg(&ecb_des3_192_alg);
+	if (ret)
+		goto ecb_des3_192_err;
+	ret = crypto_register_alg(&cbc_des3_192_alg);
+	if (ret)
+		goto cbc_des3_192_err;
+
+out:
+	return ret;
+
+cbc_des3_192_err:
+	crypto_unregister_alg(&ecb_des3_192_alg);
+ecb_des3_192_err:
+	crypto_unregister_alg(&des3_192_alg);
+des3_192_err:
+	crypto_unregister_alg(&cbc_des_alg);
+cbc_des_err:
+	crypto_unregister_alg(&ecb_des_alg);
+ecb_des_err:
+	crypto_unregister_alg(&des_alg);
+des_err:
+	goto out;
+}
+
+static void __exit fini(void)
+{
+	crypto_unregister_alg(&cbc_des3_192_alg);
+	crypto_unregister_alg(&ecb_des3_192_alg);
+	crypto_unregister_alg(&des3_192_alg);
+	crypto_unregister_alg(&cbc_des_alg);
+	crypto_unregister_alg(&ecb_des_alg);
+	crypto_unregister_alg(&des_alg);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_ALIAS("des");
+MODULE_ALIAS("des3_ede");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");
--- /dev/null
+++ b/arch/ubicom32/crypto/Makefile
@@ -0,0 +1,36 @@
+#
+# arch/ubicom32/crypto/Makefile
+#	<TODO: Replace with short file description>
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+obj-$(CONFIG_CRYPTO_UBICOM32) += crypto_ubicom32.o
+obj-$(CONFIG_CRYPTO_AES_UBICOM32) += aes_ubicom32.o
+obj-$(CONFIG_CRYPTO_DES_UBICOM32) += des.o
+obj-$(CONFIG_CRYPTO_MD5_UBICOM32) += md5.o
+obj-$(CONFIG_CRYPTO_SHA1_UBICOM32) += sha1.o
+
+des-y := des_ubicom32.o des_check_key.o
+md5-y := md5_ubicom32.o md5_ubicom32_asm.o
+sha1-y := sha1_ubicom32.o 
--- /dev/null
+++ b/arch/ubicom32/crypto/md5_ubicom32_asm.S
@@ -0,0 +1,235 @@
+/*
+ * arch/ubicom32/crypto/md5_ubicom32_asm.S
+ *	MD5 (Message Digest 5) support for Ubicom32 v3 architecture
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#define __ASM__
+#include <asm/ip5000.h>
+
+#ifndef RP
+#define RP A5
+#endif
+
+;*****************************************************************************************
+; The function prototypes
+;*****************************************************************************************
+; void md5_ip5k_init(void)
+; void md5_ip5k_transform(u32_t *data_input)
+; void md5_get_digest(u32_t *digest)
+
+;*****************************************************************************************
+; Inputs
+;*****************************************************************************************;
+; data_input is the pointer to the block of data over which the digest will be calculated.
+;	It should be word aligned.
+;
+; digest is the pointer to the block of data into which the digest (the output) will be written.
+;	It should be word aligned.
+;
+
+;*****************************************************************************************
+; Outputs
+;*****************************************************************************************
+; None
+
+;*****************************************************************************************
+; An: Address Registers
+;*****************************************************************************************
+#define an_digest A3
+#define an_data_input A3
+#define an_security_block A4
+
+;*****************************************************************************************
+; Hash Constants
+;*****************************************************************************************
+#define HASH_MD5_IN0 0x01234567
+#define HASH_MD5_IN1 0x89abcdef
+#define HASH_MD5_IN2 0xfedcba98
+#define HASH_MD5_IN3 0x76543210
+
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION 2
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_MD5 ((1 << 4) | HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION)
+
+;*****************************************************************************************
+; Hash related defines
+;*****************************************************************************************
+#define hash_control 0x00(an_security_block)
+#define hash_control_low 0x02(an_security_block)
+#define hash_status 0x04(an_security_block)
+
+#define hash_input_0 0x30(an_security_block)
+#define hash_input_1 0x34(an_security_block)
+#define hash_input_2 0x38(an_security_block)
+#define hash_input_3 0x3c(an_security_block)
+#define hash_input_4 0x40(an_security_block)
+
+#define hash_output_0 0x70(an_security_block)
+#define hash_output_0_low 0x72(an_security_block)
+#define hash_output_1 0x74(an_security_block)
+#define hash_output_1_low 0x76(an_security_block)
+#define hash_output_2 0x78(an_security_block)
+#define hash_output_2_low 0x7a(an_security_block)
+#define hash_output_3 0x7c(an_security_block)
+#define hash_output_3_low 0x7e(an_security_block)
+
+;*****************************************************************************************
+; Assembly macros
+;*****************************************************************************************
+	; C compiler reserves RP (A5) for return address during subroutine call.
+	; Use RP to return to caller
+.macro	call_return_macro
+	calli	RP, 0(RP)
+.endm
+
+#if 0
+;*****************************************************************************************
+;	void md5_ip5k_init(void)
+;		initialize the output registers of the hash module
+;
+	;.section .text.md5_ip5k_init,"ax",@progbits
+	.section .text
+	.global	_md5_ip5k_init
+	.func md5_ip5k_init, _md5_ip5k_init
+
+_md5_ip5k_init:
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
+	movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
+
+	movei hash_output_0, #%hi(HASH_MD5_IN0)
+	movei hash_output_0_low, #%lo(HASH_MD5_IN0)
+
+	movei hash_output_1, #%hi(HASH_MD5_IN1)
+	movei hash_output_1_low, #%lo(HASH_MD5_IN1)
+
+	movei hash_output_2, #%hi(HASH_MD5_IN2)
+	movei hash_output_2_low, #%lo(HASH_MD5_IN2)
+
+	movei hash_output_3, #%hi(HASH_MD5_IN3)
+	movei hash_output_3_low, #%lo(HASH_MD5_IN3)
+
+	call_return_macro
+	.endfunc
+#endif
+
+;*****************************************************************************************
+;	void md5_ip5k_init_digest(u32_t *hash_input)
+;		initialize the output registers of the hash module
+
+	;.section .text.md5_ip5k_init_digest,"ax",@progbits
+	.section .text
+	.global	_md5_ip5k_init_digest
+	.func md5_ip5k_init_digest, _md5_ip5k_init_digest
+
+_md5_ip5k_init_digest:
+	movea an_data_input, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
+	movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
+
+	move.4 hash_output_0, (an_data_input)4++
+	move.4 hash_output_1, (an_data_input)4++
+	move.4 hash_output_2, (an_data_input)4++
+	move.4 hash_output_3, (an_data_input)4++
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;	void md5_ip5k_transform(u32_t *data_input)
+;		performs intermediate transformation step for the hash calculation
+;
+	;.sect .text.md5_ip5k_transform,"ax",@progbits
+	.section .text
+	.global	_md5_ip5k_transform
+	.func md5_ip5k_transform, _md5_ip5k_transform
+
+_md5_ip5k_transform:
+	movea an_data_input, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	; Write the first 128bits (16 bytes)
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	pipe_flush 0
+
+md5_ip5k_transform_wait:
+	; wait for the module to calculate the output hash
+	btst hash_status, #0
+	jmpne.f md5_ip5k_transform_wait
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;	void md5_ip5k_get_digest(u32_t *digest)
+;		Return the hash of the input data
+;
+	;.sect .text.md5_get_digest,"ax",@progbits
+	.section .text
+	.global	_md5_ip5k_get_digest
+	.func md5_ip5k_get_digest, _md5_ip5k_get_digest
+
+_md5_ip5k_get_digest:
+	movea an_digest, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	; we have finished
+	move.4 0(an_digest), hash_output_0
+	move.4 4(an_digest), hash_output_1
+	move.4 8(an_digest), hash_output_2
+	move.4 12(an_digest), hash_output_3
+
+	call_return_macro
+	.endfunc
+
--- /dev/null
+++ b/arch/ubicom32/crypto/md5_ubicom32.c
@@ -0,0 +1,200 @@
+/*
+ * arch/ubicom32/crypto/md5_ubicom32.c
+ *   Ubicom32 implementation of the MD5 Secure Hash Algorithm
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/crypto.h>
+
+#include "crypto_ubicom32.h"
+
+#define MD5_DIGEST_SIZE	16
+#define MD5_BLOCK_SIZE	64
+#define MD5_HASH_WORDS	4
+
+extern void _md5_ip5k_init_digest(u32_t *digest);
+extern void _md5_ip5k_transform(u32_t *data_input);
+extern void _md5_ip5k_get_digest(u32_t *digest);
+
+struct ubicom32_md5_ctx {
+	u64 count;		/* message length */
+	u32 state[MD5_HASH_WORDS];
+	u8 buf[2 * MD5_BLOCK_SIZE];
+};
+
+static void md5_init(struct crypto_tfm *tfm)
+{
+	struct ubicom32_md5_ctx *mctx = crypto_tfm_ctx(tfm);
+	mctx->state[0] = 0x01234567;
+	mctx->state[1] = 0x89abcdef;
+	mctx->state[2] = 0xfedcba98;
+	mctx->state[3] = 0x76543210;
+
+	mctx->count = 0;
+}
+
+static inline void _md5_process(u32 *digest, const u8 *data)
+{
+	_md5_ip5k_transform((u32 *)data);
+}
+
+static void md5_update(struct crypto_tfm *tfm, const u8 *data,
+			unsigned int len)
+{
+	struct ubicom32_md5_ctx *mctx = crypto_tfm_ctx(tfm);
+	int index, clen;
+
+	/* how much is already in the buffer? */
+	index = mctx->count & 0x3f;
+
+	mctx->count += len;
+
+	if (index + len < MD5_BLOCK_SIZE) {
+		goto store_only;
+	}
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+	/* init digest set ctrl register too */
+	_md5_ip5k_init_digest(mctx->state);
+
+	if (unlikely(index == 0 && SEC_ALIGNED(data))) {
+fast_process:
+		while (len >= MD5_BLOCK_SIZE) {
+			_md5_process(mctx->state, data);
+			data += MD5_BLOCK_SIZE;
+			len -= MD5_BLOCK_SIZE;
+		}
+		goto store;
+	}
+
+	/* process one stored block */
+	if (index) {
+		clen = MD5_BLOCK_SIZE - index;
+		memcpy(mctx->buf + index, data, clen);
+		_md5_process(mctx->state, mctx->buf);
+		data += clen;
+		len -= clen;
+		index = 0;
+	}
+
+	if (likely(SEC_ALIGNED(data))) {
+		goto fast_process;
+	}
+
+	/* process as many blocks as possible */
+	while (len >= MD5_BLOCK_SIZE) {
+		memcpy(mctx->buf, data, MD5_BLOCK_SIZE);
+		_md5_process(mctx->state, mctx->buf);
+		data += MD5_BLOCK_SIZE;
+		len -= MD5_BLOCK_SIZE;
+	}
+
+store:
+	_md5_ip5k_get_digest(mctx->state);
+	hw_crypto_unlock();
+
+store_only:
+	/* anything left? */
+	if (len)
+		memcpy(mctx->buf + index , data, len);
+}
+
+/* Add padding and return the message digest. */
+static void md5_final(struct crypto_tfm *tfm, u8 *out)
+{
+	struct ubicom32_md5_ctx *mctx = crypto_tfm_ctx(tfm);
+	u32 bits[2];
+	unsigned int index, end;
+
+	/* must perform manual padding */
+	index = mctx->count & 0x3f;
+	end =  (index < 56) ? MD5_BLOCK_SIZE : (2 * MD5_BLOCK_SIZE);
+
+	/* start pad with 1 */
+	mctx->buf[index] = 0x80;
+
+	/* pad with zeros */
+	index++;
+	memset(mctx->buf + index, 0x00, end - index - 8);
+
+	/* append message length */
+	bits[0] = mctx->count << 3;
+	bits[1] = mctx->count >> 29;
+	__cpu_to_le32s(bits);
+	__cpu_to_le32s(bits + 1);
+
+	memcpy(mctx->buf + end - 8, &bits, sizeof(bits));
+
+	/* force to use the mctx->buf and ignore the partial buf */
+	mctx->count = mctx->count & ~0x3f;
+	md5_update(tfm, mctx->buf, end);
+
+	/* copy digest to out */
+	memcpy(out, mctx->state, MD5_DIGEST_SIZE);
+
+	/* wipe context */
+	memset(mctx, 0, sizeof *mctx);
+}
+
+static struct crypto_alg alg = {
+	.cra_name	=	"md5",
+	.cra_driver_name=	"md5-ubicom32",
+	.cra_priority	=	CRYPTO_UBICOM32_PRIORITY,
+	.cra_flags	=	CRYPTO_ALG_TYPE_DIGEST,
+	.cra_blocksize	=	MD5_BLOCK_SIZE,
+	.cra_ctxsize	=	sizeof(struct ubicom32_md5_ctx),
+	.cra_module	=	THIS_MODULE,
+	.cra_list	=	LIST_HEAD_INIT(alg.cra_list),
+	.cra_u = {
+		.digest = {
+			.dia_digestsize =       MD5_DIGEST_SIZE,
+			.dia_init       =       md5_init,
+			.dia_update     =       md5_update,
+			.dia_final      =       md5_final,
+		}
+	}
+};
+
+static int __init init(void)
+{
+	hw_crypto_init();
+	return crypto_register_alg(&alg);
+}
+
+static void __exit fini(void)
+{
+	crypto_unregister_alg(&alg);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_ALIAS("md5");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MD5 Secure Hash Algorithm");
--- /dev/null
+++ b/arch/ubicom32/crypto/sha1_ubicom32_asm.S
@@ -0,0 +1,244 @@
+/*
+ * arch/ubicom32/crypto/sha1_ubicom32_asm.S
+ *	SHA1 hash support for Ubicom32 architecture V3.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#define __ASM__
+#include <asm/ip5000.h>
+
+#ifndef RP
+#define RP A5
+#endif
+
+;*****************************************************************************************
+; The function prototype
+;*****************************************************************************************
+; void sha1_ip5k_init(void)
+; void sha1_ip5k_transform(u32_t *data_input)
+; void sha1_ip5k_output(u32_t *digest)
+
+;*****************************************************************************************
+; Inputs
+;*****************************************************************************************
+; data_input is the pointer to the block of data over which the digest will be calculated.
+;	It should be word aligned.
+;
+; digest is the pointer to the block of data into which the digest (the output) will be written.
+;	It should be word aligned.
+;
+
+;*****************************************************************************************
+; Outputs
+;*****************************************************************************************
+; None
+
+;*****************************************************************************************
+; Hash Constants
+;*****************************************************************************************
+#define HASH_SHA1_IN0 0x67452301
+#define HASH_SHA1_IN1 0xefcdab89
+#define HASH_SHA1_IN2 0x98badcfe
+#define HASH_SHA1_IN3 0x10325476
+#define HASH_SHA1_IN4 0xc3d2e1f0
+
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION 2
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1 ((1 << 5) | HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION)
+
+;*****************************************************************************************
+; An: Address Registers
+;*****************************************************************************************
+#define an_digest a4
+#define an_data_input a4
+#define an_security_block a3
+
+;*****************************************************************************************
+; Hash related defines
+;*****************************************************************************************
+#define hash_control 0x00(an_security_block)
+#define hash_control_low 0x02(an_security_block)
+#define hash_status 0x04(an_security_block)
+
+#define hash_input_0 0x30(an_security_block)
+#define hash_input_1 0x34(an_security_block)
+#define hash_input_2 0x38(an_security_block)
+#define hash_input_3 0x3c(an_security_block)
+#define hash_input_4 0x40(an_security_block)
+
+#define hash_output_0 0x70(an_security_block)
+#define hash_output_0_low 0x72(an_security_block)
+#define hash_output_1 0x74(an_security_block)
+#define hash_output_1_low 0x76(an_security_block)
+#define hash_output_2 0x78(an_security_block)
+#define hash_output_2_low 0x7a(an_security_block)
+#define hash_output_3 0x7c(an_security_block)
+#define hash_output_3_low 0x7e(an_security_block)
+#define hash_output_4 0x80(an_security_block)
+#define hash_output_4_low 0x82(an_security_block)
+
+;*****************************************************************************************
+; Assembly macros
+;*****************************************************************************************
+	; C compiler reserves RP (A5) for return address during subroutine call.
+	; Use RP to return to caller
+.macro	call_return_macro
+	calli	RP, 0(RP)
+.endm
+
+;*****************************************************************************************
+;	void sha1_ip5k_init(void)
+;		initialize the output registers of the hash module
+
+	;.section .text.sha1_ip5k_init,"ax",@progbits
+	.section .ocm_text,"ax",@progbits
+	.global	_sha1_ip5k_init
+	.func sha1_ip5k_init, _sha1_ip5k_init
+
+_sha1_ip5k_init:
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
+	movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
+
+	movei hash_output_0, #%hi(HASH_SHA1_IN0)
+	movei hash_output_0_low, #%lo(HASH_SHA1_IN0)
+
+	movei hash_output_1, #%hi(HASH_SHA1_IN1)
+	movei hash_output_1_low, #%lo(HASH_SHA1_IN1)
+
+	movei hash_output_2, #%hi(HASH_SHA1_IN2)
+	movei hash_output_2_low, #%lo(HASH_SHA1_IN2)
+
+	movei hash_output_3, #%hi(HASH_SHA1_IN3)
+	movei hash_output_3_low, #%lo(HASH_SHA1_IN3)
+
+	movei hash_output_4, #%hi(HASH_SHA1_IN4)
+	movei hash_output_4_low, #%lo(HASH_SHA1_IN4)
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;	void sha1_ip5k_init_digest(u32_t *hash_input)
+;		initialize the output registers of the hash module
+
+	;.section .text.sha1_ip5k_init_digest,"ax",@progbits
+	.section .ocm_text,"ax",@progbits
+	.global	_sha1_ip5k_init_digest
+	.func sha1_ip5k_init_digest, _sha1_ip5k_init_digest
+
+_sha1_ip5k_init_digest:
+	movea an_data_input, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
+	movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
+
+	move.4 hash_output_0, (an_data_input)4++
+	move.4 hash_output_1, (an_data_input)4++
+	move.4 hash_output_2, (an_data_input)4++
+	move.4 hash_output_3, (an_data_input)4++
+	move.4 hash_output_4, (an_data_input)4++
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;	void sha1_ip5k_transform(u32_t *data_input)
+;		performs intermediate transformation step for the hash calculation
+
+	;.section .text.sha1_ip5k_transform,"ax",@progbits
+	.section .ocm_text,"ax",@progbits
+	.global	_sha1_ip5k_transform
+	.func sha1_ip5k_transform, _sha1_ip5k_transform
+
+_sha1_ip5k_transform:
+	movea an_data_input, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	; Write the first 128bits (16 bytes)
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	move.4 hash_input_0, (an_data_input)4++
+	move.4 hash_input_1, (an_data_input)4++
+	move.4 hash_input_2, (an_data_input)4++
+	move.4 hash_input_3, (an_data_input)4++
+	move.4 hash_input_4, D0
+
+	pipe_flush 0
+
+sha1_ip5k_transform_wait:
+	; wait for the module to calculate the output hash
+	btst hash_status, #0
+	jmpne.f sha1_ip5k_transform_wait
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;	void sha1_ip5k_output(u32_t *digest)
+;		Return the hash of the input data
+
+	;.section .text.sha1_ip5k_output,"ax",@progbits
+	.section .ocm_text,"ax",@progbits
+	.global	_sha1_ip5k_output
+	.func sha1_ip5k_output, _sha1_ip5k_output
+
+_sha1_ip5k_output:
+	movea an_digest, D0
+
+	moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
+
+	; we have finished
+	move.4 0(an_digest), hash_output_0
+	move.4 4(an_digest), hash_output_1
+	move.4 8(an_digest), hash_output_2
+	move.4 12(an_digest), hash_output_3
+	move.4 16(an_digest), hash_output_4
+
+	call_return_macro
+	.endfunc
+
+;*****************************************************************************************
+;END			;End of program code
+;*****************************************************************************************
--- /dev/null
+++ b/arch/ubicom32/crypto/sha1_ubicom32.c
@@ -0,0 +1,354 @@
+/*
+ * arch/ubicom32/crypto/sha1_ubicom32.c
+ *   Ubicom32 implementation of the SHA1 Secure Hash Algorithm.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/crypto.h>
+#include <crypto/sha.h>
+#include <asm/linkage.h>
+
+#include "crypto_ubicom32.h"
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION 2
+#define HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1 ((1 << 5) | HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION)
+
+struct ubicom32_sha1_ctx {
+	u64 count;		/* message length */
+	u32 state[5];
+	u8 buf[2 * SHA1_BLOCK_SIZE];
+};
+
+static inline void sha1_clear_2ws(u8 *buf, int wc)
+{
+	asm volatile (
+	"1:	move.4	(%0)4++, #0		\n\t"
+	"	move.4	(%0)4++, #0		\n\t"
+	"	sub.4	%1, #2, %1		\n\t"
+	"	jmple.f	1b			\n\t"
+		:
+		: "a" (buf), "d" (wc)
+		: "cc"
+	);
+}
+
+/* only wipe out count, state, and 1st half of buf - 9 bytes at most */
+#define sha1_wipe_out(sctx) sha1_clear_2ws((u8 *)sctx, 2 + 5 + 16 - 2)
+
+static inline void sha1_init_digest(u32 *digest)
+{
+	hw_crypto_set_ctrl(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1);
+	asm volatile (
+	"	; move digests to hash_output regs	\n\t"
+	"	move.4	0x70(%0), 0x0(%1)		\n\t"
+	"	move.4	0x74(%0), 0x4(%1)		\n\t"
+	"	move.4	0x78(%0), 0x8(%1)		\n\t"
+	"	move.4	0x7c(%0), 0xc(%1)		\n\t"
+	"	move.4	0x80(%0), 0x10(%1)		\n\t"
+		:
+		: "a" (SEC_BASE), "a" (digest)
+	);
+}
+
+static inline void sha1_transform_feed(const u8 *in)
+{
+	asm volatile (
+	"	; write the 1st 16 bytes	\n\t"
+	"	move.4	0x30(%0), 0x0(%1)	\n\t"
+	"	move.4	0x34(%0), 0x4(%1)	\n\t"
+	"	move.4	0x38(%0), 0x8(%1)	\n\t"
+	"	move.4	0x3c(%0), 0xc(%1)	\n\t"
+	"	move.4	0x40(%0), %1		\n\t"
+	"	; write the 2nd 16 bytes	\n\t"
+	"	move.4	0x30(%0), 0x10(%1)	\n\t"
+	"	move.4	0x34(%0), 0x14(%1)	\n\t"
+	"	move.4	0x38(%0), 0x18(%1)	\n\t"
+	"	move.4	0x3c(%0), 0x1c(%1)	\n\t"
+	"	move.4	0x40(%0), %1		\n\t"
+	"	; write the 3rd 16 bytes	\n\t"
+	"	move.4	0x30(%0), 0x20(%1)	\n\t"
+	"	move.4	0x34(%0), 0x24(%1)	\n\t"
+	"	move.4	0x38(%0), 0x28(%1)	\n\t"
+	"	move.4	0x3c(%0), 0x2c(%1)	\n\t"
+	"	move.4	0x40(%0), %1		\n\t"
+	"	; write the 4th 16 bytes	\n\t"
+	"	move.4	0x30(%0), 0x30(%1)	\n\t"
+	"	move.4	0x34(%0), 0x34(%1)	\n\t"
+	"	move.4	0x38(%0), 0x38(%1)	\n\t"
+	"	move.4	0x3c(%0), 0x3c(%1)	\n\t"
+	"	move.4	0x40(%0), %1		\n\t"
+	"	pipe_flush 0			\n\t" 
+		:
+		: "a"(SEC_BASE), "a"(in)
+	);
+}
+
+static inline void sha1_transform_wait(void)
+{
+	asm volatile (
+	"	btst	0x04(%0), #0		\n\t"
+	"	jmpne.f -4			\n\t"
+		:
+		: "a"(SEC_BASE)
+		: "cc"
+	);
+}
+
+static inline void sha1_output_digest(u32 *digest)
+{
+	asm volatile (
+	"	move.4	0x0(%1), 0x70(%0)		\n\t"
+	"	move.4	0x4(%1), 0x74(%0)		\n\t"
+	"	move.4	0x8(%1), 0x78(%0)		\n\t"
+	"	move.4	0xc(%1), 0x7c(%0)		\n\t"
+	"	move.4	0x10(%1), 0x80(%0)		\n\t"
+		: 
+		: "a" (SEC_BASE), "a" (digest)
+	);
+}
+
+static __ocm_text void sha1_init(struct crypto_tfm *tfm)
+{
+	struct ubicom32_sha1_ctx *sctx = crypto_tfm_ctx(tfm);
+
+	sctx->state[0] = SHA1_H0;
+	sctx->state[1] = SHA1_H1;
+	sctx->state[2] = SHA1_H2;
+	sctx->state[3] = SHA1_H3;
+	sctx->state[4] = SHA1_H4;
+	sctx->count = 0;
+}
+
+static void __ocm_text sha1_update(struct crypto_tfm *tfm, const u8 *data,
+			unsigned int len)
+{
+	struct ubicom32_sha1_ctx *sctx = crypto_tfm_ctx(tfm);
+	int index, clen;
+
+	/* how much is already in the buffer? */
+	index = sctx->count & 0x3f;
+
+	sctx->count += len;
+
+	if (index + len < SHA1_BLOCK_SIZE) {
+		goto store_only;
+	}
+
+	hw_crypto_lock();
+	hw_crypto_check();
+
+	/* init digest set ctrl register too */
+	sha1_init_digest(sctx->state);
+
+	if (unlikely(index == 0 && SEC_ALIGNED(data))) {
+fast_process:
+#if CRYPTO_UBICOM32_LOOP_ASM 
+		if (likely(len >= SHA1_BLOCK_SIZE)) {
+			register unsigned int cnt = len >> 6; 	// loop = len / 64;
+			sha1_transform_feed(data);
+			data += SHA1_BLOCK_SIZE;
+
+			/* cnt is pre-decremented in the loop */
+			asm volatile (
+			"; while (--loop):  work on 2nd block   \n\t"
+			"1:	add.4	%2, #-1, %2		\n\t"
+			"	jmpeq.f	5f			\n\t"
+			"					\n\t"
+			"	; write the 1st 16 bytes	\n\t"
+			"	move.4	0x30(%1), (%0)4++	\n\t"
+			"	move.4	0x34(%1), (%0)4++	\n\t"
+			"	move.4	0x38(%1), (%0)4++	\n\t"
+			"	move.4	0x3c(%1), (%0)4++	\n\t"
+			"	; can not kick off hw before it \n\t"
+			"	; is done with the prev block   \n\t"
+			"					\n\t"
+			"	btst	0x04(%1), #0		\n\t"
+			"	jmpne.f	-4			\n\t"
+			"					\n\t"
+			"	; tell hw to load 1st 16 bytes  \n\t"
+			"	move.4	0x40(%1), %2		\n\t"
+			"					\n\t"
+			"	; write the 2nd 16 bytes	\n\t"
+			"	move.4	0x30(%1), (%0)4++	\n\t"
+			"	move.4	0x34(%1), (%0)4++	\n\t"
+			"	move.4	0x38(%1), (%0)4++	\n\t"
+			"	move.4	0x3c(%1), (%0)4++	\n\t"
+			"	move.4	0x40(%1), %2		\n\t"
+			"					\n\t"
+			"	; write the 3rd 16 bytes	\n\t"
+			"	move.4	0x30(%1), (%0)4++	\n\t"
+			"	move.4	0x34(%1), (%0)4++	\n\t"
+			"	move.4	0x38(%1), (%0)4++	\n\t"
+			"	move.4	0x3c(%1), (%0)4++	\n\t"
+			"	move.4	0x40(%1), %2		\n\t"
+			"					\n\t"
+			"	; write the 4th 16 bytes	\n\t"
+			"	move.4	0x30(%1), (%0)4++	\n\t"
+			"	move.4	0x34(%1), (%0)4++	\n\t"
+			"	move.4	0x38(%1), (%0)4++	\n\t"
+			"	move.4	0x3c(%1), (%0)4++	\n\t"
+			"	move.4	0x40(%1), %2		\n\t"
+			"					\n\t"
+			"; no need flush, enough insts		\n\t"
+			"; before next hw wait			\n\t"
+			"					\n\t"
+			"; go back to loop			\n\t"
+			"	jmpt 1b				\n\t"
+			"					\n\t"
+			"; wait hw for last block		\n\t"
+			"5:	btst 0x04(%1), #0		\n\t"
+			"	jmpne.f -4			\n\t"
+			"					\n\t"
+				: "+a" (data)
+				: "a"( SEC_BASE), "d" (cnt)
+				: "cc"
+			);
+
+			len = len & (64 - 1);
+		}
+#else
+		while (likely(len >= SHA1_BLOCK_SIZE)) {
+			sha1_transform_feed(data);
+			data += SHA1_BLOCK_SIZE;
+			len -= SHA1_BLOCK_SIZE;
+			sha1_transform_wait();
+		}
+#endif
+		goto store;
+	}
+
+	/* process one stored block */
+	if (index) {
+		clen = SHA1_BLOCK_SIZE - index;
+		memcpy(sctx->buf + index, data, clen);
+		sha1_transform_feed(sctx->buf);
+		data += clen;
+		len -= clen;
+		index = 0;
+		sha1_transform_wait();
+	}
+
+	if (likely(SEC_ALIGNED(data))) {
+		goto fast_process;
+	}
+
+	/* process as many blocks as possible */
+	if (likely(len >= SHA1_BLOCK_SIZE)) {
+		memcpy(sctx->buf, data, SHA1_BLOCK_SIZE);
+		do {
+			sha1_transform_feed(sctx->buf);
+			data += SHA1_BLOCK_SIZE;
+			len -= SHA1_BLOCK_SIZE;
+			if (likely(len >= SHA1_BLOCK_SIZE)) {
+				memcpy(sctx->buf, data, SHA1_BLOCK_SIZE);
+				sha1_transform_wait();
+				continue;
+			}
+			/* it is the last block */	
+			sha1_transform_wait();
+			break;
+		} while (1);
+	}
+
+store:
+	sha1_output_digest(sctx->state);
+	hw_crypto_unlock();
+
+store_only:
+	/* anything left? */
+	if (len)
+		memcpy(sctx->buf + index , data, len);
+}
+
+/* Add padding and return the message digest. */
+static void __ocm_text sha1_final(struct crypto_tfm *tfm, u8 *out)
+{
+	struct ubicom32_sha1_ctx *sctx = crypto_tfm_ctx(tfm);
+	u64 bits;
+	unsigned int index, end;
+
+	/* must perform manual padding */
+	index = sctx->count & 0x3f;
+	end =  (index < 56) ? SHA1_BLOCK_SIZE : (2 * SHA1_BLOCK_SIZE);
+
+	/* start pad with 1 */
+	sctx->buf[index] = 0x80;
+
+	/* pad with zeros */
+	index++;
+	memset(sctx->buf + index, 0x00, end - index - 8);
+
+	/* append message length */
+	bits = sctx->count << 3 ;
+	SEC_COPY_2W(sctx->buf + end - 8, &bits);
+
+	/* force to use the sctx->buf and ignore the partial buf */
+	sctx->count = sctx->count & ~0x3f;
+	sha1_update(tfm, sctx->buf, end);
+
+	/* copy digest to out */
+	SEC_COPY_5W(out, sctx->state);
+
+	/* wipe context */
+	sha1_wipe_out(sctx);
+}
+
+static struct crypto_alg alg = {
+	.cra_name	=	"sha1",
+	.cra_driver_name=	"sha1-ubicom32",
+	.cra_priority	=	CRYPTO_UBICOM32_PRIORITY,
+	.cra_flags	=	CRYPTO_ALG_TYPE_DIGEST,
+	.cra_blocksize	=	SHA1_BLOCK_SIZE,
+	.cra_ctxsize	=	sizeof(struct ubicom32_sha1_ctx),
+	.cra_module	=	THIS_MODULE,
+	.cra_list	=	LIST_HEAD_INIT(alg.cra_list),
+	.cra_u	  = {
+		.digest = {
+			.dia_digestsize =       SHA1_DIGEST_SIZE,
+			.dia_init       =       sha1_init,
+			.dia_update     =       sha1_update,
+			.dia_final      =       sha1_final,
+		}
+	}
+};
+
+static int __init init(void)
+{
+	hw_crypto_init();
+	return crypto_register_alg(&alg);
+}
+
+static void __exit fini(void)
+{
+	crypto_unregister_alg(&alg);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_ALIAS("sha1");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
--- /dev/null
+++ b/arch/ubicom32/include/asm/a.out.h
@@ -0,0 +1,47 @@
+/*
+ * arch/ubicom32/include/asm/a.out.h
+ *   Definitions for Ubicom32 a.out executable format.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_A_OUT_H
+#define _ASM_UBICOM32_A_OUT_H
+
+struct exec
+{
+  unsigned long a_info;		/* Use macros N_MAGIC, etc for access */
+  unsigned a_text;		/* length of text, in bytes */
+  unsigned a_data;		/* length of data, in bytes */
+  unsigned a_bss;		/* length of uninitialized data area for file, in bytes */
+  unsigned a_syms;		/* length of symbol table data in file, in bytes */
+  unsigned a_entry;		/* start address */
+  unsigned a_trsize;		/* length of relocation info for text, in bytes */
+  unsigned a_drsize;		/* length of relocation info for data, in bytes */
+};
+
+#define N_TRSIZE(a)	((a).a_trsize)
+#define N_DRSIZE(a)	((a).a_drsize)
+#define N_SYMSIZE(a)	((a).a_syms)
+
+#endif /* _ASM_UBICOM32_A_OUT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/atomic.h
@@ -0,0 +1,352 @@
+/*
+ * arch/ubicom32/include/asm/atomic.h
+ *   Atomic operations definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_ATOMIC_H
+#define _ASM_UBICOM32_ATOMIC_H
+
+#include <asm/system.h>
+#include <asm/ubicom32-common.h>
+#include <asm/types.h>
+
+/*
+ * Most instructions on the Ubicom32 processor are atomic in that they
+ * execute in one clock cycle.  However, Linux has several operations
+ * (e.g. compare and swap) which will require more than a single instruction
+ * to perform.   To achieve this, the Ubicom32 processor uses a single
+ * global bit in a scratchpad register as a critical section lock. All
+ * atomic operations acquire this lock.
+ *
+ * NOTE: To AVOID DEADLOCK(s), the atomic lock must only be used for atomic
+ * operations or by the ldsr to avoid disabling a thread performing an atomic
+ * operation.
+ *
+ * Do not attempt to disable interrupts while holding the atomic operations
+ * lock or you will DEADLOCK the system.
+ */
+
+typedef struct {
+	volatile int counter;
+} atomic_t;
+
+#define ATOMIC_INIT(i)	{ (i) }
+
+/*
+ * __atomic_add()
+ * 	Add i to v and return the result.
+ */
+static inline void __atomic_add(int i, atomic_t *v)
+{
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	vt->counter += i;
+	__atomic_lock_release();
+}
+
+/*
+ * __atomic_sub()
+ * 	Subtract i from v and return the result.
+ */
+static inline void __atomic_sub(int i, atomic_t *v)
+{
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	vt->counter -= i;
+	__atomic_lock_release();
+}
+
+/*
+ * __atomic_add_return()
+ * 	Add i to v and return the result.
+ *
+ * The implementation here looks rather odd because we appear to be doing
+ * the addition twice.  In fact that's exactly what we're doing but with
+ * the ubicom32 instruction set we can do the inner load and add with two
+ * instructions whereas generating both the atomic result and the "ret"
+ * result requires three instructions.  The second add is generally only as
+ * costly as a move instruction and in cases where we compare the result
+ * with a constant the compiler can fold two constant values and do a
+ * single instruction, thus saving an instruction overall!
+ *
+ * At the worst we save one instruction inside the atomic lock.
+ */
+static inline int __atomic_add_return(int i, atomic_t *v)
+{
+	int ret;
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	ret = vt->counter;
+	vt->counter = ret + i;
+	__atomic_lock_release();
+
+	return ret + i;
+}
+
+/*
+ * __atomic_sub_return()
+ * 	Subtract i from v and return the result.
+ *
+ * The implementation here looks rather odd because we appear to be doing
+ * the subtraction twice.  In fact that's exactly what we're doing but with
+ * the ubicom32 instruction set we can do the inner load and sub with two
+ * instructions whereas generating both the atomic result and the "ret"
+ * result requires three instructions.  The second sub is generally only as
+ * costly as a move instruction and in cases where we compare the result
+ * with a constant the compiler can fold two constant values and do a
+ * single instruction, thus saving an instruction overall!
+ *
+ * At the worst we save one instruction inside the atomic lock.
+ */
+static inline int __atomic_sub_return(int i, atomic_t *v)
+{
+	int ret;
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	ret = vt->counter;
+	vt->counter = ret - i;
+	__atomic_lock_release();
+
+	return ret - i;
+}
+
+/*
+ * PUBLIC API FOR ATOMIC!
+ */
+#define atomic_add(i,v)	(__atomic_add( ((int)i),(v)))
+#define atomic_sub(i,v)	(__atomic_sub( ((int)i),(v)))
+#define atomic_inc(v)	(__atomic_add(   1,(v)))
+#define atomic_dec(v)	(__atomic_sub(   1,(v)))
+#define atomic_add_return(i,v)	(__atomic_add_return( ((int)i),(v)))
+#define atomic_sub_return(i,v)	(__atomic_sub_return( ((int)i),(v)))
+#define atomic_inc_return(v)	(__atomic_add_return(   1,(v)))
+#define atomic_dec_return(v)	(__atomic_sub_return(   1,(v)))
+#define atomic_inc_and_test(v)	(atomic_inc_return(v) == 0)
+#define atomic_dec_and_test(v)	(atomic_dec_return(v) == 0)
+#define atomic_add_negative(a, v)	(atomic_add_return((a), (v)) < 0)
+#define atomic_sub_and_test(i,v)	(atomic_sub_return((i),(v)) == 0)
+
+/*
+ * atomic_read()
+ * 	Acquire the atomic lock and read the variable.
+ */
+static inline int atomic_read(const atomic_t *v)
+{
+	int ret;
+	const atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	ret = vt->counter;
+	__atomic_lock_release();
+
+	return ret;
+}
+
+/*
+ * atomic_set()
+ * 	Acquire the atomic lock and set the variable.
+ */
+static inline void atomic_set(atomic_t *v, int i)
+{
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	vt->counter = i;
+	__atomic_lock_release();
+}
+
+/*
+ * atomic_cmpxchg
+ * 	Acquire the atomic lock and exchange if current == old.
+ */
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
+{
+	int prev;
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	prev = vt->counter;
+	if (prev == old) {
+		vt->counter = new;
+	}
+	__atomic_lock_release();
+
+	return prev;
+}
+
+/*
+ * atomic_xchg()
+ * 	Acquire the atomic lock and exchange values.
+ */
+static inline int atomic_xchg(atomic_t *v, int new)
+{
+	int prev;
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	prev = vt->counter;
+	vt->counter = new;
+	__atomic_lock_release();
+
+	return prev;
+}
+
+/*
+ * atomic_add_unless()
+ * 	Acquire the atomic lock and add a unless the value is u.
+ */
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+	int prev;
+	atomic_t *vt = v;
+
+	__atomic_lock_acquire();
+	prev = vt->counter;
+	if (prev != u) {
+		vt->counter += a;
+		__atomic_lock_release();
+		return 1;
+	}
+
+	__atomic_lock_release();
+	return 0;
+}
+
+#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
+
+#include <asm-generic/atomic.h>
+
+/* 
+ * The following is not a real function.  The compiler should remove the function
+ * call as long as the user does not pass in a size that __xchg and __cmpxchg
+ * are not prepared for.  If the user does pass in an unknown size, the user
+ * will get a link time error.
+ *
+ * The no return is to prevent a compiler error that can occur when dealing with
+ * uninitialized variables. Given that the function doesn't exist there is no
+ * net effect (and if it did it would not return).
+ */
+extern void __xchg_called_with_bad_pointer(void) __attribute__((noreturn));
+
+/*
+ * __xchg()
+ *	Xchange *ptr for x atomically.
+ *
+ * Must be both locally atomic and atomic on SMP. Ubicom32 does not have an
+ * atomic exchange instruction so we use the global atomic_lock.
+ */
+static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
+{
+	unsigned long ret;
+
+	__atomic_lock_acquire();
+
+	switch (size) {
+	case 1:
+		ret = *(volatile unsigned char *)ptr;
+		*(volatile unsigned char *)ptr = x;
+		break;
+
+	case 2:
+		ret = *(volatile unsigned short *)ptr;
+		*(volatile unsigned short *)ptr = x;
+		break;
+
+	case 4:
+		ret = *(volatile unsigned int *)ptr;
+		*(volatile unsigned int *)ptr = x;
+		break;
+
+	default:
+		__xchg_called_with_bad_pointer();
+		break;
+	}
+	__atomic_lock_release();
+	return ret;
+}
+
+#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
+
+/*
+ * __cmpxchg()
+ *	Compare and Xchange *ptr for x atomically.
+ *
+ * Must be both locally atomic and atomic on SMP. Ubicom32 does not have an
+ * atomic exchange instruction so we use the global atomic_lock.
+ */
+static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, unsigned long next, int size)
+{
+	unsigned long prev;
+
+	__atomic_lock_acquire();
+	switch (size) {
+	case 1: 
+		prev = *(u8 *)ptr;
+		if (prev == old) {
+			*(u8 *)ptr = (u8)next;
+		}
+		break;
+
+	case 2: 
+		prev = *(u16 *)ptr;
+		if (prev == old) {
+			*(u16 *)ptr = (u16)next;
+		}
+		break;
+
+	case 4: 
+		prev = *(u32 *)ptr;
+		if (prev == old) {
+			*(u32 *)ptr = (u32)next;
+		}
+		break;
+
+	default:
+		__xchg_called_with_bad_pointer();
+		break;
+	}
+	__atomic_lock_release();
+	return prev;
+}
+
+/*
+ * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
+ * them available.
+ */
+#define cmpxchg_local(ptr, o, n) \
+	((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), sizeof(*(ptr))))
+
+#define cmpxchg(ptr, o, n) __cmpxchg((ptr), (o), (n), sizeof(*(ptr)))
+
+#define smp_mb__before_atomic_inc() asm volatile ("" : : : "memory")
+#define smp_mb__after_atomic_inc() asm volatile ("" : : : "memory")
+#define smp_mb__before_atomic_dec() asm volatile ("" : : : "memory")
+#define smp_mb__after_atomic_dec() asm volatile ("" : : : "memory")
+
+#endif /* _ASM_UBICOM32_ATOMIC_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/audio_tio.h
@@ -0,0 +1,124 @@
+/*
+ * arch/ubicom32/include/asm/audio_tio.h
+ *	AudioTIO include file
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _AUDIO_TIO_H
+#define _AUDIO_TIO_H
+
+#include <asm/devtree.h>
+#include <asm/ubi32-pcm.h>
+
+#define UBI32_AUDIO_INT_FLAG_MORE_SAMPLES 0x00000001
+#define UBI32_AUDIO_INT_FLAG_COMMAND      0x00000002
+
+/*
+ * Commands the Primary OS sends to the audio device
+ */
+enum ubi32_audio_command {
+	UBI32_AUDIO_CMD_NONE,
+	UBI32_AUDIO_CMD_START,
+	UBI32_AUDIO_CMD_STOP,
+	UBI32_AUDIO_CMD_PAUSE,
+	UBI32_AUDIO_CMD_RESUME,
+	UBI32_AUDIO_CMD_MUTE,
+	UBI32_AUDIO_CMD_UNMUTE,
+	UBI32_AUDIO_CMD_SETUP,
+	UBI32_AUDIO_CMD_ENABLE,
+	UBI32_AUDIO_CMD_DISABLE,
+};
+
+/*
+ * Flag bits passed in the registers
+ */
+#define UBI32_CMD_SETUP_FLAG_LE		(1 << 0)	/* Use Little Endian Mode */
+
+/*
+ * Status bits that audio device can set to indicate reason
+ * for interrupting the Primary OS
+ */
+#define UBI32_AUDIO_STATUS_PLAY_DMA0_REQUEST (1 << 0) /* Audio device needs samples in DMA0 for playback */
+#define UBI32_AUDIO_STATUS_PLAY_DMA1_REQUEST (1 << 1) /* Audio device needs samples in DMA1 for playback */
+
+struct ubi32_audio_dma {
+	/*
+	 * NOTE: The active flag shall only be SET by the producer and CLEARED
+	 * by the consumer, NEVER the other way around.  For playback, the
+	 * Primary OS sets this flag and ipAudioTIO clears it.
+	 *
+	 * The producer shall not modify the ptr or ctr fields when the transfer
+	 * is marked as active, as these are used by the consumer to do the
+	 * transfer.
+	 */
+	volatile uint32_t active; 		/* Nonzero if data in ptr/ctr ready to be transferred */
+	//volatile u32_t active; 		/* Nonzero if data in ptr/ctr ready to be transferred */
+	volatile void *ptr;		/* Pointer to data to be transferred */
+	volatile uint32_t ctr; 	/* Counter: number of data units to transfer */
+	//volatile u32_t ctr; 		/* Counter: number of data units to transfer */
+};
+
+#define AUDIOTIONODE_CAP_BE	(1 << 0)
+#define AUDIOTIONODE_CAP_LE	(1 << 1)
+
+/*
+ * Resource indices used to access IRQs via platform_get_resource
+ */
+#define AUDIOTIO_MEM_RESOURCE		0
+#define AUDIOTIO_TX_IRQ_RESOURCE	0
+#define AUDIOTIO_RX_IRQ_RESOURCE	1
+
+#define AUDIOTIONODE_VERSION	5
+struct audiotionode {
+	struct devtree_node dn;
+	uint32_t version;				/* Version of this node */
+	struct audiotioregs *regs;
+};
+
+#define AUDIOTIOREGS_VERSION	3
+struct audiotioregs {
+	uint32_t version;
+	uint32_t caps;					/* Capabilities of the driver */
+	u32_t *sample_rates;				/* Sample Rates supported by this driver */
+	u32_t n_sample_rates;				/* Number of sample rates supported by this driver */
+	u32_t channel_mask;				/* The channel configs supported by this driver (bit 1 = 1 channel, etc) */
+	volatile uint32_t int_flags;			/* Reason for interrupting audio device */
+	volatile enum ubi32_audio_command command;	/* Command from Primary OS */
+	volatile uint32_t flags;			/* Flag bits for this command */
+	volatile uint32_t channels;			/* Number of channels in stream */
+	volatile uint32_t sample_rate;			/* Sample rate */
+	volatile uint32_t status;			/* Status bits sent from AudioTIO to Primary OS */
+	volatile void *current_read_pos;		/* Position of next sample to be removed from Primary OS sample buffer */
+
+	/*
+	 * These are the transfer requests.  They are used in alternating
+	 * order so that when ipAudioTIO is processing one request, the
+	 * Primary OS can fill in the other one.
+	 *
+	 * NOTE: The active bit shall always be SET by the producer and
+	 * CLEARED by the consumer, NEVER the other way around.
+	 */
+	struct ubi32_audio_dma playback_xfer_requests[2];
+};
+
+extern struct platform_device * __init audio_tio_alloc(const char *driver_name, const char *node_name, int priv_size);
+
+#define audio_tio_priv(pdev) (((struct ubi32pcm_platform_data *)(((struct platform_device *)(pdev))->dev.platform_data))->priv_data)
+#endif
--- /dev/null
+++ b/arch/ubicom32/include/asm/auxvec.h
@@ -0,0 +1,32 @@
+/*
+ * arch/ubicom32/include/asm/auxvec.h
+ *   Symbolic values for the entries in the auxiliary table
+ *   put on the initial stack.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_AUXVEC_H
+#define _ASM_UBICOM32_AUXVEC_H
+
+#endif /* _ASM_UBICOM32_AUXVEC_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/bitops.h
@@ -0,0 +1,171 @@
+/*
+ * arch/ubicom32/include/asm/bitops.h
+ *   Bit manipulation definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_BITOPS_H
+#define _ASM_UBICOM32_BITOPS_H
+
+/*
+ * Copyright 1992, Linus Torvalds.
+ */
+
+#include <linux/compiler.h>
+#include <asm/byteorder.h>	/* swab32 */
+
+#ifdef __KERNEL__
+
+#ifndef _LINUX_BITOPS_H
+#error only <linux/bitops.h> can be included directly
+#endif
+
+#include <asm-generic/bitops/ffs.h>
+#include <asm-generic/bitops/__ffs.h>
+
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/ffz.h>
+
+#include <asm/ubicom32-common.h>
+
+static inline void set_bit(int bit, volatile unsigned long *p)
+{
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	*p |= mask;
+	__atomic_lock_release();
+}
+
+static inline void clear_bit(int bit, volatile unsigned long *p)
+{
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	*p &= ~mask;
+	__atomic_lock_release();
+}
+
+/*
+ * clear_bit() doesn't provide any barrier for the compiler.
+ */
+#define smp_mb__before_clear_bit()	barrier()
+#define smp_mb__after_clear_bit()	barrier()
+
+static inline void change_bit(int bit, volatile unsigned long *p)
+{
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	*p ^= mask;
+	__atomic_lock_release();
+}
+
+static inline int test_and_set_bit(int bit, volatile unsigned long *p)
+{
+	unsigned int res;
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	res = *p;
+	*p = res | mask;
+	__atomic_lock_release();
+
+	return res & mask;
+}
+
+static inline int test_and_clear_bit(int bit, volatile unsigned long *p)
+{
+	unsigned int res;
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	res = *p;
+	*p = res & ~mask;
+	__atomic_lock_release();
+
+	return res & mask;
+}
+
+static inline int test_and_change_bit(int bit, volatile unsigned long *p)
+{
+	unsigned int res;
+	unsigned long mask = 1UL << (bit & 31);
+
+	p += bit >> 5;
+
+	__atomic_lock_acquire();
+	res = *p;
+	*p = res ^ mask;
+	__atomic_lock_release();
+
+	return res & mask;
+}
+
+#include <asm-generic/bitops/non-atomic.h>
+
+/*
+ * This routine doesn't need to be atomic.
+ */
+static inline int __constant_test_bit(int nr, const volatile unsigned long *addr)
+{
+	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
+}
+
+static inline int __test_bit(int nr, const volatile unsigned long *addr)
+{
+	int 	* a = (int *) addr;
+	int	mask;
+
+	a += nr >> 5;
+	mask = 1 << (nr & 0x1f);
+	return ((mask & *a) != 0);
+}
+
+#define test_bit(nr,addr) (__builtin_constant_p(nr) ?  __constant_test_bit((nr),(addr)) :  __test_bit((nr),(addr)))
+
+#include <asm-generic/bitops/find.h>
+#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/lock.h>
+
+#include <asm-generic/bitops/ext2-non-atomic.h>
+#include <asm-generic/bitops/ext2-atomic.h>
+#include <asm-generic/bitops/minix.h>
+
+#endif /* __KERNEL__ */
+
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/fls64.h>
+
+#endif /* _ASM_UBICOM32_BITOPS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/board.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/board.h
+ *   Board init and revision definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_BOARD_H
+#define _ASM_UBICOM32_BOARD_H
+
+extern const char *board_get_revision(void);
+extern void __init board_init(void);
+
+#endif /* _ASM_UBICOM32_BOARD_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/bootargs.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/bootargs.h
+ *   Kernel command line via the devtree API.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_BOOTARGS_H
+#define _ASM_UBICOM32_BOOTARGS_H
+
+extern const char *bootargs_get_cmdline(void);
+extern void __init bootargs_init(void);
+
+#endif /* _ASM_UBICOM32_BOOTARGS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/bootinfo.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/bootinfo.h
+ *   Definitions of firmware boot parameters passed to the kernel.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_BOOTINFO_H
+#define _ASM_UBICOM32_BOOTINFO_H
+
+/* Nothing for ubicom32 */
+
+#endif /* _ASM_UBICOM32_BOOTINFO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/bug.h
@@ -0,0 +1,53 @@
+/*
+ * arch/ubicom32/include/asm/bug.h
+ *   Generic bug.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_BUG_H
+#define _ASM_UBICOM32_BUG_H
+
+#include <linux/kernel.h>
+#include <asm/thread.h>
+
+#if defined(CONFIG_STOP_ON_BUG)
+/*
+ *  __BUG_ON()
+ *  	Stall all threads to enable debugging.
+ */
+static inline void __BUG_ON(unsigned long c)
+{
+	if (unlikely(c)) {
+		THREAD_STALL;
+	}
+	return;
+}
+
+#define BUG_ON(c) __BUG_ON((unsigned long)(c))
+#define HAVE_ARCH_BUG_ON
+#endif
+
+#include <asm-generic/bug.h>
+
+#endif /* _ASM_UBICOM32_BUG_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/bugs.h
@@ -0,0 +1,44 @@
+/*
+ * arch/ubicom32/include/asm/bugs.h
+ *   Definition of check_bugs() for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1994  Linus Torvalds
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+/*
+ * This is included by init/main.c to check for architecture-dependent bugs.
+ *
+ * Needs:
+ *	void check_bugs(void);
+ */
+
+#ifndef _ASM_UBICOM32_BUGS_H
+#define _ASM_UBICOM32_BUGS_H
+
+static void check_bugs(void)
+{
+}
+
+#endif /* _ASM_UBICOM32_BUGS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/byteorder.h
@@ -0,0 +1,48 @@
+/*
+ * arch/ubicom32/include/asm/byteorder.h
+ *   Byte order swapping utility routines.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_BYTEORDER_H
+#define _ASM_UBICOM32_BYTEORDER_H
+
+#include <linux/types.h>
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+#  define __BYTEORDER_HAS_U64__
+#  define __SWAB_64_THRU_32__
+#endif
+
+#if defined(IP7000) || defined(IP7000_REV2)
+
+#define __arch__swab16 __builtin_ubicom32_swapb_2
+#define __arch__swab32 __builtin_ubicom32_swapb_4
+
+#endif /* IP7000 */
+
+#include <linux/byteorder/big_endian.h>
+
+#endif /* _ASM_UBICOM32_BYTEORDER_H */
+
--- /dev/null
+++ b/arch/ubicom32/include/asm/cachectl.h
@@ -0,0 +1,39 @@
+/*
+ * arch/ubicom32/include/asm/cachectl.h
+ *   Ubicom32 cache control definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CACHECTL_H
+#define _ASM_UBICOM32_CACHECTL_H
+
+#include <asm/ip5000.h>
+
+/*
+ * mem_cache_control()
+ *	Special cache control operation
+ */
+extern void mem_cache_control(unsigned long cc, unsigned long begin_addr, unsigned long end_addr, unsigned long op);
+
+#endif /* _ASM_UBICOM32_CACHECTL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/cacheflush.h
@@ -0,0 +1,104 @@
+/*
+ * arch/ubicom32/include/asm/cacheflush.h
+ *   Cache flushing definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CACHEFLUSH_H
+#define _ASM_UBICOM32_CACHEFLUSH_H
+
+/*
+ * (C) Copyright 2000-2004, Greg Ungerer <gerg@snapgear.com>
+ */
+#include <linux/mm.h>
+#include <asm/cachectl.h>
+#include <asm/ip5000.h>
+
+#define flush_cache_all()			__flush_cache_all()
+#define flush_cache_mm(mm)			do { } while (0)
+#define flush_cache_dup_mm(mm)			do { } while (0)
+#define flush_cache_range(vma, start, end)	__flush_cache_all()
+#define flush_cache_page(vma, vmaddr)		do { } while (0)
+#define flush_dcache_page(page)			do { } while (0)
+#define flush_dcache_mmap_lock(mapping)		do { } while (0)
+#define flush_dcache_mmap_unlock(mapping)	do { } while (0)
+
+#define flush_dcache_range(start, end)					\
+do {									\
+	/* Flush the data cache and invalidate the I cache. */		\
+	local_irq_disable();						\
+	mem_cache_control(DCCR_BASE, start, end, CCR_CTRL_FLUSH_ADDR);	\
+	mem_cache_control(ICCR_BASE, start, end, CCR_CTRL_INV_ADDR);	\
+	local_irq_enable();						\
+} while (0)
+
+#define flush_icache_range(start, end)					\
+do {									\
+	/* Flush the data cache and invalidate the I cache. */		\
+	local_irq_disable();						\
+	mem_cache_control(DCCR_BASE, start, end, CCR_CTRL_FLUSH_ADDR);	\
+	mem_cache_control(ICCR_BASE, start, end, CCR_CTRL_INV_ADDR);	\
+	local_irq_enable();						\
+} while (0)
+
+#define flush_icache_page(vma,pg)		do { } while (0)
+#define flush_icache_user_range(vma,pg,adr,len)	do { } while (0)
+#define flush_cache_vmap(start, end)		do { } while (0)
+#define flush_cache_vunmap(start, end)		do { } while (0)
+
+#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
+	memcpy(dst, src, len)
+#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
+	memcpy(dst, src, len)
+
+/*
+ * Cache handling for IP5000
+ */
+extern inline void mem_cache_invalidate_all(unsigned long cc)
+{
+	asm volatile (
+	"	bset	"D(CCR_CTRL)"(%0), "D(CCR_CTRL)"(%0), #"D(CCR_CTRL_RESET)"	\n\t"
+	"	nop									\n\t"
+	"	bclr	"D(CCR_CTRL)"(%0), "D(CCR_CTRL)"(%0), #"D(CCR_CTRL_RESET)"	\n\t"
+	"	pipe_flush 0								\n\t"
+		:
+		: "a"(cc)
+		: "cc"
+	);
+}
+
+static inline void __flush_cache_all(void)
+{
+	/*
+	 * Flush Icache
+	 */
+	mem_cache_invalidate_all(ICCR_BASE);
+
+	/*
+	 * Flush Dcache
+	 */
+	mem_cache_invalidate_all(DCCR_BASE);
+}
+
+#endif /* _ASM_UBICOM32_CACHEFLUSH_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/cache.h
@@ -0,0 +1,40 @@
+/*
+ * arch/ubicom32/include/asm/cache.h
+ *   Cache line definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CACHE_H
+#define _ASM_UBICOM32_CACHE_H
+
+/*
+ * bytes per L1 cache line
+ */
+#define L1_CACHE_SHIFT  5
+#define L1_CACHE_BYTES  (1 << L1_CACHE_SHIFT)
+
+#define __cacheline_aligned
+#define ____cacheline_aligned
+
+#endif /* _ASM_UBICOM32_CACHE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/checksum.h
@@ -0,0 +1,149 @@
+/*
+ * arch/ubicom32/include/asm/checksum.h
+ *   Checksum utilities for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CHECKSUM_H
+#define _ASM_UBICOM32_CHECKSUM_H
+
+#include <linux/in6.h>
+
+/*
+ * computes the checksum of a memory block at buff, length len,
+ * and adds in "sum" (32-bit)
+ *
+ * returns a 32-bit number suitable for feeding into itself
+ * or csum_tcpudp_magic
+ *
+ * this function must be called with even lengths, except
+ * for the last fragment, which may be odd
+ *
+ * it's best to have buff aligned on a 32-bit boundary
+ */
+__wsum csum_partial(const void *buff, int len, __wsum sum);
+
+/*
+ * the same as csum_partial, but copies from src while it
+ * checksums
+ *
+ * here even more important to align src and dst on a 32-bit (or even
+ * better 64-bit) boundary
+ */
+
+__wsum csum_partial_copy_nocheck(const void *src, void *dst,
+	int len, __wsum sum);
+
+
+/*
+ * the same as csum_partial_copy, but copies from user space.
+ *
+ * here even more important to align src and dst on a 32-bit (or even
+ * better 64-bit) boundary
+ */
+
+extern __wsum csum_partial_copy_from_user(const void __user *src,
+	void *dst, int len, __wsum sum, int *csum_err);
+
+__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
+
+/*
+ *	Fold a partial checksum
+ */
+
+static inline __sum16 csum_fold(__wsum sum)
+{
+	asm volatile (
+	"	lsr.4	d15, %0, #16	\n\t"
+	"	bfextu	%0, %0, #16	\n\t"
+	"	add.4	%0, d15, %0	\n\t"
+	"	lsr.4	d15, %0, #16	\n\t"
+	"	bfextu	%0, %0, #16	\n\t"
+	"	add.4	%0, d15, %0	\n\t"
+		: "=&d" (sum)
+		: "0"(sum)
+		: "d15"
+	);
+	return (__force __sum16)~sum;
+}
+
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+
+static inline __wsum
+csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
+		  unsigned short proto, __wsum sum)
+{
+	asm volatile (
+	"	add.4	%0, %2, %0	\n\t"
+	"	addc	%0, %3, %0	\n\t"
+	"	addc	%0, %4, %0	\n\t"
+	"	addc	%0, %5, %0	\n\t"
+	"	addc	%0, #0, %0	\n\t"
+		: "=&d" (sum)
+		: "0"(sum), "r" (saddr), "r" (daddr), "r" (len), "r"(proto)
+	);
+	return sum;
+}
+
+static inline __sum16
+csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
+		  unsigned short proto, __wsum sum)
+{
+	return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
+}
+
+/*
+ * this routine is used for miscellaneous IP-like checksums, mainly
+ * in icmp.c
+ */
+extern __sum16 ip_compute_csum(const void *buff, int len);
+
+#define _HAVE_ARCH_IPV6_CSUM
+
+static __inline__ __sum16
+csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr,
+		__u32 len, unsigned short proto, __wsum sum)
+{
+	asm volatile (
+	"	add.4	%0, 0(%2), %0	\n\t"
+	"	addc	%0, 4(%2), %0	\n\t"
+	"	addc	%0, 8(%2), %0	\n\t"
+	"	addc	%0, 12(%2), %0	\n\t"
+	"	addc	%0, 0(%3), %0	\n\t"
+	"	addc	%0, 4(%3), %0	\n\t"
+	"	addc	%0, 8(%3), %0	\n\t"
+	"	addc	%0, 12(%3), %0	\n\t"
+	"	addc	%0, %4, %0	\n\t"
+	"	addc	%0, #0, %0	\n\t"
+		: "=&d" (sum)
+		: "0" (sum), "a" (saddr), "a" (daddr), "d" (len + proto)
+	);
+	return csum_fold(sum);
+}
+
+#endif /* _ASM_UBICOM32_CHECKSUM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/cpu.h
@@ -0,0 +1,45 @@
+/*
+ * arch/ubicom32/include/asm/cpu.h
+ *   CPU definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004-2005 ARM Ltd.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CPU_H
+#define _ASM_UBICOM32_CPU_H
+
+#include <linux/percpu.h>
+
+struct cpuinfo_ubicom32 {
+	unsigned long tid;			/* Hardware thread number */
+
+#ifdef CONFIG_SMP
+	volatile unsigned long ipi_pending;	/* Bit map of operations to execute */
+	unsigned long ipi_count;		/* Number of IPI(s) taken on this cpu */
+#endif
+};
+
+DECLARE_PER_CPU(struct cpuinfo_ubicom32, cpu_data);
+
+#endif /* _ASM_UBICOM32_CPU_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/cputime.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/cputime.h
+ *   Generic cputime.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CPUTIME_H
+#define _ASM_UBICOM32_CPUTIME_H
+
+#include <asm-generic/cputime.h>
+
+#endif /* _ASM_UBICOM32_CPUTIME_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/current.h
@@ -0,0 +1,44 @@
+/*
+ * arch/ubicom32/include/asm/current.h
+ *   Definition of get_current() for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * (C) Copyright 2000, Lineo, David McCullough <davidm@uclinux.org>
+ * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_CURRENT_H
+#define _ASM_UBICOM32_CURRENT_H
+
+#include <linux/thread_info.h>
+
+struct task_struct;
+
+static inline struct task_struct *get_current(void)
+{
+	return(current_thread_info()->task);
+}
+
+#define	current	get_current()
+
+#endif /* _ASM_UBICOM32_CURRENT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/delay.h
@@ -0,0 +1,75 @@
+/*
+ * arch/ubicom32/include/asm/delay.h
+ *   Definition of delay routines for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_DELAY_H
+#define _ASM_UBICOM32_DELAY_H
+
+#include <asm/param.h>
+#include <asm/ip5000.h>
+
+static inline void __delay(unsigned long loops)
+{
+	if (loops == 0) {
+		return;
+	}
+
+	asm volatile (
+	"1:	add.4	%0, #-1, %0		\n\t"
+	"	jmpne.t	1b			\n\t"
+	: "+d" (loops)
+	);
+}
+
+/*
+ *	Ubicom32 processor uses fixed 12MHz external OSC.
+ *	So we use that as reference to count 12 cycles/us
+ */
+
+extern unsigned long loops_per_jiffy;
+
+static inline void _udelay(unsigned long usecs)
+{
+#if defined(CONFIG_UBICOM32_V4) || defined(CONFIG_UBICOM32_V3)
+	asm volatile (
+		"	add.4		d15, 0(%0), %1			\n\t"
+		"	sub.4		#0, 0(%0), d15			\n\t"
+		"	jmpmi.w.f	.-4				\n\t"
+		:
+		: "a"(TIMER_BASE + TIMER_MPTVAL), "d"(usecs * (12000000/1000000))
+		: "d15"
+	);
+#else
+	BUG();
+#endif
+}
+
+/*
+ *	Moved the udelay() function into library code, no longer inlined.
+ */
+extern void udelay(unsigned long usecs);
+
+#endif /* _ASM_UBICOM32_DELAY_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/device.h
@@ -0,0 +1,35 @@
+/*
+ * arch/ubicom32/include/asm/device.h
+ *   Generic device.h for Ubicom32 architecture.
+ *
+ *   Used for arch specific extensions to struct device
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_DEVICE_H
+#define _ASM_UBICOM32_DEVICE_H
+
+#include <asm-generic/device.h>
+
+#endif /* _ASM_UBICOM32_DEVICE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/devtree.h
@@ -0,0 +1,52 @@
+/*
+ * arch/ubicom32/include/asm/devtree.h
+ *   Device Tree Header File (Shared between ultra and the Host OS)
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_DEVTREE_H
+#define _ASM_UBICOM32_DEVTREE_H
+
+#define DEVTREE_MAX_NAME 32
+#define DEVTREE_IRQ_NONE 0xff
+#define DEVTREE_IRQ_DONTCARE 0xff
+#define DEVTREE_NODE_MAGIC 0x10203040
+
+struct devtree_node {
+	struct devtree_node *next;
+	unsigned char sendirq;
+	unsigned char recvirq;
+	char name[DEVTREE_MAX_NAME];
+	unsigned int magic;
+};
+
+extern struct devtree_node *devtree;
+extern struct devtree_node *devtree_find_by_irq(uint8_t sendirq, uint8_t recvirq);
+extern struct devtree_node *devtree_find_node(const char *str);
+extern struct devtree_node *devtree_find_next(struct devtree_node **cur);
+extern int devtree_irq(struct devtree_node *dn, unsigned char *sendirq, unsigned char *recvirq);
+extern void devtree_print(void);
+
+#endif /* _ASM_UBICOM32_DEVTREE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/div64.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/div64.h
+ *   Generic div64.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_DIV64_H
+#define _ASM_UBICOM32_DIV64_H
+
+#include <asm-generic/div64.h>
+
+#endif /* _ASM_UBICOM32_DIV64_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/dma.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/dma.h
+ *   DMA definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_DMA_H
+#define _ASM_UBICOM32_DMA_H
+
+/* Nothing so far */
+#define MAX_DMA_ADDRESS 0x00	/* This is quite suspicious */
+
+#endif /* _ASM_UBICOM32_DMA_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/dma-mapping.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/dma-mapping.h
+ *   Generic dma-mapping.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_DMA_MAPPING_H
+#define _ASM_UBICOM32_DMA_MAPPING_H
+
+#include <linux/scatterlist.h>
+#include <asm-generic/dma-mapping.h>
+
+#endif /* _ASM_UBICOM32_DMA_MAPPING_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/elf.h
@@ -0,0 +1,167 @@
+/*
+ * arch/ubicom32/include/asm/elf.h
+ *   Definitions for elf executable format for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_ELF_H
+#define _ASM_UBICOM32_ELF_H
+
+/*
+ * ELF register definitions..
+ */
+
+#include <asm/ptrace.h>
+#include <asm/user.h>
+
+/*
+ * Processor specific flags for the ELF header e_flags field.
+ */
+#define EF_UBICOM32_V3		0x00000001	/* -fmarch=ubicom32v3 */
+#define EF_UBICOM32_V4		0x00000002	/* -fmarch=ubicom32v4 */
+#define EF_UBICOM32_PIC		0x80000000	/* -fpic */
+#define EF_UBICOM32_FDPIC	0x40000000	/* -mfdpic */
+
+/*
+ * Ubicom32 ELF relocation types
+ */
+#define R_UBICOM32_NONE			0
+#define R_UBICOM32_16			1
+#define R_UBICOM32_32			2
+#define R_UBICOM32_LO16			3
+#define R_UBICOM32_HI16			4
+#define R_UBICOM32_21_PCREL		5
+#define R_UBICOM32_24_PCREL		6
+#define R_UBICOM32_HI24			7
+#define R_UBICOM32_LO7_S		8
+#define R_UBICOM32_LO7_2_S		9
+#define R_UBICOM32_LO7_4_S		10
+#define R_UBICOM32_LO7_D		11
+#define R_UBICOM32_LO7_2_D		12
+#define R_UBICOM32_LO7_4_D		13
+#define R_UBICOM32_32_HARVARD		14
+#define R_UBICOM32_LO7_CALLI		15
+#define R_UBICOM32_LO16_CALLI		16
+#define R_UBICOM32_GOT_HI24		17
+#define R_UBICOM32_GOT_LO7_S		18
+#define R_UBICOM32_GOT_LO7_2_S		19
+#define R_UBICOM32_GOT_LO7_4_S		20
+#define R_UBICOM32_GOT_LO7_D		21
+#define R_UBICOM32_GOT_LO7_2_D		22
+#define R_UBICOM32_GOT_LO7_4_D		23
+#define R_UBICOM32_FUNCDESC_GOT_HI24    24
+#define R_UBICOM32_FUNCDESC_GOT_LO7_S   25
+#define R_UBICOM32_FUNCDESC_GOT_LO7_2_S 26
+#define R_UBICOM32_FUNCDESC_GOT_LO7_4_S 27
+#define R_UBICOM32_FUNCDESC_GOT_LO7_D   28
+#define R_UBICOM32_FUNCDESC_GOT_LO7_2_D 29
+#define R_UBICOM32_FUNCDESC_GOT_LO7_4_D 30
+#define R_UBICOM32_GOT_LO7_CALLI        31
+#define R_UBICOM32_FUNCDESC_GOT_LO7_CALLI 32
+#define R_UBICOM32_FUNCDESC_VALUE       33
+#define R_UBICOM32_FUNCDESC             34
+#define R_UBICOM32_GOTOFFSET_LO         35
+#define R_UBICOM32_GOTOFFSET_HI         36
+#define R_UBICOM32_FUNCDESC_GOTOFFSET_LO 37
+#define R_UBICOM32_FUNCDESC_GOTOFFSET_HI 38
+#define R_UBICOM32_GNU_VTINHERIT        200
+#define R_UBICOM32_GNU_VTENTRY          201
+
+typedef unsigned long elf_greg_t;
+
+#define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+typedef struct user_ubicom32fp_struct elf_fpregset_t;
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ((x)->e_machine == EM_UBICOM32)
+
+#define elf_check_fdpic(x) ((x)->e_flags & EF_UBICOM32_FDPIC)
+
+#define elf_check_const_displacement(x) ((x)->e_flags & EF_UBICOM32_PIC)
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS	ELFCLASS32
+#define ELF_DATA	ELFDATA2MSB
+#define ELF_ARCH	EM_UBICOM32
+
+/* For SVR4/m68k the function pointer to be registered with `atexit' is
+   passed in %a1.  Although my copy of the ABI has no such statement, it
+   is actually used on ASV.  */
+#define ELF_PLAT_INIT(_r, load_addr)	_r->a1 = 0
+
+#define ELF_FDPIC_PLAT_INIT(_regs, _exec_map_addr, _interp_map_addr,	\
+			    _dynamic_addr)				\
+	do {								\
+		_regs->dn[1]	= _exec_map_addr;			\
+		_regs->dn[2]	= _interp_map_addr;			\
+		_regs->dn[3]	= _dynamic_addr;			\
+		_regs->an[1]	= 0; /* dl_fini will be set by ldso */	\
+	} while (0)
+
+#define USE_ELF_CORE_DUMP
+#define ELF_EXEC_PAGESIZE	4096
+
+#ifdef __KERNEL__
+#ifdef CONFIG_UBICOM32_V4
+#define ELF_FDPIC_CORE_EFLAGS	(EF_UBICOM32_FDPIC | EF_UBICOM32_V4)
+#elif defined CONFIG_UBICOM32_V3
+#define ELF_FDPIC_CORE_EFLAGS	(EF_UBICOM32_FDPIC | EF_UBICOM32_V3)
+#else
+#error Unknown/Unsupported ubicom32 architecture.
+#endif
+#endif
+
+/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+   use of this is to invoke "./ld.so someprog" to test out a new version of
+   the loader.  We need to make sure that it is out of the way of the program
+   that it will "exec", and that there is sufficient room for the brk.  */
+
+#define ELF_ET_DYN_BASE         0xD0000000UL
+
+/*
+ * For Ubicom32, the elf_gregset_t and struct pt_regs are the same size
+ * data structure so a copy is performed instead of providing the
+ * ELF_CORE_COPY_REGS macro.
+ */
+
+/* This yields a mask that user programs can use to figure out what
+   instruction set this cpu supports.  */
+
+#define ELF_HWCAP	(0)
+
+/* This yields a string that ld.so will use to load implementation
+   specific libraries for optimization.  This is more specific in
+   intent than poking at uname or /proc/cpuinfo.  */
+
+#define ELF_PLATFORM  (NULL)
+
+#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
+
+#endif /* _ASM_UBICOM32_ELF_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/emergency-restart.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/emergency-restart.h
+ *   Generic emergency-restart.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_EMERGENCY_RESTART_H
+#define _ASM_UBICOM32_EMERGENCY_RESTART_H
+
+#include <asm-generic/emergency-restart.h>
+
+#endif /* _ASM_UBICOM32_EMERGENCY_RESTART_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/entry.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/entry.h
+ *   Entry register/stack definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_ENTRY_H
+#define _ASM_UBICOM32_ENTRY_H
+
+#include <asm/setup.h>
+#include <asm/page.h>
+
+#endif /* _ASM_UBICOM32_ENTRY_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/errno.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/errno.h
+ *   Generic errno.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_ERRNO_H
+#define _ASM_UBICOM32_ERRNO_H
+
+#include <asm-generic/errno.h>
+
+#endif /* _ASM_UBICOM32_ERRNO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/fb.h
@@ -0,0 +1,39 @@
+/*
+ * arch/ubicom32/include/asm/fb.h
+ *   Definition of fb_is_primary_device() for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_FB_H
+#define _ASM_UBICOM32_FB_H
+#include <linux/fb.h>
+
+#define fb_pgprotect(...) do {} while (0)
+
+static inline int fb_is_primary_device(struct fb_info *info)
+{
+	return 0;
+}
+
+#endif /* _ASM_UBICOM32_FB_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/fcntl.h
@@ -0,0 +1,38 @@
+/*
+ * arch/ubicom32/include/asm/fcntl.h
+ *   File control bit definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_FCNTL_H
+#define _ASM_UBICOM32_FCNTL_H
+
+#define O_DIRECTORY	040000	/* must be a directory */
+#define O_NOFOLLOW	0100000	/* don't follow links */
+#define O_DIRECT	0200000	/* direct disk access hint - currently ignored */
+#define O_LARGEFILE	0400000
+
+#include <asm-generic/fcntl.h>
+
+#endif /* _ASM_UBICOM32_FCNTL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/flat.h
@@ -0,0 +1,73 @@
+/*
+ * arch/ubicom32/include/asm/flat.h
+ *   Definitions to support flat-format executables.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_FLAT_H
+#define _ASM_UBICOM32_FLAT_H
+
+#define ARCH_FLAT_ALIGN 0x80
+#define ARCH_FLAT_ALIGN_TEXT 1
+
+#define  R_UBICOM32_32		2
+#define  R_UBICOM32_HI24	7
+#define  R_UBICOM32_LO7_S	8
+#define  R_UBICOM32_LO7_2_S	9
+#define  R_UBICOM32_LO7_4_S	10
+#define  R_UBICOM32_LO7_D	11
+#define  R_UBICOM32_LO7_2_D	12
+#define  R_UBICOM32_LO7_4_D	13
+#define  R_UBICOM32_LO7_CALLI	15
+#define  R_UBICOM32_LO16_CALLI	16
+
+extern void ubicom32_flat_put_addr_at_rp(unsigned long *rp, u32_t val, u32_t rval, unsigned long  *p);
+extern unsigned long ubicom32_flat_get_addr_from_rp(unsigned long *rp, u32_t relval, u32_t flags, unsigned long *p);
+
+#define	flat_stack_align(sp)			/* nothing needed */
+#define	flat_argvp_envp_on_stack()		1
+#define	flat_old_ram_flag(flags)		(flags)
+#define	flat_reloc_valid(reloc, size)		((reloc) <= (size))
+#define	flat_get_addr_from_rp(rp, relval, flags, p)	(ubicom32_flat_get_addr_from_rp(rp, relval,flags, p))
+#define	flat_put_addr_at_rp(rp, val, relval)	do {ubicom32_flat_put_addr_at_rp(rp, val, relval, &persistent);} while(0)
+#define	flat_get_relocate_addr(rel)		((persistent) ? (persistent & 0x07ffffff) : (rel & 0x07ffffff))
+
+static inline int flat_set_persistent(unsigned int relval, unsigned long *p)
+{
+	if (*p) {
+		return 0;
+	} else {
+		if ((relval >> 27) != R_UBICOM32_32) {
+			/*
+			 * Something other than UBICOM32_32. The next entry has the relocation.
+			 */
+			*p = relval;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+#endif /* _ASM_UBICOM32_FLAT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/fpu.h
@@ -0,0 +1,37 @@
+/*
+ * arch/ubicom32/include/asm/fpu.h
+ *   Floating point state definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_FPU_H
+#define _ASM_UBICOM32_FPU_H
+
+/*
+ * MAX floating point unit state size (FSAVE/FRESTORE)
+ */
+/* No FP unit present then... */
+#define FPSTATESIZE (2) /* dummy size */
+
+#endif /* _ASM_UBICOM32_FPU_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/futex.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/futex.h
+ *   Generic futex.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_FUTEX_H
+#define _ASM_UBICOM32_FUTEX_H
+
+#include <asm-generic/futex.h>
+
+#endif /* _ASM_UBICOM32_FUTEX_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/gpio.h
@@ -0,0 +1,451 @@
+/*
+ * arch/ubicom32/include/asm/gpio.h
+ *   Definitions for GPIO operations on Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_GPIO_H
+#define _ASM_UBICOM32_GPIO_H
+
+#include <linux/compiler.h>
+#include <asm/irq.h>
+
+#include <asm/ip5000.h>
+
+#define ARCH_NR_GPIOS	         512
+#define MAX_UBICOM_ONCHIP_GPIO   (9 * 32)
+
+/*
+ * Macros for manipulating GPIO numbers
+ */
+#define gpio_bit(gn)			(1 << (gn & 0x1f))
+#define gpio_bank(gn)			(gn >> 5)
+
+#define gpio_pin_index(gn)		(gn & 0x1f)
+#define gpio_port_index(gn)		(gn >> 5)
+
+#define GPIO_RA_0    ((32 * 0) + 0)
+#define GPIO_RA_1    ((32 * 0) + 1)
+#define GPIO_RA_2    ((32 * 0) + 2)
+#define GPIO_RA_3    ((32 * 0) + 3)
+#define GPIO_RA_4    ((32 * 0) + 4)
+#define GPIO_RA_5    ((32 * 0) + 5)
+#define GPIO_RA_6    ((32 * 0) + 6)
+#define GPIO_RA_7    ((32 * 0) + 7)
+
+#define GPIO_RB_0    ((32 * 1) + 0)
+#define GPIO_RB_1    ((32 * 1) + 1)
+#define GPIO_RB_2    ((32 * 1) + 2)
+#define GPIO_RB_3    ((32 * 1) + 3)
+#define GPIO_RB_4    ((32 * 1) + 4)
+#define GPIO_RB_5    ((32 * 1) + 5)
+#define GPIO_RB_6    ((32 * 1) + 6)
+#define GPIO_RB_7    ((32 * 1) + 7)
+#define GPIO_RB_8    ((32 * 1) + 8)
+#define GPIO_RB_9    ((32 * 1) + 9)
+#define GPIO_RB_10   ((32 * 1) + 10)
+#define GPIO_RB_11   ((32 * 1) + 11)
+#define GPIO_RB_12   ((32 * 1) + 12)
+#define GPIO_RB_13   ((32 * 1) + 13)
+#define GPIO_RB_14   ((32 * 1) + 14)
+#define GPIO_RB_15   ((32 * 1) + 15)
+#define GPIO_RB_16   ((32 * 1) + 16)
+#define GPIO_RB_17   ((32 * 1) + 17)
+#define GPIO_RB_18   ((32 * 1) + 18)
+#define GPIO_RB_19   ((32 * 1) + 19)
+
+#define GPIO_RC_0    ((32 * 2) + 0)
+#define GPIO_RC_1    ((32 * 2) + 1)
+#define GPIO_RC_2    ((32 * 2) + 2)
+#define GPIO_RC_3    ((32 * 2) + 3)
+#define GPIO_RC_4    ((32 * 2) + 4)
+#define GPIO_RC_5    ((32 * 2) + 5)
+#define GPIO_RC_6    ((32 * 2) + 6)
+#define GPIO_RC_7    ((32 * 2) + 7)
+#define GPIO_RC_8    ((32 * 2) + 8)
+#define GPIO_RC_9    ((32 * 2) + 9)
+#define GPIO_RC_10   ((32 * 2) + 10)
+#define GPIO_RC_11   ((32 * 2) + 11)
+#define GPIO_RC_12   ((32 * 2) + 12)
+#define GPIO_RC_13   ((32 * 2) + 13)
+#define GPIO_RC_14   ((32 * 2) + 14)
+#define GPIO_RC_15   ((32 * 2) + 15)
+#define GPIO_RC_16   ((32 * 2) + 16)
+#define GPIO_RC_17   ((32 * 2) + 17)
+#define GPIO_RC_18   ((32 * 2) + 18)
+#define GPIO_RC_19   ((32 * 2) + 19)
+#define GPIO_RC_20   ((32 * 2) + 20)
+#define GPIO_RC_21   ((32 * 2) + 21)
+#define GPIO_RC_22   ((32 * 2) + 22)
+#define GPIO_RC_23   ((32 * 2) + 23)
+#define GPIO_RC_24   ((32 * 2) + 24)
+#define GPIO_RC_25   ((32 * 2) + 25)
+#define GPIO_RC_26   ((32 * 2) + 26)
+#define GPIO_RC_27   ((32 * 2) + 27)
+#define GPIO_RC_28   ((32 * 2) + 28)
+#define GPIO_RC_29   ((32 * 2) + 29)
+#define GPIO_RC_30   ((32 * 2) + 30)
+#define GPIO_RC_31   ((32 * 2) + 31)
+
+#define GPIO_RD_0    ((32 * 3) + 0)
+#define GPIO_RD_1    ((32 * 3) + 1)
+#define GPIO_RD_2    ((32 * 3) + 2)
+#define GPIO_RD_3    ((32 * 3) + 3)
+#define GPIO_RD_4    ((32 * 3) + 4)
+#define GPIO_RD_5    ((32 * 3) + 5)
+#define GPIO_RD_6    ((32 * 3) + 6)
+#define GPIO_RD_7    ((32 * 3) + 7)
+#define GPIO_RD_8    ((32 * 3) + 8)
+#define GPIO_RD_9    ((32 * 3) + 9)
+#define GPIO_RD_10   ((32 * 3) + 10)
+#define GPIO_RD_11   ((32 * 3) + 11)
+
+#define GPIO_RE_0    ((32 * 4) + 0)
+#define GPIO_RE_1    ((32 * 4) + 1)
+#define GPIO_RE_2    ((32 * 4) + 2)
+#define GPIO_RE_3    ((32 * 4) + 3)
+#define GPIO_RE_4    ((32 * 4) + 4)
+#define GPIO_RE_5    ((32 * 4) + 5)
+#define GPIO_RE_6    ((32 * 4) + 6)
+#define GPIO_RE_7    ((32 * 4) + 7)
+
+#define GPIO_RF_0    ((32 * 5) + 0)
+#define GPIO_RF_1    ((32 * 5) + 1)
+#define GPIO_RF_2    ((32 * 5) + 2)
+#define GPIO_RF_3    ((32 * 5) + 3)
+#define GPIO_RF_4    ((32 * 5) + 4)
+#define GPIO_RF_5    ((32 * 5) + 5)
+#define GPIO_RF_6    ((32 * 5) + 6)
+#define GPIO_RF_7    ((32 * 5) + 7)
+#define GPIO_RF_8    ((32 * 5) + 8)
+#define GPIO_RF_9    ((32 * 5) + 9)
+#define GPIO_RF_10   ((32 * 5) + 10)
+#define GPIO_RF_11   ((32 * 5) + 11)
+#define GPIO_RF_12   ((32 * 5) + 12)
+#define GPIO_RF_13   ((32 * 5) + 13)
+#define GPIO_RF_14   ((32 * 5) + 14)
+#define GPIO_RF_15   ((32 * 5) + 15)
+
+#define GPIO_RG_0    ((32 * 6) + 0)
+#define GPIO_RG_1    ((32 * 6) + 1)
+#define GPIO_RG_2    ((32 * 6) + 2)
+#define GPIO_RG_3    ((32 * 6) + 3)
+#define GPIO_RG_4    ((32 * 6) + 4)
+#define GPIO_RG_5    ((32 * 6) + 5)
+#define GPIO_RG_6    ((32 * 6) + 6)
+#define GPIO_RG_7    ((32 * 6) + 7)
+#define GPIO_RG_8    ((32 * 6) + 8)
+#define GPIO_RG_9    ((32 * 6) + 9)
+#define GPIO_RG_10   ((32 * 6) + 10)
+#define GPIO_RG_11   ((32 * 6) + 11)
+#define GPIO_RG_12   ((32 * 6) + 12)
+#define GPIO_RG_13   ((32 * 6) + 13)
+#define GPIO_RG_14   ((32 * 6) + 14)
+#define GPIO_RG_15   ((32 * 6) + 15)
+#define GPIO_RG_16   ((32 * 6) + 16)
+#define GPIO_RG_17   ((32 * 6) + 17)
+#define GPIO_RG_18   ((32 * 6) + 18)
+#define GPIO_RG_19   ((32 * 6) + 19)
+#define GPIO_RG_20   ((32 * 6) + 20)
+#define GPIO_RG_21   ((32 * 6) + 21)
+#define GPIO_RG_22   ((32 * 6) + 22)
+#define GPIO_RG_23   ((32 * 6) + 23)
+#define GPIO_RG_24   ((32 * 6) + 24)
+#define GPIO_RG_25   ((32 * 6) + 25)
+#define GPIO_RG_26   ((32 * 6) + 26)
+#define GPIO_RG_27   ((32 * 6) + 27)
+#define GPIO_RG_28   ((32 * 6) + 28)
+#define GPIO_RG_29   ((32 * 6) + 29)
+#define GPIO_RG_30   ((32 * 6) + 30)
+#define GPIO_RG_31   ((32 * 6) + 31)
+
+#define GPIO_RH_0    ((32 * 7) + 0)
+#define GPIO_RH_1    ((32 * 7) + 1)
+#define GPIO_RH_2    ((32 * 7) + 2)
+#define GPIO_RH_3    ((32 * 7) + 3)
+#define GPIO_RH_4    ((32 * 7) + 4)
+#define GPIO_RH_5    ((32 * 7) + 5)
+#define GPIO_RH_6    ((32 * 7) + 6)
+#define GPIO_RH_7    ((32 * 7) + 7)
+#define GPIO_RH_8    ((32 * 7) + 8)
+#define GPIO_RH_9    ((32 * 7) + 9)
+
+#define GPIO_RI_0    ((32 * 8) + 0)
+#define GPIO_RI_1    ((32 * 8) + 1)
+#define GPIO_RI_2    ((32 * 8) + 2)
+#define GPIO_RI_3    ((32 * 8) + 3)
+#define GPIO_RI_4    ((32 * 8) + 4)
+#define GPIO_RI_5    ((32 * 8) + 5)
+#define GPIO_RI_6    ((32 * 8) + 6)
+#define GPIO_RI_7    ((32 * 8) + 7)
+#define GPIO_RI_8    ((32 * 8) + 8)
+#define GPIO_RI_9    ((32 * 8) + 9)
+#define GPIO_RI_10   ((32 * 8) + 10)
+#define GPIO_RI_11   ((32 * 8) + 11)
+#define GPIO_RI_12   ((32 * 8) + 12)
+#define GPIO_RI_13   ((32 * 8) + 13)
+
+/*
+ * The following section defines extra GPIO available to some boards.
+ * These GPIO are generally external to the processor (i.e. SPI/I2C
+ * expander chips).
+ *
+ * Note that these defines show all possible GPIO available, however,
+ * depending on the actual board configuration, some GPIO are not
+ * available for use.
+ */
+#ifdef CONFIG_IP7500MEDIA
+/*
+ * U15
+ */
+#define IP7500MEDIA_U15_BASE	(32 * 10)
+#define IP7500MEDIA_IO0		(IP7500MEDIA_U15_BASE + 0)
+#define IP7500MEDIA_IO1		(IP7500MEDIA_U15_BASE + 1)
+#define IP7500MEDIA_IO2		(IP7500MEDIA_U15_BASE + 2)
+#define IP7500MEDIA_IO3		(IP7500MEDIA_U15_BASE + 3)
+#define IP7500MEDIA_IO4		(IP7500MEDIA_U15_BASE + 4)
+#define IP7500MEDIA_IO5		(IP7500MEDIA_U15_BASE + 5)
+#define IP7500MEDIA_IO6		(IP7500MEDIA_U15_BASE + 6)
+#define IP7500MEDIA_IO7		(IP7500MEDIA_U15_BASE + 7)
+
+/*
+ * U16
+ */
+#define IP7500MEDIA_U16_BASE	(32 * 11)
+#define IP7500MEDIA_IO8		(IP7500MEDIA_U16_BASE + 0)
+#define IP7500MEDIA_IO9		(IP7500MEDIA_U16_BASE + 1)
+#define IP7500MEDIA_IO10	(IP7500MEDIA_U16_BASE + 2)
+#define IP7500MEDIA_IO11	(IP7500MEDIA_U16_BASE + 3)
+#define IP7500MEDIA_IO12	(IP7500MEDIA_U16_BASE + 4)
+#define IP7500MEDIA_IO13	(IP7500MEDIA_U16_BASE + 5)
+#define IP7500MEDIA_IO14	(IP7500MEDIA_U16_BASE + 6)
+#define IP7500MEDIA_IO15	(IP7500MEDIA_U16_BASE + 7)
+
+/*
+ * U17
+ */
+#define IP7500MEDIA_U17_BASE	(32 * 12)
+#define IP7500MEDIA_IO16	(IP7500MEDIA_U17_BASE + 0)
+#define IP7500MEDIA_IO17	(IP7500MEDIA_U17_BASE + 1)
+#define IP7500MEDIA_IO18	(IP7500MEDIA_U17_BASE + 2)
+#define IP7500MEDIA_IO19	(IP7500MEDIA_U17_BASE + 3)
+#define IP7500MEDIA_IO20	(IP7500MEDIA_U17_BASE + 4)
+#define IP7500MEDIA_IO21	(IP7500MEDIA_U17_BASE + 5)
+#define IP7500MEDIA_IO22	(IP7500MEDIA_U17_BASE + 6)
+#define IP7500MEDIA_IO23	(IP7500MEDIA_U17_BASE + 7)
+
+/*
+ * U18
+ */
+#define IP7500MEDIA_U18_BASE	(32 * 13)
+#define IP7500MEDIA_IO24	(IP7500MEDIA_U18_BASE + 0)
+#define IP7500MEDIA_IO25	(IP7500MEDIA_U18_BASE + 1)
+#define IP7500MEDIA_IO26	(IP7500MEDIA_U18_BASE + 2)
+#define IP7500MEDIA_IO27	(IP7500MEDIA_U18_BASE + 3)
+#define IP7500MEDIA_IO28	(IP7500MEDIA_U18_BASE + 4)
+#define IP7500MEDIA_IO29	(IP7500MEDIA_U18_BASE + 5)
+#define IP7500MEDIA_IO30	(IP7500MEDIA_U18_BASE + 6)
+#define IP7500MEDIA_IO31	(IP7500MEDIA_U18_BASE + 7)
+#endif
+
+#ifdef CONFIG_IP7145DPF
+/*
+ * U48
+ */
+#define IP7145DPF_U48_BASE	(32 * 10)
+#define IP7145DPF_IO0		(IP7145DPF_U48_BASE + 0)
+#define IP7145DPF_IO1		(IP7145DPF_U48_BASE + 1)
+#define IP7145DPF_IO2		(IP7145DPF_U48_BASE + 2)
+#define IP7145DPF_IO3		(IP7145DPF_U48_BASE + 3)
+#define IP7145DPF_IO4		(IP7145DPF_U48_BASE + 4)
+#define IP7145DPF_IO5		(IP7145DPF_U48_BASE + 5)
+#define IP7145DPF_IO6		(IP7145DPF_U48_BASE + 6)
+#define IP7145DPF_IO7		(IP7145DPF_U48_BASE + 7)
+
+/*
+ * U72
+ */
+#define IP7145DPF_U72_BASE	(32 * 11)
+#define IP7145DPF_IOB0		(IP7145DPF_U72_BASE + 0)
+#define IP7145DPF_IOB1		(IP7145DPF_U72_BASE + 1)
+#define IP7145DPF_IOB2		(IP7145DPF_U72_BASE + 2)
+#define IP7145DPF_IOB3		(IP7145DPF_U72_BASE + 3)
+#define IP7145DPF_IOB4		(IP7145DPF_U72_BASE + 4)
+#define IP7145DPF_IOB5		(IP7145DPF_U72_BASE + 5)
+#define IP7145DPF_IOB6		(IP7145DPF_U72_BASE + 6)
+#define IP7145DPF_IOB7		(IP7145DPF_U72_BASE + 7)
+#endif
+
+#include <asm-generic/gpio.h>
+
+/*
+ * The following macros bypass gpiolib to generate direct references
+ * to the port registers.  These assume, minimally, that either
+ * gpio_direction_input() or gpio_direction_output() have already been
+ * called to setup the pin direction and to enable the pin function to
+ * be gpio.  These macros generate the hardware port address based on
+ * the assumption that all ports are 32 bits wide (even though we know
+ * they are not).  This is so we can efficiently turn pin numbers into
+ * port addresses without a lookup.
+ *
+ * These operations must be done in one instruction to prevent clobbering
+ * other thread's accesses to the same port.
+ */
+#define UBICOM32_GPIO_ENABLE(pin)				\
+	do {							\
+		asm volatile ("or.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_mask),	\
+				  [mask] "d" (gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_DISABLE(pin)				\
+	do {							\
+		asm volatile ("and.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_mask),	\
+				  [mask] "d" (~gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN_INPUT(pin)			\
+	do {							\
+		asm volatile ("and.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_ctl),	\
+				  [mask] "d" (~gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN_OUTPUT(pin)			\
+	do {							\
+		asm volatile ("or.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_ctl),	\
+				  [mask] "d" (gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN_TOGGLE(pin)			\
+	do {							\
+		asm volatile ("xor.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_out),	\
+				  [mask] "d" (gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN_HIGH(pin)				\
+	do {							\
+		asm volatile ("or.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_out),	\
+				  [mask] "d" (gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN_LOW(pin)				\
+	do {							\
+		asm volatile ("and.4 (%[port]), (%[port]), %[mask]\n\t"						\
+				:										\
+				: [port] "a" (&UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_out),	\
+				  [mask] "d" (~gpio_bit(pin))							\
+				: "cc", "memory"								\
+		);												\
+	} while (0);
+
+#define UBICOM32_GPIO_SET_PIN(pin, val) \
+  if ( val ) {                          \
+    UBICOM32_GPIO_SET_PIN_HIGH(pin);    \
+  } else {                              \
+    UBICOM32_GPIO_SET_PIN_LOW(pin);	\
+  }
+
+#define UBICOM32_GPIO_GET_PIN(pin)                                    \
+  (0 != (UBICOM32_IO_PORT(IO_BASE + (gpio_bank(pin) << 12))->gpio_in  \
+	 & gpio_bit(pin)))
+
+
+static inline int gpio_get_value(unsigned gpio) 
+{
+  if (gpio <= MAX_UBICOM_ONCHIP_GPIO)
+    return UBICOM32_GPIO_GET_PIN(gpio);
+  else
+    return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+  if (gpio <= MAX_UBICOM_ONCHIP_GPIO)
+    {
+      UBICOM32_GPIO_SET_PIN(gpio, value);
+    }
+  else
+    {
+      __gpio_set_value(gpio, value);
+    }
+}
+
+static inline int gpio_cansleep(unsigned gpio)
+{
+  return __gpio_cansleep(gpio);
+}
+
+static inline int gpio_to_irq(unsigned gpio)
+{
+#if defined(IP5000) || defined(IP5000_REV2)
+  if ((gpio >= GPIO_RA_4) && (gpio <= GPIO_RA_6))
+    return 25;
+  else
+    return -ENXIO;
+
+#elif defined(IP7000) || defined(IP7000_REV2)
+  if ((gpio >= GPIO_RA_4) && (gpio <= GPIO_RA_6))
+    return 44 + (gpio - GPIO_RA_4);
+  else
+    return -ENXIO;
+
+#else
+    return -ENXIO;
+
+#endif
+}
+
+static inline int irq_to_gpio(unsigned gpio)
+{
+	return -ENXIO;
+}
+
+extern struct ubicom32_io_port *ubi_gpio_get_port(unsigned gpio);
+
+extern int __init ubi_gpio_init(void);
+
+#endif /* _ASM_UBICOM32_GPIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/hardirq.h
@@ -0,0 +1,55 @@
+/*
+ * arch/ubicom32/include/asm/hardirq.h
+ *   Definition of ack_bad_irq() for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1997, 98, 99, 2000, 01, 05 Ralf Baechle (ralf@linux-mips.org)
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ * Copyright (C) 2001 MIPS Technologies, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_HARDIRQ_H
+#define _ASM_UBICOM32_HARDIRQ_H
+
+#include <linux/threads.h>
+#include <linux/irq.h>
+
+/*
+ * The hardirq mask has to be large enough to have space
+ * for potentially all IRQ sources in the system nesting
+ * on a single CPU.  For Ubicom32, we have 64 IRQ sources.
+ */
+#define HARDIRQ_BITS	6
+#if (1 << HARDIRQ_BITS) < NR_IRQS
+# error HARDIRQ_BITS is too low!
+#endif
+
+typedef struct {
+	unsigned int __softirq_pending;
+} ____cacheline_aligned irq_cpustat_t;
+
+#include <linux/irq_cpustat.h>	/* Standard mappings for irq_cpustat_t above */
+
+extern void ack_bad_irq(unsigned int irq);
+
+#endif /* _ASM_UBICOM32_HARDIRQ_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/hw_irq.h
@@ -0,0 +1,31 @@
+/*
+ * arch/ubicom32/include/asm/hw_irq.h
+ *   Ubicom32 architecture APIC support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_HW_IRQ_H
+#define _ASM_UBICOM32_HW_IRQ_H
+
+#endif /* _ASM_UBICOM32_HW_IRQ_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ioctl.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/ioctl.h
+ *   Generic ioctl.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IOCTL_H
+#define _ASM_UBICOM32_IOCTL_H
+
+#include <asm-generic/ioctl.h>
+
+#endif /* _ASM_UBICOM32_IOCTL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ioctls.h
@@ -0,0 +1,111 @@
+/*
+ * arch/ubicom32/include/asm/ioctls.h
+ *   Definitions of ioctls for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IOCTLS_H
+#define _ASM_UBICOM32_IOCTLS_H
+
+#include <asm/ioctl.h>
+
+/* 0x54 is just a magic number to make these relatively unique ('T') */
+
+#define TCGETS		0x5401
+#define TCSETS		0x5402
+#define TCSETSW		0x5403
+#define TCSETSF		0x5404
+#define TCGETA		0x5405
+#define TCSETA		0x5406
+#define TCSETAW		0x5407
+#define TCSETAF		0x5408
+#define TCSBRK		0x5409
+#define TCXONC		0x540A
+#define TCFLSH		0x540B
+#define TIOCEXCL	0x540C
+#define TIOCNXCL	0x540D
+#define TIOCSCTTY	0x540E
+#define TIOCGPGRP	0x540F
+#define TIOCSPGRP	0x5410
+#define TIOCOUTQ	0x5411
+#define TIOCSTI		0x5412
+#define TIOCGWINSZ	0x5413
+#define TIOCSWINSZ	0x5414
+#define TIOCMGET	0x5415
+#define TIOCMBIS	0x5416
+#define TIOCMBIC	0x5417
+#define TIOCMSET	0x5418
+#define TIOCGSOFTCAR	0x5419
+#define TIOCSSOFTCAR	0x541A
+#define FIONREAD	0x541B
+#define TIOCINQ		FIONREAD
+#define TIOCLINUX	0x541C
+#define TIOCCONS	0x541D
+#define TIOCGSERIAL	0x541E
+#define TIOCSSERIAL	0x541F
+#define TIOCPKT		0x5420
+#define FIONBIO		0x5421
+#define TIOCNOTTY	0x5422
+#define TIOCSETD	0x5423
+#define TIOCGETD	0x5424
+#define TCSBRKP		0x5425	/* Needed for POSIX tcsendbreak() */
+#define TIOCSBRK	0x5427  /* BSD compatibility */
+#define TIOCCBRK	0x5428  /* BSD compatibility */
+#define TIOCGSID	0x5429  /* Return the session ID of FD */
+#define TCGETS2		_IOR('T',0x2A, struct termios2)
+#define TCSETS2		_IOW('T',0x2B, struct termios2)
+#define TCSETSW2	_IOW('T',0x2C, struct termios2)
+#define TCSETSF2	_IOW('T',0x2D, struct termios2)
+#define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
+#define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+
+#define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
+#define FIOCLEX		0x5451
+#define FIOASYNC	0x5452
+#define TIOCSERCONFIG	0x5453
+#define TIOCSERGWILD	0x5454
+#define TIOCSERSWILD	0x5455
+#define TIOCGLCKTRMIOS	0x5456
+#define TIOCSLCKTRMIOS	0x5457
+#define TIOCSERGSTRUCT	0x5458 /* For debugging only */
+#define TIOCSERGETLSR   0x5459 /* Get line status register */
+#define TIOCSERGETMULTI 0x545A /* Get multiport config  */
+#define TIOCSERSETMULTI 0x545B /* Set multiport config */
+
+#define TIOCMIWAIT	0x545C	/* wait for a change on serial input line(s) */
+#define TIOCGICOUNT	0x545D	/* read serial port inline interrupt counts */
+#define FIOQSIZE	0x545E
+
+/* Used for packet mode */
+#define TIOCPKT_DATA		 0
+#define TIOCPKT_FLUSHREAD	 1
+#define TIOCPKT_FLUSHWRITE	 2
+#define TIOCPKT_STOP		 4
+#define TIOCPKT_START		 8
+#define TIOCPKT_NOSTOP		16
+#define TIOCPKT_DOSTOP		32
+
+#define TIOCSER_TEMT    0x01	/* Transmitter physically empty */
+
+#endif /* _ASM_UBICOM32_IOCTLS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/io.h
@@ -0,0 +1,313 @@
+/*
+ * arch/ubicom32/include/asm/io.h
+ *   I/O memory accessor functions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IO_H
+#define _ASM_UBICOM32_IO_H
+
+#ifdef __KERNEL__
+#include <linux/string.h>
+#include <linux/compiler.h>
+
+static inline unsigned short _swapw(volatile unsigned short v)
+{
+    return ((v << 8) | (v >> 8));
+}
+
+static inline unsigned int _swapl(volatile unsigned long v)
+{
+    return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
+}
+
+#ifndef CONFIG_PCI
+#define readb(addr) \
+    ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
+#define readw(addr) \
+    ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
+#define readl(addr) \
+    ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
+
+#define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b))
+#define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b))
+#define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b))
+#else /*CONFIG_PCI */
+
+#define PCI_CPU_REG_BASE (0x00000000UL)   /* taking lower 2GB space */
+#define PCI_DEV_REG_BASE (0x80000000UL)
+
+#if PCI_CPU_REG_BASE > PCI_DEV_REG_BASE
+#define IS_PCI_ADDRESS(x) (((unsigned int)(x)&(PCI_CPU_REG_BASE)) == 0)
+#else
+#define IS_PCI_ADDRESS(x) ((unsigned int)(x)&(PCI_DEV_REG_BASE))
+#endif 
+
+extern unsigned int ubi32_pci_read_u32(const volatile void __iomem *addr);
+extern unsigned short ubi32_pci_read_u16(const volatile void __iomem *addr);
+extern unsigned char ubi32_pci_read_u8(const volatile void __iomem *addr);
+extern  void ubi32_pci_write_u32(unsigned int val, const volatile void __iomem *addr);
+extern  void ubi32_pci_write_u16(unsigned short val, const volatile void __iomem *addr);
+extern  void ubi32_pci_write_u8(unsigned char val, const volatile void __iomem *addr);
+
+static  inline unsigned char readb(const volatile void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u8(addr);
+	else 
+		return (unsigned char)(*(volatile unsigned char *)addr); 
+}
+static inline unsigned short readw(const volatile void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u16(addr);
+	else 
+		return (unsigned short)(*(volatile unsigned short *)addr);	
+}
+
+static  inline unsigned int  readl(const volatile void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u32(addr);
+	else 
+		return (unsigned int)(*(volatile unsigned int *)addr);
+}
+
+static inline void writel(unsigned int val, volatile void __iomem *addr)
+{
+  	if (IS_PCI_ADDRESS(addr))
+                ubi32_pci_write_u32(val, addr);
+        else
+               	*(volatile unsigned int *)addr = val; 
+}
+
+static inline void writew(unsigned short val, volatile void __iomem *addr)
+{
+  	if (IS_PCI_ADDRESS(addr))
+                ubi32_pci_write_u16(val, addr);
+        else
+               	*(volatile unsigned short *)addr = val; 
+}
+
+static inline void writeb(unsigned char val, volatile void __iomem *addr)
+{
+  	if (IS_PCI_ADDRESS(addr))
+                ubi32_pci_write_u8(val, addr);
+        else
+               	*(volatile unsigned char *)addr = val; 
+}
+#endif
+
+#define readb_relaxed(addr) readb(addr)
+#define readw_relaxed(addr) readw(addr)
+#define readl_relaxed(addr) readl(addr)
+
+
+#define __raw_readb readb
+#define __raw_readw readw
+#define __raw_readl readl
+#define __raw_writeb writeb
+#define __raw_writew writew
+#define __raw_writel writel
+
+static inline void io_outsb(unsigned int addr, const void *buf, int len)
+{
+	volatile unsigned char *ap = (volatile unsigned char *) addr;
+	unsigned char *bp = (unsigned char *) buf;
+	while (len--)
+		*ap = *bp++;
+}
+
+static inline void io_outsw(unsigned int addr, const void *buf, int len)
+{
+	volatile unsigned short *ap = (volatile unsigned short *) addr;
+	unsigned short *bp = (unsigned short *) buf;
+	while (len--)
+		*ap = _swapw(*bp++);
+}
+
+static inline void io_outsl(unsigned int addr, const void *buf, int len)
+{
+	volatile unsigned int *ap = (volatile unsigned int *) addr;
+	unsigned int *bp = (unsigned int *) buf;
+	while (len--)
+		*ap = _swapl(*bp++);
+}
+
+static inline void io_insb(unsigned int addr, void *buf, int len)
+{
+	volatile unsigned char *ap = (volatile unsigned char *) addr;
+	unsigned char *bp = (unsigned char *) buf;
+	while (len--)
+		*bp++ = *ap;
+}
+
+static inline void io_insw(unsigned int addr, void *buf, int len)
+{
+	volatile unsigned short *ap = (volatile unsigned short *) addr;
+	unsigned short *bp = (unsigned short *) buf;
+	while (len--)
+		*bp++ = _swapw(*ap);
+}
+
+static inline void io_insl(unsigned int addr, void *buf, int len)
+{
+	volatile unsigned int *ap = (volatile unsigned int *) addr;
+	unsigned int *bp = (unsigned int *) buf;
+	while (len--)
+		*bp++ = _swapl(*ap);
+}
+
+#define mmiowb()
+
+/*
+ *	make the short names macros so specific devices
+ *	can override them as required
+ */
+#ifndef CONFIG_PCI
+#define memset_io(a,b,c)	memset((void *)(a),(b),(c))
+#define memcpy_fromio(a,b,c)	memcpy((a),(void *)(b),(c))
+#define memcpy_toio(a,b,c)	memcpy((void *)(a),(b),(c))
+#else 
+extern void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned len);
+extern void memcpy_toio(volatile void __iomem *to, const void *from, unsigned len);
+extern void memset_io(volatile void __iomem *addr, int val, size_t count);
+#endif
+
+#define inb(addr)    readb(addr)
+#define inw(addr)    readw(addr)
+#define inl(addr)    readl(addr)
+#define outb(x,addr) ((void) writeb(x,addr))
+#define outw(x,addr) ((void) writew(x,addr))
+#define outl(x,addr) ((void) writel(x,addr))
+
+#define inb_p(addr)    inb(addr)
+#define inw_p(addr)    inw(addr)
+#define inl_p(addr)    inl(addr)
+#define outb_p(x,addr) outb(x,addr)
+#define outw_p(x,addr) outw(x,addr)
+#define outl_p(x,addr) outl(x,addr)
+
+#define outsb(a,b,l) io_outsb(a,b,l)
+#define outsw(a,b,l) io_outsw(a,b,l)
+#define outsl(a,b,l) io_outsl(a,b,l)
+
+#define insb(a,b,l) io_insb(a,b,l)
+#define insw(a,b,l) io_insw(a,b,l)
+#define insl(a,b,l) io_insl(a,b,l)
+
+#ifndef CONFIG_PCI
+#define ioread8_rep(a,d,c)	insb(a,d,c)
+#define ioread16_rep(a,d,c)	insw(a,d,c)
+#define ioread32_rep(a,d,c)	insl(a,d,c)
+#define iowrite8_rep(a,s,c)	outsb(a,s,c)
+#define iowrite16_rep(a,s,c)	outsw(a,s,c)
+#define iowrite32_rep(a,s,c)	outsl(a,s,c)
+#else
+extern void  ioread8_rep(void __iomem *port, void *buf, unsigned long count);
+extern void  ioread16_rep(void __iomem *port, void *buf, unsigned long count);
+extern void  ioread32_rep(void __iomem *port, void *buf, unsigned long count);
+extern void  iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
+extern void  iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
+extern void  iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
+#endif
+
+
+#ifndef CONFIG_PCI
+#define ioread8(X)			readb(X)
+#define ioread16(X)			readw(X)
+#define ioread32(X)			readl(X)
+#define iowrite8(val,X)			writeb(val,X)
+#define iowrite16(val,X)		writew(val,X)
+#define iowrite32(val,X)		writel(val,X)
+#else /*CONFIG_PCI */
+extern  unsigned char  ioread8(void __iomem *addr);
+extern  unsigned short ioread16(void __iomem *addr);
+extern  unsigned int  ioread32(void __iomem *addr);
+extern  void iowrite8(unsigned char val, void __iomem *addr);
+extern  void iowrite16(unsigned short val, void __iomem *addr);
+extern  void iowrite32(unsigned int val, void __iomem *addr);
+#endif /* CONFIG_PCI */
+
+#define IO_SPACE_LIMIT 0xffff
+
+/* Values for nocacheflag and cmode */
+#define IOMAP_FULL_CACHING		0
+#define IOMAP_NOCACHE_SER		1
+#define IOMAP_NOCACHE_NONSER		2
+#define IOMAP_WRITETHROUGH		3
+
+extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
+extern void __iounmap(void *addr, unsigned long size);
+
+static inline void *ioremap(unsigned long physaddr, unsigned long size)
+{
+	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
+}
+static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
+{
+	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
+}
+static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
+{
+	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
+}
+static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
+{
+	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
+}
+
+extern void iounmap(void *addr);
+
+#define ioport_map(port, nr)            ((void __iomem*)(port))
+#define ioport_unmap(addr)
+
+
+/* Pages to physical address... */
+#define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
+#define page_to_bus(page)       ((page - mem_map) << PAGE_SHIFT)
+
+/*
+ * Macros used for converting between virtual and physical mappings.
+ */
+#define phys_to_virt(vaddr)	((void *) (vaddr))
+#define virt_to_phys(vaddr)	((unsigned long) (vaddr))
+
+#define virt_to_bus virt_to_phys
+#define bus_to_virt phys_to_virt
+
+/*
+ * Convert a physical pointer to a virtual kernel pointer for /dev/mem
+ * access
+ */
+#define xlate_dev_mem_ptr(p)	__va(p)
+
+/*
+ * Convert a virtual cached pointer to an uncached pointer
+ */
+#define xlate_dev_kmem_ptr(p)	p
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_IO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ip5000-asm.h
@@ -0,0 +1,156 @@
+/*
+ * arch/ubicom32/include/asm/ip5000-asm.h
+ *	Instruction macros for the IP5000.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_IP5000_ASM_H
+#define _ASM_UBICOM32_IP5000_ASM_H
+
+#if !defined(__LINKER__)
+
+#if defined(__ASSEMBLY__)
+.macro	cycles	quant
+.if	(\quant) == 1
+	nop
+.else
+.if	(((\quant) + 3) / 8) > 0
+.rept	(((\quant) + 3) / 8)
+	jmpt.f		.+4
+.endr
+.endif
+.if	((((\quant) + 3) % 8) / 4) > 0
+	jmpt.t		.+4
+.endif
+.endif
+.endm
+#else
+/*
+ * Same macro as above just in C inline asm
+ */
+asm ("					\n\
+.macro	cycles	quant			\n\
+.if	(\\quant) == 1			\n\
+	nop				\n\
+.else					\n\
+.if	(((\\quant) + 3) / 8) > 0	\n\
+.rept	(((\\quant) + 3) / 8)		\n\
+	jmpt.f		.+4		\n\
+.endr					\n\
+.endif					\n\
+.if	((((\\quant) + 3) % 8) / 4) > 0	\n\
+	jmpt.t		.+4		\n\
+.endif					\n\
+.endif					\n\
+.endm					\n\
+");
+#endif
+
+
+#if defined(__ASSEMBLY__)
+.macro	pipe_flush	cyc
+	cycles		11 - (\cyc)
+.endm
+#else
+/*
+ * Same macro as above just in C inline asm
+ */
+asm ("					\n\
+.macro	pipe_flush	cyc		\n\
+	cycles		11 - (\\cyc)	\n\
+.endm					\n\
+");
+
+#endif
+
+#if defined(__ASSEMBLY__)
+.macro	setcsr_flush	cyc
+	cycles		5 - (\cyc)
+.endm
+#else
+/*
+ * Same macro as above just in C inline asm
+ */
+asm ("					\n\
+.macro	setcsr_flush	cyc		\n\
+	cycles		5 - (\\cyc)	\n\
+.endm					\n\
+");
+#endif
+
+/*
+ * Macros for prefetch (using miss-aligned memory write)
+ */
+#if defined(__ASSEMBLY__)
+
+.macro	pre_fetch_macro	thread_num, Ascratch, Aaddress length
+	bclr		MT_TRAP_EN, MT_TRAP_EN, #(\thread_num)
+	bset		\Ascratch, \Aaddress, #0	; force a miss-aligned address
+	jmpt.t		.+4				; delay for both address setup and trap disable
+	move.4		(\Ascratch), #0
+	.if		(\length > 32)
+	move.4		32(\Ascratch), #0
+	.endif
+	.if		(\length > 64)
+	move.4		64(\Ascratch), #0
+	.endif
+	.if		(\length > 96)
+	move.4		96(\Ascratch), #0
+	.endif
+	.if		(\length > 128)
+	invalid_instruction				; maximum pre-fetch size is 4 cache lines
+	.endif
+	bset		MT_TRAP_EN, MT_TRAP_EN, #(\thread_num)
+.endm
+
+#else
+/*
+ * Same macro as above just in C inline asm
+ */
+asm ("								\n\
+.macro	pre_fetch_macro	thread_num, Ascratch, Aaddress length	\n\
+	bclr		MT_TRAP_EN, MT_TRAP_EN, #(\thread_num)	\n\
+	bset		\\Ascratch, \\Aaddress, #0	; force a miss-aligned address \n\
+	jmpt.t		.+4				; delay for both address setup and trap disable \n\
+	move.4		(\\Ascratch), #0			\n\
+	.if		(\\length > 32)				\n\
+	move.4		32(\\Ascratch), #0			\n\
+	.endif							\n\
+	.if		(\\length > 64)				\n\
+	move.4		64(\\Ascratch), #0			\n\
+	.endif							\n\
+	.if		(\\length > 96)				\n\
+	move.4		96(\\Ascratch), #0			\n\
+	.endif							\n\
+	.if		(\\length > 128)			\n\
+	invalid_instruction				; maximum pre-fetch size is 4 cache lines \n\
+	.endif							\n\
+	bset		MT_TRAP_EN, MT_TRAP_EN, #(\\thread_num)	\n\
+.endm								\n\
+");
+#endif
+
+#endif /* !defined(__LINKER__) */
+#endif /* defined _ASM_UBICOM32_IP5000_ASM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ip5000.h
@@ -0,0 +1,860 @@
+/*
+ * arch/ubicom32/include/asm/ip5000.h
+ *   Specific details for the Ubicom IP5000 processor.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_IP5000_H
+#define _ASM_UBICOM32_IP5000_H
+
+/*
+ * Inline assembly define
+ */
+#define S(arg) #arg
+#define D(arg) S(arg)
+
+/*
+ * Assembler include file
+ */
+#include <asm/ip5000-asm.h>
+
+/*
+ * Timing
+ */
+#define JMPT_PENALTY 3
+#define JMPF_PENALTY 7
+#define RET_PENALTY 7
+
+/*
+ * Threads
+ */
+#if defined(IP5000) || defined(IP5000_REV2)
+#define THREAD_COUNT 10
+#elif defined(IP7000) || defined(IP7000_REV2)
+#define THREAD_COUNT 12
+#else
+#error "Unknown IP5K silicon"
+#endif
+
+/*
+ * Arch
+ */
+#if defined(IP5000) || defined(IP5000_REV2)
+#define UBICOM32_ARCH_VERSION 3
+#elif defined(IP7000) || defined(IP7000_REV2)
+#define UBICOM32_ARCH_VERSION 4
+#else
+#error "Unknown IP5K silicon"
+#endif
+
+/*
+ * Memory Size
+ */
+#define OCM_SECTOR_SIZE	0x00008000		/* 32K */
+
+#if defined(IP5000) || defined(IP5000_REV2)
+#define OCMSIZE	0x00030000		/* 192K on-chip RAM for both program and data */
+#elif defined(IP7000) || defined(IP7000_REV2)
+#define OCMSIZE	0x0003C000		/* 240K on-chip RAM for both program and data */
+#else
+#error "Unknown IP5K silicon"
+#endif
+
+#define OCMSTART	0x3ffc0000		/* alias from 0x03000000 for easy jump to/from SDRAM */
+#define OCMEND		(OCMSTART + OCMSIZE)
+#define SDRAMSTART	0x40000000
+#define FLASHSTART	0x60000000
+
+/*
+ * Registers
+ */
+#define ROSR_INT (1 << 0)
+
+/* Interrupts */
+#define INT_CHIP(reg, bit) (((reg) << 5) | (bit))
+#define INT_REG(interrupt) (((interrupt) >> 5) * 4)
+#define INT_SET(interrupt) 0x0114 + INT_REG(interrupt)
+#define INT_CLR(interrupt) 0x0124 + INT_REG(interrupt)
+#define INT_STAT(interrupt) 0x0104 + INT_REG(interrupt)
+#define INT_MASK(interrupt) 0x00C0 + INT_REG(interrupt)
+#define INT_BIT(interrupt) ((interrupt) & 0x1F)
+#define INT_BIT_MASK(interrupt) (1 << INT_BIT(interrupt))
+
+/*
+ * The LOCK_INT and THREAD_INT are used to wake up corresponding thread. They are sharing
+ * the same set of SW interrupt resource.
+ *
+ * LOCK_INT(n): One SW INT per NRT thread that can participate lock operation.
+ *	The threads that can participate lock are application threads and DSR thread.
+ *	(Lock locks - numbers are hard-coded in lock.h)
+ * THREAD_INT(n):   One SW INT per HRT thread for wake up trigger.
+ */
+#define LOCK_INT(thread)	INT_CHIP(0, (thread))
+#define THREAD_INT(thread)	INT_CHIP(0, (thread))
+
+/*
+ * The SYSTEM_INT and DSR_INT are sharing the same set of SW interrupt resource.
+ *
+ * SYSTEM_INT(n): One SW INT per NRT threads (application threads) as system queue interrupt,
+ *	and for DSR as self-trigger interrupt.
+ *	(The application threads include at least thread 0)
+ * DSR_INT(n):    One SW INT per HRT thread to request DSR service.
+ */
+#define SYSTEM_INT(thread)	INT_CHIP(0, THREAD_COUNT + (thread))
+#define DSR_INT(thread)		INT_CHIP(0, THREAD_COUNT + (thread))
+
+/* GLOBAL_CTRL */
+#define GLOBAL_CTRL_TRAP_RST_EN (1 << 9)
+#define GLOBAL_CTRL_AERROR_RST_EN (1 << 8)
+#define GLOBAL_CTRL_MT_MIN_DELAY(x) ((x) << 3)
+#define GLOBAL_CTRL_HRT_BANK_SELECT (1 << 2)
+#define GLOBAL_CTRL_INT_EN (1 << 0)
+
+/*
+ * HRT Tables
+ */
+#define HRT_TABLE0_BASE 0x0800
+#define HRT_TABLE1_BASE 0x0900
+#define HRT_TABLE_SIZE 64
+
+/*
+ * Break Point Trap Register
+ */
+#define ASYNCERROR_INT INT_CHIP(0, 31)
+#define BREAKPOINT_INT INT_CHIP(1, 31)
+
+/*
+ * Port interrupts
+ *	The non-existing FIFO INTs are mapped to INT2 for the ports.
+ */
+#define IO_PORT_PTR_TO_NUM(port) (((port) & 0x0000ffff) >> 12)
+#define RX_FIFO_INT(port) \
+	((IO_PORT_PTR_TO_NUM(port) == 0) ? INT_CHIP(0, 25) : \
+	((IO_PORT_PTR_TO_NUM(port) == 1) ? INT_CHIP(0, 26) : \
+	((IO_PORT_PTR_TO_NUM(port) == 2) ? INT_CHIP(0, 29) : \
+	((IO_PORT_PTR_TO_NUM(port) == 3) ? INT_CHIP(1, 24) : \
+	((IO_PORT_PTR_TO_NUM(port) == 4) ? INT_CHIP(1, 27) : \
+	((IO_PORT_PTR_TO_NUM(port) == 5) ? INT_CHIP(1, 16) : \
+	((IO_PORT_PTR_TO_NUM(port) == 6) ? INT_CHIP(1, 19) : \
+	((IO_PORT_PTR_TO_NUM(port) == 7) ? INT_CHIP(1, 20) : \
+	((IO_PORT_PTR_TO_NUM(port) == 8) ? INT_CHIP(1, 21) : \
+	INT_CHIP(1, 15))))))))))
+#define TX_FIFO_INT(port) \
+	((IO_PORT_PTR_TO_NUM(port) == 0) ? INT_CHIP(0, 24) : \
+	((IO_PORT_PTR_TO_NUM(port) == 1) ? INT_CHIP(0, 27) : \
+	((IO_PORT_PTR_TO_NUM(port) == 2) ? INT_CHIP(0, 29) : \
+	((IO_PORT_PTR_TO_NUM(port) == 3) ? INT_CHIP(1, 25) : \
+	((IO_PORT_PTR_TO_NUM(port) == 4) ? INT_CHIP(1, 28) : \
+	((IO_PORT_PTR_TO_NUM(port) == 5) ? INT_CHIP(1, 17) : \
+	((IO_PORT_PTR_TO_NUM(port) == 6) ? INT_CHIP(1, 19) : \
+	((IO_PORT_PTR_TO_NUM(port) == 7) ? INT_CHIP(1, 20) : \
+	((IO_PORT_PTR_TO_NUM(port) == 8) ? INT_CHIP(1, 22) : \
+	INT_CHIP(1, 15))))))))))
+#define PORT_OTHER_INT(port) \
+	((IO_PORT_PTR_TO_NUM(port) == 0) ? INT_CHIP(0, 25) : \
+	((IO_PORT_PTR_TO_NUM(port) == 1) ? INT_CHIP(0, 28) : \
+	((IO_PORT_PTR_TO_NUM(port) == 2) ? INT_CHIP(0, 29) : \
+	((IO_PORT_PTR_TO_NUM(port) == 3) ? INT_CHIP(1, 26) : \
+	((IO_PORT_PTR_TO_NUM(port) == 4) ? INT_CHIP(1, 29) : \
+	((IO_PORT_PTR_TO_NUM(port) == 5) ? INT_CHIP(1, 18) : \
+	((IO_PORT_PTR_TO_NUM(port) == 6) ? INT_CHIP(1, 19) : \
+	((IO_PORT_PTR_TO_NUM(port) == 7) ? INT_CHIP(1, 20) : \
+	((IO_PORT_PTR_TO_NUM(port) == 8) ? INT_CHIP(1, 23) : \
+	INT_CHIP(1, 15))))))))))
+
+/*
+ * On Chip Peripherals Base.
+ */
+#define OCP_BASE	0x01000000
+#define OCP_GENERAL	0x000
+#define OCP_TIMERS	0x100
+#define OCP_TRNG	0x200	/* True Random Number Generator Control Reigsters */
+#define OCP_DEBUG	0x300
+#define OCP_SECURITY	0x400
+#define OCP_ICCR	0x500	/* I-Cache Control Registers */
+#define OCP_DCCR	0x600	/* D-Cache Control Registers */
+#define OCP_OCMC	0x700	/* On Chip Memory Control Registers */
+#define OCP_STATISTICS	0x800	/* Statistics Counters */
+#define OCP_MTEST	0x900	/* Memory Test Registers */
+#define OCP_MCFG	0xa00	/* Memory Configuration Registers -- IP7000 only */
+#define OCP_DEBUG_INST	0x000	/* Up to 16M */
+
+/*
+ * General Configuration Registers (PLL)
+ */
+#define GENERAL_CFG_BASE (OCP_BASE + OCP_GENERAL)
+#define GEN_CLK_CORE_CFG 0x00
+#define GEN_CLK_IO_CFG 0x04
+#define GEN_CLK_DDR_CFG 0x08
+#define GEN_CLK_DDRDS_CFG 0x0c
+#define GEN_CLK_SLIP_CLR 0x10
+#define GEN_CLK_SLIP_START 0x14
+#define GEN_CLK_SERDES_SEL 0x18	/* IP7000 only */
+#define GEN_CLK_DDR_CFG2 0x1c	/* IP7000 only */
+#define GEN_DDR_CAL_CTRL 0x30	/* IP5000 only */
+#define GEN_DDR_CAL_STAT 0x34	/* IP5000 only */
+#define GEN_USB_DFT_CTRL 0x38	/* IP5000 only */
+#define GEN_USB_DFT_STAT 0x3c	/* IP5000 only */
+#define GEN_USB_PHY_CFG 0x40	/* IP7000 only */
+#define GEN_USB_PHY_TEST 0x44	/* IP7000 only */
+#define GEN_USB_PHY_STAT 0x48	/* IP7000 only */
+#define GEN_SW_RESET 0x80
+#define GEN_RESET_REASON 0x84
+#define GEN_BOND_CFG 0x88
+#define GEN_IO_PU_CFG 0x8c
+#define GEN_MEM_RM_CFG 0x90
+#define GEN_IO_CONFIG 0x94
+
+#define GEN_CLK_PLL_SECURITY_BIT_NO 31
+#define GEN_CLK_PLL_SECURITY (1 << GEN_CLK_PLL_SECURITY_BIT_NO)
+#define GEN_CLK_PLL_ENSAT (1 << 30)
+#define GEN_CLK_PLL_FASTEN (1 << 29)
+#define GEN_CLK_PLL_NR(v) (((v) - 1) << 23)
+#define GEN_CLK_PLL_NF(v) (((v) - 1) << 11)
+#define GEN_CLK_PLL_OD(v) (((v) - 1) << 8)
+#define GEN_CLK_PLL_RESET (1 << 7)
+#define GEN_CLK_PLL_BYPASS (1 << 6)
+#define GEN_CLK_PLL_POWERDOWN (1 << 5)
+#define GEN_CLK_PLL_SELECT (1 << 4)
+
+#define GEN_GET_CLK_PLL_NR(v) ((((v) >> 23) & 0x003f) + 1)
+#define GEN_GET_CLK_PLL_NF(v) ((((v) >> 11) & 0x0fff) + 1)
+#define GEN_GET_CLK_PLL_OD(v) ((((v) >> 8) & 0x7) + 1)
+
+
+#define RESET_FLAG_DST_MEM_ERROR (1 << 18)
+#define RESET_FLAG_SRC1_MEM_ERROR (1 << 17)
+#define RESET_FLAG_WRITE_ADDR (1 << 16)
+#define RESET_FLAG_DST_SYNC_ERROR (1 << 15)
+#define RESET_FLAG_SRC1_SYNC_ERROR (1 << 14)
+#define RESET_FLAG_DST_ALGN_ERROR (1 << 13)
+#define RESET_FLAG_SRC1_ALGN_ERROR (1 << 12)
+#define RESET_FLAG_DST_ADDR_ERROR (1 << 11)
+#define RESET_FLAG_SRC1_ADDR_ERROR (1 << 10)
+#define RESET_FLAG_ILLEGAL_INST (1 << 9)
+#define RESET_FLAG_INST_SYNC_ERROR (1 << 8)
+#define RESET_FLAG_INST_ADDR_ERROR (1 << 7)
+#define RESET_FLAG_DATA_PORT_ERROR (1 << 6)
+#define RESET_FLAG_INST_PORT_ERROR (1 << 5)
+#define RESET_FLAG_SW_RESET (1 << 4)
+#define RESET_FLAG_DEBUG (1 << 3)
+#define RESET_FLAG_WATCHDOG (1 << 2)
+#define RESET_FLAG_POWER_ON (1 << 1)
+#define RESET_FLAG_EXTERNAL (1 << 0)
+
+/*
+ * Timer block
+ */
+#define TIMER_BASE (OCP_BASE + OCP_TIMERS)
+#define TIMER_MPTVAL 0x00
+#define TIMER_RTCOM 0x04
+#define TIMER_TKEY 0x08
+#define TIMER_WDCOM 0x0c
+#define TIMER_WDCFG 0x10
+#define TIMER_SYSVAL 0x14
+#define TIMER_SYSCOM(tmr) (0x18 + (tmr) * 4)
+#define TIMER_TRN_CFG 0x100
+#define TIMER_TRN 0x104
+
+#define TIMER_COUNT 10
+#define TIMER_INT(tmr) INT_CHIP(1, (tmr))
+#define TIMER_TKEYVAL 0xa1b2c3d4
+#define TIMER_WATCHDOG_DISABLE 0x4d3c2b1a
+#define TIMER_TRN_CFG_ENABLE_OSC 0x00000007
+
+#ifndef __ASSEMBLY__
+/*
+ * ubicom32_io_timer
+ */
+struct ubicom32_io_timer {
+	volatile u32_t mptval;
+	volatile u32_t rtcom;
+	volatile u32_t tkey;
+	volatile u32_t wdcom;
+	volatile u32_t wdcfg;
+	volatile u32_t sysval;
+	volatile u32_t syscom[TIMER_COUNT];
+	volatile u32_t reserved[64 - 6 - TIMER_COUNT];	// skip all the way to OCP-TRNG section
+	volatile u32_t rsgcfg;
+	volatile u32_t trn;
+};
+
+#define UBICOM32_IO_TIMER ((struct ubicom32_io_timer *)TIMER_BASE)
+#endif
+
+#define UBICOM32_VECTOR_TO_TIMER_INDEX(vector) (vector - TIMER_INT(0))
+
+/*
+ * OCP-Debug Module (Mailbox)
+ */
+#define ISD_MAILBOX_BASE (OCP_BASE + OCP_DEBUG)
+#define ISD_MAILBOX_IN 0x00
+#define ISD_MAILBOX_OUT 0x04
+#define ISD_MAILBOX_STATUS 0x08
+
+#define ISD_MAILBOX_INT INT_CHIP(1, 30)
+
+#define ISD_MAILBOX_STATUS_IN_FULL (1 << 31)
+#define ISD_MAILBOX_STATUS_IN_EMPTY (1 << 30)
+#define ISD_MAILBOX_STATUS_OUT_FULL (1 << 29)
+#define ISD_MAILBOX_STATUS_OUT_EMPTY (1 << 28)
+
+/*
+ * OCP-Security
+ */
+#define SECURITY_BASE (OCP_BASE + OCP_SECURITY)
+#define SECURITY_BASE_EFFECTIVE_ADDRESS (SECURITY_BASE >> 7) // To load the base address in a single instruction
+#define SECURITY_CTRL 0x00
+#define SECURITY_CTRL_BYTE_OFFSET(x) ((x) << 16)
+#define SECURITY_CTRL_KEY_SIZE(x) ((x) << 8)
+#define SECURITY_CTRL_HASH_ALG_NONE (0 << 4)
+#define SECURITY_CTRL_HASH_ALG_MD5 (1 << 4)
+#define SECURITY_CTRL_HASH_ALG_SHA1 (2 << 4)
+#define SECURITY_CTRL_CBC (1 << 3)
+#define SECURITY_CTRL_CIPHER_ALG_AES (0 << 1)
+#define SECURITY_CTRL_CIPHER_ALG_NONE (1 << 1)
+#define SECURITY_CTRL_CIPHER_ALG_DES (2 << 1)
+#define SECURITY_CTRL_CIPHER_ALG_3DES (3 << 1)
+#define SECURITY_CTRL_ENCIPHER (1 << 0)
+#define SECURITY_CTRL_DECIPHER (0 << 0)
+#define SECURITY_STAT 0x04
+#define SECURITY_STAT_BUSY (1 << 0)
+#define SECURITY_KEY_VALUE(x) (0x10 + (x) * 4)
+#define SECURITY_KEY_IN(x) (0x30 + (x) * 4)
+#define SECURITY_KEY_OUT(x) (0x50 + (x) * 4)
+#define SECURITY_KEY_HASH(x) (0x70 + (x) * 4)
+
+/*
+ * OCP-ICCR
+ */
+#define ICCR_BASE (OCP_BASE + OCP_ICCR)
+#define ICACHE_TOTAL_SIZE 16384			/* in bytes */
+
+/*
+ * OCP-DCCR
+ */
+#define DCCR_BASE (OCP_BASE + OCP_DCCR)
+#if defined(IP5000) || defined(IP5000_REV2)
+#define DCACHE_TOTAL_SIZE 8192			/* in bytes */
+#elif defined(IP7000) || defined(IP7000_REV2)
+#define DCACHE_TOTAL_SIZE 16384			/* in bytes */
+#endif
+
+#if defined(IP5000) || defined(IP5000_REV2) || defined(IP7000) || defined(IP7000_REV2)
+#define DCACHE_WRITE_QUEUE_LENGTH 6
+#else
+#error "Unknown IP5K silicon"
+#endif
+
+#define CACHE_LINE_SIZE 32			/* in bytes */
+
+#define CCR_ADDR 0x00
+#define CCR_RDD 0x04
+#define CCR_WRD 0x08
+#define CCR_STAT 0x0c
+#define CCR_CTRL 0x10
+
+#define CCR_STAT_MCBE 0
+#define CCR_STAT_WIDEL 1			/* D-cache only */
+
+#define CCR_CTRL_DONE 0
+#define CCR_CTRL_RESET 2
+#define CCR_CTRL_VALID 3
+#define CCR_CTRL_RD_DATA (1 << 4)
+#define CCR_CTRL_RD_TAG (2 << 4)
+#define CCR_CTRL_WR_DATA (3 << 4)
+#define CCR_CTRL_WR_TAG (4 << 4)
+#define CCR_CTRL_INV_INDEX (5 << 4)
+#define CCR_CTRL_INV_ADDR (6 << 4)
+#define CCR_CTRL_FLUSH_INDEX (7 << 4)		/* D-cache only */
+#define CCR_CTRL_FLUSH_INV_INDEX (8 << 4)	/* D-cache only */
+#define CCR_CTRL_FLUSH_ADDR (9 << 4)		/* D-cache only */
+#define CCR_CTRL_FLUSH_INV_ADDR (10 << 4)	/* D-cache only */
+
+/*
+ * OCP-OCMC
+ */
+#define OCMC_BASE (OCP_BASE + OCP_OCMC)
+#define OCMC_BANK_MASK 0x00
+#define OCMC_BIST_CNTL 0x04	/* IP5000 only */
+#define OCMC_BIST_STAT 0x08	/* IP5000 only */
+
+#define OCMC_BANK_PROG(n) ((1<<(n))-1)
+
+#define OCMC_BIST_WRCK (1 << 7)
+#define OCMC_BIST_RESET (1 << 5)
+#define OCMC_BIST_SMART (1 << 4)
+#define OCMC_BIST_RUN (1 << 3)
+#define OCMC_BIST_REPAIR (1 << 2)
+
+#define OCMC_BIST_READY (1 << 3)
+#define OCMC_BIST_FAIL (1 << 2)
+
+/*
+ * OCP-STATISTICS
+ */
+#define STATISTICS_BASE (OCP_BASE + OCP_STATISTICS)
+#define STAT_COUNTER_CTRL(n) ((n)*8)
+#define STAT_COUNTER(n) ((n)*8 + 4)
+
+#define STAT_EVENT_MP_INST 0
+#define STAT_EVENT_OCM_ACCESS 4
+#define STAT_EVENT_OCM_REQ 5
+#define STAT_EVENT_IC_REQ_INVAL 13
+#define STAT_EVENT_IC_MISS_INVAL 14
+#define STAT_EVENT_IC_REQ_INVAL_NACK 15
+#define STAT_EVENT_IC_REQ_VAL 16
+#define STAT_EVENT_IC_MISS_VAL 17
+#define STAT_EVENT_IC_REQ_VAL_NACK 18
+#define STAT_EVENT_IC_MISS_Q 19
+#define STAT_EVENT_DC_RD_REQ 20
+#define STAT_EVENT_DC_RD_MISS 21
+#define STAT_EVENT_DC_WR_REQ 22
+#define STAT_EVENT_DC_WR_MISS 23
+#define STAT_EVENT_DC_MISS_Q 24
+#define STAT_EVENT_DC_WB_FULL 25
+#define STAT_EVENT_DC_REQ_NACK 26
+#define STAT_EVENT_DC_CORE_REQ 27
+#define STAT_EVENT_DC_MISS 28
+#define STAT_EVENT_DC_EVICT 29
+#define STAT_EVENT_TRUE 30
+#define STAT_EVENT_FALSE 31
+
+/*
+ * OCP_MTEST
+ */
+#define MTEST_BASE (OCP_BASE + OCP_MTEST)
+#define MTEST_ADDR 0x00
+#define MTEST_WR 0x04
+#define MTEST_RD 0x08
+#define MTEST_CTRL 0x0c
+
+/*
+ * OCP_MCFG (IP7000 only)
+ */
+#define MCFG_BASE (OCP_BASE + OCP_MCFG)
+#define MCFG_CTRL 0x00
+#define MCFG_WCFG 0x04
+#define MCFG_RCFG 0x08
+
+/*
+ * Port registers
+ */
+#define IO_BASE 0x02000000
+#define RA (IO_BASE + 0x00000000)
+#define RB (IO_BASE + 0x00001000)
+#define RC (IO_BASE + 0x00002000)
+#define RD (IO_BASE + 0x00003000)
+#define RE (IO_BASE + 0x00004000)
+#define RF (IO_BASE + 0x00005000)
+#define RG (IO_BASE + 0x00006000)
+#define RH (IO_BASE + 0x00007000)
+#define RI (IO_BASE + 0x00008000)
+#define RJ (IO_BASE + 0x00009000)
+#define RLATCH (IO_BASE + 0x00ff0000)	// For latched output only
+#define IO_PORT_BR_OFFSET 0x00000800
+
+/*
+ * General I/O Register Map (per port)
+ */
+#define IO_FUNC 0x00
+#define IO_GPIO_CTL 0x04
+#define IO_GPIO_OUT 0x08
+#define IO_GPIO_IN 0x0C
+#define IO_INT_STATUS 0x10
+#define IO_INT_MASK 0x14
+#define IO_INT_SET 0x18
+#define IO_INT_CLR 0x1C
+#define IO_TX_FIFO 0x20
+#define IO_TX_FIFO_HI 0x24
+#define IO_RX_FIFO 0x28
+#define IO_RX_FIFO_HI 0x2c
+#define IO_CTL0 0x30
+#define IO_CTL1 0x34
+#define IO_CTL2 0x38
+#define IO_STATUS0 0x3c
+#define IO_STATUS1 0x40
+#define IO_STATUS2 0x44
+#define IO_FIFO_WATER 0x48
+#define IO_FIFO_LEVEL 0x4c
+#define IO_GPIO_MASK 0x50
+
+#define IO_FUNC_FUNCTION_RESET(func) ((1 << ((func) - 1)) << 4)	/* Function 0 doesn't need reset */
+#define IO_FUNC_RX_FIFO (1 << 3)
+#define IO_FUNC_SELECT(func) ((func) << 0)
+
+/*
+ * External interrupt pins.
+ */
+#define EXT_INT_IO_BIT(pin) ((pin) + 5)	// Interrupt pin number -> I/O INT bit
+#define EXT_INT_RISING_EDGE(pin) (0x2 << (2*(pin) + 7))
+#define EXT_INT_FALLING_EDGE(pin) (0x1 << (2*(pin) + 7))
+
+/*
+ * Flash
+ */
+#define IO_XFL_BASE RA
+
+#define IO_XFL_INT_START (1 << 16)
+#define IO_XFL_INT_ERR (1 << 8)
+#define IO_XFL_INT_DONE (1 << 0)
+
+#define IO_XFL_CTL0_MASK (0xffe07fff)
+#define IO_XFL_CTL0_RD_CMD(cmd) (((cmd) & 0xff) << 24)
+#define IO_XFL_CTL0_RD_DUMMY(n) (((n) & 0x7) << 21)
+#define IO_XFL_CTL0_CLK_WIDTH(core_cycles) ((((core_cycles) + 1) & 0x7e) << 8)	/* must be even number */
+#define IO_XFL_CTL0_CE_WAIT(spi_cycles) (((spi_cycles) & 0x3f) << 2)
+#define IO_XFL_CTL0_MCB_LOCK (1 << 1)
+#define IO_XFL_CTL0_ENABLE (1 << 0)
+#define IO_XFL_CTL0_FAST_VALUE(div, wait) (IO_XFL_CTL0_RD_CMD(0xb) | IO_XFL_CTL0_RD_DUMMY(1) | IO_XFL_CTL0_CLK_WIDTH(div) | IO_XFL_CTL0_CE_WAIT(wait) | IO_XFL_CTL0_ENABLE)
+#define IO_XFL_CTL0_VALUE(div, wait) (IO_XFL_CTL0_RD_CMD(3) | IO_XFL_CTL0_CLK_WIDTH(div) | IO_XFL_CTL0_CE_WAIT(wait) | IO_XFL_CTL0_ENABLE)
+
+#define IO_XFL_CTL1_MASK (0xc0003fff)
+#define IO_XFL_CTL1_FC_INST(inst) (((inst) & 0x3) << 30)
+#define IO_XFL_CTL1_FC_DATA(n) (((n) & 0x3ff) << 4)
+#define IO_XFL_CTL1_FC_DUMMY(n) (((n) & 0x7) << 1)
+#define IO_XFL_CTL1_FC_ADDR (1 << 0)
+
+#define IO_XFL_CTL2_FC_CMD(cmd) (((cmd) & 0xff) << 24)
+#define IO_XFL_CTL2_FC_ADDR(addr) ((addr) & 0x00ffffff)	/* Only up to 24 bits */
+
+#define IO_XFL_STATUS0_MCB_ACTIVE (1 << 0)
+#define IO_XFL_STATUS0_IOPCS_ACTIVE (1 << 1)
+
+/*
+ * SDRAM
+ */
+#define IO_SDRAM_DATA_BASE RG
+#define IO_SDRAM_CNTL_BASE RH
+
+#define IO_SDRAM_CTRL0_EN_REF (1 << 0)
+
+/*
+ * Port function code (common fucntion codes for all I/O ports)
+ */
+#define IO_PORTX_FUNC_GPIO 0x00
+#define IO_PORTX_FUNC_XFL 0x01
+#define IO_PORTX_FUNC_PCI 0x01
+#define IO_PORTX_FUNC_SERDES 0x01
+#define IO_PORTX_FUNC_GMII 0x01
+#define IO_PORTX_FUNC_DDR 0x01
+#define IO_PORTX_FUNC_PCIX 0x01
+#define IO_PORTX_FUNC_USB2_0 0x01
+#define IO_PORTX_FUNC_GPIO_INT_CLK 0x02
+#define IO_PORTX_FUNC_PLIO 0x02
+#define IO_PORTX_FUNC_GPIO_INT 0x03
+#define IO_PORTX_FUNC_MII 0x03
+
+/*
+ * Port 0
+ */
+#define IO_PORT0_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT0_FUNC_XFL_INT_CLK IO_PORTX_FUNC_XFL	// Default mode after reset
+#define IO_PORT0_FUNC_GPIO_INT_CLK IO_PORTX_FUNC_GPIO_INT_CLK
+#define IO_PORT0_FUNC_GPIO_INT IO_PORTX_FUNC_GPIO_INT
+
+/*
+ * Port 1
+ */
+#define IO_PORT1_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT1_FUNC_PCI IO_PORTX_FUNC_PCI		// PCI control
+#define IO_PORT1_FUNC_MII IO_PORTX_FUNC_MII		// port 4 MII extension
+
+/*
+ * Port 2
+ */
+#define IO_PORT2_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT2_FUNC_PCI IO_PORTX_FUNC_PCI		// PCI data I/O
+#define IO_PORT2_FUNC_PLIO IO_PORTX_FUNC_PLIO		// Extended LM
+
+/*
+ * Port 3
+ */
+#define IO_PORT3_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT3_FUNC_SERDES IO_PORTX_FUNC_SERDES
+#define IO_PORT3_FUNC_PLIO IO_PORTX_FUNC_PLIO
+
+/*
+ * Port 4
+ */
+#define IO_PORT4_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT4_FUNC_SERDES IO_PORTX_FUNC_SERDES
+#define IO_PORT4_FUNC_PLIO IO_PORTX_FUNC_PLIO		// Extended LM
+#define IO_PORT4_FUNC_MII IO_PORTX_FUNC_MII
+
+/*
+ * Port 5
+ */
+#define IO_PORT5_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT5_FUNC_GMII IO_PORTX_FUNC_GMII
+
+/*
+ * Port 6
+ */
+#define IO_PORT6_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT6_FUNC_DDR IO_PORTX_FUNC_DDR
+
+/*
+ * Port 7
+ */
+#define IO_PORT7_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT7_FUNC_DDR IO_PORTX_FUNC_DDR
+
+/*
+ * Port 8
+ */
+#define IO_PORT8_FUNC_GPIO IO_PORTX_FUNC_GPIO
+#define IO_PORT8_FUNC_PCIX IO_PORTX_FUNC_PCIX
+#define IO_PORT8_FUNC_PLIO IO_PORTX_FUNC_PLIO		// Extended LM
+#define IO_PORT8_FUNC_MII IO_PORTX_FUNC_MII		// port 4 MII extension
+
+/*
+ * Port 9
+ */
+#define IO_PORT9_FUNC_USB2_0 IO_PORTX_FUNC_USB2_0
+
+/*
+ * FIFO
+ */
+#define IO_PORTX_INT_FIFO_TX_RESET (1 << 31)
+#define IO_PORTX_INT_FIFO_RX_RESET (1 << 30)
+#define IO_PORTX_INT_FIFO_TX_UF (1 << 15)
+#define IO_PORTX_INT_FIFO_TX_WM (1 << 14)
+#define IO_PORTX_INT_FIFO_RX_OF (1 << 13)
+#define IO_PORTX_INT_FIFO_RX_WM (1 << 12)
+
+#define IO_PORTX_FUNC_FIFO_TX_WM(n) ((n) << 16)
+#define IO_PORTX_FUNC_FIFO_RX_WM(n) ((n) << 0)
+
+/*
+ * MII
+ */
+#define IO_PORTX_INT_MII_TX_ERR_SEND (1 << 18)
+#define IO_PORTX_INT_MII_TX_HALT (1 << 17)
+#define IO_PORTX_INT_MII_TX_START (1 << 16)
+#define IO_PORTX_INT_MII_THRESHOLD (1 << 8)
+#define IO_PORTX_INT_MII_RX_EOP (1 << 7)
+#define IO_PORTX_INT_MII_RX_SFD (1 << 6)
+#define IO_PORTX_INT_MII_RX_ERR (1 << 5)
+#define IO_PORTX_INT_MII_TX_EOP (1 << 4)
+#define IO_PORTX_INT_MII_COL (1 << 3)
+#define IO_PORTX_INT_MII_CRS (1 << 2)
+#define IO_PORTX_INT_MII_ODD_NIB_ERR (1 << 1)
+#define IO_PORTX_INT_MII_FALSE_CARRIER (1 << 0)
+
+/*
+ * SerDes
+ */
+#define IO_PORTX_INT_SERDES_TXBUF_VALID (1 << 16)
+#define IO_PORTX_INT_SERDES_RXERR (1 << 7)
+#define IO_PORTX_INT_SERDES_RXEOP (1 << 6)
+#define IO_PORTX_INT_SERDES_SYND (1 << 5)
+#define IO_PORTX_INT_SERDES_TXBE (1 << 4)
+#define IO_PORTX_INT_SERDES_TXEOP (1 << 3)
+#define IO_PORTX_INT_SERDES_SXLP (1 << 2)
+#define IO_PORTX_INT_SERDES_RXBF (1 << 1)
+#define IO_PORTX_INT_SERDES_RXCRS (1 << 0)
+
+#ifndef __ASSEMBLY__
+struct ubicom32_io_port {
+	volatile u32_t function;
+	volatile u32_t gpio_ctl;
+	volatile u32_t gpio_out;
+	volatile u32_t gpio_in;
+	volatile u32_t int_status;
+	volatile u32_t int_mask;
+	volatile u32_t int_set;
+	volatile u32_t int_clr;
+	volatile u32_t tx_fifo;
+	volatile u32_t tx_fifo_hi;
+	volatile u32_t rx_fifo;
+	volatile u32_t rx_fifo_hi;
+	volatile u32_t ctl0;
+	volatile u32_t ctl1;
+	volatile u32_t ctl2;
+	volatile u32_t status0;
+	volatile u32_t status1;
+	volatile u32_t status2;
+	volatile u32_t fifo_watermark;
+	volatile u32_t fifo_level;
+	volatile u32_t gpio_mask;
+};
+
+#define UBICOM32_IO_PORT(port) ((struct ubicom32_io_port *)((port)))
+#endif
+
+#ifndef __ASSEMBLY__
+/*
+ * ubicom32_set_interrupt()
+ */
+extern inline void ubicom32_set_interrupt(u8_t interrupt)
+{
+	u32_t ibit = INT_BIT_MASK(interrupt);
+
+	if (INT_REG(interrupt) == INT_REG(INT_CHIP(0, 0))) {
+		asm volatile (
+			"move.4		"D(INT_SET(INT_CHIP(0, 0)))", %0\n\t"
+			:
+			: "r" (ibit)
+		);
+
+		return;
+	}
+
+	asm volatile (
+		"move.4		"D(INT_SET(INT_CHIP(1, 0)))", %0\n\t"
+		:
+		: "r" (ibit)
+	);
+}
+
+/*
+ * ubicom32_clear_interrupt()
+ */
+extern inline void ubicom32_clear_interrupt(u8_t interrupt)
+{
+	u32_t ibit = INT_BIT_MASK(interrupt);
+
+	if (INT_REG(interrupt) == INT_REG(INT_CHIP(0, 0))) {
+		asm volatile (
+			"move.4		"D(INT_CLR(INT_CHIP(0, 0)))", %0\n\t"
+			:
+			: "r" (ibit)
+		);
+
+		return;
+	}
+
+	asm volatile (
+		"move.4		"D(INT_CLR(INT_CHIP(1, 0)))", %0\n\t"
+		:
+		: "r" (ibit)
+	);
+}
+
+/*
+ * ubicom32_enable_interrupt()
+ */
+extern inline void ubicom32_enable_interrupt(u8_t interrupt)
+{
+	u32_t ibit = INT_BIT_MASK(interrupt);
+
+	if (INT_REG(interrupt) == INT_REG(INT_CHIP(0, 0))) {
+		asm volatile (
+			"or.4		"D(INT_MASK(INT_CHIP(0, 0)))", "D(INT_MASK(INT_CHIP(0, 0)))", %0\n\t"
+			:
+			: "d" (ibit)
+		);
+
+		return;
+	}
+
+	asm volatile (
+		"or.4		"D(INT_MASK(INT_CHIP(1, 0)))", "D(INT_MASK(INT_CHIP(1, 0)))", %0\n\t"
+		:
+		: "d" (ibit)
+	);
+}
+
+/*
+ * ubicom32_disable_interrupt()
+ */
+extern inline void ubicom32_disable_interrupt(u8_t interrupt)
+{
+	u32_t ibit = ~INT_BIT_MASK(interrupt);
+
+	if (INT_REG(interrupt) == INT_REG(INT_CHIP(0, 0))) {
+		asm volatile (
+			"and.4		"D(INT_MASK(INT_CHIP(0, 0)))", "D(INT_MASK(INT_CHIP(0, 0)))", %0\n\t"
+			:
+			: "d" (ibit)
+		);
+
+		return;
+	}
+
+	asm volatile (
+		"and.4		"D(INT_MASK(INT_CHIP(1, 0)))", "D(INT_MASK(INT_CHIP(1, 0)))", %0\n\t"
+		:
+		: "d" (ibit)
+	);
+}
+
+/*
+ * ubicom32_enable_global_interrupts()
+ */
+extern inline void ubicom32_enable_global_interrupts(void)
+{
+	asm volatile(
+		"bset		GLOBAL_CTRL, GLOBAL_CTRL, #%bit("D(GLOBAL_CTRL_INT_EN)")"
+	);
+}
+
+/*
+ * ubicom32_disable_global_interrupts()
+ */
+extern inline void ubicom32_disable_global_interrupts(void)
+{
+	asm volatile(
+		"bclr		GLOBAL_CTRL, GLOBAL_CTRL, #%bit("D(GLOBAL_CTRL_INT_EN)")"
+	);
+}
+
+/*
+ * ubicom32_get_reset_reason()
+ */
+extern inline u32_t ubicom32_get_reset_reason(void)
+{
+	return *(u32_t *)(GENERAL_CFG_BASE + GEN_RESET_REASON);
+}
+
+/*
+ * ubicom32_read_reg()
+ */
+extern inline u32_t ubicom32_read_reg(volatile void *reg)
+{
+	u32_t v;
+	asm volatile (
+		"move.4		%[dest], %[src]	\n\t"
+		: [dest] "=r" (v)
+		: [src] "m" (*(u32_t *)reg)
+	);
+	return v;
+}
+
+/*
+ * ubicom32_write_reg()
+ */
+extern inline void ubicom32_write_reg(volatile void *reg, u32_t v)
+{
+	asm volatile (
+		"move.4		%[dest], %[src]	\n\t"
+		:
+		: [src] "r" (v), [dest] "m" (*(u32_t *)reg)
+	);
+}
+
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_UBICOM32_IP5000_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ipcbuf.h
@@ -0,0 +1,55 @@
+/*
+ * arch/ubicom32/include/asm/ipcbuf.h
+ *   Definition of ipc64_perm struct for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IPCBUF_H
+#define _ASM_UBICOM32_IPCBUF_H
+
+/*
+ * The user_ipc_perm structure for m68k architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t and seq
+ * - 2 miscellaneous 32-bit values
+ */
+struct ipc64_perm
+{
+	__kernel_key_t		key;
+	__kernel_uid32_t	uid;
+	__kernel_gid32_t	gid;
+	__kernel_uid32_t	cuid;
+	__kernel_gid32_t	cgid;
+	__kernel_mode_t		mode;
+	unsigned short		__pad1;
+	unsigned short		seq;
+	unsigned short		__pad2;
+	unsigned long		__unused1;
+	unsigned long		__unused2;
+};
+
+#endif /* _ASM_UBICOM32_IPCBUF_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/irqflags.h
@@ -0,0 +1,94 @@
+/*
+ * arch/ubicom32/include/asm/irqflags.h
+ *   Raw implementation of local IRQ functions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IRQFLAGS_H
+#define _ASM_UBICOM32_IRQFLAGS_H
+
+#include <linux/thread_info.h>
+#include <asm/ubicom32-common.h>
+#include <asm/smp.h>
+#include <asm/ldsr.h>
+
+#if defined(CONFIG_PREEMPT)
+#error Not supported by Ubicom32 irq handling, yet!
+#endif
+
+/*
+ * raw_local_irq_enable()
+ *	Enable interrupts for this thread.
+ */
+static inline void raw_local_irq_enable(void)
+{
+	ldsr_local_irq_enable();
+}
+
+/*
+ * raw_local_irq_disable()
+ *	Disable interrupts for this thread.
+ */
+static inline void raw_local_irq_disable(void)
+{
+	ldsr_local_irq_disable();
+}
+
+/*
+ * raw_local_save_flags()
+ *	Get the current IRQ state.
+ */
+#define raw_local_save_flags(flags) 		\
+do {						\
+	(flags) = ldsr_local_irq_is_disabled();	\
+} while (0)
+
+/*
+ * raw_local_irq_save()
+ *	Save the current interrupt state and disable interrupts.
+ */
+#define raw_local_irq_save(flags)		\
+do {						\
+	(flags) = ldsr_local_irq_save();	\
+} while (0)
+
+/*
+ * raw_local_irq_restore()
+ *	Restore the IRQ state back to flags.
+ */
+static inline void raw_local_irq_restore(unsigned long flags)
+{
+	ldsr_local_irq_restore(flags);
+}
+
+/*
+ * raw_irqs_disabled_flags()
+ *	Return true if the flags indicate that IRQ(s) are disabled.
+ */
+static inline int raw_irqs_disabled_flags(unsigned long flags)
+{
+	return (flags);
+}
+
+#endif /* _ASM_UBICOM32_IRQFLAGS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/irq.h
@@ -0,0 +1,45 @@
+/*
+ * arch/ubicom32/include/asm/irq.h
+ *   IRQ definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IRQ_H
+#define _ASM_UBICOM32_IRQ_H
+
+#include <asm/irqflags.h>
+
+/*
+ * We setup the IRQS to cover the full range of interrupt registers in
+ * processor.
+ */
+#define NR_IRQS		64
+
+#define irq_canonicalize(irq) (irq)
+
+extern int irq_soft_alloc(unsigned int *soft);
+extern void ack_bad_irq(unsigned int irq);
+extern void do_IRQ(int irq, struct pt_regs *fp);
+
+#endif /* _ASM_UBICOM32_IRQ_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/irq_regs.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/irq_regs.h
+ *   Generic irq_regs.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_IRQ_REGS_H
+#define _ASM_UBICOM32_IRQ_REGS_H
+
+#include <asm-generic/irq_regs.h>
+
+#endif /* _ASM_UBICOM32_IRQ_REGS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/Kbuild
@@ -0,0 +1 @@
+include include/asm-generic/Kbuild.asm
--- /dev/null
+++ b/arch/ubicom32/include/asm/kdebug.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/kdebug.h
+ *   Generic kdebug.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_KDEBUG_H
+#define _ASM_UBICOM32_KDEBUG_H
+
+#include <asm-generic/kdebug.h>
+
+#endif /* _ASM_UBICOM32_KDEBUG_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/kmap_types.h
@@ -0,0 +1,48 @@
+/*
+ * arch/ubicom32/include/asm/kmap_types.h
+ *   Definition of km_type's for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_KMAP_TYPES_H
+#define _ASM_UBICOM32_KMAP_TYPES_H
+
+enum km_type {
+	KM_BOUNCE_READ,
+	KM_SKB_SUNRPC_DATA,
+	KM_SKB_DATA_SOFTIRQ,
+	KM_USER0,
+	KM_USER1,
+	KM_BIO_SRC_IRQ,
+	KM_BIO_DST_IRQ,
+	KM_PTE0,
+	KM_PTE1,
+	KM_IRQ0,
+	KM_IRQ1,
+	KM_SOFTIRQ0,
+	KM_SOFTIRQ1,
+	KM_TYPE_NR
+};
+
+#endif /* _ASM_UBICOM32_KMAP_TYPES_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ldsr.h
@@ -0,0 +1,186 @@
+/*
+ * arch/ubicom32/include/asm/ldsr.h
+ *   Ubicom32 LDSR interface definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_LDSR_H
+#define _ASM_UBICOM32_LDSR_H
+
+#include <asm/ubicom32-common.h>
+#include <asm/types.h>
+#include <asm/thread.h>
+
+extern unsigned int ldsr_soft_irq_mask;
+
+/*
+ * ldsr_local_irq_is_disabled()
+ *	Test if interrupts are disabled for this thread?
+ */
+static inline int ldsr_local_irq_is_disabled(void)
+{
+	int ret;
+	thread_t self = thread_get_self();
+	unsigned int mask = (1 << self);
+
+	asm volatile (
+	"	and.4	%0, scratchpad1, %1	\n\t"
+		: "=r" (ret)
+		: "d" (mask)
+		: "cc"
+	);
+
+	/*
+	 *  We return a simple 1 == disabled, 0 == enabled
+	 *  losing which tid this is for, because Linux
+	 *  can restore interrupts on a different thread.
+	 */
+	return ret >> self;
+}
+
+/*
+ * ldsr_local_irq_save()
+ *	Get the current interrupt state and disable interrupts.
+ */
+static inline unsigned int ldsr_local_irq_save(void)
+{
+	int ret;
+	thread_t self = thread_get_self();
+	unsigned int mask = (1 << self);
+
+	/*
+	 * Ensure the compiler can not optimize out the code
+	 * (volatile) and that it does not "cache" values around
+	 * the interrupt state change (memory).  This ensures
+	 * that interrupt changes are treated as a critical
+	 * section.
+	 */
+	asm volatile (
+	"	and.4	%0, scratchpad1, %1		\n\t"
+	"	or.4	scratchpad1, scratchpad1, %1	\n\t"
+		: "=&r" (ret)
+		: "d" (mask)
+		: "cc", "memory"
+	);
+
+	/*
+	 *  We return a simple 1 == disabled, 0 == enabled
+	 *  losing which tid this is for, because Linux
+	 *  can restore interrupts on a different thread.
+	 */
+	return ret >> self;
+}
+
+/*
+ * ldsr_local_irq_restore()
+ * 	Restore this cpu's interrupt enable/disable state.
+ *
+ * Note: flags is either 0 or 1.
+ */
+static inline void ldsr_local_irq_restore(unsigned int flags)
+{
+	unsigned int temp;
+	thread_t self = thread_get_self();
+	unsigned int mask = (1 << self);
+	flags = (flags << self);
+
+	/*
+	 * Ensure the compiler can not optimize out the code
+	 * (volatile) and that it does not "cache" values around
+	 * the interrupt state change (memory).  This ensures
+	 * that interrupt changes are treated as a critical
+	 * section.
+	 *
+	 * Atomic change to our bit in scratchpad1 without
+	 * causing any temporary glitch in the value and
+	 * without effecting other values.  Also this uses
+	 * no branches so no penalties.
+	 */
+	asm volatile (
+	"	xor.4	%0, scratchpad1, %1		\n\t"
+	"	and.4	%0, %2, %0			\n\t"
+	"	xor.4	scratchpad1, scratchpad1, %0	\n\t"
+	"	move.4	int_set0, %3			\n\t"
+		: "=&d"(temp)
+		: "d"(flags), "r"(mask), "r"(ldsr_soft_irq_mask)
+		: "cc", "memory"
+	);
+}
+
+/*
+ * ldsr_local_irq_disable_interrupt()
+ * 	Disable ints for this thread.
+ */
+static inline void ldsr_local_irq_disable(void)
+{
+	unsigned int mask = (1 << thread_get_self());
+
+	/*
+	 * Ensure the compiler can not optimize out the code
+	 * (volatile) and that it does not "cache" values around
+	 * the interrupt state change (memory).  This ensures
+	 * that interrupt changes are treated as a critical
+	 * section.
+	 */
+	asm  volatile (
+	"	or.4	scratchpad1, scratchpad1, %0	\n\t"
+		:
+		: "d" (mask)
+		: "cc", "memory"
+	);
+}
+
+/*
+ * ldsr_local_irq_enable_interrupt
+ * 	Enable ints for this thread.
+ */
+static inline void ldsr_local_irq_enable(void)
+{
+	unsigned int mask = (1 << thread_get_self());
+
+	/*
+	 * Ensure the compiler can not optimize out the code
+	 * (volatile) and that it does not "cache" values around
+	 * the interrupt state change (memory).  This ensures
+	 * that interrupt changes are treated as a critical
+	 * section.
+	 */
+	asm volatile (
+	"	and.4	scratchpad1, scratchpad1, %0	\n\t"
+	"	move.4	int_set0, %1			\n\t"
+		:
+		: "d" (~mask), "r" (ldsr_soft_irq_mask)
+		: "cc", "memory"
+	);
+}
+
+extern void ldsr_init(void);
+extern void ldsr_set_trap_irq(unsigned int irq);
+extern void ldsr_mask_vector(unsigned int vector);
+extern void ldsr_unmask_vector(unsigned int vector);
+extern void ldsr_enable_vector(unsigned int vector);
+extern void ldsr_disable_vector(unsigned int vector);
+extern thread_t ldsr_get_threadid(void);
+
+#endif /* _ASM_UBICOM32_LDSR_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/linkage.h
@@ -0,0 +1,34 @@
+/*
+ * arch/ubicom32/include/asm/linkage.h
+ *   Definition of Ubicom32 architecture specific linkage types.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_LINKAGE_H
+#define _ASM_UBICOM32_LINKAGE_H
+
+#define __ocm_text __section(.ocm_text)
+#define __ocm_data __section(.ocm_data)
+
+#endif	/* _ASM_UBICOM32_LINKAGE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/local.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/local.h
+ *   Generic local.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_LOCAL_H
+#define _ASM_UBICOM32_LOCAL_H
+
+#include <asm-generic/local.h>
+
+#endif /* _ASM_UBICOM32_LOCAL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/machdep.h
@@ -0,0 +1,43 @@
+/*
+ * arch/ubicom32/include/asm/machdep.h
+ *   Machine dependent utility routines.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_MACHDEP_H
+#define _ASM_UBICOM32_MACHDEP_H
+
+#include <linux/interrupt.h>
+
+/* Hardware clock functions */
+extern unsigned long hw_timer_offset(void);
+
+/* machine dependent power off functions */
+extern void (*mach_reset)(void);
+extern void (*mach_halt)(void);
+extern void (*mach_power_off)(void);
+
+extern void config_BSP(char *command, int len);
+
+#endif /* _ASM_UBICOM32_MACHDEP_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/mc146818rtc.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/mc146818rtc.h
+ *   Generic mc146818rtc.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ * Machine dependent access functions for RTC registers.
+ */
+#ifndef _ASM_UBICOM32_MC146818RTC_H
+#define _ASM_UBICOM32_MC146818RTC_H
+
+/* empty include file to satisfy the include in genrtc.c/ide-geometry.c */
+
+#endif /* _ASM_UBICOM32_MC146818RTC_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/mman.h
@@ -0,0 +1,44 @@
+/*
+ * arch/ubicom32/include/asm/mman.h
+ *   Memory mapping definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_MMAN_H
+#define _ASM_UBICOM32_MMAN_H
+
+#include <asm-generic/mman.h>
+
+#define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
+#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
+#define MAP_LOCKED	0x2000		/* pages are locked */
+#define MAP_NORESERVE	0x4000		/* don't check for reservations */
+#define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
+#define MAP_NONBLOCK	0x10000		/* do not block on IO */
+
+#define MCL_CURRENT	1		/* lock all current mappings */
+#define MCL_FUTURE	2		/* lock all future mappings */
+
+#endif /* _ASM_UBICOM32_MMAN_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/mmu_context.h
@@ -0,0 +1,60 @@
+/*
+ * arch/ubicom32/include/asm/mmu_context.h
+ *   MMU context definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004, Microtronix Datacom Ltd., All rights reserved.          
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_MMU_CONTEXT_H
+#define _ASM_UBICOM32_MMU_CONTEXT_H
+
+#include <asm/setup.h>
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+
+static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
+{
+}
+
+extern inline int
+init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+{
+	// mm->context = virt_to_phys(mm->pgd);
+	return(0);
+}
+
+#define destroy_context(mm)		do { } while(0)
+
+static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
+{
+}
+
+#define deactivate_mm(tsk,mm)	do { } while (0)
+
+extern inline void activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm)
+{
+}
+
+#endif /* _ASM_UBICOM32_MMU_CONTEXT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/mmu.h
@@ -0,0 +1,41 @@
+/*
+ * arch/ubicom32/include/asm/mmu.h
+ *   Definition of mm_context_t struct for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2002, David McCullough <davidm@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_MMU_H
+#define _ASM_UBICOM32_MMU_H
+
+typedef struct {
+	struct vm_list_struct	*vmlist;
+	unsigned long		end_brk;
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+	unsigned long	exec_fdpic_loadmap;
+	unsigned long	interp_fdpic_loadmap;
+#endif
+} mm_context_t;
+
+#endif /* _ASM_UBICOM32_MMU_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/module.h
@@ -0,0 +1,44 @@
+/*
+ * arch/ubicom32/include/asm/module.h
+ *   Ubicom32 architecture specific module definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_MODULE_H
+#define _ASM_UBICOM32_MODULE_H
+
+struct mod_arch_specific {
+	void *ocm_inst;
+	int ocm_inst_size;
+};
+
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Ehdr Elf32_Ehdr
+
+#define ARCH_PROC_MODULES_EXTRA(m,mod) \
+	seq_printf(m, " OCM(%d bytes @ 0x%p)", \
+		   (mod)->arch.ocm_inst_size, (mod)->arch.ocm_inst)
+
+#endif /* _ASM_UBICOM32_MODULE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/msgbuf.h
@@ -0,0 +1,58 @@
+/*
+ * arch/ubicom32/include/asm/msgbuf.h
+ *   Definition of msqid64_ds struct for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_MSGBUF_H
+#define _ASM_UBICOM32_MSGBUF_H
+
+/*
+ * The msqid64_ds structure for ubicom32 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+	struct ipc64_perm msg_perm;
+	__kernel_time_t msg_stime;	/* last msgsnd time */
+	unsigned long	__unused1;
+	__kernel_time_t msg_rtime;	/* last msgrcv time */
+	unsigned long	__unused2;
+	__kernel_time_t msg_ctime;	/* last change time */
+	unsigned long	__unused3;
+	unsigned long  msg_cbytes;	/* current number of bytes on queue */
+	unsigned long  msg_qnum;	/* number of messages in queue */
+	unsigned long  msg_qbytes;	/* max number of bytes on queue */
+	__kernel_pid_t msg_lspid;	/* pid of last msgsnd */
+	__kernel_pid_t msg_lrpid;	/* last receive pid */
+	unsigned long  __unused4;
+	unsigned long  __unused5;
+};
+
+#endif /* _ASM_UBICOM32_MSGBUF_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/mutex.h
@@ -0,0 +1,41 @@
+/*
+ * arch/ubicom32/include/asm/mutex.h
+ *   Generic mutex.h for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ * Pull in the generic implementation for the mutex fastpath.
+ *
+ * TODO: implement optimized primitives instead, or leave the generic
+ * implementation in place, or pick the atomic_xchg() based generic
+ * implementation. (see asm-generic/mutex-xchg.h for details)
+ */
+
+#ifndef _ASM_UBICOM32_MUTEX_H
+#define _ASM_UBICOM32_MUTEX_H
+
+#include <asm-generic/mutex-dec.h>
+
+#endif /* _ASM_UBICOM32_MUTEX_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/namei.h
@@ -0,0 +1,38 @@
+/*
+ * arch/ubicom32/include/asm/namei.h
+ *   Definition of __emul_prefix() for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_NAMEI_H
+#define _ASM_UBICOM32_NAMEI_H
+
+/* This dummy routine maybe changed to something useful
+ * for /usr/gnemul/ emulation stuff.
+ * Look at asm-sparc/namei.h for details.
+ */
+
+#define __emul_prefix() NULL
+
+#endif /* _ASM_UBICOM32_NAMEI_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ocm-alloc.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/ocm-alloc.h
+ *   Ubicom32 architecture specific ocm definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_OCM_ALLOC_H
+#define _ASM_UBICOM32_OCM_ALLOC_H
+
+
+extern void *ocm_inst_alloc(size_t size, pid_t pid);
+extern int ocm_free(const void *ptr);
+extern int ocm_inst_free(const void *ptr);
+
+#endif /* _ASM_UBICOM32_OCM_ALLOC_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ocm_size.h
@@ -0,0 +1,2 @@
+#define APP_OCM_CODE_SIZE (0x3ffc2e00-0x3ffc0000)
+#define APP_OCM_DATA_SIZE (0x3ffd3500-0x3ffc8000)
--- /dev/null
+++ b/arch/ubicom32/include/asm/ocm_text.lds.inc
@@ -0,0 +1,175 @@
+/*
+ * arch/ubicom32/include/asm/ocm_text.lds.inc
+ *	<TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+*(.text.do_csum)
+*(.text.tcp_packet)
+*(.text.ipt_do_table)
+*(.text.nf_conntrack_in)
+*(.text.ip_forward)
+*(.text.dev_queue_xmit)
+*(.text.netif_receive_skb)
+*(.text.ip_route_input)
+*(.text.ip_finish_output)
+*(.text.nf_iterate)
+*(.text.__hash_conntrack)
+*(.text.memset)
+*(.text.memcpy)
+*(.text.ip_rcv)
+*(.text.__nf_conntrack_find)
+*(.text.dev_hard_start_xmit)
+*(.text.vlan_dev_hard_start_xmit)
+*(.text.vlan_dev_hard_header)
+*(.text.__nf_ct_refresh_acct)
+*(.text.tcp_error)
+*(.text.pfifo_fast_enqueue)
+*(.text.ipv4_confirm)
+*(.text.ip_output)
+*(.text.neigh_connected_output)
+*(.text.nf_hook_slow)
+*(.text.nf_nat_packet)
+*(.text.local_bh_enable)
+*(.text.pfifo_fast_dequeue)
+*(.text.ubi32_eth_receive)
+*(.text.nf_nat_fn)
+*(.text.skb_checksum)
+*(.text.memmove)
+*(.text.ubi32_eth_tx_done)
+*(.text.eth_header)
+*(.text.skb_release_data)
+*(.text.nf_conntrack_find_get)
+*(.text.process_backlog)
+*(.text.vlan_skb_recv)
+*(.text.ip_rcv_finish)
+*(.text.__qdisc_run)
+*(.text.skb_push)
+*(.text.eth_type_trans)
+*(.text.__alloc_skb)
+*(.text.netif_rx)
+*(.text.nf_ip_checksum)
+*(.text.__skb_checksum_complete_head)
+*(.text.ipv4_conntrack_defrag)
+*(.text.tcp_pkt_to_tuple)
+*(.text.kfree)
+*(.text.tcp_manip_pkt)
+*(.text.skb_put)
+*(.text.nf_ct_get_tuple)
+*(.text.__kmalloc)
+*(.text.ubi32_eth_start_xmit)
+*(.text.free_block)
+*(.text.ipt_hook)
+*(.text.kmem_cache_free)
+*(.text.skb_pull_rcsum)
+*(.text.cache_alloc_refill)
+*(.text.skb_release_head_state)
+*(.text.manip_pkt)
+*(.text.ip_sabotage_in)
+*(.text.ip_forward_finish)
+*(.text.kmem_cache_alloc)
+*(.text.local_bh_disable)
+*(.text.ipv4_pkt_to_tuple)
+*(.text.inet_proto_csum_replace4)
+*(.text.__nf_ct_l4proto_find)
+*(.text.csum_partial)
+*(.text.neigh_resolve_output)
+*(.text.__kfree_skb)
+*(.text.kfree_skb)
+*(.text.__find_vlan_dev)
+*(.text.ldsr_ctxsw_thread)
+*(.text.__do_IRQ)
+*(.text.skb_pull)
+*(.text.ipv4_invert_tuple)
+*(.text.nf_ct_invert_tuplepr)
+*(.text.skb_make_writable)
+*(.text.ipv4_get_l4proto)
+*(.text.handle_IRQ_event)
+*(.text.net_rx_action)
+*(.text.__do_softirq)
+*(.text.nf_nat_in)
+*(.text.note_interrupt)
+*(.text.ipv4_conntrack_in)
+*(.text.dst_release)
+*(.text.tasklet_action)
+*(.text.nf_nat_out)
+*(.text.nf_ct_invert_tuple)
+*(.text.do_IRQ)
+*(.text.__tasklet_schedule)
+*(.text.__skb_checksum_complete)
+*(.text.ubi32_eth_interrupt)
+*(.text.dev_kfree_skb_any)
+*(.text.ret_from_interrupt_to_kernel)
+*(.text.preemptive_context_save)
+*(.text.irq_ack_vector)
+*(.text.update_wall_time)
+*(.text.ldsr_thread)
+*(.text.irq_exit)
+*(.text.ubi32_eth_do_tasklet)
+*(.text.__napi_schedule)
+*(.text.idle_cpu)
+*(.text.run_timer_softirq)
+*(.text.ldsr_mask_vector)
+*(.text.irq_enter)
+*(.text.ldsr_get_lsb)
+*(.text.ldsr_unmask_vector)
+*(.text.ip_fast_csum)
+*(.text.hrtimer_run_queues)
+*(.text.tcp_invert_tuple)
+*(.text.T___705)
+*(.text.run_posix_cpu_timers)
+*(.text.free_hot_cold_page)
+*(.text.lock_timer_base)
+*(.text.calc_delta_mine)
+*(.text.slab_destroy)
+*(.text.rcu_pending)
+*(.text.scheduler_tick)
+*(.text.hrtimer_run_pending)
+*(.text.do_softirq)
+*(.text.del_timer)
+*(.text.irq_end_vector)
+*(.text.pci_read_u32)
+*(.text.udivmodsi4)
+*(.text.memcmp)
+*(.text.memset)
+*(.text.__slab_alloc)
+*(.text.br_handle_frame)
+*(.text.br_fdb_update)
+*(.text.__br_fdb_get)
+*(.text.br_forward)
+*(.text.br_handle_frame_finish)
+*(.text.pci_write_u32)
+*(.text.kmem_freepages)
+*(.text.br_dev_queue_push_xmit)
+*(.text.ioread32)
+*(.text.next_zones_zonelist)
+*(.text.ubi32_pci_read_u32)
+*(.text.zone_watermark_ok)
+*(.text.__rmqueue_smallest)
+*(.text.ubi32_eth_napi_poll)
+*(.text.ubi32_pci_write_u32)
+*(.text.ubi32_pci_read_u32)
+*(.text._local_bh_enable)
+*(.text._local_bh_disable)
+*(.text.get_slab)
--- /dev/null
+++ b/arch/ubicom32/include/asm/page.h
@@ -0,0 +1,106 @@
+/*
+ * arch/ubicom32/include/asm/page.h
+ *   Memory page related operations and definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PAGE_H
+#define _ASM_UBICOM32_PAGE_H
+
+/* PAGE_SHIFT determines the page size */
+
+#define PAGE_SHIFT	12
+#define PAGE_SIZE	(1 << PAGE_SHIFT)
+#define PAGE_MASK	(~(PAGE_SIZE-1))
+
+#include <asm/setup.h>
+
+#ifndef __ASSEMBLY__
+
+#define get_user_page(vaddr)		__get_free_page(GFP_KERNEL)
+#define free_user_page(page, addr)	free_page(addr)
+
+#define clear_page(page)	memset((page), 0, PAGE_SIZE)
+#define copy_page(to,from)	memcpy((to), (from), PAGE_SIZE)
+
+#define clear_user_page(page, vaddr, pg)	clear_page(page)
+#define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
+
+#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
+	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
+#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
+
+/*
+ * These are used to make use of C type-checking..
+ */
+typedef struct { unsigned long pte; } pte_t;
+typedef struct { unsigned long pmd[16]; } pmd_t;
+typedef struct { unsigned long pgd; } pgd_t;
+typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
+
+#define pte_val(x)	((x).pte)
+#define pmd_val(x)	((&x)->pmd[0])
+#define pgd_val(x)	((x).pgd)
+#define pgprot_val(x)	((x).pgprot)
+
+#define __pte(x)	((pte_t) { (x) } )
+#define __pmd(x)	((pmd_t) { (x) } )
+#define __pgd(x)	((pgd_t) { (x) } )
+#define __pgprot(x)	((pgprot_t) { (x) } )
+
+extern unsigned long memory_start;
+extern unsigned long memory_end;
+
+#endif /* !__ASSEMBLY__ */
+
+#include <asm/page_offset.h>
+
+#define PAGE_OFFSET		(PAGE_OFFSET_RAW)
+
+#ifndef __ASSEMBLY__
+
+#define __pa(vaddr)		virt_to_phys((void *)(vaddr))
+#define __va(paddr)		phys_to_virt((unsigned long)(paddr))
+
+#define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
+#define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
+
+#define virt_to_page(addr)	(mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
+#define page_to_virt(page)	((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
+
+#define pfn_to_page(pfn)	virt_to_page(pfn_to_virt(pfn))
+#define page_to_pfn(page)	virt_to_pfn(page_to_virt(page))
+#define pfn_valid(pfn)	        ((pfn) < max_mapnr)
+
+#define	virt_addr_valid(kaddr)	(((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
+				((void *)(kaddr) < (void *)memory_end))
+
+#endif /* __ASSEMBLY__ */
+
+#ifdef __KERNEL__
+#include <asm-generic/page.h>
+#endif
+
+#endif /* _ASM_UBICOM32_PAGE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/page_offset.h
@@ -0,0 +1,35 @@
+/*
+ * arch/ubicom32/include/asm/page_offset.h
+ *   Definition of PAGE_OFFSET_RAW for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_PAGE_OFFSET_H
+#define _ASM_UBICOM32_PAGE_OFFSET_H
+
+/* This handles the memory map.. */
+#define	PAGE_OFFSET_RAW		0x3ffc0000
+
+#endif /* _ASM_UBICOM32_PAGE_OFFSET_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/param.h
@@ -0,0 +1,49 @@
+/*
+ * arch/ubicom32/include/asm/param.h
+ *   Definition of miscellaneous constants, including HZ.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PARAM_H
+#define _ASM_UBICOM32_PARAM_H
+
+#ifdef __KERNEL__
+#define HZ CONFIG_HZ
+#define	USER_HZ		HZ
+#define	CLOCKS_PER_SEC	(USER_HZ)
+#endif
+
+#ifndef HZ
+#define HZ	100
+#endif
+
+#define EXEC_PAGESIZE	4096
+
+#ifndef NOGROUP
+#define NOGROUP		(-1)
+#endif
+
+#define MAXHOSTNAMELEN	64	/* max length of hostname */
+
+#endif /* _ASM_UBICOM32_PARAM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/pci.h
@@ -0,0 +1,210 @@
+/*
+ * arch/ubicom32/include/asm/pci.h
+ *   Definitions of PCI operations for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PCI_H
+#define _ASM_UBICOM32_PCI_H
+
+#include <asm/io.h>
+
+/* The PCI address space does equal the physical memory
+ * address space.  The networking and block device layers use
+ * this boolean for bounce buffer decisions.
+ */
+#define PCI_DMA_BUS_IS_PHYS	(1)
+
+
+
+/*
+ * Perform a master read/write to the PCI bus.
+ * These functions return a PCI_RESP_xxx code.
+ */
+extern u8 pci_read_u32(u8 pci_cmd, u32 address, u32 *data);
+extern u8 pci_write_u32(u8 pci_cmd, u32 address, u32 data);
+extern u8 pci_read_u16(u8 pci_cmd, u32 address, u16 *data);
+extern u8 pci_write_u16(u8 pci_cmd, u32 address, u16 data);
+extern u8 pci_read_u8(u8 pci_cmd, u32 address, u8 *data);
+extern u8 pci_write_u8(u8 pci_cmd, u32 address, u8 data);
+
+
+#define PCIBIOS_MIN_IO          0x100
+#define PCIBIOS_MIN_MEM         0x10000000
+
+#define pcibios_assign_all_busses()	0
+#define pcibios_scan_all_fns(a, b)	0
+extern void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+	struct resource *res);
+
+extern void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+	struct pci_bus_region *region);
+
+struct pci_sys_data;
+struct pci_bus;
+
+struct hw_pci {
+        struct list_head buses;
+        int             nr_controllers;
+        int             (*setup)(int nr, struct pci_sys_data *);
+        struct pci_bus *(*scan)(int nr, struct pci_sys_data *);
+        void            (*preinit)(void);
+        void            (*postinit)(void);
+        u8              (*swizzle)(struct pci_dev *dev, u8 *pin);
+        int             (*map_irq)(struct pci_dev *dev, u8 slot, u8 pin);
+};
+
+/*
+ * Per-controller structure
+ */
+struct pci_sys_data {
+        struct list_head node;
+        int             busnr;          /* primary bus number                   */
+        u64             mem_offset;     /* bus->cpu memory mapping offset       */
+        unsigned long   io_offset;      /* bus->cpu IO mapping offset           */
+        struct pci_bus  *bus;           /* PCI bus                              */
+        struct resource *resource[3];   /* Primary PCI bus resources            */
+                                        /* Bridge swizzling                     */
+        u8              (*swizzle)(struct pci_dev *, u8 *);
+                                        /* IRQ mapping                          */
+        int             (*map_irq)(struct pci_dev *, u8, u8);
+        struct hw_pci   *hw;
+};
+
+static  inline struct resource *
+pcibios_select_root(struct pci_dev *pdev, struct resource *res)
+{
+        struct resource *root = NULL;
+
+        if (res->flags & IORESOURCE_IO)
+                root = &ioport_resource;
+        if (res->flags & IORESOURCE_MEM)
+                root = &iomem_resource;
+
+        return root;
+}
+
+static inline void pcibios_set_master(struct pci_dev *dev)
+{
+        /* No special bus mastering setup handling */
+}
+#define HAVE_ARCH_PCI_SET_DMA_MAX_SEGMENT_SIZE 1
+#define HAVE_ARCH_PCI_SET_DMA_SEGMENT_BOUNDARY 1
+
+#ifdef CONFIG_PCI
+static inline void * pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
+                     dma_addr_t *dma_handle)
+{
+    void *vaddr = kmalloc(size, GFP_KERNEL);
+    if(vaddr != NULL) {
+        *dma_handle = virt_to_phys(vaddr);
+    }
+    return vaddr;
+}
+
+static  inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+{
+ 	return 1;
+}
+
+static  inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
+	void *cpu_addr, dma_addr_t dma_handle)
+{ 
+	kfree(cpu_addr);
+	return;
+}
+
+static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
+	size_t size, int direction)
+{
+	 return virt_to_phys(ptr);
+}
+
+static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
+	size_t size, int direction)
+{
+	 return;
+}
+
+static inline dma_addr_t
+pci_map_page(struct pci_dev *hwdev, struct page *page,
+             unsigned long offset, size_t size, int direction)
+{
+	 return pci_map_single(hwdev, page_address(page) + offset, size, (int)direction);
+}
+
+static inline void
+pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
+               size_t size, int direction)
+{
+	pci_unmap_single(hwdev, dma_address, size, direction);
+}
+
+static inline int
+pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+           int nents, int direction)
+{
+        return nents; 
+}
+
+static inline void
+pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+             int nents, int direction)
+{
+}
+
+static inline void
+pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg,
+                int nelems, int direction)
+{
+}
+
+static inline void
+pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg,
+                int nelems, int direction)
+{
+}
+
+static inline void
+pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle,
+                    size_t size, int direction)
+{
+}
+
+static inline void
+pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle,
+                    size_t size, int direction)
+{
+}
+
+static inline int
+pci_dma_mapping_error(struct pci_dev *hwdev, dma_addr_t dma_addr)
+{
+        return dma_addr == 0;
+}
+extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
+#endif
+
+#endif /* _ASM_UBICOM32_PCI_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/percpu.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/percpu.h
+ *   Generic percpu.h for the Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PERCPU_H
+#define _ASM_UBICOM32_PERCPU_H
+
+#include <asm-generic/percpu.h>
+
+#endif /* _ASM_UBICOM32_PERCPU_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/pgalloc.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/pgalloc.h
+ *   Page table allocation definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PGALLOC_H
+#define _ASM_UBICOM32_PGALLOC_H
+
+#include <linux/mm.h>
+#include <asm/setup.h>
+
+#define check_pgt_cache()	do { } while (0)
+
+#endif /* _ASM_UBICOM32_PGALLOC_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/pgtable.h
@@ -0,0 +1,124 @@
+/*
+ * arch/ubicom32/include/asm/pgtable.h
+ *   Ubicom32 pseudo page table definitions and operations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004   Microtronix Datacom Ltd
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *   and various works, Alpha, ix86, M68K, Sparc, ...et al
+ */
+#ifndef _ASM_UBICOM32_PGTABLE_H
+#define _ASM_UBICOM32_PGTABLE_H
+
+#include <asm-generic/4level-fixup.h>
+
+//vic - this bit copied from m68knommu version
+#include <asm/setup.h>
+#include <asm/io.h>
+#include <linux/sched.h>
+
+typedef pte_t *pte_addr_t;
+
+#define pgd_present(pgd)     	(1)       /* pages are always present on NO_MM */
+#define pgd_none(pgd)		(0)
+#define pgd_bad(pgd)		(0)
+#define pgd_clear(pgdp)
+#define kern_addr_valid(addr) 	(1)
+#define	pmd_offset(a, b)	((void *)0)
+
+#define PAGE_NONE		__pgprot(0)    /* these mean nothing to NO_MM */
+#define PAGE_SHARED		__pgprot(0)    /* these mean nothing to NO_MM */
+#define PAGE_COPY		__pgprot(0)    /* these mean nothing to NO_MM */
+#define PAGE_READONLY		__pgprot(0)    /* these mean nothing to NO_MM */
+#define PAGE_KERNEL		__pgprot(0)    /* these mean nothing to NO_MM */
+//vic - this bit copied from m68knommu version
+
+extern void paging_init(void);
+#define swapper_pg_dir ((pgd_t *) 0)
+
+#define __swp_type(x)		(0)
+#define __swp_offset(x)		(0)
+#define __swp_entry(typ,off)	((swp_entry_t) { ((typ) | ((off) << 7)) })
+#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
+#define __swp_entry_to_pte(x)	((pte_t) { (x).val })
+
+/*
+ * pgprot_noncached() is only for infiniband pci support, and a real
+ * implementation for RAM would be more complicated.
+ */
+#define pgprot_noncached(prot)	(prot)
+
+static inline int pte_file(pte_t pte) { return 0; }
+
+/*
+ * ZERO_PAGE is a global shared page that is always zero: used
+ * for zero-mapped memory areas etc..
+ */
+#define ZERO_PAGE(vaddr)	(virt_to_page(0))
+
+extern unsigned int kobjsize(const void *objp);
+extern int is_in_rom(unsigned long);
+
+/*
+ * No page table caches to initialise
+ */
+#define pgtable_cache_init()   do { } while (0)
+
+#define io_remap_pfn_range(vma, vaddr, pfn, size, prot)		\
+		remap_pfn_range(vma, vaddr, pfn, size, prot)
+
+extern inline void flush_cache_mm(struct mm_struct *mm)
+{
+}
+
+extern inline void flush_cache_range(struct mm_struct *mm,
+				     unsigned long start,
+				     unsigned long end)
+{
+}
+
+/* Push the page at kernel virtual address and clear the icache */
+extern inline void flush_page_to_ram (unsigned long address)
+{
+}
+
+/* Push n pages at kernel virtual address and clear the icache */
+extern inline void flush_pages_to_ram (unsigned long address, int n)
+{
+}
+
+/*
+ * All 32bit addresses are effectively valid for vmalloc...
+ * Sort of meaningless for non-VM targets.
+ */
+#define	VMALLOC_START	0
+#define	VMALLOC_END	0xffffffff
+
+#define arch_enter_lazy_mmu_mode()	do {} while (0)
+#define arch_leave_lazy_mmu_mode()	do {} while (0)
+#define arch_flush_lazy_mmu_mode()	do {} while (0)
+#define arch_enter_lazy_cpu_mode()	do {} while (0)
+#define arch_leave_lazy_cpu_mode()	do {} while (0)
+#define arch_flush_lazy_cpu_mode()	do {} while (0)
+
+#endif /* _ASM_UBICOM32_PGTABLE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/poll.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/poll.h
+ *   Ubicom32 specific poll() related flags definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_POLL_H
+#define _ASM_UBICOM32_POLL_H
+
+#define POLLWRNORM	POLLOUT
+#define POLLWRBAND	0x0100
+
+#include <asm-generic/poll.h>
+
+#endif /* _ASM_UBICOM32_POLL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/posix_types.h
@@ -0,0 +1,93 @@
+/*
+ * arch/ubicom32/include/asm/posix_types.h
+ *   Ubicom32 architecture posix types.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004   Microtronix Datacom Ltd
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef __ARCH_UBICOM32_POSIX_TYPES_H
+#define __ARCH_UBICOM32_POSIX_TYPES_H
+
+/*
+ * This file is generally used by user-level software, so you need to
+ * be a little careful about namespace pollution etc.  Also, we cannot
+ * assume GCC is being used.
+ */
+
+typedef unsigned long	__kernel_ino_t;
+typedef unsigned short	__kernel_mode_t;
+typedef unsigned short	__kernel_nlink_t;
+typedef long		__kernel_off_t;
+typedef int		__kernel_pid_t;
+typedef unsigned short	__kernel_ipc_pid_t;
+typedef unsigned short	__kernel_uid_t;
+typedef unsigned short	__kernel_gid_t;
+typedef unsigned int	__kernel_size_t;
+typedef int		__kernel_ssize_t;
+typedef int		__kernel_ptrdiff_t;
+typedef long		__kernel_time_t;
+typedef long		__kernel_suseconds_t;
+typedef long		__kernel_clock_t;
+typedef int		__kernel_timer_t;
+typedef int		__kernel_clockid_t;
+typedef int		__kernel_daddr_t;
+typedef char *		__kernel_caddr_t;
+typedef unsigned short	__kernel_uid16_t;
+typedef unsigned short	__kernel_gid16_t;
+typedef unsigned int	__kernel_uid32_t;
+typedef unsigned int	__kernel_gid32_t;
+
+typedef unsigned short	__kernel_old_uid_t;
+typedef unsigned short	__kernel_old_gid_t;
+typedef unsigned short	__kernel_old_dev_t;
+
+#ifdef __GNUC__
+typedef long long	__kernel_loff_t;
+#endif
+
+typedef struct {
+#if defined(__KERNEL__) || defined(__USE_ALL)
+	int	val[2];
+#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
+	int	__val[2];
+#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
+} __kernel_fsid_t;
+
+#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+
+#undef	__FD_SET
+#define	__FD_SET(d, set)	((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
+
+#undef	__FD_CLR
+#define	__FD_CLR(d, set)	((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
+
+#undef	__FD_ISSET
+#define	__FD_ISSET(d, set)	((set)->fds_bits[__FDELT(d)] & __FDMASK(d))
+
+#undef	__FD_ZERO
+#define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
+
+#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+
+#endif
--- /dev/null
+++ b/arch/ubicom32/include/asm/processor.h
@@ -0,0 +1,163 @@
+/*
+ * arch/ubicom32/include/asm/processor.h
+ *   Thread related definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1995 Hamish Macdonald
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_PROCESSOR_H
+#define _ASM_UBICOM32_PROCESSOR_H
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr() ({ __label__ _l; _l: &&_l;})
+
+#include <linux/compiler.h>
+#include <linux/threads.h>
+#include <asm/types.h>
+#include <asm/segment.h>
+#include <asm/fpu.h>
+#include <asm/ptrace.h>
+#include <asm/current.h>
+#include <asm/thread_info.h>
+
+#if defined(CONFIG_UBICOM32_V3)
+	#define	CPU "IP5K"
+#endif
+#if defined(CONFIG_UBICOM32_V4)
+	#define	CPU "IP7K"
+#endif
+#ifndef CPU
+	#define	CPU "UNKNOWN"
+#endif
+
+/*
+ * User space process size: 1st byte beyond user address space.
+ */
+extern unsigned long memory_end;
+#define TASK_SIZE	(memory_end)
+
+/*
+ * This decides where the kernel will search for a free chunk of vm
+ * space during mmap's. We won't be using it
+ */
+#define TASK_UNMAPPED_BASE	0
+
+/*
+ * This is the structure where we are going to save callee-saved registers.
+ * A5 is the return address, A7 is the stack pointer, A6 is the frame
+ * pointer.  This is the frame that is created because of switch_to. This
+ * is not the frame due to interrupt preemption or because of syscall entry.
+ */
+
+struct thread_struct {
+	unsigned long  d10;		/* D10  */
+	unsigned long  d11;		/* D11  */
+	unsigned long  d12;		/* D12  */
+	unsigned long  d13;		/* D13  */
+	unsigned long  a1;		/* A1  */
+	unsigned long  a2;		/* A2  */
+	unsigned long  a5;		/* A5 return address. */
+	unsigned long  a6;		/* A6 */
+	unsigned long  sp;		/* A7 kernel stack pointer. */
+};
+
+#define INIT_THREAD  { \
+	0, 0, 0, 0, 0, 0, 0, 0, \
+	sizeof(init_stack) + (unsigned long) init_stack - 8, \
+}
+
+/*
+ * Do necessary setup to start up a newly executed thread.
+ *
+ * pass the data segment into user programs if it exists,
+ * it can't hurt anything as far as I can tell
+ */
+/*
+ * Do necessary setup to start up a newly executed thread.
+ */
+#define start_thread(regs, new_pc, new_sp)	 \
+	do {					 \
+		regs->pc = new_pc & ~3;		 \
+		regs->an[5] = new_pc & ~3;	 \
+		regs->an[7] = new_sp;		 \
+		regs->nesting_level = -1;	 \
+		regs->frame_type = UBICOM32_FRAME_TYPE_NEW_THREAD; \
+		regs->thread_type = NORMAL_THREAD; \
+	} while(0)
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+
+/* Free all resources held by a thread. */
+static inline void release_thread(struct task_struct *dead_task)
+{
+}
+
+/* Prepare to copy thread state - unlazy all lazy status */
+#define prepare_to_copy(tsk)	do { } while (0)
+
+extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
+
+/*
+ * Free current thread data structures etc..
+ */
+static inline void exit_thread(void)
+{
+}
+
+unsigned long thread_saved_pc(struct task_struct *tsk);
+unsigned long get_wchan(struct task_struct *p);
+
+#define	KSTK_EIP(tsk)	(tsk->thread.a5)
+#define	KSTK_ESP(tsk)	(tsk->thread.sp)
+
+#define cpu_relax()    barrier()
+
+extern void processor_init(void);
+extern unsigned int processor_timers(void);
+extern unsigned int processor_threads(void);
+extern unsigned int processor_frequency(void);
+extern int processor_interrupts(unsigned int *int0, unsigned int *int1);
+extern int processor_ocm(void **socm, void **eocm);
+extern int processor_dram(void **sdram, void **edram);
+
+#define THREAD_SIZE_LONGS      (THREAD_SIZE/sizeof(unsigned long))
+#define KSTK_TOP(info)                                                 \
+({                                                                     \
+       unsigned long *__ptr = (unsigned long *)(info);                 \
+       (unsigned long)(&__ptr[THREAD_SIZE_LONGS]);                     \
+})
+
+#define task_pt_regs(task)                                             \
+({                                                                     \
+       struct pt_regs *__regs__;                                       \
+       __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
+       __regs__ - 1;                                                   \
+})
+
+#endif	/* _ASM_UBICOM32_PROCESSOR_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ptrace.h
@@ -0,0 +1,177 @@
+/*
+ * arch/ubicom32/include/asm/ptrace.h
+ *   Ubicom32 architecture ptrace support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_PTRACE_H
+#define _ASM_UBICOM32_PTRACE_H
+
+#ifndef __ASSEMBLY__
+
+/*
+ * We use hard coded constants because this is shared with user
+ * space and the values are NOT allowed to change.  Only fields
+ * that are intended to be exposed get values.
+ */
+#define PT_D0           0
+#define PT_D1           4
+#define PT_D2           8
+#define PT_D3           12
+#define PT_D4           16
+#define PT_D5           20
+#define PT_D6           24
+#define PT_D7           28
+#define PT_D8           32
+#define PT_D9           36
+#define PT_D10          40
+#define PT_D11          44
+#define PT_D12          48
+#define PT_D13          52
+#define PT_D14          56
+#define PT_D15          60
+#define PT_A0           64
+#define PT_A1           68
+#define PT_A2           72
+#define PT_A3           76
+#define PT_A4           80
+#define PT_A5           84
+#define PT_A6           88
+#define PT_A7           92
+#define PT_SP           92
+#define PT_ACC0HI       96
+#define PT_ACC0LO       100
+#define PT_MAC_RC16     104
+#define PT_ACC1HI       108
+#define PT_ACC1LO       112
+#define PT_SOURCE3      116
+#define PT_INST_CNT     120
+#define PT_CSR          124
+#define PT_DUMMY_UNUSED 128
+#define PT_INT_MASK0    132
+#define PT_INT_MASK1    136
+#define PT_TRAP_CAUSE   140
+#define PT_PC           144
+#define PT_ORIGINAL_D0  148
+#define PT_FRAME_TYPE   152
+
+/*
+ * The following 'registers' are not registers at all but are used
+ * locate the relocated sections.
+ */
+#define PT_TEXT_ADDR		200
+#define PT_TEXT_END_ADDR	204
+#define PT_DATA_ADDR		208
+#define PT_EXEC_FDPIC_LOADMAP	212
+#define PT_INTERP_FDPIC_LOADMAP	216
+
+/*
+ * This struct defines the way the registers are stored on the
+ * stack during a system call.
+ */
+enum thread_type {
+	NORMAL_THREAD,
+	KERNEL_THREAD,
+};
+
+#define UBICOM32_FRAME_TYPE_SYSCALL	-1 /* System call frame */
+#define UBICOM32_FRAME_TYPE_INVALID	0 /* Invalid frame, no longer in use */
+#define UBICOM32_FRAME_TYPE_INTERRUPT	1 /* Interrupt frame */
+#define UBICOM32_FRAME_TYPE_TRAP	2 /* Trap frame */
+#define UBICOM32_FRAME_TYPE_SIGTRAMP	3 /* Signal trampoline frame. */
+#define UBICOM32_FRAME_TYPE_NEW_THREAD	4 /* New Thread. */
+
+struct pt_regs {
+	/*
+	 * Data Registers
+	 */
+	unsigned long dn[16];
+
+	/*
+	 * Address Registers
+	 */
+	unsigned long an[8];
+
+	/*
+	 * Per thread misc registers.
+	 */
+	unsigned long acc0[2];
+	unsigned long mac_rc16;
+	unsigned long acc1[2];
+	unsigned long source3;
+	unsigned long inst_cnt;
+	unsigned long csr;
+	unsigned long dummy_unused;
+	unsigned long int_mask0;
+	unsigned long int_mask1;
+	unsigned long trap_cause;
+	unsigned long pc;
+	unsigned long original_dn_0;
+
+	/*
+	 * Frame type. Syscall frames are -1. For other types look above.
+	 */
+	unsigned long frame_type;
+
+	/*
+	 * These fields are not exposed to ptrace.
+	 */
+	unsigned long previous_pc;
+	long nesting_level;		/* When the kernel in in user space this
+					 * will be -1. */
+	unsigned long thread_type;	/* This indicates if this is a kernel
+					 * thread. */
+};
+
+/*
+ * This is the extended stack used by signal handlers and the context
+ * switcher: it's pushed after the normal "struct pt_regs".
+ */
+struct switch_stack {
+	unsigned long  dummy;
+};
+
+#ifdef __KERNEL__
+
+/* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */
+#define PTRACE_GETREGS		12
+#define PTRACE_SETREGS		13
+
+#ifndef PS_S
+#define PS_S  (0x2000)
+#define PS_M  (0x1000)
+#endif
+
+extern  int __user_mode(unsigned long sp);
+
+#define user_mode(regs) (__user_mode((regs->an[7])))
+#define user_stack(regs) ((regs)->an[7])
+#define instruction_pointer(regs) ((regs)->pc)
+#define profile_pc(regs) instruction_pointer(regs)
+extern void show_regs(struct pt_regs *);
+#endif /* __KERNEL__ */
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_UBICOM32_PTRACE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/range-protect-asm.h
@@ -0,0 +1,91 @@
+/*
+ * arch/ubicom32/include/asm/range-protect-asm.h
+ *   Assembly macros for enabling memory protection.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_RANGE_PROTECT_ASM_H
+#define _ASM_UBICOM32_RANGE_PROTECT_ASM_H
+
+#if defined(__ASSEMBLY__)
+
+#include <asm/thread-asm.h>
+
+/*
+ * You should only use the enable/disable ranges when you have the atomic lock,
+ * if you do not there will be problems.
+ */
+
+/*
+ * enable_kernel_ranges
+ *	Enable the kernel ranges (disabling protection) for thread,
+ *	where thread == (1 << thread number)
+ */
+.macro	enable_kernel_ranges thread
+#ifdef CONFIG_PROTECT_KERNEL
+	or.4	I_RANGE0_EN, I_RANGE0_EN, \thread	 /* Enable Range Register */
+	or.4	D_RANGE0_EN, D_RANGE0_EN, \thread
+	or.4	D_RANGE1_EN, D_RANGE1_EN, \thread
+#endif
+.endm
+
+/*
+ * enable_kernel_ranges_for_current
+ *	Enable the kernel ranges (disabling protection) for this thread
+ */
+.macro	enable_kernel_ranges_for_current scratch_reg
+#ifdef CONFIG_PROTECT_KERNEL
+	thread_get_self_mask \scratch_reg
+	enable_kernel_ranges \scratch_reg
+#endif
+.endm
+
+/*
+ * disable_kernel_ranges
+ *	Disables the kernel ranges (enabling protection) for thread
+ *	where thread == (1 << thread number)
+ */
+.macro	disable_kernel_ranges thread
+#ifdef CONFIG_PROTECT_KERNEL
+	not.4	\thread, \thread
+	and.4	I_RANGE0_EN, I_RANGE0_EN, \thread	 /* Disable Range Register */
+	and.4	D_RANGE0_EN, D_RANGE0_EN, \thread
+	and.4	D_RANGE1_EN, D_RANGE1_EN, \thread
+#endif
+.endm
+
+/*
+ * disable_kernel_ranges_for_current
+ *	Disable kernel ranges (enabling protection) for this thread
+ */
+.macro	disable_kernel_ranges_for_current scratch_reg
+#ifdef CONFIG_PROTECT_KERNEL
+	thread_get_self_mask \scratch_reg
+	disable_kernel_ranges \scratch_reg
+#endif
+.endm
+#endif
+
+#endif  /* _ASM_UBICOM32_RANGE_PROTECT_ASM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/range-protect.h
@@ -0,0 +1,62 @@
+/*
+ * arch/ubicom32/include/asm/range-protect.h
+ *   Assembly macros declared in C for enabling memory protection.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_RANGE_PROTECT_H
+#define _ASM_UBICOM32_RANGE_PROTECT_H
+
+#if !defined(__ASSEMBLY__)
+#include <asm/thread.h>
+/*
+ * The following macros should be the identical to the ones in
+ * range-protect-asm.h
+ *
+ * You should only use the enable/disable ranges when you have the atomic lock,
+ * if you do not there will be problems.
+ */
+
+/*
+ * enable_kernel_ranges
+ *	Enable the kernel ranges (disabling protection) for thread,
+ *	where thread == (1 << thread number)
+ */
+asm (
+	".macro	enable_kernel_ranges thread			\n\t"
+#ifdef CONFIG_PROTECT_KERNEL
+	"	or.4	I_RANGE0_EN, I_RANGE0_EN, \\thread	\n\t" /* Enable Range Register */
+	"	or.4	D_RANGE0_EN, D_RANGE0_EN, \\thread	\n\t"
+	"	or.4	D_RANGE1_EN, D_RANGE1_EN, \\thread	\n\t"
+#endif
+	".endm							\n\t"
+);
+
+#else /* __ASSEMBLY__ */
+
+#include <asm/range-protect-asm.h>
+
+#endif
+#endif  /* _ASM_UBICOM32_RANGE_PROTECT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/resource.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/resource.h
+ *   Generic definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_RESOURCE_H
+#define _ASM_UBICOM32_RESOURCE_H
+
+#include <asm-generic/resource.h>
+
+#endif /* _ASM_UBICOM32_RESOURCE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ring_tio.h
@@ -0,0 +1,42 @@
+/*
+ * arch/ubicom32/include/asm/ring_tio.h
+ *   Ubicom32 architecture Ring TIO definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_RING_TIO_H
+#define _ASM_UBICOM32_RING_TIO_H
+
+#include <asm/devtree.h>
+
+#define RING_TIO_NODE_VERSION	2
+
+/*
+ * Devtree node for ring
+ */
+struct ring_tio_node {
+	struct devtree_node	dn;
+
+	u32_t			version;
+	void			*regs;
+};
+
+extern void ring_tio_init(const char *node_name);
+
+#endif /* _ASM_UBICOM32_RING_TIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/scatterlist.h
@@ -0,0 +1,49 @@
+/*
+ * arch/ubicom32/include/asm/scatterlist.h
+ *   Definitions of struct scatterlist for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SCATTERLIST_H
+#define _ASM_UBICOM32_SCATTERLIST_H
+
+#include <linux/mm.h>
+#include <asm/types.h>
+
+struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+	unsigned long	sg_magic;
+#endif
+	unsigned long	page_link;
+	unsigned int	offset;
+	dma_addr_t	dma_address;
+	unsigned int	length;
+};
+
+#define sg_dma_address(sg)      ((sg)->dma_address)
+#define sg_dma_len(sg)          ((sg)->length)
+
+#define ISA_DMA_THRESHOLD	(0xffffffff)
+
+#endif /* _ASM_UBICOM32_SCATTERLIST_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/sd_tio.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/sd_tio.h
+ *   SD TIO definitions
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_SD_TIO_H
+#define _ASM_UBICOM32_SD_TIO_H
+
+#include <asm/devtree.h>
+
+/*
+ * Devtree node for SD
+ */
+struct sd_tio_node {
+	struct devtree_node	dn;
+	void			*regs;
+};
+
+#endif /* _ASM_UBICOM32_SD_TIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/sections.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/sections.h
+ *   Generic sections.h definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SECTIONS_H
+#define _ASM_UBICOM32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_UBICOM32_SECTIONS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/segment.h
@@ -0,0 +1,78 @@
+/*
+ * arch/ubicom32/include/asm/segment.h
+ *   Memory segment definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SEGMENT_H
+#define _ASM_UBICOM32_SEGMENT_H
+
+/* define constants */
+/* Address spaces (FC0-FC2) */
+#define USER_DATA     (1)
+#ifndef __USER_DS
+#define __USER_DS     (USER_DATA)
+#endif
+#define USER_PROGRAM  (2)
+#define SUPER_DATA    (5)
+#ifndef __KERNEL_DS
+#define __KERNEL_DS   (SUPER_DATA)
+#endif
+#define SUPER_PROGRAM (6)
+#define CPU_SPACE     (7)
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+	unsigned long seg;
+} mm_segment_t;
+
+#define MAKE_MM_SEG(s)	((mm_segment_t) { (s) })
+#define USER_DS		MAKE_MM_SEG(__USER_DS)
+#define KERNEL_DS	MAKE_MM_SEG(__KERNEL_DS)
+
+/*
+ * Get/set the SFC/DFC registers for MOVES instructions
+ */
+
+static inline mm_segment_t get_fs(void)
+{
+    return USER_DS;
+}
+
+static inline mm_segment_t get_ds(void)
+{
+    /* return the supervisor data space code */
+    return KERNEL_DS;
+}
+
+static inline void set_fs(mm_segment_t val)
+{
+}
+
+#define segment_eq(a,b)	((a).seg == (b).seg)
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_UBICOM32_SEGMENT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/semaphore.h
@@ -0,0 +1,140 @@
+/*
+ * arch/ubicom32/include/asm/semaphore.h
+ *   Interrupt-safe semaphores for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * (C) Copyright 1996 Linus Torvalds
+ * m68k version by Andreas Schwab
+ * Copyright (C) 2004   Microtronix Datacom Ltd
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SEMAPHORE_H
+#define _ASM_UBICOM32_SEMAPHORE_H
+
+#define RW_LOCK_BIAS		 0x01000000
+
+#ifndef __ASSEMBLY__
+
+#include <linux/linkage.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <linux/rwsem.h>
+
+#include <asm/system.h>
+#include <asm/atomic.h>
+
+struct semaphore {
+	atomic_t count;
+	atomic_t waking;
+	wait_queue_head_t wait;
+};
+
+#define __SEMAPHORE_INITIALIZER(name, n)				\
+{									\
+	.count		= ATOMIC_INIT(n),				\
+	.waking		= ATOMIC_INIT(0),				\
+	.wait		= __WAIT_QUEUE_HEAD_INITIALIZER((name).wait)	\
+}
+
+#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
+	struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
+
+#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
+#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
+
+static inline void sema_init (struct semaphore *sem, int val)
+{
+	*sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
+}
+
+static inline void init_MUTEX (struct semaphore *sem)
+{
+	sema_init(sem, 1);
+}
+
+static inline void init_MUTEX_LOCKED (struct semaphore *sem)
+{
+	sema_init(sem, 0);
+}
+
+asmlinkage void __down_failed(void /* special register calling convention */);
+asmlinkage int  __down_failed_interruptible(void  /* params in registers */);
+asmlinkage int  __down_failed_trylock(void  /* params in registers */);
+asmlinkage void __up_wakeup(void /* special register calling convention */);
+
+asmlinkage void __down(struct semaphore * sem);
+asmlinkage int  __down_interruptible(struct semaphore * sem);
+asmlinkage int  __down_trylock(struct semaphore * sem);
+asmlinkage void __up(struct semaphore * sem);
+
+extern spinlock_t semaphore_wake_lock;
+
+/*
+ * This is ugly, but we want the default case to fall through.
+ * "down_failed" is a special asm handler that calls the C
+ * routine that actually waits.
+ */
+static inline void down(struct semaphore * sem)
+{
+	might_sleep();
+
+	if (atomic_dec_return(&sem->count) < 0)
+		__down(sem);
+}
+
+static inline int down_interruptible(struct semaphore * sem)
+{
+	int ret = 0;
+
+
+	might_sleep();
+
+	if(atomic_dec_return(&sem->count) < 0)
+		ret = __down_interruptible(sem);
+	return ret;
+}
+
+static inline int down_trylock(struct semaphore * sem)
+{
+	int ret = 0;
+
+	if (atomic_dec_return (&sem->count) < 0)
+		ret = __down_trylock(sem);
+	return ret;
+}
+
+/*
+ * Note! This is subtle. We jump to wake people up only if
+ * the semaphore was negative (== somebody was waiting on it).
+ * The default case (no contention) will result in NO
+ * jumps for both down() and up().
+ */
+static inline void up(struct semaphore * sem)
+{
+	if (atomic_inc_return(&sem->count) <= 0)
+		__up(sem);
+}
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_UBICOM32_SEMAPHORE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/semaphore-helper.h
@@ -0,0 +1,109 @@
+/*
+ * arch/ubicom32/include/asm/semaphore-helper.h
+ *   Semaphore related definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SEMAPHORE_HELPER_H
+#define _ASM_UBICOM32_SEMAPHORE_HELPER_H
+
+/*
+ * SMP- and interrupt-safe semaphores helper functions.
+ *
+ * (C) Copyright 1996 Linus Torvalds
+ *
+ * m68k version by Andreas Schwab
+ */
+
+
+/*
+ * These two _must_ execute atomically wrt each other.
+ */
+static inline void wake_one_more(struct semaphore * sem)
+{
+	atomic_inc(&sem->waking);
+}
+
+static inline int waking_non_zero(struct semaphore *sem)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&semaphore_wake_lock, flags);
+	ret = 0;
+	if (atomic_read(&sem->waking) > 0) {
+		atomic_dec(&sem->waking);
+		ret = 1;
+	}
+	spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+	return ret;
+}
+
+/*
+ * waking_non_zero_interruptible:
+ *	1	got the lock
+ *	0	go to sleep
+ *	-EINTR	interrupted
+ */
+static inline int waking_non_zero_interruptible(struct semaphore *sem,
+						struct task_struct *tsk)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&semaphore_wake_lock, flags);
+	ret = 0;
+	if (atomic_read(&sem->waking) > 0) {
+		atomic_dec(&sem->waking);
+		ret = 1;
+	} else if (signal_pending(tsk)) {
+		atomic_inc(&sem->count);
+		ret = -EINTR;
+	}
+	spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+	return ret;
+}
+
+/*
+ * waking_non_zero_trylock:
+ *	1	failed to lock
+ *	0	got the lock
+ */
+static inline int waking_non_zero_trylock(struct semaphore *sem)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&semaphore_wake_lock, flags);
+	ret = 1;
+	if (atomic_read(&sem->waking) > 0) {
+		atomic_dec(&sem->waking);
+		ret = 0;
+	} else
+		atomic_inc(&sem->count);
+	spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+	return ret;
+}
+
+#endif /* _ASM_UBICOM32_SEMAPHORE_HELPER_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/sembuf.h
@@ -0,0 +1,52 @@
+/*
+ * arch/ubicom32/include/asm/sembuf.h
+ *   The semid64_ds structure for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SEMBUF_H
+#define _ASM_UBICOM32_SEMBUF_H
+
+/*
+ * The semid64_ds structure for ubicom32 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct semid64_ds {
+	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
+	__kernel_time_t	sem_otime;		/* last semop time */
+	unsigned long	__unused1;
+	__kernel_time_t	sem_ctime;		/* last change time */
+	unsigned long	__unused2;
+	unsigned long	sem_nsems;		/* no. of semaphores in array */
+	unsigned long	__unused3;
+	unsigned long	__unused4;
+};
+
+#endif /* _ASM_UBICOM32_SEMBUF_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/setup.h
@@ -0,0 +1,35 @@
+/*
+ * arch/ubicom32/include/asm/setup.h
+ *   Kernel command line length definition.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004, Microtronix Datacom Ltd., All rights reserved.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_SETUP_H
+#define _ASM_UBICOM32_SETUP_H
+
+#define COMMAND_LINE_SIZE 512
+
+#endif /* _ASM_UBICOM32_SETUP_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/shmbuf.h
@@ -0,0 +1,69 @@
+/*
+ * arch/ubicom32/include/asm/shmbuf.h
+ *   The shmid64_ds structure for the Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SHMBUF_H
+#define _ASM_UBICOM32_SHMBUF_H
+
+/*
+ * The shmid64_ds structure for m68k architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+	struct ipc64_perm	shm_perm;	/* operation perms */
+	size_t			shm_segsz;	/* size of segment (bytes) */
+	__kernel_time_t		shm_atime;	/* last attach time */
+	unsigned long		__unused1;
+	__kernel_time_t		shm_dtime;	/* last detach time */
+	unsigned long		__unused2;
+	__kernel_time_t		shm_ctime;	/* last change time */
+	unsigned long		__unused3;
+	__kernel_pid_t		shm_cpid;	/* pid of creator */
+	__kernel_pid_t		shm_lpid;	/* pid of last operator */
+	unsigned long		shm_nattch;	/* no. of current attaches */
+	unsigned long		__unused4;
+	unsigned long		__unused5;
+};
+
+struct shminfo64 {
+	unsigned long	shmmax;
+	unsigned long	shmmin;
+	unsigned long	shmmni;
+	unsigned long	shmseg;
+	unsigned long	shmall;
+	unsigned long	__unused1;
+	unsigned long	__unused2;
+	unsigned long	__unused3;
+	unsigned long	__unused4;
+};
+
+#endif /* _ASM_UBICOM32_SHMBUF_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/shmparam.h
@@ -0,0 +1,35 @@
+/*
+ * arch/ubicom32/include/asm/shmparam.h
+ *   Shared memory definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2004   Microtronix Datacom Ltd
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *   Alpha, ix86, M68K, Sparc, ...et al
+ */
+#ifndef _ASM_UBICOM32_SHMPARAM_H
+#define _ASM_UBICOM32_SHMPARAM_H
+
+#define	SHMLBA		PAGE_SIZE	/* attach addr a multiple of this */
+
+#endif /* _ASM_UBICOM32_SHMPARAM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/sigcontext.h
@@ -0,0 +1,37 @@
+/*
+ * arch/ubicom32/include/asm/sigcontext.h
+ *   Definition of sigcontext struct for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SIGCONTEXT_H
+#define _ASM_UBICOM32_SIGCONTEXT_H
+
+#include <asm/ptrace.h>
+
+struct sigcontext {
+	struct pt_regs sc_regs;
+};
+
+#endif /* _ASM_UBICOM32_SIGCONTEXT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/siginfo.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/siginfo.h
+ *   Generic siginfo.h definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SIGINFO_H
+#define _ASM_UBICOM32_SIGINFO_H
+
+#include <asm-generic/siginfo.h>
+
+#endif /* _ASM_UBICOM32_SIGINFO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/signal.h
@@ -0,0 +1,180 @@
+/*
+ * arch/ubicom32/include/asm/signal.h
+ *   Signal related definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SIGNAL_H
+#define _ASM_UBICOM32_SIGNAL_H
+
+#include <linux/types.h>
+
+/* Avoid too many header ordering problems.  */
+struct siginfo;
+
+#ifdef __KERNEL__
+/* Most things should be clean enough to redefine this at will, if care
+   is taken to make libc match.  */
+
+#define _NSIG		64
+#define _NSIG_BPW	32
+#define _NSIG_WORDS	(_NSIG / _NSIG_BPW)
+
+typedef unsigned long old_sigset_t;		/* at least 32 bits */
+
+typedef struct {
+	unsigned long sig[_NSIG_WORDS];
+} sigset_t;
+
+#endif /* __KERNEL__ */
+
+#define SIGHUP		 1
+#define SIGINT		 2
+#define SIGQUIT		 3
+#define SIGILL		 4
+#define SIGTRAP		 5
+#define SIGABRT		 6
+#define SIGIOT		 6
+#define SIGBUS		 7
+#define SIGFPE		 8
+#define SIGKILL		 9
+#define SIGUSR1		10
+#define SIGSEGV		11
+#define SIGUSR2		12
+#define SIGPIPE		13
+#define SIGALRM		14
+#define SIGTERM		15
+#define SIGSTKFLT	16
+#define SIGCHLD		17
+#define SIGCONT		18
+#define SIGSTOP		19
+#define SIGTSTP		20
+#define SIGTTIN		21
+#define SIGTTOU		22
+#define SIGURG		23
+#define SIGXCPU		24
+#define SIGXFSZ		25
+#define SIGVTALRM	26
+#define SIGPROF		27
+#define SIGWINCH	28
+#define SIGIO		29
+#define SIGPOLL		SIGIO
+/*
+#define SIGLOST		29
+*/
+#define SIGPWR		30
+#define SIGSYS		31
+#define	SIGUNUSED	31
+
+/* These should not be considered constants from userland.  */
+#define SIGRTMIN	32
+#define SIGRTMAX	_NSIG
+
+/*
+ * SA_FLAGS values:
+ *
+ * SA_ONSTACK indicates that a registered stack_t will be used.
+ * SA_RESTART flag to get restarting signals (which were the default long ago)
+ * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
+ * SA_RESETHAND clears the handler when the signal is delivered.
+ * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
+ * SA_NODEFER prevents the current signal from being masked in the handler.
+ *
+ * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
+ * Unix names RESETHAND and NODEFER respectively.
+ */
+#define SA_NOCLDSTOP	0x00000001
+#define SA_NOCLDWAIT	0x00000002
+#define SA_SIGINFO	0x00000004
+#define SA_ONSTACK	0x08000000
+#define SA_RESTART	0x10000000
+#define SA_NODEFER	0x40000000
+#define SA_RESETHAND	0x80000000
+
+#define SA_NOMASK	SA_NODEFER
+#define SA_ONESHOT	SA_RESETHAND
+
+/* 
+ * sigaltstack controls
+ */
+#define SS_ONSTACK	1
+#define SS_DISABLE	2
+
+#define MINSIGSTKSZ	2048
+#define SIGSTKSZ	8192
+
+#include <asm-generic/signal.h>
+
+#ifdef __KERNEL__
+struct old_sigaction {
+	__sighandler_t sa_handler;
+	old_sigset_t sa_mask;
+	unsigned long sa_flags;
+	void (*sa_restorer)(void);
+};
+
+struct sigaction {
+	__sighandler_t sa_handler;
+	unsigned long sa_flags;
+	void (*sa_restorer)(void);
+	sigset_t sa_mask;		/* mask last for extensibility */
+};
+
+struct k_sigaction {
+	struct sigaction sa;
+};
+#else
+/* Here we must cater to libcs that poke about in kernel headers.  */
+
+struct sigaction {
+	union {
+	  __sighandler_t _sa_handler;
+	  void (*_sa_sigaction)(int, struct siginfo *, void *);
+	} _u;
+	sigset_t sa_mask;
+	unsigned long sa_flags;
+	void (*sa_restorer)(void);
+};
+
+#define sa_handler	_u._sa_handler
+#define sa_sigaction	_u._sa_sigaction
+
+#endif /* __KERNEL__ */
+
+typedef struct sigaltstack {
+	void *ss_sp;
+	int ss_flags;
+	size_t ss_size;
+} stack_t;
+
+#ifdef __KERNEL__
+
+#include <asm/sigcontext.h>
+#undef __HAVE_ARCH_SIG_BITOPS
+
+#define ptrace_signal_deliver(regs, cookie) do { } while (0)
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_SIGNAL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/smp.h
@@ -0,0 +1,83 @@
+/*
+ * arch/ubicom32/include/asm/smp.h
+ *   SMP definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SMP_H
+#define _ASM_UBICOM32_SMP_H
+
+#ifndef ASSEMBLY
+#include <linux/bitops.h>
+#include <linux/threads.h>
+#include <linux/cpumask.h>
+#include <asm/ip5000.h>
+
+typedef unsigned long address_t;
+extern cpumask_t cpu_online_map;
+extern unsigned int smp_ipi_irq;
+
+/*
+ * This magic constant controls our willingness to transfer
+ * a process across CPUs.
+ *
+ * Such a transfer incurs cache and tlb
+ * misses. The current value is inherited from i386. Still needs
+ * to be tuned for parisc.
+ */
+#define PROC_CHANGE_PENALTY	15		/* Schedule penalty */
+#define NO_PROC_ID		0xFF		/* No processor magic marker */
+#define ANY_PROC_ID		0xFF		/* Any processor magic marker */
+
+#ifdef CONFIG_SMP
+#define raw_smp_processor_id()	(current_thread_info()->cpu)
+#endif /* CONFIG_SMP */
+
+static inline int __cpu_disable (void)
+{
+  return 0;
+}
+
+static inline void __cpu_die (unsigned int cpu)
+{
+	while(1) {
+	};
+}
+
+extern int __cpu_up(unsigned int cpu);
+extern void smp_send_timer_all(void);
+extern void smp_timer_broadcast(cpumask_t mask);
+extern void smp_set_affinity(unsigned int irq, cpumask_t dest);
+extern void arch_send_call_function_single_ipi(int cpu);
+extern void arch_send_call_function_ipi(cpumask_t mask);
+
+/*
+ * TODO: Once these are fully tested, we should turn them into
+ * inline macros for performance.
+ */
+extern unsigned long smp_get_affinity(unsigned int irq, int *all);
+extern void smp_reset_ipi(unsigned long mask);
+
+#endif /* !ASSEMBLY */
+#endif /*  _ASM_UBICOM32_SMP_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/socket.h
@@ -0,0 +1,84 @@
+/*
+ * arch/ubicom32/include/asm/socket.h
+ *   Socket options definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SOCKET_H
+#define _ASM_UBICOM32_SOCKET_H
+
+#include <asm/sockios.h>
+
+/* For setsockopt(2) */
+#define SOL_SOCKET	1
+
+#define SO_DEBUG	1
+#define SO_REUSEADDR	2
+#define SO_TYPE		3
+#define SO_ERROR	4
+#define SO_DONTROUTE	5
+#define SO_BROADCAST	6
+#define SO_SNDBUF	7
+#define SO_RCVBUF	8
+#define SO_SNDBUFFORCE	32
+#define SO_RCVBUFFORCE	33
+#define SO_KEEPALIVE	9
+#define SO_OOBINLINE	10
+#define SO_NO_CHECK	11
+#define SO_PRIORITY	12
+#define SO_LINGER	13
+#define SO_BSDCOMPAT	14
+/* To add :#define SO_REUSEPORT 15 */
+#define SO_PASSCRED	16
+#define SO_PEERCRED	17
+#define SO_RCVLOWAT	18
+#define SO_SNDLOWAT	19
+#define SO_RCVTIMEO	20
+#define SO_SNDTIMEO	21
+
+/* Security levels - as per NRL IPv6 - don't actually do anything */
+#define SO_SECURITY_AUTHENTICATION		22
+#define SO_SECURITY_ENCRYPTION_TRANSPORT	23
+#define SO_SECURITY_ENCRYPTION_NETWORK		24
+
+#define SO_BINDTODEVICE	25
+
+/* Socket filtering */
+#define SO_ATTACH_FILTER        26
+#define SO_DETACH_FILTER        27
+
+#define SO_PEERNAME             28
+#define SO_TIMESTAMP		29
+#define SCM_TIMESTAMP		SO_TIMESTAMP
+
+#define SO_ACCEPTCONN		30
+
+#define SO_PEERSEC              31
+#define SO_PASSSEC		34
+#define SO_TIMESTAMPNS		35
+#define SCM_TIMESTAMPNS		SO_TIMESTAMPNS
+
+#define SO_MARK			36
+
+#endif /* _ASM_UBICOM32_SOCKET_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/sockios.h
@@ -0,0 +1,40 @@
+/*
+ * arch/ubicom32/include/asm/sockios.h
+ *   Socket-level ioctl definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SOCKIOS_H
+#define _ASM_UBICOM32_SOCKIOS_H
+
+/* Socket-level I/O control calls. */
+#define FIOSETOWN	0x8901
+#define SIOCSPGRP	0x8902
+#define FIOGETOWN	0x8903
+#define SIOCGPGRP	0x8904
+#define SIOCATMARK	0x8905
+#define SIOCGSTAMP	0x8906		/* Get stamp (timeval) */
+#define SIOCGSTAMPNS	0x8907		/* Get stamp (timespec) */
+
+#endif /* _ASM_UBICOM32_SOCKIOS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/spinlock.h
@@ -0,0 +1,293 @@
+/*
+ * arch/ubicom32/include/asm/spinlock.h
+ *   Spinlock related definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SPINLOCK_H
+#define _ASM_UBICOM32_SPINLOCK_H
+
+#include <asm/system.h>
+#include <asm/processor.h>
+#include <asm/spinlock_types.h>
+
+/*
+ * __raw_spin_lock()
+ *	Lock the lock.
+ */
+static inline void __raw_spin_lock(raw_spinlock_t *x)
+{
+	asm volatile (
+	"1:	bset	%0, %0, #0	\n\t"
+	"	jmpne.f	1b		\n\t"
+		: "+U4" (x->lock)
+		:
+		: "memory", "cc"
+	);
+}
+
+/*
+ * __raw_spin_unlock()
+ *	Unlock the lock.
+ */
+static inline void __raw_spin_unlock(raw_spinlock_t *x)
+{
+	asm volatile (
+	"	bclr	%0, %0, #0	\n\t"
+		: "+U4" (x->lock)
+		:
+		: "memory", "cc"
+	);
+}
+
+/*
+ * __raw_spin_is_locked()
+ *	Test if the lock is locked.
+ */
+static inline int __raw_spin_is_locked(raw_spinlock_t *x)
+{
+	return x->lock;
+}
+
+/*
+ * __raw_spin_unlock_wait()
+ *	Wait for the lock to be unlocked.
+ *
+ * Note: the caller has not guarantee that the lock will not
+ * be acquired before they get to it.
+ */
+static inline void __raw_spin_unlock_wait(raw_spinlock_t *x)
+{
+	do { 
+		cpu_relax(); 
+	} while (__raw_spin_is_locked(x));
+}
+
+/*
+ * __raw_spin_trylock()
+ *	Try the lock, return 0 on failure, 1 on success.
+ */
+static inline int __raw_spin_trylock(raw_spinlock_t *x)
+{
+	int ret = 0;
+
+	asm volatile (
+	"	bset	%1, %1, #0	\n\t"
+	"	jmpne.f	1f		\n\t"
+	"	move.4	%0, #1		\n\t"
+	"1:				\n\t"
+		: "+r" (ret), "+U4" (x->lock)
+		:
+		: "memory", "cc"
+	);
+
+	return ret;
+}
+
+/*
+ * __raw_spin_lock_flags()
+ *	Spin waiting for the lock (enabling IRQ(s))
+ */
+static inline void __raw_spin_lock_flags(raw_spinlock_t *x, unsigned long flags)
+{
+	mb();
+	while (!__raw_spin_trylock(x)) {
+		/*
+		 * If the flags from the IRQ are set, interrupts are disabled and we 
+		 * need to re-enable them.
+		 */
+		if (!flags) {
+			cpu_relax();
+		} else {
+			raw_local_irq_enable();
+			cpu_relax();
+			raw_local_irq_disable();
+		}
+	}
+	mb();
+}
+
+/*
+ * Read-write spinlocks, allowing multiple readers but only one writer.
+ * Linux rwlocks are unfair to writers; they can be starved for an indefinite
+ * time by readers.  With care, they can also be taken in interrupt context.
+ *
+ * In Ubicom32 architecture implementation, we have a spinlock and a counter.
+ * Readers use the lock to serialise their access to the counter (which
+ * records how many readers currently hold the lock).
+ * Writers hold the spinlock, preventing any readers or other writers from
+ * grabbing the rwlock.
+ */
+
+/*
+ * __raw_read_lock()
+ *	Increment the counter in the rwlock.
+ *
+ * Note that we have to ensure interrupts are disabled in case we're
+ * interrupted by some other code that wants to grab the same read lock 
+ */
+static inline void __raw_read_lock(raw_rwlock_t *rw)
+{
+	unsigned long flags;
+	raw_local_irq_save(flags);
+	__raw_spin_lock_flags(&rw->lock, flags);
+	rw->counter++;
+	__raw_spin_unlock(&rw->lock);
+	raw_local_irq_restore(flags);
+}
+
+/*
+ * __raw_read_unlock()
+ *	Decrement the counter.
+ *
+ * Note that we have to ensure interrupts are disabled in case we're
+ * interrupted by some other code that wants to grab the same read lock 
+ */
+static inline void __raw_read_unlock(raw_rwlock_t *rw)
+{
+	unsigned long flags;
+	raw_local_irq_save(flags);
+	__raw_spin_lock_flags(&rw->lock, flags);
+	rw->counter--;
+	__raw_spin_unlock(&rw->lock);
+	raw_local_irq_restore(flags);
+}
+
+/* 
+ * __raw_read_trylock()
+ *	Increment the counter if we can.
+ *
+ * Note that we have to ensure interrupts are disabled in case we're
+ * interrupted by some other code that wants to grab the same read lock 
+ */
+static inline int __raw_read_trylock(raw_rwlock_t *rw)
+{
+	unsigned long flags;
+ retry:
+	raw_local_irq_save(flags);
+	if (__raw_spin_trylock(&rw->lock)) {
+		rw->counter++;
+		__raw_spin_unlock(&rw->lock);
+		raw_local_irq_restore(flags);
+		return 1;
+	}
+
+	raw_local_irq_restore(flags);
+
+	/* 
+	 * If write-locked, we fail to acquire the lock 
+	 */
+	if (rw->counter < 0) {
+		return 0;
+	}
+
+	/* 
+	 * Wait until we have a realistic chance at the lock 
+	 */
+	while (__raw_spin_is_locked(&rw->lock) && rw->counter >= 0) {
+		cpu_relax();
+	}
+
+	goto retry;
+}
+
+/*
+ * __raw_write_lock()
+ *	
+ * Note that we have to ensure interrupts are disabled in case we're
+ * interrupted by some other code that wants to read_trylock() this lock 
+ */
+static inline void __raw_write_lock(raw_rwlock_t *rw)
+{
+	unsigned long flags;
+retry:
+	raw_local_irq_save(flags);
+	__raw_spin_lock_flags(&rw->lock, flags);
+
+	if (rw->counter != 0) {
+		__raw_spin_unlock(&rw->lock);
+		raw_local_irq_restore(flags);
+
+		while (rw->counter != 0)
+			cpu_relax();
+
+		goto retry;
+	}
+
+	rw->counter = -1; /* mark as write-locked */
+	mb();
+	raw_local_irq_restore(flags);
+}
+
+static inline void __raw_write_unlock(raw_rwlock_t *rw)
+{
+	rw->counter = 0;
+	__raw_spin_unlock(&rw->lock);
+}
+
+/* Note that we have to ensure interrupts are disabled in case we're
+ * interrupted by some other code that wants to read_trylock() this lock */
+static inline int __raw_write_trylock(raw_rwlock_t *rw)
+{
+	unsigned long flags;
+	int result = 0;
+
+	raw_local_irq_save(flags);
+	if (__raw_spin_trylock(&rw->lock)) {
+		if (rw->counter == 0) {
+			rw->counter = -1;
+			result = 1;
+		} else {
+			/* Read-locked.  Oh well. */
+			__raw_spin_unlock(&rw->lock);
+		}
+	}
+	raw_local_irq_restore(flags);
+
+	return result;
+}
+
+/*
+ * read_can_lock - would read_trylock() succeed?
+ * @lock: the rwlock in question.
+ */
+static inline int __raw_read_can_lock(raw_rwlock_t *rw)
+{
+	return rw->counter >= 0;
+}
+
+/*
+ * write_can_lock - would write_trylock() succeed?
+ * @lock: the rwlock in question.
+ */
+static inline int __raw_write_can_lock(raw_rwlock_t *rw)
+{
+	return !rw->counter;
+}
+
+#define _raw_spin_relax(lock)	cpu_relax()
+#define _raw_read_relax(lock)	cpu_relax()
+#define _raw_write_relax(lock)	cpu_relax()
+
+#endif /* _ASM_UBICOM32_SPINLOCK_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/spinlock_types.h
@@ -0,0 +1,43 @@
+/*
+ * arch/ubicom32/include/asm/spinlock_types.h
+ *   Spinlock related structure definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SPINLOCK_TYPES_H
+#define _ASM_UBICOM32_SPINLOCK_TYPES_H
+
+typedef struct {
+	volatile unsigned int lock;
+} raw_spinlock_t;
+
+typedef struct {
+	raw_spinlock_t lock;
+	volatile int counter;
+} raw_rwlock_t;
+
+#define __RAW_SPIN_LOCK_UNLOCKED	{ 0 }
+#define __RAW_RW_LOCK_UNLOCKED		{ __RAW_SPIN_LOCK_UNLOCKED, 0 }
+
+#endif /* _ASM_UBICOM32_SPINLOCK_TYPES_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/stacktrace.h
@@ -0,0 +1,72 @@
+/*
+ * arch/ubicom32/include/asm/stacktrace.h
+ *   Stacktrace functions for the Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_STACKTRACE_H
+#define _ASM_UBICOM32_STACKTRACE_H
+
+#define between(a, b, c)	(( \
+			((unsigned long) a) >= ((unsigned long) b)) && \
+			(((unsigned long)a) <= ((unsigned long)c)))
+
+/*
+ * These symbols are filled in by the linker.
+ */
+extern unsigned long _stext;
+extern unsigned long _etext;
+
+/* OCM text goes from __ocm_text_run_begin to __data_begin */
+extern unsigned long __ocm_text_run_begin;
+extern unsigned long __data_begin;
+
+/* Account for OCM case - see stacktrace.c maybe combine(also trap.c) */
+/*
+ * ubicom32_is_kernel()
+ *
+ * 	Check to see if the given address belongs to the kernel.
+ * NOMMU does not permit any other means.
+ */
+static inline int ubicom32_is_kernel(unsigned long addr)
+{
+	int is_kernel = between(addr, &_stext, &_etext) || \
+			between(addr, &__ocm_text_run_begin, &__data_begin);
+
+#ifdef CONFIG_MODULES
+	if (!is_kernel)
+		is_kernel = is_module_address(addr);
+#endif
+	return is_kernel;
+}
+
+extern unsigned long stacktrace_iterate(
+				unsigned long **trace, 
+				unsigned long stext, unsigned long etext,
+				unsigned long ocm_stext, unsigned long ocm_etext, 
+				unsigned long sstack, unsigned long estack);
+#ifdef CONFIG_STACKTRACE
+void stacktrace_save_entries(struct task_struct *tsk, struct stack_trace *trace, unsigned long sp);
+#endif
+#endif /* _ASM_UBICOM32_STACKTRACE_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/statfs.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/statfs.h
+ *   Generic statfs.h definitions
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_STATFS_H
+#define _ASM_UBICOM32_STATFS_H
+
+#include <asm-generic/statfs.h>
+
+#endif /* _ASM_UBICOM32_STATFS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/stat.h
@@ -0,0 +1,104 @@
+/*
+ * arch/ubicom32/include/asm/stat.h
+ *   File status definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_STAT_H
+#define _ASM_UBICOM32_STAT_H
+
+struct __old_kernel_stat {
+	unsigned short st_dev;
+	unsigned short st_ino;
+	unsigned short st_mode;
+	unsigned short st_nlink;
+	unsigned short st_uid;
+	unsigned short st_gid;
+	unsigned short st_rdev;
+	unsigned long  st_size;
+	unsigned long  st_atime;
+	unsigned long  st_mtime;
+	unsigned long  st_ctime;
+};
+
+struct stat {
+	unsigned short st_dev;
+	unsigned short __pad1;
+	unsigned long  st_ino;
+	unsigned short st_mode;
+	unsigned short st_nlink;
+	unsigned short st_uid;
+	unsigned short st_gid;
+	unsigned short st_rdev;
+	unsigned short __pad2;
+	unsigned long  st_size;
+	unsigned long  st_blksize;
+	unsigned long  st_blocks;
+	unsigned long  st_atime;
+	unsigned long  __unused1;
+	unsigned long  st_mtime;
+	unsigned long  __unused2;
+	unsigned long  st_ctime;
+	unsigned long  __unused3;
+	unsigned long  __unused4;
+	unsigned long  __unused5;
+};
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat64 {
+	unsigned long long	st_dev;
+	unsigned char	__pad1[2];
+
+#define STAT64_HAS_BROKEN_ST_INO	1
+	unsigned long	__st_ino;
+
+	unsigned int	st_mode;
+	unsigned int	st_nlink;
+
+	unsigned long	st_uid;
+	unsigned long	st_gid;
+
+	unsigned long long	st_rdev;
+	unsigned char	__pad3[2];
+
+	long long	st_size;
+	unsigned long	st_blksize;
+
+	unsigned long long	st_blocks;	/* Number 512-byte blocks allocated. */
+
+	unsigned long	st_atime;
+	unsigned long	st_atime_nsec;
+
+	unsigned long	st_mtime;
+	unsigned long	st_mtime_nsec;
+
+	unsigned long	st_ctime;
+	unsigned long	st_ctime_nsec;
+
+	unsigned long long	st_ino;
+};
+
+#endif /* _ASM_UBICOM32_STAT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/string.h
@@ -0,0 +1,37 @@
+/*
+ * arch/ubicom32/include/asm/string.h
+ *   String operation definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_STRING_H
+#define _ASM_UBICOM32_STRING_H
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *b, int c, size_t len);
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *to, const void *from, size_t len);
+
+#endif /* _ASM_UBICOM32_STRING_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/switch-bcm539x.h
@@ -0,0 +1,57 @@
+/*
+ * arch/ubicom32/include/asm/switch-bcm539x.h
+ *   Broadcom bcm539x platform data definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SWITCH_BCM539X_H
+#define _ASM_UBICOM32_SWITCH_BCM539X_H
+
+#define SWITCH_BCM539X_FLAG_HW_RESET	0x01
+#define SWITCH_BCM539X_FLAG_SW_RESET	0x02
+
+struct switch_bcm539x_platform_data {
+	/*
+	 * See flags above
+	 */
+	u32_t		flags;
+
+	/*
+	 * GPIO to use for nReset
+	 */
+	int		pin_reset;
+
+
+	/*
+	 * GPIO to use for chip select
+	 */
+	int		pin_cs;
+
+	/*
+	 * Name of this switch
+	 */
+	const char	*name;
+};
+
+#endif /* _ASM_UBICOM32_SWITCH_BCM539X_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/system.h
@@ -0,0 +1,101 @@
+/*
+ * arch/ubicom32/include/asm/system.h
+ *   Low level switching definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_SYSTEM_H
+#define _ASM_UBICOM32_SYSTEM_H
+
+#include <linux/irqflags.h>
+#include <linux/linkage.h>
+#include <asm/segment.h>
+#include <asm/entry.h>
+#include <asm/ldsr.h>
+#include <asm/irq.h>
+#include <asm/percpu.h>
+#include <asm/ubicom32-common.h>
+#include <asm/processor.h>
+
+/*
+ * switch_to(n) should switch tasks to task ptr, first checking that
+ * ptr isn't the current task, in which case it does nothing.
+ */
+asmlinkage void resume(void);
+extern void *__switch_to(struct task_struct *prev,
+		struct thread_struct *prev_switch,
+		struct thread_struct *next_switch);
+
+/*
+ * We will need a per linux thread sw_ksp for the switch_to macro to
+ * track the kernel stack pointer for the current thread on that linux thread.
+ */
+#define switch_to(prev,next,last)					\
+({									\
+	void *_last;							\
+	_last = (void *)						\
+		__switch_to(prev, &prev->thread, &next->thread);	\
+	(last) = _last;							\
+})
+
+/*
+ * Force strict CPU ordering.
+ * Not really required on ubicom32...
+ */
+#define nop()  asm volatile ("nop"::)
+#define mb()   asm volatile (""   : : :"memory")
+#define rmb()  asm volatile (""   : : :"memory")
+#define wmb()  asm volatile (""   : : :"memory")
+#define set_mb(var, value)	({ (var) = (value); wmb(); })
+
+#ifdef CONFIG_SMP
+#define smp_mb()	mb()
+#define smp_rmb()	rmb()
+#define smp_wmb()	wmb()
+#define smp_read_barrier_depends()	read_barrier_depends()
+#else
+#define smp_mb()	mb()
+#define smp_rmb()	rmb()
+#define smp_wmb()	wmb()
+#define smp_read_barrier_depends()	do { } while(0)
+#endif
+
+#define read_barrier_depends()  ((void)0)
+
+/*
+ * The following defines change how the scheduler calls the switch_to()
+ * macro.
+ *
+ * 1) The first causes the runqueue to be unlocked on entry to
+ * switch_to().  Since our ctx code does not play with the runqueue
+ * we do not need it unlocked.
+ *
+ * 2) The later turns interrupts on during a ctxsw to reduce the latency of
+ * interrupts during ctx.  At this point in the port, we believe that this
+ * latency is not a problem since we have very little code to perform a ctxsw.
+ */
+// #define __ARCH_WANT_UNLOCKED_CTXSW
+// #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
+
+#endif /* _ASM_UBICOM32_SYSTEM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/termbits.h
@@ -0,0 +1,227 @@
+/*
+ * arch/ubicom32/include/asm/termbits.h
+ *   Terminal/serial port definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TERMBITS_H
+#define _ASM_UBICOM32_TERMBITS_H
+
+#include <linux/posix_types.h>
+
+typedef unsigned char	cc_t;
+typedef unsigned int	speed_t;
+typedef unsigned int	tcflag_t;
+
+#define NCCS 19
+struct termios {
+	tcflag_t c_iflag;		/* input mode flags */
+	tcflag_t c_oflag;		/* output mode flags */
+	tcflag_t c_cflag;		/* control mode flags */
+	tcflag_t c_lflag;		/* local mode flags */
+	cc_t c_line;			/* line discipline */
+	cc_t c_cc[NCCS];		/* control characters */
+};
+
+struct termios2 {
+	tcflag_t c_iflag;		/* input mode flags */
+	tcflag_t c_oflag;		/* output mode flags */
+	tcflag_t c_cflag;		/* control mode flags */
+	tcflag_t c_lflag;		/* local mode flags */
+	cc_t c_line;			/* line discipline */
+	cc_t c_cc[NCCS];		/* control characters */
+	speed_t c_ispeed;		/* input speed */
+	speed_t c_ospeed;		/* output speed */
+};
+
+struct ktermios {
+	tcflag_t c_iflag;		/* input mode flags */
+	tcflag_t c_oflag;		/* output mode flags */
+	tcflag_t c_cflag;		/* control mode flags */
+	tcflag_t c_lflag;		/* local mode flags */
+	cc_t c_line;			/* line discipline */
+	cc_t c_cc[NCCS];		/* control characters */
+	speed_t c_ispeed;		/* input speed */
+	speed_t c_ospeed;		/* output speed */
+};
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+
+/* c_iflag bits */
+#define IGNBRK	0000001
+#define BRKINT	0000002
+#define IGNPAR	0000004
+#define PARMRK	0000010
+#define INPCK	0000020
+#define ISTRIP	0000040
+#define INLCR	0000100
+#define IGNCR	0000200
+#define ICRNL	0000400
+#define IUCLC	0001000
+#define IXON	0002000
+#define IXANY	0004000
+#define IXOFF	0010000
+#define IMAXBEL	0020000
+#define IUTF8	0040000
+
+/* c_oflag bits */
+#define OPOST	0000001
+#define OLCUC	0000002
+#define ONLCR	0000004
+#define OCRNL	0000010
+#define ONOCR	0000020
+#define ONLRET	0000040
+#define OFILL	0000100
+#define OFDEL	0000200
+#define NLDLY	0000400
+#define   NL0	0000000
+#define   NL1	0000400
+#define CRDLY	0003000
+#define   CR0	0000000
+#define   CR1	0001000
+#define   CR2	0002000
+#define   CR3	0003000
+#define TABDLY	0014000
+#define   TAB0	0000000
+#define   TAB1	0004000
+#define   TAB2	0010000
+#define   TAB3	0014000
+#define   XTABS	0014000
+#define BSDLY	0020000
+#define   BS0	0000000
+#define   BS1	0020000
+#define VTDLY	0040000
+#define   VT0	0000000
+#define   VT1	0040000
+#define FFDLY	0100000
+#define   FF0	0000000
+#define   FF1	0100000
+
+/* c_cflag bit meaning */
+#define CBAUD	0010017
+#define  B0	0000000		/* hang up */
+#define  B50	0000001
+#define  B75	0000002
+#define  B110	0000003
+#define  B134	0000004
+#define  B150	0000005
+#define  B200	0000006
+#define  B300	0000007
+#define  B600	0000010
+#define  B1200	0000011
+#define  B1800	0000012
+#define  B2400	0000013
+#define  B4800	0000014
+#define  B9600	0000015
+#define  B19200	0000016
+#define  B38400	0000017
+#define EXTA B19200
+#define EXTB B38400
+#define CSIZE	0000060
+#define   CS5	0000000
+#define   CS6	0000020
+#define   CS7	0000040
+#define   CS8	0000060
+#define CSTOPB	0000100
+#define CREAD	0000200
+#define PARENB	0000400
+#define PARODD	0001000
+#define HUPCL	0002000
+#define CLOCAL	0004000
+#define CBAUDEX 0010000
+#define    BOTHER 0010000
+#define    B57600 0010001
+#define   B115200 0010002
+#define   B230400 0010003
+#define   B460800 0010004
+#define   B500000 0010005
+#define   B576000 0010006
+#define   B921600 0010007
+#define  B1000000 0010010
+#define  B1152000 0010011
+#define  B1500000 0010012
+#define  B2000000 0010013
+#define  B2500000 0010014
+#define  B3000000 0010015
+#define  B3500000 0010016
+#define  B4000000 0010017
+#define CIBAUD	  002003600000		/* input baud rate */
+#define CMSPAR	  010000000000		/* mark or space (stick) parity */
+#define CRTSCTS	  020000000000		/* flow control */
+
+#define IBSHIFT	16			/* Shift from CBAUD to CIBAUD */
+
+/* c_lflag bits */
+#define ISIG	0000001
+#define ICANON	0000002
+#define XCASE	0000004
+#define ECHO	0000010
+#define ECHOE	0000020
+#define ECHOK	0000040
+#define ECHONL	0000100
+#define NOFLSH	0000200
+#define TOSTOP	0000400
+#define ECHOCTL	0001000
+#define ECHOPRT	0002000
+#define ECHOKE	0004000
+#define FLUSHO	0010000
+#define PENDIN	0040000
+#define IEXTEN	0100000
+
+
+/* tcflow() and TCXONC use these */
+#define	TCOOFF		0
+#define	TCOON		1
+#define	TCIOFF		2
+#define	TCION		3
+
+/* tcflush() and TCFLSH use these */
+#define	TCIFLUSH	0
+#define	TCOFLUSH	1
+#define	TCIOFLUSH	2
+
+/* tcsetattr uses these */
+#define	TCSANOW		0
+#define	TCSADRAIN	1
+#define	TCSAFLUSH	2
+
+#endif /* _ASM_UBICOM32_TERMBITS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/termios.h
@@ -0,0 +1,119 @@
+/*
+ * arch/ubicom32/include/asm/termios.h
+ *   Ubicom32 termio definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TERMIOS_H
+#define _ASM_UBICOM32_TERMIOS_H
+
+#include <asm/termbits.h>
+#include <asm/ioctls.h>
+
+struct winsize {
+	unsigned short ws_row;
+	unsigned short ws_col;
+	unsigned short ws_xpixel;
+	unsigned short ws_ypixel;
+};
+
+#define NCC 8
+struct termio {
+	unsigned short c_iflag;		/* input mode flags */
+	unsigned short c_oflag;		/* output mode flags */
+	unsigned short c_cflag;		/* control mode flags */
+	unsigned short c_lflag;		/* local mode flags */
+	unsigned char c_line;		/* line discipline */
+	unsigned char c_cc[NCC];	/* control characters */
+};
+
+#ifdef __KERNEL__
+/*	intr=^C		quit=^|		erase=del	kill=^U
+	eof=^D		vtime=\0	vmin=\1		sxtc=\0
+	start=^Q	stop=^S		susp=^Z		eol=\0
+	reprint=^R	discard=^U	werase=^W	lnext=^V
+	eol2=\0
+*/
+#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
+#endif
+
+/* modem lines */
+#define TIOCM_LE	0x001
+#define TIOCM_DTR	0x002
+#define TIOCM_RTS	0x004
+#define TIOCM_ST	0x008
+#define TIOCM_SR	0x010
+#define TIOCM_CTS	0x020
+#define TIOCM_CAR	0x040
+#define TIOCM_RNG	0x080
+#define TIOCM_DSR	0x100
+#define TIOCM_CD	TIOCM_CAR
+#define TIOCM_RI	TIOCM_RNG
+#define TIOCM_OUT1	0x2000
+#define TIOCM_OUT2	0x4000
+#define TIOCM_LOOP	0x8000
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+
+#ifdef __KERNEL__
+
+/*
+ * Translate a "termio" structure into a "termios". Ugh.
+ */
+#define user_termio_to_kernel_termios(termios, termio) \
+({ \
+	unsigned short tmp; \
+	get_user(tmp, &(termio)->c_iflag); \
+	(termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
+	get_user(tmp, &(termio)->c_oflag); \
+	(termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
+	get_user(tmp, &(termio)->c_cflag); \
+	(termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
+	get_user(tmp, &(termio)->c_lflag); \
+	(termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
+	get_user((termios)->c_line, &(termio)->c_line); \
+	copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
+})
+
+/*
+ * Translate a "termios" structure into a "termio". Ugh.
+ */
+#define kernel_termios_to_user_termio(termio, termios) \
+({ \
+	put_user((termios)->c_iflag, &(termio)->c_iflag); \
+	put_user((termios)->c_oflag, &(termio)->c_oflag); \
+	put_user((termios)->c_cflag, &(termio)->c_cflag); \
+	put_user((termios)->c_lflag, &(termio)->c_lflag); \
+	put_user((termios)->c_line,  &(termio)->c_line); \
+	copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
+})
+
+#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
+#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
+#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
+#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
+
+#endif	/* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_TERMIOS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/thread-asm.h
@@ -0,0 +1,49 @@
+/*
+ * arch/ubicom32/include/asm/thread-asm.h
+ *   Ubicom32 architecture specific thread definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_THREAD_ASM_H
+#define _ASM_UBICOM32_THREAD_ASM_H
+
+/*
+ * thread_get_self
+ *	Read and shift the current thread into reg
+ */
+.macro	thread_get_self reg
+	lsr.4	\reg, ROSR, #2
+	and.4	\reg, #31, \reg	 /* Mask to get thread number into register */
+.endm
+
+/*
+ * thread_get_self_mask
+ *	Read and shift the current thread mask into reg
+ */
+.macro	thread_get_self_mask reg
+	lsr.4	\reg, ROSR, #2
+	lsl.4	\reg, #1, \reg	 /* Thread bit */
+.endm
+
+#endif /* _ASM_UBICOM32_THREAD_ASM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/thread.h
@@ -0,0 +1,313 @@
+/*
+ * arch/ubicom32/include/asm/thread.h
+ *   Ubicom32 architecture specific thread definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_THREAD_H
+#define _ASM_UBICOM32_THREAD_H
+
+#if !defined(__ASSEMBLY__)
+
+#include <asm/ptrace.h>
+#include <asm/ubicom32-common.h>
+
+typedef int thread_t;
+typedef unsigned char thread_type_t;
+typedef void (*thread_exec_fn_t)(void *arg);
+
+#define THREAD_NULL 0x40
+#define THREAD_TYPE_HRT (1 << 0)
+#define THREAD_TYPE_SPECIAL 0
+#define THREAD_TYPE_NORMAL 0
+#define THREAD_TYPE_BACKGROUND (1 << 1)
+
+/*
+ * This is the upper bound on the maximum hardware threads that one will find
+ * on a Ubicom processor. It is used to size per hardware thread data structures.
+ */
+#define THREAD_ARCHITECTURAL_MAX 16
+
+/*
+ * TODO: Rename this at some point to be thread_
+ */
+extern unsigned int sw_ksp[THREAD_ARCHITECTURAL_MAX];
+
+
+/*
+ * thread_get_self()
+ */
+static inline thread_t thread_get_self(void)
+{
+	thread_t result;
+	asm (
+		"lsr.4	%0, ROSR, #2	\n\t"
+		: "=d" (result)
+		:
+		: "cc"
+	);
+	return result & 31;
+}
+
+/*
+ * thread_suspend()
+ */
+static inline void thread_suspend(void)
+{
+	asm volatile (
+		"suspend\n\t"
+		:
+		:
+	);
+}
+
+/*
+ * thread_resume()
+ */
+static inline void thread_resume(thread_t thread)
+{
+	asm volatile (
+		"move.4		MT_ACTIVE_SET, %0	\n\t"
+		"pipe_flush	0			\n\t"
+		"pipe_flush	0			\n\t"
+		:
+		: "d" (1 << thread)
+	);
+}
+
+
+
+/*
+ * thread_enable_mask()
+ *	Enable all threads in the mask.
+ *
+ * All writes to MT_EN must be protected by the MT_EN_LOCK bit
+ */
+static inline void thread_enable_mask(unsigned int mask)
+{
+	/*
+	 * must flush the pipeline twice.
+	 * first pipe_flush is to ensure write to MT_EN is completed
+	 * second one is to ensure any new instructions from
+	 * the targeted thread (the one being disabled), that
+	 * are issued while the write to MT_EN is being executed,
+	 * are completed.
+	 */
+	UBICOM32_LOCK(MT_EN_LOCK_BIT);
+	asm volatile (
+		"or.4		MT_EN, MT_EN, %0	\n\t"
+		"pipe_flush	0			\n\t"
+		"pipe_flush	0			\n\t"
+		:
+		: "d" (mask)
+		: "cc"
+	);
+	UBICOM32_UNLOCK(MT_EN_LOCK_BIT);
+}
+
+/*
+ * thread_enable()
+ */
+static inline void thread_enable(thread_t thread)
+{
+	thread_enable_mask(1 << thread);
+}
+
+/*
+ * thread_disable_mask()
+ *	Disable all threads in the mask.
+ *
+ * All writes to MT_EN must be protected by the MT_EN_LOCK bit
+ */
+static inline void thread_disable_mask(unsigned int mask)
+{
+	/*
+	 * must flush the pipeline twice.
+	 * first pipe_flush is to ensure write to MT_EN is completed
+	 * second one is to ensure any new instructions from
+	 * the targeted thread (the one being disabled), that
+	 * are issued while the write to MT_EN is being executed,
+	 * are completed.
+	 */
+	UBICOM32_LOCK(MT_EN_LOCK_BIT);
+	asm volatile (
+		"and.4		MT_EN, MT_EN, %0	\n\t"
+		"pipe_flush	0			\n\t"
+		"pipe_flush	0			\n\t"
+		:
+		: "d" (~mask)
+		: "cc"
+	);
+	UBICOM32_UNLOCK(MT_EN_LOCK_BIT);
+}
+
+/*
+ * thread_disable()
+ */
+static inline void thread_disable(thread_t thread)
+{
+	thread_disable_mask(1 << thread);
+}
+
+/*
+ * thread_disable_others()
+ *	Disable all other threads
+ */
+static inline void thread_disable_others(void)
+{
+	thread_t self = thread_get_self();
+	thread_disable_mask(~(1 << self));
+}
+
+/*
+ * thread_is_trapped()
+ *	Is the specified tid trapped?
+ */
+static inline int thread_is_trapped(thread_t tid)
+{
+	int thread_mask = (1 << tid);
+	int trap_thread;
+
+	asm (
+		"move.4		%0, MT_TRAP		\n\t"
+		: "=d" (trap_thread)
+		:
+	);
+	return (trap_thread & thread_mask);
+}
+
+/*
+ * thread_is_enabled()
+ *	Is the specified tid enabled?
+ */
+static inline int thread_is_enabled(thread_t tid)
+{
+	int thread_mask = (1 << tid);
+	int enabled_threads;
+
+	asm (
+		"move.4		%0, MT_EN		\n\t"
+		: "=d" (enabled_threads)
+		:
+	);
+	return (enabled_threads & thread_mask);
+}
+
+/*
+ * thread_get_instruction_count()
+ */
+static inline unsigned int thread_get_instruction_count(void)
+{
+	unsigned int result;
+	asm (
+		"move.4		%0, INST_CNT		\n\t"
+		: "=r" (result)
+	);
+	return result;
+}
+
+/*
+ * thread_get_pc()
+ *	pc could point to a speculative and cancelled instruction unless thread is disabled
+ */
+static inline void *thread_get_pc(thread_t thread)
+{
+	void *result;
+	asm (
+		"move.4		csr, %1		\n\t"
+		"setcsr_flush	0		\n\t"
+		"move.4		%0, pc		\n\t"
+		"move.4		csr, #0		\n\t"
+		"setcsr_flush	0		\n\t"
+		: "=r" (result)
+		: "r" ((thread << 9) | (1 << 8))
+	);
+	return result;
+}
+
+/*
+ * thread_get_trap_cause()
+ *	This should be called only when the thread is not running
+ */
+static inline unsigned int thread_get_trap_cause(thread_t thread)
+{
+	unsigned int result;
+	asm (
+		"move.4		csr, %1		\n\t"
+		"setcsr_flush	0		\n\t"
+		"move.4		%0, trap_cause	\n\t"
+		"move.4		csr, #0		\n\t"
+		"setcsr_flush	0		\n\t"
+		: "=r" (result)
+		: "r" ((thread << 9) | (1 << 8))
+	);
+	return result;
+}
+
+/*
+ * THREAD_STALL macro.
+ */
+#define THREAD_STALL \
+		asm volatile ( \
+			"move.4	mt_dbg_active_clr, #-1	\n\t" \
+			"pipe_flush 0			\n\t" \
+			: \
+			: \
+		)
+
+extern unsigned int thread_get_mainline(void);
+extern void thread_set_mainline(thread_t tid);
+extern thread_t thread_alloc(void);
+extern thread_t thread_start(thread_t thread, thread_exec_fn_t exec, void *arg, unsigned int *sp_high, thread_type_t type);
+
+/*
+ * asm macros
+ */
+asm (
+/*
+ * thread_get_self
+ *	Read and shift the current thread into reg
+ */
+".macro	thread_get_self reg		\n\t"
+"	lsr.4	\\reg, ROSR, #2		\n\t"
+"	and.4	\\reg, #31, \\reg	\n\t"/* Mask to get thread number into
+					      * register */
+".endm					\n\t"
+
+/*
+ * thread_get_self_mask
+ *	Read and shift the current thread mask into reg
+ */
+".macro	thread_get_self_mask reg	\n\t"
+"	lsr.4	\\reg, ROSR, #2		\n\t"
+"	lsl.4	\\reg, #1, \\reg	\n\t"	 /* Thread bit */
+".endm					\n\t"
+	);
+
+#else /* __ASSEMBLY__ */
+
+#include <asm/thread-asm.h>
+
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_UBICOM32_THREAD_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/thread_info.h
@@ -0,0 +1,134 @@
+/*
+ * arch/ubicom32/include/asm/thread_info.h
+ *   Ubicom32 architecture low-level thread information.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Adapted from the i386 and PPC versions by Greg Ungerer (gerg@snapgear.com)
+ * Copyright (C) 2002  David Howells (dhowells@redhat.com)
+ * - Incorporating suggestions made by Linus Torvalds and Dave Miller
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_THREAD_INFO_H
+#define _ASM_UBICOM32_THREAD_INFO_H
+
+#include <asm/page.h>
+
+/*
+ * Size of kernel stack for each process. This must be a power of 2...
+ */
+#ifdef CONFIG_4KSTACKS
+#define THREAD_SIZE_ORDER (0)
+#else
+#define THREAD_SIZE_ORDER (1)
+#endif
+
+/*
+ * for asm files, THREAD_SIZE is now generated by asm-offsets.c
+ */
+#define THREAD_SIZE (PAGE_SIZE<<THREAD_SIZE_ORDER)
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+/*
+ * low level task data.
+ */
+struct thread_info {
+	struct task_struct *task;		/* main task structure */
+	struct exec_domain *exec_domain;	/* execution domain */
+	unsigned long	   flags;		/* low level flags */
+	int		   cpu;			/* cpu we're on */
+	int		   preempt_count;	/* 0 => preemptable, <0 => BUG */
+	int		   interrupt_nesting; 	/* Interrupt nesting level. */
+	struct restart_block restart_block;
+};
+
+/*
+ * macros/functions for gaining access to the thread information structure
+ */
+#define INIT_THREAD_INFO(tsk)			\
+{						\
+	.task		= &tsk,			\
+	.exec_domain	= &default_exec_domain,	\
+	.flags		= 0,			\
+	.cpu		= 0,			\
+	.interrupt_nesting	= 0,		\
+	.restart_block	= {			\
+		.fn = do_no_restart_syscall,	\
+	},					\
+}
+
+#define init_thread_info	(init_thread_union.thread_info)
+#define init_stack		(init_thread_union.stack)
+
+
+/* how to get the thread information struct from C */
+static inline struct thread_info *current_thread_info(void)
+{
+	struct thread_info *ti;
+
+	asm (
+		"and.4	%0, sp, %1\n\t"
+		: "=&r" (ti)
+		: "d" (~(THREAD_SIZE-1))
+		: "cc"
+	);
+
+	return ti;
+}
+
+#define STACK_WARN (THREAD_SIZE / 8)
+
+#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR 1
+
+/* thread information allocation */
+#define alloc_thread_info(tsk) ((struct thread_info *) \
+				__get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER))
+#define free_thread_info(ti)	free_pages((unsigned long) (ti), THREAD_SIZE_ORDER)
+#endif /* __ASSEMBLY__ */
+
+#define	PREEMPT_ACTIVE	0x4000000
+
+/*
+ * thread information flag bit numbers
+ */
+#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
+#define TIF_SIGPENDING		1	/* signal pending */
+#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
+#define TIF_POLLING_NRFLAG	3	/* true if poll_idle() is polling
+					   TIF_NEED_RESCHED */
+#define TIF_MEMDIE		4
+
+/* as above, but as bit values */
+#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
+#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
+#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
+#define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
+
+#define _TIF_WORK_MASK		0x0000FFFE	/* work to do on interrupt/exception return */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_THREAD_INFO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/timex.h
@@ -0,0 +1,56 @@
+/*
+ * arch/ubicom32/include/asm/timex.h
+ *   Ubicom32 architecture timex specifications.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TIMEX_H
+#define _ASM_UBICOM32_TIMEX_H
+
+#define CLOCK_TICK_RATE	266000000
+
+// #define ARCH_HAS_READ_CURRENT_TIMER
+
+typedef unsigned long cycles_t;
+
+static inline cycles_t get_cycles(void)
+{
+	return 0;
+}
+
+extern int timer_alloc(void);
+extern void timer_set(int timervector, unsigned int cycles);
+extern int timer_reset(int timervector, unsigned int cycles);
+extern void timer_tick_init(void);
+extern void timer_device_init(void);
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
+extern void local_timer_interrupt(void);
+#endif
+
+#if defined(CONFIG_LOCAL_TIMERS) || defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
+extern int local_timer_setup(unsigned int cpu);
+#endif
+
+#endif /* _ASM_UBICOM32_TIMEX_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/tlbflush.h
@@ -0,0 +1,79 @@
+/*
+ * arch/ubicom32/include/asm/tlbflush.h
+ *   TLB operations for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2000 Lineo, David McCullough <davidm@uclinux.org>
+ * Copyright (C) 2000-2002, Greg Ungerer <gerg@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TLB_FLUSH_H
+#define _ASM_UBICOM32_TLB_FLUSH_H
+
+#include <asm/setup.h>
+
+/*
+ * flush all user-space atc entries.
+ */
+static inline void __flush_tlb(void)
+{
+	BUG();
+}
+
+static inline void __flush_tlb_one(unsigned long addr)
+{
+	BUG();
+}
+
+#define flush_tlb() __flush_tlb()
+
+/*
+ * flush all atc entries (both kernel and user-space entries).
+ */
+static inline void flush_tlb_all(void)
+{
+	BUG();
+}
+
+static inline void flush_tlb_mm(struct mm_struct *mm)
+{
+	BUG();
+}
+
+static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+	BUG();
+}
+
+static inline void flush_tlb_range(struct mm_struct *mm,
+				   unsigned long start, unsigned long end)
+{
+	BUG();
+}
+
+static inline void flush_tlb_kernel_page(unsigned long addr)
+{
+	BUG();
+}
+
+#endif /* _ASM_UBICOM32_TLB_FLUSH_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/tlb.h
@@ -0,0 +1,47 @@
+/*
+ * arch/ubicom32/include/asm/tlb.h
+ *   Ubicom32 architecture TLB operations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TLB_H
+#define _ASM_UBICOM32_TLB_H
+
+/*
+ * ubicom32 doesn't need any special per-pte or
+ * per-vma handling..
+ */
+#define tlb_start_vma(tlb, vma)	do { } while (0)
+#define tlb_end_vma(tlb, vma)	do { } while (0)
+#define __tlb_remove_tlb_entry(tlb, ptep, address)	do { } while (0)
+
+/*
+ * .. because we flush the whole mm when it
+ * fills up.
+ */
+#define tlb_flush(tlb)
+
+#include <asm-generic/tlb.h>
+
+#endif /* _ASM_UBICOM32_TLB_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/topology.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/topology.h
+ *   Generic topology.h definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TOPOLOGY_H
+#define _ASM_UBICOM32_TOPOLOGY_H
+
+#include <asm-generic/topology.h>
+
+#endif /* _ASM_UBICOM32_TOPOLOGY_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/traps.h
@@ -0,0 +1,55 @@
+/*
+ * arch/ubicom32/include/asm/traps.h
+ *   Trap related definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_TRAPS_H
+#define _ASM_UBICOM32_TRAPS_H
+
+/*
+ * Trap causes passed from ultra to Host OS
+ */
+#define TRAP_CAUSE_TOTAL		13
+#define TRAP_CAUSE_DST_RANGE_ERR	12
+#define TRAP_CAUSE_SRC1_RANGE_ERR	11
+#define TRAP_CAUSE_I_RANGE_ERR		10
+#define TRAP_CAUSE_DCAPT		9
+#define TRAP_CAUSE_DST_SERROR		8
+#define TRAP_CAUSE_SRC1_SERROR		7
+#define TRAP_CAUSE_DST_MISALIGNED	6
+#define TRAP_CAUSE_SRC1_MISALIGNED	5
+#define TRAP_CAUSE_DST_DECODE_ERR	4
+#define TRAP_CAUSE_SRC1_DECODE_ERR	3
+#define TRAP_CAUSE_ILLEGAL_INST		2
+#define TRAP_CAUSE_I_SERROR		1
+#define TRAP_CAUSE_I_DECODE_ERR		0
+
+extern void trap_handler(int irq, struct pt_regs *regs);
+extern void trap_init_interrupt(void);
+extern void unaligned_emulate(unsigned int thread);
+extern int unaligned_only(unsigned int cause);
+
+#endif /* _ASM_UBICOM32_TRAPS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/types.h
@@ -0,0 +1,75 @@
+/*
+ * arch/ubicom32/include/asm/types.h
+ *   Date type definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_TYPES_H
+#define _ASM_UBICOM32_TYPES_H
+
+/*
+ * This file is never included by application software unless
+ * explicitly requested (e.g., via linux/types.h) in which case the
+ * application is Linux specific so (user-) name space pollution is
+ * not a major issue.  However, for interoperability, libraries still
+ * need to be careful to avoid a name clashes.
+ */
+
+#include <asm-generic/int-ll64.h>
+
+#ifndef __ASSEMBLY__
+
+typedef unsigned short umode_t;
+
+#endif /* __ASSEMBLY__ */
+
+/*
+ * These aren't exported outside the kernel to avoid name space clashes
+ */
+#ifdef __KERNEL__
+
+#define BITS_PER_LONG 32
+
+#ifndef __ASSEMBLY__
+
+/* DMA addresses are always 32-bits wide */
+
+typedef u32 dma_addr_t;
+typedef u32 dma64_addr_t;
+
+/*
+ * XXX These are "Ubicom style" typedefs. They should be removed in all files used by linux.
+ */
+typedef u32 u32_t;
+typedef s32 s32_t;
+typedef u16 u16_t;
+typedef s16 s16_t;
+typedef u8 u8_t;
+typedef s8 s8_t;
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_TYPES_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/uaccess.h
@@ -0,0 +1,347 @@
+/*
+ * arch/ubicom32/include/asm/uaccess.h
+ *   User space memory access functions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *   arch/alpha
+ */
+#ifndef _ASM_UBICOM32_UACCESS_H
+#define _ASM_UBICOM32_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+
+#include <asm/segment.h>
+
+#define VERIFY_READ	0
+#define VERIFY_WRITE	1
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue.  No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+struct exception_table_entry
+{
+	unsigned long insn, fixup;
+};
+
+/* 
+ * Ubicom32 does not currently support the exception table handling.
+ */
+extern unsigned long search_exception_table(unsigned long);
+
+
+#if defined(CONFIG_ACCESS_OK_CHECKS_ENABLED)
+extern int __access_ok(unsigned long addr, unsigned long size);
+#else
+static inline int __access_ok(unsigned long addr, unsigned long size)
+{
+	return 1;
+}
+#endif
+#define access_ok(type, addr, size) \
+	likely(__access_ok((unsigned long)(addr), (size)))
+
+/*
+ * The following functions do not exist.  They keep callers
+ * of put_user and get_user from passing unsupported argument
+ * types.  They result in a link time error.
+ */
+extern int __put_user_bad(void);
+extern int __get_user_bad(void);
+
+/*
+ * __put_user_no_check()
+ *	Put the requested data into the user space verifying the address
+ *
+ * Careful to not
+ * (a) re-use the arguments for side effects (sizeof/typeof is ok)
+ * (b) require any knowledge of processes at this stage
+ */
+#define __put_user_no_check(x, ptr, size)		\
+({							\
+	int __pu_err = 0;				\
+	__typeof__(*(ptr)) __user *__pu_addr = (ptr);	\
+	switch (size) {					\
+	case 1:						\
+	case 2:						\
+	case 4:						\
+	case 8:						\
+		*__pu_addr = (__typeof__(*(ptr)))x;	\
+		break;					\
+	default:					\
+		__pu_err = __put_user_bad();		\
+		break;					\
+	}						\
+	__pu_err;					\
+})
+
+/*
+ * __put_user_check()
+ *	Put the requested data into the user space verifying the address
+ *
+ * Careful to not
+ * (a) re-use the arguments for side effects (sizeof/typeof is ok)
+ * (b) require any knowledge of processes at this stage
+ *
+ * If requested, access_ok() will verify that ptr is a valid user
+ * pointer.
+ */
+#define __put_user_check(x, ptr, size)				\
+({								\
+	int __pu_err = -EFAULT;					\
+	__typeof__(*(ptr)) __user *__pu_addr = (ptr);		\
+	if (access_ok(VERIFY_WRITE, __pu_addr, size)) {		\
+		__pu_err = 0;					\
+		switch (size) {					\
+		case 1:						\
+		case 2:						\
+		case 4:						\
+		case 8:						\
+			*__pu_addr = (__typeof__(*(ptr)))x;	\
+			break;					\
+		default:					\
+			__pu_err = __put_user_bad();		\
+			break;					\
+		}						\
+	}							\
+	__pu_err;						\
+})
+
+/*
+ * __get_user_no_check()
+ *	Read the value at ptr into x.
+ *
+ * If requested, access_ok() will verify that ptr is a valid user
+ * pointer.  If the caller passes a modifying argument for ptr (e.g. x++)
+ * this macro will not work.
+ */
+#define __get_user_no_check(x, ptr, size)			\
+({								\
+	int __gu_err = 0;					\
+	__typeof__((x)) __gu_val = 0;				\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);	\
+	switch (size) {						\
+	case 1:							\
+	case 2:							\
+	case 4:							\
+	case 8:							\
+		__gu_val = (__typeof__((x)))*(__gu_addr);	\
+		break;						\
+	default:						\
+		__gu_err = __get_user_bad();			\
+		(x) = 0;					\
+		break;						\
+	}							\
+	(x) = __gu_val;						\
+	__gu_err;						\
+})
+
+/*
+ * __get_user_check()
+ *	Read the value at ptr into x.
+ *
+ * If requested, access_ok() will verify that ptr is a valid user
+ * pointer.
+ */
+#define __get_user_check(x, ptr, size)					\
+({									\
+	int __gu_err = -EFAULT;						\
+	__typeof__(x) __gu_val = 0;					\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
+	if (access_ok(VERIFY_READ, __gu_addr, size)) {			\
+		__gu_err = 0;						\
+		switch (size) {						\
+		case 1:							\
+		case 2:							\
+		case 4:							\
+		case 8:							\
+			__gu_val = (__typeof__((x)))*(__gu_addr);	\
+			break;						\
+		default:						\
+			__gu_err = __get_user_bad();			\
+			(x) = 0;					\
+			break;						\
+		}							\
+	}								\
+	(x) = __gu_val;							\
+	__gu_err;							\
+})
+
+/*
+ * The "xxx" versions are allowed to perform some amount of address
+ * space checking.  See access_ok().
+ */
+#define put_user(x,ptr) \
+	__put_user_check((__typeof__(*(ptr)))(x),(ptr), sizeof(*(ptr)))
+#define get_user(x,ptr) \
+	__get_user_check((x), (ptr), sizeof(*(ptr)))
+
+/*
+ * The "__xxx" versions do not do address space checking, useful when
+ * doing multiple accesses to the same area (the programmer has to do the
+ * checks by hand with "access_ok()")
+ */
+#define __put_user(x,ptr) \
+	__put_user_no_check((__typeof__(*(ptr)))(x),(ptr), sizeof(*(ptr)))
+#define __get_user(x,ptr) \
+	__get_user_no_check((x), (ptr), sizeof(*(ptr)))
+
+/*
+ * __copy_tofrom_user_no_check()
+ *	Copy the data either to or from user space.
+ *
+ * Return the number of bytes NOT copied.
+ */
+static inline unsigned long
+__copy_tofrom_user_no_check(void *to, const void *from, unsigned long n)
+{
+	memcpy(to, from, n);
+	return 0;
+}
+
+/*
+ * copy_to_user()
+ * 	Copy the kernel data to user space.
+ *
+ * Return the number of bytes that were copied.
+ */
+static inline unsigned long 
+copy_to_user(void __user *to, const void *from, unsigned long n)
+{
+	if (!access_ok(VERIFY_WRITE, to, n)) {
+		return n;
+	}
+	return __copy_tofrom_user_no_check((__force void *)to, from, n);
+}
+
+/*
+ * copy_from_user()
+ * 	Copy the user data to kernel space.
+ *
+ * Return the number of bytes that were copied.  On error, we zero 
+ * out the destination.
+ */
+static inline unsigned long
+copy_from_user(void *to, const void __user *from, unsigned long n)
+{
+	if (!access_ok(VERIFY_READ, from, n)) {
+		return n;
+	}
+	return __copy_tofrom_user_no_check(to, (__force void *)from, n);
+}
+
+#define __copy_to_user(to, from, n) \
+	__copy_tofrom_user_no_check((__force void *)to, from, n)
+#define __copy_from_user(to, from, n) \
+	__copy_tofrom_user_no_check(to, (__force void *)from, n)
+#define __copy_to_user_inatomic(to, from, n) \
+	__copy_tofrom_user_no_check((__force void *)to, from, n)
+#define __copy_from_user_inatomic(to, from, n) \
+	__copy_tofrom_user_no_check(to, (__force void *)from, n)
+
+#define copy_to_user_ret(to, from, n, retval) \
+	({ if (copy_to_user(to, from, n)) return retval; })
+
+#define copy_from_user_ret(to, from, n, retval) \
+	({ if (copy_from_user(to, from, n)) return retval; })
+
+/*
+ * strncpy_from_user()
+ *	Copy a null terminated string from userspace.
+ *
+ * dst - Destination in kernel space.  The buffer must be at least count.
+ * src - Address of string in user space.
+ * count - Maximum number of bytes to copy (including the trailing NULL).
+ * 
+ * Returns the length of the string (not including the trailing NULL.  If 
+ * count is smaller than the length of the string, we copy count bytes
+ * and return count.
+ *
+ */
+static inline long strncpy_from_user(char *dst, const __user char *src, long count)
+{
+	char *tmp;
+	if (!access_ok(VERIFY_READ, src, 1)) {
+		return -EFAULT;
+	}
+
+	strncpy(dst, src, count);
+	for (tmp = dst; *tmp && count > 0; tmp++, count--) {
+		;
+	}
+	return(tmp - dst);
+}
+
+/*
+ * strnlen_user()
+ *	Return the size of a string (including the ending 0)
+ *
+ * Return -EFAULT on exception, a value greater than <n> if too long
+ */
+static inline long strnlen_user(const __user char *src, long n)
+{
+	if (!access_ok(VERIFY_READ, src, 1)) {
+		return -EFAULT;
+	}
+	return(strlen(src) + 1);
+}
+
+#define strlen_user(str) strnlen_user(str, 32767)
+
+/*
+ * __clear_user()
+ *	Zero Userspace
+ */
+static inline unsigned long __clear_user(__user void *to, unsigned long n)
+{
+	memset(to, 0, n);
+	return 0;
+}
+
+/*
+ * clear_user()
+ *	Zero user space (check for valid addresses)
+ */
+static inline unsigned long clear_user(__user void *to, unsigned long n)
+{
+	if (!access_ok(VERIFY_WRITE, to, n)) {
+		return -EFAULT;
+	}
+	return __clear_user(to, n);
+}
+
+#endif /* _ASM_UBICOM32_UACCESS_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubi32-cs4384.h
@@ -0,0 +1,53 @@
+/*
+ * arch/ubicom32/include/asm/ubi32-cs4384.h
+ *   Ubicom32 architecture CS4384 driver platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_UBI32_CS4384_H
+#define _ASM_UBICOM32_UBI32_CS4384_H
+
+enum ubi32_cs4384_mclk_source {
+	UBI32_CS4384_MCLK_PWM_0,
+	UBI32_CS4384_MCLK_PWM_1,
+	UBI32_CS4384_MCLK_PWM_2,
+	UBI32_CS4384_MCLK_CLKDIV_1,
+	UBI32_CS4384_MCLK_OTHER,
+};
+
+struct ubi32_cs4384_mclk_entry {
+	/*
+	 * Rate, in Hz, of this entry
+	 */
+	int rate;
+
+	/*
+	 * The divider to program to get the rate
+	 */
+	int div;
+};
+
+struct ubi32_cs4384_platform_data {
+	enum ubi32_cs4384_mclk_source	mclk_src;
+
+	int				n_mclk;
+	struct ubi32_cs4384_mclk_entry	*mclk_entries;
+};
+#endif /* _ASM_UBICOM32_UBI32_CS4384_H */
+
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubi32-pcm.h
@@ -0,0 +1,53 @@
+/*
+ * arch/ubicom32/include/asm/ubi32-pcm.h
+ *   Ubicom32 architecture PCM driver platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_UBI32_PCM_H
+#define _ASM_UBICOM32_UBI32_PCM_H
+
+/*
+ * This function is called when the sample rate has changed
+ */
+typedef int (*ubi32_pcm_set_rate_fn_t)(void *appdata, int rate);
+
+struct ubi32pcm_platform_data {
+	/*
+	 * Name of the audiotio node
+	 */
+	const char		*node_name;
+
+	/*
+	 * Application specific data provided when calling functions
+	 */
+	void			*appdata;
+
+	/*
+	 * Functions called when various things happen
+	 */
+	ubi32_pcm_set_rate_fn_t	set_rate;
+
+	/*
+	 * Pointer to optional upper layer data (i.e. DAC config, etc)
+	 */
+	void			*priv_data;
+};
+#endif /* _ASM_UBICOM32_UBI32_PCM_H */
+
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32bl.h
@@ -0,0 +1,84 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32bl.h
+ *   Ubicom32 architecture backlight driver platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_BL_H
+#define _ASM_UBICOM32_UBICOM32_BL_H
+
+/*
+ * Different backlight control mechanisms
+ */
+enum ubicom32bl_pwm_types {
+	/*
+	 * PWM controlled backlight
+	 */
+	UBICOM32BL_TYPE_PWM,
+
+	/*
+	 * HRT based PWM backlight
+	 */
+	UBICOM32BL_TYPE_PWM_HRT,
+
+	/*
+	 * No dimming, just on or off
+	 */
+	UBICOM32BL_TYPE_BINARY,
+};
+
+struct ubicom32bl_platform_data {
+	/*
+	 * Default intensity of the backlight 0-255
+	 */
+	u8_t				default_intensity;
+
+	/*
+	 * TRUE if the backlight sense is active low. (inverted)
+	 * FALSE if the backlight sense is active high.
+	 */
+	bool				invert;
+
+	/*
+	 * Type of the backlight
+	 */
+	enum ubicom32bl_pwm_types	type;
+
+	/*
+	 * GPIO of the backlight if UBICOM32BL_TYPE_PWM_HRT, UBICOM32BL_TYPE_BINARY
+	 */
+	unsigned			gpio;
+
+	/*
+	 * PWM channel and parameters of the backlight if UBICOM32BL_TYPE_PWM
+	 *	pre_scaler: sets the rate at which the PWM timer is clocked. (clk_core / 2^pre_scaler)
+	 *	period: sets the period of the timer in timer cycles
+	 * The duty cycle will be directly proportional to the brightness setting.
+	 */
+	u32_t				pwm_channel;
+	u8_t				pwm_prescale;
+	u16_t				pwm_period;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_BL_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32-common-asm.h
@@ -0,0 +1,49 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32-common-asm.h
+ *   Ubicom32 atomic lock operations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_UBICOM32_COMMON_ASM_H
+#define _ASM_UBICOM32_UBICOM32_COMMON_ASM_H
+
+/*
+ * atomic_lock_acquire macro
+ *	Equivalent to __atomic_lock_acquire()
+ */
+.macro atomic_lock_acquire
+	bset scratchpad1, scratchpad1, #ATOMIC_LOCK_BIT
+	jmpne.f	.-4
+.endm
+
+/*
+ * atomic_lock_release macro
+ *	Equivalent to __atomic_lock_release()
+ */
+.macro atomic_lock_release
+	bclr scratchpad1, scratchpad1, #ATOMIC_LOCK_BIT
+.endm
+
+#endif /* _ASM_UBICOM32_UBICOM32_COMMON_ASM_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32-common.h
@@ -0,0 +1,124 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32-common.h
+ *   Ubicom32 atomic lock operations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_UBICOM32_COMMON_H
+#define _ASM_UBICOM32_UBICOM32_COMMON_H
+
+#define S(arg) #arg
+#define D(arg) S(arg)
+/*
+ * scratchpad1 is owned by the LDSR.  
+ * 
+ * The upper bits provide 16 global spinlocks.  Acquiring one of these
+ * global spinlocks synchornizes across multiple threads and prevents 
+ * the LDSR from delivering any interrupts while the lock is held.
+ * Use these locks only when absolutely required.
+ *
+ * The lower 16 bits of scratchpad1 are used as per thread interrupt
+ * enable/disable bits.  These bits will prevent a thread from receiving
+ * any interrupts.
+ *
+ * Bit Usage:
+ * - MT_EN_LOCK_BIT   - Protects writes to MT_EN, so code can read current value
+ *			then write a new value atomically (profiler for example)
+ * - ATOMIC_LOCK_BIT - Used to provide general purpose atomic handling.
+ * - LDSR_LOCK_BIT   - Used by the LDSR exclusively to provide protection.
+ * - LSB 16 bits     - Used by the LDSR to represent thread enable/disable bits.
+ */
+#define MT_EN_LOCK_BIT	31
+#define ATOMIC_LOCK_BIT 30
+#define LDSR_LOCK_BIT   29
+#define PCI_LOCK_BIT	28
+
+#if !defined(__ASSEMBLY__)
+
+#define UBICOM32_TRYLOCK(bit) \
+	asm volatile (						      \
+	"	move.4 %0, #0					\n\t" \
+	"	bset scratchpad1, scratchpad1, #"D(bit)"	\n\t" \
+	"	jmpne.f	1f					\n\t" \
+	"	move.4 %0, #1					\n\t" \
+	"1:							\n\t" \
+		: "=r" (ret)					      \
+		:						      \
+		: "cc", "memory"				      \
+	);							      \
+
+#define UBICOM32_UNLOCK(bit) \
+	asm volatile (						      \
+	"	bclr scratchpad1, scratchpad1, #"D(bit)"	\n\t" \
+		:						      \
+		:						      \
+		: "cc", "memory"				      \
+	);							      \
+
+#define UBICOM32_LOCK(bit) \
+	asm volatile (						      \
+	"1:	bset scratchpad1, scratchpad1, #"D(bit)"	\n\t" \
+	"	jmpne.f	1b					\n\t" \
+		:						      \
+		:						      \
+		: "cc", "memory"				      \
+	);							      \
+
+/*
+ * __atomic_lock_trylock()
+ *	Attempt to acquire the lock, return TRUE if acquired.
+ */
+static inline int __atomic_lock_trylock(void)
+{
+	int ret;
+	UBICOM32_TRYLOCK(ATOMIC_LOCK_BIT);
+	return ret;
+}
+
+/*
+ * __atomic_lock_release()
+ *	Release the global atomic lock.
+ *
+ * Note: no one is suspended waiting since this lock is a spinning lock.
+ */
+static inline void __atomic_lock_release(void)
+{
+	UBICOM32_UNLOCK(ATOMIC_LOCK_BIT);
+}
+
+/*
+ * __atomic_lock_acquire()
+ *	Acquire the global atomic lock, spin if not available.
+ */
+static inline void __atomic_lock_acquire(void)
+{
+	UBICOM32_LOCK(ATOMIC_LOCK_BIT);
+}
+#else /* __ASSEMBLY__ */
+
+#include <asm/ubicom32-common-asm.h>
+
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_UBICOM32_UBICOM32_COMMON_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32fb.h
@@ -0,0 +1,56 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32fb.h
+ *   Ubicom32 architecture video frame buffer definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_UBICOM32FB_H
+#define _ASM_UBICOM32_UBICOM32FB_H
+
+#include <linux/ioctl.h>
+
+/* 
+ * Set next frame
+ */
+#define UBICOM32FB_IOCTL_SET_NEXT_FRAME		_IOW('r',  1, void *) 
+#define UBICOM32FB_IOCTL_SET_NEXT_FRAME_SYNC	_IOW('r',  2, void *) 
+
+/*
+ * Set Mode
+ */
+#define UBICOM32FB_IOCTL_SET_MODE		_IOW('r',  3, void *) 
+struct ubicom32fb_mode {
+	unsigned long	width;
+	unsigned long	height;
+	unsigned long	flags;
+	void		*next_frame;
+};
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV_SCAN_ORDER	(1 << 8)
+
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV_BLOCK_ORDER	(1 << 7)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV		(1 << 6)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_VSUB		(1 << 5)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_VRANGE_16_255	(1 << 4)
+
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_VRANGE_0_255	(1 << 3)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_HSUB_2_1		(1 << 2)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_HSUB_1_1		(1 << 1)
+#define UBICOM32FB_IOCTL_SET_MODE_FLAG_SCALE_ENABLE	(1 << 0)
+
+#endif /* _ASM_UBICOM32_UBICOM32FB_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32hid.h
@@ -0,0 +1,133 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32hid.h
+ *   Ubicom32 architecture HID driver platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_HID_H
+#define _ASM_UBICOM32_UBICOM32_HID_H
+
+enum ubicom32hid_bl_types {
+	/*
+	 * On or off, using command SET_BL_EN, PB4
+	 */
+	UBICOM32HID_BL_TYPE_BINARY,
+
+	/*
+	 * Dimmable, using command SET_PWM, PB3
+	 */
+	UBICOM32HID_BL_TYPE_PWM,
+};
+
+/*
+ * IR code mapping to event code.
+ *	If there are no button mappings and no ir mappings 
+ *	then no input driver will be registered.
+ */
+struct ubicom32hid_ir {
+	/*
+	 * Input event code (KEY_*, SW_*, etc)
+	 */
+	int		code;
+
+	/*
+	 * Input event type (EV_KEY, EV_SW, etc)
+	 */
+	int		type;
+
+	/*
+	 * The IR code of this button.
+	 */
+	uint32_t	ir_code;
+};
+
+/*
+ * Button mapping to event code.
+ *	If there are no button mappings and no ir mappings 
+ *	then no input driver will be registered.
+ */
+struct ubicom32hid_button {
+	/*
+	 * Input event code (KEY_*, SW_*, etc)
+	 */
+	int		code;
+
+	/*
+	 * Input event type (EV_KEY, EV_SW, etc)
+	 */
+	int		type;
+
+	/*
+	 * Bit number of this button.
+	 */
+	uint8_t		bit;
+};
+
+struct ubicom32hid_platform_data {
+	/*
+	 * Default intensity of the backlight 0-255
+	 */
+	u8_t				default_intensity;
+
+	/*
+	 * GPIO number of the reset line and its polarity.
+	 */
+	unsigned			gpio_reset;
+	int				gpio_reset_polarity;
+
+	/*
+	 * TRUE if the backlight sense is active low. (inverted)
+	 * FALSE if the backlight sense is active high.
+	 */
+	bool				invert;
+
+	/*
+	 * Type of the backlight we are controlling
+	 */
+	enum ubicom32hid_bl_types	type;
+
+	/*
+	 * Optional polling rate for input, in ms, defaults to 100ms
+	 */
+	int				poll_interval;
+	
+	/*
+	 * Optional name to register as input device
+	 */
+	const char			*input_name;
+
+	/*
+	 * Button mapping array
+	 */
+	const struct ubicom32hid_button	*buttons;
+	int				nbuttons;
+
+	/*
+	 * IR mapping array
+	 */
+	const struct ubicom32hid_ir	*ircodes;
+	int				nircodes;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_HID_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32input.h
@@ -0,0 +1,76 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32input.h
+ *   Ubicom32 Input driver, based on gpio-keys
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * TODO: add groups for inputs which can be sampled together
+ */
+
+#ifndef _ASM_UBICOM32_UBICOM32_INPUT_H
+#define _ASM_UBICOM32_UBICOM32_INPUT_H
+
+struct ubicom32input_button {
+	/*
+	 * Input event code (KEY_*, SW_*, etc)
+	 */
+	int		code;
+
+	/*
+	 * Input event type (EV_KEY, EV_SW, etc)
+	 */
+	int		type;
+
+	/*
+	 * GPIO to poll
+	 */
+	int		gpio;
+
+	/*
+	 * 1 for active low, 0 for active high
+	 */
+	int		active_low;
+
+	/*
+	 * Description, used for reserving GPIOs
+	 */
+	const char	*desc;
+};
+
+struct ubicom32input_platform_data {
+	struct ubicom32input_button	*buttons;
+	int				nbuttons;
+
+	/*
+	 * Optional poll interval, in ms, defaults to 50ms
+	 */
+	int				poll_interval;
+
+	/*
+	 * Option Name of this driver
+	 */
+	const char			*name;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_INPUT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32input_i2c.h
@@ -0,0 +1,71 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32input_i2c.h
+ *   Ubicom32 architecture Input driver over I2C platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * TODO: add groups for inputs which can be sampled together
+ */
+
+#ifndef _ASM_UBICOM32_UBICOM32_INPUT_I2C_H
+#define _ASM_UBICOM32_UBICOM32_INPUT_I2C_H
+
+struct ubicom32input_i2c_button {
+	/*
+	 * Input event code (KEY_*, SW_*, etc)
+	 */
+	int		code;
+
+	/*
+	 * Input event type (EV_KEY, EV_SW, etc)
+	 */
+	int		type;
+
+	/*
+	 * Bit number of this button. (0 - ngpio)
+	 */
+	int		bit;
+
+	/*
+	 * 1 for active low, 0 for active high
+	 */
+	int		active_low;
+};
+
+struct ubicom32input_i2c_platform_data {
+	struct ubicom32input_i2c_button	*buttons;
+	int				nbuttons;
+
+	/*
+	 * Optional poll interval, in ms, defaults to 100ms
+	 */
+	int				poll_interval;
+
+	/*
+	 * Option Name of this driver
+	 */
+	const char			*name;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_INPUT_I2C_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32lcd.h
@@ -0,0 +1,39 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32lcd.h
+ *   Ubicom32 architecture LCD driver platform data definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_LCD_H
+#define _ASM_UBICOM32_UBICOM32_LCD_H
+
+struct ubicom32lcd_platform_data {
+	/*
+	 * GPIO and polarity for VGH signal.  A FALSE polarity is active low, TRUE is active high.
+	 */
+	int		vgh_gpio;
+	bool		vgh_polarity;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_LCD_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32ring.h
@@ -0,0 +1,103 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32ring.h
+ * Userspace I/O platform driver for Ubicom32 ring buffers
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _ASM_UBICOM32_UBICOM32RING_H
+#define _ASM_UBICOM32_UBICOM32RING_H
+
+#define UIO_UBICOM32RING_REG_VERSION	2
+
+struct uio_ubicom32ring_desc {
+	volatile unsigned int		head;
+	volatile unsigned int		tail;
+	unsigned int			entries;
+	volatile unsigned int		ring[0];
+};
+
+struct uio_ubicom32ring_regs {
+	unsigned int			version;
+
+	/*
+	 * Magic type used to identify the ring set.  Each driver will
+	 * have a different magic value.
+	 */
+	unsigned int			magic;
+
+	/*
+	 * Registers defined by the driver
+	 */
+	unsigned int			regs_size;
+	void				*regs;
+
+	/*
+	 * The locations of the rings
+	 *
+	 * DO NOT ADD ANYTHING BELOW THIS LINE
+	 */
+	unsigned int			num_rings;
+	struct uio_ubicom32ring_desc	*rings[0];
+};
+
+/*
+ * ringtio_ring_flush
+ */
+static inline void ringtio_ring_flush(struct uio_ubicom32ring_desc *rd)
+{
+	rd->head = rd->tail = 0;
+}
+
+/*
+ * ringtio_ring_get
+ */
+static inline int ringtio_ring_get(struct uio_ubicom32ring_desc *rd, void **val)
+{
+	if (rd->head == rd->tail) {
+		return 0;
+	}
+
+	*val = (void *)rd->ring[rd->head++];
+	if (rd->head == rd->entries) {
+		rd->head = 0;
+	}
+	return 1;
+}
+
+/*
+ * ringtio_ring_put
+ */
+static inline int ringtio_ring_put(struct uio_ubicom32ring_desc *rd, void *val)
+{
+	unsigned int newtail = rd->tail + 1;
+	if (newtail == rd->entries) {
+		newtail = 0;
+	}
+
+	if (newtail == rd->head) {
+		return 0;
+	}
+
+	rd->ring[rd->tail] = (unsigned int)val;
+	rd->tail = newtail;
+	return 1;
+}
+
+#endif /* _ASM_UBICOM32_UBICOM32RING_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32sd.h
@@ -0,0 +1,45 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32sd.h
+ *   Ubicom32SD public include file
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_SD_H
+#define _ASM_UBICOM32_UBICOM32_SD_H
+
+struct ubicom32sd_card {
+	/*
+	 * GPIOs of PWR, WP and CD lines.
+	 * Polarity is 1 for active high and 0 for active low
+	 */
+	int				pin_pwr;
+	bool				pwr_polarity;
+	int				pin_wp;
+	bool				wp_polarity;
+	int				pin_cd;
+	bool				cd_polarity;
+};
+
+struct ubicom32sd_platform_data {
+	int			ncards;
+
+	struct ubicom32sd_card	*cards;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_SD_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32-spi-gpio.h
@@ -0,0 +1,62 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32-spi-gpio.h
+ *   Platform driver data definitions for GPIO based SPI driver.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_SPI_GPIO_H
+#define _ASM_UBICOM32_UBICOM32_SPI_GPIO_H
+
+struct ubicom32_spi_gpio_platform_data {
+	/*
+	 * GPIO to use for MOSI, MISO, CLK
+	 */
+	int	pin_mosi;
+	int	pin_miso;
+	int	pin_clk;
+
+	/*
+	 * Default state of CLK line
+	 */
+	int	clk_default;
+
+	/*
+	 * Number of chip selects on this bus
+	 */
+	int	num_chipselect;
+
+	/*
+	 * The bus number of this chip
+	 */
+	int	bus_num;
+};
+
+struct ubicom32_spi_gpio_controller_data {
+	/*
+	 * GPIO to use for chip select
+	 */
+	int	pin_cs;
+};
+
+#endif /* _ASM_UBICOM32_UBICOM32_SPI_GPIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32suart.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32suart.h
+ *   <TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_SUART_H
+#define _ASM_UBICOM32_UBICOM32_SUART_H
+
+/*
+ * Platform resource id for serdes uart clock parameter
+ */
+#define UBICOM32_SUART_IORESOURCE_CLOCK		(1)
+
+#endif /* _ASM_UBICOM32_UBICOM32_SUART_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ubicom32-tio.h
@@ -0,0 +1,42 @@
+/*
+ * arch/ubicom32/include/asm/ubicom32-tio.h
+ *   Threaded I/O interface definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UBICOM32_TIO_H
+#define _ASM_UBICOM32_UBICOM32_TIO_H
+
+extern u8_t usb_tio_read_u16(u32_t address, u16_t *data);
+extern u8_t usb_tio_read_u8(u32_t address, u8_t *data);
+
+extern u8_t usb_tio_write_u16(u32_t address, u16_t data);
+extern u8_t usb_tio_write_u8(u32_t address, u8_t data);
+
+extern u8_t usb_tio_read_fifo(u32_t address, u32_t buffer, u32_t bytes);
+extern u8_t usb_tio_write_fifo(u32_t address, u32_t buffer, u32_t bytes);
+extern u8_t usb_tio_write_fifo_sync(u32_t address, u32_t buffer, u32_t bytes);
+extern void usb_tio_read_int_status(u8_t *int_usb, u16_t *int_tx, u16_t *int_rx);
+
+#endif /* _ASM_UBICOM32_UBICOM32_TIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/ucontext.h
@@ -0,0 +1,39 @@
+/*
+ * arch/ubicom32/include/asm/ucontext.h
+ *   Definition of ucontext structure for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UCONTEXT_H
+#define _ASM_UBICOM32_UCONTEXT_H
+
+struct ucontext {
+	unsigned long	  uc_flags;
+	struct ucontext  *uc_link;
+	stack_t		  uc_stack;
+	struct sigcontext	  uc_mcontext;
+	sigset_t	  uc_sigmask;	/* mask last for extensibility */
+};
+
+#endif /* _ASM_UBICOM32_UCONTEXT_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/unaligned.h
@@ -0,0 +1,44 @@
+/*
+ * arch/ubicom32/include/asm/unaligned.h
+ *   Ubicom32 architecture unaligned memory access definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * TODO: This is a copy of arm unaligned handling that probably needs
+ * to be optimized for UBICOM32, but it works for now.
+ */
+
+#ifndef _ASM_UBICOM32_UNALIGNED_H
+#define _ASM_UBICOM32_UNALIGNED_H
+
+#include <asm/types.h>
+
+#include <linux/unaligned/le_byteshift.h>
+#include <linux/unaligned/be_byteshift.h>
+#include <linux/unaligned/generic.h>
+
+#define get_unaligned	__get_unaligned_be
+#define put_unaligned	__put_unaligned_be
+
+#endif /* _ASM_UBICOM32_UNALIGNED_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/unistd.h
@@ -0,0 +1,400 @@
+/*
+ * arch/ubicom32/include/asm/unistd.h
+ *   Ubicom32 architecture syscall definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_UNISTD_H
+#define _ASM_UBICOM32_UNISTD_H
+
+/*
+ * This file contains the system call numbers.
+ */
+
+#define __NR_restart_syscall      0
+#define __NR_exit		  1
+#define __NR_fork		  2
+#define __NR_read		  3
+#define __NR_write		  4
+#define __NR_open		  5
+#define __NR_close		  6
+#define __NR_waitpid		  7
+#define __NR_creat		  8
+#define __NR_link		  9
+#define __NR_unlink		 10
+#define __NR_execve		 11
+#define __NR_chdir		 12
+#define __NR_time		 13
+#define __NR_mknod		 14
+#define __NR_chmod		 15
+#define __NR_chown		 16
+#define __NR_break		 17
+#define __NR_oldstat		 18
+#define __NR_lseek		 19
+#define __NR_getpid		 20
+#define __NR_mount		 21
+#define __NR_umount		 22
+#define __NR_setuid		 23
+#define __NR_getuid		 24
+#define __NR_stime		 25
+#define __NR_ptrace		 26
+#define __NR_alarm		 27
+#define __NR_oldfstat		 28
+#define __NR_pause		 29
+#define __NR_utime		 30
+#define __NR_stty		 31
+#define __NR_gtty		 32
+#define __NR_access		 33
+#define __NR_nice		 34
+#define __NR_ftime		 35
+#define __NR_sync		 36
+#define __NR_kill		 37
+#define __NR_rename		 38
+#define __NR_mkdir		 39
+#define __NR_rmdir		 40
+#define __NR_dup		 41
+#define __NR_pipe		 42
+#define __NR_times		 43
+#define __NR_prof		 44
+#define __NR_brk		 45
+#define __NR_setgid		 46
+#define __NR_getgid		 47
+#define __NR_signal		 48
+#define __NR_geteuid		 49
+#define __NR_getegid		 50
+#define __NR_acct		 51
+#define __NR_umount2		 52
+#define __NR_lock		 53
+#define __NR_ioctl		 54
+#define __NR_fcntl		 55
+#define __NR_mpx		 56
+#define __NR_setpgid		 57
+#define __NR_ulimit		 58
+#define __NR_oldolduname	 59
+#define __NR_umask		 60
+#define __NR_chroot		 61
+#define __NR_ustat		 62
+#define __NR_dup2		 63
+#define __NR_getppid		 64
+#define __NR_getpgrp		 65
+#define __NR_setsid		 66
+#define __NR_sigaction		 67
+#define __NR_sgetmask		 68
+#define __NR_ssetmask		 69
+#define __NR_setreuid		 70
+#define __NR_setregid		 71
+#define __NR_sigsuspend		 72
+#define __NR_sigpending		 73
+#define __NR_sethostname	 74
+#define __NR_setrlimit		 75
+#define __NR_getrlimit		 76
+#define __NR_getrusage		 77
+#define __NR_gettimeofday	 78
+#define __NR_settimeofday	 79
+#define __NR_getgroups		 80
+#define __NR_setgroups		 81
+#define __NR_select		 82
+#define __NR_symlink		 83
+#define __NR_oldlstat		 84
+#define __NR_readlink		 85
+#define __NR_uselib		 86
+#define __NR_swapon		 87
+#define __NR_reboot		 88
+#define __NR_readdir		 89
+#define __NR_mmap		 90
+#define __NR_munmap		 91
+#define __NR_truncate		 92
+#define __NR_ftruncate		 93
+#define __NR_fchmod		 94
+#define __NR_fchown		 95
+#define __NR_getpriority	 96
+#define __NR_setpriority	 97
+#define __NR_profil		 98
+#define __NR_statfs		 99
+#define __NR_fstatfs		100
+#define __NR_ioperm		101
+#define __NR_socketcall		102
+#define __NR_syslog		103
+#define __NR_setitimer		104
+#define __NR_getitimer		105
+#define __NR_stat		106
+#define __NR_lstat		107
+#define __NR_fstat		108
+#define __NR_olduname		109
+#define __NR_iopl		/* 110 */ not supported
+#define __NR_vhangup		111
+#define __NR_idle		/* 112 */ Obsolete
+#define __NR_vm86		/* 113 */ not supported
+#define __NR_wait4		114
+#define __NR_swapoff		115
+#define __NR_sysinfo		116
+#define __NR_ipc		117
+#define __NR_fsync		118
+#define __NR_sigreturn		119
+#define __NR_clone		120
+#define __NR_setdomainname	121
+#define __NR_uname		122
+#define __NR_cacheflush		123
+#define __NR_adjtimex		124
+#define __NR_mprotect		125
+#define __NR_sigprocmask	126
+#define __NR_create_module	127
+#define __NR_init_module	128
+#define __NR_delete_module	129
+#define __NR_get_kernel_syms	130
+#define __NR_quotactl		131
+#define __NR_getpgid		132
+#define __NR_fchdir		133
+#define __NR_bdflush		134
+#define __NR_sysfs		135
+#define __NR_personality	136
+#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
+#define __NR_setfsuid		138
+#define __NR_setfsgid		139
+#define __NR__llseek		140
+#define __NR_getdents		141
+#define __NR__newselect		142
+#define __NR_flock		143
+#define __NR_msync		144
+#define __NR_readv		145
+#define __NR_writev		146
+#define __NR_getsid		147
+#define __NR_fdatasync		148
+#define __NR__sysctl		149
+#define __NR_mlock		150
+#define __NR_munlock		151
+#define __NR_mlockall		152
+#define __NR_munlockall		153
+#define __NR_sched_setparam		154
+#define __NR_sched_getparam		155
+#define __NR_sched_setscheduler		156
+#define __NR_sched_getscheduler		157
+#define __NR_sched_yield		158
+#define __NR_sched_get_priority_max	159
+#define __NR_sched_get_priority_min	160
+#define __NR_sched_rr_get_interval	161
+#define __NR_nanosleep		162
+#define __NR_mremap		163
+#define __NR_setresuid		164
+#define __NR_getresuid		165
+#define __NR_getpagesize	166
+#define __NR_query_module	167
+#define __NR_poll		168
+#define __NR_nfsservctl		169
+#define __NR_setresgid		170
+#define __NR_getresgid		171
+#define __NR_prctl		172
+#define __NR_rt_sigreturn	173
+#define __NR_rt_sigaction	174
+#define __NR_rt_sigprocmask	175
+#define __NR_rt_sigpending	176
+#define __NR_rt_sigtimedwait	177
+#define __NR_rt_sigqueueinfo	178
+#define __NR_rt_sigsuspend	179
+#define __NR_pread64		180
+#define __NR_pwrite64		181
+#define __NR_lchown		182
+#define __NR_getcwd		183
+#define __NR_capget		184
+#define __NR_capset		185
+#define __NR_sigaltstack	186
+#define __NR_sendfile		187
+#define __NR_getpmsg		188	/* some people actually want streams */
+#define __NR_putpmsg		189	/* some people actually want streams */
+#define __NR_vfork		190
+#define __NR_ugetrlimit		191
+#define __NR_mmap2		192
+#define __NR_truncate64		193
+#define __NR_ftruncate64	194
+#define __NR_stat64		195
+#define __NR_lstat64		196
+#define __NR_fstat64		197
+#define __NR_chown32		198
+#define __NR_getuid32		199
+#define __NR_getgid32		200
+#define __NR_geteuid32		201
+#define __NR_getegid32		202
+#define __NR_setreuid32		203
+#define __NR_setregid32		204
+#define __NR_getgroups32	205
+#define __NR_setgroups32	206
+#define __NR_fchown32		207
+#define __NR_setresuid32	208
+#define __NR_getresuid32	209
+#define __NR_setresgid32	210
+#define __NR_getresgid32	211
+#define __NR_lchown32		212
+#define __NR_setuid32		213
+#define __NR_setgid32		214
+#define __NR_setfsuid32		215
+#define __NR_setfsgid32		216
+#define __NR_pivot_root		217
+#define __NR_getdents64		220
+#define __NR_gettid		221
+#define __NR_tkill		222
+#define __NR_setxattr		223
+#define __NR_lsetxattr		224
+#define __NR_fsetxattr		225
+#define __NR_getxattr		226
+#define __NR_lgetxattr		227
+#define __NR_fgetxattr		228
+#define __NR_listxattr		229
+#define __NR_llistxattr		230
+#define __NR_flistxattr		231
+#define __NR_removexattr	232
+#define __NR_lremovexattr	233
+#define __NR_fremovexattr	234
+#define __NR_futex		235
+#define __NR_sendfile64		236
+#define __NR_mincore		237
+#define __NR_madvise		238
+#define __NR_fcntl64		239
+#define __NR_readahead		240
+#define __NR_io_setup		241
+#define __NR_io_destroy		242
+#define __NR_io_getevents	243
+#define __NR_io_submit		244
+#define __NR_io_cancel		245
+#define __NR_fadvise64		246
+#define __NR_exit_group		247
+#define __NR_lookup_dcookie	248
+#define __NR_epoll_create	249
+#define __NR_epoll_ctl		250
+#define __NR_epoll_wait		251
+#define __NR_remap_file_pages	252
+#define __NR_set_tid_address	253
+#define __NR_timer_create	254
+#define __NR_timer_settime	255
+#define __NR_timer_gettime	256
+#define __NR_timer_getoverrun	257
+#define __NR_timer_delete	258
+#define __NR_clock_settime	259
+#define __NR_clock_gettime	260
+#define __NR_clock_getres	261
+#define __NR_clock_nanosleep	262
+#define __NR_statfs64		263
+#define __NR_fstatfs64		264
+#define __NR_tgkill		265
+#define __NR_utimes		266
+#define __NR_fadvise64_64	267
+#define __NR_mbind		268
+#define __NR_get_mempolicy	269
+#define __NR_set_mempolicy	270
+#define __NR_mq_open		271
+#define __NR_mq_unlink		272
+#define __NR_mq_timedsend	273
+#define __NR_mq_timedreceive	274
+#define __NR_mq_notify		275
+#define __NR_mq_getsetattr	276
+#define __NR_waitid		277
+#define __NR_vserver		278
+#define __NR_add_key		279
+#define __NR_request_key	280
+#define __NR_keyctl		281
+#define __NR_ioprio_set		282
+#define __NR_ioprio_get		283
+#define __NR_inotify_init	284
+#define __NR_inotify_add_watch	285
+#define __NR_inotify_rm_watch	286
+#define __NR_migrate_pages	287
+#define __NR_openat		288
+#define __NR_mkdirat		289
+#define __NR_mknodat		290
+#define __NR_fchownat		291
+#define __NR_futimesat		292
+#define __NR_fstatat64		293
+#define __NR_unlinkat		294
+#define __NR_renameat		295
+#define __NR_linkat		296
+#define __NR_symlinkat		297
+#define __NR_readlinkat		298
+#define __NR_fchmodat		299
+#define __NR_faccessat		300
+#define __NR_pselect6		301
+#define __NR_ppoll		302
+#define __NR_unshare		303
+#define __NR_set_robust_list	304
+#define __NR_get_robust_list	305
+#define __NR_splice		306
+#define __NR_sync_file_range	307
+#define __NR_tee		308
+#define __NR_vmsplice		309
+#define __NR_move_pages		310
+#define __NR_sched_setaffinity	311
+#define __NR_sched_getaffinity	312
+#define __NR_kexec_load		313
+#define __NR_getcpu		314
+#define __NR_epoll_pwait	315
+#define __NR_utimensat		316
+#define __NR_signalfd		317
+#define __NR_timerfd_create	318
+#define __NR_eventfd		319
+#define __NR_fallocate		320
+#define __NR_timerfd_settime	321
+#define __NR_timerfd_gettime	322
+#define __NR_signalfd4		323
+#define __NR_eventfd2		324
+#define __NR_epoll_create1	325
+#define __NR_dup3		326
+#define __NR_pipe2		327
+#define __NR_inotify_init1	328
+
+#ifdef __KERNEL__
+
+#define NR_syscalls		329
+
+#define __ARCH_WANT_IPC_PARSE_VERSION
+#define __ARCH_WANT_OLD_READDIR
+#define __ARCH_WANT_OLD_STAT
+#define __ARCH_WANT_STAT64
+#define __ARCH_WANT_SYS_ALARM
+#define __ARCH_WANT_SYS_GETHOSTNAME
+#define __ARCH_WANT_SYS_PAUSE
+#define __ARCH_WANT_SYS_SGETMASK
+#define __ARCH_WANT_SYS_SIGNAL
+#define __ARCH_WANT_SYS_TIME
+#define __ARCH_WANT_SYS_UTIME
+#define __ARCH_WANT_SYS_WAITPID
+#define __ARCH_WANT_SYS_SOCKETCALL
+#define __ARCH_WANT_SYS_FADVISE64
+#define __ARCH_WANT_SYS_GETPGRP
+#define __ARCH_WANT_SYS_LLSEEK
+#define __ARCH_WANT_SYS_NICE
+#define __ARCH_WANT_SYS_OLD_GETRLIMIT
+#define __ARCH_WANT_SYS_OLDUMOUNT
+#define __ARCH_WANT_SYS_SIGPENDING
+#define __ARCH_WANT_SYS_SIGPROCMASK
+#define __ARCH_WANT_SYS_RT_SIGACTION
+
+/*
+ * "Conditional" syscalls
+ *
+ * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
+ * but it doesn't work on all toolchains, so we just do it by hand
+ */
+//#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
+#define cond_syscall(x) long x(void)  __attribute__((weak,alias("sys_ni_syscall")))
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_UBICOM32_UNISTD_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/user.h
@@ -0,0 +1,82 @@
+/*
+ * arch/ubicom32/include/asm/user.h
+ *   Ubicom32 architecture core file definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_USER_H
+#define _ASM_UBICOM32_USER_H
+
+#include <asm/ptrace.h>
+#include <asm/page.h>
+/*
+ * Adapted from <asm-powerpc/user.h>
+ *
+ * Core file format: The core file is written in such a way that gdb
+ * can understand it and provide useful information to the user (under
+ * linux we use the `trad-core' bfd, NOT the osf-core).  The file contents
+ * are as follows:
+ *
+ *  upage: 1 page consisting of a user struct that tells gdb
+ *	what is present in the file.  Directly after this is a
+ *	copy of the task_struct, which is currently not used by gdb,
+ *	but it may come in handy at some point.  All of the registers
+ *	are stored as part of the upage.  The upage should always be
+ *	only one page long.
+ *  data: The data segment follows next.  We use current->end_text to
+ *	current->brk to pick up all of the user variables, plus any memory
+ *	that may have been sbrk'ed.  No attempt is made to determine if a
+ *	page is demand-zero or if a page is totally unused, we just cover
+ *	the entire range.  All of the addresses are rounded in such a way
+ *	that an integral number of pages is written.
+ *  stack: We need the stack information in order to get a meaningful
+ *	backtrace.  We need to write the data from usp to
+ *	current->start_stack, so we round each of these in order to be able
+ *	to write an integer number of pages.
+ */
+
+struct user_ubicom32fp_struct {
+};
+
+struct user {
+	struct pt_regs	regs;			/* entire machine state */
+	size_t		u_tsize;		/* text size (pages) */
+	size_t		u_dsize;		/* data size (pages) */
+	size_t		u_ssize;		/* stack size (pages) */
+	unsigned long	start_code;		/* text starting address */
+	unsigned long	start_data;		/* data starting address */
+	unsigned long	start_stack;		/* stack starting address */
+	long int	signal;			/* signal causing core dump */
+	unsigned long	u_ar0;			/* help gdb find registers */
+	unsigned long	magic;			/* identifies a core file */
+	char		u_comm[32];		/* user command name */
+};
+
+#define NBPG			PAGE_SIZE
+#define UPAGES			1
+#define HOST_TEXT_START_ADDR	(u.start_code)
+#define HOST_DATA_START_ADDR	(u.start_data)
+#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
+
+#endif	/* _ASM_UBICOM32_USER_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/vdc_tio.h
@@ -0,0 +1,129 @@
+/*
+ * arch/ubicom32/include/asm/vdc_tio.h
+ *   Ubicom32 architecture VDC TIO definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_VDC_TIO_H
+#define _ASM_UBICOM32_VDC_TIO_H
+
+#include <asm/devtree.h>
+
+#define VDCTIO_VP_VERSION			5
+
+#define VDCTIO_SCALE_FLAG_VSUB			(1 << 9)
+#define VDCTIO_SCALE_FLAG_YUV_SCAN_ORDER	(1 << 8)
+#define VDCTIO_SCALE_FLAG_YUV_BLOCK_ORDER	(1 << 7)
+#define VDCTIO_SCALE_FLAG_YUV			(1 << 6)
+#define VDCTIO_SCALE_FLAG_VRANGE_16_255		(1 << 5)
+#define VDCTIO_SCALE_FLAG_VRANGE_0_255		(1 << 4)
+#define VDCTIO_SCALE_FLAG_HSUB_2_1		(1 << 3)
+#define VDCTIO_SCALE_FLAG_HSUB_1_1		(1 << 2)
+#define VDCTIO_SCALE_FLAG_SET_FRAME_BUFFER	(1 << 1)
+#define VDCTIO_SCALE_FLAG_ENABLE		(1 << 0)
+
+#define VDCTIO_NEXT_FRAME_FLAG_YUV_BIT		0
+#define VDCTIO_NEXT_FRAME_FLAG_YUV		(1 << (VDCTIO_NEXT_FRAME_FLAG_YUV_BIT))
+
+#define VDCTIO_CAPS_SUPPORTS_SCALING		(1 << 0)
+
+#define VDCTIO_COMMAND_START			(1 << 3)
+#define VDCTIO_COMMAND_SET_COEFF		(1 << 2)
+#define VDCTIO_COMMAND_SET_LUT			(1 << 1)
+#define VDCTIO_COMMAND_SET_SCALE_MODE		(1 << 0)
+
+/*
+ * Command / Data registers to access the VDC
+ */
+struct vdc_tio_vp_regs {
+	/*
+	 * Version of this TIO register map
+	 */
+	u32_t		version;
+
+	volatile u32_t	command;
+
+	/*
+	 * Next frame pointer, when the command VDCTIO_COMMAND_SET_FRAME_BUFFER is set,
+	 * the vdc will take the pointer here and display it.
+	 */
+	void		*next_frame;
+	u32_t		next_frame_flags;
+
+	/*
+	 * These map directly into the PIXP registers 0x20-0x80.  
+	 * DO NOT change the order of these three variables.
+	 */
+	u32_t		red_lut[6];
+	u32_t		blue_lut[6];
+	u32_t		green_lut[13];
+
+	/*
+	 * These map directly into the PIXP registers 0x04, 0x08
+	 */
+	u32_t		coeff0;
+	u32_t		coeff1;
+
+	/*
+	 * There are used to set the scaling parameters
+	 */
+	u32_t		x_in;
+	u32_t		x_out;
+	u32_t		y_in;
+	u32_t		y_out;
+	u32_t		scale_flags;
+
+	/*
+	 * Current frame number, monotonically increasing number
+	 */
+	u32_t		frame_number;
+
+	/*
+	 * These variables tell the guest OS what the underlying hardware looks like
+	 */
+	u32_t		caps;
+	u32_t		xres;
+	u32_t		yres;
+	u32_t		fb_align;
+	u8_t		bpp;
+	u8_t		rbits;
+	u8_t		gbits;
+	u8_t		bbits;
+	u8_t		rshift;
+	u8_t		gshift;
+	u8_t		bshift;
+};
+
+/*
+ * Devtree node for VDC
+ */
+struct vdc_tio_node {
+	struct devtree_node	dn;
+
+	struct vdc_tio_vp_regs	*regs;
+};
+
+extern void vdc_tio_init(void);
+
+#endif /* _ASM_UBICOM32_VDC_TIO_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/vga.h
@@ -0,0 +1,71 @@
+/*
+ * arch/ubicom32/include/asm/vga.h
+ *   Ubicom32 low level  VGA/frame buffer definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * (c) 1998 Martin Mares <mj@ucw.cz>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#ifndef _ASM_UBICOM32_VGA_H
+#define _ASM_UBICOM32_VGA_H
+
+#include <asm/byteorder.h>
+
+/*
+ *	On the PC, we can just recalculate addresses and then
+ *	access the videoram directly without any black magic.
+ */
+
+#define VGA_MAP_MEM(x, s)	(0xb0000000L + (unsigned long)(x))
+
+#define vga_readb(x)	(*(x))
+#define vga_writeb(x, y)	(*(y) = (x))
+
+#define VT_BUF_HAVE_RW
+/*
+ *  These are only needed for supporting VGA or MDA text mode, which use little
+ *  endian byte ordering.
+ *  In other cases, we can optimize by using native byte ordering and
+ *  <linux/vt_buffer.h> has already done the right job for us.
+ */
+
+#undef scr_writew
+#undef scr_readw
+
+static inline void scr_writew(u16 val, volatile u16 *addr)
+{
+	*addr = cpu_to_le16(val);
+}
+
+static inline u16 scr_readw(volatile const u16 *addr)
+{
+	return le16_to_cpu(*addr);
+}
+
+#define scr_memcpyw(d, s, c) memcpy(d, s, c)
+#define scr_memmovew(d, s, c) memmove(d, s, c)
+#define VT_BUF_HAVE_MEMCPYW
+#define VT_BUF_HAVE_MEMMOVEW
+
+#endif /* _ASM_UBICOM32_VGA_H */
--- /dev/null
+++ b/arch/ubicom32/include/asm/xor.h
@@ -0,0 +1,33 @@
+/*
+ * arch/ubicom32/include/asm/xor.h
+ *   Generic xor.h definitions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _ASM_UBICOM32_XOR_H
+#define _ASM_UBICOM32_XOR_H
+
+#include <asm-generic/xor.h>
+
+#endif /* _ASM_UBICOM32_XOR_H */
--- /dev/null
+++ b/arch/ubicom32/Kconfig
@@ -0,0 +1,455 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+mainmenu "uClinux/ubicom32 (w/o MMU) Kernel Configuration"
+
+config RAMBASE
+	hex
+	default "0x40000000"
+	help
+		Define the address that RAM starts at.
+
+config UBICOM32
+	bool
+	select HAVE_OPROFILE
+	default y
+
+config RAMKERNEL
+	bool
+	default y
+
+config CPU_BIG_ENDIAN
+	bool
+	default y
+
+config FORCE_MAX_ZONEORDER
+	int
+	default "14"
+
+config HAVE_CLK
+	bool
+	default y
+
+config MMU
+	bool
+	default n
+
+config FPU
+	bool
+	default n
+
+config ZONE_DMA
+	bool
+	default y
+
+config RWSEM_GENERIC_SPINLOCK
+	bool
+	default y
+
+config RWSEM_XCHGADD_ALGORITHM
+	bool
+	default n
+
+config ARCH_HAS_ILOG2_U32
+	bool
+	default n
+
+config ARCH_HAS_ILOG2_U64
+	bool
+	default n
+
+config GENERIC_FIND_NEXT_BIT
+	bool
+	default y
+
+config GENERIC_GPIO
+	bool
+	default y
+
+config GPIOLIB
+	bool
+	default y
+
+config GENERIC_HWEIGHT
+	bool
+	default y
+
+config GENERIC_HARDIRQS
+	bool
+	default y
+
+config STACKTRACE_SUPPORT
+	bool
+	default y
+
+config LOCKDEP_SUPPORT
+	bool
+	default y
+
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
+config GENERIC_TIME
+	bool
+	default y
+
+config TIME_LOW_RES
+	bool
+	default y
+
+config GENERIC_CLOCKEVENTS
+	bool
+	default y
+
+config GENERIC_CLOCKEVENTS_BROADCAST
+	bool
+	depends on GENERIC_CLOCKEVENTS
+	default y if SMP && !LOCAL_TIMERS
+
+config NO_IOPORT
+	def_bool y
+
+config ARCH_SUPPORTS_AOUT
+	def_bool y
+
+config IRQ_PER_CPU
+	bool
+	default y
+
+config SCHED_NO_NO_OMIT_FRAME_POINTER
+	bool
+	default y
+
+menu "Processor type and features"
+
+config BRD_32MB
+	bool
+	depends on IP5160EVAL
+	help
+		Board has 32MB of RAM on it.  It is a hidden option used to select default for size of RAM
+	default n
+
+config BRD_64MB
+	bool
+	depends on IP7145DPF || IP7160RGW || IP7160BRINGUP || IP7160DPF || IP5170DPF || IP5160DEV
+	help
+		Board has 64MB of RAM on it.  It is a hidden option used to select default for size of RAM
+	default n
+
+config BRD_128MB
+	bool
+	depends on IP7500MODULE || IP7500AV || IP7500MEDIA
+	help
+		Board has 128MB of RAM on it.  It is a hidden option used to select default for size of RAM
+	default n
+
+comment "Processor type will be selected by Board"
+
+config UBICOM32_V3
+	bool
+	help
+	  Ubicom IP5xxx series processor support.
+
+config UBICOM32_V4
+	bool
+	help
+	  Ubicom IP7xxx series processor support.
+
+comment "Board"
+choice
+	prompt "Board type"
+	help
+		Select your board.
+
+config NOBOARD
+	bool "No board selected"
+	help
+		Default. Don't select any board specific config. Will not build unless you change!
+
+# Add your boards here
+source "arch/ubicom32/mach-ip5k/Kconfig"
+source "arch/ubicom32/mach-ip7k/Kconfig"
+
+endchoice
+
+comment "Kernel Options"
+config SMP
+	bool "Symmetric multi-processing support"
+	select USE_GENERIC_SMP_HELPERS
+	default n
+	help
+	  Enables multithreading support.  Enabling SMP support increases
+	  the size of system data structures.  SMP support can have either 
+	  positive or negative impact on performance depending on workloads. 
+
+	  If you do not know what to do here, say N.
+
+config NR_CPUS
+	int "Number of configured CPUs"
+	range 2 32
+	default 2
+	depends on SMP
+	help
+		Upper bound on the number of CPUs. Space is reserved 
+		at compile time for this many CPUs.
+		
+config LOCAL_TIMERS
+	bool "Use local timer interrupts"
+	depends on SMP
+	default y
+	help
+	  Enable support for local timers on SMP platforms, rather then the
+	  legacy IPI broadcast method.  Local timers allows the system
+	  accounting to be spread across the timer interval, preventing a
+	  "thundering herd" at every timer tick.  A physical timer is allocated
+	  per cpu.		
+
+config TIMER_EXTRA_ALLOC
+	int "Number of additional physical timer events to create"
+	depends on GENERIC_CLOCKEVENTS
+	default 0
+	help
+		The Ubicom32 processor has a number of event timers that can be wrapped
+		in Linux clock event structures (assuming that the timers are not being
+		used for another purpose).  Based on the value of LOCAL_TIMERS, either 
+		2 timers will be used or a timer will be used for every CPU.  This value
+		allows the programmer to select additional timers over that amount.
+			
+config IRQSTACKS
+	bool "Create separate stacks for interrupt handling"
+	default n
+	help
+		Selecting this causes interrupts to be created on a separate
+		stack instead of nesting the interrupts on the kernel stack.
+		
+config IRQSTACKS_USEOCM
+	bool "Use OCM for interrupt stacks"
+	default n
+	depends on IRQSTACKS
+	help
+		Selecting this cause the interrupt stacks to be placed in OCM
+		reducing cache misses at the expense of using the OCM for servicing
+		interrupts.
+
+menu "OCM Instruction Heap"
+
+config OCM_MODULES_RESERVATION
+	int "OCM Instruction heap reservation. 0-192 kB"
+	range 0 192
+	default "0"
+	help
+	  The minimum amount of OCM memory to reserve for kernel loadable module
+	  code. If you are not using this memory it cannot be used for anything
+	  else. Leave it as 0 if you have prebuilt modules that are compiled with
+	  OCM support.
+
+config OCM_MODULES_MAY_CONSUME_REMAINING_CODESPACE
+	bool "Give all unused ocm code space to the ocm instruction heap."
+	default n
+	help
+	  Allow the OCM instruction heap allocation to consume any remaining
+	  unused OCM code space.  The result of this is that you will not have
+	  and deterministic results, but you will not have any waste either.
+
+config OCM_MODULES_FALLBACK_TO_DDR
+	bool "Loadable Modules requiring OCM may fallback to use DDR."
+	default n
+	help
+	  If a module cannot get the OCM code it requires allow DDR to
+	  be used instead.
+endmenu
+
+config HZ
+	int "Frequency of 'jiffies' (for polling)"
+	default 1000
+	help
+		100 is common for embedded systems, but 1000 allows
+		you to do more drivers without actually having
+		interrupts working properly.
+
+comment "RAM configuration"
+
+if BRD_32MB
+
+config RAMSIZE
+	hex "Size of RAM (in bytes)"
+	range 0x00000000 0x02000000
+	default "0x02000000"
+	help
+		Define the size of the system RAM. If you select 0 then the
+		kernel will try to probe the RAM size at runtime. This is not
+		supported on all CPU types.
+
+endif
+
+if BRD_64MB
+
+config RAMSIZE
+	hex "Size of RAM (in bytes)"
+	range 0x00000000 0x04000000
+	default "0x04000000"
+	help
+		Define the size of the system RAM. If you select 0 then the
+		kernel will try to probe the RAM size at runtime. This is not
+		supported on all CPU types.
+
+endif
+
+if BRD_128MB
+
+config RAMSIZE
+	hex "Size of RAM (in bytes)"
+	range 0x00000000 0x08000000
+	default "0x08000000"
+	help
+		Define the size of the system RAM. If you select 0 then the
+		kernel will try to probe the RAM size at runtime. This is not
+		supported on all CPU types.
+
+endif
+
+config KERNELBASE
+	hex "Address of the base of kernel code"
+	default "0x40400000"
+	help
+		For the time being we are going to start the Kernel at a 4 meg offset.
+
+comment "Build options"
+config LINKER_RELAXATION
+	bool "Linker Relaxation"
+	default y
+	help
+	  Turns on linker relaxation that will produce smaller
+	  faster code. Increases link time.
+
+comment "Driver options"
+menu "PCI Bus"
+config PCI
+	bool "PCI bus"
+	default true
+	help
+	  Enable/Disable PCI bus
+	source "drivers/pci/Kconfig"
+
+
+config PCI_DEV0_IDSEL
+	hex "slot 0 address"
+	depends on PCI
+	default "0x01000000"
+	help
+	  Slot 0 address.  This address should correspond to the address line
+	  which the IDSEL bit for this slot is connected to.
+
+config PCI_DEV1_IDSEL
+	hex "slot 1 address"
+	depends on PCI
+	default "0x02000000"
+	help
+	  Slot 1 address.  This address should correspond to the address line
+	  which the IDSEL bit for this slot is connected to.
+endmenu
+# End PCI
+
+menu "Input devices"
+config UBICOM_INPUT
+	bool "Ubicom polled GPIO input driver"
+	select INPUT
+	select INPUT_POLLDEV
+	help
+		Polling input driver, much like the GPIO input driver, except that it doesn't
+		rely on interrupts.  It will report events via the input subsystem.
+	default n
+
+config UBICOM_INPUT_I2C
+	bool "Ubicom polled GPIO input driver over I2C"
+	select INPUT
+	select INPUT_POLLDEV
+	help
+		Polling input driver, much like the PCA953x driver, it can support a variety of
+		different I2C I/O expanders.  This device polls the I2C I/O expander for events
+		and reports them via the input subsystem.
+	default n
+endmenu
+# Input devices
+
+menu "Misc devices"
+config UBICOM_HID
+	bool "Ubicom HID driver"
+	select INPUT
+	select INPUT_POLLDEV
+	select LCD_CLASS_DEVICE
+	help
+		Driver for HID chip found on some Ubicom reference designs.  This chip handles
+		PWM, button input, and IR remote control.  It registers as an input device and
+		a backlight device.
+	default n
+endmenu
+# Misc devices
+
+config CMDLINE_BOOL
+	bool "Built-in kernel command line"
+	default n
+	help
+	  Allow for specifying boot arguments to the kernel at
+	  build time.  On some systems (e.g. embedded ones), it is
+	  necessary or convenient to provide some or all of the
+	  kernel boot arguments with the kernel itself (that is,
+	  to not rely on the boot loader to provide them.)
+
+	  To compile command line arguments into the kernel,
+	  set this option to 'Y', then fill in the
+	  the boot arguments in CONFIG_CMDLINE.
+
+	  Systems with fully functional boot loaders (i.e. non-embedded)
+	  should leave this option set to 'N'.
+
+config CMDLINE
+	string "Built-in kernel command string"
+	depends on CMDLINE_BOOL
+	default ""
+	help
+	  Enter arguments here that should be compiled into the kernel
+	  image and used at boot time.  If the boot loader provides a
+	  command line at boot time, it is appended to this string to
+	  form the full kernel command line, when the system boots.
+
+	  However, you can use the CONFIG_CMDLINE_OVERRIDE option to
+	  change this behavior.
+
+	  In most cases, the command line (whether built-in or provided
+	  by the boot loader) should specify the device for the root
+	  file system.
+
+config CMDLINE_OVERRIDE
+	bool "Built-in command line overrides boot loader arguments"
+	default n
+	depends on CMDLINE_BOOL
+	help
+	  Set this option to 'Y' to have the kernel ignore the boot loader
+	  command line, and use ONLY the built-in command line.
+
+	  This is used to work around broken boot loaders.  This should
+	  be set to 'N' under normal conditions.
+
+endmenu
+# End Processor type and features
+
+source "arch/ubicom32/Kconfig.debug"
+
+menu "Executable file formats"
+source "fs/Kconfig.binfmt"
+endmenu
+
+source "init/Kconfig"
+source "kernel/Kconfig.preempt"
+source "kernel/time/Kconfig"
+source "mm/Kconfig"
+source "net/Kconfig"
+source "drivers/Kconfig"
+source "fs/Kconfig"
+source "security/Kconfig"
+source "crypto/Kconfig"
+source "lib/Kconfig"
--- /dev/null
+++ b/arch/ubicom32/Kconfig.debug
@@ -0,0 +1,117 @@
+menu "Kernel hacking"
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+	
+config PROTECT_KERNEL
+	default y
+	bool 'Enable Kernel range register Protection'
+	help
+	  Adds code to enable/disable range registers to protect static
+	  kernel code/data from userspace.  Currently the ranges covered
+	  do no protect kernel loadable modules or dynamically allocated
+	  kernel data.
+
+config NO_KERNEL_MSG
+	bool "Suppress Kernel BUG Messages"
+	help
+	  Do not output any debug BUG messages within the kernel.
+
+config EARLY_PRINTK
+	bool "Use the driver that you selected as console also for early printk (to debug kernel bootup)."
+	default n
+	help
+	  If you want to use the serdes driver (console=ttyUS0) for
+	  early printk, you must also supply an additional kernel boot
+	  parameter like this:
+
+		serdes=ioportaddr,irq,clockrate,baud
+
+	  For an IP7160RGW eval board, you could use this:
+
+		serdes=0x2004000,61,250000000,57600
+
+	  which will let you see early printk output at 57600 baud.
+
+config STOP_ON_TRAP
+	bool "Enable stopping at the LDSR for all traps"
+	default n
+	help
+	Cause the LDSR to stop all threads whenever a trap is about to be serviced
+	
+config STOP_ON_BUG
+	bool "Enable stopping on failed BUG_ON()"
+	default n
+	help
+	Cause all BUG_ON failures to stop all threads
+	
+config DEBUG_IRQMEASURE
+	bool "Enable IRQ handler measurements"
+	default n
+	help
+	When enabled each IRQ's min/avg/max times will be printed.  If the handler
+	re-enables interrupt, the times will show the full time including to service
+	nested interrupts.  See /proc/irq_measurements.
+	
+config DEBUG_PCIMEASURE
+	bool "Enable PCI transaction measurements"
+	default n
+	help
+	When enabled the system will measure the min/avg/max timer for each PCI transactions.
+	See /proc/pci_measurements.
+
+config ACCESS_OK_CHECKS_ENABLED
+	bool "Enable user space access checks"
+	default n
+	help
+	Enabling this check causes the kernel to verify that addresses passed
+	to the kernel by the user space code are within the processes 
+	address space.  On a no-mmu system, this is done by examining the
+	processes memory data structures (adversly affecting performance) but
+	ensuring that a process does not ask the kernel to violate another 
+	processes address space.  Sadly, the kernel uses access_ok() for 
+	address that are in the kernel which results in a large volume of 
+	false positives.
+
+choice
+	prompt "Unaligned Access Support"
+	default UNALIGNED_ACCESS_ENABLED
+	help
+		Kernel / Userspace unaligned access handling.
+
+config  UNALIGNED_ACCESS_ENABLED
+	bool "Kernel and Userspace"
+	help
+
+config  UNALIGNED_ACCESS_USERSPACE_ONLY
+	bool "Userspace Only"
+	help
+
+config  UNALIGNED_ACCESS_DISABLED
+	bool "Disabled"
+	help
+
+endchoice
+
+config DEBUG_STACKOVERFLOW
+	bool "Check for stack overflows"
+	default n
+	depends on DEBUG_KERNEL
+	help
+	  This option will cause messages to be printed if free kernel stack space
+	  drops below a certain limit (THREAD_SIZE /8).
+
+config DEBUG_STACK_USAGE
+	bool "Stack utilization instrumentation"
+	default n
+	depends on DEBUG_KERNEL
+	help
+	  Enables the display of the minimum amount of free kernel stack which each
+	  task has ever had available in the sysrq-T and sysrq-P debug output.
+
+	  This option will slow down process creation somewhat.
+
+source "lib/Kconfig.debug"
+
+endmenu
+
--- /dev/null
+++ b/arch/ubicom32/kernel/asm-offsets.c
@@ -0,0 +1,162 @@
+/*
+ * arch/ubicom32/kernel/asm-offsets.c
+ *   Ubicom32 architecture definitions needed by assembly language modules.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ * This program is used to generate definitions needed by
+ * assembly language modules.
+ *
+ * We use the technique used in the OSF Mach kernel code:
+ * generate asm statements containing #defines,
+ * compile this file to assembler, and then extract the
+ * #defines from the assembly-language output.
+ */
+
+#include <linux/module.h>
+#include <linux/stddef.h>
+#include <linux/sched.h>
+#include <linux/kernel_stat.h>
+#include <linux/ptrace.h>
+#include <linux/hardirq.h>
+#include <asm/bootinfo.h>
+#include <asm/irq.h>
+#include <asm/thread_info.h>
+
+#define DEFINE(sym, val) \
+        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+int main(void)
+{
+	/* offsets into the task struct */
+	DEFINE(TASK_STATE, offsetof(struct task_struct, state));
+	DEFINE(TASK_FLAGS, offsetof(struct task_struct, flags));
+	DEFINE(TASK_PTRACE, offsetof(struct task_struct, ptrace));
+	DEFINE(TASK_BLOCKED, offsetof(struct task_struct, blocked));
+	DEFINE(TASK_THREAD, offsetof(struct task_struct, thread));
+	DEFINE(TASK_THREAD_INFO, offsetof(struct task_struct, stack));
+	DEFINE(TASK_MM, offsetof(struct task_struct, mm));
+	DEFINE(TASK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
+
+	/* offsets into the kernel_stat struct */
+	DEFINE(STAT_IRQ, offsetof(struct kernel_stat, irqs));
+
+	/* offsets into the irq_cpustat_t struct */
+	DEFINE(CPUSTAT_SOFTIRQ_PENDING, offsetof(irq_cpustat_t, __softirq_pending));
+
+	/* offsets into the thread struct */
+	DEFINE(THREAD_D10, offsetof(struct thread_struct, d10));
+	DEFINE(THREAD_D11, offsetof(struct thread_struct, d11));
+	DEFINE(THREAD_D12, offsetof(struct thread_struct, d12));
+	DEFINE(THREAD_D13, offsetof(struct thread_struct, d13));
+	DEFINE(THREAD_A1, offsetof(struct thread_struct, a1));
+	DEFINE(THREAD_A2, offsetof(struct thread_struct, a2));
+	DEFINE(THREAD_A5, offsetof(struct thread_struct, a5));
+	DEFINE(THREAD_A6, offsetof(struct thread_struct, a6));
+	DEFINE(THREAD_SP, offsetof(struct thread_struct, sp));
+
+	/* offsets into the pt_regs */
+	DEFINE(PT_D0, offsetof(struct pt_regs, dn[0]));
+	DEFINE(PT_D1, offsetof(struct pt_regs, dn[1]));
+	DEFINE(PT_D2, offsetof(struct pt_regs, dn[2]));
+	DEFINE(PT_D3, offsetof(struct pt_regs, dn[3]));
+	DEFINE(PT_D4, offsetof(struct pt_regs, dn[4]));
+	DEFINE(PT_D5, offsetof(struct pt_regs, dn[5]));
+	DEFINE(PT_D6, offsetof(struct pt_regs, dn[6]));
+	DEFINE(PT_D7, offsetof(struct pt_regs, dn[7]));
+	DEFINE(PT_D8, offsetof(struct pt_regs, dn[8]));
+	DEFINE(PT_D9, offsetof(struct pt_regs, dn[9]));
+	DEFINE(PT_D10, offsetof(struct pt_regs, dn[10]));
+	DEFINE(PT_D11, offsetof(struct pt_regs, dn[11]));
+	DEFINE(PT_D12, offsetof(struct pt_regs, dn[12]));
+	DEFINE(PT_D13, offsetof(struct pt_regs, dn[13]));
+	DEFINE(PT_D14, offsetof(struct pt_regs, dn[14]));
+	DEFINE(PT_D15, offsetof(struct pt_regs, dn[15]));
+	DEFINE(PT_A0, offsetof(struct pt_regs, an[0]));
+	DEFINE(PT_A1, offsetof(struct pt_regs, an[1]));
+	DEFINE(PT_A2, offsetof(struct pt_regs, an[2]));
+	DEFINE(PT_A3, offsetof(struct pt_regs, an[3]));
+	DEFINE(PT_A4, offsetof(struct pt_regs, an[4]));
+	DEFINE(PT_A5, offsetof(struct pt_regs, an[5]));
+	DEFINE(PT_A6, offsetof(struct pt_regs, an[6]));
+	DEFINE(PT_A7, offsetof(struct pt_regs, an[7]));
+	DEFINE(PT_SP, offsetof(struct pt_regs, an[7]));
+
+	DEFINE(PT_ACC0HI, offsetof(struct pt_regs, acc0[0]));
+	DEFINE(PT_ACC0LO, offsetof(struct pt_regs, acc0[1]));
+	DEFINE(PT_MAC_RC16, offsetof(struct pt_regs, mac_rc16));
+
+	DEFINE(PT_ACC1HI, offsetof(struct pt_regs, acc1[0]));
+	DEFINE(PT_ACC1LO, offsetof(struct pt_regs, acc1[1]));
+
+	DEFINE(PT_SOURCE3, offsetof(struct pt_regs, source3));
+	DEFINE(PT_INST_CNT, offsetof(struct pt_regs, inst_cnt));
+	DEFINE(PT_CSR, offsetof(struct pt_regs, csr));
+	DEFINE(PT_DUMMY_UNUSED, offsetof(struct pt_regs, dummy_unused));
+
+	DEFINE(PT_INT_MASK0, offsetof(struct pt_regs, int_mask0));
+	DEFINE(PT_INT_MASK1, offsetof(struct pt_regs, int_mask1));
+
+	DEFINE(PT_PC, offsetof(struct pt_regs, pc));
+
+	DEFINE(PT_TRAP_CAUSE, offsetof(struct pt_regs, trap_cause));
+
+	DEFINE(PT_SIZE, sizeof(struct pt_regs));
+
+	DEFINE(PT_FRAME_TYPE, offsetof(struct pt_regs, frame_type));
+
+	DEFINE(PT_ORIGINAL_D0, offsetof(struct pt_regs, original_dn_0));
+	DEFINE(PT_PREVIOUS_PC, offsetof(struct pt_regs, previous_pc));
+
+	/* offsets into the kernel_stat struct */
+	DEFINE(STAT_IRQ, offsetof(struct kernel_stat, irqs));
+
+	/* signal defines */
+	DEFINE(SIGSEGV, SIGSEGV);
+	//DEFINE(SEGV_MAPERR, SEGV_MAPERR);
+	DEFINE(SIGTRAP, SIGTRAP);
+	//DEFINE(TRAP_TRACE, TRAP_TRACE);
+
+	DEFINE(PT_PTRACED, PT_PTRACED);
+	DEFINE(PT_DTRACE, PT_DTRACE);
+
+	DEFINE(ASM_THREAD_SIZE, THREAD_SIZE);
+
+	/* Offsets in thread_info structure */
+	DEFINE(TI_TASK, offsetof(struct thread_info, task));
+	DEFINE(TI_EXECDOMAIN, offsetof(struct thread_info, exec_domain));
+	DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
+	DEFINE(TI_PREEMPTCOUNT, offsetof(struct thread_info, preempt_count));
+	DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
+	DEFINE(TI_INTR_NESTING, offsetof(struct thread_info, interrupt_nesting));
+	DEFINE(ASM_TIF_NEED_RESCHED, TIF_NEED_RESCHED);
+	DEFINE(ASM_TIF_SYSCALL_TRACE, TIF_SYSCALL_TRACE);
+	DEFINE(ASM_TIF_SIGPENDING, TIF_SIGPENDING);
+
+	DEFINE(ASM_RAM_END, (CONFIG_RAMBASE + CONFIG_RAMSIZE));
+	return 0;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/devtree.c
@@ -0,0 +1,173 @@
+/*
+ * arch/ubicom32/kernel/devtree.c
+ *   Ubicom32 architecture device tree implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <asm/devtree.h>
+
+/*
+ * The device tree.
+ */
+struct devtree_node *devtree;
+
+/*
+ * devtree_print()
+ *	Print the device tree.
+ */
+void devtree_print(void)
+{
+	struct devtree_node *p = devtree;
+	printk(KERN_INFO "Device Tree:\n");
+	while (p) {
+		if (p->magic != DEVTREE_NODE_MAGIC) {
+			printk(KERN_EMERG
+			       "device tree has improper node: %p\n", p);
+			return;
+		}
+		printk(KERN_INFO "\t%p: sendirq=%03d, recvirq=%03d, "
+		       " name=%s\n", p, p->sendirq, p->recvirq, p->name);
+		p = p->next;
+	}
+}
+EXPORT_SYMBOL(devtree_print);
+
+/*
+ * devtree_irq()
+ *	Return the IRQ(s) associated with devtree node.
+ */
+int devtree_irq(struct devtree_node *dn,
+		unsigned char *sendirq,
+		unsigned char *recvirq)
+{
+	if (dn->magic != DEVTREE_NODE_MAGIC) {
+		printk(KERN_EMERG "improper node: %p\n", dn);
+		if (sendirq) {
+			*sendirq = DEVTREE_IRQ_NONE;
+		}
+		if (recvirq) {
+			*recvirq = DEVTREE_IRQ_NONE;
+		}
+		return -EFAULT;
+	}
+
+	/*
+	 * Copy the devtree irq(s) to the output parameters.
+	 */
+	if (sendirq) {
+		*sendirq = dn->sendirq;
+	}
+	if (recvirq) {
+		*recvirq = dn->recvirq;
+	}
+	return 0;
+}
+EXPORT_SYMBOL(devtree_irq);
+
+/*
+ * devtree_find_next()
+ *	Provide an iterator for walking the device tree.
+ */
+struct devtree_node *devtree_find_next(struct devtree_node **cur)
+{
+	struct devtree_node *p = *cur;
+	if (!p) {
+		*cur = devtree;
+		return devtree;
+	}
+	p = p->next;
+	*cur = p;
+	return p;
+}
+
+/*
+ * devtree_find_by_irq()
+ *	Return the node associated with a given irq.
+ */
+struct devtree_node *devtree_find_by_irq(uint8_t sendirq, uint8_t recvirq)
+{
+	struct devtree_node *p = devtree;
+
+	if (sendirq == recvirq) {
+		printk(KERN_EMERG "identical request makes no sense sendirq = "
+		       "%d, recvirq= %d\n", sendirq, recvirq);
+		return NULL;
+	}
+
+	while (p) {
+		if (p->magic != DEVTREE_NODE_MAGIC) {
+			printk(KERN_EMERG
+			       "device tree has improper node: %p\n", p);
+			return NULL;
+		}
+
+		/*
+		 * See if we can find a match on the IRQ(s) specified.
+		 */
+		if ((sendirq == p->sendirq) && (recvirq == p->recvirq)) {
+			return p;
+		}
+
+		if ((sendirq == DEVTREE_IRQ_DONTCARE) &&
+		    (p->recvirq == recvirq)) {
+			return p;
+		}
+
+		if ((recvirq == DEVTREE_IRQ_DONTCARE) &&
+		    (p->sendirq == sendirq)) {
+			return p;
+		}
+
+		p = p->next;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(devtree_find_by_irq);
+
+/*
+ * devtree_find_node()
+ *	Find a node in the device tree by name.
+ */
+struct devtree_node *devtree_find_node(const char *str)
+{
+	struct devtree_node *p = devtree;
+	while (p) {
+		if (p->magic != DEVTREE_NODE_MAGIC) {
+			printk(KERN_EMERG
+			       "device tree has improper node: %p\n", p);
+			return NULL;
+		}
+		if (strcmp(p->name, str) == 0) {
+			return p;
+		}
+		p = p->next;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(devtree_find_node);
--- /dev/null
+++ b/arch/ubicom32/kernel/dma.c
@@ -0,0 +1,60 @@
+/*
+ * arch/ubicom32/kernel/dma.c
+ *   Ubicom32 architecture dynamic DMA mapping support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * We never have any address translations to worry about, so this
+ * is just alloc/free.
+ */
+
+#include <linux/types.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/device.h>
+#include <linux/io.h>
+
+void *dma_alloc_coherent(struct device *dev, size_t size,
+			   dma_addr_t *dma_handle, int gfp)
+{
+	void *ret;
+	/* ignore region specifiers */
+	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
+
+	if (dev == NULL || (*dev->dma_mask < 0xffffffff))
+		gfp |= GFP_DMA;
+	ret = (void *)__get_free_pages(gfp, get_order(size));
+
+	if (ret != NULL) {
+		memset(ret, 0, size);
+		*dma_handle = virt_to_phys(ret);
+	}
+	return ret;
+}
+
+void dma_free_coherent(struct device *dev, size_t size,
+			 void *vaddr, dma_addr_t dma_handle)
+{
+	free_pages((unsigned long)vaddr, get_order(size));
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/flat.c
@@ -0,0 +1,206 @@
+/*
+ * arch/ubicom32/kernel/flat.c
+ *   Ubicom32 architecture flat executable format support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/flat.h>
+
+unsigned long ubicom32_flat_get_addr_from_rp(unsigned long *rp,
+					     u32_t relval,
+					     u32_t flags,
+					     unsigned long *persistent)
+{
+	u32_t relval_reloc_type = relval >> 27;
+	u32_t insn = *rp;
+
+	if (*persistent) {
+		/*
+		 * relval holds the relocation that has to be adjusted.
+		 */
+		if (relval == 0) {
+			*persistent = 0;
+		}
+
+		return relval;
+	}
+
+	if (relval_reloc_type == R_UBICOM32_32) {
+		/*
+		 * insn holds the relocation
+		 */
+		return insn;
+	}
+
+	/*
+	 * We don't know this one.
+	 */
+	return 0;
+}
+
+void ubicom32_flat_put_addr_at_rp(unsigned long *rp,
+				  u32_t val,
+				  u32_t relval,
+				  unsigned long *persistent)
+{
+	u32_t reloc_type = (relval >> 27) & 0x1f;
+	u32_t insn = *rp;
+
+	/*
+	 * If persistent is set then it contains the relocation type.
+	 */
+	if (*persistent) {
+		/*
+		 * If persistent is set then it contains the relocation type.
+		 */
+		reloc_type = (*persistent >> 27) & 0x1f;
+	}
+
+	switch (reloc_type) {
+	case R_UBICOM32_32:
+		/*
+		 * Store the 32 bits as is.
+		 */
+		*rp = val;
+		break;
+	case R_UBICOM32_HI24:
+		{
+			/*
+			 * 24 bit relocation that is part of the MOVEAI
+			 * instruction. The 24 bits come from bits 7 - 30 of the
+			 * relocation. The 24 bits eventually get split into 2
+			 * fields in the instruction encoding.
+			 *
+			 * - Bits 7 - 27 of the relocation are encoded into bits
+			 * 0 - 20 of the instruction.
+			 *
+			 * - Bits 28 - 30 of the relocation are encoded into bit
+			 * 24 - 26 of the instruction.
+			 */
+			u32_t mask = 0x1fffff | (0x7 << 24);
+			u32_t valid24bits = (val >> 7) & 0xffffff;
+			u32_t bot_21 = valid24bits & 0x1fffff;
+			u32_t upper_3_bits = ((valid24bits & 0xe00000) << 3);
+			insn &= ~mask;
+
+			insn |= bot_21;
+			insn |= upper_3_bits;
+			*rp = insn;
+		}
+		break;
+	case R_UBICOM32_LO7_S:
+	case R_UBICOM32_LO7_2_S:
+	case R_UBICOM32_LO7_4_S:
+		{
+			/*
+			 * Bits 0 - 6 of the relocation are encoded into the
+			 * 7bit unsigned immediate fields of the SOURCE-1 field
+			 * of the instruction.  The immediate value is left
+			 * shifted by (0, 1, 2) based on the operand size.
+			 */
+			u32_t mask = 0x1f | (0x3 << 8);
+			u32_t bottom, top;
+			val &= 0x7f;
+			if (reloc_type == R_UBICOM32_LO7_2_S) {
+				val >>= 1;
+			} else if (reloc_type == R_UBICOM32_LO7_4_S) {
+				val >>= 2;
+			}
+
+			bottom  = val & 0x1f;
+			top = val >> 5;
+			insn &= ~mask;
+			insn |= bottom;
+			insn |= (top << 8);
+			BUG_ON(*rp != insn);
+			*rp = insn;
+			break;
+		}
+	case R_UBICOM32_LO7_D:
+	case R_UBICOM32_LO7_2_D:
+	case R_UBICOM32_LO7_4_D:
+		{
+			/*
+			 * Bits 0 - 6 of the relocation are encoded into the
+			 * 7bit unsigned immediate fields of the DESTINATION
+			 * field of the instruction.  The immediate value is
+			 * left shifted by (0, 1, 2) based on the operand size.
+			 */
+			u32_t mask = (0x1f | (0x3 << 8)) << 16;
+			u32_t bottom, top;
+			val &= 0x7f;
+			if (reloc_type == R_UBICOM32_LO7_2_D) {
+				val >>= 1;
+			} else if (reloc_type == R_UBICOM32_LO7_4_D) {
+				val >>= 2;
+			}
+			bottom  = (val & 0x1f) << 16;
+			top = (val >> 5) << 16;
+			insn &= ~mask;
+			insn |= bottom;
+			insn |= (top << 8);
+			BUG_ON(*rp != insn);
+			*rp = insn;
+			break;
+		}
+	case R_UBICOM32_LO7_CALLI:
+	case R_UBICOM32_LO16_CALLI:
+		{
+			/*
+			 * Extract the offset for a CALLI instruction. The
+			 * offsets can be either 7 bits or 18 bits. Since all
+			 * instructions in ubicom32 architecture are at work
+			 * aligned addresses the truncated offset is right
+			 * shifted by 2 before being encoded in the instruction.
+			 */
+			if (reloc_type == R_UBICOM32_LO7_CALLI) {
+				val &= 0x7f;
+			} else {
+				val &= 0x3ffff;
+			}
+
+			val >>= 2;
+
+			insn &= ~0x071f071f;
+			insn |= (val & 0x1f) << 0;
+			val >>= 5;
+			insn |= (val & 0x07) << 8;
+			val >>= 3;
+			insn |= (val & 0x1f) << 16;
+			val >>= 5;
+			insn |= (val & 0x07) << 24;
+			if (reloc_type == R_UBICOM32_LO7_CALLI) {
+				BUG_ON(*rp != insn);
+			}
+			*rp = insn;
+		}
+		break;
+	}
+
+	if (*persistent) {
+		*persistent = 0;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/head.S
@@ -0,0 +1,247 @@
+/*
+ * arch/ubicom32/kernel/head.S
+ *	<TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/asm-offsets.h>
+#include <asm/page_offset.h>
+#define __ASM__
+#include <asm/ip5000.h>
+
+
+#define SRC_AN A3
+#define DST_AN A4
+
+#define PARAM_DN D0
+#define TMP_DN D15
+#define TMP2_DN D14
+
+/*
+ * The following code is placed at the start of the Linux section of memory.
+ * This is the primary entry point for Linux.
+ *
+ * However, we also want the syscall entry/exit code to be at a fixed address.
+ * So we take the primary entry point and reserve 16 bytes.  That address is
+ * where the system_call entry point exists.  This 16 bytes basically allows
+ * us to jump around the system_call entry point code to the actual startup
+ * code.
+ *
+ * Linux Memory Map (see vlinux.lds.S):
+ * 0x40400000 - Primary Entry Point for Linux (jump around code below).
+ * 0x40400010 - Syscall Entry Point.
+ */
+
+	.sect	.skip_syscall, "ax", @progbits
+	.global	__skip_syscall_section
+__skip_syscall_section:
+	moveai		A3, #%hi(_start)
+	lea.1		A3, %lo(_start)(A3)
+	ret		A3
+/*
+ * __os_node_offset contains the offset from KERNELBASE to the os_node, it is
+ * not intended to be used by anything except the boot code.
+ */
+__os_node_offset:
+.long	(_os_node - CONFIG_KERNELBASE)
+
+.text
+.global	_start
+
+/*
+ * start()
+ *	This is the start of the Linux kernel.
+ */
+_start:
+	move.4		SCRATCHPAD1, #0
+
+
+/*
+ * Setup the range registers... the loader has setup a few, but we will go ahead
+ * and correct them for our own limits. Note that once set these are never
+ * changed again.  The ranges are as follows
+ *
+ *  D_RANGE0 - io block (set up by loaded)
+ *
+ *  I_RANGE0 and D_RANGE1 - kernel/ultra loader address space bottom of ocm-> top
+ *	of ram typically 0x3ffc0000 - 0x440000000
+ *  I_RANGE1 - kernel / userspace transition area (aka syscalls, context switches)
+ *	typically 0x40400000 - ~0x40400400
+ *  I_RANGE2 / D_RANGE2 - slab area
+ *	typically 0x40A00000 - ~0x44000000
+ *
+ *  I_RANGE4, D_RANGE3, D_RANGE3 - unused.
+ */
+	moveai		SRC_AN, #%hi(PAGE_OFFSET_RAW)
+	lea.4		SRC_AN, %lo(PAGE_OFFSET_RAW)(SRC_AN)
+	move.4		D_RANGE1_LO, SRC_AN
+	move.4		I_RANGE0_LO, SRC_AN
+
+; don't try to calculate I_RANGE_HI, see below
+;	moveai		SRC_AN, #%hi(___init_end-4)
+;	lea.4		SRC_AN, %lo(___init_end-4)(SRC_AN)
+;	move.4		I_RANGE0_HI, SRC_AN
+
+	moveai		SRC_AN, #%hi(CONFIG_RAMBASE+CONFIG_RAMSIZE-4)
+	lea.4		SRC_AN, %lo(CONFIG_RAMBASE+CONFIG_RAMSIZE-4)(SRC_AN)
+	move.4		D_RANGE1_HI, SRC_AN
+
+; for now allow the whole ram to be executable as well so we don't run into problems
+; once we load user more code.
+	move.4		I_RANGE0_HI, SRC_AN
+
+#ifdef CONFIG_PROTECT_KERNEL
+; when kernel protection is enabled, we only open up syscall and non kernel text
+; for userspace apps, for now only irange registers registers 1 and 2 are used for userspace.
+
+	;; syscall range
+	moveai		SRC_AN, #%hi(_begin)
+	lea.4		SRC_AN, %lo(_begin)(SRC_AN)
+	move.4		I_RANGE1_LO, SRC_AN
+	moveai		SRC_AN, #%hi(__fixed_text_end)
+	lea.4		SRC_AN, %lo(__fixed_text_end)(SRC_AN)
+	move.4		I_RANGE1_HI, SRC_AN
+
+	;; slab instructions
+	moveai		SRC_AN, #%hi(_edata)
+	lea.4		SRC_AN, %lo(_edata)(SRC_AN)
+	move.4		I_RANGE2_LO, SRC_AN
+	;; End of DDR is already in range0 hi so just copy it.
+	move.4		I_RANGE2_HI, I_RANGE0_HI
+
+	;; slab data (same as slab instructions but starting a little earlier).
+	moveai		SRC_AN, #%hi(_data_protection_end)
+	lea.4		SRC_AN, %lo(_data_protection_end)(SRC_AN)
+	move.4		D_RANGE2_LO, SRC_AN
+	move.4		D_RANGE2_HI, I_RANGE0_HI
+
+;; enable ranges
+	;; skip I_RANGE0_EN
+	move.4		I_RANGE1_EN, #-1
+	move.4		I_RANGE2_EN, #-1
+	move.4		I_RANGE3_EN, #0
+
+	;; skip D_RANGE0_EN or D_RANGE1_EN
+	move.4		D_RANGE2_EN, #-1
+	move.4		D_RANGE3_EN, #0
+	move.4		D_RANGE4_EN, #0
+#endif
+
+;
+; If __ocm_free_begin is smaller than __ocm_free_end the
+; setup OCM text and data ram banks properly
+;
+	moveai		DST_AN, #%hi(__ocm_free_begin)
+	lea.4		TMP_DN, %lo(__ocm_free_begin)(DST_AN)
+	moveai		DST_AN, #%hi(__ocm_free_end)
+	lea.4		TMP2_DN, %lo(__ocm_free_end)(DST_AN)
+	sub.4		#0, TMP2_DN, TMP_DN
+	jmple.f		2f
+	moveai		DST_AN, #%hi(__data_begin)
+	lea.4		TMP_DN, %lo(__data_begin)(DST_AN)
+	moveai		DST_AN, #%hi(OCMSTART)
+	lea.4		TMP2_DN, %lo(OCMSTART)(DST_AN)
+	sub.4		TMP_DN, TMP_DN, TMP2_DN
+	lsr.4		TMP_DN, TMP_DN, #15
+	lsl.4		TMP_DN, #1, TMP_DN
+	moveai		DST_AN, #%hi(OCMC_BASE)
+	add.4		OCMC_BANK_MASK(DST_AN), #-1, TMP_DN
+	pipe_flush	0
+2:
+;
+; Load .ocm_text
+;
+	moveai          DST_AN, #%hi(__ocm_text_run_end)
+	lea.4           TMP_DN, %lo(__ocm_text_run_end)(DST_AN)
+	moveai          DST_AN, #%hi(__ocm_text_run_begin)
+	lea.4           DST_AN, %lo(__ocm_text_run_begin)(DST_AN)
+	moveai          SRC_AN, #%hi(__ocm_text_load_begin)
+	lea.4           SRC_AN, %lo(__ocm_text_load_begin)(SRC_AN)
+	jmpt.t          2f
+
+1:      move.4          (DST_AN)4++, (SRC_AN)4++
+
+2:      sub.4           #0, DST_AN, TMP_DN
+	jmpne.t         1b
+
+;
+; Load .ocm_data
+;
+	moveai          DST_AN, #%hi(__ocm_data_run_end)
+	lea.4           TMP_DN, %lo(__ocm_data_run_end)(DST_AN)
+	moveai          DST_AN, #%hi(__ocm_data_run_begin)
+	lea.4           DST_AN, %lo(__ocm_data_run_begin)(DST_AN)
+	moveai          SRC_AN, #%hi(__ocm_data_load_begin)
+	lea.4           SRC_AN, %lo(__ocm_data_load_begin)(SRC_AN)
+	jmpt.t          2f
+
+1:      move.4          (DST_AN)4++, (SRC_AN)4++
+
+2:      sub.4           #0, DST_AN, TMP_DN
+	jmpne.t         1b
+
+; Clear .bss
+;
+	moveai		SRC_AN, #%hi(_ebss)
+	lea.4		TMP_DN, %lo(_ebss)(SRC_AN)
+	moveai		DST_AN, #%hi(_sbss)
+	lea.4		DST_AN, %lo(_sbss)(DST_AN)
+	jmpt.t		2f
+
+1:	move.4		(DST_AN)4++, #0
+
+2:	sub.4		#0, DST_AN, TMP_DN
+	jmpne.t		1b
+
+; save our parameter to devtree (after clearing .bss)
+	moveai		DST_AN, #%hi(devtree)
+	lea.4		DST_AN, %lo(devtree)(DST_AN)
+	move.4		(DST_AN), PARAM_DN
+
+	moveai		sp, #%hi(init_thread_union)
+	lea.4		sp, %lo(init_thread_union)(sp)
+	movei		TMP_DN, #ASM_THREAD_SIZE
+	add.4		sp, sp, TMP_DN
+	move.4		-4(sp)++, #0 ; nesting level = 0
+	move.4		-4(sp)++, #1 ; KERNEL_THREAD
+
+;; ip3k-elf-gdb backend now sets scratchpad3 to 1 when either continue
+;; or single step commands are issued. scratchpad3 is set to 0 when the
+;; debugger detaches from the board.
+	move.4		TMP_DN, scratchpad3
+	lsl.4		TMP_DN, TMP_DN, #0x0
+	jmpeq.f		_jump_to_start_kernel
+_ok_to_set_break_points_in_linux:
+;; THREAD_STALL
+	move.4		mt_dbg_active_clr,#-1
+;; stalling the threads isn't instantaneous.. need to flush the pipe.
+	pipe_flush	0
+	pipe_flush	0
+
+_jump_to_start_kernel:
+	moveai		SRC_AN, #%hi(start_kernel)
+	lea.4		SRC_AN, %lo(start_kernel)(SRC_AN)
+	ret		SRC_AN
--- /dev/null
+++ b/arch/ubicom32/kernel/init_task.c
@@ -0,0 +1,62 @@
+/*
+ * arch/ubicom32/kernel/init_task.c
+ *   Ubicom32 architecture task initialization implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/init_task.h>
+#include <linux/fs.h>
+#include <linux/mqueue.h>
+#include <linux/uaccess.h>
+#include <asm/pgtable.h>
+
+static struct fs_struct init_fs = INIT_FS;
+static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
+static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
+struct mm_struct init_mm = INIT_MM(init_mm);
+EXPORT_SYMBOL(init_mm);
+
+/*
+ * Initial task structure.
+ *
+ * All other task structs will be allocated on slabs in fork.c
+ */
+struct task_struct init_task = INIT_TASK(init_task);
+
+EXPORT_SYMBOL(init_task);
+
+/*
+ * Initial thread structure.
+ *
+ * We need to make sure that this is 8192-byte aligned due to the
+ * way process stacks are handled. This is done by having a special
+ * "init_task" linker map entry..
+ */
+union thread_union init_thread_union
+	__attribute__((__section__(".data.init_task"))) =
+		{ INIT_THREAD_INFO(init_task) };
--- /dev/null
+++ b/arch/ubicom32/kernel/irq.c
@@ -0,0 +1,596 @@
+/*
+ * arch/ubicom32/kernel/irq.c
+ *   Ubicom32 architecture IRQ support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * (C) Copyright 2007, Greg Ungerer <gerg@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/types.h>
+#include <linux/irq.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/kernel_stat.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
+#include <asm/system.h>
+#include <asm/traps.h>
+#include <asm/ldsr.h>
+#include <asm/ip5000.h>
+#include <asm/machdep.h>
+#include <asm/asm-offsets.h>
+#include <asm/thread.h>
+#include <asm/devtree.h>
+
+unsigned int irq_soft_avail;
+static struct irqaction ubicom32_reserve_action[NR_IRQS];
+
+#if !defined(CONFIG_DEBUG_IRQMEASURE)
+#define IRQ_DECLARE_MEASUREMENT
+#define IRQ_MEASUREMENT_START()
+#define IRQ_MEASUREMENT_END(irq)
+#else
+#define IRQ_DECLARE_MEASUREMENT \
+	int __diff;		\
+	unsigned int __tstart;
+
+#define IRQ_MEASUREMENT_START() \
+	__tstart = UBICOM32_IO_TIMER->sysval;
+
+#define IRQ_MEASUREMENT_END(irq) \
+	__diff = (int)UBICOM32_IO_TIMER->sysval - (int)__tstart; \
+	irq_measurement_update((irq), __diff);
+
+/*
+ * We keep track of the time spent in both irq_enter()
+ * and irq_exit().
+ */
+#define IRQ_WEIGHT 32
+
+struct irq_measurement {
+	volatile unsigned int min;
+	volatile unsigned int avg;
+	volatile unsigned int max;
+};
+
+static DEFINE_SPINLOCK(irq_measurement_lock);
+
+/*
+ *  Add 1 in for softirq (irq_exit());
+ */
+static struct irq_measurement irq_measurements[NR_IRQS + 1];
+
+/*
+ * irq_measurement_update()
+ *	Update an entry in the measurement array for this irq.
+ */
+static void irq_measurement_update(int irq, int sample)
+{
+	struct irq_measurement *im = &irq_measurements[irq];
+	spin_lock(&irq_measurement_lock);
+	if ((im->min == 0) || (im->min > sample)) {
+		im->min = sample;
+	}
+	if (im->max < sample) {
+		im->max = sample;
+	}
+	im->avg = ((im->avg * (IRQ_WEIGHT - 1)) + sample) / IRQ_WEIGHT;
+	spin_unlock(&irq_measurement_lock);
+}
+#endif
+
+/*
+ * irq_kernel_stack_check()
+ *	See if the kernel stack is within STACK_WARN of the end.
+ */
+static void irq_kernel_stack_check(int irq, struct pt_regs *regs)
+{
+#ifdef CONFIG_DEBUG_STACKOVERFLOW
+	unsigned long sp;
+
+	/*
+	 * Make sure that we are not close to the top of the stack and thus
+	 * can not really service this interrupt.
+	 */
+	asm volatile (
+		"and.4		%0, SP, %1 \n\t"
+		: "=d" (sp)
+		: "d" (THREAD_SIZE - 1)
+		: "cc"
+	);
+
+	if (sp < (sizeof(struct thread_info) + STACK_WARN)) {
+		printk(KERN_WARNING
+			"cpu[%d]: possible overflow detected sp remain: %p, "
+		       "irq: %d, regs: %p\n",
+			thread_get_self(), (void *)sp, irq, regs);
+		dump_stack();
+	}
+
+	if (sp < (sizeof(struct thread_info) + 16)) {
+		THREAD_STALL;
+	}
+#endif
+}
+
+/*
+ * irq_get_lsb()
+ *	Get the LSB set in value
+ */
+static int irq_get_lsb(unsigned int value)
+{
+	static unsigned char irq_bits[8] = {
+		3, 0, 1, 0, 2, 0, 1, 0
+	};
+	u32_t nextbit = 0;
+
+	value = (value >> nextbit) | (value << ((sizeof(value) * 8) - nextbit));
+
+	/*
+	 * It's unlikely that we find that we execute the body of this while
+	 * loop.  50% of the time we won't take this at all and then of the
+	 * cases where we do about 50% of those we only execute once.
+	 */
+	if (!(value & 0xffff)) {
+		nextbit += 0x10;
+		value >>= 16;
+	}
+
+	if (!(value & 0xff)) {
+		nextbit += 0x08;
+		value >>= 8;
+	}
+
+	if (!(value & 0xf)) {
+		nextbit += 0x04;
+		value >>= 4;
+	}
+
+	nextbit += irq_bits[value & 0x7];
+	if (nextbit > 63) {
+		panic("nextbit out of range: %d\n", nextbit);
+	}
+	return nextbit;
+}
+
+/*
+ * ubicom32_reserve_handler()
+ *	Bogus handler associated with pre-reserved IRQ(s).
+ */
+static irqreturn_t ubicom32_reserve_handler(int irq, void *dev_id)
+{
+	BUG();
+	return IRQ_HANDLED;
+}
+
+/*
+ * __irq_disable_vector()
+ *	Disable the interrupt by clearing the appropriate bit in the
+ *	LDSR Mask Register.
+ */
+static void __irq_disable_vector(unsigned int irq)
+{
+	ldsr_disable_vector(irq);
+}
+
+/*
+ * __irq_ack_vector()
+ *	Acknowledge the specific interrupt by clearing the associate bit in
+ *	hardware
+ */
+static void __irq_ack_vector(unsigned int irq)
+{
+	if (irq < 32) {
+		asm volatile ("move.4 INT_CLR0, %0" : : "d" (1 << irq));
+	} else {
+		asm volatile ("move.4 INT_CLR1, %0" : : "d" (1 << (irq - 32)));
+	}
+}
+
+/*
+ * __irq_enable_vector()
+ *	Clean and then enable the interrupt by setting the appropriate bit in
+ *	the LDSR Mask Register.
+ */
+static void __irq_enable_vector(unsigned int irq)
+{
+	/*
+	 * Acknowledge, really clear the vector.
+	 */
+	__irq_ack_vector(irq);
+	ldsr_enable_vector(irq);
+}
+
+/*
+ * __irq_mask_vector()
+ */
+static void __irq_mask_vector(unsigned int irq)
+{
+	ldsr_mask_vector(irq);
+}
+
+/*
+ * __irq_unmask_vector()
+ */
+static void __irq_unmask_vector(unsigned int irq)
+{
+	ldsr_unmask_vector(irq);
+}
+
+/*
+ * __irq_end_vector()
+ *	Called once an interrupt is completed (reset the LDSR mask).
+ */
+static void __irq_end_vector(unsigned int irq)
+{
+	ldsr_unmask_vector(irq);
+}
+
+#if defined(CONFIG_SMP)
+/*
+ * __irq_set_affinity()
+ *	Set the cpu affinity for this interrupt.
+ */
+static void __irq_set_affinity(unsigned int irq, cpumask_t dest)
+{
+	smp_set_affinity(irq, dest);
+	irq_desc[irq].affinity = dest;
+}
+#endif
+
+/*
+ * On-Chip Generic Interrupt function handling.
+ */
+static struct irq_chip ubicom32_irq_chip = {
+	.name		= "Ubicom32",
+	.startup	= NULL,
+	.shutdown	= NULL,
+	.enable		= __irq_enable_vector,
+	.disable	= __irq_disable_vector,
+	.ack		= __irq_ack_vector,
+	.mask		= __irq_mask_vector,
+	.unmask		= __irq_unmask_vector,
+	.end		= __irq_end_vector,
+#if defined(CONFIG_SMP)
+	.set_affinity	= __irq_set_affinity,
+#endif
+};
+
+/*
+ * do_IRQ()
+ *	Primary interface for handling IRQ() requests.
+ */
+asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
+{
+	struct pt_regs *oldregs;
+	struct thread_info *ti;
+	unsigned long sp;
+
+	IRQ_DECLARE_MEASUREMENT;
+
+	oldregs = set_irq_regs(regs);
+
+	/*
+	 * Before we call the handler and potentially enable
+	 * interrupts, track the nesting level.
+	 */
+	asm volatile (
+		"and.4		%0, SP, %1 \n\t"
+		: "=d" (sp)
+		: "d" (~(THREAD_SIZE - 1))
+		: "cc"
+	);
+	ti = (struct thread_info *)sp;
+	ti->interrupt_nesting++;
+
+	/*
+	 * Check for possible stack overflow on the kernel stack.
+	 */
+	irq_kernel_stack_check(irq, regs);
+
+	/*
+	 * Execute the IRQ handler and any pending SoftIRQ requests.
+	 */
+	BUG_ON(!irqs_disabled());
+	irq_enter();
+
+	BUG_ON(!irqs_disabled());
+	IRQ_MEASUREMENT_START();
+	__do_IRQ(irq);
+	IRQ_MEASUREMENT_END(irq);
+	BUG_ON(!irqs_disabled());
+
+	IRQ_MEASUREMENT_START();
+	irq_exit();
+	IRQ_MEASUREMENT_END(NR_IRQS);
+	BUG_ON(!irqs_disabled());
+
+	set_irq_regs(oldregs);
+	ti->interrupt_nesting--;
+}
+
+/*
+ * irq_soft_alloc()
+ *	Allocate a soft IRQ.
+ */
+int irq_soft_alloc(unsigned int *soft)
+{
+	if (irq_soft_avail == 0) {
+		printk(KERN_NOTICE "no soft irqs to allocate\n");
+		return -EFAULT;
+	}
+
+	*soft = irq_get_lsb(irq_soft_avail);
+	irq_soft_avail &= ~(1 << *soft);
+	return 0;
+}
+
+/*
+ * ack_bad_irq()
+ *	Called to handle an bad irq request.
+ */
+void ack_bad_irq(unsigned int irq)
+{
+	printk(KERN_ERR "IRQ: unexpected irq=%d\n", irq);
+	__irq_end_vector(irq);
+}
+
+/*
+ * show_interrupts()
+ *	Return a string that displays the state of each of the interrupts.
+ */
+int show_interrupts(struct seq_file *p, void *v)
+{
+	struct irqaction *ap;
+	int irq = *((loff_t *) v);
+	int j;
+
+	if (irq >= NR_IRQS) {
+		return 0;
+	}
+
+	if (irq == 0) {
+		seq_puts(p, "           ");
+		for_each_online_cpu(j) {
+			seq_printf(p, "CPU%d       ", j);
+		}
+		seq_putc(p, '\n');
+	}
+
+	ap = irq_desc[irq].action;
+	if (ap) {
+		seq_printf(p, "%3d: ", irq);
+		for_each_online_cpu(j) {
+			seq_printf(p, "%10u ", kstat_irqs_cpu(irq, j));
+		}
+		seq_printf(p, "%14s  ", irq_desc[irq].chip->name);
+		seq_printf(p, "%s", ap->name);
+		for (ap = ap->next; ap; ap = ap->next) {
+			seq_printf(p, ", %s", ap->name);
+		}
+		seq_putc(p, '\n');
+	}
+	return 0;
+}
+
+#if defined(CONFIG_DEBUG_IRQMEASURE)
+static unsigned int irq_cycles_to_micro(unsigned int cycles, unsigned int frequency)
+{
+	unsigned int micro = (cycles / (frequency / 1000000));
+	return micro;
+}
+
+/*
+ * irq_measurement_show()
+ *	Print out the min, avg, max values for each IRQ
+ *
+ * By request, the max value is reset after each dump.
+ */
+static int irq_measurement_show(struct seq_file *p, void *v)
+{
+	struct irqaction *ap;
+	unsigned int freq = processor_frequency();
+	int irq = *((loff_t *) v);
+
+
+	if (irq == 0) {
+		seq_puts(p, "\tmin\tavg\tmax\t(micro-seconds)\n");
+	}
+
+	if (irq > NR_IRQS) {
+		return 0;
+	}
+
+	if (irq == NR_IRQS) {
+		unsigned int min, avg, max;
+		spin_lock(&irq_measurement_lock);
+		min = irq_cycles_to_micro(irq_measurements[irq].min, freq);
+		avg = irq_cycles_to_micro(irq_measurements[irq].avg, freq);
+		max = irq_cycles_to_micro(irq_measurements[irq].max, freq);
+		irq_measurements[irq].max = 0;
+		spin_unlock(&irq_measurement_lock);
+		seq_printf(p, "   \t%u\t%u\t%u\tsoftirq\n", min, avg, max);
+		return 0;
+	}
+
+	ap = irq_desc[irq].action;
+	if (ap) {
+		unsigned int min, avg, max;
+		spin_lock(&irq_measurement_lock);
+		min = irq_cycles_to_micro(irq_measurements[irq].min, freq);
+		avg = irq_cycles_to_micro(irq_measurements[irq].avg, freq);
+		max = irq_cycles_to_micro(irq_measurements[irq].max, freq);
+		irq_measurements[irq].max = 0;
+		spin_unlock(&irq_measurement_lock);
+		seq_printf(p, "%2u:\t%u\t%u\t%u\t%s\n", irq, min, avg, max, ap->name);
+	}
+	return 0;
+}
+
+static void *irq_measurement_start(struct seq_file *f, loff_t *pos)
+{
+	return (*pos <= NR_IRQS) ? pos : NULL;
+}
+
+static void *irq_measurement_next(struct seq_file *f, void *v, loff_t *pos)
+{
+	(*pos)++;
+	if (*pos > NR_IRQS)
+		return NULL;
+	return pos;
+}
+
+static void irq_measurement_stop(struct seq_file *f, void *v)
+{
+	/* Nothing to do */
+}
+
+static const struct seq_operations irq_measurement_seq_ops = {
+	.start = irq_measurement_start,
+	.next  = irq_measurement_next,
+	.stop  = irq_measurement_stop,
+	.show  = irq_measurement_show,
+};
+
+static int irq_measurement_open(struct inode *inode, struct file *filp)
+{
+	return seq_open(filp, &irq_measurement_seq_ops);
+}
+
+static const struct file_operations irq_measurement_fops = {
+	.open		= irq_measurement_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
+static int __init irq_measurement_init(void)
+{
+	proc_create("irq_measurements", 0, NULL, &irq_measurement_fops);
+	return 0;
+}
+module_init(irq_measurement_init);
+#endif
+
+/*
+ * init_IRQ(void)
+ *	Initialize the on-chip IRQ subsystem.
+ */
+void __init init_IRQ(void)
+{
+	int irq;
+	struct devtree_node *p = NULL;
+	struct devtree_node *iter = NULL;
+	unsigned int mask = 0;
+	unsigned int reserved = 0;
+
+	/*
+	 * Pull out the list of software interrupts that are avialable to
+	 * Linux and provide an allocation function for them.  The first
+	 * 24 interrupts of INT0 are software interrupts.
+	 */
+	irq_soft_avail = 0;
+	if (processor_interrupts(&irq_soft_avail, NULL) < 0) {
+		printk(KERN_WARNING "No Soft IRQ(s) available\n");
+	}
+	irq_soft_avail &= ((1 << 24) - 1);
+
+	/*
+	 * Initialize all of the on-chip interrupt handling
+	 * to use a common set of interrupt functions.
+	 */
+	for (irq = 0; irq < NR_IRQS; irq++) {
+		irq_desc[irq].status = IRQ_DISABLED;
+		irq_desc[irq].action = NULL;
+		irq_desc[irq].depth = 1;
+		set_irq_chip(irq, &ubicom32_irq_chip);
+	}
+
+	/*
+	 * The sendirq of a devnode is not registered within Linux but instead
+	 * is used by the software I/O thread.  These interrupts are reserved.
+	 * The recvirq is used by Linux and registered by a device driver, these
+	 * are not reserved.
+	 *
+	 * recvirq(s) that are in the software interrupt range are not supposed
+	 * to be marked as reserved.  We track this while we scan the device
+	 * nodes.
+	 */
+	p = devtree_find_next(&iter);
+	while (p) {
+		unsigned char sendirq, recvirq;
+		devtree_irq(p, &sendirq, &recvirq);
+
+		/*
+		 * If the sendirq is valid, mark that irq as taken by the
+		 * devtree node.
+		 */
+		if (sendirq < NR_IRQS) {
+			ubicom32_reserve_action[sendirq].handler =
+				ubicom32_reserve_handler;
+			ubicom32_reserve_action[sendirq].name = p->name;
+			irq_desc[sendirq].action =
+				&ubicom32_reserve_action[sendirq];
+			mask |= (1 << sendirq);
+		}
+
+		/*
+		 * Track the relevant recieve IRQ(s)
+		 */
+		if (recvirq < 24) {
+			mask |= (1 << recvirq);
+		}
+
+		/*
+		 * Move to the next node.
+		 */
+		p = devtree_find_next(&iter);
+	}
+
+	/*
+	 * Remove these bits from the irq_soft_avail list and then use the
+	 * result as the list of pre-reserved IRQ(s).
+	 */
+	reserved = ~irq_soft_avail & ~mask;
+	for (irq = 0; irq < 24; irq++) {
+		if ((reserved & (1 << irq))) {
+			ubicom32_reserve_action[irq].handler =
+				ubicom32_reserve_handler;
+			ubicom32_reserve_action[irq].name = "reserved";
+			irq_desc[irq].action = &ubicom32_reserve_action[irq];
+		}
+	}
+
+	/*
+	 * Initialize the LDSR which is the Ubicom32 programmable
+	 * interrupt controller.
+	 */
+	ldsr_init();
+
+	/*
+	 * The Ubicom trap code needs a 2nd init after IRQ(s) are setup.
+	 */
+	trap_init_interrupt();
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/ldsr.c
@@ -0,0 +1,1176 @@
+/*
+ * arch/ubicom32/kernel/ldsr.c
+ *   Ubicom32 architecture Linux Device Services Driver Interface
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * NOTES:
+ *
+ * The LDSR is a programmable interrupt controller that is written in software.
+ * It emulates the behavior of an pic by fielding the interrupts, choosing a
+ * victim thread to take the interrupt and forcing that thread to take a context
+ * switch to the appropriate interrupt handler.
+ *
+ * Because traps are treated as just a special class of interrupts, the LDSR
+ * also handles the processing of traps.
+ *
+ * Because we compile Linux both UP and SMP, we need the LDSR to use
+ * architectural locking that is not "compiled out" when compiling UP.  For now,
+ * we use the single atomic bit lock.
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/profile.h>
+#include <linux/clocksource.h>
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/cpumask.h>
+#include <linux/bug.h>
+#include <linux/delay.h>
+#include <asm/ip5000.h>
+#include <asm/atomic.h>
+#include <asm/machdep.h>
+#include <asm/asm-offsets.h>
+#include <asm/traps.h>
+#include <asm/thread.h>
+#include <asm/range-protect.h>
+
+/*
+ * One can not print from the LDSR so the best we can do is
+ * check a condition and stall all of the threads.
+ */
+
+// #define DEBUG_LDSR 1
+#if defined(DEBUG_LDSR)
+#define DEBUG_ASSERT(cond) \
+	if (!(cond)) { \
+		THREAD_STALL; \
+	}
+#else
+#define DEBUG_ASSERT(cond)
+#endif
+
+/*
+ * Make global so that we can use it in the RFI code in assembly.
+ */
+unsigned int ldsr_soft_irq_mask;
+EXPORT_SYMBOL(ldsr_soft_irq_mask);
+
+static unsigned int ldsr_suspend_mask;
+static unsigned int ldsr_soft_irq;
+static unsigned int ldsr_stack_space[1024];
+
+static struct ldsr_register_bank {
+	volatile unsigned int enabled0;
+	volatile unsigned int enabled1;
+	volatile unsigned int mask0;
+	volatile unsigned int mask1;
+	unsigned int total;
+	unsigned int retry;
+	unsigned int backout;
+} ldsr_interrupt;
+
+/*
+ * Which thread/cpu are we?
+ */
+static int ldsr_tid = -1;
+
+#if defined(CONFIG_IRQSTACKS)
+/*
+ * per-CPU IRQ stacks (thread information and stack)
+ *
+ * NOTE: Do not use DEFINE_PER_CPU() as it makes it harder
+ * to find the location of ctx from assembly language.
+ */
+union irq_ctx {
+	struct thread_info      tinfo;
+	u32                     stack[THREAD_SIZE/sizeof(u32)];
+};
+static union irq_ctx *percpu_irq_ctxs[NR_CPUS];
+
+/*
+ *  Storage for the interrupt stack.
+ */
+#if !defined(CONFIG_IRQSTACKS_USEOCM)
+static char percpu_irq_stacks[(NR_CPUS * THREAD_SIZE) + (THREAD_SIZE - 1)];
+#else
+/*
+ *  For OCM, the linker will ensure that space is allocated for the stack
+ *  see (vmlinux.lds.S)
+ */
+static char percpu_irq_stacks[];
+#endif
+
+#endif
+
+/*
+ * Save trap IRQ because we need to un-suspend if it gets set.
+ */
+static unsigned int ldsr_trap_irq_mask;
+static unsigned int ldsr_trap_irq;
+
+/*
+ * ret_from_interrupt_to_kernel
+ *	Just restore the context and do nothing else.
+ */
+asmlinkage void ret_from_interrupt_to_kernel(void)__attribute__((naked));
+
+/*
+ * ret_from_interrupt_to_user
+ *	Call scheduler if needed. Just restore the context.
+ */
+asmlinkage void ret_from_interrupt_to_user(void)__attribute__((naked));
+
+#ifdef DEBUG_LDSR
+u32_t old_sp, old_pc, old_a0, old_a5, old_a3;
+struct pt_regs copy_regs, *copy_save_area;
+#endif
+
+int __user_mode(unsigned long sp)
+{
+
+	u32_t saved_stack_base = sp & ~(ASM_THREAD_SIZE - 1);
+#if defined(CONFIG_IRQSTACKS_USEOCM)
+	if ((union irq_ctx *)saved_stack_base == percpu_irq_ctxs[smp_processor_id()]) {
+		/*
+		 *  On the interrupt stack.
+		 */
+		return 0;
+	}
+#endif
+
+	if (!(u32_t)current) {
+		return 0;
+	}
+	return saved_stack_base != ((u32_t)current->stack);
+}
+
+/*
+ * ldsr_lock_release()
+ *	Release the LDSR lock.
+ */
+static void ldsr_lock_release(void)
+{
+	UBICOM32_UNLOCK(LDSR_LOCK_BIT);
+}
+
+/*
+ * ldsr_lock_acquire()
+ *	Acquire the LDSR lock, spin if not available.
+ */
+static void ldsr_lock_acquire(void)
+{
+	UBICOM32_LOCK(LDSR_LOCK_BIT);
+}
+
+/*
+ * ldsr_thread_irq_disable()
+ *	Disable interrupts for the specified thread.
+ */
+static void ldsr_thread_irq_disable(unsigned int tid)
+{
+	unsigned int mask = (1 << tid);
+
+	asm volatile (
+	"	or.4	scratchpad1, scratchpad1, %0	\n\t"
+		:
+		: "d"(mask)
+		: "cc"
+	);
+}
+
+/*
+ * ldsr_thread_get_interrupts()
+ *	Get the interrupt state for all threads.
+ */
+static unsigned long ldsr_thread_get_interrupts(void)
+{
+	unsigned long ret = 0;
+	asm volatile (
+	"	move.4	%0, scratchpad1	\n\t"
+		: "=r" (ret)
+		:
+	);
+	return ret;
+}
+
+/*
+ * ldsr_emulate_and_run()
+ *	Emulate the instruction and then set the thread to run.
+ */
+static void ldsr_emulate_and_run(unsigned int tid)
+{
+	unsigned int thread_mask = (1 << tid);
+	u32_t write_csr = (tid << 15) | (1 << 14);
+
+	/*
+	 * Emulate the unaligned access.
+	 */
+	unaligned_emulate(tid);
+
+	/*
+	 * Get the thread back in a running state.
+	 */
+	asm volatile (
+	"	setcsr	%0			\n\t"
+	"	setcsr_flush 0			\n\t"
+	"	move.4	trap_cause, #0		\n\t" /* Clear the trap cause
+						       * register */
+	"	setcsr	#0			\n\t"
+	"	setcsr_flush 0			\n\t"
+	"	move.4	mt_dbg_active_set, %1	\n\t" /* Activate thread even if
+						       * in dbg/fault state */
+	"	move.4	mt_active_set, %1	\n\t" /* Restart target
+						       * thread. */
+		:
+		: "r" (write_csr), "d" (thread_mask)
+		: "cc"
+	);
+	thread_enable_mask(thread_mask);
+}
+
+/*
+ * ldsr_preemptive_context_save()
+ *	save thread context from another hardware thread.  The other thread must
+ *	be stalled.
+ */
+static inline void ldsr_preemptive_context_save(u32_t thread,
+						struct pt_regs *regs)
+{
+	/*
+	 * Save the current state of the specified thread
+	 */
+	asm volatile (
+	"       move.4  a3, %0					\n\t"
+
+		/* set src1 from the target thread */
+	"       move.4  csr, %1					\n\t"
+	"	setcsr_flush 0					\n\t"
+	"	setcsr_flush 0					\n\t"
+
+		/* copy state from the other thread */
+	"       move.4  "D(PT_D0)"(a3), d0			\n\t"
+	"       move.4  "D(PT_D1)"(a3), d1			\n\t"
+	"       move.4  "D(PT_D2)"(a3), d2			\n\t"
+	"       move.4  "D(PT_D3)"(a3), d3			\n\t"
+	"       move.4  "D(PT_D4)"(a3), d4			\n\t"
+	"       move.4  "D(PT_D5)"(a3), d5			\n\t"
+	"       move.4  "D(PT_D6)"(a3), d6			\n\t"
+	"       move.4  "D(PT_D7)"(a3), d7			\n\t"
+	"       move.4  "D(PT_D8)"(a3), d8			\n\t"
+	"       move.4  "D(PT_D9)"(a3), d9			\n\t"
+	"       move.4  "D(PT_D10)"(a3), d10			\n\t"
+	"       move.4  "D(PT_D11)"(a3), d11			\n\t"
+	"       move.4  "D(PT_D12)"(a3), d12			\n\t"
+	"       move.4  "D(PT_D13)"(a3), d13			\n\t"
+	"       move.4  "D(PT_D14)"(a3), d14			\n\t"
+	"       move.4  "D(PT_D15)"(a3), d15			\n\t"
+	"       move.4  "D(PT_A0)"(a3), a0			\n\t"
+	"       move.4  "D(PT_A1)"(a3), a1			\n\t"
+	"       move.4  "D(PT_A2)"(a3), a2			\n\t"
+	"       move.4  "D(PT_A3)"(a3), a3			\n\t"
+	"       move.4  "D(PT_A4)"(a3), a4			\n\t"
+	"       move.4  "D(PT_A5)"(a3), a5			\n\t"
+	"       move.4  "D(PT_A6)"(a3), a6			\n\t"
+	"       move.4  "D(PT_SP)"(a3), a7			\n\t"
+	"       move.4  "D(PT_ACC0HI)"(a3), acc0_hi		\n\t"
+	"       move.4  "D(PT_ACC0LO)"(a3), acc0_lo		\n\t"
+	"       move.4  "D(PT_MAC_RC16)"(a3), mac_rc16		\n\t"
+	"       move.4  "D(PT_ACC1HI)"(a3), acc1_hi		\n\t"
+	"       move.4  "D(PT_ACC1LO)"(a3), acc1_lo		\n\t"
+	"       move.4  "D(PT_SOURCE3)"(a3), source3		\n\t"
+	"       move.4  "D(PT_INST_CNT)"(a3), inst_cnt		\n\t"
+	"       move.4  "D(PT_CSR)"(a3), csr			\n\t"
+	"       move.4  "D(PT_DUMMY_UNUSED)"(a3), #0		\n\t"
+	"       move.4  "D(PT_INT_MASK0)"(a3), int_mask0	\n\t"
+	"       move.4  "D(PT_INT_MASK1)"(a3), int_mask1	\n\t"
+	"       move.4  "D(PT_TRAP_CAUSE)"(a3), trap_cause	\n\t"
+	"       move.4  "D(PT_PC)"(a3), pc			\n\t"
+	"	move.4	"D(PT_PREVIOUS_PC)"(a3), previous_pc	\n\t"
+		/* disable csr thread select */
+	"       movei   csr, #0					\n\t"
+	"       setcsr_flush 0					\n\t"
+	:
+	: "r" (regs->dn), "d" ((thread << 9) | (1 << 8))
+	: "a3"
+	);
+}
+
+/*
+ * ldsr_rotate_threads()
+ *	Simple round robin algorithm for choosing the next cpu
+ */
+static int ldsr_rotate_threads(unsigned long cpus)
+{
+	static unsigned char ldsr_bits[8] = {
+		3, 0, 1, 0, 2, 0, 1, 0
+	};
+
+	static int nextbit;
+	int thisbit;
+
+	/*
+	 * Move the interrupts down so that we consider interrupts from where
+	 * we left off, then take the interrupts we would lose and move them
+	 * to the top half of the interrupts value.
+	 */
+	cpus = (cpus >> nextbit) | (cpus << ((sizeof(cpus) * 8) - nextbit));
+
+	/*
+	 * 50% of the time we won't take this at all and then of the cases where
+	 * we do about 50% of those we only execute once.
+	 */
+	if (!(cpus & 0xffff)) {
+		nextbit += 16;
+		cpus >>= 16;
+	}
+
+	if (!(cpus & 0xff)) {
+		nextbit += 8;
+		cpus >>= 8;
+	}
+
+	if (!(cpus & 0xf)) {
+		nextbit += 4;
+		cpus >>= 4;
+	}
+
+	nextbit += ldsr_bits[cpus & 0x7];
+	thisbit = (nextbit & ((sizeof(cpus) * 8) - 1));
+	nextbit = (thisbit + 1) & ((sizeof(cpus) * 8) - 1);
+	DEBUG_ASSERT(thisbit < THREAD_ARCHITECTURAL_MAX);
+	return thisbit;
+}
+
+/*
+ * ldsr_rotate_interrupts()
+ *	Get rotating next set bit value.
+ */
+static int ldsr_rotate_interrupts(unsigned long long interrupts)
+{
+	static unsigned char ldsr_bits[8] = {
+		3, 0, 1, 0, 2, 0, 1, 0
+	};
+
+	static int nextbit;
+	int thisbit;
+
+	/*
+	 * Move the interrupts down so that we consider interrupts from where
+	 * we left off, then take the interrupts we would lose and move them
+	 * to the top half of the interrupts value.
+	 */
+	interrupts = (interrupts >> nextbit) |
+		(interrupts << ((sizeof(interrupts) * 8) - nextbit));
+
+	/*
+	 * 50% of the time we won't take this at all and then of the cases where
+	 * we do about 50% of those we only execute once.
+	 */
+	if (!(interrupts & 0xffffffff)) {
+		nextbit += 32;
+		interrupts >>= 32;
+	}
+
+	if (!(interrupts & 0xffff)) {
+		nextbit += 16;
+		interrupts >>= 16;
+	}
+
+	if (!(interrupts & 0xff)) {
+		nextbit += 8;
+		interrupts >>= 8;
+	}
+
+	if (!(interrupts & 0xf)) {
+		nextbit += 4;
+		interrupts >>= 4;
+	}
+
+	nextbit += ldsr_bits[interrupts & 0x7];
+	thisbit = (nextbit & ((sizeof(interrupts) * 8) - 1));
+	nextbit = (thisbit + 1) & ((sizeof(interrupts) * 8) - 1);
+
+	DEBUG_ASSERT(thisbit < (sizeof(interrupts) * 8));
+	return thisbit;
+}
+
+/*
+ * ldsr_backout_or_irq()
+ *
+ * One way or the other this interrupt is not being
+ * processed, make sure that it is reset.  We are
+ * not going to call irq_end_vector() so unmask the
+ * interrupt.
+ */
+static void ldsr_backout_of_irq(int vector, unsigned long tid_mask)
+{
+#if defined(CONFIG_SMP)
+	if (unlikely(vector == smp_ipi_irq)) {
+		smp_reset_ipi(tid_mask);
+	}
+#endif
+	ldsr_unmask_vector(vector);
+	ldsr_interrupt.backout++;
+}
+
+#if defined(CONFIG_IRQSTACKS)
+/*
+ * ldsr_choose_savearea_and_returnvec()
+ *	Test our current state (user, kernel, interrupt) and set things up.
+ *
+ * This version of the function uses 3 stacks and nests interrupts
+ * on the interrupt stack.
+ */
+static struct pt_regs *ldsr_choose_savearea_and_returnvec(thread_t tid, u32_t linux_sp, u32_t *pvec)
+{
+	struct pt_regs *save_area;
+	u32_t masked_linux_sp = linux_sp & ~(THREAD_SIZE - 1);
+	struct thread_info * ti= (struct thread_info *)sw_ksp[tid];
+
+#if defined(CONFIG_SMP)
+	union irq_ctx *icp = percpu_irq_ctxs[tid];
+#else
+	union irq_ctx *icp = percpu_irq_ctxs[0];
+#endif
+
+	if (masked_linux_sp == (u32_t)icp) {
+		/*
+		 * Fault/Interrupt occurred while on the interrupt stack.
+		 */
+		save_area = (struct pt_regs *)((char *)linux_sp - sizeof(struct pt_regs) - 8);
+		*pvec = (u32_t)(&ret_from_interrupt_to_kernel);
+	} else {
+		/*
+		 *  Fault/Interrupt occurred while on user/kernel stack.  This is a new
+		 *  first use of the interrupt stack.
+		 */
+		save_area = (struct pt_regs *) ((char *)icp + sizeof(icp->stack) - sizeof(struct pt_regs) - 8);
+		if (masked_linux_sp == (u32_t)ti) {
+			*pvec  = (u32_t)(&ret_from_interrupt_to_kernel);
+		} else {
+			*pvec  = (u32_t)(&ret_from_interrupt_to_user);
+		}
+
+		/*
+		 * Because the softirq code will execute on the "interrupt" stack, we
+		 * need to maintain the knowledge of what "task" was executing on the
+		 * cpu.  This is done by copying the thread_info->task from the cpu
+		 * we are about to context switch into the interrupt contexts thread_info
+		 * structure.
+		 */
+		icp->tinfo.task = ti->task;
+		icp->tinfo.preempt_count =
+				(icp->tinfo.preempt_count & ~SOFTIRQ_MASK) |
+				(ti->preempt_count & SOFTIRQ_MASK);
+		icp->tinfo.interrupt_nesting = 0;
+	}
+	save_area->nesting_level = icp->tinfo.interrupt_nesting;
+	return save_area;
+}
+
+#else
+/*
+ * ldsr_choose_savearea_and_returnvec()
+ *	Test our current state (user, kernel, interrupt) and set things up.
+ *
+ * The version of the function uses just the user & kernel stack and
+ * nests interrupts on the existing kernel stack.
+ */
+static struct pt_regs *ldsr_choose_savearea_and_returnvec(thread_t tid, u32_t linux_sp, u32_t *pvec)
+{
+	struct pt_regs *save_area;
+	u32_t masked_linux_sp = linux_sp & ~(THREAD_SIZE - 1);
+	struct thread_info *ti = (struct thread_info *)sw_ksp[tid];
+
+	if (masked_linux_sp == (u32_t)ti) {
+		/*
+		 * Fault/Interrupt occurred while on the kernel stack.
+		 */
+		save_area = (struct pt_regs *)((char *)linux_sp - sizeof(struct pt_regs) - 8);
+		*pvec = (u32_t) (&ret_from_interrupt_to_kernel);
+	} else {
+		/*
+		 *  Fault/Interrupt occurred while on user stack.
+		 */
+		ti->interrupt_nesting = 0;
+		save_area = (struct pt_regs *)((u32_t)ti + THREAD_SIZE - sizeof(struct pt_regs) - 8);
+		*pvec  = (u32_t) (&ret_from_interrupt_to_user);
+	}
+	save_area->nesting_level = ti->interrupt_nesting;
+	return save_area;
+}
+#endif
+
+/*
+ * ldsr_ctxsw_thread()
+ *	Context switch a mainline thread to execute do_IRQ() for the specified
+ *	vector.
+ */
+static void ldsr_ctxsw_thread(int vector, thread_t tid)
+{
+	u32_t linux_sp;
+	u32_t return_vector;
+	struct pt_regs *save_area, *regs;
+	u32_t thread_mask = (1 << tid);
+	u32_t read_csr = ((tid << 9) | (1 << 8));
+	u32_t write_csr = (tid << 15) | (1 << 14);
+	u32_t interrupt_vector = (u32_t)(&do_IRQ);
+
+	unsigned int frame_type = UBICOM32_FRAME_TYPE_INTERRUPT;
+
+
+	DEBUG_ASSERT(!thread_is_enabled(tid));
+
+	/*
+	 * Acquire the necessary global and per thread locks for tid.
+	 * As a side effect, we ensure that the thread has not trapped
+	 * and return true if it has.
+	 */
+	if (unlikely(thread_is_trapped(tid))) {
+		/*
+		 * Read the trap cause, the sp and clear the MT_TRAP bits.
+		 */
+		unsigned int cause;
+		asm volatile (
+		"	setcsr	%3		\n\t"
+		"	setcsr_flush 0		\n\t"
+		"	setcsr_flush 0		\n\t"
+		"	move.4	%0, TRAP_CAUSE	\n\t"
+		"	move.4	%1, SP		\n\t"
+		"	setcsr	#0		\n\t"
+		"	setcsr_flush 0		\n\t"
+		"	move.4	MT_BREAK_CLR, %2\n\t"
+		"	move.4	MT_TRAP_CLR, %2	\n\t"
+			: "=&r" (cause), "=&r" (linux_sp)
+			: "r" (thread_mask), "m" (read_csr)
+		);
+
+		ldsr_backout_of_irq(vector, (1 << tid));
+
+#if !defined(CONFIG_UNALIGNED_ACCESS_DISABLED)
+		/*
+		 * See if the unaligned trap handler can deal with this.
+		 * If so, emulate the instruction and then just restart
+		 * the thread.
+		 */
+		if (unaligned_only(cause)) {
+#if defined(CONFIG_UNALIGNED_ACCESS_USERSPACE_ONLY)
+			/*
+			 * Check if this is a kernel stack if so we will not
+			 * handle the trap
+			 */
+			u32_t masked_linux_sp = linux_sp & ~(THREAD_SIZE - 1);
+			if ((masked_linux_sp != (u32_t)sw_ksp[tid]) &&
+			    unaligned_only(cause)) {
+				ldsr_emulate_and_run(tid);
+				return;
+			}
+#else
+			ldsr_emulate_and_run(tid);
+			return;
+#endif
+
+		}
+#endif
+
+		interrupt_vector = (u32_t)(&trap_handler);
+		frame_type = UBICOM32_FRAME_TYPE_TRAP;
+	} else {
+		/*
+		 * Read the target thread's SP
+		 */
+		asm volatile (
+		"	setcsr	%1		\n\t"
+		"	setcsr_flush 0		\n\t"
+		"	setcsr_flush 0		\n\t"
+		"	move.4	%0, SP		\n\t"
+		"	setcsr	#0		\n\t"
+		"	setcsr_flush 0		\n\t"
+			: "=m" (linux_sp)
+			: "m" (read_csr)
+		);
+	}
+
+	/*
+	 * We are delivering an interrupt, count it.
+	 */
+	ldsr_interrupt.total++;
+
+	/*
+	 * At this point, we will definitely force this thread to
+	 * a new context, show its interrupts as disabled.
+	 */
+	ldsr_thread_irq_disable(tid);
+
+	/*
+	 * Test our current state (user, kernel, interrupt).  Save the
+	 * appropriate data and setup for the return.
+	 */
+	save_area = ldsr_choose_savearea_and_returnvec(tid, linux_sp, &return_vector);
+
+	/*
+	 *  The pt_regs (save_area) contains the type of thread that we are dealing
+	 *  with (KERNEL/NORMAL) and is copied into each pt_regs area.  We get this
+	 *  from the current tasks kernel pt_regs area that always exists at the
+	 *  top of the kernel stack.
+	 */
+	regs = (struct pt_regs *)((u32_t)sw_ksp[tid] + THREAD_SIZE - sizeof(struct pt_regs) - 8);
+	save_area->thread_type = regs->thread_type;
+
+	/*
+	 * Preserve the context of the Linux thread.
+	 */
+	ldsr_preemptive_context_save(tid, save_area);
+
+	/*
+	 * Load the fram_type into the save_area.
+	 */
+	save_area->frame_type = frame_type;
+
+#ifdef CONFIG_STOP_ON_TRAP
+	/*
+	 * Before we get backtrace and showing stacks working well, it sometimes
+	 * helps to enter the debugger when a trap occurs before we change the
+	 * thread to handle the fault.  This optional code causes all threads to
+	 * stop on every trap frame.  One assumes that GDB connected via the
+	 * mailbox interface will be used to recover from this state.
+	 */
+	if (frame_type == UBICOM32_FRAME_TYPE_TRAP) {
+		THREAD_STALL;
+	}
+#endif
+
+#ifdef DEBUG_LDSR
+	copy_regs = *save_area;
+	copy_save_area = save_area;
+
+	old_a0 = save_area->an[0];
+	old_a3 = save_area->an[3];
+	old_sp = save_area->an[7];
+	old_a5 = save_area->an[5];
+	old_pc = save_area->pc;
+#endif
+
+	/*
+	 * Now we have to switch the kernel thread to run do_IRQ function.
+	 *	Set pc to do_IRQ
+	 *	Set d0 to vector
+	 *	Set d1 to save_area.
+	 *	Set a5 to the proper return vector.
+	 */
+	asm volatile (
+	"	setcsr	%0			\n\t"
+	"	setcsr_flush 0			\n\t"
+	"	move.4	d0, %5			\n\t" /* d0 = 0 vector # */
+	"	move.4	d1, %1			\n\t" /* d1 = save_area */
+	"	move.4	sp, %1			\n\t" /* sp = save_area */
+	"	move.4	a5, %2			\n\t" /* a5 = return_vector */
+	"	move.4	pc, %3			\n\t" /* pc = do_IRQ routine. */
+	"	move.4	trap_cause, #0		\n\t" /* Clear the trap cause
+						       * register */
+	"	setcsr	#0			\n\t"
+	"	setcsr_flush 0			\n\t"
+	"	enable_kernel_ranges %4		\n\t"
+	"	move.4	mt_dbg_active_set, %4	\n\t" /* Activate thread even if
+						       * in dbg/fault state */
+	"	move.4	mt_active_set, %4	\n\t" /* Restart target
+						       * thread. */
+		:
+		: "r" (write_csr), "r" (save_area),
+		  "r" (return_vector), "r" (interrupt_vector),
+		  "d" (thread_mask), "r" (vector)
+		: "cc"
+	);
+	thread_enable_mask(thread_mask);
+}
+
+/*
+ * ldsr_deliver_interrupt()
+ *	Deliver the interrupt to one of the threads or all of the threads.
+ */
+static void ldsr_deliver_interrupt(int vector,
+				   unsigned long deliver_to,
+				   int all)
+{
+	unsigned long disabled_threads;
+	unsigned long possible_threads;
+	unsigned long trapped_threads;
+	unsigned long global_locks;
+
+	/*
+	 * Disable all of the threads that we might want to send
+	 * this interrupt to.
+	 */
+retry:
+	DEBUG_ASSERT(deliver_to);
+	thread_disable_mask(deliver_to);
+
+	/*
+	 * If any threads are in the trap state, we have to service the
+	 * trap for those threads first.
+	 */
+	asm volatile (
+		"move.4	%0, MT_TRAP		\n\t"
+		: "=r" (trapped_threads)
+		:
+	);
+
+	trapped_threads &= deliver_to;
+	if (unlikely(trapped_threads)) {
+		/*
+		 * all traps will be handled, so clear the trap bit before restarting any threads
+		 */
+	        ubicom32_clear_interrupt(ldsr_trap_irq);
+
+		/*
+		 * Let the remaining untrapped threads, continue.
+		 */
+		deliver_to &= ~trapped_threads;
+		if (deliver_to) {
+			thread_enable_mask(deliver_to);
+		}
+
+		/*
+		 * For the trapped threads force them to handle
+		 * a trap.
+		 */
+		while (trapped_threads) {
+			unsigned long which = ffz(~trapped_threads);
+			trapped_threads &= ~(1 << which);
+			ldsr_ctxsw_thread(vector, which);
+		}
+		return;
+	}
+
+	/*
+	 * Can we deliver an interrupt to any of the threads?
+	 */
+	disabled_threads = ldsr_thread_get_interrupts();
+	possible_threads = deliver_to & ~disabled_threads;
+	if (unlikely(!possible_threads)) {
+#if defined(CONFIG_SMP)
+		/*
+		 * In the SMP case, we can not wait because 1 cpu might be
+		 * sending an IPI to another cpu which is currently blocked.
+		 * The only way to ensure IPI delivery is to backout and
+		 * keep trying.  For SMP, we don't sleep until the interrupts
+		 * are delivered.
+		 */
+		thread_enable_mask(deliver_to);
+		ldsr_backout_of_irq(vector, deliver_to);
+		return;
+#else
+		/*
+		 * In the UP case, we have nothing to do so we should wait.
+		 *
+		 * Since the INT_MASK0 and INT_MASK1 are "re-loaded" before we
+		 * suspend in the outer loop, we do not need to save them here.
+		 *
+		 * We test that we were awakened for our specific interrupts
+		 * because the ldsr mask/unmask operations will force the ldsr
+		 * awake even if the interrupt on the mainline thread is not
+		 * completed.
+		 */
+		unsigned int scratch = 0;
+		thread_enable_mask(deliver_to);
+		asm volatile (
+		"	move.4	INT_MASK0, %1		\n\t"
+		"	move.4	INT_MASK1, #0		\n\t"
+
+		"1:	suspend				\n\t"
+		"	move.4	%0, INT_STAT0		\n\t"
+		"	and.4	%0, %0, %1		\n\t"
+		"	jmpeq.f	1b			\n\t"
+
+		"	move.4	INT_CLR0, %2		\n\t"
+			: "+r" (scratch)
+			: "d" (ldsr_suspend_mask), "r" (ldsr_soft_irq_mask)
+			: "cc"
+		);
+
+		/*
+		 * This delay is sized to coincide with the time it takes a
+		 * thread to complete the exit (see return_from_interrupt).
+		 */
+		ldsr_interrupt.retry++;
+		__delay(10);
+		goto retry;
+#endif
+	}
+
+	/*
+	 * If any of the global locks are held, we can not deliver any
+	 * interrupts, we spin delay(10) and then try again.  If our
+	 * spinning becomes a bottle neck, we will need to suspend but for
+	 * now lets just spin.
+	 */
+	asm volatile (
+		"move.4	%0, scratchpad1		\n\t"
+		: "=r" (global_locks)
+		:
+	);
+	if (unlikely(global_locks & 0xffff0000)) {
+		thread_enable_mask(deliver_to);
+
+		/*
+		 * This delay is sized to coincide with the average time it
+		 * takes a thread to release a global lock.
+		 */
+		ldsr_interrupt.retry++;
+		__delay(10);
+		goto retry;
+	}
+
+	/*
+	 * Deliver to one cpu.
+	 */
+	if (!all) {
+		/*
+		 * Find our victim and then enable everyone else.
+		 */
+		unsigned long victim = ldsr_rotate_threads(possible_threads);
+		DEBUG_ASSERT((deliver_to & (1 << victim)));
+		DEBUG_ASSERT((possible_threads & (1 << victim)));
+
+		deliver_to &= ~(1 << victim);
+		if (deliver_to) {
+			thread_enable_mask(deliver_to);
+		}
+		ldsr_ctxsw_thread(vector, victim);
+		return;
+	}
+
+	/*
+	 * If we can't deliver to some threads, wake them
+	 * back up and reset things to deliver to them.
+	 */
+	deliver_to &= ~possible_threads;
+	if (unlikely(deliver_to)) {
+		thread_enable_mask(deliver_to);
+		ldsr_backout_of_irq(vector, deliver_to);
+	}
+
+	/*
+	 * Deliver to all possible threads(s).
+	 */
+	while (possible_threads) {
+		unsigned long victim = ffz(~possible_threads);
+		possible_threads &= ~(1 << victim);
+		ldsr_ctxsw_thread(vector, victim);
+	}
+}
+
+/*
+ * ldsr_thread()
+ *	This thread acts as the interrupt controller for Linux.
+ */
+static void ldsr_thread(void *arg)
+{
+	int stat0;
+	int stat1;
+	int interrupt0;
+	int interrupt1;
+	long long interrupts;
+	unsigned long cpus;
+
+#if !defined(CONFIG_SMP)
+	/*
+	 * In a non-smp configuration, we can not use the cpu(s) arrays because
+	 * there is not a 1-1 correspondence between cpus(s) and our threads.
+	 * Thus we must get a local idea of the mainline threads and use the
+	 * one and only 1 set as the victim.  We do this once before the ldsr
+	 * loop.
+	 *
+	 * In the SMP case, we will use the cpu(s) map to determine which cpu(s)
+	 * are valid to send interrupts to.
+	 */
+	int victim = 0;
+	unsigned int mainline = thread_get_mainline();
+	if (mainline == 0) {
+		panic("no mainline Linux threads to interrupt");
+		return;
+	}
+	victim = ffz(~mainline);
+	cpus = (1 << victim);
+#endif
+
+	while (1) {
+		/*
+		 * If one changes this code not to reload the INT_MASK(s), you
+		 * need to know that code in the lock waiting above does not
+		 * reset the MASK registers back; so that code will need to be
+		 * changed.
+		 */
+		ldsr_lock_acquire();
+		asm volatile (
+		"	move.4 INT_MASK0, %0	\n\t"
+		"	move.4 INT_MASK1, %1	\n\t"
+			:
+			: "U4" (ldsr_interrupt.mask0), "U4" (ldsr_interrupt.mask1)
+		);
+		ldsr_lock_release();
+		thread_suspend();
+
+		/*
+		 * Read the interrupt status registers
+		 */
+		asm volatile (
+			"move.4 %0, INT_STAT0	\n\t"
+			"move.4 %1, INT_STAT1	\n\t"
+			: "=r" (stat0), "=r" (stat1)
+			:
+		);
+
+		/*
+		 * We only care about interrupts that we have been told to care
+		 * about.  The interrupt must be enabled, unmasked, and have
+		 * occurred in the hardware.
+		 */
+		ldsr_lock_acquire();
+		interrupt0 = ldsr_interrupt.enabled0 &
+			ldsr_interrupt.mask0 & stat0;
+		interrupt1 = ldsr_interrupt.enabled1 &
+			ldsr_interrupt.mask1 & stat1;
+		ldsr_lock_release();
+
+		/*
+		 * For each interrupt in the "snapshot" we will mask the
+		 * interrupt handle the interrupt (typically calling do_IRQ()).
+		 *
+		 * The interrupt is unmasked by desc->chip->end() function in
+		 * the per chip generic interrupt handling code
+		 * (arch/ubicom32/kernel/irq.c).8
+		 */
+		interrupts = ((unsigned long long)interrupt1 << 32) |
+			interrupt0;
+		while (interrupts) {
+			int all = 0;
+			int vector = ldsr_rotate_interrupts(interrupts);
+			interrupts &= ~((unsigned long long)1 << vector);
+
+			/*
+			 * Now mask off this vector so that the LDSR ignores
+			 * it until it is acknowledged.
+			 */
+			ldsr_mask_vector(vector);
+#if !defined(CONFIG_SMP)
+			ldsr_deliver_interrupt(vector, cpus, all);
+#else
+			cpus = smp_get_affinity(vector, &all);
+			if (cpus) {
+				ldsr_deliver_interrupt(vector, cpus, all);
+			}
+#endif
+		}
+	}
+
+	/* NOTREACHED */
+}
+
+/*
+ * ldsr_mask_vector()
+ *	Temporarily mask the interrupt vector, turn off the bit in the mask
+ *	register.
+ */
+void ldsr_mask_vector(unsigned int vector)
+{
+	unsigned int mask;
+	if (vector < 32) {
+		mask = ~(1 << vector);
+		ldsr_lock_acquire();
+		ldsr_interrupt.mask0 &= mask;
+		ldsr_lock_release();
+		thread_resume(ldsr_tid);
+		return;
+	}
+
+	mask = ~(1 << (vector - 32));
+	ldsr_lock_acquire();
+	ldsr_interrupt.mask1 &= mask;
+	ldsr_lock_release();
+	thread_resume(ldsr_tid);
+}
+
+/*
+ * ldsr_unmask_vector()
+ *	Unmask the interrupt vector so that it can be used, turn on the bit in
+ *	the mask register.
+ *
+ * Because it is legal for the interrupt path to disable an interrupt,
+ * the unmasking code must ensure that disabled interrupts are not
+ * unmasked.
+ */
+void ldsr_unmask_vector(unsigned int vector)
+{
+	unsigned int mask;
+	if (vector < 32) {
+		mask = (1 << vector);
+		ldsr_lock_acquire();
+		ldsr_interrupt.mask0 |= (mask & ldsr_interrupt.enabled0);
+		ldsr_lock_release();
+		thread_resume(ldsr_tid);
+		return;
+	}
+
+	mask = (1 << (vector - 32));
+	ldsr_lock_acquire();
+	ldsr_interrupt.mask1 |= (mask & ldsr_interrupt.enabled1);
+	ldsr_lock_release();
+	thread_resume(ldsr_tid);
+}
+
+/*
+ * ldsr_enable_vector()
+ *	The LDSR implements an interrupt controller and has a local (to the
+ *	LDSR) copy of its interrupt mask.
+ */
+void ldsr_enable_vector(unsigned int vector)
+{
+	unsigned int mask;
+	if (vector < 32) {
+		mask = (1 << vector);
+		ldsr_lock_acquire();
+		ldsr_interrupt.enabled0 |= mask;
+		ldsr_interrupt.mask0 |= mask;
+		ldsr_lock_release();
+		thread_resume(ldsr_tid);
+		return;
+	}
+
+	mask = (1 << (vector - 32));
+	ldsr_lock_acquire();
+	ldsr_interrupt.enabled1 |= mask;
+	ldsr_interrupt.mask1 |= mask;
+	ldsr_lock_release();
+	thread_resume(ldsr_tid);
+}
+
+/*
+ * ldsr_disable_vector()
+ *	The LDSR implements an interrupt controller and has a local (to the
+ *	LDSR) copy of its interrupt mask.
+ */
+void ldsr_disable_vector(unsigned int vector)
+{
+	unsigned int mask;
+
+	if (vector < 32) {
+		mask = ~(1 << vector);
+		ldsr_lock_acquire();
+		ldsr_interrupt.enabled0 &= mask;
+		ldsr_interrupt.mask0 &= mask;
+		ldsr_lock_release();
+		thread_resume(ldsr_tid);
+		return;
+	}
+
+	mask = ~(1 << (vector - 32));
+	ldsr_lock_acquire();
+	ldsr_interrupt.enabled1 &= mask;
+	ldsr_interrupt.mask1 &= mask;
+	ldsr_lock_release();
+	thread_resume(ldsr_tid);
+}
+
+/*
+ * ldsr_get_threadid()
+ *	Return the threadid of the LDSR thread.
+ */
+thread_t ldsr_get_threadid(void)
+{
+	return ldsr_tid;
+}
+
+/*
+ * ldsr_set_trap_irq()
+ *	Save away the trap Soft IRQ
+ *
+ * See the per thread lock suspend code above for an explination.
+ */
+void ldsr_set_trap_irq(unsigned int irq)
+{
+	ldsr_trap_irq = irq;
+	ldsr_trap_irq_mask = (1 << irq);
+	ldsr_suspend_mask |= ldsr_trap_irq_mask;
+}
+
+/*
+ * ldsr_init()
+ *	Initialize the LDSR (Interrupt Controller)
+ */
+void ldsr_init(void)
+{
+#if defined(CONFIG_IRQSTACKS)
+	int i;
+	union irq_ctx *icp;
+#endif
+
+	void *stack_high = (void *)ldsr_stack_space;
+	stack_high += sizeof(ldsr_stack_space);
+	stack_high -= 8;
+
+
+	/*
+	 * Obtain a soft IRQ to use
+	 */
+	if (irq_soft_alloc(&ldsr_soft_irq) < 0) {
+		panic("no software IRQ is available\n");
+		return;
+	}
+	ldsr_soft_irq_mask |= (1 << ldsr_soft_irq);
+	ldsr_suspend_mask |= ldsr_soft_irq_mask;
+
+	/*
+	 * Now allocate and start the LDSR thread.
+	 */
+	ldsr_tid = thread_alloc();
+	if (ldsr_tid < 0) {
+		panic("no thread available to run LDSR");
+		return;
+	}
+
+#if defined(CONFIG_IRQSTACKS)
+	/*
+	 * Initialize the per-cpu irq thread_info structure that
+	 * is at the top of each per-cpu irq stack.
+	 */
+	icp = (union irq_ctx *)
+		(((unsigned long)percpu_irq_stacks + (THREAD_SIZE - 1)) & ~(THREAD_SIZE - 1));
+	for (i = 0; i < NR_CPUS; i++) {
+		struct thread_info *ti = &(icp->tinfo);
+		ti->task = NULL;
+		ti->exec_domain = NULL;
+		ti->cpu = i;
+		ti->preempt_count = 0;
+		ti->interrupt_nesting = 0;
+		percpu_irq_ctxs[i] = icp++;
+	}
+#endif
+	thread_start(ldsr_tid, ldsr_thread, NULL,
+		     stack_high, THREAD_TYPE_NORMAL);
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/Makefile
@@ -0,0 +1,64 @@
+#
+# arch/ubicom32/kernel/Makefile
+#	Main Makefile for the Ubicom32 arch directory.
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+extra-y := head.o vmlinux.lds
+
+obj-y += \
+	devtree.o \
+	dma.o \
+	flat.o \
+	init_task.o \
+	irq.o \
+	ldsr.o \
+	os_node.o \
+	process.o \
+	processor.o \
+	ptrace.o \
+	setup.o \
+	signal.o \
+	stacktrace.o \
+	sys_ubicom32.o \
+	syscalltable.o \
+	thread.o \
+	time.o \
+	traps.o \
+	ubicom32_context_switch.o \
+	ubicom32_ksyms.o \
+	ubicom32_syscall.o \
+	unaligned_trap.o
+
+obj-$(CONFIG_MODULES)				+= module.o
+obj-$(CONFIG_COMEMPCI)				+= comempci.o
+obj-$(CONFIG_SMP)				+= smp.o topology.o
+obj-$(CONFIG_ACCESS_OK_CHECKS_ENABLED)		+= uaccess.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= timer_device.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)	+= timer_broadcast.o
+
+ifndef CONFIG_GENERIC_CLOCKEVENTS
+obj-y			+= timer_tick.o
+endif
--- /dev/null
+++ b/arch/ubicom32/kernel/module.c
@@ -0,0 +1,463 @@
+/*
+ * arch/ubicom32/kernel/module.c
+ *   Ubicom32 architecture loadable module support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/moduleloader.h>
+#include <linux/bug.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <asm/ocm-alloc.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt...)
+#endif
+
+static void _module_free_ocm(struct module *mod)
+{
+	printk(KERN_INFO "module arch cleanup %s: OCM instruction memory free "
+	       " of %d @%p\n", mod->name, mod->arch.ocm_inst_size,
+	       mod->arch.ocm_inst);
+
+	if (mod->arch.ocm_inst) {
+		ocm_inst_free(mod->arch.ocm_inst);
+		mod->arch.ocm_inst = 0;
+		mod->arch.ocm_inst_size = 0;
+	}
+}
+
+void *module_alloc(unsigned long size)
+{
+	if (size == 0)
+		return NULL;
+	return vmalloc(size);
+}
+
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+	vfree(module_region);
+	/* FIXME: If module_region == mod->init_region, trim exception
+	   table entries. */
+
+	/*
+	 * This is expected to be final module free, use this to prune the
+	 * ocm
+	 */
+	if (module_region && module_region == mod->module_core)
+		_module_free_ocm(mod);
+
+}
+
+/*
+ * module_frob_arch_sections()
+ *	Called from kernel/module.c allowing arch specific handling of
+ *	sections/headers.
+ */
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+			      Elf_Shdr *sechdrs,
+			      char *secstrings,
+			      struct module *mod)
+{
+	Elf_Shdr *s, *sechdrs_end;
+	void *ocm_inst = NULL;
+	int ocm_inst_size = 0;
+
+	/*
+	 * Ubicom32 v3 and v4 are almost binary compatible but not completely.
+	 * To be safe check that the module was compiled with the correct -march
+	 * which is flags.
+	 */
+#ifdef CONFIG_UBICOM32_V4
+	if ((hdr->e_flags & 0xFFFF) != EF_UBICOM32_V4) {
+		printk(KERN_WARNING "Module %s was not compiled for "
+		       "ubicom32v4, elf_flags:%x,\n",
+		       mod->name, hdr->e_flags);
+		return -ENOEXEC;
+	}
+#elif defined CONFIG_UBICOM32_V3
+	if ((hdr->e_flags & 0xFFFF) != EF_UBICOM32_V3) {
+		printk(KERN_WARNING "Module %s was not compiled for "
+		       "ubicom32v3, elf_flags:%x\n",
+		       mod->name, hdr->e_flags);
+		return -ENOEXEC;
+	}
+#else
+#error Unknown/Unsupported ubicom32 architecture.
+#endif
+
+	/*
+	 * XXX: sechdrs are vmalloced in kernel/module.c
+	 * and would be vfreed just after module is loaded,
+	 * so we hack to keep the only information we needed
+	 * in mod->arch to correctly free L1 I/D sram later.
+	 * NOTE: this breaks the semantic of mod->arch structure.
+	 */
+	sechdrs_end = sechdrs + hdr->e_shnum;
+	for (s = sechdrs; s < sechdrs_end; ++s) {
+		if (strncmp(".ocm_text", secstrings + s->sh_name, 9) == 0)
+			ocm_inst_size += s->sh_size;
+	}
+
+	if (!ocm_inst_size)
+		return 0;
+
+	ocm_inst = ocm_inst_alloc(ocm_inst_size, 0 /* internal */);
+	if (ocm_inst == NULL) {
+#ifdef CONFIG_OCM_MODULES_FALLBACK_TO_DDR
+		printk(KERN_WARNING
+		       "module %s: OCM instruction memory allocation of %d"
+		       "failed, fallback to DDR\n", mod->name, ocm_inst_size);
+		return 0;
+#else
+		printk(KERN_ERR
+		       "module %s: OCM instruction memory allocation of %d"
+		       "failed.\n", mod->name, ocm_inst_size);
+		return -ENOMEM;
+#endif
+	}
+
+	mod->arch.ocm_inst = ocm_inst;
+	mod->arch.ocm_inst_size = ocm_inst_size;
+
+	printk(KERN_INFO
+	       "module %s: OCM instruction memory allocation of %d @%p\n",
+	       mod->name, mod->arch.ocm_inst_size, mod->arch.ocm_inst);
+
+	for (s = sechdrs; s < sechdrs_end; ++s) {
+		if (strncmp(".ocm_text", secstrings + s->sh_name, 9) == 0) {
+			memcpy(ocm_inst, (void *)s->sh_addr, s->sh_size);
+			s->sh_flags &= ~SHF_ALLOC;
+			s->sh_addr = (unsigned long)ocm_inst;
+			ocm_inst += s->sh_size;
+		}
+	}
+
+	return 0;
+}
+
+int apply_relocate(Elf32_Shdr *sechdrs,
+		   const char *strtab,
+		   unsigned int symindex,
+		   unsigned int relsec,
+		   struct module *me)
+{
+	DEBUGP("Invalid Applying relocate section %u to %u\n", relsec,
+	       sechdrs[relsec].sh_info);
+	return -EINVAL;
+}
+
+int apply_relocate_add(Elf32_Shdr *sechdrs,
+		       const char *strtab,
+		       unsigned int symindex,
+		       unsigned int relsec,
+		       struct module *me)
+{
+	unsigned int i;
+	Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
+	Elf32_Sym *sym;
+	uint32_t *location;
+	uint32_t insn;
+
+	DEBUGP("Applying relocate_add section %u to %u\n", relsec,
+	       sechdrs[relsec].sh_info);
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
+		uint32_t v;
+		const int elf32_rtype = ELF32_R_TYPE(rel[i].r_info);
+
+		/* This is where to make the change */
+		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
+			+ rel[i].r_offset;
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
+		sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
+			+ ELF32_R_SYM(rel[i].r_info);
+
+		v = rel[i].r_addend + sym->st_value;
+
+
+		switch (elf32_rtype) {
+		case R_UBICOM32_32:
+		{
+			/*
+			 * Store the 32 bit relocation as is.
+			 */
+			*location = v;
+			break;
+		}
+		case R_UBICOM32_HI24:
+		{
+			/*
+			 * 24 bit relocation that is part of the MOVEAI
+			 * instruction. The 24 bits come from bits 7 - 30 of the
+			 * relocation. Theses bits eventually get split into 2
+			 * fields in the instruction encoding.
+			 *
+			 * - Bits 7 - 27 of the relocation are encoded into bits
+			 * 0 - 20 of the instruction.
+			 *
+			 *  - Bits 28 - 30 of the relocation are encoded into
+			 *  bit 24 - 26 of the instruction.
+			 */
+			uint32_t valid24 = (v >> 7) & 0xffffff;
+			insn = *location;
+
+			insn &= ~(0x1fffff | (0x7 << 24));
+			insn |= (valid24 & 0x1fffff);
+			insn |= ((valid24 & 0xe00000) << 3);
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_LO7_S:
+		case R_UBICOM32_LO7_2_S:
+		case R_UBICOM32_LO7_4_S:
+		{
+			/*
+			 * Bits 0 - 6 of the relocation are encoded into the
+			 * 7bit unsigned immediate fields of the SOURCE-1 field
+			 * of the instruction.  The immediate value is left
+			 * shifted by (0, 1, 2) based on the operand size.
+			 */
+			uint32_t valid7 = v & 0x7f;
+			insn = *location;
+
+			if (elf32_rtype == R_UBICOM32_LO7_2_S) {
+				valid7 >>= 1;
+			} else if (elf32_rtype == R_UBICOM32_LO7_4_S) {
+				valid7 >>= 2;
+			}
+
+			insn &= ~(0x1f | (0x3 << 8));
+			insn |= (valid7 & 0x1f);
+			insn |= ((valid7 & 0x60) << 3);
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_LO7_D:
+		case R_UBICOM32_LO7_2_D:
+		case R_UBICOM32_LO7_4_D:
+		{
+			/*
+			 * Bits 0 - 6 of the relocation are encoded into the
+			 * 7bit unsigned immediate fields of the DESTINATION
+			 * field of the instruction.  The immediate value is
+			 * left shifted by (0, 1, 2) based on the operand size.
+			 */
+			uint32_t valid7 = v & 0x7f;
+			insn = *location;
+
+			if (elf32_rtype == R_UBICOM32_LO7_2_D) {
+				valid7 >>= 1;
+			} else if (elf32_rtype == R_UBICOM32_LO7_4_D) {
+				valid7 >>= 2;
+			}
+
+			insn &= ~((0x1f | (0x3 << 8)) << 16);
+			insn |= ((valid7 & 0x1f) << 16);
+			insn |= ((valid7 & 0x60) << 19);
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_LO7_CALLI:
+		case R_UBICOM32_LO16_CALLI:
+		{
+			/*
+			 * Extract the offset for a CALLI instruction. The
+			 * offsets can be either 7 bits or 18 bits. Since all
+			 * instructions in ubicom32 architecture are at work
+			 * aligned addresses the truncated offset is right
+			 * shifted by 2 before being encoded in the instruction.
+			 */
+			uint32_t val;
+			if (elf32_rtype == R_UBICOM32_LO7_CALLI) {
+				val  = v & 0x7f;
+			} else {
+				val  = v & 0x3ffff;
+			}
+
+			val >>= 2;
+
+			insn = *location;
+
+			insn &= ~0x071f071f;
+			insn |= (val & 0x1f) << 0;
+			val >>= 5;
+			insn |= (val & 0x07) << 8;
+			val >>= 3;
+			insn |= (val & 0x1f) << 16;
+			val >>= 5;
+			insn |= (val & 0x07) << 24;
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_24_PCREL:
+		{
+			/*
+			 * Extract 26 bit signed PC relative offset for CALL
+			 * instructions. Since instruction addresses are word
+			 * aligned the offset is right shited by 2 before
+			 * encoding into instruction.
+			 */
+			int32_t val = v - (int32_t)location;
+
+			/*
+			 * Check that the top 7 bits are all equal to the sign
+			 * bit (26), i.e all 0's or all 1's.  If they are not then
+			 * the absolute difference is greater than 25 bits.
+			 */
+			if (((uint32_t)val & 0xFE000000) != 0xFE000000 &&
+				((uint32_t)val & 0xFE000000) != 0x0) {
+				/*
+				 * The relocation is beyond our addressable
+				 * range with a 26 bit call.
+				 */
+				printk(KERN_ERR "module %s: PC Relative "
+					"relocation out of range: "
+					"%u (%x->%x, %x)\n",
+					me->name, elf32_rtype,
+					v, (uint32_t) location, val);
+				return -ENOEXEC;
+			}
+
+			val = (val & 0x3ffffff) >> 2;
+			insn = *location;
+			insn = insn & 0xf8e00000;
+
+			insn |= (val >> 21) << 24;
+			insn |= (val & 0x1fffff);
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_LO16:
+		case R_UBICOM32_HI16:
+		{
+			/*
+			 * 16 bit immediate value that is encoded into bit 0 -
+			 * 15 of the instruction.
+			 */
+			uint32_t val;
+
+			if (elf32_rtype == R_UBICOM32_LO16) {
+				val  = v & 0xffff;
+			} else {
+				val  = (v >> 16) & 0xffff;
+			}
+
+			insn = *location;
+			insn &= 0xffff0000;
+
+			insn |= val;
+			*location = insn;
+		}
+		break;
+		case R_UBICOM32_21_PCREL:
+		{
+			/*
+			 * Extract 23 bit signed PC relative offset for JMP<cc>
+			 * instructions. Since instruction addresses are word
+			 * aligned the offset is right shited by 2 before
+			 * encoding into instruction.
+			 */
+			int32_t val = v - (int32_t)location;
+
+			val = (val & 0x7fffff) >> 2;
+			insn = *location;
+			insn = insn & 0xffe00000;
+
+			insn |= (val >> 21) << 24;
+			insn |= val;
+			*location = insn;
+		}
+		break;
+		default:
+			BUG();
+			printk(KERN_ERR "module %s: Unknown relocation: %u\n",
+			       me->name, elf32_rtype);
+			return -ENOEXEC;
+		}
+	}
+	return 0;
+}
+
+int module_finalize(const Elf_Ehdr *hdr,
+		    const Elf_Shdr *sechdrs,
+		    struct module *mod)
+{
+	unsigned int i, strindex = 0, symindex = 0;
+	char *secstrings;
+	int err;
+
+	err = module_bug_finalize(hdr, sechdrs, mod);
+	if (err)
+		return err;
+
+	if (!mod->arch.ocm_inst) {
+		/*
+		 * No OCM code, so nothing more to do.
+		 */
+		return 0;
+	}
+
+	secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+
+	for (i = 1; i < hdr->e_shnum; i++) {
+		/* Internal symbols and strings. */
+		if (sechdrs[i].sh_type == SHT_SYMTAB) {
+			symindex = i;
+			strindex = sechdrs[i].sh_link;
+		}
+	}
+
+	for (i = 1; i < hdr->e_shnum; i++) {
+		const char *strtab = (char *)sechdrs[strindex].sh_addr;
+		unsigned int info = sechdrs[i].sh_info;
+
+		/* Not a valid relocation section? */
+		if (info >= hdr->e_shnum)
+			continue;
+
+		if ((sechdrs[i].sh_type == SHT_RELA) &&
+		    (strncmp(".rela.ocm_text",
+			     secstrings + sechdrs[i].sh_name, 5 + 9) == 0)) {
+			err = apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
+						 symindex, i, mod);
+			if (err)
+				return err;
+		}
+	}
+
+	return 0;
+}
+
+void module_arch_cleanup(struct module *mod)
+{
+	module_bug_cleanup(mod);
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/os_node.c
@@ -0,0 +1,80 @@
+/*
+ * arch/ubicom32/kernel/os_node.c
+ *   <TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "linux/types.h"
+#include "linux/linkage.h"
+#include "linux/uts.h"
+#include "linux/utsrelease.h"
+#include "linux/version.h"
+#include <asm/ocm_size.h>
+#include <asm/devtree.h>
+#include <asm/ip5000.h>
+
+extern asmlinkage void *_start;
+
+/*
+ * This file provides static information to the boot code allowing it to decide
+ * if the os is compatible. Thus hopefully enabling the boot code to prevent
+ * accidentally booting a kernel that has no hope of running.
+ */
+struct os_node {
+	struct devtree_node node;
+	unsigned long version; /* Always 1 */
+	unsigned long entry_point;
+	const char    os_name[32]; /* For diagnostic purposes only */
+	const char    os_version_str[32];
+	unsigned long os_version_num;
+	unsigned long expected_ocm_code_start;/* OS Code */
+	unsigned long expected_ocm_data_end;  /* OS Data */
+	unsigned long expected_ram_start;
+	unsigned long expected_ram_end;
+	unsigned long arch_version;
+};
+
+
+/*
+ * The os_node is only referenced by head.S and should never be modified at
+ * run-time.
+ */
+asmlinkage const struct os_node _os_node = {
+	.node = {
+		.next = NULL,
+		.name = { "OS" },
+		.magic = 0x10203040,
+	},
+	.version = 0x10001,
+	.entry_point = (unsigned long)&_start,
+#if APP_OCM_CODE_SIZE || APP_OCM_DATA_SIZE
+	.expected_ocm_code_start = OCMSTART + APP_OCM_CODE_SIZE,
+	.expected_ocm_data_end   = OCMEND   - APP_OCM_DATA_SIZE,
+#else
+	.expected_ocm_code_start = OCMEND,
+	.expected_ocm_data_end   = OCMEND,
+#endif
+	.os_name = { UTS_SYSNAME },
+	.os_version_str = { UTS_RELEASE },
+	.os_version_num = LINUX_VERSION_CODE,
+	.expected_ram_start = CONFIG_KERNELBASE,
+	.expected_ram_end = CONFIG_RAMBASE + CONFIG_RAMSIZE,
+	.arch_version = UBICOM32_ARCH_VERSION
+};
--- /dev/null
+++ b/arch/ubicom32/kernel/process.c
@@ -0,0 +1,494 @@
+/*
+ * arch/ubicom32/kernel/process.c
+ *   Ubicom32 architecture-dependent process handling.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1995  Hamish Macdonald
+ *
+ * 68060 fixes by Jesper Skov
+ *
+ * uClinux changes
+ * Copyright (C) 2000-2002, David McCullough <davidm@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+/*
+ * This file handles the architecture-dependent parts of process handling..
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/stddef.h>
+#include <linux/unistd.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/user.h>
+#include <linux/a.out.h>
+#include <linux/interrupt.h>
+#include <linux/reboot.h>
+#include <linux/fs.h>
+#include <linux/pm.h>
+
+#include <linux/uaccess.h>
+#include <asm/system.h>
+#include <asm/traps.h>
+#include <asm/machdep.h>
+#include <asm/setup.h>
+#include <asm/pgtable.h>
+#include <asm/ip5000.h>
+#include <asm/range-protect.h>
+
+asmlinkage void ret_from_fork(void);
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+/* machine-dependent / hardware-specific power functions */
+void (*mach_reset)(void);
+void (*mach_halt)(void);
+void (*mach_power_off)(void);
+
+/*
+ * cpu_idle()
+ *	The idle thread.
+ *
+ * Our idle loop suspends and is woken up by a timer interrupt.
+ */
+void cpu_idle(void)
+{
+	while (1) {
+		local_irq_disable();
+		while (!need_resched()) {
+			local_irq_enable();
+			thread_suspend();
+			local_irq_disable();
+		}
+		local_irq_enable();
+		preempt_enable_no_resched();
+		schedule();
+		preempt_disable();
+	}
+}
+
+/*
+ * dump_fpu()
+ *
+ *	Fill in the fpu structure for a core dump. (just a stub as we don't have
+ *	an fpu)
+ */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t * fpregs)
+{
+	return 1;
+}
+
+/*
+ * machine_restart()
+ *	Resets the system.
+ */
+void machine_restart(char *__unused)
+{
+	/*
+	 * Disable all threads except myself. We can do this
+	 * directly without needing to call smp_send_stop
+	 * because we have a unique architecture where
+	 * one thread can disable one or more other threads.
+	 */
+	thread_disable_others();
+
+	/*
+	 * Call the hardware-specific machine reset function.
+	 */
+	if (mach_reset) {
+		mach_reset();
+	}
+
+	printk(KERN_EMERG "System Restarting\n");
+
+	/*
+	 * Set watchdog to trigger (after 1ms delay) (12 Mhz is the fixed OSC)
+	 */
+	UBICOM32_IO_TIMER->tkey = TIMER_TKEYVAL;
+	UBICOM32_IO_TIMER->wdcom = UBICOM32_IO_TIMER->mptval +
+		(12000000 / 1000);
+	UBICOM32_IO_TIMER->wdcfg = 0;
+	UBICOM32_IO_TIMER->tkey = 0;
+
+	/*
+	 * Wait for watchdog
+	 */
+	asm volatile (
+		"	move.4		MT_EN, #0		\n\t"
+		"	pipe_flush	0			\n\t"
+	);
+
+	local_irq_disable();
+	for (;;) {
+		thread_suspend();
+	}
+}
+
+/*
+ * machine_halt()
+ *	Halt the machine.
+ *
+ * Similar to machine_power_off, but don't shut off power.  Add code
+ * here to freeze the system for e.g. post-mortem debug purpose when
+ * possible.  This halt has nothing to do with the idle halt.
+ */
+void machine_halt(void)
+{
+	/*
+	 * Disable all threads except myself. We can do this
+	 * directly without needing to call smp_send_stop
+	 * because we have a unique architecture where
+	 * one thread can disable one or more other threads.
+	 */
+	thread_disable_others();
+
+	/*
+	 * Call the hardware-specific machine halt function.
+	 */
+	if (mach_halt) {
+		mach_halt();
+	}
+
+	printk(KERN_EMERG "System Halted, OK to turn off power\n");
+	local_irq_disable();
+	for (;;) {
+		thread_suspend();
+	}
+}
+
+/*
+ * machine_power_off()
+ *	Turn the power off, if a power off handler is defined, otherwise, spin
+ *	endlessly.
+ */
+void machine_power_off(void)
+{
+	/*
+	 * Disable all threads except myself. We can do this
+	 * directly without needing to call smp_send_stop
+	 * because we have a unique architecture where
+	 * one thread can disable one or more other threads.
+	 */
+	thread_disable_others();
+
+	/*
+	 * Call the hardware-specific machine power off function.
+	 */
+	if (mach_power_off) {
+		mach_power_off();
+	}
+
+	printk(KERN_EMERG "System Halted, OK to turn off power\n");
+	local_irq_disable();
+	for (;;) {
+		thread_suspend();
+	}
+}
+
+/*
+ * show_regs()
+ *	Print out all of the registers.
+ */
+void show_regs(struct pt_regs *regs)
+{
+	unsigned int i;
+
+	printk(KERN_NOTICE "regs: %p, tid: %d\n",
+		(void *)regs,
+		thread_get_self());
+
+	printk(KERN_NOTICE "pc: %08x, previous_pc: %08x\n\n",
+		(unsigned int)regs->pc,
+		(unsigned int)regs->previous_pc);
+
+	printk(KERN_NOTICE "Data registers\n");
+	for (i = 0; i < 16; i++) {
+		printk("D%02d: %08x, ", i, (unsigned int)regs->dn[i]);
+		if ((i % 4) == 3) {
+			printk("\n");
+		}
+	}
+	printk("\n");
+
+	printk(KERN_NOTICE "Address registers\n");
+	for (i = 0; i < 8; i++) {
+		printk("A%02d: %08x, ", i, (unsigned int)regs->an[i]);
+		if ((i % 4) == 3) {
+			printk("\n");
+		}
+	}
+	printk("\n");
+
+	printk(KERN_NOTICE "acc0: %08x-%08x, acc1: %08x-%08x\n",
+		(unsigned int)regs->acc0[1],
+		(unsigned int)regs->acc0[0],
+		(unsigned int)regs->acc1[1],
+		(unsigned int)regs->acc1[0]);
+
+	printk(KERN_NOTICE "mac_rc16: %08x, source3: %08x\n",
+		(unsigned int)regs->mac_rc16,
+		(unsigned int)regs->source3);
+
+	printk(KERN_NOTICE "inst_cnt: %08x, csr: %08x\n",
+		(unsigned int)regs->inst_cnt,
+		(unsigned int)regs->csr);
+
+	printk(KERN_NOTICE "int_mask0: %08x, int_mask1: %08x\n",
+		(unsigned int)regs->int_mask0,
+		(unsigned int)regs->int_mask1);
+
+	printk(KERN_NOTICE "frame_type: %d, nesting_level: %d, thread_type %d\n\n",
+		(int)regs->frame_type,
+		(int)regs->nesting_level,
+		(int)regs->thread_type);
+}
+
+/*
+ * kernel_thread_helper()
+ *	On execution d0 will be 0, d1 will be the argument to be passed to the
+ *	kernel function.  d2 contains the kernel function that needs to get
+ *	called. d3 will contain address to do_exit which need to get moved
+ *	into a5. On return from fork the child thread d0 will be 0. We call
+ *	this dummy function which in turn loads the argument
+ */
+asmlinkage void kernel_thread_helper(void);
+
+/*
+ * kernel_thread()
+ *	Create a kernel thread
+ */
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+	struct pt_regs regs;
+
+	memset(&regs, 0, sizeof(regs));
+
+	regs.dn[1] = (unsigned long)arg;
+	regs.dn[2] = (unsigned long)fn;
+	regs.dn[3] = (unsigned long)do_exit;
+	regs.an[5] = (unsigned long)kernel_thread_helper;
+	regs.pc = (unsigned long)kernel_thread_helper;
+	regs.nesting_level = 0;
+	regs.thread_type = KERNEL_THREAD;
+
+	return do_fork(flags | CLONE_VM | CLONE_UNTRACED,
+		       0, &regs, 0, NULL, NULL);
+}
+EXPORT_SYMBOL(kernel_thread);
+
+/*
+ * flush_thread()
+ *	XXX todo
+ */
+void flush_thread(void)
+{
+	/* XXX todo */
+}
+
+/*
+ * sys_fork()
+ *	Not implemented on no-mmu.
+ */
+asmlinkage int sys_fork(struct pt_regs *regs)
+{
+	/* fork almost works, enough to trick you into looking elsewhere :-( */
+	return -EINVAL;
+}
+
+/*
+ * sys_vfork()
+ *	By the time we get here, the non-volatile registers have also been saved
+ *	on the stack. We do some ugly pointer stuff here.. (see also copy_thread
+ *	which does context copy).
+ */
+asmlinkage int sys_vfork(struct pt_regs *regs)
+{
+	unsigned long old_sp = regs->an[7];
+	unsigned long old_a5 = regs->an[5];
+	unsigned long old_return_address;
+	long do_fork_return;
+
+	/*
+	 * Read the old retrun address from the stack.
+	 */
+	if (copy_from_user(&old_return_address,
+			   (void *)old_sp, sizeof(unsigned long))) {
+		force_sig(SIGSEGV, current);
+		return 0;
+	}
+
+	/*
+	 * Pop the vfork call frame by setting a5 and pc to the old_return
+	 * address and incrementing the stack pointer by 4.
+	 */
+	regs->an[5] = old_return_address;
+	regs->pc = old_return_address;
+	regs->an[7] += 4;
+
+	do_fork_return = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
+				 regs->an[7], regs, 0, NULL, NULL);
+
+	/*
+	 * Now we have to test if the return code is an error. If it is an error
+	 * then restore the frame and we will execute error processing in user
+	 * space. Other wise the child and the parent will return to the correct
+	 * places.
+	 */
+	if ((unsigned long)(do_fork_return) >= (unsigned long)(-125)) {
+		/*
+		 * Error case. We need to restore the frame.
+		 */
+		regs->an[5] = old_a5;
+		regs->pc = old_a5;
+		regs->an[7] = old_sp;
+	}
+
+	return do_fork_return;
+}
+
+/*
+ * sys_clone()
+ *	creates a child thread.
+ */
+asmlinkage int sys_clone(unsigned long clone_flags,
+			 unsigned long newsp,
+			 struct pt_regs *regs)
+{
+	if (!newsp)
+		newsp = regs->an[7];
+	return do_fork(clone_flags, newsp, regs, 0,
+		       NULL, NULL);
+}
+
+/*
+ * copy_thread()
+ *	low level thread copy, only used by do_fork in kernel/fork.c
+ */
+int copy_thread(int nr, unsigned long clone_flags,
+		unsigned long usp, unsigned long topstk,
+		struct task_struct *p, struct pt_regs *regs)
+{
+	struct pt_regs *childregs;
+
+	childregs = (struct pt_regs *)
+		(task_stack_page(p) + THREAD_SIZE - 8) - 1;
+
+	*childregs = *regs;
+
+	/*
+	 * Set return value for child to be 0.
+	 */
+	childregs->dn[0] = 0;
+
+	if (usp)
+		childregs->an[7] = usp;
+	else
+		childregs->an[7] = (unsigned long)task_stack_page(p) +
+			THREAD_SIZE - 8;
+
+	/*
+	 * Set up the switch_to frame to return to "ret_from_fork"
+	 */
+	p->thread.a5 = (unsigned long)ret_from_fork;
+	p->thread.sp = (unsigned long)childregs;
+
+	return 0;
+}
+
+/*
+ * sys_execve()
+ *	executes a new program.
+ */
+asmlinkage int sys_execve(char *name, char **argv,
+			  char **envp, struct pt_regs *regs)
+{
+	int error;
+	char *filename;
+
+	lock_kernel();
+	filename = getname(name);
+	error = PTR_ERR(filename);
+	if (IS_ERR(filename))
+		goto out;
+	error = do_execve(filename, argv, envp, regs);
+	putname(filename);
+	asm ("       .global sys_execve_complete\n"
+	     "       sys_execve_complete:");
+out:
+	unlock_kernel();
+	return error;
+}
+
+/*
+ * Return saved PC of a blocked thread.
+ */
+unsigned long thread_saved_pc(struct task_struct *tsk)
+{
+	return tsk->thread.a5;
+}
+
+
+unsigned long get_wchan(struct task_struct *p)
+{
+	unsigned long pc;
+
+	/*
+	 * If we don't have a process, or it is not the current
+	 * one or not RUNNING, it makes no sense to ask for a
+	 * wchan.
+	 */
+	if (!p || p == current || p->state == TASK_RUNNING)
+		return 0;
+
+	/*
+	 * TODO: If the process is in the middle of schedule, we
+	 * are supposed to do something different but for now we
+	 * will return the same thing in both situations.
+	 */
+	pc = thread_saved_pc(p);
+	if (in_sched_functions(pc))
+		return pc;
+	return pc;
+}
+
+/*
+ * __switch_to is the function that implements the contex save and
+ * switch within the kernel. Since this is a function call very few
+ * registers have to be saved to pull this off. d0 holds prev and we
+ * want to preserve it. prev_switch is a pointer to task->thread
+ * structure. This is where we will save the register state. next_switch
+ * is pointer to the next task's thread structure that holds the
+ * registers.
+ */
+asmlinkage void *__switch_to(struct task_struct *prev,
+			     struct thread_struct *prev_switch,
+			     struct thread_struct *next_switch)
+	__attribute__((naked));
--- /dev/null
+++ b/arch/ubicom32/kernel/processor.c
@@ -0,0 +1,258 @@
+/*
+ * arch/ubicom32/kernel/processor.c
+ *   Ubicom32 architecture processor info implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/profile.h>
+#include <linux/clocksource.h>
+#include <linux/types.h>
+#include <linux/seq_file.h>
+#include <linux/delay.h>
+#include <linux/cpu.h>
+#include <asm/devtree.h>
+#include <asm/processor.h>
+#include <asm/cpu.h>
+
+struct procnode {
+	struct devtree_node dn;
+	unsigned int threads;
+	unsigned int timers;
+	unsigned int frequency;
+	unsigned int interrupt0;
+	unsigned int interrupt1;
+	void *socm;
+	void *eocm;
+	void *sdram;
+	void *edram;
+};
+
+struct procnode *pn;
+
+/*
+ * show_processorinfo()
+ *	Print the actual processor information.
+ */
+static void show_processorinfo(struct seq_file *m)
+{
+	char *cpu, *mmu, *fpu;
+	unsigned int clockfreq;
+	unsigned int chipid;
+
+	cpu = CPU;
+	mmu = "none";
+	fpu = "none";
+
+	asm volatile (
+	"move.4		%0, CHIP_ID	\n\t"
+	: "=r" (chipid)
+	);
+
+	/*
+	 * General Processor Information.
+	 */
+	seq_printf(m, "Vendor:\t\t%s\n", "Ubicom");
+	seq_printf(m, "CPU:\t\t%s\n", cpu);
+	seq_printf(m, "MMU:\t\t%s\n", mmu);
+	seq_printf(m, "FPU:\t\t%s\n", fpu);
+	seq_printf(m, "Arch:\t\t%hx\n", chipid >> 16);
+	seq_printf(m, "Rev:\t\t%hx\n", (chipid & 0xffff));
+
+	/*
+	 * Now compute the clock frequency in Mhz.
+	 */
+	clockfreq = processor_frequency();
+	seq_printf(m, "Clock Freq:\t%u.%1u MHz\n",
+		   clockfreq / 1000000,
+		   (clockfreq / 100000) % 10);
+	seq_printf(m, "BogoMips:\t%lu.%02lu\n",
+		   (loops_per_jiffy * HZ) / 500000,
+		   ((loops_per_jiffy * HZ) / 5000) % 100);
+	seq_printf(m, "Calibration:\t%lu loops\n", (loops_per_jiffy * HZ));
+}
+
+/*
+ * show_cpuinfo()
+ *	Get CPU information for use by the procfs.
+ */
+static int show_cpuinfo(struct seq_file *m, void *v)
+{
+	unsigned long n = (unsigned long)v - 1;
+
+#if defined(CONFIG_SMP)
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, n);
+#endif
+
+	/*
+	 * Print the general processor information on the first
+	 * call.
+	 */
+	if (n == 0) {
+		show_processorinfo(m);
+	}
+
+#if defined(CONFIG_SMP)
+	/*
+	 * For each hwthread, print if this hwthread is running Linux
+	 * or is an I/O thread.
+	 */
+	if (cpu_isset(n, cpu_online_map)) {
+		seq_printf(m, "cpu[%02lu]:\tthread id - %lu\n", n, p->tid);
+	} else {
+		seq_printf(m, "cpu[%02lu]:\toff-line\n", n);
+	}
+#endif
+	return 0;
+
+}
+
+static void *c_start(struct seq_file *m, loff_t *pos)
+{
+	unsigned long i = *pos;
+
+	return i < NR_CPUS ? (void *)(i + 1) : NULL;
+}
+
+static void *c_next(struct seq_file *m, void *v, loff_t *pos)
+{
+	++*pos;
+	return c_start(m, pos);
+}
+
+static void c_stop(struct seq_file *m, void *v)
+{
+}
+
+const struct seq_operations cpuinfo_op = {
+	.start	= c_start,
+	.next	= c_next,
+	.stop	= c_stop,
+	.show	= show_cpuinfo,
+};
+
+/*
+ * processor_timers()
+ *	Returns the timers available to Linux.
+ */
+unsigned int processor_timers(void)
+{
+	if (!pn) {
+		return 0;
+	}
+	return pn->timers;
+}
+
+/*
+ * processor_threads()
+ *	Returns the threads available to Linux.
+ */
+unsigned int processor_threads(void)
+{
+	if (!pn) {
+		return 0;
+	}
+	return pn->threads;
+}
+
+/*
+ * processor_frequency()
+ *	Returns the frequency of the system clock.
+ */
+unsigned int processor_frequency(void)
+{
+	if (!pn) {
+		return 0;
+	}
+	return pn->frequency;
+}
+EXPORT_SYMBOL(processor_frequency);
+
+/*
+ * processor_interrupts()
+ *	Return the interrupts that are setup at boot time.
+ */
+int processor_interrupts(unsigned int *int0, unsigned int *int1)
+{
+	if (!pn) {
+		return -EFAULT;
+	}
+
+	if (int0) {
+		*int0 = pn->interrupt0;
+	}
+
+	if (int1) {
+		*int1 = pn->interrupt1;
+	}
+	return 0;
+}
+
+/*
+ * processor_ocm()
+ *	Returns the OCM available to Linux.
+ */
+int processor_ocm(void **socm, void **eocm)
+{
+	if (!pn) {
+		return -ENOSYS;
+	}
+
+	*socm = pn->socm;
+	*eocm = pn->eocm;
+	return 0;
+}
+
+/*
+ * processor_dram()
+ *	Returns the dram available to Linux.
+ */
+int processor_dram(void **sdram, void **edram)
+{
+	if (!pn) {
+		return -ENOSYS;
+	}
+
+	*sdram = pn->sdram;
+	*edram = pn->edram;
+	return 0;
+}
+
+void __init processor_init(void)
+{
+	/*
+	 * If we do not have a trap node in the device tree, we leave the fault
+	 * handling to the underlying hardware.
+	 */
+	pn = (struct procnode *)devtree_find_node("processor");
+	if (!pn) {
+		printk(KERN_WARNING "processor node not found\n");
+		return;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/ptrace.c
@@ -0,0 +1,275 @@
+/*
+ * arch/ubicom32/kernel/ptrace.c
+ *   Ubicom32 architecture ptrace implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * (C) 1994 by Hamish Macdonald
+ * Taken from linux/kernel/ptrace.c and modified for M680x0.
+ * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/user.h>
+#include <linux/signal.h>
+#include <linux/uaccess.h>
+
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/cacheflush.h>
+#include <asm/processor.h>
+
+/*
+ * ptrace_getregs()
+ *
+ *	Get all user integer registers.
+ */
+static inline int ptrace_getregs(struct task_struct *task, void __user *uregs)
+{
+	struct pt_regs *regs = task_pt_regs(task);
+	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
+}
+
+/*
+ * ptrace_get_reg()
+ *
+ *	Get contents of register REGNO in task TASK.
+ */
+static unsigned long ptrace_get_reg(struct task_struct *task, int regno)
+{
+	if (regno < sizeof(struct pt_regs)) {
+		struct pt_regs *pt_regs = task_pt_regs(task);
+		return *(unsigned long *)((long) pt_regs + regno);
+	}
+
+	return -EIO;
+}
+
+/*
+ * ptrace_put_reg()
+ *	Write contents of register REGNO in task TASK.
+ */
+static int ptrace_put_reg(struct task_struct *task, int regno,
+			  unsigned long data)
+{
+	if (regno <= sizeof(struct pt_regs) && regno != PT_FRAME_TYPE) {
+		struct pt_regs *pt_regs = task_pt_regs(task);
+		*(unsigned long *)((long) pt_regs + regno) = data;
+		return 0;
+	}
+	return -EIO;
+}
+
+/*
+ * ptrace_disable_single_step()
+ *	Disable Single Step
+ */
+static int ptrace_disable_single_step(struct task_struct *task)
+{
+	/*
+	 * Single Step not yet implemented, so must always be disabled
+	 */
+	return 0;
+}
+
+/*
+ * ptrace_disable()
+ *	Make sure the single step bit is not set.
+ * Called by kernel/ptrace.c when detaching..
+ */
+void ptrace_disable(struct task_struct *child)
+{
+	ptrace_disable_single_step(child);
+}
+
+/*
+ * arch_ptrace()
+ *	architecture specific ptrace routine.
+ */
+long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+{
+	int ret;
+	switch (request) {
+	/* when I and D space are separate, these will need to be fixed. */
+	case PTRACE_PEEKTEXT: /* read word at location addr. */
+	case PTRACE_PEEKDATA:
+		ret = generic_ptrace_peekdata(child, addr, data);
+		break;
+
+	/* read the word at location addr in the USER area. */
+	case PTRACE_PEEKUSR: {
+		unsigned long tmp;
+
+		ret = -EIO;
+		if (((unsigned long) addr > PT_INTERP_FDPIC_LOADMAP)
+		    || (addr & 3))
+			break;
+
+		tmp = 0;  /* Default return condition */
+
+		ret = -EIO;
+		if (addr < sizeof(struct pt_regs)) {
+			tmp = ptrace_get_reg(child, addr);
+		} else if (addr == PT_TEXT_ADDR) {
+			tmp = child->mm->start_code;
+		} else if (addr == PT_TEXT_END_ADDR) {
+			tmp = child->mm->end_code;
+		} else if (addr == PT_DATA_ADDR) {
+			tmp = child->mm->start_data;
+		} else if (addr == PT_EXEC_FDPIC_LOADMAP) {
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+			tmp = child->mm->context.exec_fdpic_loadmap;
+#endif
+		} else if (addr == PT_INTERP_FDPIC_LOADMAP) {
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+			tmp = child->mm->context.interp_fdpic_loadmap;
+#endif
+		} else {
+			break;
+		}
+
+		ret = put_user(tmp, (unsigned long *)data);
+		break;
+	}
+
+	case PTRACE_POKETEXT: /* write the word at location addr. */
+	case PTRACE_POKEDATA:
+		ret = generic_ptrace_pokedata(child, addr, data);
+
+		/*
+		 * If we just changed some code so we need to
+		 * correct the caches
+		 */
+		if (request == PTRACE_POKETEXT && ret == 0) {
+			flush_icache_range(addr, addr + 4);
+		}
+		break;
+
+	case PTRACE_POKEUSR: /* write the word at location addr
+			      * in the USER area */
+		ret = -EIO;
+
+		if (((unsigned long) addr > PT_DATA_ADDR) || (addr & 3))
+			break;
+
+		if (addr < sizeof(struct pt_regs)) {
+			ret = ptrace_put_reg(child, addr, data);
+		}
+		break;
+
+	case PTRACE_SYSCALL: /* continue and stop at next (return from)
+			      * syscall */
+	case PTRACE_CONT: { /* restart after signal. */
+
+		ret = -EIO;
+		if (!valid_signal(data))
+			break;
+		if (request == PTRACE_SYSCALL)
+			set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+		else
+			clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+		child->exit_code = data;
+		/* make sure the single step bit is not set. */
+		ptrace_disable_single_step(child);
+		wake_up_process(child);
+		ret = 0;
+		break;
+	}
+
+	/*
+	 * make the child exit.  Best I can do is send it a sigkill.
+	 * perhaps it should be put in the status that it wants to exit.
+	 */
+	case PTRACE_KILL: {
+		ret = 0;
+		if (child->exit_state == EXIT_ZOMBIE) /* already dead */
+			break;
+		child->exit_code = SIGKILL;
+		/* make sure the single step bit is not set. */
+		ptrace_disable_single_step(child);
+		wake_up_process(child);
+		break;
+	}
+
+	case PTRACE_DETACH:	/* detach a process that was attached. */
+		ret = ptrace_detach(child, data);
+		break;
+
+	case PTRACE_GETREGS:    /* Get all gp regs from the child. */
+		ptrace_getregs(child, (unsigned long *)data);
+		ret = 0;
+		break;
+
+	case PTRACE_SETREGS: { /* Set all gp regs in the child. */
+		int i;
+		unsigned long tmp;
+		int count = sizeof(struct pt_regs) / sizeof(unsigned long);
+		for (i = 0; i < count; i++) {
+			if (get_user(tmp, (unsigned long *) data)) {
+				ret = -EFAULT;
+				break;
+			}
+			ptrace_put_reg(child, sizeof(unsigned long) * i, tmp);
+			data += sizeof(long);
+		}
+		ret = 0;
+		break;
+	}
+
+	default:
+		return ptrace_request(child, request, addr, data);
+		break;
+	}
+	return ret;
+}
+/*
+ * syscall_trace
+ *
+ * called by syscall enter/exit when the TIF_SYSCALL_TRACE bit is set.
+ */
+asmlinkage void syscall_trace(void)
+{
+	struct task_struct *cur = current;
+	if (!test_thread_flag(TIF_SYSCALL_TRACE))
+		return;
+	if (!(cur->ptrace & PT_PTRACED))
+		return;
+	ptrace_notify(SIGTRAP | ((cur->ptrace & PT_TRACESYSGOOD)
+				 ? 0x80 : 0));
+	/*
+	 * this isn't the same as continuing with a signal, but it will do
+	 * for normal use.  strace only continues with a signal if the
+	 * stopping signal is not SIGTRAP.  -brl
+	 */
+	if (cur->exit_code) {
+		send_sig(cur->exit_code, current, 1);
+		current->exit_code = 0;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/semaphore.c
@@ -0,0 +1,159 @@
+/*
+ * arch/ubicom32/kernel/semaphore.c
+ *   Ubicom32 architecture semaphore implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ *  Generic semaphore code. Buyer beware. Do your own
+ * specific changes in <asm/semaphore-helper.h>
+ */
+
+#include <linux/sched.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <asm/semaphore-helper.h>
+
+#ifndef CONFIG_RMW_INSNS
+spinlock_t semaphore_wake_lock;
+#endif
+
+/*
+ * Semaphores are implemented using a two-way counter:
+ * The "count" variable is decremented for each process
+ * that tries to sleep, while the "waking" variable is
+ * incremented when the "up()" code goes to wake up waiting
+ * processes.
+ *
+ * Notably, the inline "up()" and "down()" functions can
+ * efficiently test if they need to do any extra work (up
+ * needs to do something only if count was negative before
+ * the increment operation.
+ *
+ * waking_non_zero() (from asm/semaphore.h) must execute
+ * atomically.
+ *
+ * When __up() is called, the count was negative before
+ * incrementing it, and we need to wake up somebody.
+ *
+ * This routine adds one to the count of processes that need to
+ * wake up and exit.  ALL waiting processes actually wake up but
+ * only the one that gets to the "waking" field first will gate
+ * through and acquire the semaphore.  The others will go back
+ * to sleep.
+ *
+ * Note that these functions are only called when there is
+ * contention on the lock, and as such all this is the
+ * "non-critical" part of the whole semaphore business. The
+ * critical part is the inline stuff in <asm/semaphore.h>
+ * where we want to avoid any extra jumps and calls.
+ */
+void __up(struct semaphore *sem)
+{
+	wake_one_more(sem);
+	wake_up(&sem->wait);
+}
+
+/*
+ * Perform the "down" function.  Return zero for semaphore acquired,
+ * return negative for signalled out of the function.
+ *
+ * If called from __down, the return is ignored and the wait loop is
+ * not interruptible.  This means that a task waiting on a semaphore
+ * using "down()" cannot be killed until someone does an "up()" on
+ * the semaphore.
+ *
+ * If called from __down_interruptible, the return value gets checked
+ * upon return.  If the return value is negative then the task continues
+ * with the negative value in the return register (it can be tested by
+ * the caller).
+ *
+ * Either form may be used in conjunction with "up()".
+ *
+ */
+
+
+#define DOWN_HEAD(task_state)						\
+									\
+									\
+	current->state = (task_state);					\
+	add_wait_queue(&sem->wait, &wait);				\
+									\
+	/*								\
+	 * Ok, we're set up.  sem->count is known to be less than zero	\
+	 * so we must wait.						\
+	 *								\
+	 * We can let go the lock for purposes of waiting.		\
+	 * We re-acquire it after awaking so as to protect		\
+	 * all semaphore operations.					\
+	 *								\
+	 * If "up()" is called before we call waking_non_zero() then	\
+	 * we will catch it right away.  If it is called later then	\
+	 * we will have to go through a wakeup cycle to catch it.	\
+	 *								\
+	 * Multiple waiters contend for the semaphore lock to see	\
+	 * who gets to gate through and who has to wait some more.	\
+	 */								\
+	for (;;) {
+
+#define DOWN_TAIL(task_state)			\
+		current->state = (task_state);	\
+	}					\
+	current->state = TASK_RUNNING;		\
+	remove_wait_queue(&sem->wait, &wait);
+
+void __sched __down(struct semaphore *sem)
+{
+	DECLARE_WAITQUEUE(wait, current);
+
+	DOWN_HEAD(TASK_UNINTERRUPTIBLE)
+	if (waking_non_zero(sem))
+		break;
+	schedule();
+	DOWN_TAIL(TASK_UNINTERRUPTIBLE)
+}
+
+int __sched __down_interruptible(struct semaphore *sem)
+{
+	DECLARE_WAITQUEUE(wait, current);
+	int ret = 0;
+
+	DOWN_HEAD(TASK_INTERRUPTIBLE)
+
+	ret = waking_non_zero_interruptible(sem, current);
+	if (ret) {
+		if (ret == 1)
+			/* ret != 0 only if we get interrupted -arca */
+			ret = 0;
+		break;
+	}
+	schedule();
+	DOWN_TAIL(TASK_INTERRUPTIBLE)
+	return ret;
+}
+
+int __down_trylock(struct semaphore *sem)
+{
+	return waking_non_zero_trylock(sem);
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/setup.c
@@ -0,0 +1,189 @@
+/*
+ * arch/ubicom32/kernel/setup.c
+ *   Ubicom32 architecture-dependent parts of system setup.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1999-2007  Greg Ungerer (gerg@snapgear.com)
+ * Copyright (C) 1998,1999  D. Jeff Dionne <jeff@uClinux.org>
+ * Copyleft  ()) 2000       James D. Schettine {james@telos-systems.com}
+ * Copyright (C) 1998       Kenneth Albanowski <kjahds@kjahds.com>
+ * Copyright (C) 1995       Hamish Macdonald
+ * Copyright (C) 2000       Lineo Inc. (www.lineo.com)
+ * Copyright (C) 2001	    Lineo, Inc. <www.lineo.com>
+ * 68VZ328 Fixes/support    Evan Stawnyczy <e@lineo.ca>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/fb.h>
+#include <linux/module.h>
+#include <linux/console.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/bootmem.h>
+#include <linux/seq_file.h>
+#include <linux/init.h>
+
+#include <asm/devtree.h>
+#include <asm/setup.h>
+#include <asm/irq.h>
+#include <asm/machdep.h>
+#include <asm/pgtable.h>
+#include <asm/pgalloc.h>
+#include <asm/ubicom32-common.h>
+#include <asm/processor.h>
+#include <asm/bootargs.h>
+#include <asm/thread.h>
+
+unsigned long memory_start;
+EXPORT_SYMBOL(memory_start);
+
+unsigned long memory_end;
+EXPORT_SYMBOL(memory_end);
+
+static char __initdata command_line[COMMAND_LINE_SIZE];
+#ifdef CONFIG_CMDLINE_BOOL
+static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
+#endif
+
+extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
+
+/*
+ * setup_arch()
+ *	Setup the architecture dependent portions of the system.
+ */
+void __init setup_arch(char **cmdline_p)
+{
+	int bootmap_size;
+
+	processor_init();
+	bootargs_init();
+
+	/*
+	 * TODO: The memory regions should really come from the
+	 * processor node.
+	 */
+	memory_start = PAGE_ALIGN(((unsigned long)&_end));
+	memory_end = CONFIG_RAMBASE+CONFIG_RAMSIZE;
+
+	init_mm.start_code = (unsigned long) &_stext;
+	init_mm.end_code = (unsigned long) &_etext;
+	init_mm.end_data = (unsigned long) &_edata;
+	init_mm.brk = (unsigned long) 0;
+
+	strlcpy(boot_command_line, bootargs_get_cmdline(), COMMAND_LINE_SIZE);
+
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_OVERRIDE
+	strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+#else
+	if (builtin_cmdline[0]) {
+		/* append boot loader cmdline to builtin */
+		strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
+		strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+		strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+	}
+#endif
+#endif
+
+	strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	*cmdline_p = command_line;
+
+	parse_early_param();
+
+	printk(KERN_INFO "%s Processor, Ubicom, Inc. <www.ubicom.com>\n", CPU);
+
+#if defined(DEBUG)
+	printk(KERN_DEBUG "KERNEL -> TEXT=0x%06x-0x%06x DATA=0x%06x-0x%06x "
+		"BSS=0x%06x-0x%06x\n", (int) &_stext, (int) &_etext,
+		(int) &_sdata, (int) &_edata,
+		(int) &_sbss, (int) &_ebss);
+	printk(KERN_DEBUG "MEMORY -> ROMFS=0x%06x-0x%06x MEM=0x%06x-0x%06x\n ",
+		(int) &_ebss, (int) memory_start,
+		(int) memory_start, (int) memory_end);
+#endif
+
+	/* Keep a copy of command line */
+	*cmdline_p = &command_line[0];
+	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
+	boot_command_line[COMMAND_LINE_SIZE-1] = 0;
+
+#ifdef DEBUG
+	if (strlen(*cmdline_p))
+		printk(KERN_DEBUG "Command line: '%s'\n", *cmdline_p);
+#endif
+
+#if defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_DUMMY_CONSOLE)
+	conswitchp = &dummy_con;
+#endif
+
+	/*
+	 * If we have a device tree, see if we have the nodes we need.
+	 */
+	if (devtree) {
+		devtree_print();
+	}
+
+	/*
+	 * From the arm initialization comment:
+	 *
+	 * This doesn't seem to be used by the Linux memory manager any
+	 * more, but is used by ll_rw_block.  If we can get rid of it, we
+	 * also get rid of some of the stuff above as well.
+	 *
+	 * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
+	 * the system, not the maximum PFN.
+	 */
+	max_pfn = max_low_pfn = (memory_end - PAGE_OFFSET) >> PAGE_SHIFT;
+
+	/*
+	 * Give all the memory to the bootmap allocator, tell it to put the
+	 * boot mem_map at the start of memory.
+	 */
+	bootmap_size = init_bootmem_node(
+			NODE_DATA(0),
+			memory_start >> PAGE_SHIFT,	/* map goes here */
+			PAGE_OFFSET >> PAGE_SHIFT,	/* 0 on coldfire */
+			memory_end >> PAGE_SHIFT);
+	/*
+	 * Free the usable memory, we have to make sure we do not free
+	 * the bootmem bitmap so we then reserve it after freeing it :-)
+	 */
+	free_bootmem(memory_start, memory_end - memory_start);
+	reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
+
+	/*
+	 * Get kmalloc into gear.
+	 */
+	paging_init();
+
+	/*
+	 * Fix up the thread_info structure, indicate this is a mainline Linux
+	 * thread and setup the sw_ksp().
+	 */
+	sw_ksp[thread_get_self()] = (unsigned int) current_thread_info();
+	thread_set_mainline(thread_get_self());
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/signal.c
@@ -0,0 +1,458 @@
+/*
+ * arch/ubicom32/kernel/signal.c
+ *   Ubicom32 architecture signal handling implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1991, 1992  Linus Torvalds
+ * Linux/m68k support by Hamish Macdonald
+ * 68060 fixes by Jesper Skov
+ * 1997-12-01  Modified for POSIX.1b signals by Andreas Schwab
+ * mathemu support by Roman Zippel
+ * ++roman (07/09/96): implemented signal stacks
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * mathemu support by Roman Zippel
+ *  (Note: fpstate in the signal context is completely ignored for the emulator
+ *         and the internal floating point format is put on stack)
+ *
+ * ++roman (07/09/96): implemented signal stacks (specially for tosemu on
+ * Atari :-) Current limitation: Only one sigstack can be active at one time.
+ * If a second signal with SA_ONSTACK set arrives while working on a sigstack,
+ * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested
+ * signal handlers!
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/syscalls.h>
+#include <linux/errno.h>
+#include <linux/wait.h>
+#include <linux/ptrace.h>
+#include <linux/unistd.h>
+#include <linux/stddef.h>
+#include <linux/highuid.h>
+#include <linux/tty.h>
+#include <linux/personality.h>
+#include <linux/binfmts.h>
+
+#include <asm/setup.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+#include <asm/traps.h>
+#include <asm/ucontext.h>
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+/*
+ * asm signal return handlers.
+ */
+void ret_from_user_signal(void);
+void ret_from_user_rt_signal(void);
+asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs);
+
+/*
+ * Common signal suspend implementation
+ */
+static int signal_suspend(sigset_t *saveset, struct pt_regs *regs)
+{
+	regs->dn[0] = -EINTR;
+	while (1) {
+		current->state = TASK_INTERRUPTIBLE;
+		schedule();
+		if (!do_signal(saveset, regs)) {
+			continue;
+		}
+		/*
+		 * If the current frame type is a signal trampoline we are
+		 * actually going to call the signal handler so we return the
+		 * desired d0 as the return value.
+		 */
+		if (regs->frame_type == UBICOM32_FRAME_TYPE_SIGTRAMP) {
+			return regs->dn[0];
+		}
+		return -EINTR;
+	}
+	/*
+	 * Should never get here
+	 */
+	BUG();
+	return 0;
+}
+
+/*
+ * Atomically swap in the new signal mask, and wait for a signal.
+ */
+asmlinkage int do_sigsuspend(struct pt_regs *regs)
+{
+	old_sigset_t mask = regs->dn[0];
+	sigset_t saveset;
+
+	mask &= _BLOCKABLE;
+	spin_lock_irq(&current->sighand->siglock);
+	saveset = current->blocked;
+	siginitset(&current->blocked, mask);
+	recalc_sigpending();
+	spin_unlock_irq(&current->sighand->siglock);
+
+	/*
+	 * Call common handler
+	 */
+	return signal_suspend(&saveset, regs);
+}
+
+asmlinkage int
+do_rt_sigsuspend(struct pt_regs *regs)
+{
+	sigset_t *unewset = (sigset_t *)regs->dn[0];
+	size_t sigsetsize = (size_t)regs->dn[1];
+	sigset_t saveset, newset;
+
+	/* XXX: Don't preclude handling different sized sigset_t's.  */
+	if (sigsetsize != sizeof(sigset_t))
+		return -EINVAL;
+
+	if (copy_from_user(&newset, unewset, sizeof(newset)))
+		return -EFAULT;
+	sigdelsetmask(&newset, ~_BLOCKABLE);
+
+	spin_lock_irq(&current->sighand->siglock);
+	saveset = current->blocked;
+	current->blocked = newset;
+	recalc_sigpending();
+	spin_unlock_irq(&current->sighand->siglock);
+
+	/*
+	 * Call common handler
+	 */
+	return signal_suspend(&saveset, regs);
+}
+
+asmlinkage int
+sys_sigaction(int sig, const struct old_sigaction *act,
+	      struct old_sigaction *oact)
+{
+	struct k_sigaction new_ka, old_ka;
+	int ret;
+
+	if (act) {
+		old_sigset_t mask;
+		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
+		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
+		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
+			return -EFAULT;
+		__get_user(new_ka.sa.sa_flags, &act->sa_flags);
+		__get_user(mask, &act->sa_mask);
+		siginitset(&new_ka.sa.sa_mask, mask);
+	}
+
+	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
+
+	if (!ret && oact) {
+		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
+		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
+		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
+			return -EFAULT;
+		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
+		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
+	}
+
+	return ret;
+}
+
+asmlinkage int
+do_sys_sigaltstack(struct pt_regs *regs)
+{
+	const stack_t *uss = (stack_t *) regs->dn[0];
+	stack_t *uoss = (stack_t *)regs->dn[1];
+	return do_sigaltstack(uss, uoss, regs->an[7]);
+}
+
+/*
+ * fdpic_func_descriptor describes sa_handler when the application is FDPIC
+ */
+struct fdpic_func_descriptor {
+	unsigned long	text;
+	unsigned long	GOT;
+};
+
+/*
+ * rt_sigframe is stored on the user stack immediately before (above)
+ * the signal handlers stack.
+ */
+struct rt_sigframe
+{
+	unsigned long syscall_number;	/* This holds __NR_rt_sigreturn. */
+	unsigned long restore_all_regs; /* This field gets set to 1 if the frame
+					 * type is TRAP or INTERRUPT. */
+	siginfo_t *info;
+	struct ucontext uc;
+	int sig;
+	void *pretcode;
+};
+
+/*
+ * Do a signal return; undo the signal stack.
+ */
+asmlinkage int do_sigreturn(unsigned long __unused)
+{
+	BUG();
+	return 0;
+}
+
+asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
+{
+	unsigned long usp = regs->an[7];
+	struct rt_sigframe *frame = (struct rt_sigframe *)(usp);
+	sigset_t set;
+
+	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
+		goto badframe;
+	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+		goto badframe;
+
+	sigdelsetmask(&set, ~_BLOCKABLE);
+	spin_lock_irq(&current->sighand->siglock);
+	current->blocked = set;
+	recalc_sigpending();
+	spin_unlock_irq(&current->sighand->siglock);
+
+	if (copy_from_user(regs, &frame->uc.uc_mcontext, sizeof(struct pt_regs)))
+		goto badframe;
+	return regs->dn[0];
+
+badframe:
+	force_sig(SIGSEGV, current);
+	return 0;
+}
+
+static inline void *
+get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
+{
+	unsigned long usp;
+
+	/* Default to using normal stack.  */
+	usp = regs->an[7];
+
+	/* This is the X/Open sanctioned signal stack switching.  */
+	if (ka->sa.sa_flags & SA_ONSTACK) {
+		if (!sas_ss_flags(usp))
+			usp = current->sas_ss_sp + current->sas_ss_size;
+	}
+	return (void *)((usp - frame_size) & ~0x3);
+}
+
+/*
+ * signal_trampoline:  Defined in ubicom32_syscall.S
+ */
+asmlinkage void signal_trampoline(void)__attribute__((naked));
+
+static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
+			    sigset_t *set, struct pt_regs *regs)
+{
+	struct rt_sigframe *frame;
+	int err = 0;
+
+	frame = (struct rt_sigframe *) get_sigframe(ka, regs, sizeof(*frame));
+
+	/*
+	 * The 'err |=' have been may criticized as bad code style, but I
+	 * strongly suspect that we want this code to be fast.  So for
+	 * now it stays as is.
+	 */
+	err |= __put_user( (  (current_thread_info()->exec_domain)
+			   && (current_thread_info()->exec_domain->signal_invmap)
+			   && (sig < 32) )
+			   ? current_thread_info()->exec_domain->signal_invmap[sig]
+			   : sig, &frame->sig);
+	err |= __put_user(info, &frame->info);
+
+	/* Create the ucontext.  */
+	err |= __put_user(0, &frame->uc.uc_flags);
+	err |= __put_user(0, &frame->uc.uc_link);
+	err |= __put_user((void *)current->sas_ss_sp,
+			  &frame->uc.uc_stack.ss_sp);
+	err |= __put_user(sas_ss_flags(regs->an[7]),
+			  &frame->uc.uc_stack.ss_flags);
+	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
+	err |= __put_user(__NR_rt_sigreturn, &frame->syscall_number);
+	if ((regs->frame_type == UBICOM32_FRAME_TYPE_TRAP) ||
+	    (regs->frame_type == UBICOM32_FRAME_TYPE_INTERRUPT)) {
+		err |= __put_user(1, &frame->restore_all_regs);
+	} else {
+		err |= __put_user(0, &frame->restore_all_regs);
+	}
+	err |= copy_to_user (&frame->uc.uc_mcontext.sc_regs, regs, sizeof(struct pt_regs));
+	err |= copy_to_user (&frame->uc.uc_sigmask, set, sizeof(*set));
+
+	if (err)
+		goto give_sigsegv;
+
+	/*
+	 * Set up registers for signal handler NOTE: Do not modify dn[14], it
+	 * contains the userspace tls pointer, so it important that it carries
+	 * over to the signal handler.
+	 */
+	regs->an[7] = (unsigned long)frame;
+	regs->pc = (unsigned long) signal_trampoline;
+	regs->an[5] = (unsigned long) signal_trampoline;
+	regs->dn[0] = sig;
+	regs->dn[1] = (unsigned long) frame->info;
+	regs->dn[2] = (unsigned int) &frame->uc;
+
+	/*
+	 * If this is FDPIC then the signal handler is actually a function
+	 * descriptor.
+	 */
+	if (current->personality & FDPIC_FUNCPTRS) {
+		struct fdpic_func_descriptor __user *funcptr =
+			(struct fdpic_func_descriptor *) ka->sa.sa_handler;
+		err |= __get_user(regs->dn[3], &funcptr->text);
+		err |= __get_user(regs->an[0], &funcptr->GOT);
+		if (err)
+			goto give_sigsegv;
+
+		/*
+		 * The funcdesc must be in a3 as this is required for the lazy
+		 * resolver in ld.so, if the application is not FDPIC a3 is not
+		 * used.
+		 */
+		regs->an[3] = (unsigned long) funcptr;
+
+	} else {
+		regs->dn[3] = (unsigned long)ka->sa.sa_handler;
+		regs->an[0] = 0;
+	}
+
+	regs->frame_type =  UBICOM32_FRAME_TYPE_SIGTRAMP;
+
+	return;
+
+give_sigsegv:
+	/* user space exception */
+	force_sigsegv(sig, current);
+}
+
+static inline void
+handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
+{
+	switch (regs->dn[0]) {
+	case -ERESTARTNOHAND:
+		if (!has_handler)
+			goto do_restart;
+		regs->dn[0] = -EINTR;
+		break;
+
+	case -ERESTARTSYS:
+		if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
+			regs->dn[0] = -EINTR;
+			break;
+		}
+	/* fallthrough */
+	case -ERESTARTNOINTR:
+	do_restart:
+		regs->dn[0] = regs->original_dn_0;
+		regs->pc -= 8;
+		regs->an[5] -= 8;
+		break;
+	}
+}
+
+/*
+ * OK, we're invoking a handler
+ */
+static void
+handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
+	      sigset_t *oldset, struct pt_regs *regs)
+{
+	/* are we from a system call? */
+	if (regs->frame_type == -1)
+		/* If so, check system call restarting.. */
+		handle_restart(regs, ka, 1);
+
+	/* set up the stack frame */
+	setup_rt_frame(sig, ka, info, oldset, regs);
+
+	if (ka->sa.sa_flags & SA_ONESHOT)
+		ka->sa.sa_handler = SIG_DFL;
+
+	spin_lock_irq(&current->sighand->siglock);
+	sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
+	if (!(ka->sa.sa_flags & SA_NODEFER))
+		sigaddset(&current->blocked,sig);
+	recalc_sigpending();
+	spin_unlock_irq(&current->sighand->siglock);
+}
+
+/*
+ * Note that 'init' is a special process: it doesn't get signals it doesn't
+ * want to handle. Thus you cannot kill init even with a SIGKILL even by
+ * mistake.
+ */
+asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs)
+{
+	struct k_sigaction ka;
+	siginfo_t info;
+	int signr;
+
+	/*
+	 * We want the common case to go fast, which
+	 * is why we may in certain cases get here from
+	 * kernel mode. Just return without doing anything
+	 * if so.
+	 */
+	if (!user_mode(regs))
+		return 1;
+
+	if (!oldset)
+		oldset = &current->blocked;
+
+	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+	if (signr > 0) {
+		/* Whee!  Actually deliver the signal.  */
+		handle_signal(signr, &ka, &info, oldset, regs);
+		return 1;
+	}
+
+	/* Did we come from a system call? */
+	if (regs->frame_type == -1) {
+		/* Restart the system call - no handlers present */
+		handle_restart(regs, NULL, 0);
+	}
+
+	return 0;
+}
+
+/*
+ * sys_sigreturn()
+ *	Return handler for signal clean-up.
+ *
+ * NOTE: Ubicom32 does not use this syscall.  Instead we rely
+ * on do_rt_sigreturn().
+ */
+asmlinkage long sys_sigreturn(void)
+{
+	return -ENOSYS;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/smp.c
@@ -0,0 +1,808 @@
+/*
+ * arch/ubicom32/kernel/smp.c
+ *   SMP implementation for Ubicom32 processors.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
+ * Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
+ * Copyright (C) 2001,2004 Grant Grundler <grundler@parisc-linux.org>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+
+#include <linux/kernel.h>
+#include <linux/bootmem.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/smp.h>
+#include <linux/kernel_stat.h>
+#include <linux/mm.h>
+#include <linux/err.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+#include <linux/cpu.h>
+#include <linux/profile.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/ptrace.h>
+#include <linux/unistd.h>
+#include <linux/irq.h>
+
+#include <asm/system.h>
+#include <asm/atomic.h>
+#include <asm/current.h>
+#include <asm/tlbflush.h>
+#include <asm/timex.h>
+#include <asm/cpu.h>
+#include <asm/irq.h>
+#include <asm/processor.h>
+#include <asm/thread.h>
+#include <asm/sections.h>
+#include <asm/ip5000.h>
+
+/*
+ * Mask the debug printout for IPI because they are too verbose
+ * for regular debugging.
+ */
+
+// #define DEBUG_SMP 1
+#if !defined(DEBUG_SMP)
+#define smp_debug(lvl, ...)
+#else
+static unsigned int smp_debug_lvl = 50;
+#define smp_debug(lvl, printargs...)		\
+	if (lvl >= smp_debug_lvl) {		\
+			printk(printargs);	\
+	}
+#endif
+
+#if !defined(DEBUG_SMP)
+#define DEBUG_ASSERT(cond)
+#else
+#define DEBUG_ASSERT(cond) \
+	if (!(cond)) { \
+		THREAD_STALL; \
+	}
+#endif
+
+/*
+ * List of IPI Commands (more than one can be set at a time).
+ */
+enum ipi_message_type {
+	IPI_NOP,
+	IPI_RESCHEDULE,
+	IPI_CALL_FUNC,
+	IPI_CALL_FUNC_SINGLE,
+	IPI_CPU_STOP,
+	IPI_CPU_TIMER,
+};
+
+/*
+ * These values are properly adjusted by smp_prepare_cpus() below.  They are
+ * required to be declared in the arch directory if CONFIG_SMP is set.
+ */
+cpumask_t cpu_online_map = CPU_MASK_NONE;  /* Bitmap of online CPUs */
+EXPORT_SYMBOL(cpu_online_map);
+
+cpumask_t cpu_possible_map = CPU_MASK_ALL; /* Bitmap of Present CPUs */
+EXPORT_SYMBOL(cpu_possible_map);
+
+/*
+ * We maintain a hardware thread oriented view of online threads
+ * and those involved or needing IPI.
+ */
+static unsigned long smp_online_threads = 0;
+static unsigned long smp_needs_ipi = 0;
+static unsigned long smp_inside_ipi = 0;
+static unsigned long smp_irq_affinity[NR_IRQS];
+
+/*
+ * What do we need to track on a per cpu/thread basis?
+ */
+DEFINE_PER_CPU(struct cpuinfo_ubicom32, cpu_data);
+
+/*
+ * Each thread cpuinfo IPI information is guarded by a lock
+ * that is kept local to this file.
+ */
+DEFINE_PER_CPU(spinlock_t, ipi_lock) = SPIN_LOCK_UNLOCKED;
+
+/*
+ * The IPI(s) are based on a software IRQ through the LDSR.
+ */
+unsigned int smp_ipi_irq;
+
+/*
+ * Define a spinlock so that only one cpu is able to modify the
+ * smp_needs_ipi and to set/clear the IRQ at a time.
+ */
+DEFINE_SPINLOCK(smp_ipi_lock);
+
+/*
+ * smp_halt_processor()
+ *	Halt this hardware thread.
+ */
+static void smp_halt_processor(void)
+{
+	int cpuid = thread_get_self();
+	cpu_clear(smp_processor_id(), cpu_online_map);
+	local_irq_disable();
+	printk(KERN_EMERG "cpu[%d] has halted. It is not OK to turn off power \
+		until all cpu's are off.\n", cpuid);
+	for (;;) {
+		thread_suspend();
+	}
+}
+
+/*
+ * ipi_interrupt()
+ *	Handle an Interprocessor Interrupt.
+ */
+static irqreturn_t ipi_interrupt(int irq, void *dev_id)
+{
+	int cpuid = smp_processor_id();
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, cpuid);
+	unsigned long ops;
+
+	/*
+	 * Count this now; we may make a call that never returns.
+	 */
+	p->ipi_count++;
+
+	/*
+	 * We are about to process all ops.  If another cpu has stated
+	 * that we need an IPI, we will have already processed it.  By
+	 * clearing our smp_needs_ipi, and processing all ops,
+	 * we reduce the number of IPI interrupts.  However, this introduces
+	 * the possibility that smp_needs_ipi will be clear and the soft irq
+	 * will have gone off; so we need to make the get_affinity() path
+	 * tolerant of spurious interrupts.
+	 */
+	spin_lock(&smp_ipi_lock);
+	smp_needs_ipi &= ~p->tid;
+	spin_unlock(&smp_ipi_lock);
+
+	for (;;) {
+		/*
+		 * Read the set of IPI commands we should handle.
+		 */
+		spinlock_t *lock = &per_cpu(ipi_lock, cpuid);
+		spin_lock(lock);
+		ops = p->ipi_pending;
+		p->ipi_pending = 0;
+		spin_unlock(lock);
+
+		/*
+		 * If we have no IPI commands to execute, break out.
+		 */
+		if (!ops) {
+			break;
+		}
+
+		/*
+		 * Execute the set of commands in the ops word, one command
+		 * at a time in no particular order.  Strip of each command
+		 * as we execute it.
+		 */
+		while (ops) {
+			unsigned long which = ffz(~ops);
+			ops &= ~(1 << which);
+
+			BUG_ON(!irqs_disabled());
+			switch (which) {
+			case IPI_NOP:
+				smp_debug(100, KERN_INFO "cpu[%d]: "
+					  "IPI_NOP\n", cpuid);
+				break;
+
+			case IPI_RESCHEDULE:
+				/*
+				 * Reschedule callback.  Everything to be
+				 * done is done by the interrupt return path.
+				 */
+				smp_debug(200, KERN_INFO "cpu[%d]: "
+					  "IPI_RESCHEDULE\n", cpuid);
+				break;
+
+			case IPI_CALL_FUNC:
+				smp_debug(100, KERN_INFO "cpu[%d]: "
+					  "IPI_CALL_FUNC\n", cpuid);
+				generic_smp_call_function_interrupt();
+				break;
+
+			case IPI_CALL_FUNC_SINGLE:
+				smp_debug(100, KERN_INFO "cpu[%d]: "
+					  "IPI_CALL_FUNC_SINGLE\n", cpuid);
+				generic_smp_call_function_single_interrupt();
+				break;
+
+			case IPI_CPU_STOP:
+				smp_debug(100, KERN_INFO "cpu[%d]: "
+					  "IPI_CPU_STOP\n", cpuid);
+				smp_halt_processor();
+				break;
+
+#if !defined(CONFIG_LOCAL_TIMERS)
+			case IPI_CPU_TIMER:
+				smp_debug(100, KERN_INFO "cpu[%d]: "
+					  "IPI_CPU_TIMER\n", cpuid);
+#if defined(CONFIG_GENERIC_CLOCKEVENTS)
+				local_timer_interrupt();
+#else
+				update_process_times(user_mode(get_irq_regs()));
+				profile_tick(CPU_PROFILING);
+#endif
+#endif
+				break;
+
+			default:
+				printk(KERN_CRIT "cpu[%d]: "
+					  "Unknown IPI: %lu\n", cpuid, which);
+
+				return IRQ_NONE;
+			}
+
+			/*
+			 * Let in any pending interrupts
+			 */
+			BUG_ON(!irqs_disabled());
+			local_irq_enable();
+			local_irq_disable();
+		}
+	}
+	return IRQ_HANDLED;
+}
+
+/*
+ * ipi_send()
+ *	Send an Interprocessor Interrupt.
+ */
+static void ipi_send(int cpu, enum ipi_message_type op)
+{
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, cpu);
+	spinlock_t *lock = &per_cpu(ipi_lock, cpu);
+	unsigned long flags;
+
+	/*
+	 * We protect the setting of the ipi_pending field and ensure
+	 * that the ipi delivery mechanism and interrupt are atomically
+	 * handled.
+	 */
+	spin_lock_irqsave(lock, flags);
+	p->ipi_pending |= 1 << op;
+	spin_unlock_irqrestore(lock, flags);
+
+	spin_lock_irqsave(&smp_ipi_lock, flags);
+	smp_needs_ipi |= (1 << p->tid);
+	ubicom32_set_interrupt(smp_ipi_irq);
+	spin_unlock_irqrestore(&smp_ipi_lock, flags);
+}
+
+/*
+ * ipi_send_mask
+ *	Send an IPI to each cpu in mask.
+ */
+static inline void ipi_send_mask(unsigned int op, cpumask_t mask)
+{
+	int cpu;
+	for_each_cpu_mask(cpu, mask) {
+		ipi_send(cpu, op);
+	}
+}
+
+/*
+ * ipi_send_allbutself()
+ *	Send an IPI to all threads but ourselves.
+ */
+static inline void ipi_send_allbutself(unsigned int op)
+{
+	int self = smp_processor_id();
+	cpumask_t result = cpu_online_map;
+	cpu_clear(self, result);
+	ipi_send_mask(op, result);
+}
+
+/*
+ * smp_enable_vector()
+ */
+static void smp_enable_vector(unsigned int irq)
+{
+	ubicom32_clear_interrupt(smp_ipi_irq);
+	ldsr_enable_vector(irq);
+}
+
+/*
+ * smp_disable_vector()
+ *	Disable the interrupt by clearing the appropriate bit in the
+ *	LDSR Mask Register.
+ */
+static void smp_disable_vector(unsigned int irq)
+{
+	ldsr_disable_vector(irq);
+}
+
+/*
+ * smp_mask_vector()
+ */
+static void smp_mask_vector(unsigned int irq)
+{
+	ldsr_mask_vector(irq);
+}
+
+/*
+ * smp_unmask_vector()
+ */
+static void smp_unmask_vector(unsigned int irq)
+{
+	ldsr_unmask_vector(irq);
+}
+
+/*
+ * smp_end_vector()
+ *	Called once an interrupt is completed (reset the LDSR mask).
+ */
+static void smp_end_vector(unsigned int irq)
+{
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, smp_processor_id());
+	spin_lock(&smp_ipi_lock);
+	smp_inside_ipi &= ~(1 << p->tid);
+	if (smp_inside_ipi) {
+		spin_unlock(&smp_ipi_lock);
+		return;
+	}
+	spin_unlock(&smp_ipi_lock);
+	ldsr_unmask_vector(irq);
+}
+
+/*
+ * Special hanlder functions for SMP.
+ */
+static struct irq_chip ubicom32_smp_chip = {
+	.name		= "UbicoIPI",
+	.startup	= NULL,
+	.shutdown	= NULL,
+	.enable		= smp_enable_vector,
+	.disable	= smp_disable_vector,
+	.ack		= NULL,
+	.mask		= smp_mask_vector,
+	.unmask		= smp_unmask_vector,
+	.end		= smp_end_vector,
+};
+
+/*
+ * smp_reset_ipi()
+ *	None of these cpu(s) got their IPI, turn it back on.
+ *
+ * Note: This is called by the LDSR which is not a full
+ * Linux cpu.  Thus you must use the raw form of locks
+ * because lock debugging will not work on the partial
+ * cpu nature of the LDSR.
+ */
+void smp_reset_ipi(unsigned long mask)
+{
+	__raw_spin_lock(&smp_ipi_lock.raw_lock);
+	smp_needs_ipi |= mask;
+	smp_inside_ipi &= ~mask;
+	ubicom32_set_interrupt(smp_ipi_irq);
+	__raw_spin_unlock(&smp_ipi_lock.raw_lock);
+}
+
+/*
+ * smp_get_affinity()
+ *	Choose the thread affinity for this interrupt.
+ *
+ * Note: This is called by the LDSR which is not a full
+ * Linux cpu.  Thus you must use the raw form of locks
+ * because lock debugging will not work on the partial
+ * cpu nature of the LDSR.
+ */
+unsigned long smp_get_affinity(unsigned int irq, int *all)
+{
+	unsigned long mask = 0;
+
+	/*
+	 * Most IRQ(s) are delivered in a round robin fashion.
+	 */
+	if (irq != smp_ipi_irq) {
+		unsigned long result = smp_irq_affinity[irq] & smp_online_threads;
+		DEBUG_ASSERT(result);
+		*all = 0;
+		return result;
+	}
+
+	/*
+	 * This is an IPI request.  Return all cpu(s) scheduled for an IPI.
+	 * We also track those cpu(s) that are going to be "receiving" IPI this
+	 * round.  When all CPU(s) have called smp_end_vector(),
+	 * we will unmask the IPI interrupt.
+	 */
+	__raw_spin_lock(&smp_ipi_lock.raw_lock);
+	ubicom32_clear_interrupt(smp_ipi_irq);
+	if (smp_needs_ipi) {
+		mask = smp_needs_ipi;
+		smp_inside_ipi |= smp_needs_ipi;
+		smp_needs_ipi = 0;
+	}
+	__raw_spin_unlock(&smp_ipi_lock.raw_lock);
+	*all = 1;
+	return mask;
+}
+
+/*
+ *  smp_set_affinity()
+ *  	Set the affinity for this irq but store the value in tid(s).
+ */
+void smp_set_affinity(unsigned int irq, cpumask_t dest)
+{
+	int cpuid;
+	unsigned long *paffinity = &smp_irq_affinity[irq];
+
+	/*
+	 *  If none specified, all cpus are allowed.
+	 */
+	if (cpus_empty(dest)) {
+		*paffinity = 0xffffffff;
+		return;
+	}
+
+	/*
+	 * Make sure to clear the old value before setting up the
+	 * list.
+	 */
+	*paffinity = 0;
+	for_each_cpu_mask(cpuid, dest) {
+		struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, cpuid);
+		*paffinity |= (1 << p->tid);
+	}
+}
+
+/*
+ * smp_send_stop()
+ *	Send a stop request to all CPU but this one.
+ */
+void smp_send_stop(void)
+{
+	ipi_send_allbutself(IPI_CPU_STOP);
+}
+
+/*
+ * smp_send_timer_all()
+ *	Send all cpu(s) but this one, a request to update times.
+ */
+void smp_send_timer_all(void)
+{
+	ipi_send_allbutself(IPI_CPU_TIMER);
+}
+
+/*
+ * smp_timer_broadcast()
+ *	Use an IPI to broadcast a timer message
+ */
+void smp_timer_broadcast(cpumask_t mask)
+{
+	ipi_send_mask(IPI_CPU_TIMER, mask);
+}
+
+/*
+ * smp_send_reschedule()
+ *	Send a reschedule request to the specified cpu.
+ */
+void smp_send_reschedule(int cpu)
+{
+	ipi_send(cpu, IPI_RESCHEDULE);
+}
+
+/*
+ * arch_send_call_function_ipi()
+ *	Cause each cpu in the mask to call the generic function handler.
+ */
+void arch_send_call_function_ipi(cpumask_t mask)
+{
+	int cpu;
+	for_each_cpu_mask(cpu, mask) {
+		ipi_send(cpu, IPI_CALL_FUNC);
+	}
+}
+
+/*
+ * arch_send_call_function_single_ipi()
+ *	Cause the specified cpu to call the generic function handler.
+ */
+void arch_send_call_function_single_ipi(int cpu)
+{
+	ipi_send(cpu, IPI_CALL_FUNC_SINGLE);
+}
+
+/*
+ * smp_mainline_start()
+ *	Start a slave thread executing a mainline Linux context.
+ */
+static void __init smp_mainline_start(void *arg)
+{
+	int cpuid = smp_processor_id();
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, cpuid);
+
+	BUG_ON(p->tid != thread_get_self());
+
+	/*
+	 * Well, support 2.4 linux scheme as well.
+	 */
+	if (cpu_test_and_set(cpuid, cpu_online_map)) {
+		printk(KERN_CRIT "cpu[%d]: already initialized!\n", cpuid);
+		smp_halt_processor();
+		return;
+	}
+
+	/*
+	 * Initialise the idle task for this CPU
+	 */
+	atomic_inc(&init_mm.mm_count);
+	current->active_mm = &init_mm;
+	if (current->mm) {
+		printk(KERN_CRIT "cpu[%d]: idle task already has memory "
+		       "management\n", cpuid);
+		smp_halt_processor();
+		return;
+	}
+
+	/*
+	 * TODO: X86 does this prior to calling notify, try to understand why?
+	 */
+	preempt_disable();
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS)
+	/*
+	 * Setup a local timer event so that this cpu will get timer interrupts
+	 */
+	if (local_timer_setup(cpuid) == -1) {
+		printk(KERN_CRIT "cpu[%d]: timer alloc failed\n", cpuid);
+		smp_halt_processor();
+		return;
+	}
+#endif
+
+	/*
+	 * Notify those interested that we are up and alive.  This must
+	 * be done before interrupts are enabled.  It must also be completed
+	 * before the bootstrap cpu returns from __cpu_up() (see comment
+	 * above cpu_set() of the cpu_online_map).
+	 */
+	notify_cpu_starting(cpuid);
+
+	/*
+	 * Indicate that this thread is now online and present.   Setting
+	 * cpu_online_map has the side effect of allowing the bootstrap
+	 * cpu to continue along; so anything that MUST be done prior to the
+	 * bootstrap cpu returning from __cpu_up() needs to go above here.
+	 */
+	cpu_set(cpuid, cpu_online_map);
+	cpu_set(cpuid, cpu_present_map);
+
+	/*
+	 * Maintain a thread mapping in addition to the cpu mapping.
+	 */
+	smp_online_threads |= (1 << p->tid);
+
+	/*
+	 * Enable interrupts for this thread.
+	 */
+	local_irq_enable();
+
+	/*
+	 * Enter the idle loop and wait for a timer to schedule some work.
+	 */
+	printk(KERN_INFO "cpu[%d]: entering cpu_idle()\n", cpuid);
+	cpu_idle();
+
+	/* Not Reached */
+}
+
+/*
+ * smp_cpus_done()
+ *	Called once the kernel_init() has brought up all cpu(s).
+ */
+void smp_cpus_done(unsigned int cpu_max)
+{
+	/* Do Nothing */
+}
+
+/*
+ * __cpu_up()
+ *	Called to startup a sepcific cpu.
+ */
+int __cpuinit __cpu_up(unsigned int cpu)
+{
+	struct task_struct *idle;
+	unsigned int *stack;
+	long timeout;
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, cpu);
+
+	/*
+	 * Create an idle task for this CPU.
+	 */
+	idle = fork_idle(cpu);
+	if (IS_ERR(idle)) {
+		panic("cpu[%d]: fork failed\n", cpu);
+		return -ENOSYS;
+	}
+	task_thread_info(idle)->cpu = cpu;
+
+	/*
+	 * Setup the sw_ksp[] to point to this new task.
+	 */
+	sw_ksp[p->tid] = (unsigned int)idle->stack;
+	stack = (unsigned int *)(sw_ksp[p->tid] + PAGE_SIZE - 8);
+
+	/*
+	 * Cause the specified thread to execute our smp_mainline_start
+	 * function as a TYPE_NORMAL thread.
+	 */
+	printk(KERN_INFO "cpu[%d]: launching mainline Linux thread\n", cpu);
+	if (thread_start(p->tid, smp_mainline_start, (void *)NULL, stack,
+			 THREAD_TYPE_NORMAL) == -1) {
+		printk(KERN_WARNING "cpu[%d]: failed thread_start\n", cpu);
+		return -ENOSYS;
+	}
+
+	/*
+	 * Wait for the thread to start up.  The thread will set
+	 * the online bit when it is running.  Our caller execpts the
+	 * cpu to be online if we return 0.
+	 */
+	for (timeout = 0; timeout < 10000; timeout++) {
+		if (cpu_online(cpu)) {
+			break;
+		}
+
+		udelay(100);
+		barrier();
+		continue;
+	}
+
+	if (!cpu_online(cpu)) {
+		printk(KERN_CRIT "cpu[%d]: failed to live after %ld us\n",
+		       cpu, timeout * 100);
+		return -ENOSYS;
+	}
+
+	printk(KERN_INFO "cpu[%d]: came alive after %ld us\n",
+	       cpu, timeout * 100);
+	return 0;
+}
+
+/*
+ * Data used by setup_irq for the IPI.
+ */
+static struct irqaction ipi_irq = {
+	.name	 = "ipi",
+	.flags	 = IRQF_DISABLED | IRQF_PERCPU,
+	.handler = ipi_interrupt,
+};
+
+/*
+ * smp_prepare_cpus()
+ *	Mark threads that are available to Linux as possible cpus(s).
+ */
+void __init smp_prepare_cpus(unsigned int max_cpus)
+{
+	int i;
+
+	/*
+	 * We will need a software IRQ to send IPI(s).  We will use
+	 * a single software IRQ for all IPI(s).
+	 */
+	if (irq_soft_alloc(&smp_ipi_irq) < 0) {
+		panic("no software IRQ is available\n");
+		return;
+	}
+
+	/*
+	 * For the IPI interrupt, we want to use our own chip definition.
+	 * This allows us to define what happens in SMP IPI without affecting
+	 * the performance of the other interrupts.
+	 *
+	 * Next, Register the IPI interrupt function against the soft IRQ.
+	 */
+	set_irq_chip(smp_ipi_irq, &ubicom32_smp_chip);
+	setup_irq(smp_ipi_irq, &ipi_irq);
+
+	/*
+	 * We use the device tree node to determine how many
+	 * free cpus we will have (up to NR_CPUS) and we indicate
+	 * that those cpus are present.
+	 *
+	 * We need to do this very early in the SMP case
+	 * because the Linux init code uses the cpu_present_map.
+	 */
+	for_each_possible_cpu(i) {
+		thread_t tid;
+		struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, i);
+
+		/*
+		 *  Skip the bootstrap cpu
+		 */
+		if (i == 0) {
+			continue;
+		}
+
+		/*
+		 * If we have a free thread left in the mask,
+		 * indicate that the cpu is present.
+		 */
+		tid = thread_alloc();
+		if (tid == (thread_t)-1) {
+			break;
+		}
+
+		/*
+		 * Save the hardware thread id for this cpu.
+		 */
+		p->tid = tid;
+		cpu_set(i, cpu_present_map);
+		printk(KERN_INFO "cpu[%d]: added to cpu_present_map - tid: %d\n", i, tid);
+	}
+}
+
+/*
+ * smp_prepare_boot_cpu()
+ *	Copy the per_cpu data into the appropriate spot for the bootstrap cpu.
+ *
+ * The code in boot_cpu_init() has already set the boot cpu's
+ * state in the possible, present, and online maps.
+ */
+void __devinit smp_prepare_boot_cpu(void)
+{
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, 0);
+
+	smp_online_threads |= (1 << p->tid);
+	printk(KERN_INFO "cpu[%d]: bootstrap CPU online - tid: %ld\n",
+			current_thread_info()->cpu, p->tid);
+}
+
+/*
+ * smp_setup_processor_id()
+ *	Set the current_thread_info() structure cpu value.
+ *
+ * We set the value to the true hardware thread value that we are running on.
+ * NOTE: this function overrides the weak alias function in main.c
+ */
+void __init smp_setup_processor_id(void)
+{
+	struct cpuinfo_ubicom32 *p = &per_cpu(cpu_data, 0);
+	current_thread_info()->cpu = 0;
+	p->tid = thread_get_self();
+}
+
+/*
+ * setup_profiling_timer()
+ *	Dummy function created to keep Oprofile happy in the SMP case.
+ */
+int setup_profiling_timer(unsigned int multiplier)
+{
+	return 0;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/stacktrace.c
@@ -0,0 +1,243 @@
+/*
+ * arch/ubicom32/kernel/stacktrace.c
+ *   Ubicom32 architecture stack back trace implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/sched.h>
+#include <linux/stacktrace.h>
+#include <linux/module.h>
+#include <asm/stacktrace.h>
+#include <asm/thread.h>
+
+/*
+ * These symbols are filled in by the linker.
+ */
+extern unsigned long _stext;
+extern unsigned long _etext;
+
+extern unsigned long __ocm_text_run_begin;
+extern unsigned long __data_begin;
+
+/*
+ * stacktrace_iterate()
+ *	Walk the stack looking for call and calli instructions on an aligned
+ *	boundary.
+ *
+ * Trace must point to the top of the current stack frame.
+ */
+unsigned long stacktrace_iterate(unsigned long **trace,
+				 unsigned long stext,
+				 unsigned long etext,
+				 unsigned long ocm_stext,
+				 unsigned long ocm_etext,
+				 unsigned long sstack,
+				 unsigned long estack)
+{
+	unsigned int thread_trap_en, instruction;
+	unsigned long address;
+	unsigned int limit = 0;
+	unsigned long result = 0;
+	unsigned long *sp = *trace;
+
+	/*
+	 * Exclude the current thread from being monitored for traps.
+	 */
+	asm volatile(
+		"	thread_get_self_mask d15		\n\t"
+			/* save current trap status */
+		"	and.4	%0, MT_TRAP_EN, d15		\n\t"
+		"	not.4	d15, d15			\n\t"
+			/* disable trap */
+		"	and.4	MT_TRAP_EN, MT_TRAP_EN, d15	\n\t"
+		"	pipe_flush 0				\n\t"
+		: "=r" (thread_trap_en)
+		:
+		: "d15", "cc"
+	);
+
+	while (limit++ < 256) {
+		/*
+		 * See if we have a valid stack.
+		 */
+		if (!between((unsigned long)sp, sstack, estack)) {
+#ifdef TRAP_DEBUG_STACK_TRACE
+			printk(KERN_EMERG "stack address is out of range - "
+			       "sp: %x, sstack: %x, estack: %x\n",
+			       (unsigned int)sp, (unsigned int)sstack,
+			       (unsigned int)estack);
+#endif
+			result = 0;
+			*trace = 0;
+			break;
+		}
+
+		/*
+		 * Get the value off the stack and back up 4 bytes to what
+		 * should be the address of a call or calli.
+		 */
+		address = (*sp++) - 4;
+
+		/*
+		 * If the address is not within the text segment, skip this
+		 * value.
+		 */
+		if (!between(address, stext, etext) &&
+		    !between(address, ocm_stext, ocm_etext)) {
+#ifdef TRAP_DEBUG_STACK_TRACE
+			printk(KERN_EMERG "not a text address - "
+			       "address: %08x, stext: %08x, etext: %08x\n"
+			       "ocm_stext: %08x, ocm_etext: %08x\n",
+			       (unsigned int)address,
+			       (unsigned int)stext,
+			       (unsigned int)etext,
+			       (unsigned int)ocm_stext,
+			       (unsigned int)ocm_etext);
+#endif
+			continue;
+
+		}
+
+		/*
+		 * If the address is not on an aligned boundary it can not be a
+		 * return address.
+		 */
+		if (address & 0x3) {
+			continue;
+		}
+
+		/*
+		 * Read the probable instruction.
+		 */
+		instruction = *(unsigned int *)address;
+
+		/*
+		 * Is this a call instruction?
+		 */
+		if ((instruction & 0xF8000000) == (u32_t)(0x1B << 27)) {
+#ifdef TRAP_DEBUG_STACK_TRACE
+			printk(KERN_EMERG "call inst. result: %x, "
+			       "test: %x\n", (unsigned int)address,
+			       (unsigned int)instruction);
+#endif
+			*trace = sp;
+			result = address;
+			break;
+		}
+
+		/*
+		 * Is this a calli instruction?
+		 */
+		if ((instruction & 0xF8000000) == (u32_t)(0x1E << 27)) {
+#ifdef TRAP_DEBUG_STACK_TRACE
+			printk(KERN_EMERG "calli inst. result: %x, "
+			       "test: %x\n", (unsigned int)address,
+			       (unsigned int)instruction);
+#endif
+			*trace = sp;
+			result = address;
+			break;
+		}
+	}
+
+	/*
+	 * Restore the current thread to be monitored for traps.
+	 */
+	if (thread_trap_en) {
+		asm volatile(
+		"	thread_get_self_mask d15		\n\t"
+		"	or.4	MT_TRAP_EN, MT_TRAP_EN, d15	\n\t"
+			:
+			:
+			: "d15", "cc"
+		);
+	}
+	return result;
+}
+
+#ifdef CONFIG_STACKTRACE
+/*
+ * stacktrace_save_entries()
+ *	Save stack back trace information into the provided trace structure.
+ */
+void stacktrace_save_entries(struct task_struct *tsk,
+			     struct stack_trace *trace,
+			     unsigned long sp)
+{
+	unsigned long code_start = (unsigned long)&_stext;
+	unsigned long code_end = (unsigned long)&_etext;
+	unsigned long ocm_code_start = (unsigned long)&__ocm_text_run_begin;
+	unsigned long ocm_code_end = (unsigned long)&__data_begin;
+	unsigned long stack_end = (unsigned long)(tsk->stack + THREAD_SIZE - 8);
+	unsigned long stack = (unsigned long)sp;
+	unsigned int idx = 0;
+	unsigned long *handle;
+	int skip = trace->skip;
+
+	handle = (unsigned long *)stack;
+	while (idx < trace->max_entries) {
+		if (skip) {
+			skip--;
+			continue;
+		}
+		trace->entries[idx] = stacktrace_iterate(&handle,
+					code_start, code_end,
+					ocm_code_start, ocm_code_end,
+					(unsigned long)stack, stack_end);
+		if (trace->entries[idx] == 0) {
+			break;
+		}
+		idx++;
+	}
+}
+
+/*
+ * save_stack_trace()
+ *	Save the specified amount of the kernel stack trace information
+ *	for the current task.
+ */
+void save_stack_trace(struct stack_trace *trace)
+{
+	unsigned long sp = 0;
+	asm volatile (
+	"	move.4	%0, SP		\n\t"
+		: "=r" (sp)
+	);
+	stacktrace_save_entries(current, trace, sp);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
+
+/*
+ * save_stack_trace_tsk()
+ *	Save the specified amount of the kernel stack trace information
+ *	for the specified task.
+ *
+ * Note: We assume the specified task is not currently running.
+ */
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+	stacktrace_save_entries(tsk, trace, tsk->thread.sp);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
+#endif /* CONFIG_STACKTRACE */
--- /dev/null
+++ b/arch/ubicom32/kernel/syscalltable.S
@@ -0,0 +1,377 @@
+/*
+ * arch/ubicom32/kernel/syscalltable.S
+ *	<TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ *
+ *  Copyright (C) 2002, Greg Ungerer (gerg@snapgear.com)
+ *  Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>, Kenneth Albanowski <kjahds@kjahds.com>,
+ *  Copyright (C) 2000  Lineo Inc. (www.lineo.com) 
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+.text
+ALIGN
+	.global sys_call_table
+sys_call_table:	
+	.long sys_ni_syscall	/* 0  -  old "setup()" system call*/
+	.long sys_exit
+	.long sys_fork
+	.long sys_read
+	.long sys_write
+	.long sys_open		/* 5 */
+	.long sys_close
+	.long sys_waitpid
+	.long sys_creat
+	.long sys_link
+	.long sys_unlink	/* 10 */
+	.long execve_intercept
+	.long sys_chdir
+	.long sys_time
+	.long sys_mknod
+	.long sys_chmod		/* 15 */
+	.long sys_chown16
+	.long sys_ni_syscall	/* old break syscall holder */
+	.long sys_stat
+	.long sys_lseek
+	.long sys_getpid	/* 20 */
+	.long sys_mount
+	.long sys_oldumount
+	.long sys_setuid16
+	.long sys_getuid16
+	.long sys_stime		/* 25 */
+	.long sys_ptrace
+	.long sys_alarm
+	.long sys_fstat
+	.long sys_pause
+	.long sys_utime		/* 30 */
+	.long sys_ni_syscall	/* old stty syscall holder */
+	.long sys_ni_syscall	/* old gtty syscall holder */
+	.long sys_access
+	.long sys_nice
+	.long sys_ni_syscall	/* 35 */ /* old ftime syscall holder */
+	.long sys_sync
+	.long sys_kill
+	.long sys_rename
+	.long sys_mkdir
+	.long sys_rmdir		/* 40 */
+	.long sys_dup
+	.long sys_pipe
+	.long sys_times
+	.long sys_ni_syscall	/* old prof syscall holder */
+	.long sys_brk		/* 45 */
+	.long sys_setgid16
+	.long sys_getgid16
+	.long sys_signal
+	.long sys_geteuid16
+	.long sys_getegid16	/* 50 */
+	.long sys_acct
+	.long sys_umount	/* recycled never used phys() */
+	.long sys_ni_syscall	/* old lock syscall holder */
+	.long sys_ioctl
+	.long sys_fcntl		/* 55 */
+	.long sys_ni_syscall	/* old mpx syscall holder */
+	.long sys_setpgid
+	.long sys_ni_syscall	/* old ulimit syscall holder */
+	.long sys_ni_syscall
+	.long sys_umask		/* 60 */
+	.long sys_chroot
+	.long sys_ustat
+	.long sys_dup2
+	.long sys_getppid
+	.long sys_getpgrp	/* 65 */
+	.long sys_setsid
+	.long sys_sigaction
+	.long sys_sgetmask
+	.long sys_ssetmask
+	.long sys_setreuid16	/* 70 */
+	.long sys_setregid16
+	.long sys_sigsuspend
+	.long sys_sigpending
+	.long sys_sethostname
+	.long sys_setrlimit	/* 75 */
+	.long sys_old_getrlimit
+	.long sys_getrusage
+	.long sys_gettimeofday
+	.long sys_settimeofday
+	.long sys_getgroups16	/* 80 */
+	.long sys_setgroups16
+	.long old_select
+	.long sys_symlink
+	.long sys_lstat
+	.long sys_readlink	/* 85 */
+	.long sys_uselib
+	.long sys_ni_syscall	/* _sys_swapon */
+	.long sys_reboot
+	.long sys_old_readdir
+	.long old_mmap		/* 90 */
+	.long sys_munmap
+	.long sys_truncate
+	.long sys_ftruncate
+	.long sys_fchmod
+	.long sys_fchown16	/* 95 */
+	.long sys_getpriority
+	.long sys_setpriority
+	.long sys_ni_syscall	/* old profil syscall holder */
+	.long sys_statfs
+	.long sys_fstatfs	/* 100 */
+	.long sys_ni_syscall	/* ioperm for i386 */
+	.long sys_socketcall
+	.long sys_syslog
+	.long sys_setitimer
+	.long sys_getitimer	/* 105 */
+	.long sys_newstat
+	.long sys_newlstat
+	.long sys_newfstat
+	.long sys_ni_syscall
+	.long sys_ni_syscall	/* iopl for i386 */ /* 110 */
+	.long sys_vhangup
+	.long sys_ni_syscall	/* obsolete idle() syscall */
+	.long sys_ni_syscall	/* vm86old for i386 */
+	.long sys_wait4
+	.long sys_ni_syscall	/* 115 */ /* _sys_swapoff */
+	.long sys_sysinfo
+	.long sys_ipc
+	.long sys_fsync
+	.long sys_sigreturn
+	.long clone_intercept	/* 120 */
+	.long sys_setdomainname
+	.long sys_newuname
+	.long sys_cacheflush	/* modify_ldt for i386 */
+	.long sys_adjtimex
+	.long sys_ni_syscall	/* 125 */ /* _sys_mprotect */
+	.long sys_sigprocmask
+	.long sys_ni_syscall	/* old "creat_module" */
+	.long sys_init_module
+	.long sys_delete_module
+	.long sys_ni_syscall	/* 130: old "get_kernel_syms" */
+	.long sys_quotactl
+	.long sys_getpgid
+	.long sys_fchdir
+	.long sys_bdflush
+	.long sys_sysfs		/* 135 */
+	.long sys_personality
+	.long sys_ni_syscall	/* for afs_syscall */
+	.long sys_setfsuid16
+	.long sys_setfsgid16
+	.long sys_llseek	/* 140 */
+	.long sys_getdents
+	.long sys_select
+	.long sys_flock
+	.long sys_ni_syscall	/* _sys_msync */
+	.long sys_readv		/* 145 */
+	.long sys_writev
+	.long sys_getsid
+	.long sys_fdatasync
+	.long sys_sysctl
+	.long sys_ni_syscall	/* 150 */ /* _sys_mlock */
+	.long sys_ni_syscall	/* _sys_munlock */
+	.long sys_ni_syscall	/* _sys_mlockall */
+	.long sys_ni_syscall	/* _sys_munlockall */
+	.long sys_sched_setparam
+	.long sys_sched_getparam /* 155 */
+	.long sys_sched_setscheduler
+	.long sys_sched_getscheduler
+	.long sys_sched_yield
+	.long sys_sched_get_priority_max
+	.long sys_sched_get_priority_min  /* 160 */
+	.long sys_sched_rr_get_interval
+	.long sys_nanosleep
+	.long sys_ni_syscall	/* _sys_mremap */
+	.long sys_setresuid16
+	.long sys_getresuid16	/* 165 */
+	.long sys_getpagesize	/* _sys_getpagesize */
+	.long sys_ni_syscall	/* old "query_module" */
+	.long sys_poll
+	.long sys_ni_syscall	/* _sys_nfsservctl */
+	.long sys_setresgid16	/* 170 */
+	.long sys_getresgid16
+	.long sys_prctl
+	.long sys_rt_sigreturn
+	.long sys_rt_sigaction
+	.long sys_rt_sigprocmask /* 175 */
+	.long sys_rt_sigpending
+	.long sys_rt_sigtimedwait
+	.long sys_rt_sigqueueinfo
+	.long sys_rt_sigsuspend
+	.long sys_pread64	/* 180 */
+	.long sys_pwrite64
+	.long sys_lchown16
+	.long sys_getcwd
+	.long sys_capget
+	.long sys_capset	/* 185 */
+	.long sys_sigaltstack
+	.long sys_sendfile
+	.long sys_ni_syscall	/* streams1 */
+	.long sys_ni_syscall	/* streams2 */
+	.long vfork_intercept		/* 190 */
+	.long sys_getrlimit
+	.long sys_mmap2
+	.long sys_truncate64
+	.long sys_ftruncate64
+	.long sys_stat64	/* 195 */
+	.long sys_lstat64
+	.long sys_fstat64
+	.long sys_chown
+	.long sys_getuid
+	.long sys_getgid	/* 200 */
+	.long sys_geteuid
+	.long sys_getegid
+	.long sys_setreuid
+	.long sys_setregid
+	.long sys_getgroups	/* 205 */
+	.long sys_setgroups
+	.long sys_fchown
+	.long sys_setresuid
+	.long sys_getresuid
+	.long sys_setresgid	/* 210 */
+	.long sys_getresgid
+	.long sys_lchown
+	.long sys_setuid
+	.long sys_setgid
+	.long sys_setfsuid	/* 215 */
+	.long sys_setfsgid
+	.long sys_pivot_root
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_getdents64	/* 220 */
+	.long sys_gettid
+	.long sys_tkill
+	.long sys_setxattr
+	.long sys_lsetxattr
+	.long sys_fsetxattr	/* 225 */
+	.long sys_getxattr
+	.long sys_lgetxattr
+	.long sys_fgetxattr
+	.long sys_listxattr
+	.long sys_llistxattr	/* 230 */
+	.long sys_flistxattr
+	.long sys_removexattr
+	.long sys_lremovexattr
+	.long sys_fremovexattr
+	.long sys_futex		/* 235 */
+	.long sys_sendfile64
+	.long sys_ni_syscall	/* _sys_mincore */
+	.long sys_ni_syscall	/* _sys_madvise */
+	.long sys_fcntl64
+	.long sys_readahead	/* 240 */
+	.long sys_io_setup
+	.long sys_io_destroy
+	.long sys_io_getevents
+	.long sys_io_submit
+	.long sys_io_cancel	/* 245 */
+	.long sys_fadvise64
+	.long sys_exit_group
+	.long sys_lookup_dcookie
+	.long sys_epoll_create
+	.long sys_epoll_ctl	/* 250 */
+	.long sys_epoll_wait
+	.long sys_ni_syscall	/* _sys_remap_file_pages */
+	.long sys_set_tid_address
+	.long sys_timer_create
+	.long sys_timer_settime	/* 255 */
+	.long sys_timer_gettime
+	.long sys_timer_getoverrun
+	.long sys_timer_delete
+	.long sys_clock_settime
+	.long sys_clock_gettime	/* 260 */
+	.long sys_clock_getres
+	.long sys_clock_nanosleep
+	.long sys_statfs64
+	.long sys_fstatfs64
+	.long sys_tgkill	/* 265 */
+	.long sys_utimes
+	.long sys_fadvise64_64
+	.long sys_mbind	
+	.long sys_get_mempolicy
+	.long sys_set_mempolicy	/* 270 */
+	.long sys_mq_open
+	.long sys_mq_unlink
+	.long sys_mq_timedsend
+	.long sys_mq_timedreceive
+	.long sys_mq_notify	/* 275 */
+	.long sys_mq_getsetattr
+	.long sys_waitid
+	.long sys_ni_syscall	/* for _sys_vserver */
+	.long sys_add_key
+	.long sys_request_key	/* 280 */
+	.long sys_keyctl
+	.long sys_ioprio_set
+	.long sys_ioprio_get
+	.long sys_inotify_init
+	.long sys_inotify_add_watch	/* 285 */
+	.long sys_inotify_rm_watch
+	.long sys_migrate_pages
+	.long sys_openat
+	.long sys_mkdirat
+	.long sys_mknodat		/* 290 */
+	.long sys_fchownat
+	.long sys_futimesat
+	.long sys_fstatat64
+	.long sys_unlinkat
+	.long sys_renameat		/* 295 */
+	.long sys_linkat
+	.long sys_symlinkat
+	.long sys_readlinkat
+	.long sys_fchmodat
+	.long sys_faccessat		/* 300 */
+	.long sys_ni_syscall		/* Reserved for pselect6 */
+	.long sys_ni_syscall		/* Reserved for ppoll */
+	.long sys_unshare
+	.long sys_set_robust_list
+	.long sys_get_robust_list	/* 305 */
+	.long sys_splice
+	.long sys_sync_file_range
+	.long sys_tee
+	.long sys_vmsplice
+	.long sys_move_pages		/* 310 */
+	.long sys_sched_setaffinity
+	.long sys_sched_getaffinity
+	.long sys_kexec_load
+	.long sys_getcpu
+	.long sys_epoll_pwait		/* 315 */
+	.long sys_utimensat
+	.long sys_signalfd
+	.long sys_timerfd_create
+	.long sys_eventfd
+	.long sys_fallocate		/* 320 */
+	.long sys_timerfd_settime
+	.long sys_timerfd_gettime
+	.long sys_ni_syscall		/* sys_signalfd4 */
+	.long sys_ni_syscall		/* sys_eventfd2 */
+	.long sys_ni_syscall		/* sys_epoll_create1 */
+					/* 325 */
+	.long sys_ni_syscall		/* sys_dup3 */
+	.long sys_ni_syscall		/* sys_pipe2 */
+	.long sys_ni_syscall		/* sys_inotify_init1 */
+	.rept NR_syscalls-(.-sys_call_table)/4
+		.long sys_ni_syscall
+	.endr
+
--- /dev/null
+++ b/arch/ubicom32/kernel/sys_ubicom32.c
@@ -0,0 +1,237 @@
+/*
+ * arch/ubicom32/kernel/sys_ubicom32.c
+ *   Ubicom32 architecture system call support implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ * This file contains various random system calls that
+ * have a non-standard calling sequence on the Linux/ubicom32
+ * platform.
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/sem.h>
+#include <linux/msg.h>
+#include <linux/shm.h>
+#include <linux/stat.h>
+#include <linux/syscalls.h>
+#include <linux/mman.h>
+#include <linux/file.h>
+#include <linux/utsname.h>
+#include <linux/ipc.h>
+#include <linux/fs.h>
+#include <linux/uaccess.h>
+#include <linux/unistd.h>
+
+#include <asm/setup.h>
+#include <asm/traps.h>
+#include <asm/cacheflush.h>
+
+/* common code for old and new mmaps */
+static inline long do_mmap2(
+	unsigned long addr, unsigned long len,
+	unsigned long prot, unsigned long flags,
+	unsigned long fd, unsigned long pgoff)
+{
+	int error = -EBADF;
+	struct file *file = NULL;
+
+	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
+	if (!(flags & MAP_ANONYMOUS)) {
+		file = fget(fd);
+		if (!file)
+			goto out;
+	}
+
+	down_write(&current->mm->mmap_sem);
+	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	up_write(&current->mm->mmap_sem);
+
+	if (file)
+		fput(file);
+out:
+	return error;
+}
+
+asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
+	unsigned long prot, unsigned long flags,
+	unsigned long fd, unsigned long pgoff)
+{
+	return do_mmap2(addr, len, prot, flags, fd, pgoff);
+}
+
+/*
+ * Perform the select(nd, in, out, ex, tv) and mmap() system
+ * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
+ * handle more than 4 system call parameters, so these system calls
+ * used a memory block for parameter passing..
+ */
+
+struct mmap_arg_struct {
+	unsigned long addr;
+	unsigned long len;
+	unsigned long prot;
+	unsigned long flags;
+	unsigned long fd;
+	unsigned long offset;
+};
+
+asmlinkage int old_mmap(struct mmap_arg_struct *arg)
+{
+	struct mmap_arg_struct a;
+	int error = -EFAULT;
+
+	if (copy_from_user(&a, arg, sizeof(a)))
+		goto out;
+
+	error = -EINVAL;
+	if (a.offset & ~PAGE_MASK)
+		goto out;
+
+	a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
+
+	error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd,
+			 a.offset >> PAGE_SHIFT);
+out:
+	return error;
+}
+
+struct sel_arg_struct {
+	unsigned long n;
+	fd_set *inp, *outp, *exp;
+	struct timeval *tvp;
+};
+
+asmlinkage int old_select(struct sel_arg_struct *arg)
+{
+	struct sel_arg_struct a;
+
+	if (copy_from_user(&a, arg, sizeof(a)))
+		return -EFAULT;
+	/* sys_select() does the appropriate kernel locking */
+	return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
+}
+
+/*
+ * sys_ipc() is the de-multiplexer for the SysV IPC calls..
+ *
+ * This is really horribly ugly.
+ */
+asmlinkage int sys_ipc(uint call, int first, int second,
+			int third, void *ptr, long fifth)
+{
+	int version, ret;
+
+	version = call >> 16; /* hack for backward compatibility */
+	call &= 0xffff;
+
+	if (call <= SEMCTL)
+		switch (call) {
+		case SEMOP:
+			return sys_semop(first, (struct sembuf *)ptr, second);
+		case SEMGET:
+			return sys_semget(first, second, third);
+		case SEMCTL: {
+			union semun fourth;
+			if (!ptr)
+				return -EINVAL;
+			if (get_user(fourth.__pad, (void **) ptr))
+				return -EFAULT;
+			return sys_semctl(first, second, third, fourth);
+			}
+		default:
+			return -EINVAL;
+		}
+	if (call <= MSGCTL)
+		switch (call) {
+		case MSGSND:
+			return sys_msgsnd(first, (struct msgbuf *) ptr,
+					  second, third);
+		case MSGRCV:
+			switch (version) {
+			case 0: {
+				struct ipc_kludge tmp;
+				if (!ptr)
+					return -EINVAL;
+				if (copy_from_user(&tmp,
+						   (struct ipc_kludge *)ptr,
+						   sizeof(tmp)))
+					return -EFAULT;
+				return sys_msgrcv(first, tmp.msgp, second,
+						   tmp.msgtyp, third);
+				}
+			default:
+				return sys_msgrcv(first,
+						  (struct msgbuf *) ptr,
+						  second, fifth, third);
+			}
+		case MSGGET:
+			return sys_msgget((key_t) first, second);
+		case MSGCTL:
+			return sys_msgctl(first, second,
+					   (struct msqid_ds *) ptr);
+		default:
+			return -EINVAL;
+		}
+	if (call <= SHMCTL)
+		switch (call) {
+		case SHMAT:
+			switch (version) {
+			default: {
+				ulong raddr;
+				ret = do_shmat(first, ptr, second, &raddr);
+				if (ret)
+					return ret;
+				return put_user(raddr, (ulong __user *) third);
+			}
+			}
+		case SHMDT:
+			return sys_shmdt(ptr);
+		case SHMGET:
+			return sys_shmget(first, second, third);
+		case SHMCTL:
+			return sys_shmctl(first, second, ptr);
+		default:
+			return -ENOSYS;
+		}
+
+	return -EINVAL;
+}
+
+/* sys_cacheflush -- flush (part of) the processor cache.  */
+asmlinkage int
+sys_cacheflush(unsigned long addr, int scope, int cache, unsigned long len)
+{
+	flush_cache_all();
+	return 0;
+}
+
+asmlinkage int sys_getpagesize(void)
+{
+	return PAGE_SIZE;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/thread.c
@@ -0,0 +1,228 @@
+/*
+ * arch/ubicom32/kernel/thread.c
+ *   Ubicom32 architecture hardware thread support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/profile.h>
+#include <linux/clocksource.h>
+#include <linux/types.h>
+#include <asm/ip5000.h>
+#include <asm/machdep.h>
+#include <asm/asm-offsets.h>
+#include <asm/thread.h>
+
+/*
+ * TODO: At some point change the name here to be thread_ksp
+ */
+unsigned int sw_ksp[THREAD_ARCHITECTURAL_MAX];
+
+static unsigned int thread_mask = -1;
+static unsigned int thread_mainline_mask;
+
+/*
+ * thread_entry()
+ *	Returning from the called function will disable the thread.
+ *
+ * This could be a naked call to allow for hwthreads that do not have stacks.
+ * However, with -O0, the code still writes to thex stack, and this was
+ * corrupting memory just after the callers stack.
+ */
+static void thread_entry(void *arg, thread_exec_fn_t exec)
+{
+	/*
+	 * Call thread function
+	 */
+	exec(arg);
+
+	/*
+	 * Complete => Disable self
+	 */
+	thread_disable(thread_get_self());
+}
+
+/*
+ * thread_start()
+ *	Start the specified function on the specified hardware thread.
+ */
+thread_t thread_start(thread_t thread,
+		      thread_exec_fn_t exec,
+		      void *arg,
+		      unsigned int *sp_high,
+		      thread_type_t type)
+{
+	/*
+	 * Sanity check
+	 */
+	unsigned int enabled, mask, csr;
+	asm volatile (
+		"move.4		%0, MT_EN\n\t"
+		: "=m" (enabled)
+	);
+
+	mask = 1 << thread;
+	if (enabled & mask) {
+		printk(KERN_WARNING "request to enable a previously enabled thread\n");
+		return (thread_t)-1;
+	}
+
+	/*
+	 * Update thread state
+	 */
+	csr = (thread << 15) | (1 << 14);
+	asm volatile (
+		"setcsr		%0		\n\t"
+		"setcsr_flush	0		\n\t"
+
+		"move.4		A0, #0		\n\t"
+		"move.4		A1, #0		\n\t"
+		"move.4		A2, #0		\n\t"
+		"move.4		A3, #0		\n\t"
+		"move.4		A4, #0		\n\t"
+		"move.4		A5, #0		\n\t"
+		"move.4		A6, #0		\n\t"
+		"move.4		SP, %4		\n\t"	/* A7 is SP */
+
+		"move.4		D0, %3		\n\t"
+		"move.4		D1, %2		\n\t"
+		"move.4		D2, #0		\n\t"
+		"move.4		D3, #0		\n\t"
+		"move.4		D4, #0		\n\t"
+		"move.4		D5, #0		\n\t"
+		"move.4		D6, #0		\n\t"
+		"move.4		D7, #0		\n\t"
+		"move.4		D8, #0		\n\t"
+		"move.4		D9, #0		\n\t"
+		"move.4		D10, #0		\n\t"
+		"move.4		D11, #0		\n\t"
+		"move.4		D12, #0		\n\t"
+		"move.4		D13, #0		\n\t"
+		"move.4		D14, #0		\n\t"
+		"move.4		D15, #0		\n\t"
+
+		"move.4		INT_MASK0, #0	\n\t"
+		"move.4		INT_MASK1, #0	\n\t"
+		"move.4		PC, %1		\n\t"
+		"setcsr		#0		\n\t"
+		"setcsr_flush	0		\n\t"
+		:
+		: "r" (csr), "r" (thread_entry), "r" (exec),
+		  "r" (arg), "r" (sp_high)
+	);
+
+	/*
+	 * Apply HRT state
+	 */
+	if (type & THREAD_TYPE_HRT) {
+		asm volatile (
+			"or.4		MT_HRT, MT_HRT, %0\n\t"
+			:
+			: "d" (mask)
+			: "cc"
+		);
+	} else {
+		asm volatile (
+			"and.4		MT_HRT, MT_HRT, %0\n\t"
+			:
+			: "d" (~mask)
+			: "cc"
+		);
+	}
+
+	/*
+	 * Set priority
+	 */
+	asm volatile (
+		"or.4		MT_HPRI, MT_HPRI, %0\n\t"
+		:
+		: "d" (mask)
+		: "cc"
+	);
+
+	/*
+	 * Enable thread
+	 */
+	asm volatile (
+		"move.4		MT_ACTIVE_SET, %0	\n\t"
+		:
+		: "d" (mask)
+	);
+	thread_enable_mask(mask);
+	return thread;
+}
+
+/*
+ * thread_get_mainline()
+ *	Return a mask of those threads that are Linux mainline threads.
+ */
+unsigned int thread_get_mainline(void)
+{
+	return thread_mainline_mask;
+}
+
+/*
+ * thread_set_mainline()
+ *	Indicate that the specified thread is a Linux mainline thread.
+ */
+void thread_set_mainline(thread_t tid)
+{
+	thread_mainline_mask |= (1 << tid);
+}
+
+/*
+ * thread_alloc()
+ *	Allocate an unused hardware thread.
+ */
+thread_t thread_alloc(void)
+{
+	thread_t tid;
+
+	/*
+	 * If this is the first time we are here get the list of unused
+	 * threads from the processor device tree node.
+	 */
+	if (thread_mask == -1) {
+		thread_mask = processor_threads();
+	}
+
+	if (!thread_mask) {
+		return (thread_t)-1;
+	}
+
+	tid = ffs(thread_mask);
+	if (tid != 0) {
+		tid--;
+		thread_mask &= ~(1 << tid);
+		return tid;
+	}
+
+	return (thread_t)-1;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/time.c
@@ -0,0 +1,212 @@
+/*
+ * arch/ubicom32/kernel/time.c
+ *	Initialize the timer list and start the appropriate timers.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1991, 1992, 1995  Linus Torvalds
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/profile.h>
+#include <linux/smp.h>
+#include <asm/ip5000.h>
+#include <asm/machdep.h>
+
+/*
+ * A bitmap of the timers on the processor indicates
+ * that the timer is free or in-use.
+ */
+static unsigned int timers;
+
+/*
+ * timer_set()
+ *	Init the specified compare register to go off <n> cycles from now.
+ */
+void timer_set(int timervector, unsigned int cycles)
+{
+	int idx = UBICOM32_VECTOR_TO_TIMER_INDEX(timervector);
+	UBICOM32_IO_TIMER->syscom[idx] =
+			UBICOM32_IO_TIMER->sysval + cycles;
+	ldsr_enable_vector(timervector);
+}
+
+/*
+ * timer_reset()
+ *	Set/reset the timer to go off again.
+ *
+ * Because sysval is a continuous timer, this function is able
+ * to ensure that we do not have clock sku by using the previous
+ * value in syscom to set the next value for syscom.
+ *
+ * Returns the number of ticks that transpired since the last event.
+ */
+int timer_reset(int timervector, unsigned int cycles)
+{
+	/*
+	 * Reset the timer in the LDSR thread to go off appropriately.
+	 *
+	 * Use the previous value of the timer to calculate the new stop
+	 * time.  This allows us to account for it taking an
+	 * indeterminate amount of time to get here.
+	 */
+	const int timer_index = UBICOM32_VECTOR_TO_TIMER_INDEX(timervector);
+	unsigned int prev = UBICOM32_IO_TIMER->syscom[timer_index];
+	unsigned int next = prev + cycles;
+	int scratchpad3;
+	int diff;
+	int ticks = 1;
+
+	/*
+	 * If the difference is negative, we have missed at least one
+	 * timer tick.
+	 *
+	 * TODO: Decide if we want to "ignore" time (as done below) or
+	 * if we want to process time (unevenly) by calling timer_tick()
+	 * lost_ticks times.
+	 */
+	while (1) {
+		/*
+		 * Set our future time first.
+		 */
+		UBICOM32_IO_TIMER->syscom[timer_index] = next;
+
+		/*
+		 * Then check if we are really set time in the futrue.
+		 */
+		diff = (int)next - (int)UBICOM32_IO_TIMER->sysval;
+		if (diff >= 0) {
+			break;
+		}
+
+		/*
+		 * Oops, we are too slow. Playing catch up.
+		 *
+		 * If the debugger is connected the there is a good
+		 * chance that we lost time because we were in a
+		 * break-point, so in this case we do not print out
+		 * diagnostics.
+		 */
+		asm volatile ("move.4 %0, scratchpad3"
+			      : "=r" (scratchpad3));
+		if ((scratchpad3 & 0x1) == 0) {
+			/*
+			 * No debugger attached, print to the console
+			 */
+			printk(KERN_EMERG "diff: %d, timer has lost %u "
+			       "ticks [rounded up]\n",
+			       -diff,
+			       (unsigned int)((-diff + cycles - 1) / cycles));
+		}
+
+		do {
+			next += cycles;
+			diff = (int)next - (int)UBICOM32_IO_TIMER->sysval;
+			ticks++;
+		} while (diff < 0);
+	}
+	return ticks;
+}
+
+/*
+ * sched_clock()
+ *	Returns current time in nano-second units.
+ *
+ * Notes:
+ * 1) This is an override for the weak alias in
+ * kernel/sched_clock.c.
+ * 2) Do not use xtime_lock as this function is
+ * sometimes called with xtime_lock held.
+ * 3) We use a retry algorithm to ensure that
+ * we get a consistent value.
+ * 4) sched_clock must be overwritten if IRQ tracing
+ * is enabled because the default implementation uses
+ * the xtime_lock sequence while holding xtime_lock.
+ */
+unsigned long long sched_clock(void)
+{
+	unsigned long long my_jiffies;
+	unsigned long jiffies_top;
+	unsigned long jiffies_bottom;
+
+	do {
+		jiffies_top = jiffies_64 >> 32;
+		jiffies_bottom = jiffies_64 & 0xffffffff;
+	} while (unlikely(jiffies_top != (unsigned long)(jiffies_64 >> 32)));
+
+	my_jiffies = ((unsigned long long)jiffies_top << 32) | (jiffies_bottom);
+	return (my_jiffies - INITIAL_JIFFIES) * (NSEC_PER_SEC / HZ);
+}
+
+/*
+ * timer_free()
+ *	Free a hardware timer.
+ */
+void timer_free(int interrupt)
+{
+	unsigned int bit = interrupt - TIMER_INT(0);
+
+	/*
+	 * The timer had not been allocated.
+	 */
+	BUG_ON(timers & (1 << bit));
+	timers |= (1 << bit);
+}
+
+/*
+ * timer_alloc()
+ *	Allocate a hardware timer.
+ */
+int timer_alloc(void)
+{
+	unsigned int bit = find_first_bit((unsigned long *)&timers, 32);
+	if (!bit) {
+		printk(KERN_WARNING "no more free timers\n");
+		return -1;
+	}
+
+	timers &= ~(1 << bit);
+	return bit + TIMER_INT(0);
+}
+
+/*
+ * time_init()
+ *	Time init function.
+ */
+void time_init(void)
+{
+	/*
+	 * Find the processor node and determine what timers are
+	 * available for us.
+	 */
+	timers = processor_timers();
+	if (timers == 0) {
+		printk(KERN_WARNING "no timers are available for Linux\n");
+		return;
+	}
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
+	timer_device_init();
+#else
+	timer_tick_init();
+#endif
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/timer_broadcast.c
@@ -0,0 +1,102 @@
+/*
+ * arch/ubicom32/kernel/timer_broadcast.c
+ *   Implements a dummy clock event for each cpu.
+ *
+ * Copyright (C) 2008  Paul Mundt
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *   arch/arm
+ *   arch/sh
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/smp.h>
+#include <linux/jiffies.h>
+#include <linux/percpu.h>
+#include <linux/clockchips.h>
+#include <linux/irq.h>
+
+static DEFINE_PER_CPU(struct clock_event_device, local_clockevent);
+
+/*
+ *  The broadcast trick only works when the timer will be used in a periodic mode.
+ *  If the user has configured either NO_HZ or HIGH_RES_TIMERS they must have
+ *  a per cpu timer.
+ */
+#if defined(CONFIG_NO_HZ) || defined(CONFIG_HIGH_RES_TIMERS)
+#error "Tickless and High Resolution Timers require per-CPU local timers: CONFIG_LOCAL_TIMERS"
+#endif
+
+/*
+ * local_timer_interrupt()
+ *	Used on SMP for local timer interrupt sent via an IPI.
+ */
+void local_timer_interrupt(void)
+{
+	struct clock_event_device *dev = &__get_cpu_var(local_clockevent);
+
+	dev->event_handler(dev);
+}
+
+/*
+ * dummy_timer_set_next_event()
+ *	Cause the timer to go off "cycles" from now.
+ */
+static int dummy_timer_set_next_event(unsigned long cycles, struct clock_event_device *dev)
+{
+	return 0;
+}
+
+/*
+ * dummy_timer_set_mode()
+ *	Do Nothing.
+ */
+static void dummy_timer_set_mode(enum clock_event_mode mode,
+				 struct clock_event_device *clk)
+{
+}
+
+/*
+ * local_timer_setup()
+ *	Adds a clock event for the specified cpu.
+ */
+int __cpuinit local_timer_setup(unsigned int cpu)
+{
+	struct clock_event_device *dev = &per_cpu(local_clockevent, cpu);
+
+	dev->name		= "timer-dummy";
+	dev->features		= CLOCK_EVT_FEAT_DUMMY;
+	dev->rating		= 200;
+	dev->mult		= 1;
+	dev->set_mode		= dummy_timer_set_mode;
+	dev->set_next_event	= dummy_timer_set_next_event;
+	dev->broadcast		= smp_timer_broadcast;
+	dev->cpumask		= cpumask_of_cpu(cpu);
+	dev->irq		= -1;
+	printk(KERN_NOTICE "timer[%d]: %s - created\n", dev->irq, dev->name);
+
+	clockevents_register_device(dev);
+	return 0;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/timer_device.c
@@ -0,0 +1,302 @@
+/*
+ * arch/ubicom32/kernel/timer_device.c
+ *   Implements a Ubicom32 clock device and event devices.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/types.h>
+#include <linux/clockchips.h>
+#include <linux/clocksource.h>
+#include <linux/spinlock.h>
+#include <asm/ip5000.h>
+#include <asm/machdep.h>
+
+#if defined(CONFIG_SMP)
+#include <asm/smp.h>
+#endif
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
+#define MAX_TIMERS (2 + CONFIG_TIMER_EXTRA_ALLOC)
+#else
+#define MAX_TIMERS (NR_CPUS + CONFIG_TIMER_EXTRA_ALLOC)
+#endif
+
+#if (MAX_TIMERS > 10)
+#error "Ubicom32 only has 10 timers"
+#endif
+
+static unsigned int frequency;
+static struct clock_event_device timer_device_devs[MAX_TIMERS];
+static struct irqaction timer_device_irqs[MAX_TIMERS];
+static int timer_device_next_timer = 0;
+
+DEFINE_SPINLOCK(timer_device_lock);
+
+/*
+ * timer_device_set_next_event()
+ *	Cause the timer to go off "cycles" from now.
+ */
+static int timer_device_set_next_event(unsigned long cycles, struct clock_event_device *dev)
+{
+	timer_set(dev->irq, cycles);
+	return 0;
+}
+
+/*
+ * timer_device_set_mode()
+ *	Handle the mode switch for a clock event device.
+ */
+static void timer_device_set_mode(enum clock_event_mode mode, struct clock_event_device *dev)
+{
+	switch (mode) {
+	case CLOCK_EVT_MODE_SHUTDOWN:
+		/*
+		 * Make sure the vector is disabled
+		 * until the next event is set.
+		 */
+		printk(KERN_NOTICE "timer[%d]: shutdown\n", dev->irq);
+		ldsr_disable_vector(dev->irq);
+		break;
+
+	case CLOCK_EVT_MODE_ONESHOT:
+		/*
+		 * Make sure the vector is disabled
+		 * until the next event is set.
+		 */
+		printk(KERN_NOTICE "timer[%d]: oneshot\n", dev->irq);
+		ldsr_disable_vector(dev->irq);
+		break;
+
+	case CLOCK_EVT_MODE_PERIODIC:
+		/*
+		 * The periodic request is 1 per jiffies
+		 */
+		printk(KERN_NOTICE "timer[%d]: periodic: %d cycles\n",
+			dev->irq, frequency / CONFIG_HZ);
+		timer_set(dev->irq, frequency / CONFIG_HZ);
+		break;
+
+	case CLOCK_EVT_MODE_UNUSED:
+	case CLOCK_EVT_MODE_RESUME:
+		printk(KERN_WARNING "timer[%d]: unimplemented mode: %d\n",
+			dev->irq, mode);
+		break;
+	};
+}
+
+/*
+ * timer_device_event()
+ *	Call the device's event handler.
+ *
+ * The pointer is initialized by the generic Linux code
+ * to the function to be called.
+ */
+static irqreturn_t timer_device_event(int irq, void *dev_id)
+{
+	struct clock_event_device *dev = (struct clock_event_device *)dev_id;
+
+	if (dev->mode == CLOCK_EVT_MODE_PERIODIC) {
+		/*
+		 * The periodic request is 1 per jiffies
+		 */
+		timer_reset(dev->irq, frequency / CONFIG_HZ);
+	} else {
+		/*
+		 * The timer will go off again at the rollover
+		 * point.  We must disable the IRQ to prevent
+		 * getting a spurious interrupt.
+		 */
+		ldsr_disable_vector(dev->irq);
+	}
+
+	if (!dev->event_handler) {
+		printk(KERN_CRIT "no registered event handler\n");
+		return IRQ_HANDLED;
+	}
+
+	dev->event_handler(dev);
+	return IRQ_HANDLED;
+}
+
+/*
+ * timer_device_clockbase_read()
+ *	Provide a primary clocksource around the sysval timer.
+ */
+static cycle_t timer_device_clockbase_read(void)
+{
+	return (cycle_t)UBICOM32_IO_TIMER->sysval;
+}
+
+/*
+ * Primary Clock Source Description
+ *
+ * We use 24 for the shift factor because we want
+ * to ensure there are less than 2^24 clocks
+ * in a jiffie of 10 ms.
+ */
+static struct clocksource timer_device_clockbase = {
+	.name	= "sysval",
+	.rating	= 400,
+	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
+	.mask	= CLOCKSOURCE_MASK(32),
+	.shift	= 24,
+	.mult	= 0,
+	.read	= timer_device_clockbase_read,
+};
+
+/*
+ * timer_device_alloc_event()
+ * 	Allocate a timer device event.
+ */
+static int timer_device_alloc_event(const char *name, int cpuid, cpumask_t mask)
+{
+	struct clock_event_device *dev;
+	struct irqaction *action;
+
+	/*
+	 * Are we out of configured timers?
+	 */
+	spin_lock(&timer_device_lock);
+	if (timer_device_next_timer >= MAX_TIMERS) {
+		spin_unlock(&timer_device_lock);
+		printk(KERN_WARNING "out of timer event entries\n");
+		return -1;
+	}
+	dev = &timer_device_devs[timer_device_next_timer];
+	action = &timer_device_irqs[timer_device_next_timer];
+	timer_device_next_timer++;
+	spin_unlock(&timer_device_lock);
+
+	/*
+	 * Now allocate a timer to ourselves.
+	 */
+	dev->irq = timer_alloc();
+	if (dev->irq == -1) {
+		spin_lock(&timer_device_lock);
+		timer_device_next_timer--;
+		spin_unlock(&timer_device_lock);
+		printk(KERN_WARNING "out of hardware timers\n");
+		return -1;
+	}
+
+	/*
+	 * Init the IRQ action structure.  Make sure
+	 * this in place before you register the clock
+	 * event device.
+	 */
+	action->name = name;
+	action->flags = IRQF_DISABLED | IRQF_TIMER;
+	action->handler = timer_device_event;
+	action->mask = mask;
+	action->dev_id = dev;
+	setup_irq(dev->irq, action);
+	irq_set_affinity(dev->irq, mask);
+	ldsr_disable_vector(dev->irq);
+
+	/*
+	 * init clock dev structure.
+	 *
+	 * The min_delta_ns is chosen to ensure that setting next
+	 * event will never be requested with too small of value.
+	 */
+	dev->name = name;
+	dev->rating = timer_device_clockbase.rating;
+	dev->shift = timer_device_clockbase.shift;
+	dev->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
+	dev->set_mode = timer_device_set_mode;
+	dev->set_next_event = timer_device_set_next_event;
+	dev->mult = div_sc(frequency, NSEC_PER_SEC, dev->shift);
+	dev->max_delta_ns = clockevent_delta2ns(0xffffffff, dev);
+	dev->min_delta_ns = clockevent_delta2ns(100, dev);
+	dev->cpumask = mask;
+	printk(KERN_NOTICE "timer[%d]: %s - created\n", dev->irq, dev->name);
+
+	/*
+	 * Now register the device.
+	 */
+	clockevents_register_device(dev);
+	return dev->irq;
+}
+
+#if defined(CONFIG_LOCAL_TIMERS)
+/*
+ * local_timer_setup()
+ * 	Allocation function for creating a per cpu local timer.
+ */
+int __cpuinit local_timer_setup(unsigned int cpu)
+{
+	return timer_device_alloc_event("timer-cpu", cpu, cpumask_of_cpu(cpu));
+}
+#endif
+
+/*
+ * timer_device_init()
+ * 	Create and init a generic clock driver for Ubicom32.
+ */
+void timer_device_init(void)
+{
+	int i;
+
+	/*
+	 * Get the frequency from the processor device tree node or use
+	 * the default if not available. We will store this as the frequency
+	 * of the timer to avoid future calculations.
+	 */
+	frequency = processor_frequency();
+	if (frequency == 0) {
+		frequency = CLOCK_TICK_RATE;
+	}
+
+	/*
+	 * Setup the primary clock source around sysval.  Linux does not
+	 * supply a Mhz multiplier so convert down to khz.
+	 */
+	timer_device_clockbase.mult =
+		clocksource_khz2mult(frequency / 1000,
+			timer_device_clockbase.shift);
+	if (clocksource_register(&timer_device_clockbase)) {
+		printk(KERN_ERR "timer: clocksource failed to register\n");
+		return;
+	}
+
+	/*
+	 * Always allocate a primary timer.
+	 */
+	timer_device_alloc_event("timer-primary", -1, CPU_MASK_ALL);
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
+	/*
+	 * If BROADCAST is selected we need to add a broadcast timer.
+	 */
+	timer_device_alloc_event("timer-broadcast", -1, CPU_MASK_ALL);
+#endif
+
+	/*
+	 * Allocate extra timers that are requested.
+	 */
+	for (i = 0; i < CONFIG_TIMER_EXTRA_ALLOC; i++) {
+		timer_device_alloc_event("timer-extra", -1, CPU_MASK_ALL);
+	}
+}
+
--- /dev/null
+++ b/arch/ubicom32/kernel/timer_tick.c
@@ -0,0 +1,109 @@
+/*
+ * arch/ubicom32/kernel/timer_tick.c
+ *	Impelemets a perodic timer.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 1991, 1992, 1995  Linus Torvalds
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/profile.h>
+
+#include <asm/ip5000.h>
+#include <asm/machdep.h>
+#if defined(CONFIG_SMP)
+#include <asm/smp.h>
+#endif
+
+static unsigned int timervector;
+static unsigned int frequency;
+
+/*
+ * timer_tick()
+ *	Kernel system timer support. Needs to keep up the real-time clock, 
+ * 	as well as call the "do_timer()" routine every clocktick.
+ */
+static irqreturn_t timer_tick(int irq, void *dummy)
+{
+	int ticks;
+
+	BUG_ON(!irqs_disabled());
+	ticks = timer_reset(timervector, frequency);
+
+	write_seqlock(&xtime_lock);
+	do_timer(ticks);
+	write_sequnlock(&xtime_lock);
+
+	update_process_times(user_mode(get_irq_regs()));
+	profile_tick(CPU_PROFILING);
+
+#if defined(CONFIG_SMP)
+	smp_send_timer_all();
+#endif
+	return(IRQ_HANDLED);
+}
+
+/*
+ * Data used by setup_irq for the timer.
+ */
+static struct irqaction timer_irq = {
+	.name	 = "timer",
+	.flags	 = IRQF_DISABLED | IRQF_TIMER,
+	.handler = timer_tick,
+};
+
+/*
+ * timer_tick_init()
+ * 	Implements a periodic timer
+ *
+ * This implementation directly calls the timer_tick() and move
+ * the Linux kernel forward.  This is used when the user has not
+ * selected GENERIC_CLOCKEVENTS.
+ */
+void timer_tick_init(void)
+{
+	/*
+	 * Now allocate a timer to ourselves.
+	 */
+	timervector = timer_alloc();
+	if (timervector == -1) {
+		printk(KERN_WARNING "where did the timer go?\n");
+		return;
+	}
+
+	setup_irq(timervector, &timer_irq);
+
+	/*
+	 * Get the frequency from the processor device tree node or use
+	 * the default if not available. We will store this as the frequency
+	 * of the timer to avoid future calculations.
+	 */
+	frequency = processor_frequency();
+	if (frequency == 0) {
+		frequency = CLOCK_TICK_RATE;
+	}
+	frequency /= CONFIG_HZ;
+
+	printk(KERN_NOTICE "timer will interrupt every: %d cycles\n", frequency);
+	timer_set(timervector, frequency);
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/topology.c
@@ -0,0 +1,47 @@
+/*
+ * arch/ubicom32/kernel/topology.c
+ *   Ubicom32 architecture sysfs topology information.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/cpu.h>
+#include <linux/cache.h>
+
+static struct cpu cpu_devices[NR_CPUS] __read_mostly;
+
+static int __init topology_init(void)
+{
+	int num;
+
+	for_each_present_cpu(num) {
+		cpu_devices[num].hotpluggable = 0;
+		register_cpu(&cpu_devices[num], num);
+	}
+	return 0;
+}
+
+subsys_initcall(topology_init);
--- /dev/null
+++ b/arch/ubicom32/kernel/traps.c
@@ -0,0 +1,510 @@
+/*
+ * arch/ubicom32/kernel/traps.c
+ *   Ubicom32 architecture trap handling support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+/*
+ * Sets up all exception vectors
+ */
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/a.out.h>
+#include <linux/user.h>
+#include <linux/string.h>
+#include <linux/linkage.h>
+#include <linux/init.h>
+#include <linux/ptrace.h>
+#include <linux/kallsyms.h>
+#include <linux/compiler.h>
+#include <linux/stacktrace.h>
+#include <linux/personality.h>
+
+#include <asm/uaccess.h>
+#include <asm/stacktrace.h>
+#include <asm/devtree.h>
+#include <asm/setup.h>
+#include <asm/fpu.h>
+#include <asm/system.h>
+#include <asm/traps.h>
+#include <asm/pgtable.h>
+#include <asm/machdep.h>
+#include <asm/siginfo.h>
+#include <asm/ip5000.h>
+#include <asm/thread.h>
+
+#define TRAP_MAX_STACK_DEPTH 20
+
+/*
+ * These symbols are filled in by the linker.
+ */
+extern unsigned long _stext;
+extern unsigned long _etext;
+
+extern unsigned long __ocm_text_run_begin;
+extern unsigned long __data_begin;
+
+const char *trap_cause_strings[] = {
+	/*0*/	"inst address decode error",
+	/*1*/	"inst sync error",
+	/*2*/	"inst illegal",
+	/*3*/	"src1 address decode error",
+	/*4*/	"dst address decode error",
+	/*5*/	"src1 alignment error",
+	/*6*/	"dst alignment error",
+	/*7*/	"src1 sync error",
+	/*8*/	"dst sync error",
+	/*9*/	"DCAPT error",
+	/*10*/	"inst range error",
+	/*11*/	"src1 range error",
+	/*12*/	"dst range error",
+};
+
+/*
+ * The device tree trap node definition.
+ */
+struct trapnode {
+	struct devtree_node dn;
+	unsigned int intthread;
+};
+
+static struct trapnode *tn;;
+
+/*
+ * trap_interrupt_handler()
+ *	Software Interrupt to ensure that a trap is serviced.
+ */
+static irqreturn_t trap_interrupt_handler(int irq, void *dummy)
+{
+	/* Do Nothing */
+	return IRQ_HANDLED;
+}
+
+/*
+ * Data used by setup_irq for the timer.
+ */
+static struct irqaction trap_irq = {
+	.name	 = "trap",
+	.flags	 = IRQF_DISABLED,
+	.handler = trap_interrupt_handler,
+};
+
+/*
+ * trap_cause_to_str()
+ *	Convert a trap_cause into a series of printk
+ */
+static void trap_cause_to_str(long status)
+{
+	int bit;
+
+	if ((status & ((1 << TRAP_CAUSE_TOTAL) - 1)) == 0) {
+		printk(KERN_NOTICE "decode: UNKNOWN CAUSES\n");
+		return;
+	}
+
+	for (bit = 0; bit < TRAP_CAUSE_TOTAL; bit++) {
+		if (status & (1 << bit)) {
+			printk(KERN_NOTICE "\tdecode: %08x %s\n",
+			       1 << bit, trap_cause_strings[bit]);
+		}
+	}
+}
+
+/*
+ * trap_print_information()
+ *	Print the cause of the trap and additional info.
+ */
+static void trap_print_information(const char *str, struct pt_regs *regs)
+{
+	printk(KERN_WARNING "\n");
+
+	if (current) {
+		printk(KERN_WARNING "Process %s (pid: %d)\n",
+			current->comm, current->pid);
+	}
+
+	if (current && current->mm) {
+		printk(KERN_NOTICE "text = 0x%p-0x%p  data = 0x%p-0x%p\n"
+			KERN_NOTICE "bss = 0x%p-0x%p   user-stack = 0x%p\n"
+			KERN_NOTICE "\n",
+			(void *)current->mm->start_code,
+			(void *)current->mm->end_code,
+			(void *)current->mm->start_data,
+			(void *)current->mm->end_data,
+			(void *)current->mm->end_data,
+			(void *)current->mm->brk,
+			(void *)current->mm->start_stack);
+	}
+
+	printk(KERN_WARNING "%s: Causes: 0x%08x\n", str,
+			(unsigned int)regs->trap_cause);
+	trap_cause_to_str(regs->trap_cause);
+	show_regs(regs);
+	show_stack(NULL, (unsigned long *)regs->an[7]);
+	printk(KERN_NOTICE "--- End Trap --- \n");
+}
+
+/*
+ * dump_stack()
+ *	Dump the stack of the current task.
+ */
+void dump_stack(void)
+{
+	show_stack(NULL, NULL);
+}
+EXPORT_SYMBOL(dump_stack);
+
+/*
+ * show_stack()
+ *	Print out information from the current stack.
+ */
+void show_stack(struct task_struct *task, unsigned long *sp)
+{
+	/*
+	 *  Allocate just enough entries on the stack.
+	 */
+	unsigned int calls[TRAP_MAX_STACK_DEPTH];
+	unsigned long code_start = (unsigned long)CONFIG_RAMBASE;
+	unsigned long code_end = (unsigned long)CONFIG_RAMBASE+CONFIG_RAMSIZE;
+	unsigned long ocm_code_start = (unsigned long)&__ocm_text_run_begin;
+	unsigned long ocm_code_end = (unsigned long)&__data_begin;
+	unsigned long stack_end = (unsigned long)(current->stack + THREAD_SIZE - 8);
+	unsigned long stack = (unsigned long)sp;
+	int kernel_stack = 1;
+
+	/*
+	 * Which task are we talking about.
+	 */
+	if (!task) {
+		task = current;
+	}
+
+	/*
+	 * Find the stack for the task if one was not specified.  Otherwise
+	 * use the specified stack.
+	 */
+	if (!stack) {
+		if (task != current) {
+			stack = task->thread.sp;
+			stack_end = (unsigned long)task->stack + THREAD_SIZE - 8;
+		} else {
+			asm volatile (
+				"move.4		%0, SP		\n\t"
+				: "=r" (stack)
+			);
+		}
+	}
+
+	printk(KERN_NOTICE "Starting backtrace: PID %d '%s'\n",
+			task->pid, task->comm);
+
+	/*
+	 * We do 2 passes the first pass is Kernel stack is the second
+	 * User stack.
+	 */
+	while (kernel_stack) {
+		unsigned long *handle;
+		unsigned int i, idx = 0;
+		struct pt_regs *pt = task_pt_regs(task);
+
+		/*
+		 * If the task is in user mode, reset the start
+		 * and end values for text.
+		 */
+		if (__user_mode(stack)) {
+			if (!(task->personality & FDPIC_FUNCPTRS)) {
+				printk(KERN_NOTICE "  User Stack:\n");
+				code_start = task->mm->start_code;
+				code_end = task->mm->end_code;
+			} else {
+				printk(KERN_NOTICE "  User Stack (fdpic):\n");
+
+			}
+			stack_end = task->mm->start_stack;
+			ocm_code_end = ocm_code_start = 0;
+			kernel_stack = 0;
+		} else {
+			printk(KERN_NOTICE "  Kernel Stack:\n");
+		}
+
+		/*
+		 * Collect the stack back trace information.
+		 */
+		printk("    code[0x%lx-0x%lx]", code_start, code_end);
+		if (ocm_code_start) {
+			printk(" ocm_code[0x%lx-0x%lx]",
+			       ocm_code_start, ocm_code_end);
+		}
+		printk("\n    stack[0x%lx-0x%lx]\n", stack, stack_end);
+
+		handle = (unsigned long*)stack;
+		while (idx < TRAP_MAX_STACK_DEPTH) {
+			calls[idx] = stacktrace_iterate(&handle,
+					code_start, code_end,
+					ocm_code_start, ocm_code_end,
+					(unsigned long)stack, stack_end);
+			if (calls[idx] == 0) {
+				break;
+			}
+			idx++;
+		}
+
+		/*
+		 * Now print out the data.
+		 */
+		printk(KERN_NOTICE "  CALL && CALLI on stack:");
+		for (i = 0; i < idx; i++) {
+			printk("%s0x%x, ", (i & 0x3) == 0 ?  "\n    " : "",
+					calls[i]);
+		}
+		printk(idx == TRAP_MAX_STACK_DEPTH ? "...\n" : "\n");
+
+		/*
+		 * If we are doing user stack we are done
+		 */
+		if (!kernel_stack) {
+			break;
+		}
+
+		/*
+		 * Does this kernel stack have a mm (i.e. is it user)
+		 */
+		if (!task->mm) {
+			printk("No mm for userspace stack.\n");
+			break;
+		}
+		/*
+		 * Get the user-mode stack (if any)
+		 */
+		stack = pt->an[7];
+		printk(KERN_NOTICE "Userspace stack at 0x%lx frame type %d\n",
+				stack, (int)pt->frame_type);
+		if (!__user_mode(stack)) {
+			break;
+		}
+	}
+}
+
+/*
+ * die_if_kernel()
+ *	Determine if we are in kernel mode and if so print stuff out and die.
+ */
+void die_if_kernel(char *str, struct pt_regs *regs, long trap_cause)
+{
+	unsigned int s3value;
+
+	if (user_mode(regs)) {
+		return;
+	}
+
+	console_verbose();
+	trap_print_information(str, regs);
+
+	/*
+	 * If the debugger is attached via the hardware mailbox protocol,
+	 * go into an infinite loop and the debugger will figure things out.
+	 */
+	asm volatile (
+	      "move.4 %0, scratchpad3"
+	      : "=r" (s3value)
+	);
+	if (s3value) {
+		asm volatile("1:	jmpt.t 1b");
+	}
+
+	/*
+	 * Set the debug taint value.
+	 */
+	add_taint(TAINT_DIE);
+	do_exit(SIGSEGV);
+}
+
+/*
+ * trap_handler()
+ *	Handle traps.
+ *
+ * Traps are treated as interrupts and registered with the LDSR.  When
+ * the LDSR takes the interrupt, it will determine if a trap has occurred
+ * and service the trap prior to servicing the interrupt.
+ *
+ * This function is directly called by the LDSR.
+ */
+void trap_handler(int irq, struct pt_regs *regs)
+{
+	int sig = SIGSEGV;
+	siginfo_t info;
+	unsigned int trap_cause = regs->trap_cause;
+
+	BUG_ON(!irqs_disabled());
+
+	/*
+	 * test if in kernel and die.
+	 */
+	die_if_kernel("Kernel Trap", regs, trap_cause);
+
+	/*
+	 * User process problem, setup a signal for this process
+	 */
+	if ((trap_cause & (1 << TRAP_CAUSE_DST_RANGE_ERR)) ||
+	    (trap_cause & (1 << TRAP_CAUSE_SRC1_RANGE_ERR)) ||
+	    (trap_cause & (1 << TRAP_CAUSE_I_RANGE_ERR))) {
+		sig = SIGSEGV;
+		info.si_code = SEGV_MAPERR;
+	} else if ((trap_cause & (1 << TRAP_CAUSE_DST_MISALIGNED)) ||
+		   (trap_cause & (1 << TRAP_CAUSE_SRC1_MISALIGNED))) {
+		sig = SIGBUS;
+		info.si_code = BUS_ADRALN;
+	} else if ((trap_cause & (1 << TRAP_CAUSE_DST_DECODE_ERR)) ||
+		   (trap_cause & (1 << TRAP_CAUSE_SRC1_DECODE_ERR))) {
+		sig = SIGILL;
+		info.si_code = ILL_ILLOPN;
+	} else if ((trap_cause & (1 << TRAP_CAUSE_ILLEGAL_INST))) {
+		/*
+		 * Check for software break point and if found signal trap
+		 * not illegal instruction.
+		 */
+		unsigned long instruction;
+		if (between(regs->pc, CONFIG_RAMBASE,
+			    CONFIG_RAMBASE + CONFIG_RAMSIZE) &&
+			(regs->pc & 3) == 0 &&
+			get_user(instruction, (unsigned long *)regs->pc) == 0) {
+
+			/*
+			 * This used to be 0xaabbccdd but it turns out
+			 * that is now valid in ubicom32v4 isa so we
+			 * have switched to 0xfabbccdd
+			 */
+			if ((instruction == 0xfabbccdd) ||
+			    (instruction == 0xaabbccdd)) {
+				sig = SIGTRAP;
+				info.si_code = TRAP_BRKPT;
+				goto send_signal;
+			}
+		}
+		sig = SIGILL;
+		info.si_code = ILL_ILLOPC;
+	} else if ((trap_cause & (1 << TRAP_CAUSE_I_DECODE_ERR))) {
+		sig = SIGILL;
+		info.si_code = ILL_ILLOPC;
+	} else if ((trap_cause & (1 << TRAP_CAUSE_DCAPT))) {
+		sig = SIGTRAP;
+		info.si_code = TRAP_TRACE;
+	}
+
+	/*
+	 * Print a trap information block to the console, do not
+	 * print this above the case because we don't want it
+	 * printed for software break points.
+	 */
+	trap_print_information("User Trap", regs);
+
+send_signal:
+
+	force_sig_info(sig, &info, current);
+
+	/*
+	 * Interrupts are disabled, re-enable them now.
+	 */
+	if (!irqs_disabled()) {
+		printk(KERN_EMERG "interrupts enabled on exit, irq=%d, regs=%p",
+				irq, regs);
+		BUG();
+	}
+}
+
+/*
+ * trap_init_interrupt()
+ *	We need a 2nd trap handling init that will occur after init_IRQ().
+ */
+void __init trap_init_interrupt(void)
+{
+	int err;
+	unsigned char tirq;
+	struct devtree_node *dn = (struct devtree_node *)tn;
+
+	/*
+	 * Now setup the Software IRQ so that if a trap occurs the LDSR
+	 * is started.  The irq is there just to "force" the LDSR to run.
+	 */
+	if (!tn) {
+		printk(KERN_WARNING "trap_init_interrupt skipped.\n");
+		return;
+	}
+
+	err = devtree_irq(dn, NULL, &tirq);
+	if (err) {
+		printk(KERN_WARNING "error obtaining trap irq value: %d\n",
+			err);
+		return;
+	}
+
+	if (tirq == DEVTREE_IRQ_NONE) {
+		printk(KERN_WARNING "trap irq not available: %d\n", tirq);
+		return;
+	}
+
+	err = setup_irq(tirq, &trap_irq);
+	if (err) {
+		printk(KERN_WARNING "trap irq setup failed: %d\n", err);
+		return;
+	}
+
+	/*
+	 * Let ultra know which thread is handling the traps and
+	 * what the interrupt to use is.
+	 */
+	tn->intthread = ldsr_get_threadid();
+
+	/*
+	 * Tell the LDSR about our IRQ so that it will unsuspend
+	 * if one occurs while waiting for the per thread lock.
+	 */
+	ldsr_set_trap_irq(tirq);
+}
+
+/*
+ * trap_init()
+ *	init trap handling
+ *
+ * Trap handling is done through the ldsr.  Every time an interrupt
+ * occurs, the LDSR looks for threads that are listed in the TRAP
+ * register and forces a call to the trap handler.
+ */
+void __init trap_init(void)
+{
+	/*
+	 * If we do not have a trap node in the device tree, we leave the fault
+	 * handling to the underlying hardware.
+	 */
+	tn = (struct trapnode *)devtree_find_node("traps");
+	if (!tn) {
+		printk(KERN_WARNING "traps are not handled by linux\n");
+		return;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/uaccess.c
@@ -0,0 +1,109 @@
+/*
+ * arch/ubicom32/include/asm/uaccess.c
+ *   User space memory access functions for Ubicom32 architecture.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/module.h>
+
+#include <asm/segment.h>
+#include <asm/uaccess.h>
+
+extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
+
+/*
+ * __access_ok()
+ *	Check that the address is in the current processes.
+ * 
+ * NOTE: The kernel uses "pretend" user addresses that wind
+ * up calling access_ok() so this approach has only marginal
+ * value because you wind up with lots of false positives.
+ */
+int __access_ok(unsigned long addr, unsigned long size)
+{
+	// struct vm_area_struct *vma;
+
+	/*
+	 * Don't do anything if we are not a running system yet.
+	 */
+	if (system_state != SYSTEM_RUNNING) {
+		return 1;
+	}
+
+	/*
+	 * It appears that Linux will call this function even when we are not
+	 * in the context of a user space application that has a VM address 
+	 * space.  So we must check that current and mm are valid before
+	 * performing the check.
+	 */
+	if ((!current) || (!current->mm)) {
+		return 1;
+	}
+
+	/*
+	 * We perform some basic checks on the address to ensure that it
+	 * is at least within the range of DRAM.
+	 */
+	if ((addr < (int)&_etext) || (addr > memory_end)) {
+		printk(KERN_WARNING "pid=%d[%s]: range [%lx - %lx] not in memory area: [%lx - %lx]\n",
+			current->pid, current->comm, 
+			addr, addr + size,
+			memory_start, memory_end);
+		return 0;
+	}
+
+	/*
+	 * For nommu Linux we can check this by looking at the allowed
+	 * memory map for the process.
+	 *
+	 * TODO: Since the kernel passes addresses in it's own space as though
+	 * they were user address, we can not validate the addresses this way.
+	 */
+#if 0
+	if (!down_read_trylock(&current->mm->mmap_sem)) {
+		return 1;
+	}
+	vma = find_vma(current->mm, addr);
+	if (!vma) {
+		up_read(&current->mm->mmap_sem);
+		printk(KERN_WARNING "pid=%d[%s]: possible invalid acesss on range: [%lx - %lx]\n",
+				current->pid, current->comm, addr, addr + size);
+		return 1;
+	}
+	if ((addr + size) > vma->vm_end) {
+		up_read(&current->mm->mmap_sem);
+		printk(KERN_WARNING "pid=%d[%s]: possible invalid length on range: [%lx - %lx]\n",
+				current->pid, current->comm, addr, addr + size);
+		return 1;
+	}
+	up_read(&current->mm->mmap_sem);
+#endif
+	return 1;
+}
+
+EXPORT_SYMBOL(__access_ok);
--- /dev/null
+++ b/arch/ubicom32/kernel/ubicom32_context_switch.S
@@ -0,0 +1,325 @@
+/*
+ * arch/ubicom32/kernel/ubicom32_context_switch.S
+ *	Implements context switch and return functions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/asm-offsets.h>
+#include <asm/ubicom32-common.h>
+#include <asm/ip5000.h>
+#include <asm/range-protect.h>
+
+/*
+ * restore_context()
+ *	Restore the full context from sp (struct pt_reg *)
+ *
+ * Note: Recovered PC and CSR are saved on the stack and are to be popped off
+ * before returning.
+ */
+.macro restore_context
+	move.4	a0, sp			; Set up a0 as base address for register recovery
+	move.4	sp, PT_SP(a0)		; Recover Stack pointer from save area
+	move.4	-4(sp)++, PT_PC(a0)	; Recover saved PC and save to stack
+	move.4	-4(sp)++, PT_CSR(a0)	; Recover saved csr and save to stack
+	move.4	d0, PT_D0(a0)
+	move.4	d1, PT_D1(a0)
+	move.4	d2, PT_D2(a0)
+	move.4	d3, PT_D3(a0)
+	move.4	d4, PT_D4(a0)
+	move.4	d5, PT_D5(a0)
+	move.4	d6, PT_D6(a0)
+	move.4	d7, PT_D7(a0)
+	move.4	d8, PT_D8(a0)
+	move.4	d9, PT_D9(a0)
+	move.4	d10, PT_D10(a0)
+	move.4	d11, PT_D11(a0)
+	move.4	d12, PT_D12(a0)
+	move.4	d13, PT_D13(a0)
+	move.4	d14, PT_D14(a0)
+	move.4	d15, PT_D15(a0)
+	move.4	a1, PT_A1(a0)
+	move.4	a2, PT_A2(a0)
+	move.4	a3, PT_A3(a0)
+	move.4	a4, PT_A4(a0)
+	move.4	a5, PT_A5(a0)
+	move.4	a6, PT_A6(a0)
+	move.4	acc0_hi, PT_ACC0HI(a0)
+	move.4	acc0_lo, PT_ACC0LO(a0)
+	move.4	mac_rc16, PT_MAC_RC16(a0)
+	move.4	acc1_hi, PT_ACC1HI(a0)
+	move.4	acc1_lo, PT_ACC1LO(a0)
+	move.4	source3, PT_SOURCE3(a0)
+	move.4	int_mask0, PT_INT_MASK0(a0)
+	move.4	int_mask1, PT_INT_MASK1(a0)
+	move.4	a0, PT_A0(a0)
+.endm
+
+/*
+ * ldsr_thread_enable_interrupts()
+ *	An assembly version of the enable interrupts function.
+ *
+ * The stack is fair game but all registers MUST be preserved.
+ *
+ */
+.macro ldsr_thread_enable_interrupts
+	move.4	-4(sp)++, d3	; Push d3
+	move.4	-4(sp)++, a3	; Push a3
+
+	/*
+	 * Read the ROSR and obtain ~(1 << tid)
+	 */
+	lsr.4	d3, rosr, #0x2	; Move the thread portion of ROSR into d3
+	lsl.4	d3, #1, d3	; perform a (1 << tid)
+	not.4	d3, d3		; Negate the value of d3 == ~(1 << threadid)
+
+	/*
+	 * Get the value of the ldsr_soft_irq_mask
+	 */
+	moveai	a3, #%hi(ldsr_soft_irq_mask)
+	move.4	a3, %lo(ldsr_soft_irq_mask)(a3)
+
+	/*
+	 * Now re-enable interrupts for this thread and then
+	 * wakeup the LDSR.
+	 */
+	and.4	scratchpad1, scratchpad1, d3
+	move.4	int_set0, a3
+
+	/*
+	 * Restore the registers.
+	 */
+	move.4	a3, (sp)4++
+	move.4	d3, (sp)4++
+.endm
+
+/*
+ * ret_from_interrupt_to_kernel()
+ *	RFI function that is where do_IRQ() returns to if the thread was in kernel space.
+ */
+	.section .text.ret_from_interrupt_to_kernel
+	.global ret_from_interrupt_to_kernel
+ret_from_interrupt_to_kernel:
+	atomic_lock_acquire		; Enter critical section
+	restore_context			; Restore the thread context
+	atomic_lock_release		; Leave critical section
+	ldsr_thread_enable_interrupts	; enable the threads interrupts
+	move.4	csr, (sp)4++		; Restore csr from the stack
+	ret	(sp)4++
+
+/*
+ * ret_from_interrupt_to_user()
+ *	RFI function that is where do_IRQ() returns to if the thread was in user space.
+ *
+ * TODO: Do we really need the ciritical section handling in this code?
+ *
+ */
+	.section .ret_from_interrupt_to_user.text
+	.global ret_from_interrupt_to_user
+ret_from_interrupt_to_user:
+	ldsr_thread_enable_interrupts			; enable the threads interrupts
+	movei	d0, #(~(ASM_THREAD_SIZE-1))
+	and.4	a3, sp, d0				; a3 now has the thread info pointer
+
+	/*
+	 * Test if the scheduler needs to be called.
+	 */
+	btst	TI_FLAGS(a3), #ASM_TIF_NEED_RESCHED
+	jmpeq.t	2f
+	moveai	a5, #%hi(schedule)
+	calli	a5, %lo(schedule)(a5)			; Call the scheduler. I will come back here.
+
+	/*
+	 * See if we have pending signals and call do_signal
+	 * if needed.
+	 */
+2:	atomic_lock_acquire				; Enter critical section
+	move.4	-4(sp)++, a1				; Save A1 on the stack. We are going to use a1 it.
+	movei	d0, #(~(ASM_THREAD_SIZE-1))
+	and.4	a1, sp, d0				; a1 now has the thread info pointer
+	btst	TI_FLAGS(a1), #ASM_TIF_SIGPENDING	; Any signals needed?
+	jmpeq.t	1f
+
+
+	/*
+	 * Now call do_signal()
+	 */
+	atomic_lock_release				; Leave critical section
+	move.4	d0, #0					; oldset pointer is NULL
+	lea.1	d1, 4(sp)				; d1 is the regs pointer
+	moveai	a5, #%hi(do_signal)
+	calli	a5, %lo(do_signal)(a5)			; Call do_signal()
+
+	/*
+	 * Back from do_signal(), re-enter critical section.
+	 */
+	atomic_lock_acquire				; Enter critical section
+
+1:	move.4	a1, (sp)4++				; pop A1 off the stack
+
+	disable_kernel_ranges_for_current d15		; disable kernel ranges
+
+	restore_context					; restore the previous context
+	atomic_lock_release				; Leave critical section
+	move.4	csr, (sp)4++				; Restore csr from the stack
+	ret	(sp)4++
+
+/*
+ * restore_all_registers()
+ *
+ * restore_all_registers will be the alternate exit route for
+ * preempted processes that have called a signal handler
+ * and are returning back to user space.
+ */
+	.global restore_all_registers
+restore_all_registers:
+	atomic_lock_acquire			; Enter critical section
+	disable_kernel_ranges_for_current d15	; disable kernel ranges
+	atomic_lock_release			; Leave critical section
+	restore_context				; restore previous context
+	move.4	csr, (sp)4++			; Restore csr from the stack
+	ret	(sp)4++
+
+/*
+ * ret_from_fork()
+ *	Called on the child's return from fork system call.
+ */
+	.section .ret_from_fork.text
+	.global ret_from_fork
+ret_from_fork:
+	;;;  d0 contains the arg for schedule_tail
+	;;;  the others we don't care about as they are in PT_REGS (sp)
+	moveai  a5, #%hi(schedule_tail)
+	calli   a5, %lo(schedule_tail)(a5)
+
+	atomic_lock_acquire		; Enter critical section
+
+	move.4	a3, sp
+	move.4	d0, PT_D0(a3)		; Restore D0
+	move.4	d1, PT_D1(a3)		; Restore D1
+	move.4	d2, PT_D2(a3)		; Restore D2
+	move.4	d3, PT_D3(a3)		; Restore D3
+	move.4	d10, PT_D10(a3)		; Restore D10
+	move.4	d11, PT_D11(a3)		; Restore D11
+	move.4	d12, PT_D12(a3)		; Restore D12
+	move.4	d13, PT_D13(a3)		; Restore D13
+	move.4	a1, PT_A1(a3)		; Restore A1
+	move.4	a2, PT_A2(a3)		; Restore A2
+	move.4	a5, PT_A5(a3)		; Restore A5
+	move.4	a6, PT_A6(a3)		; Restore A6
+	move.4	sp, PT_SP(a3)		; Restore sp
+	move.4	a4, PT_PC(a3)		; Restore pc in register a4
+	move.4	PT_FRAME_TYPE(a3), #0	; Clear frame_type to indicate it is invalid.
+
+	disable_kernel_ranges_for_current d15
+	atomic_lock_release		; Leave critical section
+	calli	a4, 0(a4)		; Return.
+
+/*
+ * __switch_to()
+ *
+ * Call with:
+ *	void *__switch_to(struct task_struct *prev, struct thread_struct *prev_switch,
+ *				struct thread_struct *next_switch)
+ */
+	.global __switch_to
+__switch_to:
+
+	/*
+	 * Set up register a3 to point to save area.
+	 */
+	movea	a3, d1			; a3 now holds prev_switch
+	move.4	(a3)4++, d10
+	move.4	(a3)4++, d11
+	move.4	(a3)4++, d12
+	move.4	(a3)4++, d13
+	move.4	(a3)4++, a1
+	move.4	(a3)4++, a2
+	move.4	(a3)4++, a5
+	move.4	(a3)4++, a6
+	move.4	(a3)4++, a7
+
+	/*
+	 * Set up register a3 to point to restore area.
+	 */
+	movea	a3, d2			; a3 now holds next_switch
+	move.4	d10 , (a3)4++
+	move.4	d11 , (a3)4++
+	move.4	d12 , (a3)4++
+	move.4	d13 , (a3)4++
+	move.4	a1 , (a3)4++
+	move.4	a2 , (a3)4++
+	move.4	a5 , (a3)4++
+	move.4	a6 , (a3)4++
+	move.4	a7 , (a3)4++
+
+	/*
+	 * Load the sw_ksp with the proper thread_info pointer.
+	 */
+	movei	d15, #(~(ASM_THREAD_SIZE-1))
+	and.4	a3, sp, d15		; a3 now has the thread info pointer
+	moveai	a4, #%hi(sw_ksp)
+	lea.1	a4, %lo(sw_ksp)(a4)	; a4 now has the base address of sw_ksp array
+	lsr.4	d15, ROSR, #2		; Thread number + garbage
+	and.4	d15, #31, D15		; Mask to get thread number into register D15
+	move.4	(a4, d15), a3		; Load the thread info pointer into the hw_ksp array..
+
+	/*
+	 * We are done with context switch. Time to return..
+	 */
+	ret	a5
+
+
+/*
+ * ubicom32_emulate_insn()
+ *	Emulates the instruction.
+ *
+ * Call with:
+ *	unsigned int ubicom32_emulate_insn(int source1, int source2, int source3, int *save_acc, int *save_csr);
+ */
+	.global ubicom32_emulate_insn
+	.global trap_emulate
+ubicom32_emulate_insn:
+	movea	a3, d3		; a3 holds save_acc pointer
+	movea	a4, d4		; a4 hods save_csr pointer
+	move.4	source3, d2
+	move.4	acc0_lo, (a3)
+	move.4	acc0_hi, 4(a3)
+	move.4	acc1_lo, 8(a3)
+	move.4	acc1_hi, 12(a3)
+	move.4	mac_rc16, 16(a3)
+	move.4	CSR, (a4)
+	setcsr_flush 0
+
+trap_emulate:
+	move.4	d0, d1
+	setcsr_flush 0
+	move.4	(a4), CSR	; Save csr
+	move.4	(a3), acc0_lo
+	move.4	4(a3), acc0_hi
+	move.4	8(a3), acc1_lo
+	move.4	12(a3), acc1_hi
+	move.4	16(a3), mac_rc16
+	ret	a5
--- /dev/null
+++ b/arch/ubicom32/kernel/ubicom32_ksyms.c
@@ -0,0 +1,95 @@
+/*
+ * arch/ubicom32/kernel/ubicom32_ksyms.c
+ *   Ubicom32 architecture compiler support and misc symbols.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/linkage.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/user.h>
+#include <linux/elfcore.h>
+#include <linux/in6.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/semaphore.h>
+
+#include <asm/setup.h>
+#include <asm/machdep.h>
+#include <asm/pgalloc.h>
+#include <asm/irq.h>
+#include <asm/checksum.h>
+#include <asm/current.h>
+
+/* platform dependent support */
+
+EXPORT_SYMBOL(__ioremap);
+EXPORT_SYMBOL(iounmap);
+
+EXPORT_SYMBOL(ip_fast_csum);
+
+
+/* Networking helper routines. */
+EXPORT_SYMBOL(csum_partial_copy_nocheck);
+
+/* The following are special because they're not called
+   explicitly (the C compiler generates them).  Fortunately,
+   their interface isn't gonna change any time soon now, so
+   it's OK to leave it out of version control.  */
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memset);
+
+#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4
+/*
+ * libgcc functions - functions that are used internally by the
+ * compiler...  (prototypes are not correct though, but that
+ * doesn't really matter since they're not versioned).
+ */
+extern void __ashldi3(void);
+extern void __ashrdi3(void);
+extern void __divsi3(void);
+extern void __lshrdi3(void);
+extern void __modsi3(void);
+extern void __muldi3(void);
+extern void __udivsi3(void);
+extern void __umodsi3(void);
+
+/* gcc lib functions */
+EXPORT_SYMBOL(__ashldi3);
+EXPORT_SYMBOL(__ashrdi3);
+EXPORT_SYMBOL(__divsi3);
+EXPORT_SYMBOL(__lshrdi3);
+EXPORT_SYMBOL(__modsi3);
+EXPORT_SYMBOL(__muldi3);
+EXPORT_SYMBOL(__udivsi3);
+EXPORT_SYMBOL(__umodsi3);
+#else
+extern void __libgcc_udivmodsi(void);
+extern void __libgcc_divmodsi(void);
+
+EXPORT_SYMBOL(__libgcc_udivmodsi);
+EXPORT_SYMBOL(__libgcc_divmodsi);
+#endif
--- /dev/null
+++ b/arch/ubicom32/kernel/ubicom32_syscall.S
@@ -0,0 +1,643 @@
+/*
+ * arch/ubicom32/kernel/ubicom32_syscall.S
+ *	<TODO: Replace with short file description>
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <linux/unistd.h>
+
+#include <asm/ubicom32-common.h>
+#include <asm/thread_info.h>
+#include <asm/asm-offsets.h>
+#include <asm/range-protect.h>
+
+/*
+ * system_call()
+ */
+	.section .syscall_entry.text
+	.global system_call
+system_call:
+	/*
+	 * Regular ABI rules for function calls apply for syscall.  d8 holds
+	 * the syscall number. We will use that to index into the syscall table.
+	 * d0 - d5 hold the parameters.
+	 *
+	 * First we get the current thread_info and swap to the kernel stack.
+	 * This is done by reading the current thread and looking up the ksp
+	 * from the sw_ksp array and storing it in a3.
+	 *
+	 * Then we reserve space for the syscall context a struct pt_regs and
+	 * save it using a4 initially and later as sp.
+	 * Once sp is set to the kernel sp we can leave the critical section.
+	 *
+	 * For the user case the kernel stack will have the following layout.
+	 *
+	 *  a3		 ksp[0] +-----------------------+
+	 *			| Thread info area	|
+	 *			| struct thread_info	|
+	 *			+-----------------------+
+	 *			:			:
+	 *			|   Kernel Stack Area	|
+	 *			|			|
+	 *  a4 / sp >>>		+-----------------------+
+	 *			| Context save area	|
+	 *			| struct pt_reg		|
+	 *  ksp[THREAD_SIZE-8]  +-----------------------+
+	 *			| 8 Byte Buffer Zone	|
+	 *  ksp[THREAD_SIZE]    +-----------------------+
+
+	 *
+	 * For kernel syscalls the layout is as follows.
+	 *
+	 *  a3		 ksp[0] +-----------------------+
+	 *			| Thread info area	|
+	 *			| struct thread_info	|
+	 *			+-----------------------+
+	 *			:			:
+	 *			|   Kernel Stack Area	|
+	 *			|			|
+	 *  a4 / sp >>>		+-----------------------+
+	 *			| Context save area	|
+	 *			| struct pt_reg		|
+	 * sp at syscall entry  +-----------------------+
+	 *			| Callers Kernel Stack	|
+	 *			:			:
+	 *
+	 * Once the context is saved we optionally call syscall_trace and setup
+	 * the exit routine and jump to the syscall.
+	 */
+
+	/*
+	 * load the base address for sw_ksp into a3
+	 * Note.. we cannot access it just yet as protection is still on.
+	 */
+	moveai	a3, #%hi(sw_ksp)
+	lea.1	a3, %lo(sw_ksp)(a3)
+
+	/*
+	 * Enter critical section .
+	 *
+	 * The 'critical' aspects here are the switching the to the ksp and
+	 * changing the protection registers, these both use per thread
+	 * information so we need to protect from a context switch. For now this
+	 * is done using the global atomic lock.
+	 */
+	atomic_lock_acquire
+
+	thread_get_self d15			; Load current thread number
+#ifdef CONFIG_PROTECT_KERNEL
+	lsl.4	d9, #1, d15			; Convert to thread bit
+	enable_kernel_ranges d9
+#endif
+	/*
+	 * We need to Determine if this is a kernel syscall or user syscall.
+	 * Start by loading the pointer for the thread_info structure for the
+	 * current process in to a3.
+	 */
+	move.4	a3, (a3, d15)			; a3 = sw_ksp[d15]
+
+	/*
+	 * Now if this is a kernel thread the same value can be a acheived by
+	 * masking off the lower bits on the current stack pointer.
+	 */
+	movei	d9, #(~(ASM_THREAD_SIZE-1))	; load mask
+	and.4	d9, sp, d9			; apply mask
+
+	/*
+	 * d9 now has the masked version of the sp. If this is identical to
+	 * what is in a3 then don't switch to ksp as we are already in the
+	 * kernel.
+	 */
+	sub.4	#0, a3, d9
+
+	/*
+	 * if d9 and a3 are not equal. We are usespace and have to shift to
+	 * ksp.
+	 */
+	jmpne.t	1f
+
+	/*
+	 * Kernel Syscall.
+	 *
+	 * The kernel has called this routine. We have to pdec space for pt_regs
+	 * from sp.
+	 */
+	pdec	a4, PT_SIZE(sp)			; a4 = ksp - PT_SIZE
+	jmpt.t	2f
+
+	/*
+	 * Userspace Syscall.
+	 *
+	 * Add THREAD_SIZE and subtract PT_SIZE to create the proper ksp
+	 */
+1:	movei	d15, #(ASM_THREAD_SIZE - 8 - PT_SIZE)
+	lea.1	a4, (a3, d15)			; a4 = ksp + d15
+
+	/*
+	 * Replace user stack pointer with kernel stack pointer (a4)
+	 * Load -1 into frame_type in save area to indicate this is system call
+	 * frame.
+	 */
+2:	move.4	PT_A7(a4), a7			; Save old sp/A7 on kernel stack
+	move.4	PT_FRAME_TYPE(a4), #-1		; Set the frame type.
+	move.4	sp, a4				; Change to ksp.
+	/*
+	 * We are now officially back in the kernel!
+	 */
+
+	/*
+	 * Now that we are on the ksp we can leave the critical section
+	 */
+	atomic_lock_release
+
+	/*
+	 * We need to save a0 because we need to be able to restore it in
+	 * the event that we need to handle a signal.  It's not generally
+	 * a callee-saved register but is the GOT pointer.
+	 */
+	move.4	PT_A0(sp), a0			; Save A0 on kernel stack
+
+	/*
+	 * We still need to save d10-d13, a1, a2, a5, a6 in the kernel frame
+	 * for this process, we also save the system call params in the case of
+	 * syscall restart. (note a7 was saved above)
+	 */
+	move.4	PT_A1(sp), a1			; Save A1 on kernel stack
+	move.4	PT_A2(sp), a2			; Save A2 on kernel stack
+	move.4	PT_A5(sp), a5			; Save A5 on kernel stack
+	move.4	PT_A6(sp), a6			; Save A6 on kernel stack
+	move.4	PT_PC(sp), a5			; Save A5 at the PC location
+	move.4	PT_D10(sp), d10			; Save D10 on kernel stack
+	move.4	PT_D11(sp), d11			; Save D11 on kernel stack
+	move.4	PT_D12(sp), d12			; Save D12 on kernel stack
+	move.4	PT_D13(sp), d13			; Save D13 on kernel stack
+
+	/*
+	 * Now save the syscall parameters
+	 */
+	move.4	PT_D0(sp), d0			; Save d0 on kernel stack
+	move.4	PT_ORIGINAL_D0(sp), d0		; Save d0 on kernel stack
+	move.4	PT_D1(sp), d1			; Save d1 on kernel stack
+	move.4	PT_D2(sp), d2			; Save d2 on kernel stack
+	move.4	PT_D3(sp), d3			; Save d3 on kernel stack
+	move.4	PT_D4(sp), d4			; Save d4 on kernel stack
+	move.4	PT_D5(sp), d5			; Save d5 on kernel stack
+	/* add this back if we ever have a syscall with 7 args */
+	move.4	PT_D8(sp), d8			; Save d8 on kernel stack
+
+	/*
+	 * Test if syscalls are being traced and if they are jump to syscall
+	 * trace (it will comeback here)
+	 */
+	btst	TI_FLAGS(a3), #ASM_TIF_SYSCALL_TRACE
+	jmpne.f .Lsystem_call__trace
+.Lsystem_call__trace_complete:
+	/*
+	 * Check for a valid call number [ 0 <= syscall_number < NR_syscalls ]
+	 */
+	cmpi	d8, #0
+	jmplt.f 3f
+	cmpi	d8, #NR_syscalls
+	jmplt.t	4f
+
+	/*
+	 * They have passed an invalid number. Call sys_ni_syscall staring by
+	 * load a4 with the base address of sys_ni_syscall
+	 */
+3:	moveai	a4, #%hi(sys_ni_syscall)
+	lea.1	a4, %lo(sys_ni_syscall)(a4)
+	jmpt.t	5f				; Jump to regular processing
+
+	/*
+	 * Validated syscall, load the syscall table base address into a3 and
+	 * read the syscall ptr out.
+	 */
+4:	moveai	a3, #%hi(sys_call_table)
+	lea.1	a3, %lo(sys_call_table)(a3)	; a3 = sys_call_table
+	move.4	a4, (a3, d8)			; a4 = sys_call_table[d8]
+
+	/*
+	 * Before calling the syscall, setup a5 so that syscall_exit is called
+	 * on return from syscall
+	 */
+5:	moveai	a5, #%hi(syscall_exit)		; Setup return address
+	lea.1	a5, %lo(syscall_exit)(a5)	; from system call
+
+	/*
+	 * If the syscall is __NR_rt_rigreturn then we have to test d1 to
+	 * figure out if we have to change change the return routine to restore
+	 * all registers.
+	 */
+	cmpi	d8, #__NR_rt_sigreturn
+	jmpeq.f	6f
+
+	/*
+	 * Launch system call (it will return through a5 - syscall_exit)
+	 */
+	calli	a3, 0(a4)
+
+	/*
+	 * System call is rt_sigreturn. Test d1. If it is 1 we have to
+	 * change the return address to restore_all_registers
+	 */
+6:	cmpi	d1, #1
+	jmpne.t	7f
+
+	moveai	a5, #%hi(restore_all_registers)	 ; Setup return address
+	lea.1	a5, %lo(restore_all_registers)(a5) ; to restore_all_registers.
+
+	/*
+	 * Launch system call  (it will return through a5)
+	 */
+7:	calli	a3, 0(a4)			 ; Launch system call
+
+.Lsystem_call__trace:
+	/*
+	 * Syscalls are being traced.
+	 * Call syscall_trace, (return here)
+	 */
+	moveai	a4, #%hi(syscall_trace)
+	calli	a5, %lo(syscall_trace)(a4)
+
+	/*
+	 * Restore syscall state (it would have been discarded during the
+	 * syscall trace)
+	 */
+	move.4	d0, PT_D0(sp)			; Restore d0 from kernel stack
+	move.4	d1, PT_D1(sp)			; Restore d1 from kernel stack
+	move.4	d2, PT_D2(sp)			; Restore d2 from kernel stack
+	move.4	d3, PT_D3(sp)			; Restore d3 from kernel stack
+	move.4	d4, PT_D4(sp)			; Restore d4 from kernel stack
+	move.4	d5, PT_D5(sp)			; Restore d5 from kernel stack
+	/* add this back if we ever have a syscall with 7 args */
+	move.4	d8, PT_D8(sp)			; Restore d8 from kernel stack
+
+	/*
+	 * return to syscall
+	 */
+	jmpt.t .Lsystem_call__trace_complete
+	.size system_call, . - system_call
+
+/*
+ * syscall_exit()
+ */
+	.section .syscall_exit.text
+	.global syscall_exit
+syscall_exit:
+	/*
+	 * d0 contains the return value. We should move that into the kernel
+	 * stack d0 location.  We will be transitioning from kernel to user
+	 * mode. Test the flags and see if we have to call schedule. If we are
+	 * going to truly exit then all that has to be done is that from the
+	 * kernel stack we have to restore d0, a0, a1, a2, a5, a6 and sp (a7)bb
+	 * and then return via a5.
+	 */
+
+	/*
+	 * Save d0 to pt_regs
+	 */
+	move.4	PT_D0(sp), d0			; Save d0 into the kernel stack
+
+	/*
+	 * load the thread_info structure by masking off the THREAD_SIZE
+	 * bits.
+	 *
+	 * Note: we used to push a1, but now we don't as we are going
+	 * to eventually restore it to the userspace a1.
+	 */
+	movei	d9, #(~(ASM_THREAD_SIZE-1))
+	and.4	a1, sp, d9
+
+	/*
+	 * Are any interesting bits set on TI flags, if there are jump
+	 * aside to post_processing.
+	 */
+	move.4	d9, #(_TIF_SYSCALL_TRACE | _TIF_NEED_RESCHED | _TIF_SIGPENDING)
+	and.4	#0, TI_FLAGS(a1), d9
+	jmpne.f	.Lsyscall_exit__post_processing ; jump to handler
+.Lsyscall_exit__post_processing_complete:
+
+	move.4	d0, PT_D0(sp)			; Restore D0 from kernel stack
+	move.4	d1, PT_D1(sp)			; Restore d1 from kernel stack
+	move.4	d2, PT_D2(sp)			; Restore d2 from kernel stack
+	move.4	d3, PT_D3(sp)			; Restore d3 from kernel stack
+	move.4	d4, PT_D4(sp)			; Restore d4 from kernel stack
+	move.4	d5, PT_D5(sp)			; Restore d5 from kernel stack
+	move.4	d8, PT_D8(sp)			; Restore d8 from kernel stack
+	move.4	d10, PT_D10(sp)			; Restore d10 from kernel stack
+	move.4	d11, PT_D11(sp)			; Restore d11 from kernel stack
+	move.4	d12, PT_D12(sp)			; Restore d12 from kernel stack
+	move.4	d13, PT_D13(sp)			; Restore d13 from kernel stack
+	move.4	a1, PT_A1(sp)			; Restore A1 from kernel stack
+	move.4	a2, PT_A2(sp)			; Restore A2 from kernel stack
+	move.4	a5, PT_A5(sp)			; Restore A5 from kernel stack
+	move.4	a6, PT_A6(sp)			; Restore A6 from kernel stack
+	move.4	a0, PT_A0(sp)			; Restore A6 from kernel stack
+
+	/*
+	 * this is only for debug, and could be removed for production builds
+	 */
+	move.4	PT_FRAME_TYPE(sp), #0		; invalidate frame_type
+
+#ifdef CONFIG_PROTECT_KERNEL
+	/*
+	 * Enter critical section
+	 */
+	atomic_lock_acquire
+	disable_kernel_ranges_for_current d15
+#endif
+	/*
+	 * Lastly restore userspace stack ptr
+	 *
+	 * Note: that when protection is on we need to hold the lock around the
+	 * stack swap as well because otherwise the protection could get
+	 * inadvertently disabled again at the end of a context switch.
+	 */
+	move.4	a7, PT_A7(sp)			; Restore A7 from kernel stack
+
+	/*
+	 * We are now officially back in userspace!
+	 */
+
+#ifdef CONFIG_PROTECT_KERNEL
+	/*
+	 * Leave critical section and return to user space.
+	 */
+	atomic_lock_release
+#endif
+	calli	a5, 0(a5)			; Back to userspace code.
+
+	bkpt #-1				; we will never get here
+
+	/*
+	 * Post syscall processing. (unlikely part of syscall_exit)
+	 *
+	 * Are we tracing syscalls. If TIF_SYSCALL_TRACE is set, call
+	 * syscall_trace routine and return here.
+	 */
+.Lsyscall_exit__post_processing:
+	btst	TI_FLAGS(a1), #ASM_TIF_SYSCALL_TRACE
+	jmpeq.t	1f
+	moveai	a5, #%hi(syscall_trace)
+	calli	a5, %lo(syscall_trace)(a5)
+
+	/*
+	 * Do we need to resched ie call schedule. If TIF_NEED_RESCHED is set,
+	 * call the scheduler, it will come back here.
+	 */
+1:	btst	TI_FLAGS(a1), #ASM_TIF_NEED_RESCHED
+	jmpeq.t	2f
+	moveai	a5, #%hi(schedule)
+	calli	a5, %lo(schedule)(a5)
+
+	/*
+	 * Do we need to post a signal, if TIF_SIGPENDING is set call the
+	 * do_signal.
+	 */
+2:	btst	TI_FLAGS(a1), #ASM_TIF_SIGPENDING
+	jmpeq.t	.Lsyscall_exit__post_processing_complete
+
+	/*
+	 * setup the do signal call
+	 */
+	move.4	d0, #0				; oldset pointer is NULL
+	lea.1	d1, (sp)			; d1 is the regs pointer.
+	moveai	a5, #%hi(do_signal)		; Have to call do_signal
+	calli	a5, %lo(do_signal)(a5)
+
+	jmpt.t  .Lsyscall_exit__post_processing_complete
+
+	.size syscall_exit, . - syscall_exit
+
+/*
+ * kernel_execve()
+ *	kernel_execv is called when we the kernel is starting a
+ *	userspace application.
+ */
+	.section .kernel_unprotected
+	.global kernel_execve
+kernel_execve:
+	move.4	-4(sp)++, a5			; Save return address
+	/*
+	 * Call execve
+	 */
+	movei	d8, #__NR_execve		; call execve
+	moveai	a3, #%hi(system_call)
+	calli	a5, %lo(system_call)(a3)
+	move.4	a5, (sp)4++
+
+	/*
+	 * protection was enabled again at syscall exit, but we want
+	 * to return to kernel so we enable it again.
+	 */
+#ifdef CONFIG_PROTECT_KERNEL
+	/*
+	 * We are entering the kernel so we need to disable the protection.
+	 * Enter critical section, disable ranges and leave critical section.
+	 */
+	atomic_lock_acquire			; Enter critical section
+	enable_kernel_ranges_for_current d15
+	atomic_lock_release			; Leave critical section
+#endif
+	ret a5					; jump back to the kernel
+
+	.size kernel_execve, . - kernel_execve
+
+/*
+ * signal_trampoline()
+ *
+ *	Deals with transitioning from to userspace signal handlers and returning
+ *	to userspace, only called from the kernel.
+ *
+ */
+	.section .kernel_unprotected
+	.global signal_trampoline
+signal_trampoline:
+	/*
+	 * signal_trampoline is called when we are jumping from the kernel to
+	 * the userspace signal handler.
+	 *
+	 * The following registers are relevant. (set setup_rt_frame)
+	 *   sp is the user space stack not the kernel stack
+	 *  d0 = signal number
+	 *  d1 = siginfo_t *
+	 *  d2 = ucontext *
+	 *  d3 = the user space signal handler
+	 *  a0 is set to the GOT if userspace application is FDPIC, otherwise 0
+	 *  a3 is set to the FD for the signal if userspace application is FDPIC
+	 */
+#ifdef CONFIG_PROTECT_KERNEL
+	/*
+	 * We are leaving the kernel so we need to enable the protection.
+	 * Enter critical section, disable ranges and leave critical section.
+	 */
+	atomic_lock_acquire			; Enter critical section
+	disable_kernel_ranges_for_current d15	; disable kernel ranges
+	atomic_lock_release			; Leave critical section
+#endif
+	/*
+	 * The signal handler pointer is in register d3 so tranfer it to a4 and
+	 * call it
+	 */
+	movea	a4, d3				; signal handler
+	calli	a5, 0(a4)
+
+	/*
+	 * Return to userspace through rt_syscall which is stored on top of the
+	 * stack d1 contains ret_via_interrupt status.
+	 */
+	move.4	d8, (sp)			; d8 (syscall #) = rt_syscall
+	move.4	d1, 4(sp)			; d1 = ret_via_interrupt
+	moveai	a3, #%hi(system_call)		; call system_call
+	calli	a5, %lo(system_call)(a3)
+
+	bkpt -1					; will never get here.
+	.size signal_trampoline, . - signal_trampoline
+
+/*
+ * kernel_thread_helper()
+ *
+ *	Entry point for kernel threads (only referenced by kernel_thread()).
+ *
+ *	On execution d0 will be 0, d1 will be the argument to be passed to the
+ *	kernel function.
+ *	d2 contains the kernel function that needs to get called.
+ *	d3 will contain address to do_exit which needs to get moved into a5.
+ *
+ *	On return from fork the child thread d0 will be 0. We call this dummy
+ *	function which in turn loads the argument
+ */
+	.section .kernel_unprotected
+	.global kernel_thread_helper
+kernel_thread_helper:
+	/*
+	 * Create a kernel thread. This is called from ret_from_vfork (a
+	 * userspace return routine) so we need to put it in an unprotected
+	 * section and re-enable protection before calling the vector in d2.
+	 */
+
+#ifdef CONFIG_PROTECT_KERNEL
+	/*
+	 * We are entering the kernel so we need to disable the protection.
+	 * Enter critical section, disable ranges and leave critical section.
+	 */
+	atomic_lock_acquire			; Enter critical section
+	enable_kernel_ranges_for_current d0
+	atomic_lock_release			; Leave critical section
+#endif
+	/*
+	 * Move argument for kernel function into d0, and set a5 return address
+	 * (a5) to do_exit and return through a2
+	 */
+	move.4  d0, d1				; d0 = arg
+	move.4  a5, d3				; a5 = do_exit
+	ret	d2				; call function ptr in d2
+
+	.size kernel_thread_helper, . - kernel_thread_helper
+
+/*
+ * execve_intercept()
+ */
+	.section .text
+	.global execve_intercept
+execve_intercept:
+	move.4	d3, sp	; Save retrun address
+	moveai	a3, #%hi(sys_execve)
+	calli	a3, %lo(sys_execve)(a3)
+
+	.size execve_intercept, . - execve_intercept
+
+/*
+ * vfork_intercept()
+ */
+	.section .text
+	.global vfork_intercept
+vfork_intercept:
+	move.4	d0, sp	; Save pt_regs address
+	moveai	a3, #%hi(sys_vfork)
+	calli	a3, %lo(sys_vfork)(a3)
+
+	.size vfork_intercept, . - vfork_intercept
+
+/*
+ * clone_intercept()
+ */
+	.section .text
+	.global clone_intercept
+clone_intercept:
+	move.4	d2, sp	; Save pt_regs address
+	moveai	a3, #%hi(sys_clone)
+	calli	a3, %lo(sys_clone)(a3)
+
+	.size clone_intercept, . - clone_intercept
+
+/*
+ * sys_sigsuspend()
+ */
+	.section .text
+	.global sys_sigsuspend
+sys_sigsuspend:
+	move.4	d0, sp	; Pass pointer to pt_regs in d0
+	moveai	a3, #%hi(do_sigsuspend)
+	calli	a3, %lo(do_sigsuspend)(a3)
+
+	.size sys_sigsuspend, . - sys_sigsuspend
+
+/*
+ * sys_rt_sigsuspend()
+ */
+	.section .text
+	.global sys_rt_sigsuspend
+sys_rt_sigsuspend:
+	move.4	d0, sp	; Pass pointer to pt_regs in d0
+	moveai	a3, #%hi(do_rt_sigsuspend)
+	calli	a3, %lo(do_rt_sigsuspend)(a3)
+
+	.size sys_rt_sigsuspend, . - sys_rt_sigsuspend
+
+/*
+ * sys_rt_sigreturn()
+ */
+	.section .text
+	.global sys_rt_sigreturn
+sys_rt_sigreturn:
+	move.4	d0, sp	; Pass pointer to pt_regs in d0
+	moveai	a3, #%hi(do_rt_sigreturn)
+	calli	a3, %lo(do_rt_sigreturn)(a3)
+
+	.size sys_rt_sigreturn, . - sys_rt_sigreturn
+
+/*
+ * sys_sigaltstack()
+ */
+	.section .text
+	.global sys_sigaltstack
+sys_sigaltstack:
+	move.4	d0, sp	; Pass pointer to pt_regs in d0
+	moveai	a3, #%hi(do_sys_sigaltstack)
+	calli	a3, %lo(do_sys_sigaltstack)(a3)
+
+	.size sys_sigaltstack, . - sys_sigaltstack
--- /dev/null
+++ b/arch/ubicom32/kernel/unaligned_trap.c
@@ -0,0 +1,698 @@
+/*
+ * arch/ubicom32/kernel/unaligned_trap.c
+ *   Handle unaligned traps in both user or kernel space.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <asm/cacheflush.h>
+#include <asm/traps.h>
+
+#define FALSE 0
+#define TRUE 1
+
+/* no possible trap */
+#define UNUSED 0
+/* possible source operand trap */
+#define SRC 1
+#define SRC_2 2
+/* possible destination operand trap */
+#define DEST 3
+#define DEST_2 4
+/* can be either source or destination or both */
+#define TWO_OP 5
+#define TWO_OP_2 6
+
+/* TODO: What is the real value here, put something in to make it compile for
+ * now */
+#define MOVE_2	0x0d
+#define LSL_2	0x11
+#define LSR_2	0x13
+#define MOVEI	0x19
+#define CMPI	0x18
+
+static int op_format[32] =
+{
+	TWO_OP,		/* 0x00 */
+	UNUSED,
+	SRC,
+	UNUSED,
+	TWO_OP,		/* 0x04 */
+	TWO_OP,
+	SRC,
+	UNUSED,
+	TWO_OP_2,	/* 0x08 */
+	TWO_OP,
+	TWO_OP_2,
+	TWO_OP,
+	TWO_OP_2,	/* 0x0C */
+	TWO_OP,
+	TWO_OP_2,
+	TWO_OP,
+	TWO_OP,		/* 0x10 */
+	TWO_OP_2,
+	TWO_OP,
+	TWO_OP,
+	UNUSED,		/* 0x14 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	SRC_2,		/* 0x18 */
+	DEST_2,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x1C */
+	UNUSED,
+	UNUSED,		/* unaligned CALLI will not be fixed. */
+	UNUSED
+};
+
+static int op_0_format[32] =
+{
+	UNUSED,		/* 0x00 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x04 - ret don't fix - bad ret is always wrong */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x08 */
+	UNUSED,
+	TWO_OP,
+	TWO_OP_2,
+	TWO_OP,		/* 0x0c */
+	TWO_OP_2,
+	TWO_OP,
+	UNUSED,		/* .1 can't trap */
+	UNUSED,		/* 0x10 */
+	UNUSED,
+	SRC,
+	UNUSED,
+	UNUSED,		/* 0x14 */
+	TWO_OP_2,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x18 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	DEST,		/* 0x1c */
+	DEST,
+	DEST,
+	DEST,		/* all lea have 32-bit destination */
+};
+
+static int op_2_format[32] =
+{
+	UNUSED,		/* 0x00 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x04 */
+	UNUSED,
+	SRC,
+	UNUSED,
+	UNUSED,		/* 0x08 crcgen is .1 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x0c */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	SRC,		/* 0x10 */
+	SRC_2,
+	SRC,
+	SRC_2,
+	SRC,		/* 0x14 */
+	SRC_2,
+	SRC,
+	UNUSED,
+	UNUSED,		/* 0x18 */
+	UNUSED,
+	SRC,
+	UNUSED,
+	SRC,		/* 0x1c */
+	UNUSED,
+	SRC_2,
+	UNUSED,
+};
+
+static int op_6_format[32] =
+{
+	SRC_2,		/* 0x00 */
+	SRC_2,
+	SRC_2,
+	SRC_2,
+	SRC_2,		/* 0x04 */
+	SRC_2,
+	UNUSED,
+	SRC_2,
+	SRC,		/* 0x08 MULS.4 */
+	SRC_2,
+	SRC,
+	UNUSED,
+	UNUSED,		/* 0x0c */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	SRC,		/* 0x10 */
+	SRC_2,
+	SRC,
+	SRC_2,
+	UNUSED,		/* 0x14 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x18 */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+	UNUSED,		/* 0x1c */
+	UNUSED,
+	UNUSED,
+	UNUSED,
+};
+
+/*
+ * unaligned_get_address()
+ *	get an address using save_an and save_dn registers, and updates save_an
+ *	with side effects
+ */
+unsigned char *unaligned_get_address(int thread, int specifier, int four_byte,
+				     unsigned int save_an[],
+				     unsigned int save_dn[], int *write_back_an)
+{
+	unsigned char *address;
+
+	int areg = (specifier >> 5) & 7;
+	if ((specifier >> 8) == 2) {
+		int offset = specifier & 0xf;
+		offset = ((offset << 28) >> 28);
+		if (likely(four_byte)) {
+			offset <<= 2;
+		} else {
+			offset <<= 1;
+		}
+		if (specifier & 0x10) {
+			address = (unsigned char *)(save_an[areg] + offset);
+		} else {
+			address = (unsigned char *)save_an[areg];
+		}
+		save_an[areg] = save_an[areg] + offset;
+
+		/*
+		 * Let caller know An registers have been modified.
+		 */
+		*write_back_an = 1;
+	} else if ((specifier >> 8) == 3) {
+		int dreg = specifier & 0xf;
+		if (likely(four_byte)) {
+			address = (unsigned char *)(save_an[areg] +
+						    (save_dn[dreg] << 2));
+		} else {
+			address = (unsigned char *)(save_an[areg] +
+						    (save_dn[dreg] << 1));
+		}
+	} else {
+		int offset = ((specifier >> 3) & 0x60) | (specifier & 0x1f);
+		if (likely(four_byte)) {
+			address = (unsigned char *)(save_an[areg] +
+						    (offset << 2));
+		} else {
+			address = (unsigned char *)(save_an[areg] +
+						    (offset << 1));
+		}
+	}
+
+	return address;
+}
+
+static	int save_dn[16];
+static	int save_an[8];
+static	int save_acc[5];
+
+/*
+ * unaligned_emulate()
+ *	emulate the instruction at thread's pc that has taken an unaligned data
+ *	trap.
+ *
+ * source or destination or both might be unaligned
+ * the instruction must have a memory source or destination or both
+ * the emulated instruction is copied and executed in this thread
+ *
+ *	TODO: Protection is handled outside of this function
+ *	TODO: handling simultaneous unaligned and memory protection traps
+ *
+ *	Get thread state
+ *		the PC and instruction (and local copy, emulate_inst), and An
+ *		and Dn registers
+ *		All implicit soruce state (source3, CSR, accumulators)
+
+ *	if the instruction has a memory source
+ *		Use the instruction, An and Dn registers to form src_address
+ *		get unaligned source data from src_address (usually sign
+ *		extended)
+ *			(2 bytes, with or without sign extension, or 4 bytes)
+ *		modify emulate_inst to use d0 as source
+ *	else
+ *		get the soure operand from one of thread's registers
+ *	if instruction has a memory destination
+ *		Use the instruction, An and Dn registers to form dest_address
+ *		modify emulate_inst to use d0 as destination
+ *	if there was a memory source
+ *		put the source data in thread's d0
+ *	get the source-2 Dn operand and source 3 operand from thread
+ *	execute modified inst
+ *		(save it, flush caches, set up local values for implicit
+ *		sources, execute, save explicit and implicit results)
+ *	if inst has destination address
+ *		copy result to dest_address, possibly unaligned, 1, 2, or 4
+ *		bytes
+ *	restore thread's implicit results (modified address registers, CSR,
+ *	accumulators) add 4 to thread's pc
+ */
+void unaligned_emulate(unsigned int thread)
+{
+	unsigned int pc;
+	unsigned int inst;
+	unsigned int op;
+	unsigned int subop;
+	int format;
+	unsigned int emulate_inst;
+	int four_byte;
+	int src_operand, dest_operand;
+	int save_csr;
+	int source3;
+	unsigned int source1;
+	unsigned int source_data;
+	unsigned char *dest_address = NULL;
+	int source2 = 0;
+	unsigned int result;
+	unsigned int write_back_an = 0;
+	unsigned int chip_id_copy;
+
+	extern unsigned int trap_emulate;
+	extern unsigned int ubicom32_emulate_insn(int source1, int source2,
+						  int source3, int *save_acc,
+						  int *save_csr);
+
+	/*
+	 * get the chip_id
+	 */
+	asm volatile (
+	"	move.4		%0, chip_id		\n\t" /* get chip_id. */
+		: "=r"(chip_id_copy)
+		:
+	);
+
+	/*
+	 * get the pc
+	 */
+	asm volatile (
+	"	move.4		CSR, %1		\n\t" /* set source thread in
+						       * CSR */
+	"	setcsr_flush	0		\n\t"
+	"	move.4		%0, pc		\n\t"
+	"	move.4		CSR, #0		\n\t" /* restore CSR */
+	"	setcsr_flush	0		\n\t"
+		: "=a"(pc)
+		: "d" ((1 << 8) | (thread << 9))
+		: "cc"
+	);
+
+	inst = *((unsigned int *)pc);
+	op = inst >> 27;
+	if (unlikely(op == 2 || op == 6)) {
+		subop = (inst >> 21) & 0x1f;
+	} else {
+		subop = (inst >> 11) & 0x1f;
+	}
+	format = op_format[op];
+	emulate_inst = inst;
+
+	if (op == 0) {
+		format = op_0_format[subop];
+	} else if (op == 2) {
+		format = op_2_format[subop];
+	} else if (op == 6) {
+		format = op_6_format[subop];
+	}
+
+	if (unlikely(format == UNUSED)) {
+		/*
+		 * We are not going to emulate this. Bump PC by 4 and move on.
+		 */
+		asm volatile (
+		"	move.4		CSR, %0			\n\t"
+		"	setcsr_flush	0			\n\t"
+		"	move.4		pc, %1			\n\t"
+		"	setcsr		#0			\n\t"
+		"	setcsr_flush	0			\n\t"
+			:
+			: "d"((1 << 14) | (thread << 15)), "d"(pc + 4)
+			: "cc"
+		);
+		return;
+	}
+
+	four_byte = (format == TWO_OP || format == DEST || format == SRC);
+
+	/*
+	 * source or destination memory operand needs emulation
+	 */
+	src_operand = (format == SRC ||
+		       format == SRC_2 ||
+		       format == TWO_OP ||
+		       format == TWO_OP_2) &&
+		((inst >> 8) & 7) > 1;
+
+	dest_operand = (format == DEST ||
+			format == DEST_2 ||
+			format == TWO_OP ||
+			format == TWO_OP_2) &&
+		((inst >> 24) & 7) > 1;
+
+	/*
+	 * get thread's implicit sources (not covered by source context select).
+	 * data and address registers and CSR (for flag bits) and src3 and
+	 * accumulators
+	 */
+	asm volatile (
+	"	move.4		CSR, %2		\n\t"	/* set source thread in
+							 * CSR */
+	"	setcsr_flush	0		\n\t"
+	"	move.4		(%3), d0	\n\t"	/* get dn registers */
+	"	move.4		4(%3), d1	\n\t"
+	"	move.4		8(%3), d2	\n\t"
+	"	move.4		12(%3), d3	\n\t"
+	"	move.4		16(%3), d4	\n\t"
+	"	move.4		20(%3), d5	\n\t"
+	"	move.4		24(%3), d6	\n\t"
+	"	move.4		28(%3), d7	\n\t"
+	"	move.4		32(%3), d8	\n\t"
+	"	move.4		36(%3), d9	\n\t"
+	"	move.4		40(%3), d10	\n\t"
+	"	move.4		44(%3), d11	\n\t"
+	"	move.4		48(%3), d12	\n\t"
+	"	move.4		52(%3), d13	\n\t"
+	"	move.4		56(%3), d14	\n\t"
+	"	move.4		60(%3), d15	\n\t"
+	"	move.4		(%4), a0	\n\t"	/* get an registers */
+	"	move.4		4(%4), a1	\n\t"
+	"	move.4		8(%4), a2	\n\t"
+	"	move.4		12(%4), a3	\n\t"
+	"	move.4		16(%4), a4	\n\t"
+	"	move.4		20(%4), a5	\n\t"
+	"	move.4		24(%4), a6	\n\t"
+	"	move.4		28(%4), a7	\n\t"
+	"	move.4		%0, CSR		\n\t"	/* get csr and source3
+							 * implicit operands */
+	"	move.4		%1, source3	\n\t"
+	"	move.4		(%5), acc0_lo	\n\t"	/* get accumulators */
+	"	move.4		4(%5), acc0_hi	\n\t"
+	"	move.4		8(%5), acc1_lo	\n\t"
+	"	move.4		12(%5), acc1_hi	\n\t"
+	"	move.4		16(%5), mac_rc16	\n\t"
+	"	move.4		CSR, #0		\n\t"	/* restore CSR */
+	"	setcsr_flush	0		\n\t"
+		: "=m"(save_csr), "=m"(source3)
+		: "d"((1 << 8) | (thread << 9)),
+		  "a"(save_dn), "a"(save_an), "a"(save_acc)
+		: "cc"
+	);
+
+	/*
+	 * turn off thread select bits if they were on
+	 */
+	BUG_ON((save_csr & 0x04100) != 0);
+	if (unlikely(save_csr & 0x04100)) {
+		/*
+		 * Things are in funny state as thread select bits are on in
+		 * csr. PANIC.
+		 */
+		panic("In unaligned trap handler. Trap thread CSR has thread "
+		      "select bits on.\n");
+	}
+
+	save_csr = save_csr & 0x1000ff;
+
+	/*
+	 * get the source1 operand
+	 */
+	source1 = 0;
+	if (src_operand) {
+		unsigned char *src_address;
+
+		/*
+		 * source1 comes from memory
+		 */
+		BUG_ON(!(format == TWO_OP || format == TWO_OP_2 ||
+			 format == SRC || format == SRC_2));
+		src_address = unaligned_get_address(thread, inst & 0x7ff,
+						    four_byte, save_an,
+						    save_dn, &write_back_an);
+
+		/*
+		 * get data (possibly unaligned)
+		 */
+		if (likely(four_byte)) {
+			source_data = (*src_address << 24) |
+				(*(src_address + 1) << 16) |
+				(*(src_address + 2) << 8) |
+				*(src_address + 3);
+			source1 = source_data;
+		} else {
+			source1 = *src_address << 8 |
+				*(src_address + 1);
+
+			/*
+			 * Source is not extended if the instrution is MOVE.2 or
+			 * if the cpu CHIP_ID >= 0x30000 and the instruction is
+			 * either LSL.2 or LSR.2.  All other cases have to be
+			 * sign extended.
+			 */
+			if ((!(op == 2 && subop == MOVE_2)) &&
+			    (!((chip_id_copy >= 0x30000) &&
+			       (subop == LSL_2 || subop == LSR_2)))) {
+				/*
+				 * Have to sign extend the .2 entry.
+				 */
+				source1 = ((unsigned int)
+					   ((signed int)
+					    ((signed short) source1)));
+			}
+		}
+	} else if (likely(op != MOVEI)) {
+		/*
+		 * source1 comes from a register, using move.4 d0, src1
+		 * unaligned_emulate_get_source is pointer to code to insert remulated instruction
+		 */
+		extern unsigned int unaligned_emulate_get_src;
+		*((int *)&unaligned_emulate_get_src) &= ~(0x7ff);
+		*((int *)&unaligned_emulate_get_src) |= (inst & 0x7ff);
+		flush_dcache_range((unsigned long)(&unaligned_emulate_get_src),
+				   (unsigned long)(&unaligned_emulate_get_src) + 4);
+
+		asm volatile (
+			/* source1 uses thread's registers */
+		"	move.4		CSR, %1			\n\t"
+		"	setcsr_flush 0				\n\t"
+		"unaligned_emulate_get_src:			\n\t"
+		"	move.4	%0, #0				\n\t"
+		"	setcsr		#0			\n\t"
+		"	setcsr_flush	0			\n\t"
+			: "=d" (source1)
+			: "d" ((1 << 8) | (thread << 9))
+			: "cc"
+		);
+	}
+
+	/*
+	 * get the destination address
+	 */
+	if (dest_operand) {
+		BUG_ON(!(format == TWO_OP || format == TWO_OP_2 ||
+			 format == DEST || format == DEST_2));
+		dest_address = unaligned_get_address(thread,
+						     ((inst >> 16) & 0x7ff),
+						     four_byte, save_an,
+						     save_dn, &write_back_an);
+	}
+
+	if (write_back_an) {
+		/*
+		 * restore any modified An registers
+		 */
+		asm volatile (
+		"	move.4		CSR, %0			\n\t"
+		"	setcsr_flush	0			\n\t"
+		"	move.4		a0, (%1)		\n\t"
+		"	move.4		a1, 4(%1)		\n\t"
+		"	move.4		a2, 8(%1)		\n\t"
+		"	move.4		a3, 12(%1)		\n\t"
+		"	move.4		a4, 16(%1)		\n\t"
+		"	move.4		a5, 20(%1)		\n\t"
+		"	move.4		a6, 24(%1)		\n\t"
+		"	move.4		a7, 28(%1)		\n\t"
+		"	setcsr		#0			\n\t"
+		"	setcsr_flush	0			\n\t"
+			:
+			: "d" ((1 << 14) | (thread << 15)), "a" (save_an)
+			: "cc"
+		);
+	}
+
+	/*
+	 * get source 2 register if needed, and modify inst to use d1 for
+	 * source-2 source-2 will come from this thread, not the trapping thread
+	 */
+	source2 = 0;
+	if ((op >= 8 && op <= 0x17) ||
+	    ((op == 2 || op == 6) && (inst & 0x4000000))) {
+		int src_dn = (inst >> 11) & 0xf;
+		source2 = save_dn[src_dn];
+		/*
+		 * force the emulated instruction to use d1 for source2 operand
+		 */
+		emulate_inst = (emulate_inst & 0xffff07ff) | 0x800;
+	}
+
+	if (likely(op != MOVEI)) {
+		/*
+		 * change emulated instruction source1 to d0
+		 */
+		emulate_inst &= ~0x7ff;
+		emulate_inst |= 1 << 8;
+	}
+
+	if (unlikely(op == 6 || op == 2)) {
+		/*
+		 * Set destination to d0
+		 */
+		emulate_inst &= ~(0xf << 16);
+	} else if (likely(op != CMPI)) {
+		/*
+		 * Set general destination field to d0.
+		 */
+		emulate_inst &= ~(0x7ff << 16);
+		emulate_inst |= 1 << 24;
+	}
+
+	/*
+	 * execute emulated instruction d0, to d0, no memory access
+	 * source2 if needed will be in d1
+	 * source3, CSR, and accumulators are set up before execution
+	 */
+	*((unsigned int *)&trap_emulate) = emulate_inst;
+	flush_dcache_range((unsigned long)(&trap_emulate),
+			   (unsigned long)(&trap_emulate) + 4);
+
+	result = ubicom32_emulate_insn(source1, source2, source3,
+				       save_acc, &save_csr);
+
+	/*
+	 * set the result value
+	 */
+	if (dest_operand) {
+		/*
+		 * copy result to memory
+		 */
+		if (four_byte) {
+			*dest_address++ =
+				(unsigned char)((result >> 24) & 0xff);
+			*dest_address++ =
+				(unsigned char)((result >> 16) & 0xff);
+		}
+		*dest_address++ = (unsigned char)((result >> 8) & 0xff);
+		*dest_address = (unsigned char)(result & 0xff);
+	} else if (likely(op != CMPI)) {
+		/*
+		 * copy result to a register, using move.4 dest, result
+		 */
+		extern unsigned int unaligned_trap_set_result;
+		*((unsigned int *)&unaligned_trap_set_result) &= ~0x7ff0000;
+
+		if (op == 2 || op == 6) {
+			*((unsigned int *)&unaligned_trap_set_result) |=
+				((inst & 0x000f0000) | 0x01000000);
+		} else {
+			*((unsigned int *)&unaligned_trap_set_result) |=
+				(inst & 0x7ff0000);
+		}
+		flush_dcache_range((unsigned long)&unaligned_trap_set_result,
+				   ((unsigned long)(&unaligned_trap_set_result) + 4));
+
+		asm volatile (
+			/* result uses thread's registers */
+		"	move.4		CSR, %1			\n\t"
+		"	setcsr_flush 0				\n\t"
+		"unaligned_trap_set_result:			\n\t"
+		"	move.4 #0, %0				\n\t"
+		"	setcsr		#0			\n\t"
+		"	setcsr_flush	0			\n\t"
+			:
+			: "d"(result), "d" ((1 << 14) | (thread << 15))
+			: "cc"
+		);
+	}
+
+	/*
+	 * bump PC in thread and restore implicit register changes
+	 */
+	asm volatile (
+	"	move.4		CSR, %0			\n\t"
+	"	setcsr_flush	0			\n\t"
+	"	move.4		pc, %1			\n\t"
+	"	move.4		acc0_lo, (%3)		\n\t"
+	"	move.4		acc0_hi, 4(%3)		\n\t"
+	"	move.4		acc1_lo, 8(%3)		\n\t"
+	"	move.4		acc1_hi, 12(%3)		\n\t"
+	"	move.4		mac_rc16, 16(%3)	\n\t"
+	"	move.4		CSR, %2			\n\t"
+	"	setcsr		#0			\n\t"
+	"	setcsr_flush	0			\n\t"
+		:
+		: "d"((1 << 14) | (thread << 15)),
+		  "d"(pc + 4), "d"(save_csr), "a"(save_acc)
+		: "cc"
+	);
+}
+
+/*
+ * unaligned_only()
+ *	Return true if either of the unaligned causes are set (and no others).
+ */
+int unaligned_only(unsigned int cause)
+{
+	unsigned int unaligned_cause_mask =
+		(1 << TRAP_CAUSE_DST_MISALIGNED) |
+		(1 << TRAP_CAUSE_SRC1_MISALIGNED);
+
+	BUG_ON(cause == 0);
+	return (cause & unaligned_cause_mask) == cause;
+}
--- /dev/null
+++ b/arch/ubicom32/kernel/vmlinux.lds.S
@@ -0,0 +1,303 @@
+/*
+ * arch/ubicom32/kernel/vmlinux.lds.S
+ *	vmlinux primary linker script
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <asm-generic/vmlinux.lds.h>
+#include <asm/ocm_size.h>
+#include <asm/thread_info.h>
+#include <linux/threads.h>
+
+/*
+ * Sanity checks to prevent errors later on that are much harder to understand
+ */
+#if !defined APP_OCM_CODE_SIZE
+#error APP_OCM_CODE_SIZE has not been defined in ocm_size.h
+#endif
+
+#if !defined APP_OCM_DATA_SIZE
+#error APP_OCM_DATA_SIZE has not been defined in ocm_size.h
+#endif
+
+/*
+ * XXX Should get these from a common header file, but <asm/ip5000.h> is a mess
+ * and can't be included by anything other than C code at the moment.
+ */
+/*
+ * Memory Size
+ */
+#define OCM_SECTOR_SIZE 0x00008000              /* 32K */
+
+#if defined(CONFIG_UBICOM32_V3)
+#define OCMSIZE         0x00030000              /* 192K on-chip RAM for both program and data */
+#elif defined(CONFIG_UBICOM32_V4)
+#define OCMSIZE         0x0003C000              /* 240K on-chip RAM for both program and data */
+#else
+#error "Unknown IP5K silicon"
+#endif
+
+#define OCMSTART        0x3ffc0000              /* alias from 0x03000000 for easy jump to/from SDRAM */
+#define OCMEND          (OCMSTART + OCMSIZE)
+
+/*
+ * The `free' ocm area that ultra does not use.
+ */
+#if APP_OCM_CODE_SIZE || APP_OCM_DATA_SIZE
+#define OCM_FREE_START	(OCMSTART + APP_OCM_CODE_SIZE)
+#define OCM_FREE_LENGTH	(OCMSIZE - APP_OCM_CODE_SIZE - APP_OCM_DATA_SIZE)
+#else
+#define OCM_FREE_START OCMEND
+#define OCM_FREE_LENGTH 0
+#endif
+/*
+ * If you want to limit OCM use for text/data or completely disable it you can change these values.
+ */
+#define OCM_TEXT_LENGTH	OCM_FREE_LENGTH
+#define OCM_DATA_LENGTH	OCM_FREE_LENGTH
+
+#define	RAM_START	CONFIG_KERNELBASE
+#define	RAM_LENGTH	(CONFIG_RAMBASE + CONFIG_RAMSIZE - CONFIG_KERNELBASE)
+#define	TEXT		ram
+#define	DATA		ram
+#define	INIT		ram
+#define	BSS		ram
+
+#ifndef DATA_ADDR
+#define	DATA_ADDR
+#endif
+
+OUTPUT_ARCH(ubicom32)
+ENTRY(_start)
+
+MEMORY {
+	ram		: ORIGIN = RAM_START, LENGTH = RAM_LENGTH
+	ocm		: ORIGIN = OCM_FREE_START, LENGTH = OCM_FREE_LENGTH
+}
+
+jiffies = jiffies_64 + 4;
+
+/*
+ * Fixed locations required by gdb coredumps.
+ *
+ * Note that the names are what gdb is expecting so renaming will break
+ * the toolchain.
+ */
+__ocm_begin		= OCMSTART;
+__ocm_limit		= __ocm_begin + OCMSIZE;
+__sdram_begin		= CONFIG_RAMBASE;
+__sdram_limit		= __sdram_begin + CONFIG_RAMSIZE;
+__filemedia_begin_addr	= 0x60000000;
+__filemedia_end_addr	= __filemedia_begin_addr + 0x00800000;
+
+SECTIONS {
+
+	.fixed_text : {
+		_begin = .;
+		*(.skip_syscall)
+		*(.syscall_entry.text)
+		*(.syscall_exit.text)
+		*(.ret_from_interrupt_to_user.text)
+		*(.ret_from_fork.text)
+		*(.kernel_unprotected)
+		__fixed_text_end = .;
+	} > TEXT
+	. = _begin + SIZEOF(.fixed_text) ;
+
+	__ocm_text_load_begin = .;
+	__ocm_text_run_begin = OCM_FREE_START ;
+	.ocm_text __ocm_text_run_begin : AT(__ocm_text_load_begin) {
+#if OCM_TEXT_LENGTH
+		*(.ocm_text)
+		*(.sched.text)
+		*(.spinlock.text)
+#include <asm/ocm_text.lds.inc>
+		. = ALIGN(4);
+#endif
+		__ocm_text_run_end = .;
+		__data_begin = ALIGN(OCM_SECTOR_SIZE);
+	} > ocm /* .ocm_text */
+
+	.ocm_module_text __ocm_text_run_end (NOLOAD) : AT(__ocm_text_run_end) {
+		__ocm_inst_heap_begin = .;
+		/* Reserve the min requested */
+		. += (CONFIG_OCM_MODULES_RESERVATION) * 1024;
+#ifdef CONFIG_OCM_MODULES_MAY_CONSUME_REMAINING_CODESPACE
+		/* Round up to OCM sector size (we cannot use it for data) */
+		. = ALIGN(OCM_SECTOR_SIZE);
+#endif
+		__ocm_inst_heap_end = .;
+		/* update __data_begin */
+		__data_begin = ALIGN(OCM_SECTOR_SIZE);
+	} > ocm  /* .ocm_module_text */
+
+	. = __ocm_text_load_begin + __ocm_text_run_end - __ocm_text_run_begin ;
+	__ocm_text_load_end = .;
+
+	__ocm_data_load_begin = .;
+	__ocm_data_run_begin = __data_begin ;
+#if OCM_DATA_LENGTH
+	.ocm_data __ocm_data_run_begin : AT(__ocm_data_load_begin) {
+#if defined(CONFIG_IRQSTACKS_USEOCM)
+		percpu_irq_stacks = .;
+		. += NR_CPUS * THREAD_SIZE;
+#endif
+		*(.ocm_data)
+		. = ALIGN(4) ;
+		__ocm_data_run_end = .;
+	} > ocm
+	. = __ocm_data_load_begin + __ocm_data_run_end - __ocm_data_run_begin ;
+#else
+	__ocm_data_run_end = __ocm_data_run_begin;
+#endif
+	__ocm_data_load_end = .;
+
+	__ocm_free_begin = __ocm_data_run_end;
+	__ocm_free_end = OCM_FREE_START + OCM_FREE_LENGTH;
+
+	.text __ocm_data_load_end : AT(__ocm_data_load_end) {
+		. = ALIGN(4);
+		_stext = .;
+		_text = .;
+		TEXT_TEXT
+		SCHED_TEXT
+		LOCK_TEXT
+		*(.text.lock)
+		*(.text.__libgcc_udivmodsi)
+		*(.text.__libgcc_divmodsi)
+		*(.text.__libgcc_muldi3)
+		*(.text.__libgcc_udivmoddi)
+		*(.text.__libgcc_divmoddi)
+		*(.text.*)
+#if OCM_TEXT_LENGTH == 0
+		*(.ocm_text)
+		*(.sched.text)
+		*(.spinlock.text)
+#endif
+		. = ALIGN(16);          /* Exception table              */
+		__start___ex_table = .;
+		*(__ex_table)
+		__stop___ex_table = .;
+
+	} > TEXT
+
+	RO_DATA(16)
+
+	.rodata : {} > TEXT
+	.rodata1 : {} > TEXT
+	.pci_fixup : {} > TEXT
+	.builtin_fw : {} > TEXT
+	.rio_route : {} > TEXT
+	.tracedata : {} > TEXT
+	__ksymtab : {} > TEXT
+	__ksymtab_gpl : {} > TEXT
+	__ksymtab_gpl_future : {} > TEXT
+	__kcrctab_gpl : {} > TEXT
+	__kcrctab_unused : {} > TEXT
+	__kcrctab_unused_gpl : {} > TEXT
+	__kcrctab_gpl_future : {} > TEXT
+	__ksymtab_strings : {} > TEXT
+	__init_rodata : {} > TEXT
+	__param : {} > TEXT
+
+	_etext = .;
+
+	.data DATA_ADDR : {
+		. = ALIGN(4);
+		_sdata = . ;
+		DATA_DATA
+#if OCM_DATA_LENGTH == 0
+		*(.ocm_data)
+#endif
+		. = ALIGN(8192) ;
+		_data_protection_end = .;
+		*(.data.init_task)
+		. = ALIGN(4);
+		_edata = . ;
+	} > DATA
+
+	.init : {
+		. = ALIGN(4096);
+		__init_begin = .;
+		_sinittext = .;
+		INIT_TEXT
+		_einittext = .;
+		*(.init.rodata)
+		INIT_DATA
+		. = ALIGN(16);
+		__setup_start = .;
+		*(.init.setup)
+		__setup_end = .;
+		__initcall_start = .;
+		INITCALLS
+		__initcall_end = .;
+		__con_initcall_start = .;
+		*(.con_initcall.init)
+		__con_initcall_end = .;
+		___security_initcall_start = .;
+		*(.security_initcall.init)
+		___security_initcall_end = .;
+#ifdef CONFIG_BLK_DEV_INITRD
+		. = ALIGN(4);
+		__initramfs_start = .;
+		*(.init.ramfs)
+		__initramfs_end = .;
+#endif
+		. = ALIGN(4096);
+		__per_cpu_start = .;
+			*(.data.percpu)
+			*(.data.percpu.shared_aligned)
+		__per_cpu_end = .;
+
+		. = ALIGN(4096);
+		__init_end = .;
+	} > INIT
+
+	  .eh_frame   :
+	  {
+	    PROVIDE (___eh_frame_begin = .);
+	    *(.eh_frame)
+	    LONG (0);
+	    PROVIDE (___eh_frame_end = .);
+	  } > INIT
+
+	.bss : {
+		. = ALIGN(4);
+		_sbss = . ;
+		*(.bss)
+		*(COMMON)
+		. = ALIGN(4) ;
+		_ebss = . ;
+		_end = . ;
+	} > BSS
+
+	/DISCARD/ : {
+		EXIT_TEXT
+		EXIT_DATA
+		*(.exitcall.exit)
+	}
+
+	NOTES > BSS
+
+}
--- /dev/null
+++ b/arch/ubicom32/lib/checksum.c
@@ -0,0 +1,250 @@
+/*
+ * arch/ubicom32/lib/checksum.c
+ *   Optimized checksum utilities for IP.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ * INET		An implementation of the TCP/IP protocol suite for the LINUX
+ *		operating system.  INET is implemented using the  BSD Socket
+ *		interface as the means of communication with the user level.
+ *
+ *		IP/TCP/UDP checksumming routines
+ *
+ * Authors:	Jorge Cwik, <jorge@laser.satlink.net>
+ *		Arnt Gulbrandsen, <agulbra@nvg.unit.no>
+ *		Tom May, <ftom@netcom.com>
+ *		Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>
+ *		Lots of code moved from tcp.c and ip.c; see those files
+ *		for more names.
+ *
+ * 03/02/96	Jes Sorensen, Andreas Schwab, Roman Hodek:
+ *		Fixed some nasty bugs, causing some horrible crashes.
+ *		A: At some points, the sum (%0) was used as
+ *		length-counter instead of the length counter
+ *		(%1). Thanks to Roman Hodek for pointing this out.
+ *		B: GCC seems to mess up if one uses too many
+ *		data-registers to hold input values and one tries to
+ *		specify d0 and d1 as scratch registers. Letting gcc choose these
+ *		registers itself solves the problem.
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ */
+
+/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access kills, so most
+   of the assembly has to go. */
+
+#include <linux/module.h>
+#include <net/checksum.h>
+
+static unsigned long do_csum(const unsigned char * buff, int len)
+{
+	int count;
+	unsigned long result = 0;
+
+	/*
+	 * The following optimized assembly code cannot handle data length less than 7 bytes!
+	 */
+	if (likely(len >= 7)) {
+		len -= (4 - (int)buff) & 3;
+		count = len >> 2;
+		asm (
+		"	sub.4		d15, #0, %2		\n\t"	// set up for jump table
+		"	and.4		d15, #(32-1), d15	\n\t"	// d15 = (-m) & (32 - 1)
+
+		"	bfextu		d14, %0, #2		\n\t"	// test 2 LSB of buff
+		"	jmpne.w.f	100f			\n\t"
+		"	add.4		%1, #0, %1		\n\t"	// clear C
+		"	moveai		a3, #%%hi(1f)		\n\t"	// table jump
+		"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+		"	lea.4		a3, (a3,d15)		\n\t"
+		"	calli		a3, 0(a3)		\n\t"
+
+		"100:	sub.4		%0, %0, d14		\n\t"
+		"	sub.4		d14, #4, d14		\n\t"
+		"	lsl.4		d14, d14, #3		\n\t"
+		"	add.4		%1, #0, %1		\n\t"	// clear C
+		"	moveai		a3, #%%hi(1f)		\n\t"	// table jump
+		"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+		"	lea.4		a3, (a3,d15)		\n\t"
+		"	bfextu		%1, (%0)4++, d14	\n\t"	// read first partial word
+		"	calli		a3, 0(a3)		\n\t"
+#if 1
+		"200:	lsl.4		%3, %3, #3		\n\t"
+		"	bfrvrs		d15, (%0), #0		\n\t"	// read last word (partial)
+		"	bfextu		d15, d15, %3		\n\t"
+		"	bfrvrs		d15, d15, #0		\n\t"
+		"	add.4		%1, d15, %1		\n\t"
+		"	addc		%1, #0, %1		\n\t"	// sample C again
+		"	jmpt.w.t	2f			\n\t"
+#else
+		"200:	move.1		d15, 0(%0)		\n\t"
+		"	lsl.4		d15, d15, #8		\n\t"
+		"	add.4		%1, d15, %1		\n\t"
+		"	addc		%1, #0, %1		\n\t"	// sample C again
+		"	add.4		%3, #-1, %3		\n\t"
+		"	jmpeq.w.t	2f			\n\t"
+
+		"	move.1		d15, 1(%0)		\n\t"
+		"	add.4		%1, d15, %1		\n\t"
+		"	addc		%1, #0, %1		\n\t"	// sample C again
+		"	add.4		%3, #-1, %3		\n\t"
+		"	jmpeq.w.t	2f			\n\t"
+
+		"	move.1		d15, 2(%0)		\n\t"
+		"	lsl.4		d15, d15, #8		\n\t"
+		"	add.4		%1, d15, %1		\n\t"
+		"	addc		%1, #0, %1		\n\t"	// sample C again
+		"	jmpt.w.t	2f			\n\t"
+#endif
+#if defined(IP7000) || defined(IP7000_REV2)
+		"300:	swapb.2		%1, %1			\n\t"
+#else
+		"300:	shmrg.2		%1, %1, %1		\n\t"
+		"	lsr.4		%1, %1, #8		\n\t"
+		"	bfextu		%1, %1, #16		\n\t"
+#endif
+		"	jmpt.w.t	3f			\n\t"
+
+		"1:	add.4		%1, (%0)4++, %1		\n\t"	// first add without C
+		"	.rept		31			\n\t"
+		"	addc		%1, (%0)4++, %1		\n\t"
+		"	.endr					\n\t"
+		"	addc		%1, #0, %1		\n\t"	// sample C again
+		"	add.4		%2, #-32, %2		\n\t"
+		"	jmpgt.w.t	1b			\n\t"
+
+		"	and.4		%3, #3, %3		\n\t"	// check n
+		"	jmpne.w.f	200b			\n\t"
+
+		"2:	.rept		2			\n\t"
+		"	lsr.4		d15, %1, #16		\n\t"
+		"	bfextu		%1, %1, #16		\n\t"
+		"	add.4		%1, d15, %1		\n\t"
+		"	.endr					\n\t"
+		"	btst		d14, #3			\n\t"	// start from odd address (<< 3)?
+		"	jmpne.w.f	300b			\n\t"
+		"3:						\n\t"
+
+			: "+a"(buff), "+d"(result), "+d"(count), "+d"(len)
+			:
+			: "d15", "d14", "a3", "cc"
+		);
+
+		return result;
+	}
+
+	/*
+	 * handle a few bytes and fold result into 16-bit
+	 */
+	while (len-- > 0) {
+		result += (*buff++ << 8);
+		if (len) {
+			result += *buff++;
+			len--;
+		}
+	}
+	asm (
+	"	.rept		2			\n\t"
+	"	lsr.4		d15, %0, #16		\n\t"
+	"	bfextu		%0, %0, #16		\n\t"
+	"	add.4		%0, d15, %0		\n\t"
+	"	.endr					\n\t"
+		: "+d" (result)
+		:
+		: "d15", "cc"
+	);
+
+	return result;
+}
+
+/*
+ *	This is a version of ip_compute_csum() optimized for IP headers,
+ *	which always checksum on 4 octet boundaries.
+ */
+__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
+{
+	return (__force __sum16)~do_csum(iph,ihl*4);
+}
+
+/*
+ * computes the checksum of a memory block at buff, length len,
+ * and adds in "sum" (32-bit)
+ *
+ * returns a 32-bit number suitable for feeding into itself
+ * or csum_tcpudp_magic
+ *
+ * this function must be called with even lengths, except
+ * for the last fragment, which may be odd
+ *
+ * it's best to have buff aligned on a 32-bit boundary
+ */
+__wsum csum_partial(const void *buff, int len, __wsum sum)
+{
+	unsigned int result = do_csum(buff, len);
+
+	/* add in old sum, and carry.. */
+	result += (__force u32)sum;
+	if ((__force u32)sum > result)
+		result += 1;
+	return (__force __wsum)result;
+}
+
+EXPORT_SYMBOL(csum_partial);
+
+/*
+ * this routine is used for miscellaneous IP-like checksums, mainly
+ * in icmp.c
+ */
+__sum16 ip_compute_csum(const void *buff, int len)
+{
+	return (__force __sum16)~do_csum(buff,len);
+}
+
+/*
+ * copy from fs while checksumming, otherwise like csum_partial
+ */
+
+__wsum
+csum_partial_copy_from_user(const void __user *src, void *dst,
+			    int len, __wsum sum, int *csum_err)
+{
+	if (csum_err) *csum_err = 0;
+	memcpy(dst, (__force const void *)src, len);
+	return csum_partial(dst, len, sum);
+}
+
+/*
+ * copy from ds while checksumming, otherwise like csum_partial
+ */
+
+__wsum
+csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
+{
+	memcpy(dst, src, len);
+	return csum_partial(dst, len, sum);
+}
--- /dev/null
+++ b/arch/ubicom32/lib/delay.c
@@ -0,0 +1,49 @@
+/*
+ * arch/ubicom32/lib/delay.c
+ *   Ubicom32 implementation of udelay()
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <asm/param.h>
+#include <asm/delay.h>
+#include <asm/ip5000.h>
+
+/*
+ * read_current_timer()
+ *	Return the current value of sysval.
+ */
+int __devinit read_current_timer(unsigned long *timer_val)
+{
+	*timer_val = (long)(UBICOM32_IO_TIMER->sysval);
+	return 0;
+}
+
+
+void udelay(unsigned long usecs)
+{
+	_udelay(usecs);
+}
+EXPORT_SYMBOL(udelay);
--- /dev/null
+++ b/arch/ubicom32/lib/Makefile
@@ -0,0 +1,32 @@
+#
+# arch/ubicom32/lib/Makefile
+#	<TODO: Replace with short file description>
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+#
+# Makefile for m68knommu specific library files..
+#
+
+lib-y	:= checksum.o delay.o mem_ubicom32.o muldi3.o lshrdi3.o ashldi3.o ashrdi3.o divmod.o
--- /dev/null
+++ b/arch/ubicom32/lib/mem_ubicom32.c
@@ -0,0 +1,242 @@
+/*
+ * arch/ubicom32/lib/mem_ubicom32.c
+ *   String functions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/compiler.h>
+
+#define LIKELY likely
+#define UNLIKELY unlikely
+
+typedef u32_t addr_t;
+
+/*
+ * memcpy()
+ */
+void *memcpy(void *dest, const void *src, size_t n)
+{
+	void *dest_ret = dest;
+
+	if (LIKELY((((addr_t)dest ^ (addr_t)src) & 3) == 0) && LIKELY(n > 6)) {
+		size_t m;
+		n -= (4 - (addr_t)dest) & 0x03;
+		m = n >> 2;
+		asm volatile (
+		"	sub.4		d15, #0, %2		\n\t"	// set up for jump table
+		"	and.4		d15, #(32-1), d15	\n\t"	// d15 = (-m) & (32 - 1)
+		"	moveai		a3, #%%hi(1f)		\n\t"
+		"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+		"	lea.4		a3, (a3,d15)		\n\t"
+
+		"	bfextu		d15, %0, #2		\n\t"	// d15 = (dest & 3)
+		"	jmpne.w.f	100f			\n\t"
+		"	calli		a3, 0(a3)		\n\t"	// 4-byte alignment
+
+		"100:	cmpi		d15, #2			\n\t"
+		"	jmpne.s.f	101f			\n\t"
+		"	move.2		(%0)2++, (%1)2++	\n\t"
+		"	calli		a3, 0(a3)		\n\t"	// 2-byte alignment
+
+		"101:	move.1		(%0)1++, (%1)1++	\n\t"
+		"	jmpgt.s.f	102f			\n\t"	// 3-byte alignment
+		"	move.2		(%0)2++, (%1)2++	\n\t"	// 1-byte alignment
+		"102:	calli		a3, 0(a3)		\n\t"
+
+		"200:	cmpi		%3, #2			\n\t"
+		"	jmplt.s.f	201f			\n\t"
+		"	move.2		(%0)2++, (%1)2++	\n\t"
+		"	jmpeq.s.t	2f			\n\t"
+		"201:	move.1		(%0)1++, (%1)1++	\n\t"
+		"	jmpt.w.t	2f			\n\t"
+
+		"1:	.rept		25			\n\t"
+		"	movea		(%0)4++, (%1)4++	\n\t"
+		"	.endr					\n\t"
+		"	.rept		7			\n\t"
+		"	move.4		(%0)4++, (%1)4++	\n\t"
+		"	.endr					\n\t"
+		"	add.4		%2, #-32, %2		\n\t"
+		"	jmpgt.w.f	1b			\n\t"
+
+		"	and.4		%3, #3, %3		\n\t"	// check n
+		"	jmpne.w.f	200b			\n\t"
+		"2:						\n\t"
+			: "+a" (dest), "+a" (src), "+d" (m), "+d" (n)
+			:
+			: "d15", "a3", "memory", "cc"
+		);
+
+		return dest_ret;
+	}
+
+	if (LIKELY((((addr_t)dest ^ (addr_t)src) & 1) == 0) && LIKELY(n > 2)) {
+		size_t m;
+		n -= (addr_t)dest & 0x01;
+		m = n >> 1;
+		asm volatile (
+		"	sub.4		d15, #0, %2		\n\t"	// set up for jump table
+		"	and.4		d15, #(32-1), d15	\n\t"	// d15 = (-m) & (32 - 1)
+		"	moveai		a3, #%%hi(1f)		\n\t"
+		"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+		"	lea.4		a3, (a3,d15)		\n\t"
+
+		"	btst		%0, #0			\n\t"	// check bit 0
+		"	jmpne.w.f	100f			\n\t"
+		"	calli		a3, 0(a3)		\n\t"	// 4-byte alignment
+
+		"100:	move.1		(%0)1++, (%1)1++	\n\t"
+		"	calli		a3, 0(a3)		\n\t"
+
+		"200:	move.1		(%0)1++, (%1)1++	\n\t"
+		"	jmpt.w.t	2f			\n\t"
+
+		"1:	.rept		32			\n\t"
+		"	move.2		(%0)2++, (%1)2++	\n\t"
+		"	.endr					\n\t"
+		"	add.4		%2, #-32, %2		\n\t"
+		"	jmpgt.w.f	1b			\n\t"
+
+		"	and.4		%3, #1, %3		\n\t"	// check n
+		"	jmpne.w.f	200b			\n\t"
+		"2:						\n\t"
+
+			: "+a" (dest), "+a" (src), "+d" (m), "+d" (n)
+			:
+			: "d15", "a3", "memory", "cc"
+		);
+
+		return dest_ret;
+	}
+
+	asm volatile (
+	"	sub.4		d15, #0, %2		\n\t"
+	"	jmpeq.w.f	2f			\n\t"
+	"	and.4		d15, #(16-1), d15	\n\t"	// d15 = (-n) & (16 - 1)
+	"	moveai		a3, #%%hi(1f)		\n\t"
+	"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+	"	lea.4		a3, (a3,d15)		\n\t"
+	"	calli		a3, 0(a3)		\n\t"
+
+	"1:	.rept		16			\n\t"
+	"	move.1		(%0)1++, (%1)1++	\n\t"
+	"	.endr					\n\t"
+	"	add.4		%2, #-16, %2		\n\t"
+	"	jmpgt.w.f	1b			\n\t"
+	"2:						\n\t"
+
+		: "+a" (dest), "+a" (src), "+d" (n)
+		:
+		: "d15", "a3", "memory", "cc"
+	);
+
+	return dest_ret;
+}
+
+/*
+ * memset()
+ */
+void *memset(void *s, int c, size_t n)
+{
+	void *s_ret = s;
+
+	if (LIKELY(n > 6)) {
+		size_t m;
+		n -= (4 - (addr_t)s) & 0x03;
+		m = n >> 2;
+		asm volatile (
+		"	sub.4		d15, #0, %2		\n\t"	// set up for jump table
+		"	and.4		d15, #(32-1), d15	\n\t"	// d15 = (-m) & (32 - 1)
+		"	shmrg.1		%1, %1, %1		\n\t"
+		"	shmrg.2		%1, %1, %1		\n\t"	// %1 = (c<<24)|(c<<16)|(c<<8)|c
+		"	moveai		a3, #%%hi(1f)		\n\t"
+		"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+		"	lea.4		a3, (a3,d15)		\n\t"
+
+		"	bfextu		d15, %0, #2		\n\t"	// d15 = (s & 3)
+		"	jmpne.w.f	100f			\n\t"
+		"	calli		a3, 0(a3)		\n\t"	// 4-byte alignment
+
+		"100:	cmpi		d15, #2			\n\t"
+		"	jmpne.s.f	101f			\n\t"
+		"	move.2		(%0)2++, %1		\n\t"
+		"	calli		a3, 0(a3)		\n\t"	// 2-byte alignment
+
+		"101:	move.1		(%0)1++, %1		\n\t"
+		"	jmpgt.s.f	102f			\n\t"	// 3-byte alignment
+		"	move.2		(%0)2++, %1		\n\t"	// 1-byte alignment
+		"102:	calli		a3, 0(a3)		\n\t"
+
+		"200:	cmpi		%3, #2			\n\t"
+		"	jmplt.s.f	201f			\n\t"
+		"	move.2		(%0)2++, %1		\n\t"
+		"	jmpeq.s.t	2f			\n\t"
+		"201:	move.1		(%0)1++, %1		\n\t"
+		"	jmpt.w.t	2f			\n\t"
+
+		"1:	.rept		25			\n\t"
+		"	movea		(%0)4++, %1		\n\t"
+		"	.endr					\n\t"
+		"	.rept		7			\n\t"
+		"	move.4		(%0)4++, %1		\n\t"
+		"	.endr					\n\t"
+		"	add.4		%2, #-32, %2		\n\t"
+		"	jmpgt.w.f	1b			\n\t"
+
+		"	and.4		%3, #3, %3		\n\t"	// test bit 1 of n
+		"	jmpne.w.f	200b			\n\t"
+		"2:						\n\t"
+
+			: "+a" (s), "+d" (c), "+d" (m), "+d" (n)
+			:
+			: "d15", "a3", "memory", "cc"
+		);
+
+		return s_ret;
+	}
+
+	asm volatile (
+	"	sub.4		d15, #0, %2		\n\t"
+	"	jmpeq.w.f	2f			\n\t"
+	"	and.4		d15, #(8-1), d15	\n\t"	// d15 = (-%2) & (16 - 1)
+	"	moveai		a3, #%%hi(1f)		\n\t"
+	"	lea.1		a3, %%lo(1f)(a3)	\n\t"
+	"	lea.4		a3, (a3,d15)		\n\t"
+	"	calli		a3, 0(a3)		\n\t"
+
+	"1:	.rept		8			\n\t"
+	"	move.1		(%0)1++, %1		\n\t"
+	"	.endr					\n\t"
+	"2:						\n\t"
+
+		: "+a" (s), "+d" (c), "+d" (n)
+		:
+		: "d15", "a3", "memory", "cc"
+	);
+
+	return s_ret;
+}
--- /dev/null
+++ b/arch/ubicom32/mach-common/audio_tio.c
@@ -0,0 +1,115 @@
+/*
+ * arch/ubicom32/mach-common/audio_tio.c
+ *   Generic initialization for Ubicom32 Audio
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#include <asm/devtree.h>
+#include <asm/audio_tio.h>
+#include <asm/ubi32-pcm.h>
+
+/*
+ * The number of audio_tio's currently allocated, used for .id
+ */
+static int __initdata audio_tio_count;
+
+/*
+ * The maximum number of resources that the audio_tio will have.
+ * Currently 3, a register space, and up to 2 interrupts.
+ */
+#define AUDIO_TIO_MAX_RESOURCES	3
+
+/*
+ * audio_tio_alloc
+ *	Checks the device tree and allocates a platform_device if found
+ */
+struct platform_device * __init audio_tio_alloc(const char *driver_name, 
+		const char *node_name, int priv_bytes)
+{
+	struct platform_device *pdev;
+	struct resource *res;
+	struct audiotionode *audio_node;
+	struct ubi32pcm_platform_data *pdata;
+
+	/*
+	 * Check the device tree for the audio_tio
+	 */
+	audio_node = (struct audiotionode *)devtree_find_node(node_name);
+	if (!audio_node) {
+		printk(KERN_WARNING "audio TIO '%s' found\n", node_name);
+		return NULL;
+	}
+
+	if (audio_node->version != AUDIOTIONODE_VERSION) {
+		printk(KERN_WARNING "audio_tio not compatible\n");
+		return NULL;
+	}
+
+	/*
+	 * Dynamically create the platform_device structure and resources
+	 */
+	pdev = kzalloc(sizeof(struct platform_device) + 
+		       sizeof(struct ubi32pcm_platform_data) + 
+		       priv_bytes , GFP_KERNEL);
+	if (!pdev) {
+		printk(KERN_WARNING "audio_tio could not alloc pdev\n");
+		return NULL;
+	}
+
+	res = kzalloc(sizeof(struct resource) * AUDIO_TIO_MAX_RESOURCES,
+			GFP_KERNEL);
+	if (!res) {
+		kfree(pdev);
+		printk(KERN_WARNING "audio_tio could not alloc res\n");
+		return NULL;
+	}
+
+	pdev->name = driver_name;
+	pdev->id = audio_tio_count++;
+	pdev->resource = res;
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	res[0].start = (u32_t)(audio_node->regs);
+	res[0].end = (u32_t)(audio_node->regs);
+	res[0].flags = IORESOURCE_MEM;
+	res[1 + AUDIOTIO_TX_IRQ_RESOURCE].start = audio_node->dn.sendirq;
+	res[1 + AUDIOTIO_TX_IRQ_RESOURCE].flags = IORESOURCE_IRQ;
+	res[1 + AUDIOTIO_RX_IRQ_RESOURCE].start = audio_node->dn.recvirq;
+	res[1 + AUDIOTIO_RX_IRQ_RESOURCE].flags = IORESOURCE_IRQ;
+	pdev->num_resources = 3;
+
+	printk(KERN_INFO "AudioTIO.%d '%s' found irq=%d/%d regs=%p pdev=%p/%p\n",
+		audio_tio_count - 1, node_name, audio_node->dn.sendirq,
+		audio_node->dn.recvirq, audio_node->regs, pdev, res);
+	pdata = (struct ubi32pcm_platform_data *)(pdev + 1);
+	pdev->dev.platform_data = pdata;
+	pdata->node_name = node_name;
+	if (priv_bytes) {
+		pdata->priv_data = pdata + 1;
+	}
+
+	return pdev;
+}
+
--- /dev/null
+++ b/arch/ubicom32/mach-common/board.c
@@ -0,0 +1,63 @@
+/*
+ * arch/ubicom32/mach-common/board.c
+ *   Board init and support code.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/cpu.h>
+#include <asm/devtree.h>
+
+struct boardnode {
+	struct devtree_node dn;
+	const char *revision;
+};
+
+static const struct boardnode *bn;
+
+/*
+ * board_get_revision()
+ *	Returns revision string of the board.
+ */
+const char *board_get_revision(void)
+{
+	if (!bn) {
+		return "NULL";
+	}
+
+	return bn->revision;
+}
+
+/*
+ * board_init
+ */
+void __init board_init(void)
+{
+	bn = (struct boardnode *)devtree_find_node("board");
+	if (!bn) {
+		printk(KERN_WARNING "board node not found\n");
+		return;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/mach-common/bootargs.c
@@ -0,0 +1,63 @@
+/*
+ * arch/ubicom32/mach-common/bootargs.c
+ *   Board init and support code.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/cpu.h>
+#include <asm/devtree.h>
+
+struct bootargsnode {
+	struct devtree_node dn;
+	const char cmdline[512];
+};
+
+static const struct bootargsnode *ban;
+
+/*
+ * bootargs_get_cmdline()
+ *	Returns kernel boot arguments set by the bootloader.
+ */
+const char *bootargs_get_cmdline(void)
+{
+	if (!ban) {
+		return "";
+	}
+
+	return ban->cmdline;
+}
+
+/*
+ * bootargs_init
+ */
+void __init bootargs_init(void)
+{
+	ban = (struct bootargsnode *)devtree_find_node("bootargs");
+	if (!ban) {
+		printk(KERN_WARNING "bootargs node not found\n");
+		return;
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/mach-common/cachectl.c
@@ -0,0 +1,125 @@
+/*
+ * arch/ubicom32/mach-common/cachectl.c
+ *   Architecture cache control support
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <asm/cachectl.h>
+
+/*
+ * The write queue flush procedure in mem_cache_control needs to make
+ * DCACHE_WRITE_QUEUE_LENGTH writes to DDR (not OCM). Here we reserve some
+ * memory for this operation.
+ * Allocate array of cache lines of least DCACHE_WRITE_QUEUE_LENGTH + 1 words in
+ * length rounded up to the nearest cache line.
+ */
+#define CACHE_WRITE_QUEUE_FLUSH_AREA_SIZE \
+	ALIGN(sizeof(int) * (DCACHE_WRITE_QUEUE_LENGTH + 1), CACHE_LINE_SIZE)
+
+static char cache_write_queue_flush_area[CACHE_WRITE_QUEUE_FLUSH_AREA_SIZE]
+	__attribute__((aligned(CACHE_LINE_SIZE)));
+
+/*
+ * ONE_CCR_ADDR_OP is a helper macro that executes a single CCR operation.
+ */
+#define ONE_CCR_ADDR_OP(cc, op_addr, op)				\
+	do {								\
+		asm volatile (						\
+		"	btst	"D(CCR_CTRL)"(%0), #"D(CCR_CTRL_VALID)"				\n\t" \
+		"	jmpne.f	.-4								\n\t" \
+		"	move.4	"D(CCR_ADDR)"(%0), %1						\n\t" \
+		"	move.1	"D(CCR_CTRL+3)"(%0), %2						\n\t" \
+		"	bset	"D(CCR_CTRL)"(%0), "D(CCR_CTRL)"(%0), #"D(CCR_CTRL_VALID)"	\n\t" \
+		"	cycles	2								\n\t" \
+		"	btst	"D(CCR_CTRL)"(%0), #"D(CCR_CTRL_DONE)"				\n\t" \
+		"	jmpeq.f	.-4								\n\t" \
+			:						\
+			: "a"(cc), "r"(op_addr), "r"(op & 0xff)		\
+			: "cc"						\
+		);							\
+	} while (0)
+
+/*
+ * mem_cache_control()
+ *	Special cache control operation
+ */
+void mem_cache_control(unsigned long cc, unsigned long begin_addr,
+		       unsigned long end_addr, unsigned long op)
+{
+	unsigned long op_addr;
+
+	if (cc == DCCR_BASE && op == CCR_CTRL_FLUSH_ADDR) {
+		/*
+		 * We ensure all previous writes have left the data cache write
+		 * queue by sending DCACHE_WRITE_QUEUE_LENGTH writes (to
+		 * different words) down the queue.  If this is not done it's
+		 * possible that the data we are trying to flush hasn't even
+		 * entered the data cache.
+		 * The +1 ensure that the final 'flush' is actually a flush.
+		 */
+		int *flush_area = (int *)cache_write_queue_flush_area;
+		asm volatile(
+			"	.rept "D(DCACHE_WRITE_QUEUE_LENGTH + 1)"	\n\t"
+			"	move.4 (%0)4++, d0				\n\t"
+			"	.endr						\n\t"
+			: "+a"(flush_area)
+			);
+	}
+
+	/*
+	 * Calculate the cache lines we need to operate on that include
+	 * begin_addr though end_addr.
+	 */
+	begin_addr = begin_addr & ~(CACHE_LINE_SIZE - 1);
+	end_addr = (end_addr + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1);
+	op_addr = begin_addr;
+
+	do {
+		ONE_CCR_ADDR_OP(cc, op_addr, op);
+		op_addr += CACHE_LINE_SIZE;
+	} while (likely(op_addr < end_addr));
+
+	if (cc == DCCR_BASE && op == CCR_CTRL_FLUSH_ADDR) {
+		/*
+		 * It turns out that when flushing the data cache the last flush
+		 * isn't actually complete at this point. This is because there
+		 * is another write buffer on the DDR side of the cache that is
+		 * arbitrated with the I-Cache.
+		 *
+		 * The only foolproof method that ensures that the last data
+		 * cache flush *actually* completed is to do another flush on a
+		 * dirty cache line. This flush will block until the DDR write
+		 * buffer is empty.
+		 *
+		 * Rather than creating a another dirty cache line, we use the
+		 * flush_area above as we know that it is dirty from previous
+		 * writes.
+		 */
+		ONE_CCR_ADDR_OP(cc, cache_write_queue_flush_area, op);
+	}
+}
+EXPORT_SYMBOL(mem_cache_control);
--- /dev/null
+++ b/arch/ubicom32/mach-common/common.c
@@ -0,0 +1,64 @@
+/*
+ * arch/ubicom32/mach-common/common.c
+ *   Common platform support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/string.h>
+#include <linux/clk.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+
+/* Minimum CLK support */
+
+struct clk *clk_get(struct device *dev, const char *id)
+{
+	return ERR_PTR(-ENOENT);
+}
+EXPORT_SYMBOL(clk_get);
+
+void clk_put(struct clk *clk)
+{
+}
+EXPORT_SYMBOL(clk_put);
+
+int clk_enable(struct clk *clk)
+{
+	return 0;
+}
+EXPORT_SYMBOL(clk_enable);
+
+
+void clk_disable(struct clk *clk)
+{
+}
+EXPORT_SYMBOL(clk_disable);
--- /dev/null
+++ b/arch/ubicom32/mach-common/io.c
@@ -0,0 +1,250 @@
+/*
+ * arch/ubicom32/mach-common/io.c
+ *   PCI I/O memory read/write support functions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/io.h>
+
+#ifdef CONFIG_PCI
+unsigned char  ioread8(void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u8(addr);
+	else
+		return (unsigned char)(*(volatile unsigned char *)addr);
+}
+EXPORT_SYMBOL(ioread8);
+
+unsigned short  ioread16(void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u16(addr);
+	else
+		return (unsigned short)(*(volatile unsigned short *)addr);
+}
+EXPORT_SYMBOL(ioread16);
+
+unsigned int  ioread32(void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		return ubi32_pci_read_u32(addr);
+	else
+		return (unsigned int)(*(volatile unsigned int *)addr);
+}
+EXPORT_SYMBOL(ioread32);
+
+void iowrite32(unsigned int val, void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		ubi32_pci_write_u32(val, addr);
+	else
+		*(volatile unsigned int *)addr = val;
+}
+EXPORT_SYMBOL(iowrite32);
+
+void iowrite16(unsigned short val, void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		ubi32_pci_write_u16(val, addr);
+	else
+		*(volatile unsigned short *)addr = val;
+}
+EXPORT_SYMBOL(iowrite16);
+
+void iowrite8(unsigned char val, void __iomem *addr)
+{
+	if (IS_PCI_ADDRESS(addr))
+		ubi32_pci_write_u8(val, addr);
+	else
+		*(volatile unsigned char *)addr = val;
+}
+EXPORT_SYMBOL(iowrite8);
+
+void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned len)
+{
+	if (IS_PCI_ADDRESS(from)) {
+		if ((((u32_t)from & 0x3) == 0) && (((u32_t)to & 0x3) == 0)) {
+			while ((int)len >= 4) {
+				*(u32_t *)to = ubi32_pci_read_u32(from);
+				to += 4;
+				from += 4;
+				len -= 4;
+			}
+		} else if ((((u32_t)from & 0x1) == 0) &&
+			   (((u32_t)to & 0x1) == 0)) {
+			while ((int)len >= 2) {
+				 *(u16_t *)to = ubi32_pci_read_u16(from);
+				 to += 2;
+				 from += 2;
+				 len -= 2;
+			}
+		}
+
+		while (len) {
+			*(u8_t *)to = ubi32_pci_read_u8(from);
+			to++;
+			from++;
+			len--;
+		}
+	} else
+		memcpy(to, (void *)from, len);
+}
+EXPORT_SYMBOL(memcpy_fromio);
+
+void memcpy_toio(volatile void __iomem *to, const void *from, unsigned len)
+{
+	if (IS_PCI_ADDRESS(to)) {
+		if ((((u32_t)from & 0x3) == 0) && (((u32_t)to & 0x3) == 0)) {
+			while ((int)len >= 4) {
+				ubi32_pci_write_u32(*(u32_t *)from, to);
+				to += 4;
+				from += 4;
+				len -= 4;
+			}
+		} else if ((((u32_t)from & 0x1) == 0) &&
+			   (((u32_t)to & 0x1) == 0)) {
+			while ((int)len >= 2) {
+				ubi32_pci_write_u16(*(u16_t *)from, to);
+				to += 2;
+				from += 2;
+				len -= 2;
+			}
+		}
+
+		while (len) {
+			ubi32_pci_write_u8(*(u8_t *)from, to);
+			from++;
+			to++;
+			len--;
+		}
+	} else
+		memcpy((void *)to, from, len);
+
+}
+EXPORT_SYMBOL(memcpy_toio);
+
+void memset_io(volatile void __iomem *addr, int val, size_t len)
+{
+	if (IS_PCI_ADDRESS(addr)) {
+		while (len) {
+			ubi32_pci_write_u8((unsigned char)val, addr);
+			addr++;
+			len--;
+		}
+	} else
+		memset((void *)addr, val, len);
+
+}
+EXPORT_SYMBOL(memset_io);
+
+void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
+{
+	if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			*(u8_t *)buf = ioread8(port);
+			buf++;
+			count--;
+		}
+	} else {
+		insb((unsigned int)port, buf, count);
+	}
+
+}
+EXPORT_SYMBOL(ioread8_rep);
+
+void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
+{
+	if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			*(u16_t *)buf = ioread16(port);
+			buf += 2;
+			count--;
+		}
+	} else {
+		insw((unsigned int)port, buf, count);
+	}
+}
+EXPORT_SYMBOL(ioread16_rep);
+
+void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
+{
+	 if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			*(u32_t *)buf = ioread32(port);
+			buf += 4;
+			count--;
+		}
+	} else {
+		insl((unsigned int)port, buf, count);
+	}
+}
+EXPORT_SYMBOL(ioread32_rep);
+
+void  iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
+{
+	  if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			iowrite8(*(u8_t *)buf, port);
+			buf++;
+			count--;
+		}
+	} else {
+		outsb((unsigned int)port, buf, count);
+	}
+
+}
+EXPORT_SYMBOL(iowrite8_rep);
+
+void  iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
+{
+	if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			iowrite16(*(u16_t *)buf, port);
+			buf += 2;
+			count--;
+		}
+	} else {
+		outsw((unsigned int)port, buf, count);
+	}
+}
+EXPORT_SYMBOL(iowrite16_rep);
+
+void  iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
+{
+	if (IS_PCI_ADDRESS(port)) {
+		while (count) {
+			iowrite32(*(u32_t *)buf, port);
+			buf += 4;
+			count--;
+		}
+	} else {
+		outsl((unsigned int)port, buf, count);
+	}
+}
+EXPORT_SYMBOL(iowrite32_rep);
+
+#endif /* CONFIG_PCI */
--- /dev/null
+++ b/arch/ubicom32/mach-common/Makefile
@@ -0,0 +1,38 @@
+#
+# arch/ubicom32/mach-common/Makefile
+#	Makefile for Ubicom32 generic drivers/code.
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+obj-y += cachectl.o common.o usb_tio.o usb.o ubi32-gpio.o board.o bootargs.o
+obj-$(CONFIG_PCI) += pci.o io.o
+
+obj-$(CONFIG_FB_UBICOM32) += vdc_tio.o
+obj-$(CONFIG_UBICOM_HID) += ubicom32hid.o
+obj-$(CONFIG_UBICOM_INPUT) += ubicom32input.o
+obj-$(CONFIG_UBICOM_INPUT_I2C) += ubicom32input_i2c.o
+obj-$(CONFIG_UIO_UBICOM32RING) += ring_tio.o
+obj-$(CONFIG_SND_UBI32) += audio_tio.o
+
--- /dev/null
+++ b/arch/ubicom32/mach-common/pci.c
@@ -0,0 +1,1157 @@
+/*
+ * arch/ubicom32/mach-common/pci.c
+ *	PCI interface management.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
+
+#include <asm/devtree.h>
+#include <asm/ip5000.h>
+#include <asm/ubicom32-common.h>
+
+static int debug_pci = 1 ;
+
+/* #define PCI_USE_INTERNAL_LOCK 1 */
+
+#ifdef PCI_USE_INTERNAL_LOCK
+#define PCI_LOCK(lock, irqflag)	pci_lock_acquire(irqflag)
+#define PCI_UNLOCK(lock, irqflag) pci_lock_release(irqflag)
+#elif defined(CONFIG_SMP)
+static DEFINE_SPINLOCK(pci_master_lock);
+#define PCI_LOCK(lock, irqflag)	spin_lock_irqsave(lock, irqflag)
+#define PCI_UNLOCK(lock, irqflag) spin_unlock_irqrestore(lock, irqflag)
+#else
+#define PCI_LOCK(lock, irqflag)		local_irq_save(irqflag)
+#define PCI_UNLOCK(lock, irqflag)	local_irq_restore(irqflag)
+#endif
+
+#define PCI_DEV0_IDSEL CONFIG_PCI_DEV0_IDSEL
+#define PCI_DEV1_IDSEL CONFIG_PCI_DEV1_IDSEL
+
+/*
+ * PCI commands
+ */
+#define PCI_CMD_INT_ACK		0x00	/* not supported */
+#define PCI_CMD_SPECIAL		0x01	/* not supported */
+#define PCI_CMD_IO_READ		0x02
+#define PCI_CMD_IO_WRITE	0x03
+#define PCI_CMD_MEM_READ	0x06
+#define PCI_CMD_MEM_WRITE	0x07
+#define PCI_CMD_CFG_READ	0x0a
+#define PCI_CMD_CFG_WRITE	0x0b
+#define PCI_CMD_MEM_READ_MULT	0x0c	/* not supported */
+#define PCI_CMD_DUAL_ADDR	0x0d	/* not supported */
+#define PCI_CMD_MEM_READ_LINE	0x0e	/* not supported */
+#define PCI_CMD_MEM_WRITE_INVAL	0x0f	/* not supported */
+/*
+ * Status codes, returned by pci_read_u32() and pci_write_u32()
+ */
+#define PCI_RESP_IN_PROGRESS	0xff  /* request still in queue */
+#define PCI_RESP_OK		0
+/*
+ * The following codes indicate that the request has completed
+ */
+#define PCI_RESP_NO_DEVSEL		1  /* timeout before target asserted
+					    * DEVSEL! */
+#define PCI_RESP_LOST_DEVSEL		2  /* had DEVSEL, but went away before
+					    * transfer completed! */
+#define PCI_RESP_BAD_TRDY		3  /* target asserted TRDY without
+					    * DEVSEL! */
+#define PCI_RESP_NO_TRDY		4  /* timeout before target asserted
+					    * TRDY! */
+#define PCI_RESP_BAD_STOP		5  /* target asserted STOP and TRDY
+					    * without DEVSEL! */
+#define PCI_RESP_TARGET_ABORT		6
+#define PCI_RESP_TARGET_RETRY		7
+#define	PCI_RESP_TARGET_DISCONNECT	8
+#define PCI_RESP_MISMATCH		9  /* data read back doesn't match data
+					    * written - debug only, the core PCI
+					    * routines never return this */
+#define PCI_RESP_DET_SERR		10
+#define PCI_RESP_DET_PERR		11
+#define PCI_RESP_MALFORMED_REQ		12 /* Could be due to misaligned
+					    * requests or invalid address */
+#define PCI_RESP_NO_RESOURCE		13 /* Could be memory or other resourse
+					    * like queue space */
+#define PCI_RESP_ERROR			14 /* All emcompassing error */
+
+/* registers in PCI config space */
+#define PCI_DEVICE_VENDOR_ID_REG	0x00
+#define PCI_STATUS_COMMAND_REG		0x04
+#define PCI_CLASS_REVISION_REG		0x08
+#define PCI_BHLC_REG			0x0c  /* BIST, Header type, Latency
+					       * timer, Cache line size */
+#define PCI_BASE_ADDR_REG		0x10
+#define PCI_BASE_REG_COUNT		6
+#define CARDBUS_CIS_PTR_REG		0x28
+#define PCI_SUB_SYSTEM_ID_REG		0x2c
+#define PCI_EXP_ROM_ADDR_REG		0x30
+#define PCI_CAP_PTR_REG			0x34
+#define PCI_LGPL_REG			0x3C  /* max Latency, min Gnt, interrupt
+					       * Pin, interrupt Line */
+
+struct pci_master_request {
+	volatile u32_t pci_address;	/* must be 4-byte aligned */
+	volatile u32_t data;		/* must be 4-byte aligned */
+	volatile u8_t cmd;
+	volatile u8_t byte_valid;
+	volatile u8_t status;
+};
+
+struct pci_devnode {
+	struct devtree_node dn;
+	u32_t pci_idsel_0;
+	u32_t pci_idsel_1;
+	u32_t pci_cpu_address;
+	struct pci_master_request volatile *volatile req;
+};
+
+static struct pci_master_request req;	/* globally used for faster master write
+					 * (discarding result when possible) */
+static struct pci_devnode *pci_node;
+
+#if !defined(CONFIG_DEBUG_PCIMEASURE)
+#define PCI_DECLARE_MEASUREMENT
+#define PCI_MEASUREMENT_START()
+#define PCI_MEASUREMENT_END(idx)
+#else
+#define PCI_DECLARE_MEASUREMENT \
+	int __diff;		\
+	unsigned int __tstart;
+
+#define PCI_MEASUREMENT_START() \
+	__tstart = UBICOM32_IO_TIMER->sysval;
+
+#define PCI_MEASUREMENT_END(idx) \
+	__diff = (int)UBICOM32_IO_TIMER->sysval - (int)__tstart; \
+	pci_measurement_update((idx), __diff);
+
+#define PCI_WEIGHT 32
+
+struct pci_measurement {
+	volatile unsigned int min;
+	volatile unsigned int avg;
+	volatile unsigned int max;
+};
+
+enum pci_measurement_list {
+	PCI_MEASUREMENT_READ32,
+	PCI_MEASUREMENT_WRITE32,
+	PCI_MEASUREMENT_READ16,
+	PCI_MEASUREMENT_WRITE16,
+	PCI_MEASUREMENT_READ8,
+	PCI_MEASUREMENT_WRITE8,
+	PCI_MEASUREMENT_LAST,
+};
+
+static const char *pci_measurement_name_list[PCI_MEASUREMENT_LAST] = {
+	"READ32",
+	"WRITE32",
+	"READ16",
+	"WRITE16",
+	"READ8",
+	"WRITE8"
+};
+static struct pci_measurement pci_measurements[PCI_MEASUREMENT_LAST];
+
+/*
+ * pci_measurement_update()
+ *	Update an entry in the measurement array for this idx.
+ */
+static void pci_measurement_update(int idx, int sample)
+{
+	struct pci_measurement *pm = &pci_measurements[idx];
+	if ((pm->min == 0) || (pm->min > sample)) {
+		pm->min = sample;
+	}
+	if (pm->max < sample) {
+		pm->max = sample;
+	}
+	pm->avg = ((pm->avg * (PCI_WEIGHT - 1)) + sample) / PCI_WEIGHT;
+}
+#endif
+
+#if defined(PCI_USE_INTERNAL_LOCK)
+/*
+ * pci_lock_release()
+ *	Release the PCI lock.
+ */
+static void pci_lock_release(unsigned long irqflag)
+{
+	UBICOM32_UNLOCK(PCI_LOCK_BIT);
+}
+
+/*
+ * pci_lock_acquire()
+ *	Acquire the PCI lock, spin if not available.
+ */
+static void pci_lock_acquire(unsigned long irqflag)
+{
+	UBICOM32_LOCK(PCI_LOCK_BIT);
+}
+#endif
+
+/*
+ * pci_set_hrt_interrupt()
+ */
+static inline void pci_set_hrt_interrupt(struct pci_devnode *pci_node)
+{
+	ubicom32_set_interrupt(pci_node->dn.sendirq);
+}
+
+/*
+ * pci_read_u32()
+ *	Synchronously read 32 bits from PCI space.
+ */
+u8 pci_read_u32(u8 pci_cmd, u32 address, u32 *data)
+{
+	u8 status;
+	unsigned long irqflag;
+
+
+	/*
+	 * Fill in the request.
+	 */
+	volatile struct pci_master_request lreq;
+	PCI_DECLARE_MEASUREMENT;
+
+	lreq.pci_address = address;
+	lreq.cmd = pci_cmd;
+	lreq.byte_valid = 0xf;		/* enable all bytes */
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	pci_node->req = &lreq;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+
+	/*
+	 * Wait for the result to show up.
+	 */
+	while (unlikely(pci_node->req == &lreq))
+		;
+	status = lreq.status;
+	if (likely(status == PCI_RESP_OK))
+		*data = le32_to_cpu(lreq.data);
+	else
+		*data = 0;
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_READ32);
+	return status;
+}
+
+/*
+ * pci_write_u32()
+ *	Asyncrhnously or synchronously write 32 bits to PCI master space.
+ */
+u8 pci_write_u32(u8 pci_cmd, u32 address, u32 data)
+{
+	unsigned long irqflag;
+	PCI_DECLARE_MEASUREMENT;
+
+	/*
+	 * Wait for any previous write or pending read to complete.
+	 *
+	 * We use a global data block because once we write the request
+	 * we do not wait for it to complete before exiting.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	req.pci_address = address;
+	req.data = cpu_to_le32(data);
+	req.cmd = pci_cmd;
+	req.byte_valid = 0xf;		/* enable all bytes */
+	pci_node->req = &req;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_WRITE32);
+	return PCI_RESP_OK;
+}
+
+/*
+ * pci_read_u16()
+ *	Synchronously read 16 bits from PCI space.
+ */
+u8 pci_read_u16(u8 pci_cmd, u32 address, u16 *data)
+{
+	u8 status;
+	unsigned long irqflag;
+
+	/*
+	 * Fill in the request.
+	 */
+	volatile struct pci_master_request lreq;
+	PCI_DECLARE_MEASUREMENT;
+
+	lreq.pci_address = address & ~2;
+	lreq.cmd = pci_cmd;
+	lreq.byte_valid = (address & 2) ? 0xc : 0x3;
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	pci_node->req = &lreq;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+
+	/*
+	 * Wait for the result to show up.
+	 */
+	while (unlikely(pci_node->req == &lreq))
+		;
+	status = lreq.status;
+	if (likely(status == PCI_RESP_OK)) {
+		lreq.data = le32_to_cpu(lreq.data);
+		*data = (u16)((address & 2) ? (lreq.data >> 16) : lreq.data);
+	} else
+		*data = 0;
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_READ16);
+	return status;
+}
+
+/*
+ * pci_write_u16()
+ *	Asyncrhnously or synchronously write 16 bits to PCI master space.
+ */
+u8 pci_write_u16(u8 pci_cmd, u32 address, u16 data)
+{
+	unsigned long irqflag;
+	PCI_DECLARE_MEASUREMENT;
+
+	/*
+	 * Wait for any previous write or pending read to complete.
+	 *
+	 * We use a global data block because once we write the request
+	 * we do not wait for it to complete before exiting.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	req.pci_address = address & ~2;
+	req.data = (u32)data;
+	req.data = cpu_to_le32((address & 2) ? (req.data << 16) : req.data);
+	req.cmd = pci_cmd;
+	req.byte_valid = (address & 2) ? 0xc : 0x3;
+	pci_node->req = &req;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_WRITE16);
+	return PCI_RESP_OK;
+}
+
+/*
+ * pci_read_u8()
+ *	Synchronously read 8 bits from PCI space.
+ */
+u8 pci_read_u8(u8 pci_cmd, u32 address, u8 *data)
+{
+	u8 status;
+	unsigned long irqflag;
+
+	/*
+	 * Fill in the request.
+	 */
+	volatile struct pci_master_request lreq;
+	PCI_DECLARE_MEASUREMENT;
+
+	lreq.pci_address = address & ~3;
+	lreq.cmd = pci_cmd;
+	lreq.byte_valid = 1 << (address & 0x3);
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	pci_node->req = &lreq;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+
+	/*
+	 * Wait for the result to show up.
+	 */
+	while (unlikely(pci_node->req == &lreq))
+		;
+	status = lreq.status;
+	if (likely(status == PCI_RESP_OK)) {
+		*data = (u8)(lreq.data >> (24 - ((address & 0x3) << 3)));
+	} else
+		*data = 0;
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_READ8);
+	return status;
+}
+
+/*
+ * pci_write_u8()
+ *	Asyncrhnously or synchronously write 8 bits to PCI master space.
+ */
+u8 pci_write_u8(u8 pci_cmd, u32 address, u8 data)
+{
+	unsigned long irqflag;
+	PCI_DECLARE_MEASUREMENT;
+
+	/*
+	 * Wait for any previous write or pending read to complete.
+	 *
+	 * We use a global data block because once we write the request
+	 * we do not wait for it to complete before exiting.
+	 */
+	PCI_MEASUREMENT_START();
+	PCI_LOCK(&pci_master_lock, irqflag);
+	while (unlikely(pci_node->req == &req))
+		;
+	req.pci_address = address & ~3;
+	req.data = ((u32)data << (24 - ((address & 0x3) << 3)));
+	req.cmd = pci_cmd;
+	req.byte_valid = 1 << (address & 0x3);
+	pci_node->req = &req;
+	pci_set_hrt_interrupt(pci_node);
+	PCI_UNLOCK(&pci_master_lock, irqflag);
+	PCI_MEASUREMENT_END(PCI_MEASUREMENT_WRITE8);
+	return PCI_RESP_OK;
+}
+
+unsigned int ubi32_pci_read_u32(const volatile void __iomem *addr)
+{
+	unsigned int data;
+	pci_read_u32(PCI_CMD_MEM_READ, (u32)addr, &data);
+	return data;
+}
+EXPORT_SYMBOL(ubi32_pci_read_u32);
+
+unsigned short ubi32_pci_read_u16(const volatile void __iomem *addr)
+{
+	unsigned short data;
+	pci_read_u16(PCI_CMD_MEM_READ, (u32)addr, &data);
+	return data;
+}
+EXPORT_SYMBOL(ubi32_pci_read_u16);
+
+unsigned char  ubi32_pci_read_u8(const volatile void __iomem *addr)
+{
+	unsigned char  data;
+	pci_read_u8(PCI_CMD_MEM_READ, (u32)addr, &data);
+	return data;
+}
+EXPORT_SYMBOL(ubi32_pci_read_u8);
+
+void ubi32_pci_write_u32(unsigned int val, const volatile void __iomem *addr)
+{
+	pci_write_u32(PCI_CMD_MEM_WRITE, (u32)addr, val);
+}
+EXPORT_SYMBOL(ubi32_pci_write_u32);
+
+void ubi32_pci_write_u16(unsigned short val, const volatile void __iomem *addr)
+{
+	pci_write_u16(PCI_CMD_MEM_WRITE, (u32)addr, val);
+}
+EXPORT_SYMBOL(ubi32_pci_write_u16);
+
+void ubi32_pci_write_u8(unsigned char val, const void volatile __iomem *addr)
+{
+	pci_write_u8(PCI_CMD_MEM_WRITE, (u32)addr, val);
+}
+EXPORT_SYMBOL(ubi32_pci_write_u8);
+
+#if defined(CONFIG_DEBUG_PCIMEASURE)
+static unsigned int pci_cycles_to_nano(unsigned int cycles, unsigned int frequency)
+{
+	unsigned int nano = ((cycles * 1000) / (frequency / 1000000));
+	return nano;
+}
+
+/*
+ * pci_measurement_show()
+ *	Print out the min, avg, max values for each PCI transaction type.
+ *
+ * By request, the max value is reset after each dump.
+ */
+static int pci_measurement_show(struct seq_file *p, void *v)
+{
+	unsigned int min, avg, max;
+	unsigned int freq = processor_frequency();
+	int trans = *((loff_t *) v);
+
+	if (trans == 0) {
+		seq_puts(p, "min\tavg\tmax\t(nano-seconds)\n");
+	}
+
+	if (trans >= PCI_MEASUREMENT_LAST) {
+		return 0;
+	}
+
+	min = pci_cycles_to_nano(pci_measurements[trans].min, freq);
+	avg = pci_cycles_to_nano(pci_measurements[trans].avg, freq);
+	max = pci_cycles_to_nano(pci_measurements[trans].max, freq);
+	pci_measurements[trans].max = 0;
+	seq_printf(p, "%u\t%u\t%u\t%s\n", min, avg, max, pci_measurement_name_list[trans]);
+	return 0;
+}
+
+static void *pci_measurement_start(struct seq_file *f, loff_t *pos)
+{
+	return (*pos < PCI_MEASUREMENT_LAST) ? pos : NULL;
+}
+
+static void *pci_measurement_next(struct seq_file *f, void *v, loff_t *pos)
+{
+	(*pos)++;
+	if (*pos >= PCI_MEASUREMENT_LAST)
+		return NULL;
+	return pos;
+}
+
+static void pci_measurement_stop(struct seq_file *f, void *v)
+{
+	/* Nothing to do */
+}
+
+static const struct seq_operations pci_measurement_seq_ops = {
+	.start = pci_measurement_start,
+	.next  = pci_measurement_next,
+	.stop  = pci_measurement_stop,
+	.show  = pci_measurement_show,
+};
+
+static int pci_measurement_open(struct inode *inode, struct file *filp)
+{
+	return seq_open(filp, &pci_measurement_seq_ops);
+}
+
+static const struct file_operations pci_measurement_fops = {
+	.open		= pci_measurement_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
+static int __init pci_measurement_init(void)
+{
+	proc_create("pci_measurements", 0, NULL, &pci_measurement_fops);
+	return 0;
+}
+module_init(pci_measurement_init);
+#endif
+
+static int ubi32_pci_read_config(struct pci_bus *bus, unsigned int devfn,
+				 int where, int size, u32 *value)
+{
+	u8 cmd;
+	u32 addr;
+	u8  data8;
+	u16 data16;
+
+	u8 slot = PCI_SLOT(devfn);
+	u8 fn = PCI_FUNC(devfn);
+
+	if (slot > 1) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	} else if (slot == 0) {
+		addr = PCI_DEV0_IDSEL + where;
+	} else {
+		addr = PCI_DEV1_IDSEL + where;
+	}
+
+	addr += (fn << 8);
+
+	cmd = PCI_CMD_CFG_READ;
+	if (size == 1) {
+		pci_read_u8(cmd, addr, &data8);
+		*value = (u32)data8;
+	} else if (size == 2) {
+		pci_read_u16(cmd, addr, &data16);
+		*value = (u32)data16;
+	} else {
+		pci_read_u32(cmd, addr, value);
+	}
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static int ubi32_pci_write_config(struct pci_bus *bus, unsigned int devfn,
+				  int where, int size, u32 value)
+{
+	u8 cmd;
+	u32 addr;
+	u8 slot = PCI_SLOT(devfn);
+	u8 fn = PCI_FUNC(devfn);
+
+	if (slot > 1) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	} else if (slot == 0) {
+		addr = PCI_DEV0_IDSEL + where;
+	} else {
+		addr = PCI_DEV1_IDSEL + where;
+	}
+
+	addr += (fn << 8);
+
+	cmd = PCI_CMD_CFG_WRITE;
+	if (size == 1) {
+		pci_write_u8(cmd, addr, (u8)value);
+	} else if (size == 2) {
+		pci_write_u16(cmd, addr, (u16)value);
+	} else {
+		pci_write_u32(cmd, addr, value);
+	}
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size)
+{
+	return -EIO;
+}
+EXPORT_SYMBOL(pci_set_dma_max_seg_size);
+
+int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask)
+{
+	return -EIO;
+}
+EXPORT_SYMBOL(pci_set_dma_seg_boundary);
+
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	resource_size_t start = pci_resource_start(dev, bar);
+	resource_size_t len   = pci_resource_len(dev, bar);
+	unsigned long flags = pci_resource_flags(dev, bar);
+
+	if (!len || !start) {
+		return NULL;
+	}
+
+	if (maxlen && len > maxlen) {
+		len = maxlen;
+	}
+
+	if (flags & IORESOURCE_IO) {
+		return ioport_map(start, len);
+	}
+
+	if (flags & IORESOURCE_MEM) {
+		if (flags & IORESOURCE_CACHEABLE) {
+			return ioremap(start, len);
+		}
+		return ioremap_nocache(start, len);
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(pci_iomap);
+
+void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
+{
+	if ((unsigned long)addr >= VMALLOC_START &&
+	    (unsigned long)addr < VMALLOC_END) {
+		iounmap(addr);
+	}
+}
+EXPORT_SYMBOL(pci_iounmap);
+
+/*
+ *  From arch/arm/kernel/bios32.c
+ *
+ *  PCI bios-type initialisation for PCI machines
+ *
+ *  Bits taken from various places.
+ */
+static void __init pcibios_init_hw(struct hw_pci *hw)
+{
+	struct pci_sys_data *sys = NULL;
+	int ret;
+	int nr, busnr;
+
+	for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {
+		sys = kzalloc(sizeof(struct pci_sys_data), GFP_KERNEL);
+		if (!sys)
+			panic("PCI: unable to allocate sys data!");
+
+		sys->hw      = hw;
+		sys->busnr   = busnr;
+		sys->map_irq = hw->map_irq;
+		sys->resource[0] = &ioport_resource;
+		sys->resource[1] = &iomem_resource;
+
+		ret = hw->setup(nr, sys);
+
+		if (ret > 0) {
+			sys->bus = hw->scan(nr, sys);
+
+			if (!sys->bus)
+				panic("PCI: unable to scan bus!");
+
+			busnr = sys->bus->subordinate + 1;
+
+			list_add(&sys->node, &hw->buses);
+		} else {
+			kfree(sys);
+			if (ret < 0)
+				break;
+		}
+	}
+}
+
+/*
+ * Swizzle the device pin each time we cross a bridge.
+ * This might update pin and returns the slot number.
+ */
+static u8 __devinit pcibios_swizzle(struct pci_dev *dev, u8 *pin)
+{
+	struct pci_sys_data *sys = dev->sysdata;
+	int slot = 0, oldpin = *pin;
+
+	if (sys->swizzle)
+		slot = sys->swizzle(dev, pin);
+
+	if (debug_pci)
+		printk("PCI: %s swizzling pin %d => pin %d slot %d\n",
+			pci_name(dev), oldpin, *pin, slot);
+	return slot;
+}
+
+/*
+ * Map a slot/pin to an IRQ.
+ */
+static int pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+	struct pci_sys_data *sys = dev->sysdata;
+	int irq = -1;
+
+	if (sys->map_irq)
+		irq = sys->map_irq(dev, slot, pin);
+
+	if (debug_pci)
+		printk("PCI: %s mapping slot %d pin %d => irq %d\n",
+			pci_name(dev), slot, pin, irq);
+
+	return irq;
+}
+
+void __init pci_common_init(struct hw_pci *hw)
+{
+	struct pci_sys_data *sys;
+
+	INIT_LIST_HEAD(&hw->buses);
+
+	if (hw->preinit)
+		hw->preinit();
+	pcibios_init_hw(hw);
+	if (hw->postinit)
+		hw->postinit();
+
+	pci_fixup_irqs(pcibios_swizzle, pcibios_map_irq);
+	list_for_each_entry(sys, &hw->buses, node) {
+		struct pci_bus *bus = sys->bus;
+		/*
+		 * Size the bridge windows.
+		 */
+		pci_bus_size_bridges(bus);
+		/*
+		 * Assign resources.
+		 */
+		pci_bus_assign_resources(bus);
+
+		/*
+		 * Tell drivers about devices found.
+		 */
+		pci_bus_add_devices(bus);
+	}
+}
+
+char * __init pcibios_setup(char *str)
+{
+	if (!strcmp(str, "debug")) {
+		debug_pci = 1;
+		return NULL;
+	}
+	return str;
+}
+
+/*
+ * From arch/i386/kernel/pci-i386.c:
+ *
+ * We need to avoid collisions with `mirrored' VGA ports
+ * and other strange ISA hardware, so we always want the
+ * addresses to be allocated in the 0x000-0x0ff region
+ * modulo 0x400.
+ *
+ * Why? Because some silly external IO cards only decode
+ * the low 10 bits of the IO address. The 0x00-0xff region
+ * is reserved for motherboard devices that decode all 16
+ * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
+ * but we want to try to avoid allocating at 0x2900-0x2bff
+ * which might be mirrored at 0x0100-0x03ff..
+ */
+void pcibios_align_resource(void *data, struct resource *res,
+			    resource_size_t size, resource_size_t align)
+{
+	resource_size_t start = res->start;
+
+	if (res->flags & IORESOURCE_IO && start & 0x300)
+		start = (start + 0x3ff) & ~0x3ff;
+
+	res->start = (start + align - 1) & ~(align - 1);
+}
+
+
+void __devinit pcibios_update_irq(struct pci_dev *dev, int irq)
+{
+	if (debug_pci)
+		printk("PCI: Assigning IRQ %02d to %s\n", irq, pci_name(dev));
+	pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
+}
+
+/*
+ * If the bus contains any of these devices, then we must not turn on
+ * parity checking of any kind.  Currently this is CyberPro 20x0 only.
+ */
+static inline int pdev_bad_for_parity(struct pci_dev *dev)
+{
+	return (dev->vendor == PCI_VENDOR_ID_INTERG &&
+		(dev->device == PCI_DEVICE_ID_INTERG_2000 ||
+		 dev->device == PCI_DEVICE_ID_INTERG_2010)) ||
+		(dev->vendor == PCI_VENDOR_ID_ITE &&
+		 dev->device == PCI_DEVICE_ID_ITE_8152);
+
+}
+
+/*
+ * Adjust the device resources from bus-centric to Linux-centric.
+ */
+static void __devinit
+pdev_fixup_device_resources(struct pci_sys_data *root, struct pci_dev *dev)
+{
+	resource_size_t offset;
+	int i;
+
+	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+		if (dev->resource[i].start == 0)
+			continue;
+		if (dev->resource[i].flags & IORESOURCE_MEM)
+			offset = root->mem_offset;
+		else
+			offset = root->io_offset;
+
+		dev->resource[i].start += offset;
+		dev->resource[i].end   += offset;
+	}
+}
+
+static void __devinit
+pbus_assign_bus_resources(struct pci_bus *bus, struct pci_sys_data *root)
+{
+	struct pci_dev *dev = bus->self;
+	int i;
+
+	if (!dev) {
+		/*
+		 * Assign root bus resources.
+		 */
+		for (i = 0; i < 3; i++)
+			bus->resource[i] = root->resource[i];
+	}
+}
+
+/*
+ * pcibios_fixup_bus - Called after each bus is probed,
+ * but before its children are examined.
+ */
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+	struct pci_sys_data *root = bus->sysdata;
+	struct pci_dev *dev;
+	u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
+		PCI_COMMAND_FAST_BACK;
+
+	pbus_assign_bus_resources(bus, root);
+
+	/*
+	 * Walk the devices on this bus, working out what we can
+	 * and can't support.
+	 */
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		u16 status;
+
+		pdev_fixup_device_resources(root, dev);
+
+		pci_read_config_word(dev, PCI_STATUS, &status);
+
+		/*
+		 * If any device on this bus does not support fast back
+		 * to back transfers, then the bus as a whole is not able
+		 * to support them.  Having fast back to back transfers
+		 * on saves us one PCI cycle per transaction.
+		 */
+		if (!(status & PCI_STATUS_FAST_BACK))
+			features &= ~PCI_COMMAND_FAST_BACK;
+
+		if (pdev_bad_for_parity(dev))
+			features &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
+
+		switch (dev->class >> 8) {
+		case PCI_CLASS_BRIDGE_PCI:
+			pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &status);
+			status |= PCI_BRIDGE_CTL_PARITY |
+				PCI_BRIDGE_CTL_MASTER_ABORT;
+			status &= ~(PCI_BRIDGE_CTL_BUS_RESET |
+				    PCI_BRIDGE_CTL_FAST_BACK);
+			pci_write_config_word(dev, PCI_BRIDGE_CONTROL, status);
+			break;
+
+		case PCI_CLASS_BRIDGE_CARDBUS:
+			pci_read_config_word(dev, PCI_CB_BRIDGE_CONTROL,
+					     &status);
+			status |= PCI_CB_BRIDGE_CTL_PARITY |
+				PCI_CB_BRIDGE_CTL_MASTER_ABORT;
+			pci_write_config_word(dev, PCI_CB_BRIDGE_CONTROL,
+					      status);
+			break;
+		}
+	}
+
+	/*
+	 * Now walk the devices again, this time setting them up.
+	 */
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		u16 cmd;
+
+		pci_read_config_word(dev, PCI_COMMAND, &cmd);
+		cmd |= features;
+		pci_write_config_word(dev, PCI_COMMAND, cmd);
+
+		pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
+				      L1_CACHE_BYTES >> 2);
+	}
+
+	/*
+	 * Propagate the flags to the PCI bridge.
+	 */
+	if (bus->self && bus->self->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+		if (features & PCI_COMMAND_FAST_BACK)
+			bus->bridge_ctl |= PCI_BRIDGE_CTL_FAST_BACK;
+		if (features & PCI_COMMAND_PARITY)
+			bus->bridge_ctl |= PCI_BRIDGE_CTL_PARITY;
+	}
+
+	/*
+	 * Report what we did for this bus
+	 */
+	printk(KERN_INFO "PCI: bus%d: Fast back to back transfers %sabled\n",
+		bus->number, (features & PCI_COMMAND_FAST_BACK) ? "en" : "dis");
+}
+/*
+ * Convert from Linux-centric to bus-centric addresses for bridge devices.
+ */
+void
+pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+			 struct resource *res)
+{
+	struct pci_sys_data *root = dev->sysdata;
+	unsigned long offset = 0;
+
+	if (res->flags & IORESOURCE_IO)
+		offset = root->io_offset;
+	if (res->flags & IORESOURCE_MEM)
+		offset = root->mem_offset;
+
+	region->start = res->start - offset;
+	region->end   = res->end - offset;
+}
+
+void __devinit
+pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+			struct pci_bus_region *region)
+{
+	struct pci_sys_data *root = dev->sysdata;
+	unsigned long offset = 0;
+
+	if (res->flags & IORESOURCE_IO)
+		offset = root->io_offset;
+	if (res->flags & IORESOURCE_MEM)
+		offset = root->mem_offset;
+
+	res->start = region->start + offset;
+	res->end   = region->end + offset;
+}
+
+#ifdef CONFIG_HOTPLUG
+EXPORT_SYMBOL(pcibios_fixup_bus);
+EXPORT_SYMBOL(pcibios_resource_to_bus);
+EXPORT_SYMBOL(pcibios_bus_to_resource);
+#endif
+
+/**
+ * pcibios_enable_device - Enable I/O and memory.
+ * @dev: PCI device to be enabled
+ */
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	u16 cmd, old_cmd;
+	int idx;
+	struct resource *r;
+
+	pci_read_config_word(dev, PCI_COMMAND, &cmd);
+	old_cmd = cmd;
+	for (idx = 0; idx < 6; idx++) {
+		/* Only set up the requested stuff */
+		if (!(mask & (1 << idx)))
+			continue;
+
+		r = dev->resource + idx;
+		if (!r->start && r->end) {
+			printk(KERN_ERR "PCI: Device %s not available because"
+			       " of resource collisions\n", pci_name(dev));
+			return -EINVAL;
+		}
+		if (r->flags & IORESOURCE_IO)
+			cmd |= PCI_COMMAND_IO;
+		if (r->flags & IORESOURCE_MEM)
+			cmd |= PCI_COMMAND_MEMORY;
+	}
+
+	/*
+	 * Bridges (eg, cardbus bridges) need to be fully enabled
+	 */
+	if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
+		cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
+
+	if (cmd != old_cmd) {
+		printk("PCI: enabling device %s (%04x -> %04x)\n",
+		       pci_name(dev), old_cmd, cmd);
+		pci_write_config_word(dev, PCI_COMMAND, cmd);
+	}
+	return 0;
+}
+
+
+struct pci_ops ubi32_pci_ops = {
+	.read   = ubi32_pci_read_config,
+	.write  = ubi32_pci_write_config,
+};
+
+static struct pci_bus *ubi32_pci_scan_bus(int nr, struct pci_sys_data *sys)
+{
+	return pci_scan_bus(sys->busnr, &ubi32_pci_ops, sys);
+}
+
+#define UBI32_PCI_MEM_BASE PCI_DEV_REG_BASE
+#define UBI32_PCI_MEM_LEN  0x80000000
+
+#define UBI32_PCI_IO_BASE 0x0
+#define UBI32_PCI_IO_END  0x0
+
+static struct resource ubi32_pci_mem = {
+	.name	= "PCI memory space",
+	.start	= UBI32_PCI_MEM_BASE,
+	.end	= UBI32_PCI_MEM_BASE + UBI32_PCI_MEM_LEN - 1,
+	.flags	= IORESOURCE_MEM,
+};
+
+static struct resource ubi32_pci_io = {
+	.name	= "PCI IO space",
+	.start	= UBI32_PCI_IO_BASE,
+	.end	= UBI32_PCI_IO_END,
+	.flags	= IORESOURCE_IO,
+};
+
+static int __init ubi32_pci_setup(int nr, struct pci_sys_data *sys)
+{
+	if (nr > 0)
+		return 0;
+
+	request_resource(&iomem_resource, &ubi32_pci_mem);
+	request_resource(&ioport_resource, &ubi32_pci_io);
+
+	sys->resource[0] = &ubi32_pci_io;
+	sys->resource[1] = &ubi32_pci_mem;
+	sys->resource[2] = NULL;
+
+	return 1;
+}
+
+static void __init ubi32_pci_preinit(void)
+{
+}
+
+static int __init ubi32_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+	return pci_node->dn.recvirq;
+}
+
+struct hw_pci ubi32_pci __initdata = {
+	.nr_controllers	= 1,
+	.preinit	= ubi32_pci_preinit,
+	.setup		= ubi32_pci_setup,
+	.scan		= ubi32_pci_scan_bus,
+	.map_irq	= ubi32_pci_map_irq,
+};
+
+static int __init ubi32_pci_init(void)
+{
+	pci_node = (struct pci_devnode *)devtree_find_node("pci");
+	if (pci_node == NULL) {
+		printk(KERN_WARNING "PCI init failed\n");
+		return -ENOSYS;
+	}
+	pci_common_init(&ubi32_pci);
+	return 0;
+}
+
+subsys_initcall(ubi32_pci_init);
+
+/*
+ * workaround for dual PCI card interrupt
+ */
+#define PCI_COMMON_INT_BIT (1 << 19)
+void ubi32_pci_int_wr(void)
+{
+	volatile unsigned int pci_int_line;
+	pci_int_line = UBICOM32_IO_PORT(RB)->gpio_in;
+	if (!(pci_int_line & PCI_COMMON_INT_BIT))
+	{
+		ubicom32_set_interrupt(pci_node->dn.recvirq);
+	}
+}
+EXPORT_SYMBOL(ubi32_pci_int_wr);
--- /dev/null
+++ b/arch/ubicom32/mach-common/ring_tio.c
@@ -0,0 +1,123 @@
+/*
+ * arch/ubicom32/mach-common/ring_tio.c
+ *   Generic initialization for UIO Ubicom32 Ring
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#include <asm/devtree.h>
+#include <asm/ring_tio.h>
+
+static const char *ring_tio_driver_name = "uio_ubicom32ring";
+
+/*
+ * The number of ring_tio's currently allocated, used for .id
+ */
+static int __initdata ring_tio_count;
+
+/*
+ * The maximum number of resources that the ring_tio will have.
+ * Currently 3, a register space, and up to 2 interrupts.
+ */
+#define RING_TIO_MAX_RESOURCES	3
+
+/*
+ * ring_tio_init
+ *	Checks the device tree and instantiates the driver if found
+ */
+void __init ring_tio_init(const char *node_name)
+{
+	struct platform_device *pdev;
+	struct resource *res;
+	int resource_idx = 0;
+	struct ring_tio_node *ring_node;
+
+	/*
+	 * Check the device tree for the ring_tio
+	 */
+	ring_node = (struct ring_tio_node *)devtree_find_node(node_name);
+	if (!ring_node) {
+		printk(KERN_WARNING "Ring TIO '%s' not found\n", node_name);
+		return;
+	}
+
+	if (ring_node->version != RING_TIO_NODE_VERSION) {
+		printk(KERN_WARNING "ring_tio not compatible\n");
+		return;
+	}
+
+	/*
+	 * Dynamically create the platform_device structure and resources
+	 */
+	pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
+	if (!pdev) {
+		printk(KERN_WARNING "ring_tio could not alloc pdev\n");
+		return;
+	}
+
+	res = kzalloc(sizeof(struct resource) * RING_TIO_MAX_RESOURCES,
+			GFP_KERNEL);
+	if (!res) {
+		kfree(pdev);
+		printk(KERN_WARNING "ring_tio could not alloc res\n");
+		return;
+	}
+
+	pdev->name = ring_tio_driver_name;
+	pdev->id = ring_tio_count++;
+	pdev->resource = res;
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	res[resource_idx].start = (u32_t)(ring_node->regs);
+	res[resource_idx].end = (u32_t)(ring_node->regs);
+	res[resource_idx].flags = IORESOURCE_MEM;
+	resource_idx++;
+
+	if (ring_node->dn.sendirq != 0xFF) {
+		res[resource_idx].start = ring_node->dn.sendirq;
+		res[resource_idx].flags = IORESOURCE_IRQ;
+		resource_idx++;
+	}
+
+	if (ring_node->dn.recvirq != 0xFF) {
+		res[resource_idx].start = ring_node->dn.recvirq;
+		res[resource_idx].flags = IORESOURCE_IRQ;
+		resource_idx++;
+	}
+	pdev->num_resources = resource_idx;
+
+	printk(KERN_INFO "RingTIO.%d '%s' found irq=%d/%d regs=%p pdev=%p/%p\n",
+		ring_tio_count - 1, node_name, ring_node->dn.sendirq,
+		ring_node->dn.recvirq, ring_node->regs, pdev, res);
+
+	/*
+	 * Try to get the device registered
+	 */
+	pdev->dev.platform_data = (void *)node_name;
+	if (platform_device_register(pdev) < 0) {
+		printk(KERN_WARNING "Ring failed to register\n");
+		kfree(pdev);
+		kfree(res);
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/mach-common/ubi32-gpio.c
@@ -0,0 +1,411 @@
+/*
+ * arch/ubicom32/mach-common/ubi32-gpio.c
+ *   Ubicom gpio driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+#include <linux/version.h>
+
+#if defined(CONFIG_PROC_FS)
+#include <linux/proc_fs.h>
+#endif
+
+#include <linux/io.h>
+#include <asm/ip5000.h>
+#include <linux/gpio.h>
+
+#define UBI_GPIO_CHECK_RANGE     0  /* !0 enables range checking */
+
+
+/*
+ * Each I/O port can be configured to operate in one of several
+ * functional modes. One of these modes is GPIO, which causes the
+ * entire port to function as a GPIO port.  Since the various port
+ * registers serve the system with other important functions, such as
+ * ethernet, serial, USB, etc., it isn't advantageous to set any of
+ * the ports to be entirely dedicated for GPIO use.  The processor
+ * alternatively allows individual bits of a port to be assigned to be
+ * used as GPIO independently from the overall port function.  This
+ * bit-by-bit assignment is selected by setting the corresponding bit
+ * in the port's gpio_mask register.  When set, the selected bit is
+ * then enabled as a GPIO.  If the corresponding bit is set in the
+ * gpio_ctl register of the port, the bit is configured as a GPIO
+ * output.  Otherwise, it is an input.
+ *
+ * NOTE: This driver uses the bit-by-bit GPIO function assignment
+ * exclusively and *never* sets the port function registers to the
+ * GPIO function.
+ *
+ * GPIO is not the main function of any of the I/O ports.  The port
+ * bit widths are variable from one port to the next, determined by
+ * the more common I/O functions of the ports.  For simplicity, this
+ * driver assumes all the ports are 32 bits wide regardless of the
+ * real bit width of the port.  GPIO bits are numbered from zero to
+ * MAX_UBICOM_GPIOS.  Within a port, the least significant bit is
+ * numbered bit zero, the most significant is bit 31.  Since the ports
+ * are considered logically contiguous, GPIO #32 is the zeroth bit in
+ * port #1, and so on.  Due to the hardware definition, there are
+ * large gaps in the GPIO numbers representing real pins.
+ *
+ * NOTE: It is up to the programmer to refer to the processor data
+ * sheet to determine which bits in which ports can be accessed and
+ * used for GPIO.
+ *
+ */
+
+
+/* There are 9 ports, A through I. Not all 32 bits in each
+ * port can be a GPIO, but we pretend they are.  Its up to the
+ * programmer to refer to the processor data sheet.
+ */
+#define MAX_UBICOM_GPIOS   (9 * 32) /* ARCH_NR_GPIOS */
+#define NUM_GPIO_PORTS     (gpio_bank(MAX_UBICOM_GPIOS))
+
+
+/* GPIO reservation bit map array */
+static int reserved_gpio_map[NUM_GPIO_PORTS];
+
+
+/* Array of hardware io_port addresses */
+static struct ubicom32_io_port *gpio_bank_addr[NUM_GPIO_PORTS] =
+{
+	UBICOM32_IO_PORT(RA),
+	UBICOM32_IO_PORT(RB),
+	UBICOM32_IO_PORT(RC),
+	UBICOM32_IO_PORT(RD),
+	UBICOM32_IO_PORT(RE),
+	UBICOM32_IO_PORT(RF),
+	UBICOM32_IO_PORT(RG),
+	UBICOM32_IO_PORT(RH),
+	UBICOM32_IO_PORT(RI)
+};
+
+
+struct ubi_gpio_chip {
+	/*
+	 * Right now, nothing else lives here.
+	 */
+	struct gpio_chip gpio_chip;
+};
+
+
+#if UBI_GPIO_CHECK_RANGE
+inline int check_gpio(unsigned gpio)
+{
+	if (gpio >= MAX_UBICOM_GPIOS)
+		return -EINVAL;
+	return 0;
+}
+#else
+#define check_gpio(n)   (0)
+#endif
+
+/*
+ * ubi_gpio_get_port
+ *	Get the IO port associated with a certain gpio
+ */
+struct ubicom32_io_port *ubi_gpio_get_port(unsigned gpio)
+{
+	if (gpio_bank(gpio) > NUM_GPIO_PORTS) {
+		return NULL;
+	}
+	return gpio_bank_addr[gpio_bank(gpio)];
+}
+
+/*
+ * ubi_gpio_error()
+ */
+static void ubi_gpio_error(unsigned gpio)
+{
+	printk(KERN_ERR "ubicom-gpio: GPIO %d wasn't requested!\n", gpio);
+}
+
+/*
+ * ubi_port_setup()
+ */
+static void ubi_port_setup(unsigned gpio, unsigned short usage)
+{
+	if (!check_gpio(gpio)) {
+		if (usage) {
+			UBICOM32_GPIO_ENABLE(gpio);
+		} else {
+			UBICOM32_GPIO_DISABLE(gpio);
+		}
+	}
+}
+
+/*
+ * ubi_gpio_request()
+ */
+static int ubi_gpio_request(struct gpio_chip *chip, unsigned gpio)
+{
+	unsigned long flags;
+
+	if (check_gpio(gpio) < 0)
+		return -EINVAL;
+
+	local_irq_save(flags);
+
+	if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
+		printk(KERN_ERR "ubi-gpio: GPIO %d is already reserved!\n",
+		       gpio);
+		local_irq_restore(flags);
+		return -EBUSY;
+	}
+
+	reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
+
+	ubi_port_setup(gpio, 1);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
+/*
+ * ubi_gpio_free()
+ */
+static void ubi_gpio_free(struct gpio_chip *chip, unsigned gpio)
+{
+	unsigned long flags;
+
+	if (check_gpio(gpio) < 0)
+		return;
+
+	local_irq_save(flags);
+
+	if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
+		ubi_gpio_error(gpio);
+		local_irq_restore(flags);
+		return;
+	}
+
+	/* Assert the pin is no longer claimed */
+	reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
+
+	/* Revert port bit to use specified by port->function */
+	ubi_port_setup(gpio, 0);
+
+	local_irq_restore(flags);
+}
+
+/*
+ * ubi_gpio_direction_input()
+ */
+static int ubi_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	unsigned long flags;
+
+	if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
+		ubi_gpio_error(gpio);
+		return -EINVAL;
+	}
+
+	local_irq_save(flags);
+
+	/* Configure pin as gpio */
+	ubi_port_setup(gpio, 1);
+
+	/* Assert pin is an input */
+	UBICOM32_GPIO_SET_PIN_INPUT(gpio);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
+
+/*
+ * ubi_gpio_direction_output()
+ */
+static int ubi_gpio_direction_output(struct gpio_chip *chip,
+				     unsigned gpio, int value)
+{
+	unsigned long flags;
+
+	if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
+		ubi_gpio_error(gpio);
+		return -EINVAL;
+	}
+
+	local_irq_save(flags);
+
+	/* Configure pin as gpio and set initial value in gpio_out register
+	 * so that when we enable it as an output, it will have the correct
+	 * initial value.
+	 */
+	ubi_port_setup(gpio, 1);
+	if (value) {
+		UBICOM32_GPIO_SET_PIN_HIGH(gpio);
+	} else {
+		UBICOM32_GPIO_SET_PIN_LOW(gpio);
+	}
+
+	/* Enable the pin as an output */
+	UBICOM32_GPIO_SET_PIN_OUTPUT(gpio);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
+
+/*
+ * ubi_gpio_get_value()
+ */
+static int ubi_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	return 0 != (gpio_bank_addr[gpio_bank(gpio)]->gpio_in & gpio_bit(gpio));
+}
+
+
+/*
+ * ubi_gpio_set_value()
+ */
+static void ubi_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
+			       int arg)
+{
+	unsigned long flags;
+	local_irq_save(flags);
+
+	if (arg) {
+		UBICOM32_GPIO_SET_PIN_HIGH(gpio);
+	} else {
+		UBICOM32_GPIO_SET_PIN_LOW(gpio);
+	}
+
+	local_irq_restore(flags);
+}
+
+
+/*
+ * ubi_gpio_to_irq()
+ */
+static int ubi_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
+{
+	return gpio_to_irq(gpio);
+}
+
+
+/*
+ * ubi_gpio_init()
+ */
+int __init ubi_gpio_init(void)
+{
+	int k;
+	int status;
+	struct ubi_gpio_chip *chip;
+	struct gpio_chip *gc;
+
+	printk(KERN_INFO "Ubicom GPIO Controller\n");
+
+	chip = kzalloc(sizeof(struct ubi_gpio_chip), GFP_KERNEL);
+	if (chip == NULL)
+		return -ENOMEM;
+
+	gc = &chip->gpio_chip;
+	gc->request          = ubi_gpio_request;
+	gc->free             = ubi_gpio_free;
+	gc->to_irq           = ubi_gpio_to_irq;
+	gc->direction_input  = ubi_gpio_direction_input;
+	gc->direction_output = ubi_gpio_direction_output;
+	gc->get              = ubi_gpio_get_value;
+	gc->set              = ubi_gpio_set_value;
+	gc->can_sleep        = 0;
+	gc->base             = 0;
+	gc->ngpio            = MAX_UBICOM_GPIOS; /* ARCH_NR_GPIOS - 1 */
+	gc->label            = "ubi_gpio";
+
+	status = gpiochip_add(gc);
+	if (status != 0) {
+		kfree(chip);
+		return status;
+	}
+
+	/* Assert all pins are free */
+	for (k = 0; k < NUM_GPIO_PORTS; k++) {
+		reserved_gpio_map[k] = 0;
+	}
+
+	return 0;
+}
+
+#if defined(CONFIG_PROC_FS)
+/*
+ * ubi_get_gpio_dir()
+ */
+static int ubi_get_gpio_dir(unsigned gpio)
+{
+	if (gpio_bank_addr[gpio_bank(gpio)]->gpio_ctl & gpio_bit(gpio))
+		return 1;
+	else
+		return 0;
+}
+
+/*
+ * gpio_proc_read()
+ */
+static int ubi_gpio_proc_read(char *buf, char **start, off_t offset,
+			  int len, int *unused_i, void *unused_v)
+{
+	int c, outlen = 0;
+
+	for (c = 0; c < MAX_UBICOM_GPIOS; c++) {
+		if (!check_gpio(c) &&
+		    (reserved_gpio_map[gpio_bank(c)] & gpio_bit(c))) {
+			len = sprintf(buf, "GPIO_%d:\t\tGPIO %s\n", c,
+				      ubi_get_gpio_dir(c) ? "OUTPUT" : "INPUT");
+		} else {
+			continue;
+		}
+
+		buf += len;
+		outlen += len;
+	}
+	return outlen;
+}
+
+/*
+ * ubi_gpio_register_proc()
+ */
+static __init int ubi_gpio_register_proc(void)
+{
+	struct proc_dir_entry *proc_gpio;
+
+	proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
+	if (proc_gpio)
+		proc_gpio->read_proc = ubi_gpio_proc_read;
+
+	return proc_gpio != NULL;
+}
+device_initcall(ubi_gpio_register_proc);
+#endif
--- /dev/null
+++ b/arch/ubicom32/mach-common/ubicom32hid.c
@@ -0,0 +1,557 @@
+/*
+ * arch/ubicom32/mach-common/ubicom32hid.c
+ *   I2C driver for HID coprocessor found on some DPF implementations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+#include <linux/input.h>
+#include <linux/input-polldev.h>
+
+#include <asm/ubicom32hid.h>
+
+#define DRIVER_NAME "ubicom32hid"
+
+#ifdef DEBUG
+static int ubicom32hid_debug;
+#endif
+
+static const struct i2c_device_id ubicom32hid_id[] = {
+	{ DRIVER_NAME, },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ubicom32hid_id);
+
+/*
+ * Define this to make IR checking strict, in general, it's not needed
+ */
+#undef UBICOM32HID_STRICT_IR_CHECK
+
+#define UBICOM32HID_CMD_SET_PWM		0x01
+#define UBICOM32HID_CMD_SET_BL_EN	0x02
+#define UBICOM32HID_BL_EN_LOW		0x00
+#define UBICOM32HID_BL_EN_HIZ		0x01
+#define UBICOM32HID_BL_EN_HI		0x02
+#define UBICOM32HID_CMD_FLUSH		0x99
+#define UBICOM32HID_CMD_RESET		0x99
+#define UBICOM32HID_CMD_GET_IR_SWITCH	0xC0
+#define UBICOM32HID_CMD_GET_REVISION	0xfd
+#define UBICOM32HID_CMD_GET_DEVICE_ID	0xfe
+#define UBICOM32HID_CMD_GET_VERSION	0xff
+#define UBICOM32HID_DEVICE_ID		0x49
+
+#define UBICOM32HID_MAX_BRIGHTNESS_PWM	255
+
+/*
+ * Data structure returned by the HID device
+ */
+struct ubicom32hid_input_data {
+	uint32_t	ircmd;
+	uint8_t		sw_state;
+	uint8_t		sw_changed;
+};
+
+/*
+ * Our private data
+ */
+struct ubicom32hid_data {
+	/*
+	 * Pointer to the platform data structure, we need the settings.
+	 */
+	const struct ubicom32hid_platform_data	*pdata;
+
+	/*
+	 * Backlight device
+	 */
+	struct backlight_device			*bldev;
+
+	/*
+	 * I2C client, for sending messages to the HID device
+	 */
+	struct i2c_client			*client;
+
+	/*
+	 * Current intensity, used for get_intensity.
+	 */
+	int					cur_intensity;
+
+	/*
+	 * Input subsystem
+	 *	We won't register an input subsystem if there are no mappings.
+	 */
+	struct input_polled_dev			*poll_dev;
+};
+
+
+/*
+ * ubicom32hid_set_intensity
+ */
+static int ubicom32hid_set_intensity(struct backlight_device *bd)
+{
+	struct ubicom32hid_data *ud =
+		(struct ubicom32hid_data *)bl_get_data(bd);
+	int intensity = bd->props.brightness;
+	int reg;
+	u8_t val;
+	int ret;
+
+	/*
+	 * If we're blanked the the intensity doesn't matter.
+	 */
+	if ((bd->props.power != FB_BLANK_UNBLANK) ||
+	    (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
+		intensity = 0;
+	}
+
+	/*
+	 * Set the brightness based on the type of backlight
+	 */
+	if (ud->pdata->type == UBICOM32HID_BL_TYPE_BINARY) {
+		reg = UBICOM32HID_CMD_SET_BL_EN;
+		if (intensity) {
+			val = ud->pdata->invert
+				? UBICOM32HID_BL_EN_LOW : UBICOM32HID_BL_EN_HI;
+		} else {
+			val = ud->pdata->invert
+				? UBICOM32HID_BL_EN_HI : UBICOM32HID_BL_EN_LOW;
+		}
+	} else {
+		reg = UBICOM32HID_CMD_SET_PWM;
+		val = ud->pdata->invert
+			? (UBICOM32HID_MAX_BRIGHTNESS_PWM - intensity) :
+			intensity;
+	}
+
+	/*
+	 * Send the command
+	 */
+	ret = i2c_smbus_write_byte_data(ud->client, reg, val);
+	if (ret < 0) {
+		dev_warn(&ud->client->dev, "Unable to write backlight err=%d\n",
+			 ret);
+		return ret;
+	}
+
+	ud->cur_intensity = intensity;
+
+	return 0;
+}
+
+/*
+ * ubicom32hid_get_intensity
+ *	Return the current intensity of the backlight.
+ */
+static int ubicom32hid_get_intensity(struct backlight_device *bd)
+{
+	struct ubicom32hid_data *ud =
+		(struct ubicom32hid_data *)bl_get_data(bd);
+
+	return ud->cur_intensity;
+}
+
+/*
+ * ubicom32hid_verify_data
+ *	Verify the data to see if there is any action to be taken
+ *
+ * Returns 0 if no action is to be taken, non-zero otherwise
+ */
+static int ubicom32hid_verify_data(struct ubicom32hid_data *ud,
+				   struct ubicom32hid_input_data *data)
+{
+	uint8_t *ircmd = (uint8_t *)&(data->ircmd);
+
+	/*
+	 * ircmd == DEADBEEF means ir queue is empty.  Since this is a
+	 * meaningful code, that means the rest of the message is most likely
+	 * correct, so only process the data if the switch state has changed.
+	 */
+	if (data->ircmd == 0xDEADBEEF) {
+		return data->sw_changed != 0;
+	}
+
+	/*
+	 * We have an ircmd which is not empty:
+	 *      Data[1] should be the complement of Data[0]
+	 */
+	if (ircmd[0] != (u8_t)~ircmd[1]) {
+		return 0;
+	}
+
+#ifdef UBICOM32HID_STRICT_IR_CHECK
+	/*
+	 * It seems that some remote controls don't follow the NEC protocol
+	 * properly, so only do this check if the remote does indeed follow the
+	 * spec.  Data[3] should be the complement of Data[2]
+	 */
+	if (ircmd[2] == (u8_t)~ircmd[3]) {
+		return 1;
+	}
+
+	/*
+	 * For non-compliant remotes, check the system code according to what
+	 * they send.
+	 */
+	if ((ircmd[2] != UBICOM32HID_IR_SYSTEM_CODE_CHECK) ||
+	    (ircmd[3] != UBICOM32HID_IR_SYSTEM_CODE)) {
+		return 0;
+	}
+#endif
+
+	/*
+	 * Data checks out, process
+	 */
+	return 1;
+}
+
+/*
+ * ubicom32hid_poll_input
+ *	Poll the input from the HID device.
+ */
+static void ubicom32hid_poll_input(struct input_polled_dev *dev)
+{
+	struct ubicom32hid_data *ud = (struct ubicom32hid_data *)dev->private;
+	const struct ubicom32hid_platform_data *pdata = ud->pdata;
+	struct ubicom32hid_input_data data;
+	struct input_dev *id = dev->input;
+	int i;
+	int sync_needed = 0;
+	uint8_t cmd;
+	int ret;
+
+	/*
+	 * Flush the queue
+	 */
+	cmd = UBICOM32HID_CMD_FLUSH;
+	ret = i2c_master_send(ud->client, &cmd, 1);
+	if (ret < 0) {
+		return;
+	}
+
+	ret = i2c_smbus_read_i2c_block_data(
+		ud->client, UBICOM32HID_CMD_GET_IR_SWITCH, 6, (void *)&data);
+	if (ret < 0) {
+		return;
+	}
+
+	/*
+	 * Verify the data to see if there is any action to be taken
+	 */
+	if (!ubicom32hid_verify_data(ud, &data)) {
+		return;
+	}
+
+#ifdef DEBUG
+	if (ubicom32hid_debug) {
+		printk("Polled ircmd=%8x swstate=%2x swchanged=%2x\n",
+		       data.ircmd, data.sw_state, data.sw_changed);
+	}
+#endif
+
+	/*
+	 * Process changed switches
+	 */
+	if (data.sw_changed) {
+		const struct ubicom32hid_button *ub = pdata->buttons;
+		for (i = 0; i < pdata->nbuttons; i++, ub++) {
+			uint8_t mask = (1 << ub->bit);
+			if (!(data.sw_changed & mask)) {
+				continue;
+			}
+
+			sync_needed = 1;
+			input_event(id, ub->type, ub->code,
+				    (data.sw_state & mask) ? 1 : 0);
+		}
+	}
+	if (sync_needed) {
+		input_sync(id);
+	}
+
+	/*
+	 * Process ir codes
+	 */
+	if (data.ircmd != 0xDEADBEEF) {
+		const struct ubicom32hid_ir *ui = pdata->ircodes;
+		for (i = 0; i < pdata->nircodes; i++, ui++) {
+			if (ui->ir_code == data.ircmd) {
+				/*
+				 * Simulate a up/down event
+				 */
+				input_event(id, ui->type, ui->code, 1);
+				input_sync(id);
+				input_event(id, ui->type, ui->code, 0);
+				input_sync(id);
+			}
+		}
+	}
+}
+
+
+/*
+ * Backlight ops
+ */
+static struct backlight_ops ubicom32hid_blops = {
+	.get_brightness = ubicom32hid_get_intensity,
+	.update_status  = ubicom32hid_set_intensity,
+};
+
+/*
+ * ubicom32hid_probe
+ */
+static int ubicom32hid_probe(struct i2c_client *client,
+			     const struct i2c_device_id *id)
+{
+	struct ubicom32hid_platform_data *pdata;
+	struct ubicom32hid_data *ud;
+	int ret;
+	int i;
+	u8 version[2];
+	char buf[1];
+
+	pdata = client->dev.platform_data;
+	if (pdata == NULL) {
+		return -ENODEV;
+	}
+
+	/*
+	 * See if we even have a device available before allocating memory.
+	 *
+	 * Hard reset the device
+	 */
+	ret = gpio_request(pdata->gpio_reset, "ubicom32hid-reset");
+	if (ret < 0) {
+		return ret;
+	}
+	gpio_direction_output(pdata->gpio_reset, pdata->gpio_reset_polarity);
+	udelay(100);
+	gpio_set_value(pdata->gpio_reset, !pdata->gpio_reset_polarity);
+	udelay(100);
+
+	/*
+	 * soft reset the device.  It sometimes takes a while to do this.
+	 */
+	for (i = 0; i < 50; i++) {
+		buf[0] = UBICOM32HID_CMD_RESET;
+		ret = i2c_master_send(client, buf, 1);
+		if (ret > 0) {
+			break;
+		}
+		udelay(10000);
+	}
+	if (i == 50) {
+		dev_warn(&client->dev, "Unable to reset device\n");
+		goto fail;
+	}
+
+	ret = i2c_smbus_read_byte_data(client, UBICOM32HID_CMD_GET_DEVICE_ID);
+	if (ret != UBICOM32HID_DEVICE_ID) {
+		dev_warn(&client->dev, "Incorrect device id %02x\n", buf[0]);
+		ret = -ENODEV;
+		goto fail;
+	}
+
+	ret = i2c_smbus_read_byte_data(client, UBICOM32HID_CMD_GET_VERSION);
+	if (ret < 0) {
+		dev_warn(&client->dev, "Unable to get version\n");
+		goto fail;
+	}
+	version[0] = ret;
+
+	ret = i2c_smbus_read_byte_data(client, UBICOM32HID_CMD_GET_REVISION);
+	if (ret < 0) {
+		dev_warn(&client->dev, "Unable to get revision\n");
+		goto fail;
+	}
+	version[1] = ret;
+
+	/*
+	 * Allocate our private data
+	 */
+	ud = kzalloc(sizeof(struct ubicom32hid_data), GFP_KERNEL);
+	if (!ud) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+	ud->pdata = pdata;
+	ud->client = client;
+
+	/*
+	 * Register our backlight device
+	 */
+	ud->bldev = backlight_device_register(DRIVER_NAME, &client->dev,
+					      ud, &ubicom32hid_blops);
+	if (IS_ERR(ud->bldev)) {
+		ret = PTR_ERR(ud->bldev);
+		goto fail2;
+	}
+	platform_set_drvdata(client, ud);
+
+	/*
+	 * Start up the backlight with the requested intensity
+	 */
+	ud->bldev->props.power = FB_BLANK_UNBLANK;
+	ud->bldev->props.max_brightness =
+		(pdata->type == UBICOM32HID_BL_TYPE_PWM) ?
+		UBICOM32HID_MAX_BRIGHTNESS_PWM : 1;
+	if (pdata->default_intensity < ud->bldev->props.max_brightness) {
+		ud->bldev->props.brightness = pdata->default_intensity;
+	} else {
+		dev_warn(&client->dev, "Default brightness out of range, "
+			 "setting to max\n");
+		ud->bldev->props.brightness = ud->bldev->props.max_brightness;
+	}
+
+	ubicom32hid_set_intensity(ud->bldev);
+
+	/*
+	 * Check to see if we have any inputs
+	 */
+	if (!pdata->nbuttons && !pdata->nircodes) {
+		goto done;
+	}
+
+	/*
+	 * We have buttons or codes, we must register an input device
+	 */
+	ud->poll_dev = input_allocate_polled_device();
+	if (!ud->poll_dev) {
+		ret = -ENOMEM;
+		goto fail3;
+	}
+
+	/*
+	 * Setup the polling to default to 100ms
+	 */
+	ud->poll_dev->poll = ubicom32hid_poll_input;
+	ud->poll_dev->poll_interval =
+		pdata->poll_interval ? pdata->poll_interval : 100;
+	ud->poll_dev->private = ud;
+
+	ud->poll_dev->input->name =
+		pdata->input_name ? pdata->input_name : "Ubicom32HID";
+	ud->poll_dev->input->phys = "ubicom32hid/input0";
+	ud->poll_dev->input->dev.parent = &client->dev;
+	ud->poll_dev->input->id.bustype = BUS_I2C;
+
+	/*
+	 * Set the capabilities by running through the buttons and ir codes
+	 */
+	for (i = 0; i < pdata->nbuttons; i++) {
+		const struct ubicom32hid_button *ub = &pdata->buttons[i];
+
+		input_set_capability(ud->poll_dev->input,
+				     ub->type ? ub->type : EV_KEY, ub->code);
+	}
+
+	for (i = 0; i < pdata->nircodes; i++) {
+		const struct ubicom32hid_ir *ui = &pdata->ircodes[i];
+
+		input_set_capability(ud->poll_dev->input,
+				     ui->type ? ui->type : EV_KEY, ui->code);
+	}
+
+	ret = input_register_polled_device(ud->poll_dev);
+	if (ret) {
+		goto fail3;
+	}
+
+done:
+	printk(KERN_INFO DRIVER_NAME ": enabled, version=%02x.%02x\n",
+	       version[0], version[1]);
+
+	return 0;
+
+fail3:
+	gpio_free(ud->pdata->gpio_reset);
+	backlight_device_unregister(ud->bldev);
+fail2:
+	kfree(ud);
+fail:
+	gpio_free(pdata->gpio_reset);
+	return ret;
+}
+
+/*
+ * ubicom32hid_remove
+ */
+static int ubicom32hid_remove(struct i2c_client *client)
+{
+	struct ubicom32hid_data *ud =
+		(struct ubicom32hid_data *)platform_get_drvdata(client);
+
+	gpio_free(ud->pdata->gpio_reset);
+
+	backlight_device_unregister(ud->bldev);
+
+	if (ud->poll_dev) {
+		input_unregister_polled_device(ud->poll_dev);
+		input_free_polled_device(ud->poll_dev);
+	}
+
+	platform_set_drvdata(client, NULL);
+
+	kfree(ud);
+
+	return 0;
+}
+
+static struct i2c_driver ubicom32hid_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= ubicom32hid_probe,
+	.remove		= __exit_p(ubicom32hid_remove),
+	.id_table	= ubicom32hid_id,
+};
+
+/*
+ * ubicom32hid_init
+ */
+static int __init ubicom32hid_init(void)
+{
+	return i2c_add_driver(&ubicom32hid_driver);
+}
+module_init(ubicom32hid_init);
+
+/*
+ * ubicom32hid_exit
+ */
+static void __exit ubicom32hid_exit(void)
+{
+	i2c_del_driver(&ubicom32hid_driver);
+}
+module_exit(ubicom32hid_exit);
+
+MODULE_AUTHOR("Pat Tjin <@ubicom.com>")
+MODULE_DESCRIPTION("Ubicom HID driver");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/arch/ubicom32/mach-common/ubicom32input.c
@@ -0,0 +1,265 @@
+/*
+ * arch/ubicom32/mach-common/ubicom32input.c
+ *   Ubicom32 Input driver
+ *
+ *   based on gpio-keys
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ *
+ *
+ * TODO: add groups for inputs which can be sampled together (i.e. I2C)
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/input-polldev.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+
+#include <asm/ubicom32input.h>
+
+struct ubicom32input_data {
+	struct ubicom32input_platform_data	*pdata;
+
+	struct input_polled_dev			*poll_dev;
+
+	/*
+	 * collection of previous states for buttons
+	 */
+	u8					prev_state[0];
+};
+
+/*
+ * ubicom32input_poll
+ */
+static void ubicom32input_poll(struct input_polled_dev *dev)
+{
+	struct ubicom32input_data *ud =
+		(struct ubicom32input_data *)dev->private;
+	struct ubicom32input_platform_data *pdata = ud->pdata;
+	struct input_dev *id = dev->input;
+	int i;
+	int sync_needed = 0;
+
+	for (i = 0; i < pdata->nbuttons; i++) {
+		const struct ubicom32input_button *ub = &pdata->buttons[i];
+		int state = 0;
+
+		int val = gpio_get_value(ub->gpio);
+
+		/*
+		 * Check to see if the state changed from the last time we
+		 * looked
+		 */
+		if (val == ud->prev_state[i]) {
+			continue;
+		}
+
+		/*
+		 * The state has changed, determine if we are "up" or "down"
+		 */
+		ud->prev_state[i] = val;
+
+		if ((!val && ub->active_low) || (val && !ub->active_low)) {
+			state = 1;
+		}
+
+		input_event(id, ub->type, ub->code, state);
+		sync_needed = 1;
+	}
+
+	if (sync_needed) {
+		input_sync(id);
+	}
+}
+
+/*
+ * ubicom32input_probe
+ */
+static int __devinit ubicom32input_probe(struct platform_device *pdev)
+{
+	int i;
+	struct ubicom32input_data *ud;
+	struct input_polled_dev *poll_dev;
+	struct input_dev *input_dev;
+	struct ubicom32input_platform_data *pdata;
+	int ret;
+
+	pdata = pdev->dev.platform_data;
+	if (!pdata) {
+		return -EINVAL;
+	}
+
+	ud = kzalloc(sizeof(struct ubicom32input_data) +
+		     pdata->nbuttons, GFP_KERNEL);
+	if (!ud) {
+		return -ENOMEM;
+	}
+	ud->pdata = pdata;
+
+	poll_dev = input_allocate_polled_device();
+	if (!poll_dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	platform_set_drvdata(pdev, ud);
+
+	ud->poll_dev = poll_dev;
+	poll_dev->private = ud;
+	poll_dev->poll = ubicom32input_poll;
+
+	/*
+	 * Set the poll interval requested, default to 50 msec
+	 */
+	if (pdata->poll_interval) {
+		poll_dev->poll_interval = pdata->poll_interval;
+	} else {
+		poll_dev->poll_interval = 50;
+	}
+
+	/*
+	 * Setup the input device
+	 */
+	input_dev = poll_dev->input;
+	input_dev->name = pdata->name ? pdata->name : "Ubicom32 Input";
+	input_dev->phys = "ubicom32input/input0";
+	input_dev->dev.parent = &pdev->dev;
+	input_dev->id.bustype = BUS_HOST;
+
+	/*
+	 * Reserve the GPIOs
+	 */
+	for (i = 0; i < pdata->nbuttons; i++) {
+		const struct ubicom32input_button *ub = &pdata->buttons[i];
+
+		ret = gpio_request(ub->gpio,
+				   ub->desc ? ub->desc : "ubicom32input");
+		if (ret < 0) {
+			pr_err("ubicom32input: failed to request "
+			       "GPIO %d ret=%d\n", ub->gpio, ret);
+			goto fail2;
+		}
+
+		ret = gpio_direction_input(ub->gpio);
+		if (ret < 0) {
+			pr_err("ubicom32input: failed to set "
+			       "GPIO %d to input ret=%d\n", ub->gpio, ret);
+			goto fail2;
+		}
+
+		/*
+		 * Set the previous state to the non-active stae
+		 */
+		ud->prev_state[i] = ub->active_low;
+
+		input_set_capability(input_dev,
+				     ub->type ? ub->type : EV_KEY, ub->code);
+	}
+
+	/*
+	 * Register
+	 */
+	ret = input_register_polled_device(ud->poll_dev);
+	if (ret) {
+		goto fail2;
+	}
+
+	return 0;
+
+fail2:
+	/*
+	 * release the GPIOs we have already requested.
+	 */
+	while (--i >= 0) {
+		gpio_free(pdata->buttons[i].gpio);
+	}
+
+fail:
+	printk(KERN_ERR "Ubicom32Input: Failed to register driver %d", ret);
+	platform_set_drvdata(pdev, NULL);
+	input_free_polled_device(poll_dev);
+	kfree(ud);
+	return ret;
+}
+
+/*
+ * ubicom32input_remove
+ */
+static int __devexit ubicom32input_remove(struct platform_device *dev)
+{
+	struct ubicom32input_data *ud =
+		(struct ubicom32input_data *)platform_get_drvdata(dev);
+	int i;
+
+	/*
+	 * Free the GPIOs
+	 */
+	for (i = 0; i < ud->pdata->nbuttons; i++) {
+		gpio_free(ud->pdata->buttons[i].gpio);
+	}
+
+	platform_set_drvdata(dev, NULL);
+	input_unregister_polled_device(ud->poll_dev);
+	input_free_polled_device(ud->poll_dev);
+
+	kfree(ud);
+
+	return 0;
+}
+
+static struct platform_driver ubicom32input_driver = {
+	.driver         = {
+		.name   = "ubicom32input",
+		.owner  = THIS_MODULE,
+	},
+	.probe          = ubicom32input_probe,
+	.remove         = __devexit_p(ubicom32input_remove),
+};
+
+/*
+ * ubicom32input_init
+ */
+static int __devinit ubicom32input_init(void)
+{
+	return platform_driver_register(&ubicom32input_driver);
+}
+
+/*
+ * ubicom32input_exit
+ */
+static void __exit ubicom32input_exit(void)
+{
+	platform_driver_unregister(&ubicom32input_driver);
+}
+
+module_init(ubicom32input_init);
+module_exit(ubicom32input_exit);
+
+MODULE_AUTHOR("Pat Tjin <pattjin@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom32 Input Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ubicom32-input");
--- /dev/null
+++ b/arch/ubicom32/mach-common/ubicom32input_i2c.c
@@ -0,0 +1,325 @@
+/*
+ * arch/ubicom32/mach-common/ubicom32input_i2c.c
+ *   Ubicom32 Input driver for I2C
+ *	  Supports PCA953x and family
+ *
+ *   We hog the I2C device, turning it all to input.
+ *
+ *   Based on gpio-keys, pca953x
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/input-polldev.h>
+#include <linux/i2c.h>
+
+#include <asm/ubicom32input_i2c.h>
+
+#define UBICOM32INPUT_I2C_REG_INPUT	0
+#define UBICOM32INPUT_I2C_REG_OUTPUT	1
+#define UBICOM32INPUT_I2C_REG_INVERT	2
+#define UBICOM32INPUT_I2C_REG_DIRECTION	3
+
+static const struct i2c_device_id ubicom32input_i2c_id[] = {
+	{ "ubicom32in_pca9534", 8, },
+	{ "ubicom32in_pca9535", 16, },
+	{ "ubicom32in_pca9536", 4, },
+	{ "ubicom32in_pca9537", 4, },
+	{ "ubicom32in_pca9538", 8, },
+	{ "ubicom32in_pca9539", 16, },
+	{ "ubicom32in_pca9554", 8, },
+	{ "ubicom32in_pca9555", 16, },
+	{ "ubicom32in_pca9557", 8, },
+	{ "ubicom32in_max7310", 8, },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ubicom32input_i2c_id);
+
+struct ubicom32input_i2c_data {
+	struct ubicom32input_i2c_platform_data	*pdata;
+
+	struct i2c_client			*client;
+
+	struct input_polled_dev			*poll_dev;
+
+	/*
+	 * collection of previous states for buttons
+	 */
+	uint16_t				prev_state;
+
+	uint8_t					ngpios;
+};
+
+/*
+ * ubicom32input_i2c_write_reg
+ *	writes a register to the I2C device.
+ */
+static int ubicom32input_i2c_write_reg(struct ubicom32input_i2c_data *ud,
+				       int reg, uint16_t val)
+{
+	int ret;
+
+	if (ud->ngpios <= 8) {
+		ret = i2c_smbus_write_byte_data(ud->client, reg, val);
+	} else {
+		ret = i2c_smbus_write_word_data(ud->client, reg << 1, val);
+	}
+
+	if (ret < 0) {
+		return ret;
+	}
+
+	return 0;
+}
+
+/*
+ * ubicom32input_i2c_read_reg
+ *	reads a register from the I2C device.
+ */
+static int ubicom32input_i2c_read_reg(struct ubicom32input_i2c_data *ud,
+				      int reg, uint16_t *val)
+{
+	int ret;
+
+	if (ud->ngpios <= 8) {
+		ret = i2c_smbus_read_byte_data(ud->client, reg);
+	} else {
+		ret = i2c_smbus_read_word_data(ud->client, reg);
+	}
+
+	if (ret < 0) {
+		return ret;
+	}
+
+	*val = (uint16_t)ret;
+
+	return 0;
+}
+
+/*
+ * ubicom32input_i2c_poll
+ */
+static void ubicom32input_i2c_poll(struct input_polled_dev *dev)
+{
+	struct ubicom32input_i2c_data *ud =
+		(struct ubicom32input_i2c_data *)dev->private;
+	struct ubicom32input_i2c_platform_data *pdata = ud->pdata;
+	struct input_dev *id = dev->input;
+	int i;
+	int sync_needed = 0;
+	uint16_t val;
+	uint16_t change_mask;
+
+	/*
+	 * Try to get the input status, if we fail, bail out, maybe we can do it
+	 * next time.
+	 */
+	if (ubicom32input_i2c_read_reg(ud, UBICOM32INPUT_I2C_REG_INPUT, &val)) {
+		return;
+	}
+
+	/*
+	 * see if anything changed by using XOR
+	 */
+	change_mask = ud->prev_state ^ val;
+	ud->prev_state = val;
+
+	for (i = 0; i < pdata->nbuttons; i++) {
+		const struct ubicom32input_i2c_button *ub = &pdata->buttons[i];
+		uint16_t mask = 1 << ub->bit;
+		int state = val & mask;
+
+		/*
+		 * Check to see if the state changed from the last time we
+		 * looked
+		 */
+		if (!(change_mask & mask)) {
+			continue;
+		}
+		input_event(id, ub->type, ub->code, state);
+		sync_needed = 1;
+	}
+
+	if (sync_needed) {
+		input_sync(id);
+	}
+}
+
+/*
+ * ubicom32input_i2c_probe
+ */
+static int __devinit ubicom32input_i2c_probe(struct i2c_client *client,
+					     const struct i2c_device_id *id)
+{
+	int i;
+	struct ubicom32input_i2c_data *ud;
+	struct input_polled_dev *poll_dev;
+	struct input_dev *input_dev;
+	struct ubicom32input_i2c_platform_data *pdata;
+	int ret;
+	uint16_t invert_mask = 0;
+
+	pdata = client->dev.platform_data;
+	if (!pdata) {
+		return -EINVAL;
+	}
+
+	ud = kzalloc(sizeof(struct ubicom32input_i2c_data), GFP_KERNEL);
+	if (!ud) {
+		return -ENOMEM;
+	}
+	ud->pdata = pdata;
+	ud->client = client;
+	ud->ngpios = id->driver_data;
+
+	poll_dev = input_allocate_polled_device();
+	if (!poll_dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	ud->poll_dev = poll_dev;
+	poll_dev->private = ud;
+	poll_dev->poll = ubicom32input_i2c_poll;
+
+	/*
+	 * Set the poll interval requested, default to 100 msec
+	 */
+	if (pdata->poll_interval) {
+		poll_dev->poll_interval = pdata->poll_interval;
+	} else {
+		poll_dev->poll_interval = 100;
+	}
+
+	/*
+	 * Setup the input device
+	 */
+	input_dev = poll_dev->input;
+	input_dev->name = pdata->name ? pdata->name : "Ubicom32 Input I2C";
+	input_dev->phys = "ubicom32input_i2c/input0";
+	input_dev->dev.parent = &client->dev;
+	input_dev->id.bustype = BUS_I2C;
+
+	/*
+	 * Set the capabilities
+	 */
+	for (i = 0; i < pdata->nbuttons; i++) {
+		const struct ubicom32input_i2c_button *ub = &pdata->buttons[i];
+
+		if (ub->active_low) {
+			invert_mask |= (1 << ub->bit);
+		}
+
+		input_set_capability(input_dev,
+				     ub->type ? ub->type : EV_KEY, ub->code);
+	}
+
+	/*
+	 * Setup the device (all inputs)
+	 */
+	ret = ubicom32input_i2c_write_reg(ud, UBICOM32INPUT_I2C_REG_DIRECTION,
+					  0xFFFF);
+	if (ret < 0) {
+		goto fail;
+	}
+
+	ret = ubicom32input_i2c_write_reg(ud, UBICOM32INPUT_I2C_REG_INVERT,
+					  invert_mask);
+	if (ret < 0) {
+		goto fail;
+	}
+
+	/*
+	 * Register
+	 */
+	ret = input_register_polled_device(ud->poll_dev);
+	if (ret) {
+		goto fail;
+	}
+
+	i2c_set_clientdata(client, ud);
+
+	return 0;
+
+fail:
+	printk(KERN_ERR "ubicom32input_i2c: Failed to register driver %d\n",
+	       ret);
+	input_free_polled_device(poll_dev);
+	kfree(ud);
+	return ret;
+}
+
+/*
+ * ubicom32input_i2c_remove
+ */
+static int __devexit ubicom32input_i2c_remove(struct i2c_client *client)
+{
+	struct ubicom32input_i2c_data *ud =
+		(struct ubicom32input_i2c_data *)i2c_get_clientdata(client);
+
+	i2c_set_clientdata(client, NULL);
+	input_unregister_polled_device(ud->poll_dev);
+	input_free_polled_device(ud->poll_dev);
+
+	kfree(ud);
+
+	return 0;
+}
+
+static struct i2c_driver ubicom32input_i2c_driver = {
+	.driver         = {
+		.name   = "ubicom32input_i2c",
+		.owner  = THIS_MODULE,
+	},
+	.remove         = __devexit_p(ubicom32input_i2c_remove),
+	.id_table	= ubicom32input_i2c_id,
+	.probe          = ubicom32input_i2c_probe,
+};
+
+/*
+ * ubicom32input_i2c_init
+ */
+static int __devinit ubicom32input_i2c_init(void)
+{
+	return i2c_add_driver(&ubicom32input_i2c_driver);
+}
+
+/*
+ * ubicom32input_i2c_exit
+ */
+static void __exit ubicom32input_i2c_exit(void)
+{
+	i2c_del_driver(&ubicom32input_i2c_driver);
+}
+
+module_init(ubicom32input_i2c_init);
+module_exit(ubicom32input_i2c_exit);
+
+MODULE_AUTHOR("Pat Tjin <pattjin@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom32 Input Driver I2C");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ubicom32-input");
--- /dev/null
+++ b/arch/ubicom32/mach-common/usb.c
@@ -0,0 +1,133 @@
+/*
+ * arch/ubicom32/mach-common/ip5k_usb.c
+ *   Ubicom32 architecture usb support.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
+ * Author: Kevin Hilman
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation, either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/musb.h>
+#include <asm/devtree.h>
+#include <asm/ip5000.h>
+#include "usb_tio.h"
+
+struct usbtionode *unode = NULL;
+
+static struct resource usb_resources[] = {
+	[0] = {
+		.start	= RJ + 0x800,
+		.end	= RJ + 0x1000,
+		.flags	= IORESOURCE_MEM,
+	},
+	[1] = {	/* general IRQ */
+		.start	= 1, /* this is a dummy value, the real irq number is passed from kernel_setup_param */
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+
+static struct musb_hdrc_eps_bits musb_eps[] = {
+	{ "ep1_tx", 4, },
+	{ "ep1_rx", 4, },
+	{ "ep2_tx", 10, },
+	{ "ep2_rx", 10, },
+	{ "ep3_tx", 9, },
+	{ "ep3_rx", 9, },
+	{ "ep4_tx", 9, },
+	{ "ep4_rx", 9, },
+	{ "ep5_tx", 6, },
+	{ "ep5_rx", 6, },
+};
+
+static struct musb_hdrc_config musb_config = {
+	.multipoint     = true,
+	.dyn_fifo       = false,
+	.soft_con       = true,
+	.dma            = false,
+
+	.num_eps        = 6,
+	.dma_channels   = 0,
+	.ram_bits       = 0,
+	.eps_bits       = musb_eps,
+};
+
+static struct musb_hdrc_platform_data usb_data = {
+#ifdef CONFIG_USB_MUSB_OTG
+	.mode		= MUSB_OTG,
+#else
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	.mode		= MUSB_HOST,
+#else
+#ifdef CONFIG_USB_GADGET_MUSB_HDRC
+	.mode		= MUSB_PERIPHERAL,
+#endif
+#endif
+#endif
+	.clock		= NULL,
+	.set_clock	= NULL,
+	.config		= &musb_config,
+};
+
+static struct platform_device musb_device = {
+	.name		= "musb_hdrc",
+	.id		= 0,
+	.dev = {
+		.platform_data		= &usb_data,
+		.dma_mask		= NULL,
+		.coherent_dma_mask	= 0,
+	},
+	.resource	= usb_resources,
+	.num_resources	= ARRAY_SIZE(usb_resources),
+};
+
+struct usbtio_node *usb_node = NULL;
+void ubi32_usb_init(void)
+{
+	/*
+	 * See if the usbtio is in the device tree.
+	 */
+	usb_node = (struct usbtio_node *)devtree_find_node("usbtio");
+	if (!usb_node) {
+		printk(KERN_WARNING "usb init failed\n");
+		return;
+	}
+
+	usb_resources[1].start = usb_node->dn.recvirq;
+	if (platform_device_register(&musb_device) < 0) {
+		printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
+		return;
+	}
+}
+
+void ubi32_usb_int_clr(void)
+{
+        UBICOM32_IO_PORT(RJ)->int_clr = (1 << 3);
+}
+
--- /dev/null
+++ b/arch/ubicom32/mach-common/usb_tio.c
@@ -0,0 +1,356 @@
+/*
+ * arch/ubicom32/mach-common/usb_tio.c
+ *  Linux side Ubicom USB TIO driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <asm/devtree.h>
+#include "usb_tio.h"
+
+#ifdef CONFIG_SMP
+static DEFINE_SPINLOCK(tio_lock);
+#define USB_TIO_LOCK(lock, flag) spin_lock_irqsave(lock, flag)
+#define USB_TIO_UNLOCK(lock, flag) spin_unlock_irqrestore(lock, flag)
+#define USB_TIO_LOCK_ISLOCKED(lock) spin_try_lock(lock)
+#else
+#define USB_TIO_LOCK(lock, flag) local_irq_save(flag)
+#define USB_TIO_UNLOCK(lock, flag) local_irq_restore(flag)
+#endif
+
+spinlock_t usb_tio_lock;
+
+/*
+ * usb_tio_set_hrt_interrupt()
+ */
+static inline void usb_tio_set_hrt_interrupt(void)
+{
+	ubicom32_set_interrupt(usb_node->dn.sendirq);
+}
+
+static inline void usb_tio_wait_hrt(void)
+{
+	while (unlikely(usb_node->pdesc));
+}
+
+#if defined(USB_TIO_DEBUG)
+static void usb_tio_request_verify_magic(volatile struct usb_tio_request *req)
+{
+	BUG_ON(req->magic != USB_TIO_REQUEST_MAGIC2);
+}
+
+static void usb_tio_request_clear_magic(volatile struct usb_tio_request *req)
+{
+	req->magic = 0;
+}
+#endif
+
+static void usb_tio_request_set_magic(volatile struct usb_tio_request *req)
+{
+	req->magic = USB_TIO_REQUEST_MAGIC1;
+}
+
+/*
+ * usb_tio_commit_request()
+ */
+static inline void usb_tio_commit_request(volatile struct usb_tio_request *request)
+{
+	wmb();
+	usb_node->pdesc = request;
+
+	/*
+	 * next thing to do is alway checking if (usb_node->pdesc == NULL) 
+	 * to see if the request is done, so add a mb() here
+	 */
+	mb();
+	usb_tio_set_hrt_interrupt();
+}
+
+/*
+ * usb_tio_read_u16()
+ *	Synchronously read 16 bits.
+ */
+u8_t usb_tio_read_u16(u32_t address, u16_t *data)
+{
+	volatile struct usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	/*
+	 * Fill in the request.
+	 */
+	tio_req->address = address;
+	tio_req->cmd = USB_TIO_READ16_SYNC;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+	usb_tio_commit_request(tio_req);
+
+	/*
+	 * Wait for the result to show up.
+	 */
+	usb_tio_wait_hrt();
+	USB_TIO_REQUEST_VERIFY_MAGIC(tio_req);
+	*data = (u16_t)tio_req->data;
+	USB_TIO_REQUEST_CLEAR_MAGIC(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_read_u8()
+ *	Synchronously read 16 bits.
+ */
+u8_t usb_tio_read_u8(u32_t address, u8_t *data)
+{
+	volatile struct usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	/*
+	 * Fill in the request.
+	 */
+	tio_req->address = address;
+	tio_req->cmd = USB_TIO_READ8_SYNC;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+
+	/*
+	 * Wait for the result to show up.
+	 */
+	usb_tio_wait_hrt();
+	USB_TIO_REQUEST_VERIFY_MAGIC(tio_req);
+	*data = (u8_t)tio_req->data;
+	USB_TIO_REQUEST_CLEAR_MAGIC(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_write_u16()
+ *	Asynchronously  write 16 bits.
+ */
+u8_t usb_tio_write_u16(u32_t address, u16_t data)
+{
+	volatile struct usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	/*
+	 * Wait for any previous write or pending read to complete.
+	 */
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	tio_req->address = address;
+	tio_req->data = data;
+	tio_req->cmd = USB_TIO_WRITE16_ASYNC;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_write_u8()
+ *	Asynchronously  write 8 bits.
+ */
+u8_t usb_tio_write_u8(u32_t address, u8_t data)
+{
+	volatile struct usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	/*
+	 * Wait for any previous write or pending read to complete.
+	 */
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	tio_req->address = address;
+	tio_req->data = data;
+	tio_req->cmd = USB_TIO_WRITE8_ASYNC;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_read_fifo()
+ *	Synchronously read FIFO.
+ */
+u8_t usb_tio_read_fifo(u32_t address, u32_t buffer, u32_t bytes)
+{
+	volatile struct usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	/*
+	 * Wait for any previous request to complete and then make this request.
+	 */
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	/*
+	 * Fill in the request.
+	 */
+	tio_req->address = address;
+	tio_req->cmd = USB_TIO_READ_FIFO_SYNC;
+	tio_req->buffer = buffer;
+	tio_req->transfer_length = bytes;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+
+	 /*
+	 * Wait for the result to show up.
+	 */
+	usb_tio_wait_hrt();
+	USB_TIO_REQUEST_VERIFY_MAGIC(tio_req);
+	USB_TIO_REQUEST_CLEAR_MAGIC(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_write_fifo()
+ *	Synchronously  write 32 bits.
+ */
+u8_t usb_tio_write_fifo(u32_t address, u32_t buffer, u32_t bytes)
+{
+	volatile struct	usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	tio_req->address = address;
+	tio_req->buffer = buffer;
+	tio_req->cmd = USB_TIO_WRITE_FIFO_SYNC;
+	tio_req->transfer_length = bytes;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+	
+	/*
+	 * Wait for the result to show up.
+	 */
+	usb_tio_wait_hrt();
+	USB_TIO_REQUEST_VERIFY_MAGIC(tio_req);
+	USB_TIO_REQUEST_CLEAR_MAGIC(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_write_fifo_async()
+ *	Asynchronously write 32 bits.
+ */
+u8_t usb_tio_write_fifo_async(u32_t address, u32_t buffer, u32_t bytes)
+{
+	volatile struct	usb_tio_request *tio_req = &usb_node->request;
+	unsigned long flag;
+
+	USB_TIO_LOCK(&tio_lock, flag);
+	usb_tio_wait_hrt();
+
+	tio_req->address = address;
+	
+	/*
+	 * Is it necessary to make a local copy of the buffer? Any chance the URB is aborted before TIO finished the FIFO write?
+	 */
+	tio_req->buffer = buffer;
+	tio_req->cmd = USB_TIO_WRITE_FIFO_SYNC;
+	tio_req->transfer_length = bytes;
+	USB_TIO_REQUEST_SET_MAGIC(tio_req);
+	/*
+	 * commit the request
+	 */
+	usb_tio_commit_request(tio_req);
+	USB_TIO_UNLOCK(&tio_lock, flag);
+	return USB_TIO_OK;
+}
+
+/*
+ * usb_tio_read_int_status()
+ * 	read and clear the interrupt status registers
+ */
+void usb_tio_read_int_status(u8_t *int_usb, u16_t *int_tx, u16_t *int_rx)
+{
+
+	/*
+	 * clear the interrupt must be syncronized with the TIO thread to prevent the racing condiiton 
+	 * that TIO thread try to set it at same time
+	 */
+	asm volatile (
+	"1:	bset (%0), (%0), #0	\n\t" \
+	"	jmpne.f 1b		\n\t" \
+		:
+		: "a" (&usb_node->usb_vp_control)
+		: "memory", "cc"
+	);
+
+	*int_usb = usb_node->usb_vp_hw_int_usb;
+	*int_tx  = cpu_to_le16(usb_node->usb_vp_hw_int_tx);
+	*int_rx  = cpu_to_le16(usb_node->usb_vp_hw_int_rx);
+
+	//printk(KERN_INFO "int read %x, %x, %x\n", *int_usb, *int_tx, *int_rx);
+	
+	/* 
+	 * The interrupt status register is read-clean, so clear it now
+	 */
+	usb_node->usb_vp_hw_int_usb = 0;
+	usb_node->usb_vp_hw_int_tx = 0;
+	usb_node->usb_vp_hw_int_rx = 0;
+
+	/*
+	 * release the lock bit
+	 */
+	usb_node->usb_vp_control &= 0xfffe;
+}
--- /dev/null
+++ b/arch/ubicom32/mach-common/usb_tio.h
@@ -0,0 +1,111 @@
+/*
+ * arch/ubicom32/mach-common/usb_tio.h
+ *   Definitions for usb_tio.c
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <asm/devtree.h>
+#include <asm/ip5000.h>
+
+#ifndef _USB_TIO_H
+#define _USB_TIO_H
+
+#undef  USB_TIO_DEBUG
+
+#define USB_TIO_REQUEST_MAGIC1	0x2307
+#define USB_TIO_REQUEST_MAGIC2	0x0789
+#if defined(USB_TIO_DEBUG)
+#define USB_TIO_REQUEST_VERIFY_MAGIC(req)	usb_tio_request_verify_magic(req)
+#define USB_TIO_REQUEST_SET_MAGIC(req)          usb_tio_request_set_magic(req)
+#define USB_TIO_REQUEST_CLEAR_MAGIC(req)	usb_tio_request_clear_magic(req)
+#else
+#define USB_TIO_REQUEST_VERIFY_MAGIC(req)
+#define USB_TIO_REQUEST_SET_MAGIC(req)          usb_tio_request_set_magic(req)
+#define USB_TIO_REQUEST_CLEAR_MAGIC(req)
+#endif
+
+enum USB_TIO_status {
+	USB_TIO_OK,
+	USB_TIO_ERROR,
+	USB_TIO_ERROR_COMMIT,
+};
+
+enum USB_TIO_cmds {
+	USB_TIO_READ16_SYNC,
+	USB_TIO_READ8_SYNC,
+	USB_TIO_READ_FIFO_SYNC,
+
+	USB_TIO_WRITE16_ASYNC,
+	USB_TIO_WRITE8_ASYNC,
+	USB_TIO_WRITE_FIFO_ASYNC,
+
+	USB_TIO_WRITE16_SYNC,
+	USB_TIO_WRITE8_SYNC,
+	USB_TIO_WRITE_FIFO_SYNC,
+
+};
+
+enum USB_TIO_state {
+	USB_TIO_NORMAL,
+	USB_TIO_DMA_SETUP,
+};
+
+struct usb_tio_request {
+	volatile u32_t address;
+	union {
+		volatile u32_t data;
+		volatile u32_t buffer;
+	};
+	volatile u16_t cmd;
+	const volatile u16_t status;
+	volatile u32_t transfer_length;
+	volatile u32_t thread_mask;
+	volatile u16_t magic;
+};
+
+struct usbtio_node {
+	struct devtree_node dn;
+	volatile struct usb_tio_request * volatile pdesc;
+	struct usb_tio_request	request;
+	volatile u32_t usb_vp_config;
+	volatile u32_t usb_vp_control;
+	const volatile u32_t usb_vp_status;
+	volatile u16_t usb_vp_hw_int_tx;
+	volatile u16_t usb_vp_hw_int_rx;
+	volatile u8_t  usb_vp_hw_int_usb;
+	volatile u8_t usb_vp_hw_int_mask_usb;
+        volatile u16_t usb_vp_hw_int_mask_tx;
+        volatile u16_t usb_vp_hw_int_mask_rx;
+
+};
+
+extern struct usbtio_node *usb_node;
+extern void ubi32_usb_init(void);
+#endif
--- /dev/null
+++ b/arch/ubicom32/mach-common/vdc_tio.c
@@ -0,0 +1,111 @@
+/*
+ * arch/ubicom32/mach-common/vdc_tio.c
+ *   Generic initialization for VDC
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#include <asm/devtree.h>
+#include <asm/vdc_tio.h>
+
+/*
+ * Resources that this driver uses
+ */
+static struct resource vdc_tio_resources[] = {
+	/*
+	 * Send IRQ
+	 */
+	[0] = {
+		/*
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Receive IRQ (optional)
+	 */
+	[1] = {
+		/*
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Memory Mapped Registers
+	 */
+	[2] = {
+		/*
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+/*
+ * The platform_device structure which is passed to the driver
+ */
+static struct platform_device vdc_tio_platform_device = {
+	.name		= "ubicom32fb",
+	.id		= -1,
+	.resource	= vdc_tio_resources,
+	.num_resources	= ARRAY_SIZE(vdc_tio_resources),
+};
+
+/*
+ * vdc_tio_init
+ *	Checks the device tree and instantiates the driver if found
+ */
+void __init vdc_tio_init(void)
+{
+	/*
+	 * Check the device tree for the vdc_tio
+	 */
+	struct vdc_tio_node *vdc_node =
+		(struct vdc_tio_node *)devtree_find_node("vdctio");
+	if (!vdc_node) {
+		printk(KERN_WARNING "No vdc_tio found\n");
+		return;
+	}
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	vdc_tio_resources[0].start = vdc_node->dn.sendirq;
+	vdc_tio_resources[1].start = vdc_node->dn.recvirq;
+	vdc_tio_resources[2].start = (u32_t)vdc_node->regs;
+	vdc_tio_resources[2].end = (u32_t)vdc_node->regs +
+		sizeof(struct vdc_tio_vp_regs);
+
+	/*
+	 * Try to get the device registered
+	 */
+	if (platform_device_register(&vdc_tio_platform_device) < 0) {
+		printk(KERN_WARNING "VDC failed to register\n");
+	}
+}
--- /dev/null
+++ b/arch/ubicom32/mach-ip5k/board-ip5160dev.c
@@ -0,0 +1,110 @@
+/*
+ * arch/ubicom32/mach-ip5k/board-ip5160dev.c
+ *   Platform initialization for ip5160dev board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+#include <asm/ubicom32suart.h>
+#endif
+
+/*
+ * Factory Default Button on the board at PXn
+ * TODO: This is just a placeholder and it needs to include proper header files
+ */
+struct ubicom32fdb_platform_data {
+	int		fdb_gpio;
+	bool		fdb_polarity;
+};
+
+static struct ubicom32fdb_platform_data ip5160dev_fdb_data = {
+	.fdb_gpio		= 0,
+	.fdb_polarity		= true,
+};
+
+static struct platform_device ip5160dev_fdb_device = {
+	.name	= "ubicom32fdb",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip5160dev_fdb_data,
+	},
+};
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+static struct resource ip5160dev_ubicom32_suart_resources[] = {
+        {
+		.start	= RD,
+		.end	= RD,
+		.flags	= IORESOURCE_MEM,
+        },
+        {
+		.start	= PORT_OTHER_INT(RD),
+		.end	= PORT_OTHER_INT(RD),
+		.flags	= IORESOURCE_IRQ,
+        },
+        {
+		.start	= 240000000,
+		.end	= 240000000,
+		.flags	= UBICOM32_SUART_IORESOURCE_CLOCK,
+        },
+};
+
+static struct platform_device ip5160dev_ubicom32_suart_device = {
+	.name		= "ubicom32suart",
+	.id		= -1,
+        .num_resources  = ARRAY_SIZE(ip5160dev_ubicom32_suart_resources),
+        .resource       = ip5160dev_ubicom32_suart_resources,
+};
+#endif
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip5160dev_devices[] __initdata = {
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+	&ip5160dev_ubicom32_suart_device,
+#endif
+	&ip5160dev_fdb_device,
+};
+
+/*
+ * ip5160dev_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip5160dev_init(void)
+{
+	ubi_gpio_init();
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip5160dev_devices, ARRAY_SIZE(ip5160dev_devices));
+	return 0;
+}
+
+arch_initcall(ip5160dev_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip5k/board-ip5160rgw.c
@@ -0,0 +1,76 @@
+/*
+ * arch/ubicom32/mach-ip5k/board-ip5160rgw.c
+ *   Platform initialization for ip5160rgw board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <asm/board.h>
+#include <asm/machdep.h>
+
+/*
+ * Factory Default Button on the board at PXn
+ * TODO: This is just a placeholder and it needs to include proper header files
+ */
+struct ubicom32fdb_platform_data {
+	int		fdb_gpio;
+	bool		fdb_polarity;
+};
+
+static struct ubicom32fdb_platform_data ip5160rgw_fdb_data = {
+	.fdb_gpio		= 0,
+	.fdb_polarity		= true,
+};
+
+static struct platform_device ip5160rgw_fdb_device = {
+	.name	= "ubicom32fdb",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip5160rgw_fdb_data,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip5160rgw_devices[] __initdata = {
+	&ip5160rgw_fdb_device,
+};
+
+/*
+ * ip5160rgw_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip5160rgw_init(void)
+{
+	ubi_gpio_init();
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip5160rgw_devices, ARRAY_SIZE(ip5160rgw_devices));
+	return 0;
+}
+
+arch_initcall(ip5160rgw_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip5k/board-ip5170dpf.c
@@ -0,0 +1,280 @@
+/*
+ * arch/ubicom32/mach-ip5k/board-ip5170dpf.c
+ *   Platform initialization for ip5160dpf board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+
+#include <linux/input.h>
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32hid.h>
+#include <asm/vdc_tio.h>
+
+/*
+ * LEDs
+ *
+ * WLAN			PD9	(Note this is shared with MISO, but we don't use it)
+ * WPS			PD8
+ *
+ * TODO: check triggers, are they generic?
+ */
+static struct gpio_led ip5170dpf_gpio_leds[] = {
+	{
+		.name			= "d31:green:WLAN1",
+		.default_trigger	= "WLAN1",
+		.gpio			= GPIO_RD_9,
+		.active_low		= 1,
+	},
+	{
+		.name			= "d30:green:WPS",
+		.default_trigger	= "WPS",
+		.gpio			= GPIO_RD_8,
+		.active_low		= 1,
+	},
+};
+
+static struct gpio_led_platform_data ip5170dpf_gpio_led_platform_data = {
+	.num_leds	= 2,
+	.leds		= ip5170dpf_gpio_leds,
+};
+
+static struct platform_device ip5170dpf_gpio_leds_device = {
+	.name		= "leds-gpio",
+	.id		= -1,
+	.dev = {
+		.platform_data = &ip5170dpf_gpio_led_platform_data,
+	},
+};
+
+/*
+ * Backlight on the board PD0, hardware PWM
+ */
+static const struct ubicom32hid_button ip5170dpf_ubicom32hid_buttons[] = {
+	{
+		.type	= EV_KEY,
+		.code	= KEY_UP,
+		.bit	= 0,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_LEFT,
+		.bit	= 1,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_RIGHT,
+		.bit	= 2,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_DOWN,
+		.bit	= 3,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_ENTER,
+		.bit	= 4,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_MENU,
+		.bit	= 5,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_ESC,
+		.bit	= 7,
+	},
+};
+
+static const struct ubicom32hid_ir ip5170dpf_ubicom32hid_ircodes[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_UP,
+		.ir_code	= 0xF807916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_DOWN,
+		.ir_code	= 0xF20D916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_LEFT,
+		.ir_code	= 0xF609916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_RIGHT,
+		.ir_code	= 0xF40B916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ENTER,
+		.ir_code	= 0xF50A916E
+	},
+	{	/* rotate */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F1,
+		.ir_code	= 0xF906916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MENU,
+		.ir_code	= 0xF708916E
+	},
+	{	/* font size */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F2,
+		.ir_code	= 0xF30C916E
+	},
+	{	
+		.type		= EV_KEY,
+		.code		= KEY_ESC,
+		.ir_code	= 0xF10E916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_VOLUMEUP,
+		.ir_code	= 0xF00F916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_VOLUMEDOWN,
+		.ir_code	= 0xED12916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MUTE,
+		.ir_code	= 0xEA15916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_INFO,
+		.ir_code	= 0xEF10916E
+	},
+	{	/* Like */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F3,
+		.ir_code	= 0xEE11916E
+	},
+	{	/* Dislike */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F4,
+		.ir_code	= 0xEB14916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_POWER,
+		.ir_code	= 0xFD02916E
+	},
+};
+
+static struct ubicom32hid_platform_data ip5170dpf_ubicom32hid_platform_data = {
+	.gpio_reset		= GPIO_RA_4,
+	.gpio_reset_polarity	= 0,
+	.type			= UBICOM32HID_BL_TYPE_BINARY,
+	.invert			= 0,
+	.default_intensity	= 1,
+	.buttons		= ip5170dpf_ubicom32hid_buttons,
+	.nbuttons		= ARRAY_SIZE(ip5170dpf_ubicom32hid_buttons),
+	.ircodes		= ip5170dpf_ubicom32hid_ircodes,
+	.nircodes		= ARRAY_SIZE(ip5170dpf_ubicom32hid_ircodes),
+};
+
+/*
+ * Devices on the I2C bus
+ */
+static struct i2c_board_info __initdata ip5170dpf_i2c_board_info[] = {
+	/*
+	 * U24, ubicom32hid
+	 */
+	{
+		.type		= "ubicom32hid",
+		.addr		= 0x08,
+		.platform_data	= &ip5170dpf_ubicom32hid_platform_data,
+	},
+
+	/*
+	 * U14, CS4350 DAC, address 0x4B
+	 */
+};
+
+/*
+ * I2C bus on the board, SDA PF13, SCL PF14
+ */
+static struct i2c_gpio_platform_data ip5170dpf_i2c_data = {
+	.sda_pin		= GPIO_RF_13,
+	.scl_pin		= GPIO_RF_14,
+	.sda_is_open_drain	= 0,
+	.scl_is_open_drain	= 0,
+	.scl_is_output_only	= 1,
+	.udelay			= 5,
+};
+
+static struct platform_device ip5170dpf_i2c_device = {
+	.name	= "i2c-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip5170dpf_i2c_data,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip5170dpf_devices[] __initdata = {
+	&ip5170dpf_i2c_device,
+	&ip5170dpf_gpio_leds_device,
+};
+
+/*
+ * ip5170dpf_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip5170dpf_init(void)
+{
+	ubi_gpio_init();
+
+	vdc_tio_init();
+
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip5170dpf_devices, ARRAY_SIZE(ip5170dpf_devices));
+
+	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
+	i2c_register_board_info(0, ip5170dpf_i2c_board_info, ARRAY_SIZE(ip5170dpf_i2c_board_info));
+
+	return 0;
+}
+
+arch_initcall(ip5170dpf_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip5k/Kconfig
@@ -0,0 +1,32 @@
+
+config IP5170DPF
+	bool "IP5170DPF"
+	select UBICOM32_V3
+	select I2C
+	select I2C_GPIO
+	select FB
+	select FB_UBICOM32
+	select BACKLIGHT_LCD_SUPPORT
+	select BACKLIGHT_CLASS_DEVICE
+	select UBICOM_HID
+	select NEW_LEDS
+	select LEDS_CLASS
+	select LEDS_GPIO
+	select BRD_64MB
+	help
+		IP5170 Digital Picture Frame board, 8005-1113, IP5K-BEV-0011-13 v1.3
+
+config IP5160DEV
+	bool "IP5160Dev_Ver1Dot1"
+	select UBICOM32_V3
+	select BRD_64MB
+	help
+		Ubicom StreamEngine 5000 Development Board, IP5K-BDV-0004-11 v1.1
+
+config IP5160EVAL
+	bool "IP5160RGWEval_Ver2Rev2"
+	select UBICOM32_V3
+	select BRD_32MB
+	help
+		Ubicom StreamEngine 5000 RGW Evaluation Board, IP5K-RGW-0004-11 v2.2
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip5k/Makefile
@@ -0,0 +1,32 @@
+#
+# arch/ubicom32/mach-ip5k/Makefile
+#	Makefile for boards which have an ip5k on them.
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+obj-$(CONFIG_IP5170DPF)		+= board-ip5170dpf.o
+obj-$(CONFIG_IP5160DEV)		+= board-ip5160dev.o
+obj-$(CONFIG_IP5160EVAL)	+= board-ip5160rgw.o
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7145dpf.c
@@ -0,0 +1,716 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7145dpf.c
+ *   Board file for IP7145DPF, rev 1.0, P/N 8007-0410
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <linux/input.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+#include <linux/i2c/pca953x.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32input.h>
+#include <asm/ubicom32input_i2c.h>
+#include <asm/ubicom32bl.h>
+#include <asm/ubicom32lcd.h>
+#include <asm/vdc_tio.h>
+
+#include <asm/ubicom32sd.h>
+#include <asm/sd_tio.h>
+#include <asm/devtree.h>
+#include <asm/audio_tio.h>
+
+#include <asm/ring_tio.h>
+
+/******************************************************************************
+ * SD/IO Port F (Slot 1) platform data
+ */
+static struct resource ip7145dpf_portf_sd_resources[] = {
+	/*
+	 * Send IRQ
+	 */
+	[0] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Receive IRQ
+	 */
+	[1] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Memory Mapped Registers
+	 */
+	[2] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct ubicom32sd_card ip7145dpf_portf_sd_cards[] = {
+	[0] = {
+		.pin_wp		= IP7145DPF_IOB0,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7145DPF_IOB4,
+		.pin_cd		= GPIO_RA_4,
+	},
+	[1] = {
+		.pin_wp		= IP7145DPF_IOB1,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7145DPF_IOB5,
+		.pin_cd		= GPIO_RA_6,
+	},
+};
+
+static struct ubicom32sd_platform_data ip7145dpf_portf_sd_platform_data = {
+	.ncards		= 2,
+	.cards		= ip7145dpf_portf_sd_cards, 
+};
+
+static struct platform_device ip7145dpf_portf_sd_device = {
+	.name		= "ubicom32sd",
+	.id		= 0,
+	.resource	= ip7145dpf_portf_sd_resources,
+	.num_resources	= ARRAY_SIZE(ip7145dpf_portf_sd_resources),
+	.dev		= {
+			.platform_data = &ip7145dpf_portf_sd_platform_data,
+	},
+
+};
+
+/*
+ * ip7145dpf_portf_sd_init
+ */
+static void ip7145dpf_portf_sd_init(void)
+{
+	/*
+	 * Check the device tree for the sd_tio
+	 */
+	struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portf_sd");
+	if (!sd_node) {
+		printk(KERN_INFO "PortF SDTIO not found\n");
+		return;
+	}
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	ip7145dpf_portf_sd_resources[0].start = sd_node->dn.sendirq;
+	ip7145dpf_portf_sd_resources[1].start = sd_node->dn.recvirq;
+	ip7145dpf_portf_sd_resources[2].start = (u32_t)&(sd_node->regs);
+	ip7145dpf_portf_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
+
+	platform_device_register(&ip7145dpf_portf_sd_device);
+}
+
+/******************************************************************************
+ * SD/IO Port B (Slot 2) platform data
+ */
+static struct resource ip7145dpf_portb_sd_resources[] = {
+	/*
+	 * Send IRQ
+	 */
+	[0] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Receive IRQ
+	 */
+	[1] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Memory Mapped Registers
+	 */
+	[2] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct ubicom32sd_card ip7145dpf_portb_sd_cards[] = {
+	[0] = {
+		.pin_wp		= IP7145DPF_IOB2,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7145DPF_IOB6,
+		.pin_cd		= IP7145DPF_IOB3,
+	},
+};
+
+static struct ubicom32sd_platform_data ip7145dpf_portb_sd_platform_data = {
+	.ncards		= 1,
+	.cards		= ip7145dpf_portb_sd_cards,
+};
+
+static struct platform_device ip7145dpf_portb_sd_device = {
+	.name		= "ubicom32sd",
+	.id		= 1,
+	.resource	= ip7145dpf_portb_sd_resources,
+	.num_resources	= ARRAY_SIZE(ip7145dpf_portb_sd_resources),
+	.dev		= {
+			.platform_data = &ip7145dpf_portb_sd_platform_data,
+	},
+
+};
+
+/*
+ * ip7145dpf_portb_sd_init
+ */
+static void ip7145dpf_portb_sd_init(void)
+{
+	/*
+	 * Check the device tree for the sd_tio
+	 */
+	struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portb_sd");
+	if (!sd_node) {
+		printk(KERN_INFO "PortB SDTIO not found\n");
+		return;
+	}
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	ip7145dpf_portb_sd_resources[0].start = sd_node->dn.sendirq;
+	ip7145dpf_portb_sd_resources[1].start = sd_node->dn.recvirq;
+	ip7145dpf_portb_sd_resources[2].start = (u32_t)&(sd_node->regs);
+	ip7145dpf_portb_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
+
+	platform_device_register(&ip7145dpf_portb_sd_device);
+}
+
+
+#ifdef IP7145DPF_USE_MMC_SPI
+/******************************************************************************
+ * SPI over GPIO (MMC_SPI)
+ */
+#include <linux/spi/spi.h>
+#include <linux/spi/mmc_spi.h>
+#include <linux/mmc/host.h>
+#include <asm/ubicom32-spi-gpio.h>
+
+#define MMC_CS	GPIO_RF_5	// PF5 D3
+#define MMC_CD	GPIO_RA_4	// PA4 CD
+#define MMC_WP	IP7145DPF_IOB0	// IOB0 WP
+#define MMC_PWR	IP7145DPF_IOB4	// IOB4 PWR
+
+/*
+ * SPI bus over GPIO (for SD card)
+ */
+static struct ubicom32_spi_gpio_platform_data ip7145dpf_spi_gpio_data = {
+	.pin_mosi	= GPIO_RF_0,	// PF0 CMD
+	.pin_miso	= GPIO_RF_2,	// PF2 D0
+	.pin_clk	= GPIO_RF_1,	// PF1 CLK
+	.bus_num	= 0,		// We'll call this SPI bus 0
+	.num_chipselect	= 1,		// only one device on this SPI bus 
+};
+
+static struct platform_device ip7145dpf_spi_gpio_device = {
+	.name	= "ubicom32-spi-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7145dpf_spi_gpio_data,
+	},
+};
+
+/*
+ * ip7145dpf_mmc_spi_setpower_slot_a
+ *	Set the power state for slot A
+ */
+static void ip7145dpf_mmc_spi_setpower_slot_a(struct device *dev, unsigned int vdd)
+{
+	struct mmc_spi_platform_data *pd = dev->platform_data;
+
+	/*
+	 * Power is inverted, we could tell the IOB to do it, but it's cleaner this way.
+	 */
+	if ((1 << vdd) & pd->ocr_mask) {
+		gpio_set_value(MMC_PWR, 0);
+		return;
+	}
+	gpio_set_value(MMC_PWR, 1);
+}
+
+/*
+ * ip7145dpf_mmc_spi_get_cd_slot_a
+ *	Get the CD bit for slot A
+ */
+static int ip7145dpf_mmc_spi_get_cd_slot_a(struct device *dev)
+{
+	/*
+	 * Note that the sense of the GPIO is inverted
+	 */
+	return !gpio_get_value(MMC_CD);
+}
+
+/*
+ * ip7145dpf_mmc_spi_get_ro_slot_a
+ *	Get the WP bit for slot A
+ */
+static int ip7145dpf_mmc_spi_get_ro_slot_a(struct device *dev)
+{
+	/*
+	 * Note that the sense of the GPIO is inverted, we could tell the IOB to do it, but
+	 * it's clearer this way.
+	 */
+	return !gpio_get_value(MMC_WP);
+}
+
+/*
+ * ip7145dpf_mmc_spi_exit_slot_a
+ *	Free the appropriate GPIOs for slot A SD slot.
+ */
+static void ip7145dpf_mmc_spi_exit_slot_a(struct device *dev, void *appdata)
+{
+	gpio_free(MMC_CD);
+	gpio_free(MMC_CS);
+	gpio_free(MMC_WP);
+	gpio_free(MMC_PWR);
+	platform_device_unregister(&ip7145dpf_spi_gpio_device);
+}
+
+/*
+ * ip7145dpf_mmc_spi_init_slot_a
+ *	Allocate the appropriate GPIOs for slot A SD slot.
+ *	WP is on IOB0, CD is PA4, CS is on PF5
+ *	TODO: make CD an interrupt
+ */
+static int ip7145dpf_mmc_spi_init_slot_a(void)
+{
+	int ret = gpio_request(MMC_CD, "mmc-a-cd");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request mmc-a-cd pin\n", __FUNCTION__);
+		return -ENOSYS;
+	}
+	gpio_direction_input(MMC_CD);
+
+	ret = gpio_request(MMC_CS, "mmc-a-cs");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request mmc-a-cs pin\n", __FUNCTION__);
+		goto no_cs;
+	}
+	gpio_direction_output(MMC_CS, 0);
+
+	ret = gpio_request(MMC_WP, "mmc-a-wp");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request mmc-a-wp pin\n", __FUNCTION__);
+		goto no_wp;
+	}
+	gpio_direction_input(MMC_WP);
+
+	/*
+	 * Start off with power off
+	 */
+	ret = gpio_request(MMC_PWR, "mmc-a-pwr");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request mmc-a-pwr pin\n", __FUNCTION__);
+		goto no_pwr;
+	}
+	ret = gpio_direction_output(MMC_PWR, 1);
+
+	return 0;
+
+no_pwr:
+	gpio_free(MMC_WP);
+
+no_wp:
+	gpio_free(MMC_CS);
+
+no_cs:
+	gpio_free(MMC_CD);
+	return -ENOSYS;
+}
+
+/*
+ * MMC_SPI driver (currently bitbang)
+ */
+static struct mmc_spi_platform_data ip7145dpf_mmc_platform_data = {
+	.ocr_mask	= MMC_VDD_33_34,
+	.exit		= ip7145dpf_mmc_spi_exit_slot_a,
+	.get_ro		= ip7145dpf_mmc_spi_get_ro_slot_a,
+	.get_cd		= ip7145dpf_mmc_spi_get_cd_slot_a,
+
+	.setpower	= ip7145dpf_mmc_spi_setpower_slot_a,
+	.powerup_msecs	= 500,
+
+	.detect_delay	= 100,
+
+	.caps		= MMC_CAP_NEEDS_POLL,
+};
+
+static struct ubicom32_spi_gpio_controller_data ip7145dpf_mmc_controller_data = {
+	.pin_cs =  MMC_CS,
+};
+
+static struct spi_board_info ip7145dpf_spi_board_info[] = {
+	{
+		.modalias = "mmc_spi",
+		.bus_num = 0,
+		.chip_select = 0,
+		.max_speed_hz = 2000000,
+		.platform_data = &ip7145dpf_mmc_platform_data,
+		.controller_data = &ip7145dpf_mmc_controller_data,
+	}
+};
+#endif /* IP7145DPF_USE_MMC_SPI */
+
+/*
+ * ip7145dpf_u72_setup
+ *	Called by I2C to tell us that u72 is setup.
+ *
+ * This function is called by I2C to tell us that u72 has been setup.  All
+ * devices which rely on this chip being initialized (or even present) need to
+ * be initialized in this function otherwise they may get initialized too early.
+ *
+ * Currently the only device depending on u72 is the SPI
+ */
+static int __init ip7145dpf_u72_setup(struct i2c_client *client, unsigned gpio, unsigned ngpio, void *context)
+{
+#ifdef IP7145DPF_USE_MMC_SPI
+	if (ip7145dpf_mmc_spi_init_slot_a()) {
+		printk(KERN_ERR "%s: could not request mmc resources\n", __FUNCTION__);
+	} else {
+		printk(KERN_INFO "%s: registering SPI resources\n", __FUNCTION__);
+		spi_register_board_info(ip7145dpf_spi_board_info, ARRAY_SIZE(ip7145dpf_spi_board_info));
+		platform_device_register(&ip7145dpf_spi_gpio_device);
+	}
+#else
+	/*
+	 * Initialize the Port F/Port B SD slots
+	 */
+	ip7145dpf_portf_sd_init();
+	ip7145dpf_portb_sd_init();
+#endif
+	return 0;
+}
+
+/******************************************************************************
+ * LCD VGH on the board at PE6
+ */
+static struct ubicom32lcd_platform_data ip7145dpf_lcd_data = {
+	.vgh_gpio		= GPIO_RE_6,
+	.vgh_polarity		= true,
+};
+
+static struct platform_device ip7145dpf_lcd_device = {
+	.name	= "ubicom32lcd",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7145dpf_lcd_data,
+	},
+};
+
+/******************************************************************************
+ * Backlight on the board PD0, hardware PWM
+ */
+static struct ubicom32bl_platform_data ip7145dpf_backlight_data = {
+	.type			= UBICOM32BL_TYPE_PWM,
+	.pwm_channel		= 2,
+	.pwm_prescale		= 15,
+	.pwm_period		= 60,
+	.default_intensity	= 0x80,
+};
+
+static struct platform_device ip7145dpf_backlight_device = {
+	.name	= "ubicom32bl",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7145dpf_backlight_data,
+	},
+};
+
+/******************************************************************************
+ * Ubicom32Input on I2C, U48 MAX7310, address 0x18, 8 bits
+ */
+static struct ubicom32input_i2c_button ip7145dpf_ubicom32input_i2c_u48_buttons[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_UP,
+		.bit		= 0,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_LEFT,
+		.bit		= 1,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_RIGHT,
+		.bit		= 2,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_DOWN,
+		.bit		= 3,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ENTER,
+		.bit		= 4,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MENU,
+		.bit		= 5,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ESC,
+		.bit		= 6,
+		.active_low	= 1,
+	},
+};
+
+static struct ubicom32input_i2c_platform_data ip7145dpf_ubicom32input_i2c_u48_platform_data = {
+	.buttons	= ip7145dpf_ubicom32input_i2c_u48_buttons,
+	.nbuttons	= ARRAY_SIZE(ip7145dpf_ubicom32input_i2c_u48_buttons),
+	.name		= "Ubicom32 Input I2C U48",
+};
+
+/******************************************************************************
+ * Additional GPIO chips
+ */
+static struct pca953x_platform_data ip7145dpf_gpio_u72_platform_data = {
+	.gpio_base = IP7145DPF_U72_BASE,
+	.setup = ip7145dpf_u72_setup,
+};
+
+/******************************************************************************
+ * Devices on the I2C bus
+ */
+static struct i2c_board_info __initdata ip7145dpf_i2c_board_info[] = {
+	/*
+	 * U51, S35390A RTC, address 0x30
+	 */
+	{
+		.type		= "s35390a",
+		.addr		= 0x30,
+	},
+
+	/*
+	 * U48, MAX7310 IO expander, 8 bits, address 0x18
+	 */
+	{
+		.type		= "ubicom32in_max7310",
+		.addr		= 0x18,
+		.platform_data	= &ip7145dpf_ubicom32input_i2c_u48_platform_data,
+	},
+
+	/*
+	 * U72, MAX7310 IOB expander, 8 bits, address 0x19
+	 */
+	{
+		.type		= "max7310",
+		.addr		= 0x19,
+		.platform_data	= &ip7145dpf_gpio_u72_platform_data,
+	},
+};
+
+/*
+ * I2C bus on the board, SDA PE1, SCL PE2
+ */
+static struct i2c_gpio_platform_data ip7145dpf_i2c_data = {
+	.sda_pin		= GPIO_RE_1,
+	.scl_pin		= GPIO_RE_2,
+	.sda_is_open_drain	= 0,
+	.scl_is_open_drain	= 0,
+};
+
+static struct platform_device ip7145dpf_i2c_device = {
+	.name	= "i2c-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7145dpf_i2c_data,
+	},
+};
+
+/******************************************************************************
+ * Use ubicom32input driver to monitor the various pushbuttons on this board.
+ *
+ * WPS			PF12
+ * FACT_DEFAULT		PF13
+ * POWER		PE4
+ *
+ * Not sutable for the keypad buttons since those run on I2C GPIO.  The polling
+ * of ubicom32input would seem to be excessive for this.
+ *
+ * TODO: pick some ubicom understood EV_xxx define for WPS and Fact Default
+ */
+static struct ubicom32input_button ip7145dpf_ubicom32input_buttons[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F1,
+		.gpio		= GPIO_RF_12,
+		.desc		= "WPS",
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F2,
+		.gpio		= GPIO_RF_13,
+		.desc		= "Factory Default",
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_POWER,
+		.gpio		= GPIO_RE_4,
+		.desc		= "Power",
+		.active_low	= 1,
+	},
+};
+
+static struct ubicom32input_platform_data ip7145dpf_ubicom32input_data = {
+	.buttons	= ip7145dpf_ubicom32input_buttons,
+	.nbuttons	= ARRAY_SIZE(ip7145dpf_ubicom32input_buttons),
+};
+
+static struct platform_device ip7145dpf_ubicom32input_device = {
+	.name	= "ubicom32input",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7145dpf_ubicom32input_data,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7145dpf_devices[] __initdata = {
+	&ip7145dpf_i2c_device,
+	&ip7145dpf_lcd_device,
+	&ip7145dpf_backlight_device,
+	&ip7145dpf_ubicom32input_device,
+};
+
+/*
+ * ip7145dpf_power_off
+ *	Called to turn the power off for this board
+ */
+static void ip7145dpf_power_off(void)
+{
+	gpio_set_value(GPIO_RE_5, 0);
+}
+
+/*
+ * ip7145dpf_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7145dpf_init(void)
+{
+	int ret;
+	struct platform_device *audio_dev;
+
+	ubi_gpio_init();
+
+#ifdef CONFIG_UIO_UBICOM32RING
+	ring_tio_init("decoder_ring");
+#endif
+
+	/*
+	 * Start up the video driver first
+	 */
+	vdc_tio_init();
+
+	/*
+	 * Take over holding of the power from the system
+	 */
+	ret = gpio_request(GPIO_RE_5, "power_hold");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request power hold GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RE_5, 1);
+	mach_power_off = ip7145dpf_power_off;
+
+	/*
+	 * USB SEL_HOST_USB line
+	 */
+	ret = gpio_request(GPIO_RF_11, "SEL_HOST_USB");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request SEL_HOST_USB GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RF_11, 0);
+
+	/*
+	 * Setup audio
+	 */
+	audio_dev = audio_tio_alloc("snd-ubi32-generic", "audiotio-i2sout", 0);
+	if (audio_dev) {
+		platform_device_register(audio_dev);
+	}
+
+	/*
+	 * Register all of the devices we have on this board
+	 */
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7145dpf_devices, ARRAY_SIZE(ip7145dpf_devices));
+
+	/*
+	 * Register all of the devices which sit on the I2C bus
+	 */
+	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
+	i2c_register_board_info(0, ip7145dpf_i2c_board_info, ARRAY_SIZE(ip7145dpf_i2c_board_info));
+
+	/*
+	 * We have to initialize the SPI after the I2C IOB gets setup. SPI is initialized in 
+	 * ip7145dpf_u72_setup
+	 */
+
+	return 0;
+}
+
+arch_initcall(ip7145dpf_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7160bringup.c
@@ -0,0 +1,135 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7160bringup.c
+ *   Support for the IP7160 bringup board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32input.h>
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+#include <asm/ubicom32suart.h>
+#endif
+
+/*
+ * Use ubicom32input driver to monitor the various pushbuttons on this board.
+ *
+ * WPS			PD5
+ * FACT_DEFAULT		PD6
+ *
+ * TODO: pick some ubicom understood EV_xxx define for WPS and Fact Default
+ */
+static struct ubicom32input_button ip7160bringup_ubicom32input_buttons[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F1,
+		.gpio		= GPIO_RD_5,
+		.desc		= "WPS",
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F2,
+		.gpio		= GPIO_RD_6,
+		.desc		= "Factory Default",
+		.active_low	= 1,
+	},
+};
+
+static struct ubicom32input_platform_data ip7160bringup_ubicom32input_data = {
+	.buttons	= ip7160bringup_ubicom32input_buttons,
+	.nbuttons	= ARRAY_SIZE(ip7160bringup_ubicom32input_buttons),
+};
+
+static struct platform_device ip7160bringup_ubicom32input_device = {
+	.name	= "ubicom32input",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7160bringup_ubicom32input_data,
+	},
+};
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+static struct resource ip7160bringup_ubicom32_suart_resources[] = {
+	{
+		.start	= RE,
+		.end	= RE,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= PORT_OTHER_INT(RE),
+		.end	= PORT_OTHER_INT(RE),
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.start	= 250000000,
+		.end	= 250000000,
+		.flags	= UBICOM32_SUART_IORESOURCE_CLOCK,
+	},
+};
+
+static struct platform_device ip7160bringup_ubicom32_suart_device = {
+	.name		= "ubicom32suart",
+	.id		= -1,
+	.num_resources  = ARRAY_SIZE(ip7160bringup_ubicom32_suart_resources),
+	.resource	= ip7160bringup_ubicom32_suart_resources,
+};
+#endif
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7160bringup_devices[] __initdata = {
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+	&ip7160bringup_ubicom32_suart_device,
+#endif
+	&ip7160bringup_ubicom32input_device,
+};
+
+/*
+ * ip7160bringup_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7160bringup_init(void)
+{
+	board_init();
+
+	ubi_gpio_init();
+
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7160bringup_devices, ARRAY_SIZE(ip7160bringup_devices));
+
+	return 0;
+}
+
+arch_initcall(ip7160bringup_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7160dpf.c
@@ -0,0 +1,327 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7160dpf.c
+ *   Platform initialization for ip7160dpf board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+
+#include <linux/input.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32hid.h>
+#include <asm/vdc_tio.h>
+#include <asm/audio_tio.h>
+
+/*
+ * Backlight on the board PD0, hardware PWM
+ */
+static const struct ubicom32hid_button ip7160dpf_ubicom32hid_buttons[] = {
+	{
+		.type	= EV_KEY,
+		.code	= KEY_UP,
+		.bit	= 0,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_LEFT,
+		.bit	= 1,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_RIGHT,
+		.bit	= 2,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_DOWN,
+		.bit	= 3,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_ENTER,
+		.bit	= 4,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_MENU,
+		.bit	= 5,
+	},
+	{
+		.type	= EV_KEY,
+		.code	= KEY_ESC,
+		.bit	= 7,
+	},
+};
+
+static const struct ubicom32hid_ir ip7160dpf_ubicom32hid_ircodes[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_UP,
+		.ir_code	= 0xF807916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_DOWN,
+		.ir_code	= 0xF20D916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_LEFT,
+		.ir_code	= 0xF609916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_RIGHT,
+		.ir_code	= 0xF40B916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ENTER,
+		.ir_code	= 0xF50A916E
+	},
+	{	/* rotate */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F1,
+		.ir_code	= 0xF906916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MENU,
+		.ir_code	= 0xF708916E
+	},
+	{	/* font size */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F2,
+		.ir_code	= 0xF30C916E
+	},
+	{	
+		.type		= EV_KEY,
+		.code		= KEY_ESC,
+		.ir_code	= 0xF10E916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_VOLUMEUP,
+		.ir_code	= 0xF00F916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_VOLUMEDOWN,
+		.ir_code	= 0xED12916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MUTE,
+		.ir_code	= 0xEA15916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_INFO,
+		.ir_code	= 0xEF10916E
+	},
+	{	/* Like */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F3,
+		.ir_code	= 0xEE11916E
+	},
+	{	/* Dislike */
+		.type		= EV_KEY,
+		.code		= KEY_FN_F4,
+		.ir_code	= 0xEB14916E
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_POWER,
+		.ir_code	= 0xFD02916E
+	},
+};
+
+static struct ubicom32hid_platform_data ip7160dpf_ubicom32hid_platform_data = {
+	.gpio_reset		= GPIO_RI_5,
+	.gpio_reset_polarity	= 0,
+	.type			= UBICOM32HID_BL_TYPE_PWM,
+	.invert			= 0,
+	.default_intensity	= 128,
+	.buttons		= ip7160dpf_ubicom32hid_buttons,
+	.nbuttons		= ARRAY_SIZE(ip7160dpf_ubicom32hid_buttons),
+	.ircodes		= ip7160dpf_ubicom32hid_ircodes,
+	.nircodes		= ARRAY_SIZE(ip7160dpf_ubicom32hid_ircodes),
+};
+
+/*
+ * Devices on the I2C bus
+ *	This board has a "bus 2" which is isolated from the main bus by U47
+ *	and pin RI0.  It should be safe to always enable bus 2 by setting
+ *	RI0 to low, however, it should be noted that on all existing configurations
+ *	of this board, U49 and U51 are not populated.
+ */
+static struct i2c_board_info __initdata ip7160dpf_i2c_board_info[] = {
+	/*
+	 * U37, CS4350 DAC, address 0x4B, bus 2
+	 *	THIS ENTRY MUST BE FIRST
+	 */
+	{
+		.type		= "cs4350",
+		.addr		= 0x4B,
+	}
+
+	/*
+	 * U24, ubicom32hid
+	 */
+	{
+		.type		= "ubicom32hid",
+		.addr		= 0x08,
+		.platform_data	= &ip7160dpf_ubicom32hid_platform_data,
+	},
+
+	/*
+	 * U49, ISL29001 Ambient Light Sensor, address 0x44, bus 2 (may not be stuffed)
+	 */
+
+	/*
+	 * U51, S35390A RTC, address 0x30, bus 2 (may not be stuffed)
+	 */
+#ifdef CONFIG_RTC_DRV_S35390A
+	{
+		.type           = "s35390a",
+		.addr           = 0x30,
+	},
+#endif
+};
+
+/*
+ * I2C bus on the board, SDA PI1, SCL PI2
+ */
+static struct i2c_gpio_platform_data ip7160dpf_i2c_data = {
+	.sda_pin		= GPIO_RI_1,
+	.scl_pin		= GPIO_RI_2,
+	.sda_is_open_drain	= 0,
+	.scl_is_open_drain	= 0,
+	.scl_is_output_only	= 1,
+	.udelay			= 6,
+};
+
+static struct platform_device ip7160dpf_i2c_device = {
+	.name	= "i2c-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7160dpf_i2c_data,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7160dpf_devices[] __initdata = {
+	&ip7160dpf_i2c_device,
+};
+
+/*
+ * ip7160dpf_power_off
+ *	Called to turn the power off for this board
+ */
+static void ip7160dpf_power_off(void)
+{
+	gpio_set_value(GPIO_RF_14, 0);
+}
+
+/*
+ * ip7160dpf_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7160dpf_init(void)
+{
+	int ret;
+	struct platform_device *audio_dev;
+
+	ubi_gpio_init();
+
+	/*
+	 * Hold the POWER_HOLD line
+	 */
+	ret = gpio_request(GPIO_RF_14, "POWER_HOLD");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request POWER_HOLD GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RF_14, 0);
+	mach_power_off = ip7160dpf_power_off;
+
+	/*
+	 * USB SEL_HOST_USB line
+	 */
+	ret = gpio_request(GPIO_RI_13, "SEL_HOST_USB");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request SEL_HOST_USB GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RI_13, 0);
+
+	/*
+	 * USB/DAC nRESET line
+	 */
+	ret = gpio_request(GPIO_RI_3, "USB_DAC_nRESET");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request USB_DAC_nRESET GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RI_3, 0);
+	udelay(1);
+	gpio_direction_output(GPIO_RI_3, 1);
+
+	/*
+	 * I2C BUS2 Disable line
+	 */
+	ret = gpio_request(GPIO_RI_0, "DISABLE_BUS2");
+	if (ret) {
+		printk(KERN_ERR "%s: could not request DISABLE_BUS2 GPIO\n", __FUNCTION__);
+	}
+	gpio_direction_output(GPIO_RI_0, 0);
+
+	vdc_tio_init();
+
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7160dpf_devices, ARRAY_SIZE(ip7160dpf_devices));
+
+	/*
+	 * Allocate the audio driver if we can
+	 */
+	audio_dev = audio_tio_alloc("snd-ubi32-cs4350", "audiotio-i2sout", 0);
+	if (audio_dev) {
+		ip7160dpf_i2c_board_info[0].platform_data = audio_dev;
+	}
+
+	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
+	i2c_register_board_info(0, ip7160dpf_i2c_board_info, ARRAY_SIZE(ip7160dpf_i2c_board_info));
+
+	return 0;
+}
+
+arch_initcall(ip7160dpf_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7160rgw.c
@@ -0,0 +1,255 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7160rgw.c
+ *   Platform initialization for ip7160rgw board.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/spi/spi.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32input.h>
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+#include <asm/ubicom32suart.h>
+#endif
+
+#include <asm/ubicom32-spi-gpio.h>
+#include <asm/switch-bcm539x.h>
+
+/*
+ * SPI bus over GPIO for Gigabit Ethernet Switch
+ *	U58:
+ *		MOSI	PE0
+ *		MISO	PE1
+ *		CLK	PE3
+ *		CS	PE2
+ */
+static struct ubicom32_spi_gpio_platform_data ip7160rgw_spi_gpio_data = {
+	.pin_mosi	= GPIO_RE_0,
+	.pin_miso	= GPIO_RE_1,
+	.pin_clk	= GPIO_RE_3,
+	.bus_num	= 0,		// We'll call this SPI bus 0
+	.num_chipselect	= 1,		// only one device on this SPI bus 
+	.clk_default	= 1,
+};
+
+static struct platform_device ip7160rgw_spi_gpio_device = {
+	.name	= "ubicom32-spi-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7160rgw_spi_gpio_data,
+	},
+};
+
+static struct ubicom32_spi_gpio_controller_data ip7160rgw_bcm539x_controller_data = {
+	.pin_cs = GPIO_RE_2,
+};
+
+static struct switch_bcm539x_platform_data ip7160rgw_bcm539x_platform_data = {
+	.flags		= SWITCH_BCM539X_FLAG_HW_RESET,
+	.pin_cs		= GPIO_RE_2,
+	.pin_reset	= GPIO_RE_4,
+	.name		= "bcm539x",
+};
+
+static struct spi_board_info ip7160rgw_spi_board_info[] = {
+	{
+		.modalias		= "bcm539x-spi",
+		.bus_num		= 0,
+		.chip_select		= 0,
+		.max_speed_hz		= 2000000,
+		.platform_data		= &ip7160rgw_bcm539x_platform_data,
+		.controller_data	= &ip7160rgw_bcm539x_controller_data,
+		.mode			= SPI_MODE_3,
+	}
+};
+
+/*
+ * LEDs
+ *
+ * WLAN1		PD0	(PWM capable)
+ * WLAN2		PD1
+ * USB2.0		PD2
+ * Status		PD3
+ * WPS			PD4
+ *
+ * TODO: check triggers, are they generic?
+ */
+static struct gpio_led ip7160rgw_gpio_leds[] = {
+	{
+		.name			= "d53:green:WLAN1",
+		.default_trigger	= "WLAN1",
+		.gpio			= GPIO_RD_0,
+		.active_low		= 1,
+	},
+	{
+		.name			= "d54:green:WLAN2",
+		.default_trigger	= "WLAN2",
+		.gpio			= GPIO_RD_1,
+		.active_low		= 1,
+	},
+	{
+		.name			= "d55:green:USB",
+		.default_trigger	= "USB",
+		.gpio			= GPIO_RD_2,
+		.active_low		= 1,
+	},
+	{
+		.name			= "d56:green:Status",
+		.default_trigger	= "Status",
+		.gpio			= GPIO_RD_3,
+		.active_low		= 1,
+	},
+	{
+		.name			= "d57:green:WPS",
+		.default_trigger	= "WPS",
+		.gpio			= GPIO_RD_4,
+		.active_low		= 1,
+	},
+};
+
+static struct gpio_led_platform_data ip7160rgw_gpio_led_platform_data = {
+	.num_leds	= 5,
+	.leds		= ip7160rgw_gpio_leds,
+};
+
+static struct platform_device ip7160rgw_gpio_leds_device = {
+	.name		= "leds-gpio",
+	.id		= -1,
+	.dev = {
+		.platform_data = &ip7160rgw_gpio_led_platform_data,
+	},
+};
+
+/*
+ * Use ubicom32input driver to monitor the various pushbuttons on this board.
+ *
+ * WPS			PD5
+ * FACT_DEFAULT		PD6
+ *
+ * TODO: pick some ubicom understood EV_xxx define for WPS and Fact Default
+ */
+static struct ubicom32input_button ip7160rgw_ubicom32input_buttons[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F1,
+		.gpio		= GPIO_RD_5,
+		.desc		= "WPS",
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_FN_F2,
+		.gpio		= GPIO_RD_6,
+		.desc		= "Factory Default",
+		.active_low	= 1,
+	},
+};
+
+static struct ubicom32input_platform_data ip7160rgw_ubicom32input_data = {
+	.buttons	= ip7160rgw_ubicom32input_buttons,
+	.nbuttons	= ARRAY_SIZE(ip7160rgw_ubicom32input_buttons),
+};
+
+static struct platform_device ip7160rgw_ubicom32input_device = {
+	.name	= "ubicom32input",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7160rgw_ubicom32input_data,
+	},
+};
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+static struct resource ip7160rgw_ubicom32_suart_resources[] = {
+	{
+		.start	= RE,
+		.end	= RE,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= PORT_OTHER_INT(RE),
+		.end	= PORT_OTHER_INT(RE),
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.start	= 250000000,
+		.end	= 250000000,
+		.flags	= UBICOM32_SUART_IORESOURCE_CLOCK,
+	},
+};
+
+static struct platform_device ip7160rgw_ubicom32_suart_device = {
+	.name		= "ubicom32suart",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(ip7160rgw_ubicom32_suart_resources),
+	.resource	= ip7160rgw_ubicom32_suart_resources,
+};
+#endif
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7160rgw_devices[] __initdata = {
+#ifdef CONFIG_SERIAL_UBI32_SERDES
+	&ip7160rgw_ubicom32_suart_device,
+#endif
+	&ip7160rgw_ubicom32input_device,
+	&ip7160rgw_gpio_leds_device,
+	&ip7160rgw_spi_gpio_device,
+};
+
+/*
+ * ip7160rgw_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7160rgw_init(void)
+{
+	board_init();
+
+	/*
+	 * Rev 1.2 boards have spi in a different place than 1.1/1.0
+	 */
+	if (strcmp(board_get_revision(), "1.2") == 0) {
+		ip7160rgw_spi_gpio_data.pin_mosi = GPIO_RD_7;
+	}
+
+	ubi_gpio_init();
+
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7160rgw_devices, ARRAY_SIZE(ip7160rgw_devices));
+
+	printk(KERN_INFO "%s: registering SPI resources\n", __FUNCTION__);
+	spi_register_board_info(ip7160rgw_spi_board_info, ARRAY_SIZE(ip7160rgw_spi_board_info));
+
+	return 0;
+}
+
+arch_initcall(ip7160rgw_init);
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7500av.c
@@ -0,0 +1,167 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7500av.c
+ *   Support for IP7500 Audio Video Board + CPU module board.
+ *
+ * This file supports the IP7500 Audio Video Board:
+ *	8007-0810  Rev 1.0
+ * with one of the following CPU module boards:
+ *	8007-0510  Rev 1.0
+ *	8007-0510A Rev 1.0 (with ethernet)
+ *
+ * DIP Switch SW2 configuration: (*) default
+ *	POS 1: on(*) = PCI enabled, off = PCI disabled
+ *	POS 2: on(*) = TTYX => PA6, off = TTYX => PF12
+ *	POS 3: on(*) = TTYY => PA7, off = TTYY => PF15
+ *	POS 4: unused
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ring_tio.h>
+#include <asm/vdc_tio.h>
+#include <asm/audio_tio.h>
+#include <asm/ubi32-cs4384.h>
+
+/******************************************************************************
+ * Devices on the I2C bus
+ *
+ * BEWARE of changing the order of things in this array as we depend on
+ * certain things to be in certain places.
+ */
+static struct i2c_board_info __initdata ip7500av_i2c_board_info[] = {
+	/*
+	 * U6, CS4384 DAC, address 0x19
+	 */
+	{
+		.type		= "cs4384",
+		.addr		= 0x19,
+	},
+};
+
+/*
+ * I2C bus on the board, SDA PD1, SCL PD2
+ */
+static struct i2c_gpio_platform_data ip7500av_i2c_data = {
+	.sda_pin		= GPIO_RD_6,
+	.scl_pin		= GPIO_RD_3,
+	.sda_is_open_drain	= 0,
+	.scl_is_open_drain	= 0,
+	.udelay			= 50,
+};
+
+static struct platform_device ip7500av_i2c_device = {
+	.name	= "i2c-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7500av_i2c_data,
+	},
+};
+
+/*
+ * List of possible mclks we can generate.  This depends on the CPU frequency.
+ */
+static struct ubi32_cs4384_mclk_entry ip7500av_cs4384_mclk_entries[] = {
+	{
+		.rate	=	12288000,
+		.div	=	44,
+	},
+	{
+		.rate	=	11289600,
+		.div	=	48,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7500av_devices[] __initdata = {
+	&ip7500av_i2c_device,
+};
+
+/*
+ * ip7500av_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7500av_init(void)
+{
+	struct platform_device *audio_dev;
+	struct platform_device *audio_dev2;
+	struct ubi32_cs4384_platform_data *cs4384_pd;
+
+	board_init();
+
+	vdc_tio_init();
+
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7500av_devices, ARRAY_SIZE(ip7500av_devices));
+
+	/*
+	 * CS4384 DAC
+	 */
+	audio_dev = audio_tio_alloc("snd-ubi32-cs4384", "audiotio-i2sout", 
+			sizeof(struct ubi32_cs4384_platform_data));
+	if (audio_dev) {
+		/*
+		 * Attempt to figure out a good divisor.  This will only work
+		 * assuming the core frequency is compatible.
+		 */
+		int i;
+		unsigned int freq = processor_frequency();
+		for (i = 0; i < ARRAY_SIZE(ip7500av_cs4384_mclk_entries); i++) {
+			unsigned int div;
+			unsigned int rate = ip7500av_cs4384_mclk_entries[i].rate / 1000;
+			div = ((freq / rate) + 500) / 1000;
+			ip7500av_cs4384_mclk_entries[i].div = div;
+			printk("CS4384 mclk %d rate %u000Hz div %u act %u\n", i, rate, div, freq / div);
+		}
+
+		cs4384_pd = audio_tio_priv(audio_dev);
+		cs4384_pd->mclk_src = UBI32_CS4384_MCLK_PWM_0;
+		cs4384_pd->n_mclk = ARRAY_SIZE(ip7500av_cs4384_mclk_entries);
+		cs4384_pd->mclk_entries = ip7500av_cs4384_mclk_entries;
+		ip7500av_i2c_board_info[0].platform_data = audio_dev;
+	}
+
+	/*
+	 * SPDIF port
+	 */
+	audio_dev2 = audio_tio_alloc("snd-ubi32-generic", "audiotio-spdifout", 0);
+	if (audio_dev2) {
+		platform_device_register(audio_dev2);
+	}
+
+	/*
+	 * Register all of the devices which sit on the I2C bus
+	 */
+	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
+	i2c_register_board_info(0, ip7500av_i2c_board_info, ARRAY_SIZE(ip7500av_i2c_board_info));
+
+	ubi_gpio_init();
+
+	return 0;
+}
+arch_initcall(ip7500av_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7500media.c
@@ -0,0 +1,520 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7500media.c
+ *   Board file for IP7500 media board.
+ *
+ * Supports the following configuration
+ *	CPU Module:
+ *		P/N 8007-0510 rev 1.0
+ *			DIP Switch SW2 configuration: 
+ *				POS 1: on  = PCI enabled
+ *				POS 2: off = TTYX => PF12
+ *				POS 3: off = TTYY => PF15
+ *				POS 4: unused
+ *	Media Board:
+ *		P/N 8007-0610 rev 1.0
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <linux/input.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+#include <linux/i2c/pca953x.h>
+
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ubicom32input_i2c.h>
+#include <asm/ubicom32bl.h>
+#include <asm/ubicom32lcd.h>
+#include <asm/vdc_tio.h>
+
+#include <asm/ubicom32sd.h>
+#include <asm/sd_tio.h>
+#include <asm/devtree.h>
+#include <asm/audio_tio.h>
+
+#include <asm/ring_tio.h>
+
+/******************************************************************************
+ * SD/IO Port F (Slot 1) platform data
+ */
+static struct resource ip7500media_portf_sd_resources[] = {
+	/*
+	 * Send IRQ
+	 */
+	[0] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Receive IRQ
+	 */
+	[1] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Memory Mapped Registers
+	 */
+	[2] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct ubicom32sd_card ip7500media_portf_sd_cards[] = {
+	[0] = {
+		.pin_wp		= IP7500MEDIA_IO16,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7500MEDIA_IO20,
+		.pin_cd		= IP7500MEDIA_IO23,
+	},
+	[1] = {
+		.pin_wp		= IP7500MEDIA_IO17,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7500MEDIA_IO21,
+		.pin_cd		= IP7500MEDIA_IO24,
+	},
+};
+
+static struct ubicom32sd_platform_data ip7500media_portf_sd_platform_data = {
+	.ncards		= 2,
+	.cards		= ip7500media_portf_sd_cards, 
+};
+
+static struct platform_device ip7500media_portf_sd_device = {
+	.name		= "ubicom32sd",
+	.id		= 0,
+	.resource	= ip7500media_portf_sd_resources,
+	.num_resources	= ARRAY_SIZE(ip7500media_portf_sd_resources),
+	.dev		= {
+			.platform_data = &ip7500media_portf_sd_platform_data,
+	},
+
+};
+
+/*
+ * ip7500media_portf_sd_init
+ */
+static void ip7500media_portf_sd_init(void)
+{
+	/*
+	 * Check the device tree for the sd_tio
+	 */
+	struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portf_sd");
+	if (!sd_node) {
+		printk(KERN_INFO "PortF SDTIO not found\n");
+		return;
+	}
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	ip7500media_portf_sd_resources[0].start = sd_node->dn.sendirq;
+	ip7500media_portf_sd_resources[1].start = sd_node->dn.recvirq;
+	ip7500media_portf_sd_resources[2].start = (u32_t)&(sd_node->regs);
+	ip7500media_portf_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
+
+	platform_device_register(&ip7500media_portf_sd_device);
+}
+
+/******************************************************************************
+ * SD/IO Port B (Slot 2) platform data
+ */
+static struct resource ip7500media_portb_sd_resources[] = {
+	/*
+	 * Send IRQ
+	 */
+	[0] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Receive IRQ
+	 */
+	[1] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_IRQ,
+	},
+
+	/*
+	 * Memory Mapped Registers
+	 */
+	[2] = {
+		/* 
+		 * The init routine will query the devtree and fill this in
+		 */
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct ubicom32sd_card ip7500media_portb_sd_cards[] = {
+	[0] = {
+		.pin_wp		= IP7500MEDIA_IO19,
+		.wp_polarity	= 1,
+		.pin_pwr	= IP7500MEDIA_IO22,
+		.pin_cd		= IP7500MEDIA_IO18,
+	},
+};
+
+static struct ubicom32sd_platform_data ip7500media_portb_sd_platform_data = {
+	.ncards		= 1,
+	.cards		= ip7500media_portb_sd_cards,
+};
+
+static struct platform_device ip7500media_portb_sd_device = {
+	.name		= "ubicom32sd",
+	.id		= 1,
+	.resource	= ip7500media_portb_sd_resources,
+	.num_resources	= ARRAY_SIZE(ip7500media_portb_sd_resources),
+	.dev		= {
+			.platform_data = &ip7500media_portb_sd_platform_data,
+	},
+
+};
+
+/*
+ * ip7500media_portb_sd_init
+ */
+static void ip7500media_portb_sd_init(void)
+{
+	/*
+	 * Check the device tree for the sd_tio
+	 */
+	struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portb_sd");
+	if (!sd_node) {
+		printk(KERN_INFO "PortB SDTIO not found\n");
+		return;
+	}
+
+	/*
+	 * Fill in the resources and platform data from devtree information
+	 */
+	ip7500media_portb_sd_resources[0].start = sd_node->dn.sendirq;
+	ip7500media_portb_sd_resources[1].start = sd_node->dn.recvirq;
+	ip7500media_portb_sd_resources[2].start = (u32_t)&(sd_node->regs);
+	ip7500media_portb_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
+
+	platform_device_register(&ip7500media_portb_sd_device);
+}
+
+/*
+ * ip7500media_u17_setup
+ *	Called by I2C to tell us that u17 is setup.
+ *
+ * This function is called by I2C to tell us that u17 has been setup.  All
+ * devices which rely on this chip being initialized (or even present) need to
+ * be initialized in this function otherwise they may get initialized too early.
+ *
+ * Currently the only device depending on u17 is the SDIO
+ */
+static int __init ip7500media_u17_setup(struct i2c_client *client, unsigned gpio, unsigned ngpio, void *context)
+{
+	/*
+	 * Initialize the Port F/Port B SD slots (only the enabled ports will init)
+	 */
+	ip7500media_portf_sd_init();
+	ip7500media_portb_sd_init();
+
+	return 0;
+}
+
+/******************************************************************************
+ * LCD VGH on the board at PE6
+ */
+static struct ubicom32lcd_platform_data ip7500media_lcd_data = {
+	.vgh_gpio		= GPIO_RE_7,
+	.vgh_polarity		= true,
+};
+
+static struct platform_device ip7500media_lcd_device = {
+	.name	= "ubicom32lcd",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7500media_lcd_data,
+	},
+};
+
+/******************************************************************************
+ * Backlight on the board PD0, hardware PWM
+ */
+static struct ubicom32bl_platform_data ip7500media_backlight_data = {
+	.type			= UBICOM32BL_TYPE_PWM,
+	.pwm_channel		= 2,
+	.pwm_prescale		= 15,
+	.pwm_period		= 60,
+	.default_intensity	= 0x80,
+};
+
+static struct platform_device ip7500media_backlight_device = {
+	.name	= "ubicom32bl",
+	.id	= -1,
+	.dev	= {
+		.platform_data = &ip7500media_backlight_data,
+	},
+};
+
+/******************************************************************************
+ * Ubicom32Input on I2C, U15 MAX7310, address 0x18, 8 bits
+ */
+static struct ubicom32input_i2c_button ip7500media_ubicom32input_i2c_u15_buttons[] = {
+	{
+		.type		= EV_KEY,
+		.code		= KEY_LEFT,
+		.bit		= 0,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_RIGHT,
+		.bit		= 1,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_UP,
+		.bit		= 2,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_DOWN,
+		.bit		= 3,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ENTER,
+		.bit		= 4,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_MENU,
+		.bit		= 5,
+		.active_low	= 1,
+	},
+	{
+		.type		= EV_KEY,
+		.code		= KEY_ESC,
+		.bit		= 6,
+		.active_low	= 1,
+	},
+};
+
+static struct ubicom32input_i2c_platform_data ip7500media_ubicom32input_i2c_u15_platform_data = {
+	.buttons	= ip7500media_ubicom32input_i2c_u15_buttons,
+	.nbuttons	= ARRAY_SIZE(ip7500media_ubicom32input_i2c_u15_buttons),
+	.name		= "Ubicom32 Input I2C U15",
+};
+
+/******************************************************************************
+ * Additional GPIO chips
+ */
+static struct pca953x_platform_data ip7500media_gpio_u16_platform_data = {
+	.gpio_base = IP7500MEDIA_U16_BASE,
+};
+
+static struct pca953x_platform_data ip7500media_gpio_u17_platform_data = {
+	.gpio_base = IP7500MEDIA_U17_BASE,
+	.setup = ip7500media_u17_setup,
+};
+
+static struct pca953x_platform_data ip7500media_gpio_u18_platform_data = {
+	.gpio_base = IP7500MEDIA_U18_BASE,
+};
+
+/******************************************************************************
+ * Devices on the I2C bus
+ *
+ * BEWARE of changing the order of things in this array as we depend on
+ * certain things to be in certain places.
+ */
+static struct i2c_board_info __initdata ip7500media_i2c_board_info[] = {
+	/*
+	 * U6, CS4350 DAC, address 0x4B
+	 */
+	{
+		.type		= "cs4350",
+		.addr		= 0x4B,
+	},
+
+	/*
+	 * U14, S35390A RTC, address 0x30
+	 */
+	{
+		.type		= "s35390a",
+		.addr		= 0x30,
+	},
+
+	/*
+	 * U15, MAX7310 IO expander, 8 bits, address 0x18
+	 *	IO0: User I/O (J16-1) (Left)	IO4: User I/O (J16-5) (Enter)
+	 *	IO1: User I/O (J16-2) (Right)	IO5: User I/O (J16-6) (Menu)
+	 *	IO2: User I/O (J16-3) (Up)	IO6: User I/O (J16-7) (Back)
+	 *	IO3: User I/O (J16-4) (Down)	IO7: User I/O (J16-8)
+	 */
+	{
+		.type		= "ubicom32in_max7310",
+		.addr		= 0x18,
+		.platform_data	= &ip7500media_ubicom32input_i2c_u15_platform_data,
+	},
+
+	/*
+	 * U16, MAX7310 IO expander, 8 bits, address 0x1C
+	 *	IO8 : User I/O (J16-9)		IO12: User I/O (J16-17)
+	 *	IO9 : User I/O (J16-10)		IO13: User I/O (J16-18)
+	 *	IO10: User I/O (J16-15)		IO14: User I/O (J16-19)
+	 *	IO11: User I/O (J16-16)		IO15: User I/O (J16-20)
+	 */
+	{
+		.type		= "max7310",
+		.addr		= 0x1C,
+		.platform_data	= &ip7500media_gpio_u16_platform_data,
+	},
+
+	/*
+	 * U17, MAX7310 IO expander, 8 bits, address 0x1A
+	 *	IO16: SDIO1A_WP			IO20: SD1A_PWREN
+	 *	IO17: SDIO1B_WP			IO21: SD1B_PWREN
+	 *	IO18: SDIO2_CD			IO22: SD2_PWREN
+	 *	IO19: SDIO2_WP			IO23: SDIO1A_CD
+	 *	
+	 */
+	{
+		.type		= "max7310",
+		.addr		= 0x1A,
+		.platform_data	= &ip7500media_gpio_u17_platform_data,
+	},
+
+	/*
+	 * U18, MAX7310 IOB expander, 8 bits, address 0x1E
+	 *	IO24: SDIO1B_CD			IO28: User I/O TP6
+	 *	IO25: User I/O TP9		IO29: User I/O TP5
+	 *	IO26: User I/O TP8		IO30: User I/O TP4
+	 *	IO27: User I/O TP7		IO31: User I/O TP3
+	 */
+	{
+		.type		= "max7310",
+		.addr		= 0x1E,
+		.platform_data	= &ip7500media_gpio_u18_platform_data,
+	},
+};
+
+/*
+ * I2C bus on the board, SDA PE4, SCL PE5
+ */
+static struct i2c_gpio_platform_data ip7500media_i2c_data = {
+	.sda_pin		= GPIO_RE_4,
+	.scl_pin		= GPIO_RE_5,
+	.sda_is_open_drain	= 0,
+	.scl_is_open_drain	= 0,
+	.udelay			= 50,
+};
+
+static struct platform_device ip7500media_i2c_device = {
+	.name	= "i2c-gpio",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &ip7500media_i2c_data,
+	},
+};
+
+/*
+ * List of all devices in our system
+ */
+static struct platform_device *ip7500media_devices[] __initdata = {
+	&ip7500media_i2c_device,
+	&ip7500media_lcd_device,
+	&ip7500media_backlight_device,
+};
+
+/*
+ * ip7500media_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7500media_init(void)
+{
+	struct platform_device *audio_dev;
+
+	board_init();
+
+	ubi_gpio_init();
+
+#ifdef CONFIG_UIO_UBICOM32RING
+	ring_tio_init("decoder_ring");
+#endif
+
+	/*
+	 * Start up the video driver first
+	 */
+	vdc_tio_init();
+
+	/*
+	 * Register all of the devices we have on this board
+	 */
+	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
+	platform_add_devices(ip7500media_devices, ARRAY_SIZE(ip7500media_devices));
+
+	/*
+	 * Allocate the audio driver if we can
+	 */
+	audio_dev = audio_tio_alloc("snd-ubi32-cs4350", "audiotio-i2sout", 0);
+	if (audio_dev) {
+		ip7500media_i2c_board_info[0].platform_data = audio_dev;
+	}
+
+	/*
+	 * Register all of the devices which sit on the I2C bus
+	 */
+	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
+	i2c_register_board_info(0, ip7500media_i2c_board_info, ARRAY_SIZE(ip7500media_i2c_board_info));
+
+	/*
+	 * We have to initialize the SDIO after the I2C IOB gets setup.  SDIO is initialized in 
+	 * ip7500media_u17_setup
+	 */
+
+	return 0;
+}
+
+arch_initcall(ip7500media_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/board-ip7500module.c
@@ -0,0 +1,60 @@
+/*
+ * arch/ubicom32/mach-ip7k/board-ip7500module.c
+ *   Support for IP7500 CPU module board.
+ *
+ * This file supports the IP7500 CPU module board:
+ *	8007-0510  Rev 1.0
+ *	8007-0510A Rev 1.0 (with ethernet)
+ *
+ * DIP Switch SW2 configuration: (*) default
+ *	POS 1: on(*) = PCI enabled, off = PCI disabled
+ *	POS 2: on(*) = TTYX => PA6, off = TTYX => PF12
+ *	POS 3: on(*) = TTYY => PA7, off = TTYY => PF15
+ *	POS 4: unused
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <asm/board.h>
+#include <asm/machdep.h>
+#include <asm/ring_tio.h>
+#include <asm/vdc_tio.h>
+
+/*
+ * ip7500module_init
+ *	Called to add the devices which we have on this board
+ */
+static int __init ip7500module_init(void)
+{
+	board_init();
+
+	ubi_gpio_init();
+
+	return 0;
+}
+
+arch_initcall(ip7500module_init);
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/Kconfig
@@ -0,0 +1,132 @@
+config IP7145DPF
+	bool "IP7145DPF"
+	select UBICOM32_V4
+	select UBICOM_INPUT
+	select UBICOM_INPUT_I2C
+	select RTC_CLASS
+	select RTC_DRV_S35390A
+	select I2C
+	select I2C_GPIO
+	select GPIO_PCA953X
+	select FB
+	select FB_UBICOM32
+	select BACKLIGHT_LCD_SUPPORT
+	select LCD_CLASS_DEVICE
+	select LCD_UBICOM32
+	select BACKLIGHT_CLASS_DEVICE
+	select BACKLIGHT_UBICOM32
+	select SND_UBI32
+	select MMC_UBICOM32
+	select MMC
+	select MMC_BLOCK
+	select BRD_64MB
+	help
+		IP7145 Digital Picture Frame reference design, supports:
+			8007-0410 v1.0
+
+config IP7160RGW
+	bool "IP7160RGW"
+	select UBICOM32_V4
+	select UBICOM_INPUT
+	select NEW_LEDS
+	select LEDS_CLASS
+	select LEDS_GPIO
+	select BRD_64MB
+	select SPI
+	select SPI_UBICOM32_GPIO
+	select VLAN_8021Q
+	select UBICOM_SWITCH
+	select UBICOM_SWITCH_BCM539X
+	help
+		Ubicom IP7160 RGW Eval, supports:
+			8007-0110 v1.0
+			8007-0111 v1.1
+			8007-0112 v1.2
+
+config IP7160BRINGUP
+	bool "IP7160BRINGUP"
+	select UBICOM32_V4
+	select NEW_LEDS
+	select LEDS_CLASS
+	select LEDS_GPIO
+	select BRD_64MB
+	help
+		Ubicom IP7160 Bringup, supports:
+			8007-0010 v1.0
+
+config IP7160DPF
+	bool "IP7160DPF"
+	select UBICOM32_V4
+	select I2C
+	select I2C_GPIO
+	select FB
+	select FB_UBICOM32
+	select BACKLIGHT_LCD_SUPPORT
+	select BACKLIGHT_CLASS_DEVICE
+	select SND_UBI32
+	select SND_UBI32_AUDIO_CS4350
+	select UBICOM_HID
+	select BRD_64MB
+	help
+		IP7160 Digital Picture Frame board, supports:
+			8007-0211 Rev 1.1
+
+config IP7500MODULE
+	bool "IP7500MODULE"
+	select UBICOM32_V4
+	select BRD_128MB
+	help
+		Ubicom IP7500 CPU Module board, supports:
+			8007-0510  v1.0
+			8007-0510A v1.0
+
+		Please see ip7500module.c for more details.
+
+config IP7500AV
+	bool "IP7500AV"
+	select UBICOM32_V4
+	select BRD_128MB
+	select I2C
+	select I2C_GPIO
+	select SND_UBI32
+	select SND_UBI32_AUDIO_CS4384
+	select FB
+	select FB_UBICOM32
+	help
+		Ubicom IP7500 Audio Video board, supports:
+			8007-0810  v1.0
+
+		With Ubicom IP7500 CPU Module board:
+			8007-0510  v1.0 -or-
+			8007-0510A v1.0
+
+		Please see ip7500av.c for more details.
+
+config IP7500MEDIA
+	bool "IP7500MEDIA"
+	select UBICOM32_V4
+	select UBICOM_INPUT_I2C
+	select RTC_CLASS
+	select RTC_DRV_S35390A
+	select I2C
+	select I2C_GPIO
+	select GPIO_PCA953X
+	select FB
+	select FB_UBICOM32
+	select BACKLIGHT_LCD_SUPPORT
+	select LCD_CLASS_DEVICE
+	select LCD_UBICOM32
+	select BACKLIGHT_CLASS_DEVICE
+	select BACKLIGHT_UBICOM32
+	select SND_UBI32
+	select SND_UBI32_AUDIO_CS4350
+	select MMC_UBICOM32
+	select MMC
+	select MMC_BLOCK
+	select BRD_128MB
+	help
+		IP7500 Media Board w/ IP7500 CPU Module board, supports:
+			8007-0610 v1.0 w/ 8007-0510 v1.0
+
+		Please see ip7500media.c for more details.
+
--- /dev/null
+++ b/arch/ubicom32/mach-ip7k/Makefile
@@ -0,0 +1,35 @@
+#
+# arch/ubicom32/mach-ip7k/Makefile
+#	Makefile for ip7k based boards.
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+obj-$(CONFIG_IP7145DPF)		+= board-ip7145dpf.o
+obj-$(CONFIG_IP7160RGW)		+= board-ip7160rgw.o
+obj-$(CONFIG_IP7160BRINGUP)	+= board-ip7160bringup.o
+obj-$(CONFIG_IP7160DPF)		+= board-ip7160dpf.o
+obj-$(CONFIG_IP7500MODULE)	+= board-ip7500module.o
+obj-$(CONFIG_IP7500MEDIA)	+= board-ip7500media.o
+obj-$(CONFIG_IP7500AV)		+= board-ip7500av.o
--- /dev/null
+++ b/arch/ubicom32/Makefile
@@ -0,0 +1,103 @@
+#
+# arch/ubicom32/Makefile
+#	<TODO: Replace with short file description>
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+KBUILD_DEFCONFIG := 
+
+# setup the machine name and machine dependent settings
+machine-$(CONFIG_UBICOM32_V3)	:= ip5k
+machine-$(CONFIG_UBICOM32_V4)	:= ip7k
+MACHINE := $(machine-y)
+export MACHINE
+
+model-$(CONFIG_RAMKERNEL)	:= ram
+model-$(CONFIG_ROMKERNEL)	:= rom
+MODEL := $(model-y)
+export MODEL
+
+CPUCLASS := $(cpuclass-y)
+
+export CPUCLASS
+
+#
+# We want the core kernel built using the fastcall ABI but modules need
+# to be built using the slower calling convention because they could be
+# loaded out of range for fast calls.
+#
+CFLAGS_KERNEL    += -mfastcall
+CFLAGS_MODULE    += -mno-fastcall
+
+#
+# Some CFLAG additions based on specific CPU type.
+#
+cflags-$(CONFIG_UBICOM32_V3)		:= -march=ubicom32v3 -mno-fdpic -DIP5000
+cflags-$(CONFIG_UBICOM32_V4)		:= -march=ubicom32v4 -mno-fdpic -DIP7000
+
+ldflags-$(CONFIG_LINKER_RELAXATION)	:= --relax
+LDFLAGS_vmlinux := $(ldflags-y)
+
+GCCLIBDIR := $(dir $(shell $(CC) $(cflags-y) -print-libgcc-file-name))
+
+KBUILD_CFLAGS += $(cflags-y) -ffunction-sections
+KBUILD_AFLAGS += $(cflags-y)
+
+KBUILD_CFLAGS += -D__linux__ -Dlinux
+KBUILD_CFLAGS += -DUTS_SYSNAME=\"uClinux\"
+
+# include any machine specific directory
+ifneq ($(machine-y),)
+core-y += arch/$(ARCH)/mach-$(MACHINE)/
+endif
+
+head-y := arch/$(ARCH)/kernel/head.o
+
+core-y	+= arch/$(ARCH)/kernel/ \
+	   arch/$(ARCH)/mm/ \
+	   arch/$(ARCH)/crypto/ \
+	   arch/$(ARCH)/mach-common/
+
+drivers-$(CONFIG_OPROFILE)	+= arch/ubicom32/oprofile/
+
+libs-y	+= arch/$(ARCH)/lib/
+
+archclean:
+
+# make sure developer has selected a valid board
+ifeq ($(CONFIG_NOBOARD),y)
+# $(error have to select a valid board file $(CONFIG_NOBOARD), please run kernel config again)
+_all: config_board_error
+endif
+
+config_board_error:
+	@echo "*************************************************"
+	@echo "You have not selected a proper board."
+	@echo "Please run menuconfig (or config) against your"
+	@echo "kernel and choose your board under Processor"
+	@echo "options"
+	@echo "*************************************************"
+	@exit 1
+
--- /dev/null
+++ b/arch/ubicom32/mm/fault.c
@@ -0,0 +1,81 @@
+/*
+ * arch/ubicom32/mm/fault.c
+ *   Ubicom32 architecture page fault implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *  Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>,
+ *  Copyright (C) 2000  Lineo, Inc.  (www.lineo.com) 
+ *
+ *  Based on:
+ *
+ *  linux/arch/m68k/mm/fault.c
+ *
+ *  Copyright (C) 1995  Hamish Macdonald
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/mman.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/ptrace.h>
+
+#include <asm/system.h>
+#include <asm/pgtable.h>
+
+extern void die_if_kernel(char *, struct pt_regs *, long);
+
+/*
+ * This routine handles page faults.  It determines the problem, and
+ * then passes it off to one of the appropriate routines.
+ *
+ * error_code:
+ *	bit 0 == 0 means no page found, 1 means protection fault
+ *	bit 1 == 0 means read, 1 means write
+ *
+ * If this routine detects a bad access, it returns 1, otherwise it
+ * returns 0.
+ */
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			      unsigned long error_code)
+{
+#ifdef DEBUG
+	printk (KERN_DEBUG "regs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld\n",
+		regs->sr, regs->pc, address, error_code);
+#endif
+
+	/*
+	 * Oops. The kernel tried to access some bad page. We'll have to
+	 * terminate things with extreme prejudice.
+	 */
+	if ((unsigned long) address < PAGE_SIZE) {
+		printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
+	} else
+		printk(KERN_ALERT "Unable to handle kernel access");
+	printk(KERN_ALERT " at virtual address %08lx\n",address);
+	die_if_kernel("Oops", regs, error_code);
+	do_exit(SIGKILL);
+
+	return 1;
+}
+
--- /dev/null
+++ b/arch/ubicom32/mm/init.c
@@ -0,0 +1,261 @@
+/*
+ * arch/ubicom32/mm/init.c
+ *   Ubicom32 architecture virtual memory initialization.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *  Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>,
+ *                      Kenneth Albanowski <kjahds@kjahds.com>,
+ *  Copyright (C) 2000  Lineo, Inc.  (www.lineo.com)
+ *
+ *  Based on:
+ *
+ *  linux/arch/m68k/mm/init.c
+ *
+ *  Copyright (C) 1995  Hamish Macdonald
+ *
+ *  JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com)
+ *  DEC/2000 -- linux 2.4 support <davidm@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/mman.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
+#include <linux/init.h>
+#include <linux/highmem.h>
+#include <linux/pagemap.h>
+#include <linux/bootmem.h>
+#include <linux/slab.h>
+
+#include <asm/setup.h>
+#include <asm/segment.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/machdep.h>
+#include <asm/ocm-alloc.h>
+
+#undef DEBUG
+
+extern void die_if_kernel(char *,struct pt_regs *,long);
+extern void free_initmem(void);
+
+/*
+ * BAD_PAGE is the page that is used for page faults when linux
+ * is out-of-memory. Older versions of linux just did a
+ * do_exit(), but using this instead means there is less risk
+ * for a process dying in kernel mode, possibly leaving a inode
+ * unused etc..
+ *
+ * BAD_PAGETABLE is the accompanying page-table: it is initialized
+ * to point to BAD_PAGE entries.
+ *
+ * ZERO_PAGE is a special page that is used for zero-initialized
+ * data and COW.
+ */
+static unsigned long empty_bad_page_table;
+
+static unsigned long empty_bad_page;
+
+unsigned long empty_zero_page;
+
+void show_mem(void)
+{
+    unsigned long i;
+    int free = 0, total = 0, reserved = 0, shared = 0;
+    int cached = 0;
+
+    printk(KERN_INFO "\nMem-info:\n");
+    show_free_areas();
+    i = max_mapnr;
+    while (i-- > 0) {
+	total++;
+	if (PageReserved(mem_map+i))
+	    reserved++;
+	else if (PageSwapCache(mem_map+i))
+	    cached++;
+	else if (!page_count(mem_map+i))
+	    free++;
+	else
+	    shared += page_count(mem_map+i) - 1;
+    }
+    printk(KERN_INFO "%d pages of RAM\n",total);
+    printk(KERN_INFO "%d free pages\n",free);
+    printk(KERN_INFO "%d reserved pages\n",reserved);
+    printk(KERN_INFO "%d pages shared\n",shared);
+    printk(KERN_INFO "%d pages swap cached\n",cached);
+}
+
+extern unsigned long memory_start;
+extern unsigned long memory_end;
+extern char __ocm_free_begin;
+extern char __ocm_free_end;
+
+/*
+ * paging_init() continues the virtual memory environment setup which
+ * was begun by the code in arch/head.S.
+ * The parameters are pointers to where to stick the starting and ending
+ * addresses of available kernel virtual memory.
+ */
+void __init paging_init(void)
+{
+	/*
+	 * Make sure start_mem is page aligned, otherwise bootmem and
+	 * page_alloc get different views of the world.
+	 */
+#ifdef DEBUG
+	unsigned long start_mem = PAGE_ALIGN(memory_start);
+#endif
+	unsigned long end_mem   = memory_end & PAGE_MASK;
+
+#ifdef DEBUG
+	printk (KERN_DEBUG "start_mem is %#lx\nvirtual_end is %#lx\n",
+		start_mem, end_mem);
+#endif
+
+	/*
+	 * Initialize the bad page table and bad page to point
+	 * to a couple of allocated pages.
+	 */
+	empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
+	empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
+	empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
+	memset((void *)empty_zero_page, 0, PAGE_SIZE);
+
+	/*
+	 * TODO: enable setting up for user memory management interface.
+	 */
+
+#ifdef DEBUG
+	printk (KERN_DEBUG "before free_area_init\n");
+
+	printk (KERN_DEBUG "free_area_init -> start_mem is %#lx\nvirtual_end is %#lx\n",
+		start_mem, end_mem);
+#endif
+
+	{
+		unsigned long zones_size[MAX_NR_ZONES] = {0, };
+#ifdef CONFIG_ZONE_DMA
+		zones_size[ZONE_DMA] = OCMSIZE >> PAGE_SHIFT;
+#endif
+		zones_size[ZONE_NORMAL] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
+#ifdef CONFIG_HIGHMEM
+		zones_size[ZONE_HIGHMEM] = 0;
+#endif
+		free_area_init(zones_size);
+	}
+}
+
+void __init mem_init(void)
+{
+	int codek = 0, datak = 0, initk = 0;
+	unsigned long tmp;
+	extern char _etext, _stext, _sdata, _ebss, __init_begin, __init_end;
+	unsigned long len = CONFIG_RAMSIZE + OCMSIZE;
+	unsigned long start_mem = memory_start; /* DAVIDM - these must start at end of kernel */
+	unsigned long end_mem   = memory_end; /* DAVIDM - this must not include kernel stack at top */
+
+#ifdef DEBUG
+	printk(KERN_DEBUG "Mem_init: start=%lx, end=%lx\n", start_mem, end_mem);
+#endif
+
+	end_mem &= PAGE_MASK;
+	high_memory = (void *) end_mem;
+
+	start_mem = PAGE_ALIGN(start_mem);
+	max_mapnr = num_physpages = (((unsigned long) high_memory) - PAGE_OFFSET) >> PAGE_SHIFT;
+
+	/* this will put all memory onto the freelists */
+#ifdef CONFIG_ZONE_DMA
+	{
+		unsigned long ocm_free_begin = (unsigned long)&__ocm_free_begin;
+		unsigned long ocm_free_end = (unsigned long)&__ocm_free_end;
+		unsigned long zone_dma_begin = (ocm_free_begin + PAGE_SIZE - 1) & PAGE_MASK;
+		unsigned long zone_dma_end = ocm_free_end & PAGE_MASK;
+		if (zone_dma_end > zone_dma_begin)
+			free_bootmem(zone_dma_begin, zone_dma_end-zone_dma_begin);
+	}
+#endif
+	totalram_pages = free_all_bootmem();
+
+	codek = (&_etext - &_stext) >> 10;
+	datak = (&_ebss - &_sdata) >> 10;
+	initk = (&__init_begin - &__init_end) >> 10;
+
+	tmp = nr_free_pages() << PAGE_SHIFT;
+	printk(KERN_INFO "Memory available: %luk/%luk RAM, (%dk kernel code, %dk data)\n",
+	       tmp >> 10,
+	       len >> 10,
+	       codek,
+	       datak
+	       );
+
+}
+
+#ifdef CONFIG_BLK_DEV_INITRD
+void free_initrd_mem(unsigned long start, unsigned long end)
+{
+	int pages = 0;
+	for (; start < end; start += PAGE_SIZE) {
+		ClearPageReserved(virt_to_page(start));
+		init_page_count(virt_to_page(start));
+		free_page(start);
+		totalram_pages++;
+		pages++;
+	}
+	printk (KERN_NOTICE "Freeing initrd memory: %dk freed\n", pages);
+}
+#endif
+
+void
+free_initmem()
+{
+#ifdef CONFIG_RAMKERNEL
+	unsigned long addr;
+	extern char __init_begin, __init_end;
+	/*
+	 * The following code should be cool even if these sections
+	 * are not page aligned.
+	 */
+	addr = PAGE_ALIGN((unsigned long)(&__init_begin));
+	/* next to check that the page we free is not a partial page */
+	for (; addr + PAGE_SIZE < (unsigned long)(&__init_end); addr +=PAGE_SIZE) {
+		ClearPageReserved(virt_to_page(addr));
+		init_page_count(virt_to_page(addr));
+		free_page(addr);
+		totalram_pages++;
+	}
+	printk(KERN_NOTICE "Freeing unused kernel memory: %ldk freed (0x%x - 0x%x)\n",
+			(addr - PAGE_ALIGN((long) &__init_begin)) >> 10,
+			(int)(PAGE_ALIGN((unsigned long)(&__init_begin))),
+			(int)(addr - PAGE_SIZE));
+#endif
+}
+
--- /dev/null
+++ b/arch/ubicom32/mm/kmap.c
@@ -0,0 +1,79 @@
+/*
+ * arch/ubicom32/mm/kmap.c
+ *   Ubicom32 architecture non-mmu ioremap and friends implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2000 Lineo, <davidm@snapgear.com>
+ * Copyright (C) 2000-2002 David McCullough <davidm@snapgear.com>
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+#include <asm/setup.h>
+#include <asm/segment.h>
+#include <asm/page.h>
+#include <asm/pgalloc.h>
+#include <asm/io.h>
+#include <asm/system.h>
+
+#undef DEBUG
+
+/*
+ * Map some physical address range into the kernel address space.
+ */
+void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag)
+{
+	return (void *)physaddr;
+}
+
+/*
+ * Unmap a ioremap()ed region again.
+ */
+void iounmap(void *addr)
+{
+}
+
+/*
+ * __iounmap unmaps nearly everything, so be careful
+ * it doesn't free currently pointer/page tables anymore but it
+ * wans't used anyway and might be added later.
+ */
+void __iounmap(void *addr, unsigned long size)
+{
+}
+
+/*
+ * Set new cache mode for some kernel address space.
+ * The caller must push data for that range itself, if such data may already
+ * be in the cache.
+ */
+void kernel_set_cachemode(void *addr, unsigned long size, int cmode)
+{
+}
--- /dev/null
+++ b/arch/ubicom32/mm/Makefile
@@ -0,0 +1,32 @@
+#
+# arch/ubicom32/mm/Makefile
+#	<TODO: Replace with short file description>
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+#
+# Makefile for the linux m68knommu specific parts of the memory manager.
+#
+
+obj-y += init.o fault.o memory.o kmap.o ocm-alloc.o
--- /dev/null
+++ b/arch/ubicom32/mm/memory.c
@@ -0,0 +1,59 @@
+/*
+ * arch/ubicom32/mm/memory.c
+ *   Ubicom32 architecture kernel_map() implementation.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *  Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
+ *  Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com)
+ *
+ *  Based on:
+ *
+ *  linux/arch/m68k/mm/memory.c
+ *
+ *  Copyright (C) 1995  Hamish Macdonald
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+
+#include <asm/segment.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+
+/*
+ * Map some physical address range into the kernel address space.
+ * The code is copied and adapted from map_chunk().
+ */
+
+unsigned long kernel_map(unsigned long paddr, unsigned long size,
+			 int nocacheflag, unsigned long *memavailp )
+{
+	return paddr;
+}
+
--- /dev/null
+++ b/arch/ubicom32/mm/ocm-alloc.c
@@ -0,0 +1,439 @@
+/*
+ * arch/ubicom32/mm/ocm-alloc.c
+ *	OCM allocator for Uibcom32 On-Chip memory
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *  Copyright 2004-2008 Analog Devices Inc.
+ *
+ *  Based on:
+ *
+ *  arch/blackfin/mm/sram-alloc.c
+ *
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/miscdevice.h>
+#include <linux/ioport.h>
+#include <linux/fcntl.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <linux/proc_fs.h>
+#include <linux/mutex.h>
+#include <linux/rtc.h>
+#include <asm/ocm-alloc.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt, a...)
+#endif
+/*
+ * the data structure for OCM heap pieces
+ */
+struct ocm_piece {
+	void *paddr;
+	int size;
+	pid_t pid;
+	struct ocm_piece *next;
+};
+
+/*
+ * struct ocm_heap
+ */
+struct ocm_heap {
+	struct ocm_piece free_head;
+	struct ocm_piece used_head;
+	struct mutex lock;
+};
+
+static struct ocm_heap ocm_inst_heap;
+
+/*
+ * OCM area for storing code
+ */
+extern asmlinkage void *__ocm_inst_heap_begin;
+extern asmlinkage void *__ocm_inst_heap_end;
+#define OCM_INST_HEAP_BEGIN ((unsigned int)&__ocm_inst_heap_begin)
+#define OCM_INST_HEAP_END ((unsigned int)&__ocm_inst_heap_end)
+#define OCM_INST_HEAP_LENGTH (OCM_INST_HEAP_END - OCM_INST_HEAP_BEGIN)
+
+static struct kmem_cache *ocm_piece_cache;
+
+/*
+ * _ocm_heap_init()
+ */
+static int __init _ocm_heap_init(struct ocm_heap *ocmh,
+				  unsigned int start,
+				  unsigned int size)
+{
+	ocmh->free_head.next = kmem_cache_alloc(ocm_piece_cache, GFP_KERNEL);
+
+	if (!ocmh->free_head.next)
+		return -1;
+
+	ocmh->free_head.next->paddr = (void *)start;
+	ocmh->free_head.next->size = size;
+	ocmh->free_head.next->pid = 0;
+	ocmh->free_head.next->next = 0;
+
+	ocmh->used_head.next = NULL;
+
+	/* mutex initialize */
+	mutex_init(&ocmh->lock);
+
+	return 0;
+}
+
+/*
+ * _ocm_alloc_init()
+ *
+ * starts the ocm heap(s)
+ */
+static int __init _ocm_alloc_init(void)
+{
+	if (OCM_INST_HEAP_LENGTH) {
+		ocm_piece_cache = kmem_cache_create("ocm_piece_cache",
+						    sizeof(struct ocm_piece),
+						    0, SLAB_PANIC, NULL);
+
+		if (_ocm_heap_init(&ocm_inst_heap,
+				   OCM_INST_HEAP_BEGIN,
+				   OCM_INST_HEAP_LENGTH) == 0)
+			printk(KERN_INFO "OCM Instruction Heap %d KB\n",
+			       OCM_INST_HEAP_LENGTH >> 10);
+		else
+			printk(KERN_INFO "Failed to initialize OCM "
+			       "Instruction Heap\n");
+
+	} else
+		printk(KERN_INFO "No space available for OCM "
+		       "Instruction Heap\n");
+
+	return 0;
+}
+pure_initcall(_ocm_alloc_init);
+
+/*
+ * _ocm_alloc()
+ *	generic alloc a block in the ocm heap, if successful
+ *	returns the pointer.
+ */
+static void *_ocm_alloc(size_t size, pid_t pid, struct ocm_heap *ocmheap)
+{
+	struct ocm_piece *pslot, *plast, *pavail;
+	struct ocm_piece *pfree_head = &ocmheap->free_head;
+	struct ocm_piece *pused_head = &ocmheap->used_head;
+
+	if (size <= 0 || !pfree_head || !pused_head)
+		return NULL;
+
+	/* Align the size */
+	size = (size + 3) & ~3;
+
+	pslot = pfree_head->next;
+	plast = pfree_head;
+
+	/*
+	 * search an available piece slot
+	 */
+	while (pslot != NULL && size > pslot->size) {
+		plast = pslot;
+		pslot = pslot->next;
+	}
+
+	if (!pslot)
+		return NULL;
+
+	if (pslot->size == size) {
+		/*
+		 * Unlink this block from the list
+		 */
+		plast->next = pslot->next;
+		pavail = pslot;
+	} else {
+		/*
+		 * Split this block in two.
+		 */
+		pavail = kmem_cache_alloc(ocm_piece_cache, GFP_KERNEL);
+
+		if (!pavail)
+			return NULL;
+
+		pavail->paddr = pslot->paddr;
+		pavail->size = size;
+		pslot->paddr += size;
+		pslot->size -= size;
+	}
+
+	pavail->pid = pid;
+
+	pslot = pused_head->next;
+	plast = pused_head;
+
+	/*
+	 * insert new piece into used piece list !!!
+	 */
+	while (pslot != NULL && pavail->paddr < pslot->paddr) {
+		plast = pslot;
+		pslot = pslot->next;
+	}
+
+	pavail->next = pslot;
+	plast->next = pavail;
+
+	DEBUGP("_ocm_alloc %d bytes at %p from in %p",
+	       size, pavail->paddr, ocmheap);
+
+	return pavail->paddr;
+}
+
+#if 0
+/* Allocate the largest available block.  */
+static void *_ocm_alloc_max(struct ocm_heap *ocmheap,
+			     unsigned long *psize)
+{
+	struct ocm_piece *pfree_head = &ocmheap->free_head;
+	struct ocm_piece *pslot, *pmax;
+
+	pmax = pslot = pfree_head->next;
+
+	/* search an available piece slot */
+	while (pslot != NULL) {
+		if (pslot->size > pmax->size)
+			pmax = pslot;
+		pslot = pslot->next;
+	}
+
+	if (!pmax)
+		return NULL;
+
+	*psize = pmax->size;
+
+	return _ocm_alloc(*psize, ocmheap);
+}
+#endif
+
+/*
+ * _ocm_free()
+ *	generic free a block in the ocm heap, if successful
+ */
+static int _ocm_free(const void *addr,
+		     struct ocm_heap *ocmheap)
+{
+	struct ocm_piece *pslot, *plast, *pavail;
+	struct ocm_piece *pfree_head = &ocmheap->free_head;
+	struct ocm_piece *pused_head = &ocmheap->used_head;
+
+	/* search the relevant memory slot */
+	pslot = pused_head->next;
+	plast = pused_head;
+
+	/* search an available piece slot */
+	while (pslot != NULL && pslot->paddr != addr) {
+		plast = pslot;
+		pslot = pslot->next;
+	}
+
+	if (!pslot) {
+		DEBUGP("_ocm_free %p  not found in %p", addr, ocmheap);
+		return -1;
+	}
+	DEBUGP("_ocm_free %p from in %p", addr, ocmheap);
+
+	plast->next = pslot->next;
+	pavail = pslot;
+	pavail->pid = 0;
+
+	/* insert free pieces back to the free list */
+	pslot = pfree_head->next;
+	plast = pfree_head;
+
+	while (pslot != NULL && addr > pslot->paddr) {
+		plast = pslot;
+		pslot = pslot->next;
+	}
+
+	if (plast != pfree_head &&
+	    plast->paddr + plast->size == pavail->paddr) {
+		plast->size += pavail->size;
+		kmem_cache_free(ocm_piece_cache, pavail);
+	} else {
+		pavail->next = plast->next;
+		plast->next = pavail;
+		plast = pavail;
+	}
+
+	if (pslot && plast->paddr + plast->size == pslot->paddr) {
+		plast->size += pslot->size;
+		plast->next = pslot->next;
+		kmem_cache_free(ocm_piece_cache, pslot);
+	}
+
+	return 0;
+}
+
+/*
+ * ocm_inst_alloc()
+ *
+ *	allocates a block of size in the ocm instrction heap, if
+ *	successful returns address allocated.
+ */
+void *ocm_inst_alloc(size_t size, pid_t pid)
+{
+	void *addr;
+
+	if (!OCM_INST_HEAP_LENGTH)
+		return NULL;
+
+
+	mutex_lock(&ocm_inst_heap.lock);
+
+	addr = _ocm_alloc(size, pid, &ocm_inst_heap);
+
+	mutex_unlock(&ocm_inst_heap.lock);
+
+	return addr;
+}
+EXPORT_SYMBOL(ocm_inst_alloc);
+
+/*
+ * ocm_inst_free()
+ *	free a block in the ocm instrction heap, returns 0 if successful.
+ */
+int ocm_inst_free(const void *addr)
+{
+	int ret;
+
+	if (!OCM_INST_HEAP_LENGTH)
+		return -1;
+
+	mutex_lock(&ocm_inst_heap.lock);
+
+	ret = _ocm_free(addr, &ocm_inst_heap);
+
+	mutex_unlock(&ocm_inst_heap.lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(ocm_inst_free);
+
+/*
+ * ocm_free()
+ *	free a block in one of the ocm heaps, returns 0 if successful.
+ */
+int ocm_free(const void *addr)
+{
+	if (addr >= (void *)OCM_INST_HEAP_BEGIN
+		 && addr < (void *)(OCM_INST_HEAP_END))
+		return ocm_inst_free(addr);
+	else
+		return -1;
+}
+EXPORT_SYMBOL(ocm_free);
+
+
+#ifdef CONFIG_PROC_FS
+/* Need to keep line of output the same.  Currently, that is 46 bytes
+ * (including newline).
+ */
+static int _ocm_proc_read(char *buf, int *len, int count, const char *desc,
+			   struct ocm_heap *ocmheap)
+{
+	struct ocm_piece *pslot;
+	struct ocm_piece *pfree_head = &ocmheap->free_head;
+	struct ocm_piece *pused_head = &ocmheap->used_head;
+
+	/* The format is the following
+	 * --- OCM 123456789012345 Size   PID State     \n
+	 * 12345678-12345678 1234567890 12345 1234567890\n
+	 */
+	int l;
+	l = sprintf(&buf[*len], "--- OCM %-15s Size   PID State     \n",
+		    desc);
+
+	*len += l;
+	count -= l;
+
+	mutex_lock(&ocm_inst_heap.lock);
+
+	/*
+	 * search the relevant memory slot
+	 */
+	pslot = pused_head->next;
+
+	while (pslot != NULL && count > 46) {
+		l = sprintf(&buf[*len], "%p-%p %10i %5i %-10s\n",
+			     pslot->paddr, pslot->paddr + pslot->size,
+			     pslot->size, pslot->pid, "ALLOCATED");
+
+		*len += l;
+		count -= l;
+		pslot = pslot->next;
+	}
+
+	pslot = pfree_head->next;
+
+	while (pslot != NULL && count > 46) {
+		l = sprintf(&buf[*len], "%p-%p %10i %5i %-10s\n",
+			    pslot->paddr, pslot->paddr + pslot->size,
+			    pslot->size, pslot->pid, "FREE");
+
+		*len += l;
+		count -= l;
+		pslot = pslot->next;
+	}
+
+	mutex_unlock(&ocm_inst_heap.lock);
+
+	return 0;
+}
+static int ocm_proc_read(char *buf, char **start, off_t offset, int count,
+		int *eof, void *data)
+{
+	int len = 0;
+
+	if (_ocm_proc_read(buf, &len, count - len, "Inst Heap",
+			    &ocm_inst_heap))
+		goto not_done;
+	*eof = 1;
+ not_done:
+	return len;
+}
+
+static int __init sram_proc_init(void)
+{
+	struct proc_dir_entry *ptr;
+	ptr = create_proc_entry("ocm", S_IFREG | S_IRUGO, NULL);
+	if (!ptr) {
+		printk(KERN_WARNING "unable to create /proc/ocm\n");
+		return -1;
+	}
+	ptr->owner = THIS_MODULE;
+	ptr->read_proc = ocm_proc_read;
+	return 0;
+}
+late_initcall(sram_proc_init);
+#endif
--- /dev/null
+++ b/arch/ubicom32/oprofile/ipProf.h
@@ -0,0 +1,39 @@
+#ifndef __IP_PROF_H__
+#define __IP_PROF_H__
+
+/* This number MUST match what is used in the ultra configuration! */
+#define IPPROFILETIO_MAX_SAMPLES	600
+
+/* Move to .h file used in both; avoid special types  */
+struct profile_sample {
+	unsigned int	pc;		/* PC value */
+	unsigned int	parent;		/* a5 contents, to find the caller */
+	unsigned char	cond_codes;	/* for branch prediction */
+	unsigned char	thread;		/* I-blocked, D-blocked,
+					   4-bit thread number */
+	unsigned short	active;		/* which threads are active -
+					   for accurate counting */
+	unsigned short	blocked;	/* which threads are blocked due to
+					   I or D cache misses */
+	unsigned int	latency;	/* CPU clocks since the last message
+					   dispatch in this thread
+					   (thread 0 only for now) */
+};
+
+
+struct profilenode {
+	struct devtree_node dn;
+	volatile unsigned char enabled;	/* Is the tio enabled to
+					   take samples? */
+	volatile unsigned char busy;	/* set when the samples
+					   are being read */
+	volatile unsigned int mask;	/* Threads that change the MT_EN flag */
+	volatile unsigned short rate;	/* What is the sampling rate? */
+	volatile unsigned short head;	/* sample taker puts samples here */
+	volatile unsigned short tail;	/* packet filler takes samples here */
+	volatile unsigned short count;	/* number of valid samples */
+	volatile unsigned short total;	/* Total samples */
+	struct profile_sample samples[IPPROFILETIO_MAX_SAMPLES];
+};
+
+#endif
--- /dev/null
+++ b/arch/ubicom32/oprofile/Makefile
@@ -0,0 +1,37 @@
+#
+# arch/ubicom32/Makefile
+#       Makefile for Oprofile support on Ubicom32
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not,
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+obj-$(CONFIG_OPROFILE) += oprofile.o
+
+DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
+		oprof.o cpu_buffer.o buffer_sync.o \
+		event_buffer.o oprofile_files.o \
+		oprofilefs.o oprofile_stats.o \
+		timer_int.o )
+
+oprofile-y	:= $(DRIVER_OBJS) profile.o
--- /dev/null
+++ b/arch/ubicom32/oprofile/profile.c
@@ -0,0 +1,221 @@
+/*
+ * arch/ubicom32/oprofile/profile.c
+ *	Oprofile support for arch Ubicom32
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option)
+ * any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+/**
+ * @file profile.c
+ *
+ * @remark Copyright 2002 OProfile authors
+ * @remark Read the file COPYING
+ *
+ * @author Hunyue Yau <hy@hy-research.com>
+ */
+
+#include <linux/oprofile.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+#include <asm/devtree.h>
+#include <asm/thread.h>
+
+/* For identifying userland vs kernel address */
+#include <asm/stacktrace.h>
+#include "ipProf.h"
+
+/* For communications with the backend */
+static struct profilenode *profile_node;
+
+/* Bitmask containing all Linux threads - as seen by the ROSR reg */
+static unsigned long th_all_mask;
+
+/* Lookup table to translate a hardware thread into a CPU identifier
+ * Table is indexed by the ROSR value which is assumed to be
+ * relatively small (0...15).
+ */
+unsigned int cpu_map[THREAD_ARCHITECTURAL_MAX];
+
+static struct pt_regs regs;
+
+/*
+ * For each sample returned, checked to see if they are relevant to
+ * us. This is necessary as the ubicom32 architecture has other software
+ * running outside of Linux. Only then, put the sample into the relevant
+ * cpu bins.
+ *
+ * To minimize overhead, a global mask with all possible threads of in
+ * interest to us is used as a first check. Then a second mask identifying
+ * the thread is used to obtain an identifier for that "CPU".
+ */
+
+/*
+ * ubicom32_build_cpu_th_mask()
+ *
+ * Build a lookup table for translation between hardware thread
+ * "ROSR" values and Linux CPU ids
+ *
+ * *** This gets executed on all CPUs at once! ***
+ */
+static void ubicom32_build_cpu_th_mask(void *mask)
+{
+	thread_t self = thread_get_self();
+	unsigned long *th_m = mask;
+
+	BUG_ON(self <= 0 || self >= THREAD_ARCHITECTURAL_MAX);
+	cpu_map[self] = smp_processor_id();
+
+	set_bit(self, th_m);
+}
+
+/*
+ * profile_interrupt()
+ *
+ * Process samples returned from the profiler backend. The backend
+ * may return samples that are irrelevant to us or may even return
+ * multiple samples for the same CPU. Note that the sames may be
+ * for ANY cpu. At this time, this is unique and to support this requires
+ * Oprofile to expose an interface to accept the CPU that the same came
+ * frome.
+ */
+static irqreturn_t profile_interrupt(int irq, void *arg)
+{
+	int i, buf_entry;
+	int is_kernel;
+	unsigned int bit_th;
+	unsigned int th;
+
+	if (!(profile_node->enabled) || profile_node->count < 0) {
+		printk(KERN_WARNING
+			"Unexpected interrupt, no samples or not enabled!\n");
+		return IRQ_HANDLED;
+	}
+
+	profile_node->busy = 1;		/* Keep backend out */
+
+	for (i = 0; i < profile_node->count; i++) {
+		buf_entry = profile_node->tail;
+		profile_node->tail++;
+		profile_node->tail %= IPPROFILETIO_MAX_SAMPLES;
+
+		/* Note - the "thread" ID is only the lower 4 bits */
+		th = (0x0f & profile_node->samples[buf_entry].thread);
+		bit_th = (1 << th);
+
+		if ((bit_th & th_all_mask) == 0)
+			continue;
+
+		regs.pc = profile_node->samples[buf_entry].pc;
+
+		is_kernel = ubicom32_is_kernel(regs.pc);
+
+		oprofile_add_ext_sample_cpu(regs.pc, &regs, 0, is_kernel,
+					    cpu_map[th]);
+	}
+	profile_node->count = 0;
+	profile_node->busy = 0;
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * profile_start()
+ *
+ * Notification from oprofile to start the profiler
+ */
+static int profile_start(void)
+{
+	if (!profile_node)
+		return -1;
+
+	profile_node->enabled = 1;
+
+	return 0;
+}
+
+/*
+ * profile_stop()
+ *
+ * Notification from oprofile to stop the profiler
+ */
+static void profile_stop(void)
+{
+	if (profile_node)
+		profile_node->enabled = 0;
+}
+
+/*
+ * oprofile_arch_init()
+ *
+ * Attach to Oprofile after qualify the availability of the backend
+ * profiler support.
+ */
+int __init oprofile_arch_init(struct oprofile_operations *ops)
+{
+	int r = -ENODEV;
+
+	profile_node = (struct profilenode *)devtree_find_node("profiler");
+
+	if (profile_node == NULL) {
+		printk(KERN_WARNING "Cannot find profiler node\n");
+		return r;
+	}
+
+	r = request_irq(profile_node->dn.recvirq, profile_interrupt,
+			IRQF_DISABLED, "profiler", NULL);
+
+	if (r < 0) {
+		profile_node = NULL;
+		printk(KERN_WARNING "Cannot get profiler IRQ\n");
+		return r;
+	}
+
+	ops->start = profile_start;
+	ops->stop = profile_stop;
+	ops->cpu_type = "timer";
+
+	memset(cpu_map, 0, sizeof(cpu_map));
+
+	on_each_cpu(ubicom32_build_cpu_th_mask, &th_all_mask, 1);
+
+	memset(&regs, 0, sizeof(regs));
+
+	return r;
+}
+
+/*
+ * oprofile_arch_exit()
+ *
+ * External call to take outselves out.
+ * Make sure backend is not running.
+ */
+void oprofile_arch_exit(void)
+{
+	BUG_ON(profile_node->enabled);
+}
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -134,3 +134,16 @@ config HW_RANDOM_VIRTIO
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called virtio-rng.  If unsure, say N.
+
+config HW_RANDOM_UBICOM32
+	tristate "Ubicom32 HW Random Number Generator support"
+	depends on HW_RANDOM && UBICOM32
+	default HW_RANDOM
+	---help---
+	  This driver provides kernel-side support for the Random Number
+	  Generator hardware found on Ubicom32 processors.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pasemi-rng.
+
+	  If unsure, say Y.
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx
 obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
 obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
 obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
+obj-$(CONFIG_HW_RANDOM_UBICOM32) += ubicom32-rng.o
--- /dev/null
+++ b/drivers/char/hw_random/ubicom32-rng.c
@@ -0,0 +1,105 @@
+/*
+ * drivers/net/ubi32-eth.c
+ *   Ubicom32 hardware random number generator driver.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/hw_random.h>
+#include <linux/delay.h>
+#include <asm/io.h>
+#include <asm/ip5000.h>
+
+#define MODULE_NAME "ubicom32_rng"
+
+static int ubicom32_rng_data_present(struct hwrng *rng, int wait)
+{
+	int data, i;
+
+	for (i = 0; i < 20; i++) {
+		data = *(int *)(TIMER_BASE + TIMER_TRN);
+		if (data || !wait)
+			break;
+		udelay(10);
+	}
+	return data;
+}
+
+static int ubicom32_rng_data_read(struct hwrng *rng, u32 *data)
+{
+	*data = *(int *)(TIMER_BASE + TIMER_TRN);
+	return 4;
+}
+
+static int ubicom32_rng_init(struct hwrng *rng)
+{
+	printk(KERN_INFO "ubicom32 rng init\n");
+	*(int *)(TIMER_BASE + TIMER_TRN_CFG) = TIMER_TRN_CFG_ENABLE_OSC;
+	return 0;
+}
+
+static void ubicom32_rng_cleanup(struct hwrng *rng)
+{
+	printk(KERN_INFO "ubicom32 rng cleanup\n");
+	*(int *)(TIMER_BASE + TIMER_TRN_CFG) = 0;
+}
+
+static struct hwrng ubicom32_rng = {
+	.name		= MODULE_NAME,
+	.init		= ubicom32_rng_init,
+	.cleanup	= ubicom32_rng_cleanup,
+	.data_present	= ubicom32_rng_data_present,
+	.data_read	= ubicom32_rng_data_read,
+	.priv		= 0,
+};
+
+static int __init mod_init(void)
+{
+	int err;
+
+	printk(KERN_INFO "ubicom32 rng started\n");
+	err = hwrng_register(&ubicom32_rng);
+	if (err) {
+		printk(KERN_ERR "ubicom32 rng register failed (%d)\n",
+			err);
+	}
+
+	return err;
+}
+
+static void __exit mod_exit(void)
+{
+	printk(KERN_INFO "ubicom32 rng stopped\n");
+	hwrng_unregister(&ubicom32_rng);
+}
+
+module_init(mod_init);
+module_exit(mod_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ubicom, Inc.");
+MODULE_DESCRIPTION("H/W rng driver for ubicom32 processor");
+MODULE_VERSION("1:1.0.a");
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -61,6 +61,40 @@ config CRYPTO_DEV_GEODE
 	  To compile this driver as a module, choose M here: the module
 	  will be called geode-aes.
 
+config CRYPTO_UBICOM32
+        bool "Ubicom32 Security Module"
+        depends on UBICOM32
+        help
+          This is the ubicom32 hardware acceleration common code.
+
+config CRYPTO_AES_UBICOM32
+        tristate "Ubicom32 AES implementation"
+        depends on CRYPTO_UBICOM32
+        select CRYPTO_ALGAPI
+        help
+          This is the ubicom32 hardware AES implementation.
+
+config CRYPTO_DES_UBICOM32
+        tristate "Ubicom32 DES implementation"
+        depends on CRYPTO_UBICOM32
+        select CRYPTO_ALGAPI
+        help
+          This is the ubicom32 hardware DES and 3DES implementation.
+
+config CRYPTO_SHA1_UBICOM32
+        tristate "Ubicom32 SHA1 implementation"
+        depends on CRYPTO_UBICOM32
+        select CRYPTO_ALGAPI
+        help
+          This is the ubicom32 hardware SHA1 implementation.
+
+config CRYPTO_MD5_UBICOM32
+        tristate "Ubicom32 MD5 implementation"
+        depends on CRYPTO_UBICOM32
+        select CRYPTO_ALGAPI
+        help
+          This is the ubicom32 hardware MD5 implementation.
+
 config ZCRYPT
 	tristate "Support for PCI-attached cryptographic adapters"
 	depends on S390
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -193,6 +193,13 @@ config MMC_TMIO
 	  This provides support for the SD/MMC cell found in TC6393XB,
 	  T7L66XB and also ipaq ASIC3
 
+config MMC_UBICOM32
+	tristate "Ubicom32 MMC/SD host controller"
+	depends on UBICOM32
+	help
+	  This provides support for the SD/MMC hardware found on Ubicom32 
+	  IP7K processors
+
 config GPIOMMC
 	tristate "MMC/SD over GPIO-based SPI"
 	depends on MMC && MMC_SPI && (SPI_GPIO || SPI_GPIO_OLD)
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -22,5 +22,6 @@ obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
 obj-$(CONFIG_MMC_S3C)   	+= s3cmci.o
 obj-$(CONFIG_MMC_SDRICOH_CS)	+= sdricoh_cs.o
 obj-$(CONFIG_MMC_TMIO)		+= tmio_mmc.o
+obj-$(CONFIG_MMC_UBICOM32)	+= ubicom32sd.o
 obj-$(CONFIG_GPIOMMC)		+= gpiommc.o
 
--- /dev/null
+++ b/drivers/mmc/host/ubicom32sd.c
@@ -0,0 +1,774 @@
+/*
+ * drivers/mmc/host/ubicom32sd.c
+ *	Ubicom32 Secure Digital Host Controller Interface driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/scatterlist.h>
+#include <linux/leds.h>
+#include <linux/gpio.h>
+#include <linux/mmc/host.h>
+
+#include <asm/ubicom32sd.h>
+
+#define DRIVER_NAME "ubicom32sd"
+
+#define sd_printk(...)
+//#define sd_printk printk
+
+#define SDTIO_VP_VERSION	3
+
+#define SDTIO_MAX_SG_BLOCKS	16
+
+enum sdtio_commands {
+	SDTIO_COMMAND_NOP,
+	SDTIO_COMMAND_SETUP,
+	SDTIO_COMMAND_SETUP_SDIO,
+	SDTIO_COMMAND_EXECUTE,
+	SDTIO_COMMAND_RESET,
+};
+
+#define SDTIO_COMMAND_SHIFT			24
+#define SDTIO_COMMAND_FLAG_STOP_RSP_CRC		(1 << 10)
+#define SDTIO_COMMAND_FLAG_STOP_RSP_136		(1 << 9)
+#define SDTIO_COMMAND_FLAG_STOP_RSP		(1 << 8)
+#define SDTIO_COMMAND_FLAG_STOP_CMD		(1 << 7)
+#define SDTIO_COMMAND_FLAG_DATA_STREAM		(1 << 6)
+#define SDTIO_COMMAND_FLAG_DATA_RD		(1 << 5)
+#define SDTIO_COMMAND_FLAG_DATA_WR		(1 << 4)
+#define SDTIO_COMMAND_FLAG_CMD_RSP_CRC		(1 << 3)
+#define SDTIO_COMMAND_FLAG_CMD_RSP_136		(1 << 2)
+#define SDTIO_COMMAND_FLAG_CMD_RSP		(1 << 1)
+#define SDTIO_COMMAND_FLAG_CMD			(1 << 0)
+
+/*
+ * SDTIO_COMMAND_SETUP_SDIO
+ */
+#define SDTIO_COMMAND_FLAG_SDIO_INT_EN		(1 << 0)
+
+/*
+ * SDTIO_COMMAND_SETUP
+ *      clock speed in arg
+ */
+#define SDTIO_COMMAND_FLAG_4BIT                 (1 << 3)
+#define SDTIO_COMMAND_FLAG_1BIT                 (1 << 2)
+#define SDTIO_COMMAND_FLAG_SET_CLOCK            (1 << 1)
+#define SDTIO_COMMAND_FLAG_SET_WIDTH            (1 << 0)
+
+#define SDTIO_COMMAND_FLAG_CMD_RSP_MASK		(SDTIO_COMMAND_FLAG_CMD_RSP | SDTIO_COMMAND_FLAG_CMD_RSP_136)
+#define SDTIO_COMMAND_FLAG_STOP_RSP_MASK	(SDTIO_COMMAND_FLAG_STOP_RSP | SDTIO_COMMAND_FLAG_STOP_RSP_136)
+#define SDTIO_COMMAND_FLAG_RSP_MASK		(SDTIO_COMMAND_FLAG_CMD_RSP_MASK | SDTIO_COMMAND_FLAG_STOP_RSP_MASK)
+
+struct sdtio_vp_sg {
+	volatile void		*addr;
+	volatile u32_t		len;
+};
+
+#define SDTIO_VP_INT_STATUS_DONE		(1 << 31)
+#define SDTIO_VP_INT_STATUS_SDIO_INT		(1 << 10)
+#define SDTIO_VP_INT_STATUS_DATA_CRC_ERR	(1 << 9)
+#define SDTIO_VP_INT_STATUS_DATA_PROG_ERR	(1 << 8)
+#define SDTIO_VP_INT_STATUS_DATA_TIMEOUT	(1 << 7)
+#define SDTIO_VP_INT_STATUS_STOP_RSP_CRC	(1 << 6)
+#define SDTIO_VP_INT_STATUS_STOP_RSP_TIMEOUT	(1 << 5)
+#define SDTIO_VP_INT_STATUS_CMD_RSP_CRC		(1 << 4)
+#define SDTIO_VP_INT_STATUS_CMD_RSP_TIMEOUT	(1 << 3)
+#define SDTIO_VP_INT_STATUS_CMD_TIMEOUT		(1 << 2)
+#define SDTIO_VP_INT_STATUS_CARD1_INSERT	(1 << 1)
+#define SDTIO_VP_INT_STATUS_CARD0_INSERT	(1 << 0)
+
+struct sdtio_vp_regs {
+	u32_t				version;
+	u32_t				f_max;
+	u32_t				f_min;
+
+	volatile u32_t			int_status;
+
+	volatile u32_t			command;
+	volatile u32_t			arg;
+
+	volatile u32_t			cmd_opcode;
+	volatile u32_t			cmd_arg;
+	volatile u32_t			cmd_rsp0;
+	volatile u32_t			cmd_rsp1;
+	volatile u32_t			cmd_rsp2;
+	volatile u32_t			cmd_rsp3;
+
+	volatile u32_t			stop_opcode;
+	volatile u32_t			stop_arg;
+	volatile u32_t			stop_rsp0;
+	volatile u32_t			stop_rsp1;
+	volatile u32_t			stop_rsp2;
+	volatile u32_t			stop_rsp3;
+
+	volatile u32_t			data_timeout_ns;
+	volatile u16_t			data_blksz;
+	volatile u16_t			data_blkct;
+	volatile u32_t			data_bytes_transferred;
+	volatile u32_t			sg_len;
+	struct sdtio_vp_sg		sg[SDTIO_MAX_SG_BLOCKS];
+};
+
+struct ubicom32sd_data {
+	const struct ubicom32sd_platform_data	*pdata;
+
+	struct mmc_host				*mmc;
+
+	/*
+	 * Lock used to protect the data structure
+	spinlock_t				lock;
+	 */
+	int	int_en;
+	int	int_pend;
+
+	/*
+	 * Receive and transmit interrupts used for communicating 
+	 * with hardware
+	 */
+	int					irq_tx;
+	int					irq_rx;
+
+	/*
+	 * Current outstanding mmc request
+	 */
+	struct mmc_request			*mrq;
+
+	/*
+	 * Hardware registers
+	 */
+	struct sdtio_vp_regs			*regs;
+};
+
+/*****************************************************************************\
+ *                                                                           *
+ * Suspend/resume                                                            *
+ *                                                                           *
+\*****************************************************************************/
+
+#if 0//def CONFIG_PM
+
+int ubicom32sd_suspend_host(struct ubicom32sd_host *host, pm_message_t state)
+{
+	int ret;
+
+	ret = mmc_suspend_host(host->mmc, state);
+	if (ret)
+		return ret;
+
+	free_irq(host->irq, host);
+
+	return 0;
+}
+
+EXPORT_SYMBOL_GPL(ubicom32sd_suspend_host);
+
+int ubicom32sd_resume_host(struct ubicom32sd_host *host)
+{
+	int ret;
+
+	if (host->flags & UBICOM32SD_USE_DMA) {
+		if (host->ops->enable_dma)
+			host->ops->enable_dma(host);
+	}
+
+	ret = request_irq(host->irq, ubicom32sd_irq, IRQF_SHARED,
+			  mmc_hostname(host->mmc), host);
+	if (ret)
+		return ret;
+
+	ubicom32sd_init(host);
+	mmiowb();
+
+	ret = mmc_resume_host(host->mmc);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+EXPORT_SYMBOL_GPL(ubicom32sd_resume_host);
+
+#endif /* CONFIG_PM */
+
+/*
+ * ubicom32sd_send_command_sync
+ */
+static void ubicom32sd_send_command_sync(struct ubicom32sd_data *ud, u32_t command, u32_t arg)
+{
+	ud->regs->command = command;
+	ud->regs->arg = arg;
+	ubicom32_set_interrupt(ud->irq_tx);
+	while (ud->regs->command) {
+		ndelay(100);
+	}
+}
+
+/*
+ * ubicom32sd_send_command
+ */
+static void ubicom32sd_send_command(struct ubicom32sd_data *ud, u32_t command, u32_t arg)
+{
+	ud->regs->command = command;
+	ud->regs->arg = arg;
+	ubicom32_set_interrupt(ud->irq_tx);
+}
+
+/*
+ * ubicom32sd_reset
+ */
+static void ubicom32sd_reset(struct ubicom32sd_data *ud)
+{
+	ubicom32sd_send_command_sync(ud, SDTIO_COMMAND_RESET << SDTIO_COMMAND_SHIFT, 0);
+	ud->regs->int_status = 0;
+}
+
+/*
+ * ubicom32sd_mmc_request
+ */
+static void ubicom32sd_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	u32_t command = SDTIO_COMMAND_EXECUTE << SDTIO_COMMAND_SHIFT;
+	int ret = 0;
+
+	WARN(ud->mrq != NULL, "ud->mrq still set to %p\n", ud->mrq);
+	//pr_debug("send cmd %08x arg %08x flags %08x\n", cmd->opcode, cmd->arg, cmd->flags);
+
+	if (mrq->cmd) {
+		struct mmc_command *cmd = mrq->cmd;
+
+		sd_printk("%s:\t\t\tsetup cmd %02d arg %08x flags %08x\n", mmc_hostname(mmc), cmd->opcode, cmd->arg, cmd->flags);
+
+		ud->regs->cmd_opcode = cmd->opcode;
+		ud->regs->cmd_arg = cmd->arg;
+
+		command |= SDTIO_COMMAND_FLAG_CMD;
+
+		if (cmd->flags & MMC_RSP_PRESENT) {
+			command |= SDTIO_COMMAND_FLAG_CMD_RSP;
+		}
+
+		if (cmd->flags & MMC_RSP_136) {
+			command |= SDTIO_COMMAND_FLAG_CMD_RSP_136;
+		}
+
+		if (cmd->flags & MMC_RSP_CRC) {
+			command |= SDTIO_COMMAND_FLAG_CMD_RSP_CRC;
+		}
+	}
+
+	if (mrq->data) {
+		struct mmc_data *data = mrq->data;
+		struct scatterlist *sg = data->sg;
+		int i;
+
+printk("%s:\t\t\tsetup data blksz %d num %d sglen=%d fl=%08x Tns=%u\n", mmc_hostname(mmc), data->blksz, data->blocks, data->sg_len, data->flags, data->timeout_ns);
+
+		sd_printk("%s:\t\t\tsetup data blksz %d num %d sglen=%d fl=%08x Tns=%u\n", 
+			  mmc_hostname(mmc), data->blksz, data->blocks, data->sg_len, 
+			  data->flags, data->timeout_ns);
+
+		if (data->sg_len > SDTIO_MAX_SG_BLOCKS) {
+			ret = -EINVAL;
+			data->error = -EINVAL;
+			goto fail;
+		} 
+
+		ud->regs->data_timeout_ns = data->timeout_ns;
+		ud->regs->data_blksz = data->blksz;
+		ud->regs->data_blkct = data->blocks;
+		ud->regs->sg_len = data->sg_len;
+
+		/*
+		 * Load all of our sg list into the driver sg buffer
+		 */
+		for (i = 0; i < data->sg_len; i++) {
+			sd_printk("%s: sg %d = %p %d\n", mmc_hostname(mmc), i, sg_virt(sg), sg->length);
+			ud->regs->sg[i].addr = sg_virt(sg);
+			ud->regs->sg[i].len = sg->length;
+			if (((u32_t)ud->regs->sg[i].addr & 0x03) || (sg->length & 0x03)) {
+				sd_printk("%s: Need aligned buffers\n", mmc_hostname(mmc));
+				ret = -EINVAL;
+				data->error = -EINVAL;
+				goto fail;
+			}
+			sg++;
+		}
+		if (data->flags & MMC_DATA_READ) {
+			command |= SDTIO_COMMAND_FLAG_DATA_RD;
+		} else if (data->flags & MMC_DATA_WRITE) {
+			command |= SDTIO_COMMAND_FLAG_DATA_WR;
+		} else if (data->flags & MMC_DATA_STREAM) {
+			command |= SDTIO_COMMAND_FLAG_DATA_STREAM;
+		}
+	}
+
+	if (mrq->stop) {
+		struct mmc_command *stop = mrq->stop;
+		sd_printk("%s: \t\t\tsetup stop %02d arg %08x flags %08x\n", mmc_hostname(mmc), stop->opcode, stop->arg, stop->flags);
+
+		ud->regs->stop_opcode = stop->opcode;
+		ud->regs->stop_arg = stop->arg;
+
+		command |= SDTIO_COMMAND_FLAG_STOP_CMD;
+
+		if (stop->flags & MMC_RSP_PRESENT) {
+			command |= SDTIO_COMMAND_FLAG_STOP_RSP;
+		}
+
+		if (stop->flags & MMC_RSP_136) {
+			command |= SDTIO_COMMAND_FLAG_STOP_RSP_136;
+		}
+
+		if (stop->flags & MMC_RSP_CRC) {
+			command |= SDTIO_COMMAND_FLAG_STOP_RSP_CRC;
+		}
+	}
+
+	ud->mrq = mrq;
+
+	sd_printk("%s: Sending command %08x\n", mmc_hostname(mmc), command);
+
+	ubicom32sd_send_command(ud, command, 0);
+
+	return;
+fail:
+	sd_printk("%s: mmcreq ret = %d\n", mmc_hostname(mmc), ret);
+	mrq->cmd->error = ret;
+	mmc_request_done(mmc, mrq);
+}
+
+/*
+ * ubicom32sd_mmc_set_ios
+ */
+static void ubicom32sd_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
+{
+	struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	u32_t command = SDTIO_COMMAND_SETUP << SDTIO_COMMAND_SHIFT;
+	u32_t arg = 0;
+	sd_printk("%s: ios call bw:%u pm:%u clk:%u\n", mmc_hostname(mmc), 1 << ios->bus_width, ios->power_mode, ios->clock);
+
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_1:
+		command |= SDTIO_COMMAND_FLAG_SET_WIDTH | SDTIO_COMMAND_FLAG_1BIT;
+		break;
+
+	case MMC_BUS_WIDTH_4:
+		command |= SDTIO_COMMAND_FLAG_SET_WIDTH | SDTIO_COMMAND_FLAG_4BIT;
+		break;
+	}
+
+	if (ios->clock) {
+		arg = ios->clock;
+		command |= SDTIO_COMMAND_FLAG_SET_CLOCK;
+	}
+
+	switch (ios->power_mode) {
+
+	/*
+	 * Turn off the SD bus (power + clock)
+	 */
+	case MMC_POWER_OFF:
+		gpio_set_value(ud->pdata->cards[0].pin_pwr, !ud->pdata->cards[0].pwr_polarity);
+		command |= SDTIO_COMMAND_FLAG_SET_CLOCK;
+		break;
+
+	/*
+	 * Turn on the power to the SD bus
+	 */
+	case MMC_POWER_ON:
+		gpio_set_value(ud->pdata->cards[0].pin_pwr, ud->pdata->cards[0].pwr_polarity);
+		break;
+
+	/*
+	 * Turn on the clock to the SD bus
+	 */
+	case MMC_POWER_UP:
+		/*
+		 * Done above
+		 */
+		break;
+	}
+
+	ubicom32sd_send_command_sync(ud, command, arg);
+
+	/*
+	 * Let the power settle down
+	 */
+	udelay(500);
+}
+
+/*
+ * ubicom32sd_mmc_get_cd
+ */
+static int ubicom32sd_mmc_get_cd(struct mmc_host *mmc)
+{
+	struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	sd_printk("%s: get cd %u %u\n", mmc_hostname(mmc), ud->pdata->cards[0].pin_cd, gpio_get_value(ud->pdata->cards[0].pin_cd));
+
+	return gpio_get_value(ud->pdata->cards[0].pin_cd) ? 
+				ud->pdata->cards[0].cd_polarity : 
+				!ud->pdata->cards[0].cd_polarity;
+}
+
+/*
+ * ubicom32sd_mmc_get_ro
+ */
+static int ubicom32sd_mmc_get_ro(struct mmc_host *mmc)
+{
+	struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	sd_printk("%s: get ro %u %u\n", mmc_hostname(mmc), ud->pdata->cards[0].pin_wp, gpio_get_value(ud->pdata->cards[0].pin_wp));
+
+	return gpio_get_value(ud->pdata->cards[0].pin_wp) ? 
+				ud->pdata->cards[0].wp_polarity :
+				!ud->pdata->cards[0].wp_polarity;
+}
+
+/*
+ * ubicom32sd_mmc_enable_sdio_irq
+ */
+static void ubicom32sd_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
+{
+	struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+
+	ud->int_en = enable;
+	if (enable && ud->int_pend) {
+		ud->int_pend = 0;
+		mmc_signal_sdio_irq(mmc);
+	}
+}
+
+/*
+ * ubicom32sd_interrupt
+ */
+static irqreturn_t ubicom32sd_interrupt(int irq, void *dev)
+{
+	struct mmc_host *mmc = (struct mmc_host *)dev;
+	struct mmc_request *mrq;
+	struct ubicom32sd_data *ud;
+	u32_t int_status;
+
+	if (!mmc) {
+		return IRQ_HANDLED;
+	}
+
+	ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	if (!ud) {
+		return IRQ_HANDLED;
+	}
+
+	int_status = ud->regs->int_status;
+	ud->regs->int_status &= ~int_status;
+
+	if (int_status & SDTIO_VP_INT_STATUS_SDIO_INT) {
+		if (ud->int_en) {
+			ud->int_pend = 0;
+			mmc_signal_sdio_irq(mmc);
+		} else {
+			ud->int_pend++;
+		}
+	}
+
+	if (!(int_status & SDTIO_VP_INT_STATUS_DONE)) {
+		return IRQ_HANDLED;
+	}
+
+	mrq = ud->mrq;
+	if (!mrq) {
+		sd_printk("%s: Spurious interrupt", mmc_hostname(mmc));
+		return IRQ_HANDLED;
+	}
+	ud->mrq = NULL;
+
+	/*
+	 * SDTIO_VP_INT_DONE
+	 */
+	if (mrq->cmd->flags & MMC_RSP_PRESENT) {
+		struct mmc_command *cmd = mrq->cmd;
+		cmd->error = 0;
+
+		if ((cmd->flags & MMC_RSP_CRC) && (int_status & SDTIO_VP_INT_STATUS_CMD_RSP_CRC)) {
+			cmd->error = -EILSEQ;
+		} else if (int_status & SDTIO_VP_INT_STATUS_CMD_RSP_TIMEOUT) {
+			cmd->error = -ETIMEDOUT;
+			goto done;
+		} else if (cmd->flags & MMC_RSP_136) {
+			cmd->resp[0] = ud->regs->cmd_rsp0;
+			cmd->resp[1] = ud->regs->cmd_rsp1;
+			cmd->resp[2] = ud->regs->cmd_rsp2;
+			cmd->resp[3] = ud->regs->cmd_rsp3;
+		} else {
+			cmd->resp[0] = ud->regs->cmd_rsp0;
+		}
+		sd_printk("%s:\t\t\tResponse %08x %08x %08x %08x err=%d\n", mmc_hostname(mmc), cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error);
+	}
+
+	if (mrq->data) {
+		struct mmc_data *data = mrq->data;
+
+		if (int_status & SDTIO_VP_INT_STATUS_DATA_TIMEOUT) {
+			data->error = -ETIMEDOUT;
+			sd_printk("%s:\t\t\tData Timeout\n", mmc_hostname(mmc));
+			goto done;
+		} else if (int_status & SDTIO_VP_INT_STATUS_DATA_CRC_ERR) {
+			data->error = -EILSEQ;
+			sd_printk("%s:\t\t\tData CRC\n", mmc_hostname(mmc));
+			goto done;
+		} else if (int_status & SDTIO_VP_INT_STATUS_DATA_PROG_ERR) {
+			data->error = -EILSEQ;
+			sd_printk("%s:\t\t\tData Program Error\n", mmc_hostname(mmc));
+			goto done;
+		} else {
+			data->error = 0;
+			data->bytes_xfered = ud->regs->data_bytes_transferred;
+		}
+	}
+
+	if (mrq->stop && (mrq->stop->flags & MMC_RSP_PRESENT)) {
+		struct mmc_command *stop = mrq->stop;
+		stop->error = 0;
+
+		if ((stop->flags & MMC_RSP_CRC) && (int_status & SDTIO_VP_INT_STATUS_STOP_RSP_CRC)) {
+			stop->error = -EILSEQ;
+		} else if (int_status & SDTIO_VP_INT_STATUS_STOP_RSP_TIMEOUT) {
+			stop->error = -ETIMEDOUT;
+			goto done;
+		} else if (stop->flags & MMC_RSP_136) {
+			stop->resp[0] = ud->regs->stop_rsp0;
+			stop->resp[1] = ud->regs->stop_rsp1;
+			stop->resp[2] = ud->regs->stop_rsp2;
+			stop->resp[3] = ud->regs->stop_rsp3;
+		} else {
+			stop->resp[0] = ud->regs->stop_rsp0;
+		}
+		sd_printk("%s:\t\t\tStop Response %08x %08x %08x %08x err=%d\n", mmc_hostname(mmc), stop->resp[0], stop->resp[1], stop->resp[2], stop->resp[3], stop->error);
+	}
+
+done:
+	mmc_request_done(mmc, mrq);
+
+	return IRQ_HANDLED;
+}
+
+static struct mmc_host_ops ubicom32sd_ops = {
+	.request		= ubicom32sd_mmc_request,
+	.set_ios		= ubicom32sd_mmc_set_ios,
+	.get_ro			= ubicom32sd_mmc_get_ro,
+	.get_cd			= ubicom32sd_mmc_get_cd,
+	.enable_sdio_irq	= ubicom32sd_mmc_enable_sdio_irq,
+};
+
+/*
+ * ubicom32sd_probe
+ */
+static int __devinit ubicom32sd_probe(struct platform_device *pdev)
+{
+	struct ubicom32sd_platform_data *pdata = (struct ubicom32sd_platform_data *)pdev->dev.platform_data;
+	struct mmc_host *mmc;
+	struct ubicom32sd_data *ud;
+	struct resource *res_regs;
+	struct resource *res_irq_tx;
+	struct resource *res_irq_rx;
+	int ret;
+
+	/*
+	 * Get our resources, regs is the hardware driver base address
+	 * and the tx and rx irqs are used to communicate with the 
+	 * hardware driver.
+	 */
+	res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	res_irq_tx = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
+	if (!res_regs || !res_irq_tx || !res_irq_rx) {
+		ret = -EINVAL;
+		goto fail;
+	}
+
+	/*
+	 * Reserve any gpios we need
+	 */
+	ret = gpio_request(pdata->cards[0].pin_wp, "sd-wp");
+	if (ret) {
+		goto fail;
+	}
+	gpio_direction_input(pdata->cards[0].pin_wp);
+
+	ret = gpio_request(pdata->cards[0].pin_cd, "sd-cd");
+	if (ret) {
+		goto fail_cd;
+	}
+	gpio_direction_input(pdata->cards[0].pin_cd);
+
+	/*
+	 * HACK: for the dual port controller on port F, we don't support the second port right now
+	 */
+	if (pdata->ncards > 1) {
+		ret = gpio_request(pdata->cards[1].pin_pwr, "sd-pwr");
+		gpio_direction_output(pdata->cards[1].pin_pwr, !pdata->cards[1].pwr_polarity);
+		gpio_direction_output(pdata->cards[1].pin_pwr, pdata->cards[1].pwr_polarity);
+	}
+
+	ret = gpio_request(pdata->cards[0].pin_pwr, "sd-pwr");
+	if (ret) {
+		goto fail_pwr;
+	}
+	gpio_direction_output(pdata->cards[0].pin_pwr, !pdata->cards[0].pwr_polarity);
+
+	/*
+	 * Allocate the MMC driver, it includes memory for our data.
+	 */
+	mmc = mmc_alloc_host(sizeof(struct ubicom32sd_data), &pdev->dev);
+	if (!mmc) {
+		ret = -ENOMEM;
+		goto fail_mmc;
+	}
+	ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+	ud->mmc = mmc;
+	ud->pdata = pdata;
+	ud->regs = (struct sdtio_vp_regs *)res_regs->start;
+	ud->irq_tx = res_irq_tx->start;
+	ud->irq_rx = res_irq_rx->start;
+	platform_set_drvdata(pdev, mmc);
+
+	ret = request_irq(ud->irq_rx, ubicom32sd_interrupt, IRQF_DISABLED, mmc_hostname(mmc), mmc);
+	if (ret) {
+		goto fail_mmc;
+	}
+
+	/*
+	 * Fill in the mmc structure
+	 */
+	mmc->ops = &ubicom32sd_ops;
+	mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_NEEDS_POLL | MMC_CAP_SDIO_IRQ |
+		    MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
+
+	mmc->f_min = ud->regs->f_min;
+	mmc->f_max = ud->regs->f_max;
+	mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
+
+	/*
+	 * Setup some restrictions on transfers
+	 *
+	 * We allow up to SDTIO_MAX_SG_BLOCKS of data to DMA into, there are
+	 * not really any "max_seg_size", "max_req_size", or "max_blk_count"
+	 * restrictions (must be less than U32_MAX though), pick
+	 * something large?!...
+	 *
+	 * The hardware can do up to 4095 bytes per block, since the spec
+	 * only requires 2048, we'll set it to that and not worry about
+	 * potential weird blk lengths.
+	 */
+	mmc->max_hw_segs = SDTIO_MAX_SG_BLOCKS;
+	mmc->max_phys_segs = SDTIO_MAX_SG_BLOCKS;
+	mmc->max_seg_size = 1024 * 1024;
+	mmc->max_req_size = 1024 * 1024;
+	mmc->max_blk_count = 1024;
+
+	mmc->max_blk_size = 2048;
+
+	ubicom32sd_reset(ud);
+
+	/*
+	 * enable interrupts
+	 */
+	ud->int_en = 0;
+	ubicom32sd_send_command_sync(ud, SDTIO_COMMAND_SETUP_SDIO << SDTIO_COMMAND_SHIFT | SDTIO_COMMAND_FLAG_SDIO_INT_EN, 0);
+
+	mmc_add_host(mmc);
+
+	printk(KERN_INFO "%s at %p, irq %d/%d\n", mmc_hostname(mmc),
+			ud->regs, ud->irq_tx, ud->irq_rx);
+	return 0;
+
+fail_mmc:
+	gpio_free(pdata->cards[0].pin_pwr);
+fail_pwr:
+	gpio_free(pdata->cards[0].pin_cd);
+fail_cd:
+	gpio_free(pdata->cards[0].pin_wp);
+fail:
+	return ret;
+}
+
+/*
+ * ubicom32sd_remove
+ */
+static int __devexit ubicom32sd_remove(struct platform_device *pdev)
+{
+	struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+	platform_set_drvdata(pdev, NULL);
+
+	if (mmc) {
+		struct ubicom32sd_data *ud = (struct ubicom32sd_data *)mmc_priv(mmc);
+
+		gpio_free(ud->pdata->cards[0].pin_pwr);
+		gpio_free(ud->pdata->cards[0].pin_cd);
+		gpio_free(ud->pdata->cards[0].pin_wp);
+
+		mmc_remove_host(mmc);
+		mmc_free_host(mmc);
+	}
+
+	/*
+	 * Note that our data is allocated as part of the mmc structure
+	 * so we don't need to free it.
+	 */
+	return 0;
+}
+
+static struct platform_driver ubicom32sd_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = ubicom32sd_probe,
+	.remove = __devexit_p(ubicom32sd_remove),
+#if 0
+	.suspend = ubicom32sd_suspend,
+	.resume = ubicom32sd_resume,
+#endif
+};
+
+/*
+ * ubicom32sd_init
+ */
+static int __init ubicom32sd_init(void)
+{
+	return platform_driver_register(&ubicom32sd_driver);
+}
+module_init(ubicom32sd_init);
+
+/*
+ * ubicom32sd_exit
+ */
+static void __exit ubicom32sd_exit(void)
+{
+    platform_driver_unregister(&ubicom32sd_driver);
+}
+module_exit(ubicom32sd_exit);
+
+MODULE_AUTHOR("Patrick Tjin");
+MODULE_DESCRIPTION("Ubicom32 Secure Digital Host Controller Interface driver");
+MODULE_LICENSE("GPL");
+
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -104,6 +104,17 @@ config M25PXX_USE_FAST_READ
 	help
 	  This option enables FAST_READ access supported by ST M25Pxx.
 
+config MTD_UBI32_M25P80
+	tristate "Ubicom processor support for most SPI Flash chips (AT26DF, M25P, W25X, ...)"
+	depends on UBICOM32
+	default y
+	help
+	  This enables access to most modern SPI flash chips, used for
+	  program and data storage.   Series supported include Atmel AT26DF,
+	  Spansion S25SL, SST 25VF, ST M25P, and Winbond W25X.  Other chips
+	  are supported as well.  See the driver source for the current list,
+	  or to add other chips.
+
 config MTD_SLRAM
 	tristate "Uncached system RAM"
 	help
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -16,3 +16,4 @@ obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
 obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
 obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
+obj-$(CONFIG_MTD_UBI32_M25P80)	+= ubi32-m25p80.o
--- /dev/null
+++ b/drivers/mtd/devices/ubi32-m25p80.c
@@ -0,0 +1,1066 @@
+/*
+ * drivers/mtd/devices/ubi32-m25p80.c
+ *   NOR flash driver, Ubicom processor internal SPI flash interface.
+ *
+ *   This code instantiates the serial flash that contains the
+ *   original bootcode.  The serial flash start at address 0x60000000
+ *   in both Ubicom32V3 and Ubicom32V4 ISAs.
+ *
+ *   This piece of flash is made to appear as a Memory Technology
+ *   Device (MTD) with this driver to allow Read/Write/Erase operations.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/flash.h>
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+
+#include <asm/ip5000.h>
+#include <asm/devtree.h>
+
+#define UBICOM32_FLASH_BASE	0x60000000
+#define UBICOM32_FLASH_MAX_SIZE 0x01000000
+#define UBICOM32_FLASH_START	0x00000000
+#define UBICOM32_KERNEL_OFFSET	0x00010000 /* The kernel starts after Ubicom
+					    * .protect section. */
+
+static struct mtd_partition ubicom32_flash_partitions[] = {
+	{
+		.name	= "Bootloader",		/* Protected Section
+						 * Partition */
+		.size	= 0x10000,
+		.offset	= UBICOM32_FLASH_START,
+//		.mask_flags = MTD_WRITEABLE	/* Mark Read-only */
+	},
+	{
+		.name	= "Kernel",		/* Kernel Partition. */
+		.size	= 0,			/* this will be set up during
+						 * probe stage. At that time we
+						 * will know end of linux image
+						 * in flash. */
+		.offset	= MTDPART_OFS_APPEND,	/* Starts right after Protected
+						 * section. */
+//		.mask_flags = MTD_WRITEABLE	/* Mark Read-only */
+	},
+	{
+		.name	= "Rest",		/* Rest of the flash. */
+		.size	= 0x200000,		/* Use up what remains in the
+						 * flash. */
+		.offset	= MTDPART_OFS_NXTBLK,	/* Starts right after Protected
+						 * section. */
+	}
+};
+
+static struct flash_platform_data ubicom32_flash_data = {
+	.name = "ubicom32_boot_flash",
+	.parts = ubicom32_flash_partitions,
+	.nr_parts = ARRAY_SIZE(ubicom32_flash_partitions),
+};
+
+static struct resource ubicom32_flash_resource[] = {
+	{
+		.start	= UBICOM32_FLASH_BASE,
+		.end	= UBICOM32_FLASH_BASE +
+		UBICOM32_FLASH_MAX_SIZE - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct platform_device ubicom32_flash_device = {
+	.name = "ubicom32flashdriver",
+	.id = 0, /* Bus number */
+	.num_resources = ARRAY_SIZE(ubicom32_flash_resource),
+	.resource = ubicom32_flash_resource,
+	.dev = {
+		.platform_data = &ubicom32_flash_data,
+	},
+};
+
+static struct platform_device *ubicom32_flash_devices[] = {
+	&ubicom32_flash_device,
+};
+
+static int __init ubicom32_flash_init(void)
+{
+	printk(KERN_INFO "%s(): registering device resources\n",
+	       __FUNCTION__);
+	platform_add_devices(ubicom32_flash_devices,
+			     ARRAY_SIZE(ubicom32_flash_devices));
+	return 0;
+}
+
+arch_initcall(ubicom32_flash_init);
+
+/*
+ * MTD SPI driver for ST M25Pxx (and similar) serial flash chips through
+ * Ubicom32 SPI controller.
+ *
+ * Author: Mike Lavender, mike@steroidmicros.com
+ *
+ * Copyright (c) 2005, Intec Automation Inc.
+ *
+ * Some parts are based on lart.c by Abraham Van Der Merwe
+ *
+ * Cleaned up and generalized based on mtd_dataflash.c
+ *
+ * This code 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 FLASH_PAGESIZE		256
+
+/* Flash opcodes. */
+#define	OPCODE_WREN		0x06	/* Write enable */
+#define	OPCODE_RDSR		0x05	/* Read status register */
+#define	OPCODE_READ		0x03	/* Read data bytes (low frequency) */
+#define	OPCODE_FAST_READ	0x0b	/* Read data bytes (high frequency) */
+#define	OPCODE_PP		0x02	/* Page program (up to 256 bytes) */
+#define	OPCODE_BE_4K		0x20	/* Erase 4KiB block */
+#define	OPCODE_BE_32K		0x52	/* Erase 32KiB block */
+#define	OPCODE_SE		0xd8	/* Sector erase (usually 64KiB) */
+#define	OPCODE_RDID		0x9f	/* Read JEDEC ID */
+
+/* Status Register bits. */
+#define	SR_WIP			1	/* Write in progress */
+#define	SR_WEL			2	/* Write enable latch */
+/* meaning of other SR_* bits may differ between vendors */
+#define	SR_BP0			4	/* Block protect 0 */
+#define	SR_BP1			8	/* Block protect 1 */
+#define	SR_BP2			0x10	/* Block protect 2 */
+#define	SR_SRWD			0x80	/* SR write protect */
+
+/* Define max times to check status register before we give up. */
+#define	MAX_READY_WAIT_COUNT	100000
+
+
+#ifdef CONFIG_MTD_PARTITIONS
+#define	mtd_has_partitions()	(1)
+#else
+#define	mtd_has_partitions()	(0)
+#endif
+
+/*
+ * Ubicom32 FLASH Command Set
+ */
+#define FLASH_FC_INST_CMD	0x00	/* for SPI command only transaction */
+#define FLASH_FC_INST_WR	0x01	/* for SPI write transaction */
+#define FLASH_FC_INST_RD	0x02	/* for SPI read transaction */
+
+#define ALIGN_DOWN(v, a) ((v) & ~((a) - 1))
+#define ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
+
+#define	FLASH_COMMAND_KICK_OFF(io)							\
+	asm volatile(									\
+	"	bset	"D(IO_INT_CLR)"(%0), #0, #%%bit("D(IO_XFL_INT_DONE)")	\n\t"	\
+	"	jmpt.t	.+4							\n\t"	\
+	"	bset	"D(IO_INT_SET)"(%0), #0, #%%bit("D(IO_XFL_INT_START)")	\n\t"	\
+		:									\
+		: "a" (io)								\
+		: "memory", "cc"							\
+	);
+
+#define	FLASH_COMMAND_WAIT_FOR_COMPLETION(io)						\
+	asm volatile(									\
+	"	btst	"D(IO_INT_STATUS)"(%0), #%%bit("D(IO_XFL_INT_DONE)")	\n\t"	\
+	"	jmpeq.f	.-4							\n\t"	\
+		:									\
+		: "a" (io)								\
+		: "memory", "cc"									\
+	);
+
+#define	FLASH_COMMAND_EXEC(io)								\
+	FLASH_COMMAND_KICK_OFF(io)							\
+	FLASH_COMMAND_WAIT_FOR_COMPLETION(io)
+
+
+#define OSC1_FREQ 12000000
+#define TEN_MICRO_SECONDS (OSC1_FREQ * 10 / 1000000)
+
+/*
+ * We will have to eventually replace this null definition with the real thing.
+ */
+#define WATCHDOG_RESET()
+
+#define EXTFLASH_WRITE_FIFO_SIZE 32
+#define EXTFLASH_WRITE_BLOCK_SIZE EXTFLASH_WRITE_FIFO_SIZE /* limit the size to
+							    * FIFO capacity, so
+							    * the thread can be
+							    * suspended. */
+
+#define JFFS2_FILESYSTEM_SIZE 0x100000
+
+/****************************************************************************/
+
+struct m25p {
+	struct platform_device	*plt_dev;
+	struct mutex		lock;
+	struct mtd_info		mtd;
+	unsigned		partitioned:1;
+	u8			erase_opcode;
+	u8			command[4];
+};
+
+static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
+{
+	return container_of(mtd, struct m25p, mtd);
+}
+
+/****************************************************************************/
+
+/*
+ * Internal helper functions
+ */
+
+/*
+ * Read the status register, returning its value in the location
+ * Return the status register value.
+ * Returns negative if error occurred.
+ */
+static int read_sr(struct m25p *flash)
+{
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+
+	io->ctl1 &= ~IO_XFL_CTL1_MASK;
+	io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_RD) |
+		IO_XFL_CTL1_FC_DATA(1);
+	io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_RDSR);
+	FLASH_COMMAND_EXEC(io);
+
+	return io->status1 & 0xff;
+}
+
+/*
+ * mem_flash_io_read_u32()
+ */
+static u32 mem_flash_io_read_u32(u32 addr)
+{
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+	io->ctl1 &= ~IO_XFL_CTL1_MASK;
+	io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_RD) |
+		IO_XFL_CTL1_FC_DATA(4) | IO_XFL_CTL1_FC_DUMMY(1) |
+		IO_XFL_CTL1_FC_ADDR;
+	io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_FAST_READ) |
+		IO_XFL_CTL2_FC_ADDR(addr);
+	FLASH_COMMAND_EXEC(io);
+	return io->status1;
+}
+
+/*
+ * mem_flash_read_u8()
+ */
+static u8 mem_flash_read_u8(u32 addr)
+{
+	u32 tmp_addr = ALIGN_DOWN(addr, 4);
+	u32 tmp_data = mem_flash_io_read_u32(tmp_addr);
+	u8 *ptr = (u8 *)&tmp_data;
+	return ptr[addr & 0x3];
+}
+
+/*
+ * mem_flash_read()
+ *	No need to lock as read is implemented with ireads (same as normal flash
+ *	execution).
+ */
+static void mem_flash_read(u32 addr, void *dst, size_t length)
+{
+	/*
+	 * Range check
+	 */
+	/*
+	 * Fix source alignment.
+	 */
+	while (addr & 0x03) {
+		if (length == 0) {
+			return;
+		}
+		*((u8 *)dst) = mem_flash_read_u8(addr++);
+		dst++;
+		length--;
+	}
+
+	while (length >= 4) {
+		u32 tmp_data = mem_flash_io_read_u32(addr);
+		addr += 4;
+		length -= 4;
+
+		/*
+		 * Send the data to the destination.
+		 */
+		memcpy((void *)dst, (void *)&tmp_data, 4);
+		dst += 4;
+	}
+
+	while (length--) {
+		*((u8 *)dst) = mem_flash_read_u8(addr++);
+		dst++;
+	}
+}
+
+/*
+ * mem_flash_wait_until_complete()
+ */
+static void mem_flash_wait_until_complete(void)
+{
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+
+	do {
+		/*
+		 * Put a delay here to deal with flash programming problem.
+		 */
+		u32 mptval = UBICOM32_IO_TIMER->mptval + TEN_MICRO_SECONDS;
+		while (UBICOM32_IO_TIMER->mptval < mptval)
+			;
+
+		io->ctl1 &= ~IO_XFL_CTL1_MASK;
+		io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_RD) |
+			IO_XFL_CTL1_FC_DATA(1);
+		io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_RDSR);
+		FLASH_COMMAND_EXEC(io);
+	} while (io->status1 & SR_WIP);
+}
+
+/*
+ * mem_flash_write_next()
+ */
+static size_t mem_flash_write_next(u32 addr, u8 *buf, size_t length)
+{
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+	u32 data_start = addr;
+	u32 data_end = addr + length;
+	size_t count;
+	u32 i, j;
+
+	/*
+	 * Top limit address.
+	 */
+	u32 block_start = ALIGN_DOWN(data_start, 4);
+	u32 block_end = block_start + EXTFLASH_WRITE_BLOCK_SIZE;
+
+	union {
+		u8 byte[EXTFLASH_WRITE_BLOCK_SIZE];
+		u32 word[EXTFLASH_WRITE_BLOCK_SIZE / 4];
+	} write_buf;
+
+	u32 *flash_addr = (u32 *)block_start;
+
+	/*
+	 * The write block must be limited by FLASH internal buffer.
+	 */
+	u32 block_end_align = ALIGN_DOWN(block_end, 256);
+	bool write_needed;
+
+	block_end = (block_end_align > block_start)
+		? block_end_align : block_end;
+	data_end = (data_end <= block_end) ? data_end : block_end;
+	block_end = ALIGN_UP(data_end, 4);
+	count = data_end - data_start;
+
+	/*
+	 * Transfer data to a buffer.
+	 */
+	for (i = 0; i < (block_end - block_start) / 4; i++) {
+		/*
+		 * The FLASH read can hold D-cache for a long time.
+		 * Use I/O operation to read FLASH to avoid starving other
+		 * threads, especially HRT.  (Do this for application only)
+		 */
+		write_buf.word[i] = mem_flash_io_read_u32(
+			(u32)(&flash_addr[i]));
+	}
+
+	write_needed = false;
+	for (i = 0, j = (data_start - block_start);
+	     i < (data_end - data_start); i++, j++) {
+		write_needed = write_needed || (write_buf.byte[j] != buf[i]);
+		write_buf.byte[j] &= buf[i];
+	}
+
+
+	/*
+	 * If the data in FLASH is identical to what to be written. Then skip
+	 * it.
+	 */
+	if (write_needed) {
+		/*
+		 * Write to flash.
+		 */
+		void *tmp __attribute__((unused));
+		s32 extra_words;
+
+		asm volatile(
+		"	move.4	%0, %2									\n\t"
+		"	bset	"D(IO_INT_SET)"(%1), #0, #%%bit("D(IO_PORTX_INT_FIFO_TX_RESET)")	\n\t"
+		"	pipe_flush 0									\n\t"
+		"	.rept	"D(EXTFLASH_WRITE_FIFO_SIZE / 4)"					\n\t"
+		"	move.4	"D(IO_TX_FIFO)"(%1), (%0)4++						\n\t"
+		"	.endr										\n\t"
+			: "=&a" (tmp)
+			: "a" (io), "r" (&write_buf.word[0])
+			: "memory", "cc"
+		);
+
+		/* Lock FLASH for write access. */
+		io->ctl0 |= IO_XFL_CTL0_MCB_LOCK;
+
+		/* Command: WREN */
+		io->ctl1 &= ~IO_XFL_CTL1_MASK;
+		io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_CMD);
+		io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_WREN);
+		FLASH_COMMAND_EXEC(io);
+
+		/* Command: BYTE PROGRAM */
+		io->ctl1 &= ~IO_XFL_CTL1_MASK;
+		io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_WR) |
+			IO_XFL_CTL1_FC_DATA(block_end - block_start) |
+			IO_XFL_CTL1_FC_ADDR;
+		io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_PP) |
+			IO_XFL_CTL2_FC_ADDR(block_start);
+		FLASH_COMMAND_KICK_OFF(io);
+
+		extra_words = (s32)(block_end - block_start -
+				    EXTFLASH_WRITE_FIFO_SIZE) / 4;
+		if (extra_words > 0) {
+			asm volatile(
+			"	move.4		%0, %3				\n\t"
+			"1:	cmpi		"D(IO_FIFO_LEVEL)"(%1), #4	\n\t"
+			"	jmpgt.s.t	1b				\n\t"
+			"	move.4		"D(IO_TX_FIFO)"(%1), (%0)4++	\n\t"
+			"	add.4		%2, #-1, %2			\n\t"
+			"	jmpgt.t		1b				\n\t"
+				: "=&a" (tmp)
+				: "a" (io), "d" (extra_words),
+				  "r" (&write_buf.word[EXTFLASH_WRITE_FIFO_SIZE / 4])
+				: "memory", "cc"
+			);
+		}
+		FLASH_COMMAND_WAIT_FOR_COMPLETION(io);
+
+		mem_flash_wait_until_complete();
+
+
+		/* Unlock FLASH for cache access. */
+		io->ctl0 &= ~IO_XFL_CTL0_MCB_LOCK;
+	}
+
+	/*
+	 * Complete.
+	 */
+	return count;
+}
+
+/*
+ * mem_flash_write()
+ */
+static void mem_flash_write(u32 addr, const void *src, size_t length)
+{
+	/*
+	 * Write data
+	 */
+	u8_t *ptr = (u8_t *)src;
+	while (length) {
+		size_t count = mem_flash_write_next(addr, ptr, length);
+		addr += count;
+		ptr += count;
+		length -= count;
+	}
+}
+
+/*
+ * Service routine to read status register until ready, or timeout occurs.
+ * Returns non-zero if error.
+ */
+static int wait_till_ready(struct m25p *flash)
+{
+	int count;
+	int sr;
+
+	/* one chip guarantees max 5 msec wait here after page writes,
+	 * but potentially three seconds (!) after page erase.
+	 */
+	for (count = 0; count < MAX_READY_WAIT_COUNT; count++) {
+		u32 mptval;
+		sr = read_sr(flash);
+		if (sr < 0)
+			break;
+		else if (!(sr & SR_WIP))
+			return 0;
+
+		/*
+		 * Put a 10us delay here to deal with flash programming problem.
+		 */
+		mptval = UBICOM32_IO_TIMER->mptval + TEN_MICRO_SECONDS;
+		while ((s32)(mptval - UBICOM32_IO_TIMER->mptval) > 0) {
+			WATCHDOG_RESET();
+		}
+		/* REVISIT sometimes sleeping would be best */
+	}
+
+	return 1;
+}
+
+/*
+ * mem_flash_erase_page()
+ */
+static void mem_flash_erase_page(u32 addr)
+{
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+
+	/* Lock FLASH for write access. */
+	io->ctl0 |= IO_XFL_CTL0_MCB_LOCK;
+
+	/* Command: WREN */
+	io->ctl1 &= ~IO_XFL_CTL1_MASK;
+	io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_CMD);
+	io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_WREN);
+	FLASH_COMMAND_EXEC(io);
+
+	/* Command: ERASE */
+	io->ctl1 &= ~IO_XFL_CTL1_MASK;
+	io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_CMD) |
+		IO_XFL_CTL1_FC_ADDR;
+	io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_SE) |
+		IO_XFL_CTL2_FC_ADDR(addr);
+	FLASH_COMMAND_EXEC(io);
+
+	mem_flash_wait_until_complete();
+
+	/* Unlock FLASH for cache access. */
+	io->ctl0 &= ~IO_XFL_CTL0_MCB_LOCK;
+}
+
+/*
+ * mem_flash_erase()
+ */
+static u32 mem_flash_erase(u32 addr, u32 length)
+{
+	/*
+	 * Calculate the endaddress to be the first address of the page
+	 * just beyond this erase section of pages.
+	 */
+	u32 endaddr = addr + length;
+
+	/*
+	 * Erase.
+	 */
+	while (addr < endaddr) {
+		u32 test_addr = addr;
+		mem_flash_erase_page(addr);
+
+		/*
+		 * Test how much was erased as actual flash page at this address
+		 * may be smaller than the expected page size.
+		 */
+		while (test_addr < endaddr) {
+			/*
+			 * The FLASH read can hold D-cache for a long time.  Use
+			 * I/O operation to read FLASH to avoid starving other
+			 * threads, especially HRT.  (Do this for application
+			 * only)
+			 */
+			if (mem_flash_io_read_u32(test_addr) != 0xFFFFFFFF) {
+				break;
+			}
+			test_addr += 4;
+		}
+		if (test_addr == addr) {
+			printk("erase failed at address 0x%x, skipping",
+			       test_addr);
+			test_addr += 4;
+			return 1;
+		}
+		addr = test_addr;
+	}
+	return 0;
+}
+
+
+/****************************************************************************/
+
+/*
+ * MTD implementation
+ */
+
+/*
+ * Erase an address range on the flash chip.  The address range may extend
+ * one or more erase sectors.  Return an error is there is a problem erasing.
+ */
+static int ubicom32_flash_driver_erase(struct mtd_info *mtd,
+				       struct erase_info *instr)
+{
+	struct m25p *flash = mtd_to_m25p(mtd);
+	u32 addr, len;
+
+	DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
+			flash->plt_dev->dev.bus_id, __FUNCTION__, "at",
+			(u32)instr->addr, instr->len);
+
+	/* sanity checks */
+	if (instr->addr + instr->len > flash->mtd.size)
+		return -EINVAL;
+	if ((instr->addr % mtd->erasesize) != 0
+			|| (instr->len % mtd->erasesize) != 0) {
+		return -EINVAL;
+	}
+
+	addr = instr->addr + UBICOM32_FLASH_BASE;
+	len = instr->len;
+
+	mutex_lock(&flash->lock);
+
+	/* REVISIT in some cases we could speed up erasing large regions
+	 * by using OPCODE_SE instead of OPCODE_BE_4K
+	 */
+
+	/* now erase those sectors */
+	if (mem_flash_erase(addr, len)) {
+		instr->state = MTD_ERASE_FAILED;
+		mutex_unlock(&flash->lock);
+		return -EIO;
+	}
+
+	mutex_unlock(&flash->lock);
+	instr->state = MTD_ERASE_DONE;
+	mtd_erase_callback(instr);
+	return 0;
+}
+
+/*
+ * Read an address range from the flash chip.  The address range
+ * may be any size provided it is within the physical boundaries.
+ */
+static int ubicom32_flash_driver_read(struct mtd_info *mtd, loff_t from,
+				      size_t len, size_t *retlen, u_char *buf)
+{
+	struct m25p *flash = mtd_to_m25p(mtd);
+	u32 base_addr = UBICOM32_FLASH_BASE + from;
+
+	DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
+			flash->plt_dev->dev.bus_id, __FUNCTION__, "from",
+	      (u32)from, len);
+
+	/* sanity checks */
+	if (!len)
+		return 0;
+
+	if (from + len > flash->mtd.size)
+		return -EINVAL;
+
+	/* Byte count starts at zero. */
+	if (retlen)
+		*retlen = 0;
+
+	mutex_lock(&flash->lock);
+
+	/* Wait till previous write/erase is done. */
+	if (wait_till_ready(flash)) {
+		/* REVISIT status return?? */
+		mutex_unlock(&flash->lock);
+		return 1;
+	}
+
+	mem_flash_read(base_addr, (void *)buf, len);
+
+	if (retlen)
+		*retlen = len;
+
+	mutex_unlock(&flash->lock);
+
+	return 0;
+}
+
+/*
+ * Write an address range to the flash chip.  Data must be written in
+ * FLASH_PAGESIZE chunks.  The address range may be any size provided
+ * it is within the physical boundaries.
+ */
+static int ubicom32_flash_driver_write(struct mtd_info *mtd, loff_t to,
+				       size_t len, size_t *retlen,
+				       const u_char *buf)
+{
+	struct m25p *flash = mtd_to_m25p(mtd);
+	u32 base_addr = UBICOM32_FLASH_BASE + to;
+	DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
+			flash->plt_dev->dev.bus_id, __FUNCTION__, "to",
+			(u32)to, len);
+
+	if (retlen)
+		*retlen = 0;
+
+	/* sanity checks */
+	if (!len)
+		return 0;
+
+	if (to + len > flash->mtd.size)
+		return -EINVAL;
+
+	mutex_lock(&flash->lock);
+
+	mem_flash_write(base_addr, (void *) buf, len);
+
+	/* Wait until finished previous write command. */
+	if (wait_till_ready(flash)) {
+		mutex_unlock(&flash->lock);
+		return 1;
+	}
+
+	if (retlen)
+		*retlen = len;
+
+	mutex_unlock(&flash->lock);
+	return 0;
+}
+
+
+/****************************************************************************/
+
+/*
+ * SPI device driver setup and teardown
+ */
+
+struct flash_info {
+	char		*name;
+
+	/* JEDEC id zero means "no ID" (most older chips); otherwise it has
+	 * a high byte of zero plus three data bytes: the manufacturer id,
+	 * then a two byte device id.
+	 */
+	u32		jedec_id;
+
+	/* The size listed here is what works with OPCODE_SE, which isn't
+	 * necessarily called a "sector" by the vendor.
+	 */
+	unsigned	sector_size;
+	u16		n_sectors;
+
+	u16		flags;
+#define	SECT_4K		0x01		/* OPCODE_BE_4K works uniformly */
+};
+
+
+/* NOTE: double check command sets and memory organization when you add
+ * more flash chips.  This current list focusses on newer chips, which
+ * have been converging on command sets which including JEDEC ID.
+ */
+static struct flash_info __devinitdata m25p_data[] = {
+
+	/* Atmel -- some are (confusingly) marketed as "DataFlash" */
+	{ "at25fs010",  0x1f6601, 32 * 1024, 4, SECT_4K, },
+	{ "at25fs040",  0x1f6604, 64 * 1024, 8, SECT_4K, },
+
+	{ "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, },
+
+	{ "at26f004",   0x1f0400, 64 * 1024, 8, SECT_4K, },
+	{ "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, },
+	{ "at26df161a", 0x1f4601, 64 * 1024, 32, SECT_4K, },
+	{ "at26df321",  0x1f4701, 64 * 1024, 64, SECT_4K, },
+
+	/* Spansion -- single (large) sector size only, at least
+	 * for the chips listed here (without boot sectors).
+	 */
+	{ "s25sl004a", 0x010212, 64 * 1024, 8, },
+	{ "s25sl008a", 0x010213, 64 * 1024, 16, },
+	{ "s25sl016a", 0x010214, 64 * 1024, 32, },
+	{ "s25sl032a", 0x010215, 64 * 1024, 64, },
+	{ "s25sl064a", 0x010216, 64 * 1024, 128, },
+
+	/* SST -- large erase sizes are "overlays", "sectors" are 4K */
+	{ "sst25vf040b", 0xbf258d, 64 * 1024, 8, SECT_4K, },
+	{ "sst25vf080b", 0xbf258e, 64 * 1024, 16, SECT_4K, },
+	{ "sst25vf016b", 0xbf2541, 64 * 1024, 32, SECT_4K, },
+	{ "sst25vf032b", 0xbf254a, 64 * 1024, 64, SECT_4K, },
+
+	/* ST Microelectronics -- newer production may have feature updates */
+	{ "m25p05",  0x202010,  32 * 1024, 2, },
+	{ "m25p10",  0x202011,  32 * 1024, 4, },
+	{ "m25p20",  0x202012,  64 * 1024, 4, },
+	{ "m25p40",  0x202013,  64 * 1024, 8, },
+	{ "m25p80",         0,  64 * 1024, 16, },
+	{ "m25p16",  0x202015,  64 * 1024, 32, },
+	{ "m25p32",  0x202016,  64 * 1024, 64, },
+	{ "m25p64",  0x202017,  64 * 1024, 128, },
+	{ "m25p128", 0x202018, 256 * 1024, 64, },
+
+	{ "m45pe80", 0x204014,  64 * 1024, 16, },
+	{ "m45pe16", 0x204015,  64 * 1024, 32, },
+
+	{ "m25pe80", 0x208014,  64 * 1024, 16, },
+	{ "m25pe16", 0x208015,  64 * 1024, 32, SECT_4K, },
+
+	/* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
+	{ "w25x10", 0xef3011, 64 * 1024, 2, SECT_4K, },
+	{ "w25x20", 0xef3012, 64 * 1024, 4, SECT_4K, },
+	{ "w25x40", 0xef3013, 64 * 1024, 8, SECT_4K, },
+	{ "w25x80", 0xef3014, 64 * 1024, 16, SECT_4K, },
+	{ "w25x16", 0xef3015, 64 * 1024, 32, SECT_4K, },
+	{ "w25x32", 0xef3016, 64 * 1024, 64, SECT_4K, },
+	{ "w25x64", 0xef3017, 64 * 1024, 128, SECT_4K, },
+
+	/* Macronix -- mx25lxxx */ 
+	{ "mx25l32",  0xc22016, 64 * 1024,  64, }, 
+	{ "mx25l64",  0xc22017, 64 * 1024, 128, }, 
+	{ "mx25l128", 0xc22018, 64 * 1024, 256, },
+
+};
+
+struct flash_info *__devinit jedec_probe(struct platform_device *spi)
+{
+	int			tmp;
+	u32			jedec;
+	struct flash_info	*info;
+	struct ubicom32_io_port *io = (struct ubicom32_io_port *)RA;
+
+	/*
+	 * Setup and run RDID command on the flash.
+	 */
+	io->ctl1 &= ~IO_XFL_CTL1_MASK;
+	io->ctl1 |= IO_XFL_CTL1_FC_INST(FLASH_FC_INST_RD) |
+		IO_XFL_CTL1_FC_DATA(3);
+	io->ctl2 = IO_XFL_CTL2_FC_CMD(OPCODE_RDID);
+	FLASH_COMMAND_EXEC(io);
+
+	jedec = io->status1 & 0x00ffffff;
+
+	for (tmp = 0, info = m25p_data;
+			tmp < ARRAY_SIZE(m25p_data);
+			tmp++, info++) {
+		if (info->jedec_id == jedec)
+			return info;
+	}
+	dev_err(&spi->dev, "unrecognized JEDEC id %06x\n", jedec);
+	return NULL;
+}
+
+
+/*
+ * board specific setup should have ensured the SPI clock used here
+ * matches what the READ command supports, at least until this driver
+ * understands FAST_READ (for clocks over 25 MHz).
+ */
+static int __devinit ubicom32_flash_probe(struct platform_device *spi)
+{
+	struct flash_platform_data	*data;
+	struct m25p			*flash;
+	struct flash_info		*info;
+	unsigned			i;
+
+	/* Platform data helps sort out which chip type we have, as
+	 * well as how this board partitions it.  If we don't have
+	 * a chip ID, try the JEDEC id commands; they'll work for most
+	 * newer chips, even if we don't recognize the particular chip.
+	 */
+	data = spi->dev.platform_data;
+	if (data && data->type) {
+		for (i = 0, info = m25p_data;
+				i < ARRAY_SIZE(m25p_data);
+				i++, info++) {
+			if (strcmp(data->type, info->name) == 0)
+				break;
+		}
+
+		/* unrecognized chip? */
+		if (i == ARRAY_SIZE(m25p_data)) {
+			DEBUG(MTD_DEBUG_LEVEL0, "%s: unrecognized id %s\n",
+					spi->dev.bus_id, data->type);
+			info = NULL;
+
+		/* recognized; is that chip really what's there? */
+		} else if (info->jedec_id) {
+			struct flash_info	*chip = jedec_probe(spi);
+
+			if (!chip || chip != info) {
+				dev_warn(&spi->dev, "found %s, expected %s\n",
+						chip ? chip->name : "UNKNOWN",
+						info->name);
+				info = NULL;
+			}
+		}
+	} else
+		info = jedec_probe(spi);
+
+	if (!info)
+		return -ENODEV;
+
+	flash = kzalloc(sizeof *flash, GFP_KERNEL);
+	if (!flash)
+		return -ENOMEM;
+
+	flash->plt_dev = spi;
+	mutex_init(&flash->lock);
+	dev_set_drvdata(&spi->dev, flash);
+
+	if (data && data->name)
+		flash->mtd.name = data->name;
+	else
+		flash->mtd.name = spi->dev.bus_id;
+
+	flash->mtd.type = MTD_NORFLASH;
+	flash->mtd.writesize = 1;
+	flash->mtd.flags = MTD_CAP_NORFLASH;
+	flash->mtd.size = info->sector_size * info->n_sectors;
+	flash->mtd.erase = ubicom32_flash_driver_erase;
+	flash->mtd.read = ubicom32_flash_driver_read;
+	flash->mtd.write = ubicom32_flash_driver_write;
+
+	/* prefer "small sector" erase if possible */
+	/*
+ 	 * The Ubicom erase code does not use the opcode for smaller sectors,
+	 * so disable that functionality and keep erasesize == sector_size
+	 * so that the test in ubicom32_flash_driver_erase works properly.
+	 *
+	 * This was: `if (info->flags & SECT_4K) {' instead of `if (0) {'
+	 */
+	if (0) {
+		flash->erase_opcode = OPCODE_BE_4K;
+		flash->mtd.erasesize = 4096;
+	} else {
+		flash->erase_opcode = OPCODE_SE;
+		flash->mtd.erasesize = info->sector_size;
+	}
+
+	dev_info(&spi->dev, "%s (%d Kbytes)\n", info->name,
+			flash->mtd.size / 1024);
+
+	DEBUG(MTD_DEBUG_LEVEL2,
+		"mtd .name = %s, .size = 0x%.8x (%uMiB) "
+			".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n",
+		flash->mtd.name,
+		flash->mtd.size, flash->mtd.size / (1024*1024),
+		flash->mtd.erasesize, flash->mtd.erasesize / 1024,
+		flash->mtd.numeraseregions);
+
+	if (flash->mtd.numeraseregions)
+		for (i = 0; i < flash->mtd.numeraseregions; i++)
+			DEBUG(MTD_DEBUG_LEVEL2,
+				"mtd.eraseregions[%d] = { .offset = 0x%.8x, "
+				".erasesize = 0x%.8x (%uKiB), "
+				".numblocks = %d }\n",
+				i, flash->mtd.eraseregions[i].offset,
+				flash->mtd.eraseregions[i].erasesize,
+				flash->mtd.eraseregions[i].erasesize / 1024,
+				flash->mtd.eraseregions[i].numblocks);
+
+
+	/* partitions should match sector boundaries; and it may be good to
+	 * use readonly partitions for writeprotected sectors (BP2..BP0).
+	 */
+	if (mtd_has_partitions()) {
+		struct mtd_partition	*parts = NULL;
+		int			nr_parts = 0;
+
+#ifdef CONFIG_MTD_CMDLINE_PARTS
+		static const char *part_probes[] = { "cmdlinepart", NULL, };
+
+		nr_parts = parse_mtd_partitions(&flash->mtd,
+				part_probes, &parts, 0);
+#endif
+
+		if (nr_parts <= 0 && data && data->parts) {
+			parts = data->parts;
+			nr_parts = data->nr_parts;
+			if (nr_parts >= 2) {
+				/*
+				 * Set last partition size to be 1M.
+				 */
+				parts[1].size = flash->mtd.size - 
+					parts[0].size - JFFS2_FILESYSTEM_SIZE;
+				parts[2].size = JFFS2_FILESYSTEM_SIZE;
+			}
+		}
+
+		if (nr_parts > 0) {
+			for (i = 0; i < nr_parts; i++) {
+				DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = "
+					"{.name = %s, .offset = 0x%.8x, "
+						".size = 0x%.8x (%uKiB) }\n",
+					i, parts[i].name,
+					parts[i].offset,
+					parts[i].size,
+					parts[i].size / 1024);
+			}
+			flash->partitioned = 1;
+			return add_mtd_partitions(&flash->mtd, parts, nr_parts);
+		}
+	} else if (data->nr_parts)
+		dev_warn(&spi->dev, "ignoring %d default partitions on %s\n",
+				data->nr_parts, data->name);
+
+	return add_mtd_device(&flash->mtd) == 1 ? -ENODEV : 0;
+}
+
+
+static int __devexit ubicom32_flash_remove(struct spi_device *spi)
+{
+	struct m25p	*flash = dev_get_drvdata(&spi->dev);
+	int		status;
+
+	/* Clean up MTD stuff. */
+	if (mtd_has_partitions() && flash->partitioned)
+		status = del_mtd_partitions(&flash->mtd);
+	else
+		status = del_mtd_device(&flash->mtd);
+	if (status == 0)
+		kfree(flash);
+	return 0;
+}
+
+static struct platform_driver ubicom32_flash_driver = {
+	.driver = {
+		.name	= "ubicom32flashdriver",
+		.bus	= &platform_bus_type,
+		.owner	= THIS_MODULE,
+	},
+	.probe	= ubicom32_flash_probe,
+	.remove	= NULL,
+};
+
+static int ubicom32_flash_driver_init(void)
+{
+	return platform_driver_register(&ubicom32_flash_driver);
+}
+
+
+static void ubicom32_flash_driver_exit(void)
+{
+	platform_driver_unregister(&ubicom32_flash_driver);
+}
+
+
+module_init(ubicom32_flash_driver_init);
+module_exit(ubicom32_flash_driver_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mike Lavender");
+MODULE_DESCRIPTION("Ubicom32 MTD SPI driver for ST M25Pxx flash chips");
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2463,6 +2463,25 @@ config JME
 	  To compile this driver as a module, choose M here. The module
 	  will be called jme.
 
+config UBICOM32_GMAC
+	tristate "Ubicom Gigabit Ethernet support (EXPERIMENTAL)"
+	depends on UBICOM32
+	help
+	  Gigabit Ethernet support for IP5K/IP7K
+
+config UBICOM32_NAPI
+	bool  "USE NAPI (EXPERIMENTAL)"
+	depends on UBICOM32_GMAC
+	help
+	  Use NAPI for Ubicom's Ethernet driver
+
+config UBICOM32_OCM_FOR_SKB
+        bool  "USE OCM for SKB (EXPERIMENTAL)"
+        depends on UBICOM32_GMAC
+	default n
+        help
+          Allocate skb from OCM for Ethernet Receive
+
 endif # NETDEV_1000
 
 #
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -262,4 +262,4 @@ obj-$(CONFIG_NETXEN_NIC) += netxen/
 obj-$(CONFIG_NIU) += niu.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_SFC) += sfc/
-
+obj-$(CONFIG_UBICOM32_GMAC) += ubi32-eth.o
--- /dev/null
+++ b/drivers/net/ubi32-eth.c
@@ -0,0 +1,699 @@
+/*
+ * drivers/net/ubi32-eth.c
+ *   Ubicom32 ethernet TIO interface driver.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+/*
+ * ubi32_eth.c
+ * Ethernet driver for Ip5k/Ip7K
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+
+#include <linux/in.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/skbuff.h>
+#include <asm/checksum.h>
+#include "ubi32-eth.h"
+#include <asm/ip5000.h>
+#include <asm/devtree.h>
+#include <asm/system.h>
+
+/* #define USE_POLLING */
+
+/*
+ * TODO:
+ * mac address from flash
+ * multicast filter
+ * ethtool support
+ * sysfs support
+ * skb->nrfrag support
+ * ioctl
+ * monitor phy status
+ */
+
+static const char *eth_if_name[UBI32_ETH_NUM_OF_DEVICES] =
+	{"eth_lan", "eth_wan", "eth_ultra"};
+static struct net_device *ubi32_eth_devices[UBI32_ETH_NUM_OF_DEVICES] =
+	{NULL, NULL, NULL};
+static u8_t mac_addr[UBI32_ETH_NUM_OF_DEVICES][ETH_ALEN] = {
+	{0x00, 0x03, 0x64, 'l', 'a', 'n'},
+	{0x00, 0x03, 0x64, 'w', 'a', 'n'},
+	{0x00, 0x03, 0x64, 'u', 'l', 't'}};
+
+int ubi32_eth_ocm_alloc;
+int ubi32_eth_ddr_alloc;
+
+static inline struct sk_buff *ubi32_alloc_skb(struct net_device *dev, unsigned int length)
+{
+#if (defined(CONFIG_ZONE_DMA) && defined(CONFIG_UBICOM32_OCM_FOR_SKB))
+	struct sk_buff *sk_buff;
+
+	if (dev != ubi32_eth_devices[0])
+		return __dev_alloc_skb(length, GFP_ATOMIC);
+
+	sk_buff = __dev_alloc_skb(length, GFP_ATOMIC | __GFP_NOWARN | __GFP_NORETRY | GFP_DMA);
+	if (sk_buff) {
+		ubi32_eth_ocm_alloc++;
+		return sk_buff;
+	} else {
+		ubi32_eth_ddr_alloc++;
+		return __dev_alloc_skb(length, GFP_ATOMIC);
+	}
+#else
+	return __dev_alloc_skb(length, GFP_ATOMIC);
+#endif
+}
+
+static void ubi32_eth_vp_rxtx_enable(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	priv->regs->command = UBI32_ETH_VP_CMD_RX_ENABLE | UBI32_ETH_VP_CMD_TX_ENABLE;
+	priv->regs->int_mask = (UBI32_ETH_VP_INT_RX | UBI32_ETH_VP_INT_TX);
+	ubicom32_set_interrupt(priv->vp_int_bit);
+}
+
+static void ubi32_eth_vp_rxtx_stop(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	priv->regs->command = 0;
+	priv->regs->int_mask = 0;
+	ubicom32_set_interrupt(priv->vp_int_bit);
+
+	/* Wait for graceful shutdown */
+	while (priv->regs->status & (UBI32_ETH_VP_STATUS_RX_STATE | UBI32_ETH_VP_STATUS_TX_STATE));
+}
+
+/*
+ * ubi32_eth_tx_done()
+ */
+static int ubi32_eth_tx_done(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv;
+	struct sk_buff *skb;
+	volatile void *pdata;
+	struct ubi32_eth_dma_desc *desc;
+	u32_t 	count = 0;
+
+	priv = netdev_priv(dev);
+
+ 	priv->regs->int_status &= ~UBI32_ETH_VP_INT_TX;
+	while (priv->tx_tail != priv->regs->tx_out) {
+		pdata = priv->regs->tx_dma_ring[priv->tx_tail];
+		BUG_ON(pdata == NULL);
+
+		skb = container_of((void *)pdata, struct sk_buff, cb);
+		desc = (struct ubi32_eth_dma_desc *)pdata;
+		if (unlikely(!(desc->status & UBI32_ETH_VP_TX_OK))) {
+			atomic_inc((atomic_t *)&priv->stats.tx_errors);
+		} else {
+			priv->stats.tx_packets++;
+			priv->stats.tx_bytes += skb->len;
+		}
+		dev_kfree_skb_any(skb);
+		priv->regs->tx_dma_ring[priv->tx_tail] = NULL;
+		priv->tx_tail = (priv->tx_tail + 1) & TX_DMA_RING_MASK;
+		count++;
+	}
+
+	if (unlikely(priv->status & UBI32_ETH_PRIV_STATUS_TX_Q_FULL)) {
+		spin_lock(&priv->lock);
+		priv->status &= ~UBI32_ETH_PRIV_STATUS_TX_Q_FULL;
+		netif_wake_queue(dev);
+		spin_unlock(&priv->lock);
+	}
+	return count;
+}
+
+/*
+ * ubi32_eth_receive()
+ *	To avoid locking overhead, this is called only
+ *	by tasklet when not using NAPI, or
+ *	by NAPI poll when using NAPI.
+ *	return number of frames processed
+ */
+static int ubi32_eth_receive(struct net_device *dev, int quota)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	unsigned short rx_in = priv->regs->rx_in;
+	struct sk_buff *skb;
+	struct ubi32_eth_dma_desc *desc = NULL;
+	volatile void *pdata;
+
+	/* The number of NET_SKB_PAD bytes are already reserved by skb */
+	int extra_reserve = UBI32_ETH_RESERVE_SPACE - NET_SKB_PAD + UBI32_ETH_RESERVE_EXTRA;
+	int extra_alloc = extra_reserve + UBI32_ETH_TRASHED_MEMORY;
+	int i, replenish_cnt, count = 0;
+	int replenish_max = RX_DMA_MAX_QUEUE_SIZE;
+#if (defined(CONFIG_ZONE_DMA) && defined(CONFIG_UBICOM32_OCM_FOR_SKB))
+	if (dev == ubi32_eth_devices[0])
+		replenish_max = 21;
+#endif
+	BUG_ON((extra_reserve & 3) != NET_IP_ALIGN);	/* Must provide NET_IP_ALIGN (0 or 2) */
+
+	if (unlikely(rx_in == priv->regs->rx_out))
+		priv->vp_stats.rx_q_full_cnt++;
+
+	priv->regs->int_status &= ~UBI32_ETH_VP_INT_RX;
+	while (priv->rx_tail != priv->regs->rx_out) {
+		if (unlikely(count == quota)) {
+			/* There is still frame pending to be processed */
+			priv->vp_stats.rx_throttle++;
+			break;
+		}
+
+		pdata = priv->regs->rx_dma_ring[priv->rx_tail];
+		BUG_ON(pdata == NULL);
+
+		desc = (struct ubi32_eth_dma_desc *)pdata;
+		skb = container_of((void *)pdata, struct sk_buff, cb);
+		count++;
+		priv->regs->rx_dma_ring[priv->rx_tail] = NULL;
+		priv->rx_tail = ((priv->rx_tail + 1) & RX_DMA_RING_MASK);
+
+		/*
+		 * Check only RX_OK bit here.
+		 * The rest of status word is used as timestamp
+		 */
+		if (unlikely(!(desc->status & UBI32_ETH_VP_RX_OK))) {
+			priv->stats.rx_errors++;
+			dev_kfree_skb_any(skb);
+			continue;
+		}
+
+		skb_put(skb, desc->data_len);
+		skb->dev = dev;
+		skb->protocol = eth_type_trans(skb, dev);
+		skb->ip_summed = CHECKSUM_NONE;
+		priv->stats.rx_bytes += skb->len;
+		priv->stats.rx_packets++;
+#ifndef CONFIG_UBICOM32_NAPI
+		netif_rx(skb);
+#else
+		netif_receive_skb(skb);
+#endif
+	}
+
+	/* fill in more descripor for VP*/
+	replenish_cnt =  replenish_max -
+		((RX_DMA_RING_SIZE + rx_in - priv->rx_tail) & RX_DMA_RING_MASK);
+	if (replenish_cnt > 0) {
+		for (i = 0; i < replenish_cnt; i++) {
+			skb = ubi32_alloc_skb(dev, RX_BUF_SIZE + extra_alloc);
+			if (!skb) {
+				priv->vp_stats.rx_alloc_err++;
+				break;
+			}
+			/* set up dma descriptor */
+			desc = (struct ubi32_eth_dma_desc *)skb->cb;
+			skb_reserve(skb, extra_reserve);
+			BUG_ON((((u32)skb->data + ETH_HLEN) & (CACHE_LINE_SIZE - 1)) != 0);
+			desc->data_pointer = skb->data;
+			desc->buffer_len = RX_BUF_SIZE + UBI32_ETH_TRASHED_MEMORY;
+			desc->data_len = 0;
+			desc->status = 0;
+			priv->regs->rx_dma_ring[rx_in] = desc;
+			rx_in = (rx_in + 1) & RX_DMA_RING_MASK;
+		}
+		wmb();
+		priv->regs->rx_in = rx_in;
+		ubicom32_set_interrupt(priv->vp_int_bit);
+	}
+
+	if (likely(count > 0)) {
+		dev->last_rx = jiffies;
+	}
+	return count;
+}
+
+#ifdef CONFIG_UBICOM32_NAPI
+static int ubi32_eth_napi_poll(struct napi_struct *napi, int budget)
+{
+	struct ubi32_eth_private *priv = container_of(napi, struct ubi32_eth_private, napi);
+	struct net_device *dev = priv->dev;
+	u32_t count;
+
+	if (priv->tx_tail != priv->regs->tx_out) {
+                ubi32_eth_tx_done(dev);
+        }
+
+	count = ubi32_eth_receive(dev, budget);
+
+	priv->regs->int_mask |= (UBI32_ETH_VP_INT_RX | UBI32_ETH_VP_INT_TX);
+	if (count < budget) {
+		netif_rx_complete(dev, napi);
+		if ((priv->rx_tail != priv->regs->rx_out) || (priv->tx_tail != priv->regs->tx_out)) {
+			if (netif_rx_reschedule(dev, napi)) {
+				priv->regs->int_mask = 0;
+			}
+		}
+	}
+	return count;
+}
+
+#else
+static void ubi32_eth_do_tasklet(unsigned long arg)
+{
+	struct net_device *dev = (struct net_device *)arg;
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+
+	if (priv->tx_tail != priv->regs->tx_out) {
+		ubi32_eth_tx_done(dev);
+	}
+
+	/* always call receive to process new RX frame as well as replenish RX buffers */
+	ubi32_eth_receive(dev, RX_BOUND);
+
+	priv->regs->int_mask |= (UBI32_ETH_VP_INT_RX | UBI32_ETH_VP_INT_TX);
+	if ((priv->rx_tail != priv->regs->rx_out) || (priv->tx_tail != priv->regs->tx_out)) {
+		priv->regs->int_mask = 0;
+		tasklet_schedule(&priv->tsk);
+	}
+}
+#endif
+
+#if defined(USE_POLLING)
+static struct timer_list eth_poll_timer;
+
+static void ubi32_eth_poll(unsigned long arg)
+{
+	struct net_device *dev;
+	struct ubi32_eth_private *priv;
+	int i;
+
+	for (i = 0; i < UBI32_ETH_NUM_OF_DEVICES; i++) {
+		dev = ubi32_eth_devices[i];
+		if (dev && (dev->flags & IFF_UP)) {
+			priv = netdev_priv(dev);
+#ifdef CONFIG_UBICOM32_NAPI
+			netif_rx_schedule(dev, &priv->napi);
+#else
+			tasklet_schedule(&priv->tsk);
+#endif
+		}
+	}
+
+	eth_poll_timer.expires = jiffies + 2;
+	add_timer(&eth_poll_timer);
+}
+
+#else
+static irqreturn_t ubi32_eth_interrupt(int irq, void *dev_id)
+{
+	struct ubi32_eth_private *priv;
+
+	struct net_device *dev = (struct net_device *)dev_id;
+	BUG_ON(irq != dev->irq);
+
+	priv = netdev_priv(dev);
+	if (unlikely(!(priv->regs->int_status & priv->regs->int_mask))) {
+		return IRQ_NONE;
+	}
+
+	/*
+	 * Disable port interrupt
+	 */
+#ifdef CONFIG_UBICOM32_NAPI
+	if (netif_rx_schedule_prep(dev, &priv->napi)) {
+		priv->regs->int_mask = 0;
+		__netif_rx_schedule(dev, &priv->napi);
+	}
+#else
+	priv->regs->int_mask = 0;
+	tasklet_schedule(&priv->tsk);
+#endif
+	return IRQ_HANDLED;
+}
+#endif
+
+/*
+ * ubi32_eth_open
+ */
+static int ubi32_eth_open(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	int err;
+
+	printk(KERN_INFO "eth open %s\n",dev->name);
+#ifndef USE_POLLING
+	/* request_region() */
+	err = request_irq(dev->irq, ubi32_eth_interrupt, IRQF_DISABLED, dev->name, dev);
+	if (err) {
+		printk(KERN_WARNING "fail to request_irq %d\n",err);
+		 return -ENODEV;
+	}
+#endif
+#ifdef  CONFIG_UBICOM32_NAPI
+	napi_enable(&priv->napi);
+#else
+	tasklet_init(&priv->tsk, ubi32_eth_do_tasklet, (unsigned long)dev);
+#endif
+
+	/* call receive to supply RX buffers */
+	ubi32_eth_receive(dev, RX_DMA_MAX_QUEUE_SIZE);
+
+	/* check phy status and call netif_carrier_on */
+	ubi32_eth_vp_rxtx_enable(dev);
+	netif_start_queue(dev);
+	return 0;
+}
+
+static int ubi32_eth_close(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	volatile void *pdata;
+	struct sk_buff *skb;
+
+#ifndef USE_POLLING
+	free_irq(dev->irq, dev);
+#endif
+	netif_stop_queue(dev); /* can't transmit any more */
+#ifdef CONFIG_UBICOM32_NAPI
+	napi_disable(&priv->napi);
+#else
+	tasklet_kill(&priv->tsk);
+#endif
+	ubi32_eth_vp_rxtx_stop(dev);
+
+	/*
+	 * RX clean up
+	 */
+	while (priv->rx_tail != priv->regs->rx_in) {
+		pdata = priv->regs->rx_dma_ring[priv->rx_tail];
+		skb = container_of((void *)pdata, struct sk_buff, cb);
+		priv->regs->rx_dma_ring[priv->rx_tail] = NULL;
+		dev_kfree_skb_any(skb);
+		priv->rx_tail = ((priv->rx_tail + 1) & RX_DMA_RING_MASK);
+	}
+	priv->regs->rx_in = 0;
+	priv->regs->rx_out = priv->regs->rx_in;
+	priv->rx_tail = priv->regs->rx_in;
+
+	/*
+	 * TX clean up
+	 */
+	BUG_ON(priv->regs->tx_out != priv->regs->tx_in);
+	ubi32_eth_tx_done(dev);
+	BUG_ON(priv->tx_tail != priv->regs->tx_in);
+	priv->regs->tx_in = 0;
+	priv->regs->tx_out = priv->regs->tx_in;
+	priv->tx_tail = priv->regs->tx_in;
+
+	return 0;
+}
+
+/*
+ * ubi32_eth_set_config
+ */
+static int ubi32_eth_set_config(struct net_device *dev, struct ifmap *map)
+{
+	/* if must to down to config it */
+	printk(KERN_INFO "set_config %x\n", dev->flags);
+	if (dev->flags & IFF_UP)
+		return -EBUSY;
+
+	/* I/O and IRQ can not be changed */
+	if (map->base_addr != dev->base_addr) {
+		printk(KERN_WARNING "%s: Can't change I/O address\n", dev->name);
+		return -EOPNOTSUPP;
+	}
+
+#ifndef USE_POLLING
+	if (map->irq != dev->irq) {
+		printk(KERN_WARNING "%s: Can't change IRQ\n", dev->name);
+		return -EOPNOTSUPP;
+	}
+#endif
+
+	/* ignore other fields */
+	return 0;
+}
+
+static int ubi32_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	struct ubi32_eth_dma_desc *desc = NULL;
+	unsigned short space, tx_in;
+
+	tx_in = priv->regs->tx_in;
+
+	dev->trans_start = jiffies; /* save the timestamp */
+	space = TX_DMA_RING_MASK - ((TX_DMA_RING_SIZE + tx_in - priv->tx_tail) & TX_DMA_RING_MASK);
+
+	if (unlikely(space == 0)) {
+		atomic_inc((atomic_t *)&priv->stats.tx_errors);
+		if (!(priv->status & UBI32_ETH_PRIV_STATUS_TX_Q_FULL)) {
+			spin_lock(&priv->lock);
+			priv->status |= UBI32_ETH_PRIV_STATUS_TX_Q_FULL;
+			priv->vp_stats.tx_q_full_cnt++;
+			netif_stop_queue(dev);
+			spin_unlock(&priv->lock);
+		}
+
+		/* give both HW and this driver an extra trigger */
+		priv->regs->int_mask |= UBI32_ETH_VP_INT_TX;
+#ifndef USE_POLLING
+		ubicom32_set_interrupt(dev->irq);
+#endif
+		ubicom32_set_interrupt(priv->vp_int_bit);
+
+		return NETDEV_TX_BUSY;
+	}
+
+	/*still have room */
+	desc = (struct ubi32_eth_dma_desc *)skb->cb;
+	desc->data_pointer = skb->data;
+	desc->data_len = skb->len;
+	priv->regs->tx_dma_ring[tx_in] = desc;
+	tx_in = ((tx_in + 1) & TX_DMA_RING_MASK);
+	wmb();
+	priv->regs->tx_in = tx_in;
+	/* kick the HRT */
+	ubicom32_set_interrupt(priv->vp_int_bit);
+
+	return 0;
+}
+
+/*
+ * Deal with a transmit timeout.
+ */
+static void ubi32_eth_tx_timeout (struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	atomic_inc((atomic_t *)&priv->stats.tx_errors);
+	priv->regs->int_mask |= UBI32_ETH_VP_INT_TX;
+#ifndef USE_POLLING
+	ubicom32_set_interrupt(dev->irq);
+#endif
+	ubicom32_set_interrupt(priv->vp_int_bit);
+}
+
+static int ubi32_eth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+	printk(KERN_INFO "ioctl %s, %d\n", dev->name, cmd);
+	return -EINVAL;
+}
+
+/*
+ * Return statistics to the caller
+ */
+static struct net_device_stats *ubi32_eth_get_stats(struct net_device *dev)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	return &priv->stats;
+}
+
+
+static int ubi32_eth_change_mtu(struct net_device *dev, int new_mtu)
+{
+	struct ubi32_eth_private *priv = netdev_priv(dev);
+	unsigned long flags;
+
+	if ((new_mtu < 68) || (new_mtu > 1500))
+		return -EINVAL;
+
+	spin_lock_irqsave(&priv->lock, flags);
+	dev->mtu = new_mtu;
+	spin_unlock_irqrestore(&priv->lock, flags);
+	printk(KERN_INFO "set mtu to %d", new_mtu);
+	return 0;
+}
+
+/*
+ * ubi32_eth_cleanup: unload the module
+ */
+void ubi32_eth_cleanup(void)
+{
+	struct ubi32_eth_private *priv;
+	struct net_device *dev;
+	int i;
+
+	for (i = 0; i < UBI32_ETH_NUM_OF_DEVICES; i++) {
+		dev = ubi32_eth_devices[i];
+		if (dev) {
+			priv = netdev_priv(dev);
+			kfree(priv->regs->tx_dma_ring);
+			unregister_netdev(dev);
+			free_netdev(dev);
+			ubi32_eth_devices[i] = NULL;
+		}
+	}
+}
+
+int ubi32_eth_init_module(void)
+{
+	struct ethtionode *eth_node;
+ 	struct net_device *dev;
+	struct ubi32_eth_private *priv;
+	int i, err;
+
+	/*
+	 * Device allocation.
+	 */
+	err = 0;
+	for (i = 0; i < UBI32_ETH_NUM_OF_DEVICES; i++) {
+		/*
+		 * See if the eth_vp is in the device tree.
+		 */
+		eth_node = (struct ethtionode *)devtree_find_node(eth_if_name[i]);
+		if (!eth_node) {
+			printk(KERN_INFO "%s does not exist\n", eth_if_name[i]);
+			continue;
+		}
+
+		eth_node->tx_dma_ring = (struct ubi32_eth_dma_desc **)kmalloc(
+				sizeof(struct ubi32_eth_dma_desc *) *
+				(TX_DMA_RING_SIZE + RX_DMA_RING_SIZE), GFP_ATOMIC | __GFP_NOWARN | __GFP_NORETRY | GFP_DMA);
+
+		if (eth_node->tx_dma_ring == NULL) {
+			eth_node->tx_dma_ring = (struct ubi32_eth_dma_desc **)kmalloc(
+				sizeof(struct ubi32_eth_dma_desc *) *
+				(TX_DMA_RING_SIZE + RX_DMA_RING_SIZE), GFP_KERNEL);
+			printk(KERN_INFO "Failed to allocate from OCM\n");
+		}
+
+		if (!eth_node->tx_dma_ring) {
+			err = -ENOMEM;
+			break;
+		}
+		eth_node->rx_dma_ring = eth_node->tx_dma_ring + TX_DMA_RING_SIZE;
+		eth_node->tx_sz = TX_DMA_RING_SIZE - 1;
+		eth_node->rx_sz = RX_DMA_RING_SIZE - 1;
+
+		dev = alloc_etherdev(sizeof(struct ubi32_eth_private));
+		if (!dev) {
+			kfree(eth_node->tx_dma_ring);
+			err = -ENOMEM;
+			break;
+		}
+		priv = netdev_priv(dev);
+		priv->dev = dev;
+
+		/*
+		 * FIX IT! get proper mac address
+		 */
+		memcpy(dev->dev_addr, mac_addr[i], ETH_ALEN);
+
+		priv->regs = eth_node;
+		priv->regs->command = 0;
+		priv->regs->int_mask = 0;
+		priv->regs->int_status = 0;
+		priv->regs->tx_out = 0;
+		priv->regs->rx_out = 0;
+		priv->regs->tx_in = 0;
+		priv->regs->rx_in = 0;
+		priv->rx_tail = 0;
+		priv->tx_tail = 0;
+
+		priv->vp_int_bit = eth_node->dn.sendirq;
+		dev->irq = eth_node->dn.recvirq;
+
+		spin_lock_init(&priv->lock);
+
+		dev->open		= ubi32_eth_open;
+		dev->stop		= ubi32_eth_close;
+		dev->hard_start_xmit	= ubi32_eth_start_xmit;
+		dev->tx_timeout		= ubi32_eth_tx_timeout;
+		dev->watchdog_timeo	= UBI32_ETH_VP_TX_TIMEOUT;
+
+		dev->set_config		= ubi32_eth_set_config;
+		dev->do_ioctl		= ubi32_eth_ioctl;
+		dev->get_stats		= ubi32_eth_get_stats;
+		dev->change_mtu		= ubi32_eth_change_mtu;
+#ifdef CONFIG_UBICOM32_NAPI
+		netif_napi_add(dev, &priv->napi, ubi32_eth_napi_poll, UBI32_ETH_NAPI_WEIGHT);
+#endif
+		err = register_netdev(dev);
+		if (err) {
+			printk(KERN_WARNING "Failed to register netdev %s\n", eth_if_name[i]);
+			//release_region();
+			free_netdev(dev);
+			kfree(eth_node->tx_dma_ring);
+			break;
+		}
+
+		ubi32_eth_devices[i] = dev;
+		printk(KERN_INFO "%s vp_base:0x%p, tio_int:%d irq:%d\n",
+			dev->name, priv->regs, eth_node->dn.sendirq, dev->irq);
+	}
+
+	if (err) {
+		ubi32_eth_cleanup();
+		return err;
+	}
+
+	if (!ubi32_eth_devices[0] && !ubi32_eth_devices[1] && !ubi32_eth_devices[2]) {
+		return -ENODEV;
+	}
+
+#if defined(USE_POLLING)
+	init_timer(&eth_poll_timer);
+	eth_poll_timer.function = ubi32_eth_poll;
+	eth_poll_timer.data = (unsigned long)0;
+	eth_poll_timer.expires = jiffies + 2;
+	add_timer(&eth_poll_timer);
+#endif
+
+	return 0;
+}
+
+module_init(ubi32_eth_init_module);
+module_exit(ubi32_eth_cleanup);
+
+MODULE_AUTHOR("Kan Yan, Greg Ren");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/drivers/net/ubi32-eth.h
@@ -0,0 +1,133 @@
+/*
+ * drivers/net/ubi32-eth.h
+ *   Ubicom32 ethernet TIO interface driver definitions.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#ifndef _UBI32_ETH_H
+#define _UBI32_ETH_H
+
+#include <asm/devtree.h>
+
+#define UBI32_ETH_NUM_OF_DEVICES 3
+
+/*
+ * Number of bytes trashed beyond the packet data.
+ */
+#define UBI32_ETH_TRASHED_MEMORY	(CACHE_LINE_SIZE + ETH_HLEN - 1)
+
+/*
+ * Linux already reserves NET_SKB_PAD bytes of headroom in each sk_buff.
+ * We want to be able to reserve arbitrarily more space to align Ethernet
+ * and IP header to cache line.
+ * Note that the TIO expects a CACHE_LINE_SIZE - ETH_HLEN aligned Ethernet
+ * header, so the reserved space must be NET_SKB_PAD + NET_IP_ALIGN.
+ * (NET_SKB_PAD is 16, NET_IP_ALIGN is 2, CACHE_LINE_SIZE is 32).
+ * You can add more space by making UBI32_ETH_iRESERVE_EXTRA != 0.
+ */
+#define UBI32_ETH_RESERVE_SPACE	(CACHE_LINE_SIZE - ETH_HLEN)
+#define UBI32_ETH_RESERVE_EXTRA (1 * CACHE_LINE_SIZE)
+
+struct ubi32_eth_dma_desc {
+	volatile void 	*data_pointer;	/* pointer to the buffer */
+	volatile u16 	buffer_len;	/* the buffer size */
+	volatile u16	data_len;	/* actual frame length */
+	volatile u32	status;		/* bit0: status to be update by VP; bit[31:1] time stamp */
+};
+
+#define TX_DMA_RING_SIZE (1<<8)
+#define TX_DMA_RING_MASK (TX_DMA_RING_SIZE - 1)
+#define RX_DMA_RING_SIZE (1<<8)
+#define RX_DMA_RING_MASK (RX_DMA_RING_SIZE - 1)
+
+#define RX_DMA_MAX_QUEUE_SIZE (RX_DMA_RING_SIZE - 1)	/* no more than (RX_DMA_RING_SIZE - 1) */
+#define RX_MAX_PKT_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN)
+#define RX_MIN_PKT_SIZE	ETH_ZLEN
+#define RX_BUF_SIZE (RX_MAX_PKT_SIZE + VLAN_HLEN)	/* allow double VLAN tag */
+
+#define UBI32_ETH_VP_TX_TIMEOUT (10*HZ)
+
+struct ubi32_eth_vp_stats {
+	u32	rx_alloc_err;
+	u32	tx_q_full_cnt;
+	u32	rx_q_full_cnt;
+	u32	rx_throttle;
+};
+
+struct ubi32_eth_private {
+	struct net_device *dev;
+	struct net_device_stats stats;
+	struct ubi32_eth_vp_stats vp_stats;
+	int status;
+	spinlock_t lock;
+#ifdef CONFIG_UBICOM32_NAPI
+	struct napi_struct napi;
+#else
+	struct tasklet_struct tsk;
+#endif
+	struct ethtionode *regs;
+	u16	rx_tail;
+	u16	tx_tail;
+	u32	vp_int_bit;
+};
+
+struct ethtionode {
+	struct devtree_node dn;
+	volatile u16	command;
+	volatile u16	status;
+	volatile u16	int_mask;	/* interrupt mask */
+	volatile u16	int_status;	/* interrupt mask */
+	volatile u16	tx_in;		/* owned by driver */
+	volatile u16	tx_out;		/* owned by vp */
+	volatile u16	rx_in;		/* owned by driver */
+	volatile u16	rx_out;		/* owned by vp */
+	u16		tx_sz;		/* owned by driver */
+	u16		rx_sz;		/* owned by driver */
+	struct ubi32_eth_dma_desc **tx_dma_ring;
+	struct ubi32_eth_dma_desc **rx_dma_ring;
+};
+
+#define UBI32_ETH_VP_STATUS_LINK	(1<<0)
+#define UBI32_ETH_VP_STATUS_SPEED	(0x2<<1)
+#define UBI32_ETH_VP_STATUS_DUPLEX	(0x1<<3)
+#define UBI32_ETH_VP_STATUS_FLOW_CTRL	(0x1<<4)
+
+#define UBI32_ETH_VP_STATUS_RX_STATE	(0x1<<5)
+#define UBI32_ETH_VP_STATUS_TX_STATE	(0x1<<6)
+
+#define UBI32_ETH_PRIV_STATUS_TX_Q_FULL	(1<<0)
+
+#define UBI32_ETH_VP_INT_RX	(1<<0)
+#define UBI32_ETH_VP_INT_TX	(1<<1)
+
+#define UBI32_ETH_VP_CMD_RX_ENABLE	(1<<0)
+#define UBI32_ETH_VP_CMD_TX_ENABLE	(1<<1)
+
+#define UBI32_ETH_VP_RX_OK		(1<<0)
+#define UBI32_ETH_VP_TX_OK		(1<<1)
+
+#define TX_BOUND		TX_DMA_RING_SIZE
+#define RX_BOUND		64
+#define UBI32_ETH_NAPI_WEIGHT	64		/* for GigE */
+#endif
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -318,14 +318,33 @@ static int asix_rx_fixup(struct usbnet *
 		/* get the packet length */
 		size = (u16) (header & 0x0000ffff);
 
-		if ((skb->len) - ((size + 1) & 0xfffe) == 0)
+		if ((skb->len) - ((size + 1) & 0xfffe) == 0) {
+#ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS
+			if (((u32)packet & 0x02) == 0) {
+				memmove(packet - 2, packet, size);
+				skb->data -= 2;
+				skb->tail -= 2;
+			}
+#endif
 			return 2;
+		}
+
 		if (size > ETH_FRAME_LEN) {
 			deverr(dev,"asix_rx_fixup() Bad RX Length %d", size);
 			return 0;
 		}
 		ax_skb = skb_clone(skb, GFP_ATOMIC);
 		if (ax_skb) {
+#ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS
+			if (((u32)packet & 0x02) == 0) {
+				memmove(packet - 2, packet, size);
+				ax_skb->data = packet - 2;
+			} else {
+				ax_skb->data = packet;
+			}
+#else
+			ax_skb->data = packet;
+#endif
 			ax_skb->len = size;
 			ax_skb->data = packet;
 			skb_set_tail_pointer(ax_skb, size);
@@ -1102,13 +1121,19 @@ static int ax88178_link_reset(struct usb
 	mode = AX88178_MEDIUM_DEFAULT;
 
 	if (ecmd.speed == SPEED_1000)
+#ifdef HAVE_EFFICIENT_UNALIGNED_ACCESS
 		mode |= AX_MEDIUM_GM;
+#else
+		mode |= AX_MEDIUM_GM | AX_MEDIUM_ENCK;
+#endif
 	else if (ecmd.speed == SPEED_100)
 		mode |= AX_MEDIUM_PS;
 	else
 		mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
 
+#ifdef HAVE_EFFICIENT_UNALIGNED_ACCESS
 	mode |= AX_MEDIUM_ENCK;
+#endif
 
 	if (ecmd.duplex == DUPLEX_FULL)
 		mode |= AX_MEDIUM_FD;
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -240,10 +240,11 @@ static void oprofile_end_trace(struct op
 	cpu_buf->tracing = 0;
 }
 
-void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
-				unsigned long event, int is_kernel)
+
+void oprofile_add_ext_sample_cpu(unsigned long pc, struct pt_regs * const regs,
+				unsigned long event, int is_kernel, int cpu)
 {
-	struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
+	struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
 
 	if (!backtrace_depth) {
 		log_sample(cpu_buf, pc, is_kernel, event);
@@ -260,6 +261,13 @@ void oprofile_add_ext_sample(unsigned lo
 	oprofile_end_trace(cpu_buf);
 }
 
+void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
+				unsigned long event, int is_kernel)
+{
+	oprofile_add_ext_sample_cpu(pc, regs, event,
+					is_kernel, smp_processor_id());
+}
+
 void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
 {
 	int is_kernel = !user_mode(regs);
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -42,8 +42,8 @@ obj-$(CONFIG_PPC) += setup-bus.o
 obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o
 obj-$(CONFIG_X86_VISWS) += setup-irq.o
 obj-$(CONFIG_MN10300) += setup-bus.o
+obj-$(CONFIG_UBICOM32) += setup-bus.o setup-irq.o
 
-#
 # ACPI Related PCI FW Functions
 #
 obj-$(CONFIG_ACPI)    += pci-acpi.o
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -827,6 +827,57 @@ config SERIAL_UARTLITE_CONSOLE
 	  console (the system console is the device which receives all kernel
 	  messages and warnings and which allows logins in single user mode).
 
+config SERIAL_UBI32_UARTTIO
+        tristate "Ubicom UARTTIO support"
+        depends on UBICOM32=y
+        select SERIAL_CORE
+	default y
+        help
+          Add support for the Ubicom virtual peripherial serial interface.
+
+config SERIAL_UBI32_UARTTIO_NR_UARTS
+	int "Maximum number of UARTTIO virtual serial ports"
+	depends on SERIAL_UBI32_UARTTIO
+	default "4"
+	help
+	  Set this to the maximum number of serial ports you want the driver to support.  
+
+config SERIAL_UBI32_UARTTIO_CONSOLE
+        tristate "Ubicom UARTTIO console support"
+        depends on SERIAL_UBI32_UARTTIO=y
+        select SERIAL_CORE_CONSOLE
+	default y
+        help
+          Add support for console on the Ubicom virtual peripherial serial interface.
+
+config SERIAL_UBI32_SERDES
+        bool "Ubicom serial port support"
+        depends on UBICOM32=y
+        select SERIAL_CORE
+	default y
+        help
+          Add support for the Ubicom serial interface.
+
+config SERIAL_UBI32_SERDES_CONSOLE
+        bool "Ubicom serial console support"
+        depends on SERIAL_UBI32_SERDES=y
+        select SERIAL_CORE_CONSOLE
+	default y
+
+config SERIAL_UBI32_MAILBOX
+        bool "Ubicom mailbox support"
+        depends on UBICOM32=y
+        select SERIAL_CORE
+	default n
+        help
+          Add support for the Ubicom mailbox interface.
+
+config SERIAL_UBI32_MAILBOX_CONSOLE
+        bool "Ubicom mailbox console support"
+        depends on SERIAL_UBI32_MAILBOX=y
+        select SERIAL_CORE_CONSOLE
+	default y
+
 config SERIAL_SUNCORE
 	bool
 	depends on SPARC
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -73,3 +73,6 @@ obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_s
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
+obj-$(CONFIG_SERIAL_UBI32_SERDES) += ubi32_serdes.o
+obj-$(CONFIG_SERIAL_UBI32_UARTTIO) += ubi32_uarttio.o
+obj-$(CONFIG_SERIAL_UBI32_MAILBOX) += ubi32_mailbox.o
--- /dev/null
+++ b/drivers/serial/ubi32_mailbox.c
@@ -0,0 +1,928 @@
+/*
+ * drivers/serial/ubi32_mailbox.c
+ *   Ubicom32 On-Chip Mailbox Driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/sysrq.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial_core.h>
+
+#include <asm/ip5000.h>
+
+#define SERIAL_UBICOM_BAUDRATE	115200
+#define SERIAL_UBICOM_DATA_BIT	8	/* Fixed parameter - do not change */
+#define SERIAL_UBICOM_PAR_BIT	0	/* Fixed parameter - do not change */
+#define SERIAL_UBICOM_STOP_BIT	1	/* Fixed parameter - do not change */
+
+/* UART name and device definitions */
+#define UBI32_MAILBOX_NAME	"ttyUM" // XXX
+#define UBI32_MAILBOX_MAJOR	207 // XXX
+#define UBI32_MAILBOX_MINOR	64
+
+#define PORT_UBI32_MAILBOX	1235
+#define NR_PORTS 1
+
+#define get_sclk() 0
+
+struct ubi32_mailbox_port {
+	struct uart_port port;
+	/*
+	 * NOTE (rkeller):
+	 * the uart port is wrapped in another structure in case we need to hold more state than 
+	 * what we can hold in the uart_port.
+	 * Not sure if we need this, I took over the concept from the blackfin driver.
+	 */
+} ubi32_mailbox_ports[NR_PORTS];
+
+struct ubi32_mailbox_resource {
+	int uart_base_addr;
+	int uart_irq;
+} ubi32_mailbox_resource[NR_PORTS] = {
+	/*
+	 * uart_base_addr has to be non-NULL because it is put in the uart_port membase.
+	 * If membase if null the kernel skips the configuration and our port_type never gets set.
+	 */
+	{ISD_MAILBOX_BASE, ISD_MAILBOX_INT}
+};
+
+static volatile struct ubicom32_isd_mailbox {
+	volatile u32_t in;
+	volatile u32_t out;
+	volatile u32_t status;
+} *ubi32_mailbox = (struct ubicom32_isd_mailbox *)ISD_MAILBOX_BASE;
+
+static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port *uart);
+
+static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port *uart);
+
+#define TRUE 1
+#define FALSE 0
+
+static int mailbox_console_flg = TRUE;
+static int num_timeouts = 0;
+
+/*
+ * dummy functions and defined to be able to compile the Blackfin code
+ */
+#define UART_GET_LSR(port) (1)
+#define UART_PUT_LSR(port, bits)
+#define UART_CLEAR_LSR(port) (1)
+#define TEMT 1
+#define TFI 1
+#define BI 1
+#define PE 1
+#define OE 1
+#define FE 1
+#define THRE 1
+#define DR 1
+#define UART_GET_LCR(port) (1)
+#define UART_PUT_LCR(port, bits)
+#define SB 1
+#define STB 1
+#define PEN 1
+#define EPS 1
+#define STP 1
+#define WLS(n) 0
+#define UART_GET_IER(port) (1)
+#define UART_SET_IER(port, bits)
+#define UART_CLEAR_IER(port, bits)
+#define ETBEI 0
+#define ERBFI 0
+#define UART_GET_CHAR(port) ubi32_mailbox_get_char()
+#define UART_PUT_CHAR(port, ch) ubi32_mailbox_put_char(ch)
+#define SSYNC()
+#define UART_GET_DLL(port) 0
+#define UART_PUT_DLL(port, ch)
+#define UART_GET_DLH(port) 0
+#define UART_PUT_DLH(port, ch)
+#define UART_GET_GCTL(port) (0)
+#define UART_PUT_GCTL(port, ch)
+#define UCEN 1
+
+/*
+ * ubi32_mailbox_get_char_avail()
+ */
+static int ubi32_mailbox_get_char_avail(void)
+{
+	return !(ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY);
+}
+
+/*
+ * ubi32_mailbox_get_char()
+ */
+static u32_t ubi32_mailbox_get_char(void)
+{
+	if (mailbox_console_flg == TRUE) {
+		/*
+		 * Mailbox console is connected.
+		 */
+		while (ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY);
+		return ubi32_mailbox->in & 0xff;
+	}
+
+	/*
+	 * Mailbox console was not connected.
+	 */
+	if (ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY) {
+		return 0xff;
+	}
+
+	/*
+	 * Mailbox console is connecting.
+	 */
+	mailbox_console_flg = TRUE;
+	num_timeouts = 0;
+	return ubi32_mailbox->in & 0xff;
+}
+
+#define MAILBOX_MAX_ATTEMPTS 1000000
+#define MAILBOX_MAX_TIMEOUTS 5
+/*
+ * ubi32_mailbox_put_char()
+ */
+static void ubi32_mailbox_put_char(u32_t v)
+{
+	/*
+	 * Wait to be able to output.
+	 */
+	u32_t num_attempts = 0;
+
+	if(mailbox_console_flg == TRUE) {
+		while(num_attempts++ < MAILBOX_MAX_ATTEMPTS) {
+			if(ubi32_mailbox->status & ISD_MAILBOX_STATUS_OUT_EMPTY) {
+				break;
+			}
+		}
+
+		/*
+		 * If timed out more than 5 times on send, mailbox console is disconnected now.
+		 */
+		if (num_attempts > MAILBOX_MAX_ATTEMPTS) {
+			if (num_timeouts++ > MAILBOX_MAX_TIMEOUTS) {
+				mailbox_console_flg = FALSE;
+			}
+		}
+	}
+	
+	asm volatile(
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+		"pipe_flush 0	\n\t"
+	);
+
+	ubi32_mailbox->out = v & 0xff;
+}
+
+static void ubi32_mailbox_hw_init(struct ubi32_mailbox_port *uart)
+{
+// NOTE: It does not do any good to do these here because we are running on the linux hardware thread,
+//	and these have to be called on the ldsr thread.
+//	ubicom32_clear_interrupt(ISD_MAILBOX_INT);
+//	ubicom32_enable_interrupt(ISD_MAILBOX_INT);
+}
+
+/*
+ * interrupts are disabled on entry
+ */
+static void ubi32_mailbox_stop_tx(struct uart_port *port)
+{
+//	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+//	struct circ_buf *xmit = &uart->port.info->xmit;
+
+	while (!(UART_GET_LSR(uart) & TEMT))
+		cpu_relax();
+
+	/* Clear TFI bit */
+	UART_PUT_LSR(uart, TFI);
+	UART_CLEAR_IER(uart, ETBEI);
+}
+
+/*
+ * port is locked and interrupts are disabled
+ */
+static void ubi32_mailbox_start_tx(struct uart_port *port)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+
+	UART_SET_IER(uart, ETBEI);
+
+	ubi32_mailbox_tx_chars(uart);
+}
+
+/*
+ * Interrupts are enabled
+ */
+static void ubi32_mailbox_stop_rx(struct uart_port *port)
+{
+//	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+	UART_CLEAR_IER(uart, ERBFI);
+}
+
+/*
+ * Set the modem control timer to fire immediately.
+ */
+static void ubi32_mailbox_enable_ms(struct uart_port *port)
+{
+}
+
+static void ubi32_mailbox_rx_chars(struct ubi32_mailbox_port *uart)
+{
+	struct uart_info *info = uart->port.info;
+	struct tty_struct *tty = info->port.tty;
+	unsigned int status, ch, flg;
+
+	status = 0; // XXX? UART_GET_LSR(uart);
+	UART_CLEAR_LSR(uart);
+
+ 	ch = UART_GET_CHAR(uart);
+
+	if(ch == 0xff)
+		return; 
+
+	uart->port.icount.rx++;
+
+	if (status & BI) {
+		uart->port.icount.brk++;
+		if (uart_handle_break(&uart->port))
+			goto ignore_char;
+		status &= ~(PE | FE);
+	}
+	if (status & PE)
+		uart->port.icount.parity++;
+	if (status & OE)
+		uart->port.icount.overrun++;
+	if (status & FE)
+		uart->port.icount.frame++;
+
+	status &= uart->port.read_status_mask;
+
+	if (status & BI)
+		flg = TTY_BREAK;
+	else if (status & PE)
+		flg = TTY_PARITY;
+	else if (status & FE)
+		flg = TTY_FRAME;
+	else
+		flg = TTY_NORMAL;
+
+	if (uart_handle_sysrq_char(&uart->port, ch))
+		goto ignore_char;
+
+	uart_insert_char(&uart->port, status, OE, ch, flg);
+
+ ignore_char:
+	tty_flip_buffer_push(tty);
+}
+
+static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port *uart)
+{
+	struct circ_buf *xmit = &uart->port.info->xmit;
+
+	if (uart->port.x_char) {
+		UART_PUT_CHAR(uart, uart->port.x_char);
+		uart->port.icount.tx++;
+		uart->port.x_char = 0;
+	}
+	/*
+	 * Check the modem control lines before
+	 * transmitting anything.
+	 */
+	ubi32_mailbox_mctrl_check(uart);
+
+	if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
+		ubi32_mailbox_stop_tx(&uart->port);
+		return;
+	}
+
+	while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) {
+		UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
+		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+		uart->port.icount.tx++;
+		SSYNC();
+	}
+
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+		uart_write_wakeup(&uart->port);
+
+	if (uart_circ_empty(xmit))
+		ubi32_mailbox_stop_tx(&uart->port);
+}
+
+static irqreturn_t ubi32_mailbox_isr(int irq, void *dev_id)
+{
+	struct ubi32_mailbox_port *uart = dev_id;
+
+	spin_lock(&uart->port.lock);
+
+	//XXX?while (UART_GET_LSR(uart) & DR)
+
+	/*
+	 * RX process
+	 */
+	while (ubi32_mailbox_get_char_avail()) {
+		ubi32_mailbox_rx_chars(uart);
+	}
+
+#if 0
+	/*
+	 * TX process
+	 */
+	if (this_uart.tx_in == this_uart.tx_out) {
+		UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_mask &= ~IO_PORTX_INT_SERDES_TXBE;
+	} else if (UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_status & IO_PORTX_INT_SERDES_TXBE) {
+		uart_ubicom32_send(this_uart.tx_buf[this_uart.tx_out & (SERIAL_UBICOM_BUF_SIZE - 1)]);
+		this_uart.tx_out++;
+		UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_mask |= IO_PORTX_INT_SERDES_TXBE;
+	}
+#endif
+
+	spin_unlock(&uart->port.lock);
+
+	return IRQ_HANDLED;
+}
+#if 0
+static irqreturn_t ubi32_mailbox_tx_int(int irq, void *dev_id)
+{
+	struct ubi32_mailbox_port *uart = dev_id;
+
+	spin_lock(&uart->port.lock);
+	if (UART_GET_LSR(uart) & THRE)
+		ubi32_mailbox_tx_chars(uart);
+	spin_unlock(&uart->port.lock);
+
+	return IRQ_HANDLED;
+}
+#endif
+
+/*
+ * Return TIOCSER_TEMT when transmitter is not busy.
+ */
+static unsigned int ubi32_mailbox_tx_empty(struct uart_port *port)
+{
+//	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+	unsigned short lsr;
+
+	lsr = UART_GET_LSR(uart);
+	if (lsr & TEMT)
+		return TIOCSER_TEMT;
+	else
+		return 0;
+}
+
+static unsigned int ubi32_mailbox_get_mctrl(struct uart_port *port)
+{
+		return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
+}
+
+static void ubi32_mailbox_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+}
+
+/*
+ * Handle any change of modem status signal since we were last called.
+ */
+static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port *uart)
+{
+}
+
+/*
+ * Interrupts are always disabled.
+ */
+static void ubi32_mailbox_break_ctl(struct uart_port *port, int break_state)
+{
+//	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+	u16 lcr = UART_GET_LCR(uart);
+	if (break_state)
+		lcr |= SB;
+	else
+		lcr &= ~SB;
+	UART_PUT_LCR(uart, lcr);
+	SSYNC();
+}
+
+static int ubi32_mailbox_startup(struct uart_port *port)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+
+	if (request_irq(uart->port.irq, ubi32_mailbox_isr, IRQF_DISABLED,
+	     "UBI32_MAILBOX", uart)) {
+		printk(KERN_NOTICE "Unable to attach Ubicom32 SERDES interrupt\n");
+		return -EBUSY;
+	}
+
+	UART_SET_IER(uart, ERBFI);
+	return 0;
+}
+
+static void ubi32_mailbox_shutdown(struct uart_port *port)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+
+	free_irq(uart->port.irq, uart);
+}
+
+static void
+ubi32_mailbox_set_termios(struct uart_port *port, struct ktermios *termios,
+		   struct ktermios *old)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+	unsigned long flags;
+	unsigned int baud, quot;
+	unsigned short val, ier, lsr, lcr = 0;
+
+	switch (termios->c_cflag & CSIZE) {
+	case CS8:
+		lcr = WLS(8);
+		break;
+	case CS7:
+		lcr = WLS(7);
+		break;
+	case CS6:
+		lcr = WLS(6);
+		break;
+	case CS5:
+		lcr = WLS(5);
+		break;
+	default:
+		printk(KERN_ERR "%s: word lengh not supported\n",
+			__FUNCTION__);
+	}
+
+	if (termios->c_cflag & CSTOPB)
+		lcr |= STB;
+	if (termios->c_cflag & PARENB)
+		lcr |= PEN;
+	if (!(termios->c_cflag & PARODD))
+		lcr |= EPS;
+	if (termios->c_cflag & CMSPAR)
+		lcr |= STP;
+
+	port->read_status_mask = OE;
+	if (termios->c_iflag & INPCK)
+		port->read_status_mask |= (FE | PE);
+	if (termios->c_iflag & (BRKINT | PARMRK))
+		port->read_status_mask |= BI;
+
+	/*
+	 * Characters to ignore
+	 */
+	port->ignore_status_mask = 0;
+	if (termios->c_iflag & IGNPAR)
+		port->ignore_status_mask |= FE | PE;
+	if (termios->c_iflag & IGNBRK) {
+		port->ignore_status_mask |= BI;
+		/*
+		 * If we're ignoring parity and break indicators,
+		 * ignore overruns too (for real raw support).
+		 */
+		if (termios->c_iflag & IGNPAR)
+			port->ignore_status_mask |= OE;
+	}
+
+	baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
+	quot = uart_get_divisor(port, baud);
+	spin_lock_irqsave(&uart->port.lock, flags);
+
+	do {
+		lsr = UART_GET_LSR(uart);
+	} while (!(lsr & TEMT));
+
+	/* Disable UART */
+	ier = UART_GET_IER(uart);
+	UART_CLEAR_IER(uart, 0xF);
+
+	UART_PUT_DLL(uart, quot & 0xFF);
+	SSYNC();
+	UART_PUT_DLH(uart, (quot >> 8) & 0xFF);
+	SSYNC();
+
+	UART_PUT_LCR(uart, lcr);
+
+	/* Enable UART */
+	UART_SET_IER(uart, ier);
+
+	val = UART_GET_GCTL(uart);
+	val |= UCEN;
+	UART_PUT_GCTL(uart, val);
+
+	spin_unlock_irqrestore(&uart->port.lock, flags);
+}
+
+static const char *ubi32_mailbox_type(struct uart_port *port)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+
+	return uart->port.type == PORT_UBI32_MAILBOX ? "UBI32_MAILBOX" : NULL;
+}
+
+/*
+ * Release the memory region(s) being used by 'port'.
+ */
+static void ubi32_mailbox_release_port(struct uart_port *port)
+{
+}
+
+/*
+ * Request the memory region(s) being used by 'port'.
+ */
+static int ubi32_mailbox_request_port(struct uart_port *port)
+{
+	return 0;
+}
+
+/*
+ * Configure/autoconfigure the port.
+ */
+static void ubi32_mailbox_config_port(struct uart_port *port, int flags)
+{
+	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+
+	if (flags & UART_CONFIG_TYPE && ubi32_mailbox_request_port(&uart->port) == 0)
+		uart->port.type = PORT_UBI32_MAILBOX;
+}
+
+/*
+ * Verify the new serial_struct (for TIOCSSERIAL).
+ * The only change we allow are to the flags and type, and
+ * even then only between PORT_UBI32_MAILBOX and PORT_UNKNOWN
+ */
+static int
+ubi32_mailbox_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+	return 0;
+}
+
+static struct uart_ops ubi32_mailbox_pops = {
+	.tx_empty	= ubi32_mailbox_tx_empty,
+	.set_mctrl	= ubi32_mailbox_set_mctrl,
+	.get_mctrl	= ubi32_mailbox_get_mctrl,
+	.stop_tx	= ubi32_mailbox_stop_tx,
+	.start_tx	= ubi32_mailbox_start_tx,
+	.stop_rx	= ubi32_mailbox_stop_rx,
+	.enable_ms	= ubi32_mailbox_enable_ms,
+	.break_ctl	= ubi32_mailbox_break_ctl,
+	.startup	= ubi32_mailbox_startup,
+	.shutdown	= ubi32_mailbox_shutdown,
+	.set_termios	= ubi32_mailbox_set_termios,
+	.type		= ubi32_mailbox_type,
+	.release_port	= ubi32_mailbox_release_port,
+	.request_port	= ubi32_mailbox_request_port,
+	.config_port	= ubi32_mailbox_config_port,
+	.verify_port	= ubi32_mailbox_verify_port,
+};
+
+static void __init ubi32_mailbox_init_ports(void)
+{
+	static int first = 1;
+	int i;
+
+	if (!first)
+		return;
+	first = 0;
+
+	for (i = 0; i < NR_PORTS; i++) {
+		ubi32_mailbox_ports[i].port.uartclk   = get_sclk();
+		ubi32_mailbox_ports[i].port.ops       = &ubi32_mailbox_pops;
+		ubi32_mailbox_ports[i].port.line      = i;
+		ubi32_mailbox_ports[i].port.iotype    = UPIO_MEM;
+		ubi32_mailbox_ports[i].port.membase   =
+			(void __iomem *)ubi32_mailbox_resource[i].uart_base_addr;
+		ubi32_mailbox_ports[i].port.mapbase   =
+			ubi32_mailbox_resource[i].uart_base_addr;
+		ubi32_mailbox_ports[i].port.irq       =
+			ubi32_mailbox_resource[i].uart_irq;
+		ubi32_mailbox_ports[i].port.flags     = UPF_BOOT_AUTOCONF;
+		spin_lock_init(&ubi32_mailbox_ports[i].port.lock);
+
+		ubi32_mailbox_hw_init(&ubi32_mailbox_ports[i]);
+	}
+
+}
+
+#ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
+/*
+ * If the port was already initialised (eg, by a boot loader),
+ * try to determine the current setup.
+ */
+static void __init
+ubi32_mailbox_console_get_options(struct ubi32_mailbox_port *uart, int *baud,
+			   int *parity, int *bits)
+{
+	unsigned short status;
+
+	status = UART_GET_IER(uart) & (ERBFI | ETBEI);
+	if (status == (ERBFI | ETBEI)) {
+		/* ok, the port was enabled */
+		unsigned short lcr;
+		unsigned short dlh, dll;
+
+		lcr = UART_GET_LCR(uart);
+
+		*parity = 'n';
+		if (lcr & PEN) {
+			if (lcr & EPS)
+				*parity = 'e';
+			else
+				*parity = 'o';
+		}
+		switch (lcr & 0x03) {
+			case 0:	*bits = 5; break;
+			case 1:	*bits = 6; break;
+			case 2:	*bits = 7; break;
+			case 3:	*bits = 8; break;
+		}
+
+		dll = UART_GET_DLL(uart);
+		dlh = UART_GET_DLH(uart);
+
+		*baud = get_sclk() / (16*(dll | dlh << 8));
+	}
+	pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__, *baud, *parity, *bits);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
+static struct uart_driver ubi32_mailbox_reg;
+
+static int __init
+ubi32_mailbox_console_setup(struct console *co, char *options)
+{
+	struct ubi32_mailbox_port *uart;
+# ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
+	int baud = SERIAL_UBICOM_BAUDRATE;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+# endif
+
+	/*
+	 * Check whether an invalid uart number has been specified, and
+	 * if so, search for the first available port that does have
+	 * console support.
+	 */
+	if (co->index == -1 || co->index >= NR_PORTS)
+		co->index = 0;
+	uart = &ubi32_mailbox_ports[co->index];
+
+# ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
+	if (options)
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+	else
+		ubi32_mailbox_console_get_options(uart, &baud, &parity, &bits);
+
+	//JB return uart_set_options(&uart->port, co, baud, parity, bits, flow);
+	return 0;
+# else
+	return 0;
+# endif
+}
+#endif /* defined (CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) ||
+				 defined (CONFIG_EARLY_PRINTK) */
+
+#ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
+static void ubi32_mailbox_console_putchar(struct uart_port *port, int ch)
+{
+//	struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
+	while (!(UART_GET_LSR(uart) & THRE))
+		barrier();
+	UART_PUT_CHAR(uart, ch);
+	SSYNC();
+}
+
+/*
+ * Interrupts are disabled on entering
+ */
+static void
+ubi32_mailbox_console_write(struct console *co, const char *s, unsigned int count)
+{
+	struct ubi32_mailbox_port *uart = &ubi32_mailbox_ports[co->index];
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&uart->port.lock, flags);
+	uart_console_write(&uart->port, s, count, ubi32_mailbox_console_putchar);
+	spin_unlock_irqrestore(&uart->port.lock, flags);
+
+}
+
+static struct console ubi32_mailbox_console = {
+	.name		= UBI32_MAILBOX_NAME,
+	.write		= ubi32_mailbox_console_write,
+	.device		= uart_console_device,
+	.setup		= ubi32_mailbox_console_setup,
+	.flags		= CON_PRINTBUFFER,
+	.index		= -1,
+	.data		= &ubi32_mailbox_reg,
+};
+
+static int __init ubi32_mailbox_console_init(void)
+{
+	ubi32_mailbox_init_ports();
+	register_console(&ubi32_mailbox_console);
+	return 0;
+}
+console_initcall(ubi32_mailbox_console_init);
+
+#define UBI32_MAILBOX_CONSOLE	&ubi32_mailbox_console
+#else
+#define UBI32_MAILBOX_CONSOLE	NULL
+#endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
+
+
+#ifdef CONFIG_EARLY_PRINTK
+static __init void ubi32_mailbox_early_putc(struct uart_port *port, int ch)
+{
+	UART_PUT_CHAR(uart, ch);
+}
+
+static __init void ubi32_mailbox_early_write(struct console *con, const char *s,
+					unsigned int n)
+{
+	struct ubi32_mailbox_port *uart = &ubi32_mailbox_ports[con->index];
+	unsigned int i;
+
+	for (i = 0; i < n; i++, s++) {
+		if (*s == '\n')
+			ubi32_mailbox_early_putc(&uart->port, '\r');
+		ubi32_mailbox_early_putc(&uart->port, *s);
+	}
+}
+
+static struct __init console ubi32_mailbox_early_console = {
+	.name = "early_UM",
+	.write = ubi32_mailbox_early_write,
+	.device = uart_console_device,
+	.flags = CON_PRINTBUFFER,
+	.setup = ubi32_mailbox_console_setup,
+	.index = -1,
+	.data  = &ubi32_mailbox_reg,
+};
+
+/*
+ * XXX Unused in our driver. Need to find out what the termios initialization is good/needed for.
+ */
+struct console __init *ubi32_mailbox_early_init(unsigned int port,
+						unsigned int cflag)
+{
+	struct ubi32_mailbox_port *uart;
+	struct ktermios t;
+
+	if (port == -1 || port >= NR_PORTS)
+		port = 0;
+	ubi32_mailbox_init_ports();
+	ubi32_mailbox_early_console.index = port;
+	uart = &ubi32_mailbox_ports[port];
+	t.c_cflag = cflag;
+	t.c_iflag = 0;
+	t.c_oflag = 0;
+	t.c_lflag = ICANON;
+	t.c_line = port;
+	ubi32_mailbox_set_termios(&uart->port, &t, &t);
+	return &ubi32_mailbox_early_console;
+}
+
+#endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
+
+static struct uart_driver ubi32_mailbox_reg = {
+	.owner			= THIS_MODULE,
+	.driver_name		= "ubi32_mailbox",
+	.dev_name		= UBI32_MAILBOX_NAME,
+	.major			= UBI32_MAILBOX_MAJOR,
+	.minor			= UBI32_MAILBOX_MINOR,
+	.nr			= NR_PORTS,
+	.cons			= UBI32_MAILBOX_CONSOLE,
+};
+
+static int ubi32_mailbox_suspend(struct platform_device *dev, pm_message_t state)
+{
+	struct ubi32_mailbox_port *uart = platform_get_drvdata(dev);
+
+	if (uart)
+		uart_suspend_port(&ubi32_mailbox_reg, &uart->port);
+
+	return 0;
+}
+
+static int ubi32_mailbox_resume(struct platform_device *dev)
+{
+	struct ubi32_mailbox_port *uart = platform_get_drvdata(dev);
+
+	if (uart)
+		uart_resume_port(&ubi32_mailbox_reg, &uart->port);
+
+	return 0;
+}
+
+static int ubi32_mailbox_probe(struct platform_device *dev)
+{
+	struct resource *res = dev->resource;
+	int i;
+
+	for (i = 0; i < dev->num_resources; i++, res++)
+		if (res->flags & IORESOURCE_MEM)
+			break;
+
+	if (i < dev->num_resources) {
+		for (i = 0; i < NR_PORTS; i++, res++) {
+			if (ubi32_mailbox_ports[i].port.mapbase != res->start)
+				continue;
+			ubi32_mailbox_ports[i].port.dev = &dev->dev;
+			uart_add_one_port(&ubi32_mailbox_reg, &ubi32_mailbox_ports[i].port);
+			platform_set_drvdata(dev, &ubi32_mailbox_ports[i]);
+		}
+	}
+
+	return 0;
+}
+
+static int ubi32_mailbox_remove(struct platform_device *pdev)
+{
+	struct ubi32_mailbox_port *uart = platform_get_drvdata(pdev);
+
+	platform_set_drvdata(pdev, NULL);
+
+	if (uart)
+		uart_remove_one_port(&ubi32_mailbox_reg, &uart->port);
+
+	return 0;
+}
+
+static struct platform_driver ubi32_mailbox_driver = {
+	.probe		= ubi32_mailbox_probe,
+	.remove		= ubi32_mailbox_remove,
+	.suspend	= ubi32_mailbox_suspend,
+	.resume		= ubi32_mailbox_resume,
+	.driver		= {
+		.name	= "ubi32-mbox",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init ubi32_mailbox_init(void)
+{
+	int ret;
+
+	pr_info("Serial: Ubicom32 mailbox serial driver.\n");
+
+	mailbox_console_flg = TRUE;
+	num_timeouts = 0;
+	ubi32_mailbox_init_ports();
+
+	ret = uart_register_driver(&ubi32_mailbox_reg);
+	if (ret == 0) {
+		ret = platform_driver_register(&ubi32_mailbox_driver);
+		if (ret) {
+			pr_debug("uart register failed\n");
+			uart_unregister_driver(&ubi32_mailbox_reg);
+		}
+	}
+
+	/*
+	 * XXX HACK: currently probe does not get called, but the port needs to be added to work.
+	 */
+	uart_add_one_port(&ubi32_mailbox_reg, &ubi32_mailbox_ports[0].port);
+	return ret;
+}
+
+static void __exit ubi32_mailbox_exit(void)
+{
+	platform_driver_unregister(&ubi32_mailbox_driver);
+	uart_unregister_driver(&ubi32_mailbox_reg);
+}
+
+module_init(ubi32_mailbox_init);
+module_exit(ubi32_mailbox_exit);
+
+MODULE_ALIAS_CHARDEV_MAJOR(UBI32_MAILBOX_MAJOR);
+MODULE_ALIAS("platform:ubi32_mailbox");
--- /dev/null
+++ b/drivers/serial/ubi32_serdes.c
@@ -0,0 +1,817 @@
+/*
+ * drivers/serial/ubi32_serdes.c
+ *   Ubicom32 On-Chip Serial Driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/sysrq.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial_core.h>
+
+#include <asm/ip5000.h>
+#include <asm/ubicom32suart.h>
+
+
+#define SERIAL_UBICOM_PIN_RXD	(1 << 0)
+#define SERIAL_UBICOM_PIN_TXD	(1 << 6)
+#define SERIAL_UBICOM_CTL0	0x8b300000
+#define SERIAL_UBICOM_CTL1	0x00000009
+
+#define SERIAL_UBICOM_DATA_BIT	8	/* Fixed parameter - do not change */
+#define SERIAL_UBICOM_PAR_BIT	0	/* Fixed parameter - do not change */
+#define SERIAL_UBICOM_STOP_BIT	1	/* Fixed parameter - do not change */
+
+/* UART name and device definitions */
+#define UBI32_SERDES_NAME	"ttyUS" // XXX
+#define UBI32_SERDES_MAJOR	206 // XXX
+#define UBI32_SERDES_MINOR	64 // XXX
+
+#define PORT_UBI32_SERDES	1234
+#define NR_PORTS 1
+
+struct uart_port ubi32_serdes_ports[NR_PORTS];
+
+struct ubi32_serdes_resource {
+	void *uart_base_addr;
+	int uart_irq;
+	int uart_clock;
+} ubi32_serdes_resource[NR_PORTS] = {
+	/*
+	 * Get params from kernel command line (required for early printk)
+	 * or from platform resources.
+	 */
+	{0, 0, 0}
+};
+
+/*
+ * Can get overridden by 'serdes=' kernel command line.
+ */
+static int ubi32_serdes_default_baud_rate = 115200;
+
+
+#define IO_PORT(port) ((struct ubicom32_io_port *)port->membase)
+#define IO_PORT_INT_STATUS(port) (IO_PORT(port)->int_status)
+#define IO_PORT_INT_MASK(port) (IO_PORT(port)->int_mask)
+#define IO_PORT_INT_CLR(port) (IO_PORT(port)->int_clr)
+
+
+/*
+ * ubi32_serdes_get_char()
+ */
+static u8_t ubi32_serdes_get_char(struct ubicom32_io_port *io_port)
+{
+	/*
+	 * Read from hardware (forced 32-bit atomic read).
+	 */
+	u32_t data = 0;
+
+	if ( io_port ) {
+		io_port->int_clr = IO_PORTX_INT_SERDES_RXBF;
+		asm volatile (
+			"move.4		%0, %1		\n\t"
+			: "=r" (data)
+			: "m" (*(u32_t *)&(io_port->rx_fifo))
+			);
+	}
+
+	return (u8_t)(data & 0x000000ff);
+}
+
+/*
+ * ubi32_serdes_put_char()
+ */
+static void ubi32_serdes_put_char(struct ubicom32_io_port *io_port, u8_t c)
+{
+	u32_t data = 0x0000fe00 | (c << 1);
+
+	if ( io_port ) {
+		/*
+		 * Fixed data format: 
+		 * [LSB]1 start bit - 8 data bits - no parity - 1 stop bit[MSB]
+		 */
+		io_port->int_clr = IO_PORTX_INT_SERDES_TXBE;
+		io_port->ctl2 = data;
+		io_port->int_set = IO_PORTX_INT_SERDES_TXBUF_VALID;
+	}
+}
+
+static void ubi32_serdes_hw_init(struct uart_port *port, int baud)
+{
+	struct ubicom32_io_port *io_port = IO_PORT(port);
+
+	if ( io_port ) {
+		/*
+		 * Put port functions 1-4 into reset state.
+		 * Function 0 (GPIO) does not need or have a reset bit.
+		 *
+		 * Select SERDES function for restart below.
+		 */
+		io_port->function =
+			IO_FUNC_FUNCTION_RESET(1) | IO_FUNC_FUNCTION_RESET(2) |
+			IO_FUNC_FUNCTION_RESET(3) | IO_FUNC_FUNCTION_RESET(4) |
+			IO_PORTX_FUNC_SERDES;
+
+		/*
+		 * Configure SERDES baudrate
+		 */
+		if ( baud == 0 ) {
+			baud = ubi32_serdes_default_baud_rate;
+		}
+
+		io_port->ctl0 =
+			SERIAL_UBICOM_CTL0 | 
+			((port->uartclk / (16 * baud)) - 1);
+
+		io_port->ctl1 =
+			SERIAL_UBICOM_CTL1;
+
+		/*
+		 * don't interrupt until startup and start_tx
+		 */
+		io_port->int_mask = 0;
+
+		/*
+		 * Set TXD pin output, RXD input and prevent GPIO
+		 * override on the TXD & RXD pins
+		 */
+		io_port->gpio_ctl &= ~SERIAL_UBICOM_PIN_RXD;
+		io_port->gpio_ctl |= SERIAL_UBICOM_PIN_TXD;
+		io_port->gpio_mask &= ~(SERIAL_UBICOM_PIN_RXD | SERIAL_UBICOM_PIN_TXD);
+
+		/*
+		 * Restart (un-reset) the port's SERDES function.
+		 */
+		io_port->function &= ~(IO_FUNC_FUNCTION_RESET(IO_PORTX_FUNC_SERDES));
+	}
+}
+
+#define ULITE_STATUS_RXVALID IO_PORTX_INT_SERDES_RXBF
+#define ULITE_STATUS_OVERRUN 0
+#define ULITE_STATUS_FRAME 0
+#define ULITE_STATUS_PARITY 0
+#define ULITE_STATUS_TXEMPTY IO_PORTX_INT_SERDES_TXBE
+#define ULITE_STATUS_TXFULL 0
+
+static int ubi32_serdes_receive(struct uart_port *port, int stat)
+{
+	struct tty_struct *tty = port->info->port.tty;
+	unsigned char ch = 0;
+	char flag = TTY_NORMAL;
+
+	if ((stat & (ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN
+		     | ULITE_STATUS_FRAME)) == 0)
+		return 0;
+
+	/* stats */
+	if (stat & ULITE_STATUS_RXVALID) {
+		port->icount.rx++;
+		ch = ubi32_serdes_get_char((struct ubicom32_io_port *)port->membase);
+
+		if (stat & ULITE_STATUS_PARITY)
+			port->icount.parity++;
+	}
+
+	if (stat & ULITE_STATUS_OVERRUN)
+		port->icount.overrun++;
+
+	if (stat & ULITE_STATUS_FRAME)
+		port->icount.frame++;
+
+
+	/* drop byte with parity error if IGNPAR specificed */
+	if (stat & port->ignore_status_mask & ULITE_STATUS_PARITY)
+		stat &= ~ULITE_STATUS_RXVALID;
+
+	stat &= port->read_status_mask;
+
+	if (stat & ULITE_STATUS_PARITY)
+		flag = TTY_PARITY;
+
+	stat &= ~port->ignore_status_mask;
+
+	if (stat & ULITE_STATUS_RXVALID)
+		tty_insert_flip_char(tty, ch, flag);
+
+	if (stat & ULITE_STATUS_FRAME)
+		tty_insert_flip_char(tty, 0, TTY_FRAME);
+
+	if (stat & ULITE_STATUS_OVERRUN)
+		tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+
+	return 1;
+}
+
+/*
+ * interrupts are disabled on entry
+ */
+static void ubi32_serdes_stop_tx(struct uart_port *port)
+{
+	IO_PORT_INT_MASK(port) = IO_PORT_INT_MASK(port) & ~IO_PORTX_INT_SERDES_TXBE;
+}
+
+static int ubi32_serdes_transmit(struct uart_port *port, int stat)
+{
+	struct circ_buf *xmit  = &port->info->xmit;
+
+	if (!(stat & IO_PORTX_INT_SERDES_TXBE))
+		return 0;
+
+	if (port->x_char) {
+		ubi32_serdes_put_char(IO_PORT(port), port->x_char);
+		port->x_char = 0;
+		port->icount.tx++;
+		return 1;
+	}
+
+	if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
+		ubi32_serdes_stop_tx(port);
+		return 0;
+	}
+
+	ubi32_serdes_put_char(IO_PORT(port), xmit->buf[xmit->tail]);
+	xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1);
+	port->icount.tx++;
+
+	/* wake up */
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+		uart_write_wakeup(port);
+
+	if (uart_circ_empty(xmit))
+		ubi32_serdes_stop_tx(port);
+
+	return 1;
+}
+
+/*
+ * port is locked and interrupts are disabled
+ */
+static void ubi32_serdes_start_tx(struct uart_port *port)
+{
+	IO_PORT_INT_MASK(port) = IO_PORT_INT_MASK(port) | IO_PORTX_INT_SERDES_TXBE;
+	ubi32_serdes_transmit(port, IO_PORT_INT_STATUS(port));
+}
+
+/*
+ * Interrupts are enabled
+ */
+static void ubi32_serdes_stop_rx(struct uart_port *port)
+{
+	/* don't forward any more data (like !CREAD) */
+	port->ignore_status_mask = IO_PORTX_INT_SERDES_RXBF;
+}
+
+/*
+ * Set the modem control timer to fire immediately.
+ */
+static void ubi32_serdes_enable_ms(struct uart_port *port)
+{
+	/* N/A */
+}
+
+static irqreturn_t ubi32_serdes_isr(int irq, void *dev_id)
+{
+	struct uart_port *port = dev_id;
+	int busy;
+
+	spin_lock(&port->lock);
+
+	do {
+		int stat = IO_PORT_INT_STATUS(port);
+		busy  = ubi32_serdes_receive(port, stat);
+		busy |= ubi32_serdes_transmit(port, stat);
+	} while (busy);
+
+	tty_flip_buffer_push(port->info->port.tty);
+
+	spin_unlock(&port->lock);
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Return TIOCSER_TEMT when transmitter is not busy.
+ */
+static unsigned int ubi32_serdes_tx_empty(struct uart_port *port)
+{
+	unsigned long flags;
+	unsigned int ret;
+
+	spin_lock_irqsave(&port->lock, flags);
+	ret = IO_PORT_INT_STATUS(port);
+	spin_unlock_irqrestore(&port->lock, flags);
+
+	return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0;
+}
+
+static unsigned int ubi32_serdes_get_mctrl(struct uart_port *port)
+{
+	return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
+}
+
+static void ubi32_serdes_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+	/* N/A */
+}
+
+/*
+ * Interrupts are always disabled.
+ */
+static void ubi32_serdes_break_ctl(struct uart_port *port, int break_state)
+{
+	/* N/A */
+}
+
+static int ubi32_serdes_startup(struct uart_port *port)
+{
+	if (request_irq(port->irq, ubi32_serdes_isr, IRQF_DISABLED,
+	     "UBI32_SERDES", port)) {
+		printk(KERN_NOTICE "Unable to attach port interrupt\n");
+		return -EBUSY;
+	}
+
+	IO_PORT_INT_CLR(port) = IO_PORTX_INT_SERDES_RXBF;
+	IO_PORT_INT_MASK(port) = IO_PORTX_INT_SERDES_RXBF;
+	return 0;
+}
+
+static void ubi32_serdes_shutdown(struct uart_port *port)
+{
+	struct ubi32_serdes_port *uart = (struct ubi32_serdes_port *)port;
+
+	IO_PORT_INT_MASK(port) = 0;
+	free_irq(port->irq, uart);
+}
+
+static void
+ubi32_serdes_set_termios(struct uart_port *port, struct ktermios *termios,
+		   struct ktermios *old)
+{
+	unsigned long flags;
+	unsigned int baud;
+
+	spin_lock_irqsave(&port->lock, flags);
+
+	port->read_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN
+		| ULITE_STATUS_TXFULL;
+
+	if (termios->c_iflag & INPCK)
+		port->read_status_mask |=
+			ULITE_STATUS_PARITY | ULITE_STATUS_FRAME;
+
+	port->ignore_status_mask = 0;
+	if (termios->c_iflag & IGNPAR)
+		port->ignore_status_mask |= ULITE_STATUS_PARITY
+			| ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN;
+
+	/* ignore all characters if CREAD is not set */
+	if ((termios->c_cflag & CREAD) == 0)
+		port->ignore_status_mask |=
+			ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY
+			| ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN;
+
+	/* update timeout */
+	baud = uart_get_baud_rate(port, termios, old, 0, 460800);
+	uart_update_timeout(port, termios->c_cflag, baud);
+
+	IO_PORT(port)->ctl0 = SERIAL_UBICOM_CTL0 | 
+			((port->uartclk / (16 * baud)) - 1);
+
+	spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static const char *ubi32_serdes_type(struct uart_port *port)
+{
+	return port->type == PORT_UBI32_SERDES ? "UBI32_SERDES" : NULL;
+}
+
+/*
+ * Release the memory region(s) being used by 'port'.
+ */
+static void ubi32_serdes_release_port(struct uart_port *port)
+{
+}
+
+/*
+ * Request the memory region(s) being used by 'port'.
+ */
+static int ubi32_serdes_request_port(struct uart_port *port)
+{
+	return 0;
+}
+
+/*
+ * Configure/autoconfigure the port.
+ */
+static void ubi32_serdes_config_port(struct uart_port *port, int flags)
+{
+	if (flags & UART_CONFIG_TYPE &&
+	    ubi32_serdes_request_port(port) == 0)
+		port->type = PORT_UBI32_SERDES;
+}
+
+/*
+ * Verify the new serial_struct (for TIOCSSERIAL).
+ * The only change we allow are to the flags and type, and
+ * even then only between PORT_UBI32_SERDES and PORT_UNKNOWN
+ */
+static int
+ubi32_serdes_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+	return 0;
+}
+
+static struct uart_ops ubi32_serdes_pops = {
+	.tx_empty	= ubi32_serdes_tx_empty,
+	.set_mctrl	= ubi32_serdes_set_mctrl,
+	.get_mctrl	= ubi32_serdes_get_mctrl,
+	.stop_tx	= ubi32_serdes_stop_tx,
+	.start_tx	= ubi32_serdes_start_tx,
+	.stop_rx	= ubi32_serdes_stop_rx,
+	.enable_ms	= ubi32_serdes_enable_ms,
+	.break_ctl	= ubi32_serdes_break_ctl,
+	.startup	= ubi32_serdes_startup,
+	.shutdown	= ubi32_serdes_shutdown,
+	.set_termios	= ubi32_serdes_set_termios,
+	.type		= ubi32_serdes_type,
+	.release_port	= ubi32_serdes_release_port,
+	.request_port	= ubi32_serdes_request_port,
+	.config_port	= ubi32_serdes_config_port,
+	.verify_port	= ubi32_serdes_verify_port,
+};
+
+static void __init ubi32_serdes_init_ports(void)
+{
+	int i;
+
+	for (i = 0; i < NR_PORTS; i++) {
+		ubi32_serdes_ports[i].uartclk   = ubi32_serdes_resource[i].uart_clock;
+		ubi32_serdes_ports[i].ops       = &ubi32_serdes_pops;
+		ubi32_serdes_ports[i].line      = i;
+		ubi32_serdes_ports[i].iotype    = UPIO_MEM;
+		ubi32_serdes_ports[i].membase   =
+			(void __iomem *)ubi32_serdes_resource[i].uart_base_addr;
+		ubi32_serdes_ports[i].mapbase   =
+			(resource_size_t)ubi32_serdes_resource[i].uart_base_addr;
+		ubi32_serdes_ports[i].irq       =
+			ubi32_serdes_resource[i].uart_irq;
+		ubi32_serdes_ports[i].flags     = UPF_BOOT_AUTOCONF;
+
+		ubi32_serdes_hw_init(&ubi32_serdes_ports[i], 0);
+	}
+
+}
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES_CONSOLE
+/*
+ * If the port was already initialised (eg, by a boot loader),
+ * try to determine the current setup.
+ */
+static void __init
+ubi32_serdes_console_get_options(struct uart_port *port, int *baud)
+{
+	u32 round_to = 1200;
+	u32 real_baud;
+
+	/*
+	 * We might get called before platform init and with no
+	 * kernel command line options, so port might be NULL.
+	 */
+	*baud = ubi32_serdes_default_baud_rate;;
+	if ( IO_PORT(port) == 0 )
+		return;
+
+	real_baud = port->uartclk 
+		/ (16 * ((IO_PORT(port)->ctl0 & ~SERIAL_UBICOM_CTL0) + 1));
+
+	*baud = ((real_baud + round_to - 1) / round_to) * round_to;
+
+	pr_debug("%s:baud = %d, real_baud = %d\n", __FUNCTION__, *baud, real_baud);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_UBI32_SERDES_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
+static struct uart_driver ubi32_serdes_reg;
+
+static int __init
+ubi32_serdes_console_setup(struct console *co, char *options)
+{
+	struct uart_port *port;
+#ifdef CONFIG_SERIAL_UBI32_SERDES_CONSOLE
+	int baud = ubi32_serdes_default_baud_rate;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+#endif
+
+	/*
+	 * Check whether an invalid uart number has been specified, and
+	 * if so, search for the first available port that does have
+	 * console support.
+	 */
+	if (co->index == -1 || co->index >= NR_PORTS)
+		co->index = 0;
+	port = &ubi32_serdes_ports[co->index];
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES_CONSOLE
+	if (options) {
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+		ubi32_serdes_hw_init(port, baud);
+	}
+	else
+		ubi32_serdes_console_get_options(port, &baud);
+
+	return uart_set_options(port, co, baud, parity, bits, flow);
+#else
+	return 0;
+#endif
+}
+#endif /* defined (CONFIG_SERIAL_UBI32_SERDES_CONSOLE) ||
+				 defined (CONFIG_EARLY_PRINTK) */
+
+#ifdef CONFIG_SERIAL_UBI32_SERDES_CONSOLE
+static void 
+ubi32_serdes_console_putchar(struct uart_port *port, int ch)
+{
+	if ( IO_PORT(port) ) {
+		while (!(IO_PORT_INT_STATUS(port) & IO_PORTX_INT_SERDES_TXBE))
+			barrier();
+		ubi32_serdes_put_char(IO_PORT(port), ch);
+	}
+}
+
+/*
+ * Interrupts are disabled on entering
+ */
+static void
+ubi32_serdes_console_write(struct console *co, const char *s, unsigned int count)
+{
+	struct uart_port *port = &ubi32_serdes_ports[co->index];
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&port->lock, flags);
+	uart_console_write(port, s, count, ubi32_serdes_console_putchar);
+	spin_unlock_irqrestore(&port->lock, flags);
+
+}
+
+static struct console ubi32_serdes_console = {
+	.name		= UBI32_SERDES_NAME,
+	.write		= ubi32_serdes_console_write,
+	.device		= uart_console_device,
+	.setup		= ubi32_serdes_console_setup,
+	.flags		= CON_PRINTBUFFER,
+	.index		= -1,
+	.data		= &ubi32_serdes_reg,
+};
+
+static int __init ubi32_serdes_console_init(void)
+{
+	ubi32_serdes_init_ports();
+	register_console(&ubi32_serdes_console);
+	return 0;
+}
+console_initcall(ubi32_serdes_console_init);
+
+#define UBI32_SERDES_CONSOLE	&ubi32_serdes_console
+#else
+#define UBI32_SERDES_CONSOLE	NULL
+#endif /* CONFIG_SERIAL_UBI32_SERDES_CONSOLE */
+
+
+#ifdef CONFIG_EARLY_PRINTK
+static __init void ubi32_serdes_early_putc(struct uart_port *port, int ch)
+{
+	unsigned timeout = 0xffff;
+
+	while ((!(IO_PORT_INT_STATUS(port) & IO_PORTX_INT_SERDES_TXBE)) && --timeout)
+		cpu_relax();
+	ubi32_serdes_put_char(IO_PORT(port), ch);
+}
+
+static __init void ubi32_serdes_early_write(struct console *con, const char *s,
+					unsigned int n)
+{
+	struct uart_port *port = &ubi32_serdes_ports[con->index];
+	unsigned int i;
+
+	for (i = 0; i < n; i++, s++) {
+		if (*s == '\n')
+			ubi32_serdes_early_putc(port, '\r');
+		ubi32_serdes_early_putc(port, *s);
+	}
+}
+
+static struct __init console ubi32_serdes_early_console = {
+	.name = "early_US",
+	.write = ubi32_serdes_early_write,
+	.device = uart_console_device,
+	.flags = CON_PRINTBUFFER,
+	.setup = ubi32_serdes_console_setup,
+	.index = -1,
+	.data  = &ubi32_serdes_reg,
+};
+
+/*
+ * XXX Unused in our driver. Need to find out what the termios initialization is good/needed for.
+ */
+struct console __init *ubi32_serdes_early_init(unsigned int port_index,
+						unsigned int cflag)
+{
+	struct uart_port *uart;
+	struct ktermios t;
+
+	if (port_index == -1 || port_index >= NR_PORTS)
+		port_index = 0;
+	ubi32_serdes_init_ports();
+	ubi32_serdes_early_console.index = port_index;
+	uart = &ubi32_serdes_ports[port_index];
+	t.c_cflag = cflag;
+	t.c_iflag = 0;
+	t.c_oflag = 0;
+	t.c_lflag = ICANON;
+	t.c_line = port_index;
+	ubi32_serdes_set_termios(uart, &t, &t);
+	return &ubi32_serdes_early_console;
+}
+
+#endif /* CONFIG_SERIAL_UBI32_SERDES_CONSOLE */
+
+static struct uart_driver ubi32_serdes_reg = {
+	.owner			= THIS_MODULE,
+	.driver_name		= "ubi32_serdes",
+	.dev_name		= UBI32_SERDES_NAME,
+	.major			= UBI32_SERDES_MAJOR,
+	.minor			= UBI32_SERDES_MINOR,
+	.nr			= NR_PORTS,
+	.cons			= UBI32_SERDES_CONSOLE,
+};
+
+static int ubi32_serdes_suspend(struct platform_device *dev, pm_message_t state)
+{
+	struct uart_port *port = platform_get_drvdata(dev);
+
+	if (port)
+		uart_suspend_port(&ubi32_serdes_reg, port);
+
+	return 0;
+}
+
+static int ubi32_serdes_resume(struct platform_device *dev)
+{
+	struct uart_port *port = platform_get_drvdata(dev);
+
+	if (port)
+		uart_resume_port(&ubi32_serdes_reg, port);
+
+	return 0;
+}
+
+static int ubi32_serdes_probe(struct platform_device *dev)
+{
+	struct resource *res = dev->resource;
+	int i;
+
+	for (i = 0; i < dev->num_resources; i++, res++) {
+		if (res->flags & IORESOURCE_MEM) {
+			ubi32_serdes_resource[0].uart_base_addr = (void *) res->start;
+		}
+		else if (res->flags & IORESOURCE_IRQ) {
+			ubi32_serdes_resource[0].uart_irq = res->start;
+		}
+		else if (res->flags & UBICOM32_SUART_IORESOURCE_CLOCK) {
+			ubi32_serdes_resource[0].uart_clock = res->start;
+		}
+	}
+
+	ubi32_serdes_init_ports();
+
+	return 0;
+}
+
+static int ubi32_serdes_remove(struct platform_device *pdev)
+{
+	struct uart_port *port = platform_get_drvdata(pdev);
+
+	platform_set_drvdata(pdev, NULL);
+
+	if (port)
+		uart_remove_one_port(&ubi32_serdes_reg, port);
+
+	return 0;
+}
+
+static struct platform_driver ubi32_serdes_driver = {
+	.remove		= ubi32_serdes_remove,
+	.suspend	= ubi32_serdes_suspend,
+	.resume		= ubi32_serdes_resume,
+	.driver		= {
+		.name	= "ubicom32suart",
+		.owner	= THIS_MODULE,
+	},
+};
+
+
+#ifndef MODULE
+/*
+ * Called at boot time.
+ *
+ * You can specify IO base, IRQ, and clock for the serdes serial port
+ * using kernel command line "serdes=0xiobase,irq,clock".  Values
+ * specified will be overwritten by platform device data, if present.
+ */
+static int __init ubi32_serdes_setup(char *str)
+{
+#define N_PARMS   (4+1)
+	int ints[N_PARMS];
+	int i;
+
+	str = get_options(str, ARRAY_SIZE(ints), ints);
+
+	for (i = 0; i < N_PARMS; i++) {
+		if (i < ints[0]) {
+			if (i == 0) {
+				ubi32_serdes_resource[0].uart_base_addr = (void *) ints[i+1];
+			}
+			else if (i == 1) {
+				ubi32_serdes_resource[0].uart_irq = ints[i+1];
+			}
+			else if (i == 2) {
+				ubi32_serdes_resource[0].uart_clock = ints[i+1];
+			}
+			else if (i == 3) {
+				ubi32_serdes_default_baud_rate = ints[i+1];
+			}
+		}
+	}
+	return 1;
+}
+
+__setup("serdes=", ubi32_serdes_setup);
+#endif
+
+static int __init ubi32_serdes_init(void)
+{
+	int ret;
+
+	pr_info("Serial: Ubicom32 serdes uart serial driver\n");
+
+	ret = platform_driver_probe(&ubi32_serdes_driver, ubi32_serdes_probe);
+	if (ret != 0) {
+		printk(KERN_INFO "serdes platform_driver_probe() failed: %d\n", ret);
+		return ret;
+	}
+
+	ubi32_serdes_init_ports();
+
+	ret = uart_register_driver(&ubi32_serdes_reg);
+	if ( ret == 0 ) {
+		ret = uart_add_one_port(&ubi32_serdes_reg, &ubi32_serdes_ports[0]);
+		if ( ret != 0 ) {
+			uart_unregister_driver(&ubi32_serdes_reg);
+		}
+	}
+
+	return ret;
+}
+
+static void __exit ubi32_serdes_exit(void)
+{
+	platform_driver_unregister(&ubi32_serdes_driver);
+	uart_unregister_driver(&ubi32_serdes_reg);
+}
+
+module_init(ubi32_serdes_init);
+module_exit(ubi32_serdes_exit);
+
+MODULE_AUTHOR("Rainer Keller <rkeller@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom generic serial port driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(UBI32_SERDES_MAJOR);
+MODULE_ALIAS("platform:ubi32_serdes");
--- /dev/null
+++ b/drivers/serial/ubi32_uarttio.c
@@ -0,0 +1,1171 @@
+/*
+ * drivers/serial/ubi32_uarttio.c
+ *   Ubicom32 Serial Virtual Peripherial Driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/sysrq.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial_core.h>
+
+#include <asm/ip5000.h>
+#include <asm/gpio.h>
+#include <asm/thread.h>
+#include <asm/uart_tio.h>
+
+#define DRIVER_NAME	"ubi32_uarttio"
+
+/*
+ * For storing the module parameters.
+ */
+#define UBI32_UARTTIO_MAX_PARAM_LEN	80
+static char utio_ports_param[UBI32_UARTTIO_MAX_PARAM_LEN];
+
+/* 
+ * UART name and device definitions 
+ */
+#define UBI32_UARTTIO_NAME	"ttyUV" // XXX
+#define UBI32_UARTTIO_MAJOR	206 // XXX
+#define UBI32_UARTTIO_MINOR	64 // XXX
+
+/*
+ * The following structures are allocated statically because the
+ * memory allocation subsystem is not initialized this early on
+ */
+
+/*
+ * Per port structure
+ */
+struct ubi32_uarttio_port {
+	struct uarttio_uart		*uart;
+	unsigned int			tx_pin;
+	unsigned int			rx_pin;
+
+	struct uart_port		port;
+
+	u8_t				added;
+
+	/*
+	 * If this value is set, the port has had its direction set already
+	 */
+	u8_t				port_init;
+};
+static struct ubi32_uarttio_port uarttio_ports[CONFIG_SERIAL_UBI32_UARTTIO_NR_UARTS];
+
+/*
+ * Number of ports currently initialized
+ */
+static int uarttio_nports;
+
+/*
+ * Per device structure
+ */
+struct ubi32_uarttio_instance {
+	struct uarttio_regs		*regs;
+	struct ubi32_uarttio_port	*ports;
+
+	u8_t				irq_requested;
+	u8_t				driver_registered;
+	u8_t				irq;
+};
+static struct ubi32_uarttio_instance uarttio_inst;
+
+#ifdef CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE
+static struct console ubi32_uarttio_console;
+#define UBI32_UARTTIO_CONSOLE	&ubi32_uarttio_console
+#else
+#define UBI32_UARTTIO_CONSOLE	NULL
+#endif
+
+static struct uart_driver ubi32_uarttio_uart_driver = {
+	.owner			= THIS_MODULE,
+	.driver_name		= DRIVER_NAME,
+	.dev_name		= UBI32_UARTTIO_NAME,
+	.major			= UBI32_UARTTIO_MAJOR,
+	.minor			= UBI32_UARTTIO_MINOR,
+	.cons			= UBI32_UARTTIO_CONSOLE,
+};
+
+#ifdef UBI32_UARTTIO_UNUSED
+/*
+ * ubi32_uarttio_get_send_space
+ */
+static int ubi32_uarttio_get_send_space(struct uarttio_uart *uart)
+{
+	int count = uart->tx_fifo_head - uart->tx_fifo_tail;
+	if (count < 0) {
+		count += uart->tx_fifo_size;
+	}
+	return uart->tx_fifo_size - count;
+}
+#endif
+
+/*
+ * ubi32_uarttio_get_recv_ready
+ */
+static int ubi32_uarttio_get_recv_ready(struct uarttio_uart *uart)
+{
+	int count = uart->rx_fifo_head - uart->rx_fifo_tail;
+	if (count < 0) {
+		count += uart->rx_fifo_size;
+	}
+	return count;
+}
+
+/*
+ * ubi32_uarttio_get_char()
+ */
+static u8_t ubi32_uarttio_get_char(struct uarttio_uart *uart)
+{
+	/*
+	 * Retrieve byte
+	 */
+	u32_t tail = uart->rx_fifo_tail;
+	u8_t data = uart->rx_fifo[tail];
+
+	if (++tail == uart->rx_fifo_size) {
+		tail = 0;
+	}
+	uart->rx_fifo_tail = tail;
+
+	return data;
+}
+
+/*
+ * ubi32_uarttio_put_char()
+ */
+static int ubi32_uarttio_put_char(struct uarttio_uart *uart, u8_t c)
+{
+	u32_t head = uart->tx_fifo_head;
+	u32_t prev = head;
+
+	/*
+	 * Wrap
+	 */
+	if (++head == uart->tx_fifo_size) {
+		head = 0;
+	}
+
+	/*
+	 * If there isn't any space, return EBUSY
+	 */
+	if (head == uart->tx_fifo_tail) {
+		return -EBUSY;
+	}
+
+	/*
+	 * Put the character in the queue
+	 */
+	uart->tx_fifo[prev] = c;
+	uart->tx_fifo_head = head;
+
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_set_baud
+ */
+static int ubi32_uarttio_set_baud(struct ubi32_uarttio_port *uup, unsigned int baud)
+{
+	if (uup->uart->current_baud_rate == baud) {
+		return 0;
+	}
+
+	uup->uart->baud_rate = baud;
+	uup->uart->flags |= UARTTIO_UART_FLAG_SET_RATE;
+	while (uup->uart->flags & UARTTIO_UART_FLAG_SET_RATE) {
+		cpu_relax();
+	}
+
+	if (uup->uart->current_baud_rate != baud) {
+		/*
+		 * Failed to set baud rate
+		 */
+		printk(KERN_WARNING "Invalid baud rate %u, running at %u\n", baud, uup->uart->current_baud_rate);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_handle_receive
+ */
+static void ubi32_uarttio_handle_receive(struct ubi32_uarttio_port *uup, int stat)
+{
+	struct uarttio_uart *uart = uup->uart;
+	struct uart_port *port = &uup->port;
+	struct tty_struct *tty = port->info->port.tty;
+	unsigned char ch = 0;
+	char flag = TTY_NORMAL;
+	int count;
+
+	if ((stat & (UARTTIO_UART_INT_RX | UARTTIO_UART_INT_RXFRAME | UARTTIO_UART_INT_RXOVF)) == 0) {
+		return;
+	}
+
+	if (stat & UARTTIO_UART_INT_RX) {
+		count = ubi32_uarttio_get_recv_ready(uart);
+		port->icount.rx += count;
+	}
+
+	if (stat & UARTTIO_UART_INT_RXOVF) {
+		port->icount.overrun++;
+	}
+
+	if (stat & UARTTIO_UART_INT_RXFRAME) {
+		port->icount.frame++;
+	}
+
+	stat &= ~port->ignore_status_mask;
+
+	if (stat & UARTTIO_UART_INT_RX) {
+		int i;
+		for (i = 0; i < count; i++) {
+			ch = ubi32_uarttio_get_char(uart);
+			tty_insert_flip_char(tty, ch, flag);
+		}
+	}
+
+	if (stat & UARTTIO_UART_INT_RXFRAME) {
+		tty_insert_flip_char(tty, 0, TTY_FRAME);
+	}
+
+	if (stat & UARTTIO_UART_INT_RXOVF) {
+		tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+	}
+}
+
+/*
+ * ubi32_uarttio_stop_tx
+ *	interrupts are disabled on entry
+ */
+static void ubi32_uarttio_stop_tx(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+
+	uup->uart->int_mask &= ~UARTTIO_UART_INT_TXBE;
+}
+
+/*
+ * ubi32_uarttio_handle_transmit
+ */
+static void ubi32_uarttio_handle_transmit(struct ubi32_uarttio_port *uup, int stat)
+{
+	struct uarttio_uart *uart = uup->uart;
+	struct uart_port *port = &uup->port;
+	struct circ_buf *xmit  = &port->info->xmit;
+
+	if (!(stat & UARTTIO_UART_INT_TXBE)) {
+		return;
+	}
+
+	if (port->x_char) {
+		if (ubi32_uarttio_put_char(uart, port->x_char)) {
+			return;
+		}
+		port->x_char = 0;
+		port->icount.tx++;
+		return;
+	}
+
+	if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
+		ubi32_uarttio_stop_tx(port);
+		return;
+	}
+
+	/*
+	 * Send as many characters as we can
+	 */
+	while (ubi32_uarttio_put_char(uart, xmit->buf[xmit->tail]) == 0) {
+		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+		port->icount.tx++;
+		if (uart_circ_empty(xmit)) {
+			break;
+		}
+	}
+
+	/* wake up */
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) {
+		uart_write_wakeup(port);
+	}
+
+	if (uart_circ_empty(xmit)) {
+		ubi32_uarttio_stop_tx(port);
+	}
+}
+
+/*
+ * ubi32_uarttio_start_tx
+ *	port is locked and interrupts are disabled
+ */
+static void ubi32_uarttio_start_tx(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+	struct uarttio_uart *uart = uup->uart;
+
+	uart->int_mask |= UARTTIO_UART_INT_TXBE;
+}
+
+/*
+ * ubi32_uarttio_stop_rx
+ *	Interrupts are enabled
+ */
+static void ubi32_uarttio_stop_rx(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+	struct uarttio_uart *uart = uup->uart;
+
+	/* 
+	 * don't forward any more data (like !CREAD) 
+	 */
+	uart->int_mask &= ~UARTTIO_UART_INT_RX;
+	port->ignore_status_mask = UARTTIO_UART_INT_RX;
+}
+
+/*
+ * ubi32_uarttio_enable_ms
+ *	Set the modem control timer to fire immediately.
+ */
+static void ubi32_uarttio_enable_ms(struct uart_port *port)
+{
+	/* N/A */
+}
+
+/*
+ * ubi32_uarttio_isr
+ */
+static irqreturn_t ubi32_uarttio_isr(int irq, void *appdata)
+{
+	struct ubi32_uarttio_port *uup = uarttio_ports;
+	int i;
+
+	/*
+	 * Service all of the ports
+	 */
+	for (i = 0; i < uarttio_nports; i++) {
+		unsigned int flags;
+
+		if (!(uup->uart->flags & UARTTIO_UART_FLAG_ENABLED)) {
+			uup++;
+			continue;
+		}
+
+		spin_lock(&uup->port.lock);
+
+		flags = uup->uart->int_flags;
+
+		uup->uart->int_flags = 0;
+
+		ubi32_uarttio_handle_receive(uup, flags);
+		ubi32_uarttio_handle_transmit(uup, flags);
+
+		tty_flip_buffer_push(uup->port.info->port.tty);
+
+		spin_unlock(&uup->port.lock);
+
+		uup++;
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * ubi32_uarttio_tx_empty
+ *	Return TIOCSER_TEMT when transmitter is not busy.
+ */
+static unsigned int ubi32_uarttio_tx_empty(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+
+	if (uup->uart->tx_fifo_head == uup->uart->tx_fifo_tail) {
+		return TIOCSER_TEMT;
+	}
+
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_get_mctrl
+ */
+static unsigned int ubi32_uarttio_get_mctrl(struct uart_port *port)
+{
+	return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
+}
+
+/*
+ * ubi32_uarttio_set_mctrl
+ */
+static void ubi32_uarttio_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+	/* N/A */
+}
+
+/*
+ * ubi32_uarttio_break_ctl
+ */
+static void ubi32_uarttio_break_ctl(struct uart_port *port, int break_state)
+{
+	/* N/A */
+}
+
+/*
+ * ubi32_uarttio_startup
+ */
+static int ubi32_uarttio_startup(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+	struct uarttio_uart *uart = uup->uart;
+
+	uart->flags |= UARTTIO_UART_FLAG_ENABLED;
+
+	uart->int_mask |= UARTTIO_UART_INT_TXBE | UARTTIO_UART_INT_RX;
+
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_shutdown
+ */
+static void ubi32_uarttio_shutdown(struct uart_port *port)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+	struct uarttio_uart *uart = uup->uart;
+
+	uart->int_mask = 0;
+	uart->flags &= ~UARTTIO_UART_FLAG_ENABLED;
+}
+
+/*
+ * ubi32_uarttio_set_termios
+ */
+static void ubi32_uarttio_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+	unsigned long flags;
+	unsigned int baud;
+
+	spin_lock_irqsave(&port->lock, flags);
+
+#if 0
+	port->read_status_mask = UBI32_UARTTIO_RX | UBI32_UARTTIO_RXOVF | UBI32_UARTTIO_TXOVF;
+
+	if (termios->c_iflag & INPCK) {
+		port->read_status_mask |= UBI32_UARTTIO_RXFRAME;
+	}
+#endif
+
+	port->ignore_status_mask = 0;
+	if (termios->c_iflag & IGNPAR) {
+		port->ignore_status_mask |= UARTTIO_UART_INT_RXFRAME | 
+					    UARTTIO_UART_INT_RXOVF;
+	}
+
+	/* 
+	 * ignore all characters if CREAD is not set 
+	 */
+	if ((termios->c_cflag & CREAD) == 0) {
+		port->ignore_status_mask |= UARTTIO_UART_INT_RX | 
+					    UARTTIO_UART_INT_RXFRAME | 
+					    UARTTIO_UART_INT_RXOVF;
+	}
+
+	/* update timeout */
+	baud = uart_get_baud_rate(port, termios, old, 0, 460800);
+	uart_update_timeout(port, termios->c_cflag, baud);
+
+	ubi32_uarttio_set_baud(uup, baud);
+	spin_unlock_irqrestore(&port->lock, flags);
+}
+
+/*
+ * ubi32_uarttio_type
+ */
+static const char *ubi32_uarttio_type(struct uart_port *port)
+{
+	return (port->type == PORT_UBI32_UARTTIO) ? "UBI32_UARTTIO" : NULL;
+}
+
+/*
+ * ubi32_uarttio_release_port
+ *	Release the memory region(s) being used by 'port'.
+ */
+static void ubi32_uarttio_release_port(struct uart_port *port)
+{
+}
+
+/*
+ * ubi32_uarttio_request_port
+ *	Request the memory region(s) being used by 'port'.
+ */
+static int ubi32_uarttio_request_port(struct uart_port *port)
+{
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_config_port
+ *	Configure/autoconfigure the port.
+ */
+static void ubi32_uarttio_config_port(struct uart_port *port, int flags)
+{
+	if ((flags & UART_CONFIG_TYPE) && (ubi32_uarttio_request_port(port) == 0)) {
+		port->type = PORT_UBI32_UARTTIO;
+	}
+}
+
+/*
+ * ubi32_uarttio_verify_port
+ *	Verify the new serial_struct (for TIOCSSERIAL).
+ *
+ * The only change we allow are to the flags and type, and
+ * even then only between PORT_UBI32_UARTTIO and PORT_UNKNOWN
+ */
+static int ubi32_uarttio_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+	return 0;
+}
+
+static struct uart_ops ubi32_uarttio_pops = {
+	.tx_empty	= ubi32_uarttio_tx_empty,
+	.set_mctrl	= ubi32_uarttio_set_mctrl,
+	.get_mctrl	= ubi32_uarttio_get_mctrl,
+	.stop_tx	= ubi32_uarttio_stop_tx,
+	.start_tx	= ubi32_uarttio_start_tx,
+	.stop_rx	= ubi32_uarttio_stop_rx,
+	.enable_ms	= ubi32_uarttio_enable_ms,
+	.break_ctl	= ubi32_uarttio_break_ctl,
+	.startup	= ubi32_uarttio_startup,
+	.shutdown	= ubi32_uarttio_shutdown,
+	.set_termios	= ubi32_uarttio_set_termios,
+	.type		= ubi32_uarttio_type,
+	.release_port	= ubi32_uarttio_release_port,
+	.request_port	= ubi32_uarttio_request_port,
+	.config_port	= ubi32_uarttio_config_port,
+	.verify_port	= ubi32_uarttio_verify_port,
+};
+
+/*
+ * ubi32_uarttio_add_ports
+ */
+static int __init ubi32_uarttio_add_ports(void)
+{
+	int res = 0;
+	struct ubi32_uarttio_port *uup = uarttio_ports;
+	int i = 0;
+
+	for (i = 0; i < uarttio_nports; i++) {
+		/*
+		 * Setup the GPIOs
+		 */
+		res = gpio_request(uup->tx_pin, "ubi32_uarttio_tx");
+		if (res) {
+			printk(KERN_WARNING "Failed to request GPIO %d\n", uup->tx_pin);
+			res = -EBUSY;
+			goto next;
+		}
+
+		res = gpio_request(uup->rx_pin, "ubi32_uarttio_rx");
+		if (res) {
+			gpio_free(uup->tx_pin);
+			printk(KERN_WARNING "Failed to request GPIO %d\n", uup->rx_pin);
+			res = -EBUSY;
+			goto next;
+		}
+
+		res = uart_add_one_port(&ubi32_uarttio_uart_driver, &uup->port);
+		if (res) {
+			gpio_free(uup->rx_pin);
+			gpio_free(uup->tx_pin);
+			res = -ENODEV;
+			printk(KERN_WARNING "Failed to add port %d,%d\n", uup->tx_pin, uup->rx_pin);
+			goto next;
+		}
+		uup->added = 1;
+
+		/*
+		 * Set the direction of the ports now, after we're sure that everything is ok
+		 */
+		if (!uup->port_init) {
+			gpio_direction_output(uup->tx_pin, 1);
+			gpio_direction_input(uup->rx_pin);
+		}
+
+next:
+		uup++;
+	}
+	return res;
+}
+
+/*
+ * ubi32_uarttio_cleanup
+ */
+static void ubi32_uarttio_cleanup(void)
+{
+	struct ubi32_uarttio_port *uup;
+	int i;
+
+	/*
+	 * Stop the hardware thread
+	 */
+	if (uarttio_inst.regs) {
+		thread_disable(uarttio_inst.regs->thread);
+	}
+	if (uarttio_inst.irq_requested) {
+		free_irq(uarttio_inst.irq, NULL);
+	}
+
+	/*
+	 * Get rid of the ports
+	 */
+	uup = uarttio_inst.ports;
+	for (i = 0; i < uarttio_nports; i++) {
+		gpio_free(uup->tx_pin);
+		gpio_free(uup->rx_pin);
+		if (uup->added) {
+			uart_remove_one_port(&ubi32_uarttio_uart_driver, &uup->port);
+		}
+		uup++;
+	}
+
+	if (uarttio_inst.driver_registered) {
+		uart_unregister_driver(&ubi32_uarttio_uart_driver);
+	}
+}
+
+/*
+ * ubi32_uarttio_setup_port
+ *	Setup a port in the TIO registers
+ */
+static int ubi32_uarttio_setup_port(int index,
+				    struct uarttio_uart *uart,
+				    unsigned int baud, unsigned int tx_pin, 
+				    unsigned int rx_pin)
+{
+	struct ubi32_uarttio_port *uup = &uarttio_ports[index];
+	void *tx_port = ubi_gpio_get_port(tx_pin);
+	void *rx_port = ubi_gpio_get_port(rx_pin);
+
+	/*
+	 * Verify the ports are on chip
+	 */
+	if (!tx_port || !rx_port) {
+		printk(KERN_WARNING "Invalid port(s) specified: %u or %u\n", tx_pin, rx_pin);
+		return -EINVAL;
+	}
+
+	uup->tx_pin = tx_pin;
+	uup->rx_pin = rx_pin;
+	uup->uart = uart;
+
+	/*
+	 * Setup the port structure
+	 */
+	uup->port.ops		= &ubi32_uarttio_pops;
+	uup->port.line		= index;
+	uup->port.iotype	= UPIO_MEM;
+	uup->port.flags		= UPF_BOOT_AUTOCONF;
+	uup->port.fifosize	= uup->uart->tx_fifo_size;
+	uup->port.private_data	= uup;
+
+	/*
+	 * We share this IRQ across all ports
+	 */
+	uup->port.irq		= uarttio_inst.irq;
+
+	/*
+	 * We really don't have a mem/map base but without these variables
+	 * set, the serial_core won't startup.
+	 */
+	uup->port.membase	= (void __iomem *)uup;
+	uup->port.mapbase	= (resource_size_t)uup;
+	spin_lock_init(&uup->port.lock);
+
+	/*
+	 * Set up the hardware
+	 */
+	uart->flags = UARTTIO_UART_FLAG_SET_RATE | UARTTIO_UART_FLAG_RESET;
+
+	uart->tx_port = (unsigned int)tx_port;
+	uart->tx_pin = gpio_pin_index(tx_pin);
+	uart->tx_bits = 8;
+	uart->tx_stop_bits = 1;
+
+	uart->rx_port = (unsigned int)rx_port;
+	uart->rx_pin = gpio_pin_index(rx_pin);
+	uart->rx_bits = 8;
+	uart->rx_stop_bits = 1;
+
+	uart->baud_rate = baud;
+
+	return 0;
+}
+
+enum ubi32_uarttio_parse_states {
+	UBI32_UARTTIO_PARSE_STATE_BAUD,
+	UBI32_UARTTIO_PARSE_STATE_TX_PIN,
+	UBI32_UARTTIO_PARSE_STATE_RX_PIN,
+	UBI32_UARTTIO_PARSE_STATE_HS,
+	UBI32_UARTTIO_PARSE_STATE_CTS_PIN,
+	UBI32_UARTTIO_PARSE_STATE_RTS_PIN,
+};
+
+/*
+ * ubi32_uarttio_parse_param
+ */
+static int ubi32_uarttio_parse_param(char *str)
+{
+	int res;
+	int i;
+	int baud = 0;
+	int tx_pin = 0;
+	int rx_pin = 0;
+	int hs = 0;
+	int cts_pin = 0;
+	int rts_pin = 0;
+	int nfound = 0;
+	enum ubi32_uarttio_parse_states state = UBI32_UARTTIO_PARSE_STATE_BAUD;
+	struct uarttio_uart *uart = uarttio_inst.regs->uarts;
+
+	/*
+	 * Run though the options and generate the proper structures
+	 */
+	res = get_option(&str, &i);
+	while ((res == 2) || (res == 1)) {
+		switch (state) {
+		case UBI32_UARTTIO_PARSE_STATE_BAUD:
+			/*
+			 * If we are here and nfound > 0 then create the port 
+			 * based on the previous input
+			 */
+			if (nfound) {
+				/*
+				 * Create the port
+				 */
+				if (ubi32_uarttio_setup_port(nfound - 1, uart, baud, tx_pin, rx_pin)) {
+					/*
+					 * Port was invalid
+					 */
+					goto fail;
+				} else {
+					printk(KERN_INFO "Serial port %d: tx=%d:rx=%d @ %d\n", nfound, tx_pin, rx_pin, baud);
+					uart++;
+				}
+			}
+
+			/*
+			 * Reset the variables and go to the next state
+			 */
+			hs = 0;
+			baud = i;
+			state = UBI32_UARTTIO_PARSE_STATE_TX_PIN;
+			break;
+
+		case UBI32_UARTTIO_PARSE_STATE_TX_PIN:
+			tx_pin = i;
+			state = UBI32_UARTTIO_PARSE_STATE_RX_PIN;
+			break;
+
+		case UBI32_UARTTIO_PARSE_STATE_RX_PIN:
+			rx_pin = i;
+			state = UBI32_UARTTIO_PARSE_STATE_HS;
+			break;
+
+		case UBI32_UARTTIO_PARSE_STATE_HS:
+			hs = i;
+			if (hs) {
+				state = UBI32_UARTTIO_PARSE_STATE_CTS_PIN;
+				break;
+			}
+
+			if (nfound == uarttio_inst.regs->max_uarts) {
+				printk(KERN_WARNING "Maximum number of serial ports reached\n");
+				goto done;
+			}
+			nfound++;
+			state = UBI32_UARTTIO_PARSE_STATE_BAUD;
+			break;
+
+		case UBI32_UARTTIO_PARSE_STATE_CTS_PIN:
+			cts_pin = i;
+			state = UBI32_UARTTIO_PARSE_STATE_RTS_PIN;
+			break;
+
+		case UBI32_UARTTIO_PARSE_STATE_RTS_PIN:
+			rts_pin = i;
+
+			if (nfound == uarttio_inst.regs->max_uarts) {
+				printk(KERN_WARNING "Maximum number of serial ports reached\n");
+				goto done;
+			}
+			nfound++;
+			state = UBI32_UARTTIO_PARSE_STATE_BAUD;
+			break;
+		}
+		res = get_option(&str, &i);
+	}
+
+	if ((res > 2) || state != UBI32_UARTTIO_PARSE_STATE_BAUD) {
+		printk(KERN_WARNING "Parameter syntax error.\n");
+		res = -EINVAL;
+		goto fail;
+	}
+
+	/*
+	 * Create the final port
+	 */
+	if (ubi32_uarttio_setup_port(nfound - 1, uart, baud, tx_pin, rx_pin)) {
+		goto fail;
+	}
+	printk(KERN_INFO "Serial port %d: tx=%d:rx=%d @ %d\n", nfound, tx_pin, rx_pin, baud);
+
+done:
+	uarttio_nports = nfound;
+
+	return nfound ? 0 : -ENODEV;
+
+fail:
+	/*
+	 * Reset the ports
+	 */
+	uart = uarttio_inst.regs->uarts;
+	for (i = 0; i < uarttio_inst.regs->max_uarts; i++) {
+		uart->flags = 0;
+		uart++;
+	}
+
+	return res;
+}
+
+/*
+ * ubi32_uarttio_probe
+ */
+static int ubi32_uarttio_probe(void)
+{
+	int ret;
+	struct uarttio_node *uart_node;
+	char *str = utio_ports_param;
+	static int probed;
+
+	/*
+	 * We only want to be probed once, we could be probed twice
+	 * for example if we are used as a console
+	 */
+	if (probed) {
+		return 0;
+	}
+	probed = 1;
+
+	/*
+	 * Extract the TIO name from the setup string
+	 */
+	while (*str) {
+		if (*str == ',') {
+			*str++ = 0;
+			break;
+		}
+		str++;
+	}
+
+	if (!*str) {
+		return -EINVAL;
+	}
+
+	uart_node = (struct uarttio_node *)devtree_find_node(utio_ports_param);
+	if (!uart_node) {
+		return -ENODEV;
+	}
+
+	uarttio_inst.irq = uart_node->dn.recvirq;
+	uarttio_inst.regs = uart_node->regs;
+
+	/*
+	 * Parse module parameters.
+	 */
+	ret = ubi32_uarttio_parse_param(str);
+	if (ret != 0) {
+		goto fail;
+	}
+
+	ubi32_uarttio_uart_driver.nr = uarttio_nports;
+
+	return 0;
+
+fail:
+	ubi32_uarttio_cleanup();
+	return ret;
+}
+
+#if defined(CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE)
+/*
+ * ubi32_uarttio_console_setup
+ */
+static int __init ubi32_uarttio_console_setup(struct console *co, char *options)
+{
+	int baud;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+	struct ubi32_uarttio_port *uup;
+
+	/*
+	 * Check whether an invalid uart number has been specified, and
+	 * if so, search for the first available port that does have
+	 * console support.
+	 */
+	if (co->index == -1 || co->index >= uarttio_nports) {
+		co->index = 0;
+	}
+	uup = &uarttio_ports[co->index];
+	baud = uup->uart->baud_rate;
+	uup->uart->flags |= UARTTIO_UART_FLAG_ENABLED;
+
+	/*
+	 * Setup the GPIOs
+	 *	We have to use the direct interface because the gpio
+	 *	subsystem is not available at this point.
+	 */
+	uup->port_init = 1;
+	UBICOM32_GPIO_SET_PIN_HIGH(uup->tx_pin);
+	UBICOM32_GPIO_SET_PIN_OUTPUT(uup->tx_pin);
+	UBICOM32_GPIO_SET_PIN_INPUT(uup->rx_pin);
+
+	/*
+	 * Start the thread
+	 */
+	thread_enable(uarttio_inst.regs->thread);
+
+	/*
+	 * Process options
+	 */
+	if (options) {
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+		if (ubi32_uarttio_set_baud(uup, baud)) {
+			baud = uup->uart->current_baud_rate;
+		}
+	}
+
+	return uart_set_options(&uup->port, co, baud, 'n', 8, 'n');
+}
+
+/*
+ * ubi32_uarttio_console_putchar
+ */
+static void ubi32_uarttio_console_putchar(struct uart_port *port, int ch)
+{
+	struct ubi32_uarttio_port *uup = port->private_data;
+
+	while (ubi32_uarttio_put_char(uup->uart, ch)) {
+		cpu_relax();
+	}
+}
+
+/*
+ * ubi32_uarttio_console_write
+ *	Interrupts are disabled on entering
+ */
+static void ubi32_uarttio_console_write(struct console *co, const char *s, unsigned int count)
+{
+	struct uart_port *port = &(uarttio_ports[co->index].port);
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&port->lock, flags);
+	uart_console_write(port, s, count, ubi32_uarttio_console_putchar);
+	spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static struct console ubi32_uarttio_console = {
+	.name		= UBI32_UARTTIO_NAME,
+	.write		= ubi32_uarttio_console_write,
+	.device		= uart_console_device,
+	.setup		= ubi32_uarttio_console_setup,
+	.flags		= CON_PRINTBUFFER,
+	.index		= -1,
+	.data		= &ubi32_uarttio_uart_driver,
+};
+
+static int __init ubi32_uarttio_console_init(void)
+{
+	int res;
+	
+	res = ubi32_uarttio_probe();
+	if (res) {
+		return res;
+	}
+
+	register_console(&ubi32_uarttio_console);
+	return 0;
+}
+console_initcall(ubi32_uarttio_console_init);
+#endif /* CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE */
+
+/*
+ * ubi32_serial_suspend
+ */
+static int ubi32_uarttio_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	int i;
+	for (i = 0; i < uarttio_nports; i++) {
+		uart_suspend_port(&ubi32_uarttio_uart_driver, &uarttio_ports[i].port);
+	}
+
+	return 0;
+}
+
+/*
+ * ubi32_serial_resume
+ */
+static int ubi32_uarttio_resume(struct platform_device *pdev)
+{
+	int i;
+	for (i = 0; i < uarttio_nports; i++) {
+		uart_resume_port(&ubi32_uarttio_uart_driver, &uarttio_ports[i].port);
+	}
+
+	return 0;
+}
+
+/*
+ * ubi32_uarttio_remove
+ */
+static int __devexit ubi32_uarttio_remove(struct platform_device *pdev)
+{
+	ubi32_uarttio_cleanup();
+
+	uart_unregister_driver(&ubi32_uarttio_uart_driver);
+
+	return 0;
+}
+
+static struct platform_driver ubi32_uarttio_platform_driver = {
+	.remove		= __devexit_p(ubi32_uarttio_remove),
+	.suspend	= ubi32_uarttio_suspend,
+	.resume		= ubi32_uarttio_resume,
+	.driver		= {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+};
+
+#ifndef MODULE
+/*
+ * Called at boot time.
+ *
+ * uarttio=TIONAME,(baud,tx_pin,rx_pin,handshake[,cts_pin,rts_pin],...)
+ *	TIONAME is the name of the devtree node which describes the UARTTIO
+ *	pin is the index of the pin, i.e. PA4 is 5 [(port * 32) + pin]
+ *	handshake = 1 to enable handshaking, provide cts_pin, rts_pin (UNSUPPORTED)
+ *	handshake = 0 to disable handshaking, do not provide cts_pin, rts_pin
+ *	Ex: uarttio=UARTTIO,57600,7,6,0,9600,8,9,0
+ */
+static int __init ubi32_uarttio_setup(char *str)
+{
+	strncpy(utio_ports_param, str, UBI32_UARTTIO_MAX_PARAM_LEN);
+	utio_ports_param[UBI32_UARTTIO_MAX_PARAM_LEN - 1] = 0;
+	return 1;
+}
+__setup("uarttio=", ubi32_uarttio_setup);
+#endif
+
+/*
+ * ubi32_uarttio_init
+ */
+static int __init ubi32_uarttio_init(void)
+{
+	int ret;
+	int i;
+
+	ret = ubi32_uarttio_probe();
+	if (ret) {
+		return ret;
+	}
+
+	/*
+	 * Request the IRQ (do it here since many ports share the same IRQ)
+	 */
+	ret = request_irq(uarttio_inst.irq, ubi32_uarttio_isr, IRQF_DISABLED, DRIVER_NAME, NULL);
+	if (ret != 0) {
+		printk(KERN_WARNING "Could not request IRQ %d\n", uarttio_inst.irq);
+		goto fail;
+	}
+	uarttio_inst.irq_requested = 1;
+
+	/*
+	 * Register the UART driver and add the ports
+	 */
+	ret = uart_register_driver(&ubi32_uarttio_uart_driver);
+	if (ret != 0) {
+		goto fail;
+	}
+	uarttio_inst.driver_registered = 1;
+
+	ret = ubi32_uarttio_add_ports();
+	if (ret != 0) {
+		ubi32_uarttio_cleanup();
+		return ret;
+	}
+
+	/*
+	 * Start the thread
+	 */
+	thread_enable(uarttio_inst.regs->thread);
+
+	for (i = 0; i < uarttio_nports; i++) {
+		pr_info("Serial: Ubicom32 uarttio #%d: tx:%d rx:%d baud:%d\n", 
+			i, uarttio_ports[i].tx_pin, uarttio_ports[i].rx_pin,
+			uarttio_ports[i].uart->current_baud_rate);
+	}
+	pr_info("Serial: Ubicom32 uarttio started on thread:%d irq:%d\n", uarttio_inst.regs->thread, uarttio_inst.irq);
+
+	return ret;
+
+fail:
+	ubi32_uarttio_cleanup();
+	return ret;
+}
+module_init(ubi32_uarttio_init);
+
+/*
+ * ubi32_uarttio_exit
+ */
+static void __exit ubi32_uarttio_exit(void)
+{
+	platform_driver_unregister(&ubi32_uarttio_platform_driver);
+}
+module_exit(ubi32_uarttio_exit);
+
+module_param_string(ports, utio_ports_param, sizeof(utio_ports_param), 0444);
+MODULE_PARM_DESC(ports, "Sets the ports to allocate: ports=TIONAME,(baud,txpin,rxpin,handshake[,ctspin,rtspin],...)\n"
+			"     TIONAME is the name of the devtree node which describes the UARTTIO\n"
+			"     pin is the index of the pin, i.e. PA4 is 5 [(port * 32) + pin]\n"
+			"     handshake = 1 to enable handshaking, provide ctspin, rtspin (UNSUPPORTED)\n"
+			"     handshake = 0 to disable handshaking, do not provide ctspin, rtspin\n"
+			"     Ex: ports=UARTTIO,57600,7,6,0,9600,8,9,0\n");
+MODULE_AUTHOR("Patrick Tjin <pat.tjin@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom serial virtual peripherial driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(UBI32_UARTTIO_MAJOR);
+MODULE_ALIAS("platform:" DRIVER_NAME);
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -196,6 +196,15 @@ config SPI_S3C24XX
 	help
 	  SPI driver for Samsung S3C24XX series ARM SoCs
 
+config SPI_UBICOM32_GPIO
+	tristate "Ubicom32 SPI over GPIO"
+	depends on SPI_MASTER && UBICOM32 && EXPERIMENTAL
+	select SPI_BITBANG
+	select HAS_DMA
+	help
+	  SPI driver for the Ubicom32 architecture using
+	  GPIO lines to provide the SPI bus.
+	  
 config SPI_S3C24XX_GPIO
 	tristate "Samsung S3C24XX series SPI by GPIO"
 	depends on ARCH_S3C2410 && EXPERIMENTAL
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SPI_ORION)			+= orion_spi.o
 obj-$(CONFIG_SPI_MPC52xx_PSC)		+= mpc52xx_psc_spi.o
 obj-$(CONFIG_SPI_MPC83xx)		+= spi_mpc83xx.o
 obj-$(CONFIG_SPI_S3C24XX_GPIO)		+= spi_s3c24xx_gpio.o
+obj-$(CONFIG_SPI_UBICOM32_GPIO)		+= spi_ubicom32_gpio.o
 obj-$(CONFIG_SPI_S3C24XX)		+= spi_s3c24xx.o
 obj-$(CONFIG_SPI_TXX9)			+= spi_txx9.o
 obj-$(CONFIG_SPI_XILINX)		+= xilinx_spi.o
--- /dev/null
+++ b/drivers/spi/spi_ubicom32_gpio.c
@@ -0,0 +1,268 @@
+/*
+ * drivers/spi_spi_ubicom32_gpio.c
+ *	Ubicom32 GPIO based SPI driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+
+#include <linux/spi/spi.h>
+#include <linux/spi/spi_bitbang.h>
+
+#include <linux/gpio.h>
+
+#include <asm/ip5000.h>
+#include <asm/ubicom32-spi-gpio.h>
+
+#define DRIVER_NAME "ubicom32-spi-gpio"
+
+struct ubicom32_spi_gpio {
+	struct spi_bitbang			 bitbang;
+
+	struct ubicom32_spi_gpio_platform_data	*pdata;
+
+	struct platform_device			*dev;
+};
+
+/*
+ * The following 4 functions are used by EXPAND_BITBANG_TXRX to bitbang the data out.
+ */
+static inline void setsck(struct spi_device *dev, int on)
+{
+	struct ubicom32_spi_gpio *usg = (struct ubicom32_spi_gpio *)spi_master_get_devdata(dev->master);
+	gpio_set_value(usg->pdata->pin_clk, on ? 1 : 0);
+}
+
+static inline void setmosi(struct spi_device *dev, int on)
+{
+	struct ubicom32_spi_gpio *usg = (struct ubicom32_spi_gpio *)spi_master_get_devdata(dev->master);
+	gpio_set_value(usg->pdata->pin_mosi, on ? 1 : 0);
+}
+
+static inline u32 getmiso(struct spi_device *dev)
+{
+	struct ubicom32_spi_gpio *usg = (struct ubicom32_spi_gpio *)spi_master_get_devdata(dev->master);
+	return gpio_get_value(usg->pdata->pin_miso) ? 1 : 0;
+}
+
+#define spidelay(x) ndelay(x)
+
+#define	EXPAND_BITBANG_TXRX
+#include <linux/spi/spi_bitbang.h>
+
+/*
+ * ubicom32_spi_gpio_txrx_mode0
+ */
+static u32 ubicom32_spi_gpio_txrx_mode0(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
+{
+	return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
+}
+
+/*
+ * ubicom32_spi_gpio_txrx_mode1
+ */
+static u32 ubicom32_spi_gpio_txrx_mode1(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
+{
+	return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
+}
+
+/*
+ * ubicom32_spi_gpio_txrx_mode2
+ */
+static u32 ubicom32_spi_gpio_txrx_mode2(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
+{
+	return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
+}
+
+/*
+ * ubicom32_spi_gpio_txrx_mode3
+ */
+static u32 ubicom32_spi_gpio_txrx_mode3(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
+{
+	return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
+}
+
+/*
+ * ubicom32_spi_gpio_chipselect
+ */
+static void ubicom32_spi_gpio_chipselect(struct spi_device *dev, int value)
+{
+	struct ubicom32_spi_gpio_controller_data *cd = (struct ubicom32_spi_gpio_controller_data *)dev->controller_data;
+	unsigned int cs_polarity = dev->mode & SPI_CS_HIGH ? 1 : 0;
+
+	if (value == BITBANG_CS_ACTIVE) {
+		gpio_set_value(cd->pin_cs, cs_polarity);
+		return;
+	}
+	gpio_set_value(cd->pin_cs, !cs_polarity);
+}
+
+/*
+ * ubicom32_spi_gpio_probe
+ */
+static int ubicom32_spi_gpio_probe(struct platform_device *dev)
+{
+	struct ubicom32_spi_gpio_platform_data *pdata;
+	struct spi_master *master;
+	struct ubicom32_spi_gpio *usg;
+	int ret;
+
+	master = spi_alloc_master(&dev->dev, sizeof(struct ubicom32_spi_gpio));
+	if (master == NULL) {
+		dev_err(&dev->dev, "failed to allocate spi master\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	usg = (struct ubicom32_spi_gpio *)spi_master_get_devdata(master);
+
+	platform_set_drvdata(dev, usg);
+
+	/* 
+	 * Copy in the platform data
+	 */
+	pdata = dev->dev.platform_data;
+	usg->pdata = dev->dev.platform_data;
+
+	/*
+	 * Request the GPIO lines
+	 */
+	ret = gpio_request(pdata->pin_mosi, "spi-mosi");
+	if (ret) {
+		dev_err(&dev->dev, "Failed to allocate spi-mosi GPIO\n");
+		goto err;
+	}
+
+	ret = gpio_request(pdata->pin_miso, "spi-miso");
+	if (ret) {
+		dev_err(&dev->dev, "Failed to allocate spi-miso GPIO\n");
+		goto err_nomiso;
+	}
+
+	ret = gpio_request(pdata->pin_clk, "spi-clk");
+	if (ret) {
+		dev_err(&dev->dev, "Failed to allocate spi-clk GPIO\n");
+		goto err_noclk;
+	}
+
+	/*
+	 * Setup spi-bitbang adaptor
+	 */
+	usg->bitbang.flags |= SPI_CS_HIGH;
+	usg->bitbang.master = spi_master_get(master);
+	usg->bitbang.master->bus_num = pdata->bus_num;
+	usg->bitbang.master->num_chipselect = pdata->num_chipselect;
+	usg->bitbang.chipselect = ubicom32_spi_gpio_chipselect;
+
+	usg->bitbang.txrx_word[SPI_MODE_0] = ubicom32_spi_gpio_txrx_mode0;
+	usg->bitbang.txrx_word[SPI_MODE_1] = ubicom32_spi_gpio_txrx_mode1;
+	usg->bitbang.txrx_word[SPI_MODE_2] = ubicom32_spi_gpio_txrx_mode2;
+	usg->bitbang.txrx_word[SPI_MODE_3] = ubicom32_spi_gpio_txrx_mode3;
+
+	/*
+	 * Setup the GPIO pins
+	 */
+	gpio_direction_output(pdata->pin_clk, pdata->clk_default);
+	gpio_direction_output(pdata->pin_mosi, 0);
+	gpio_direction_input(pdata->pin_miso);
+
+	/*
+	 * Ready to go
+	 */
+	ret = spi_bitbang_start(&usg->bitbang);
+	if (ret) {
+		goto err_no_bitbang;
+	}
+
+	return 0;
+
+err_no_bitbang:
+	spi_master_put(usg->bitbang.master);
+
+	gpio_free(pdata->pin_clk);
+
+err_noclk:
+	gpio_free(pdata->pin_miso);
+
+err_nomiso:
+	gpio_free(pdata->pin_mosi);
+
+err:
+	return ret;
+}
+
+/*
+ * ubicom32_spi_gpio_remove
+ */
+static int ubicom32_spi_gpio_remove(struct platform_device *dev)
+{
+	struct ubicom32_spi_gpio *sp = platform_get_drvdata(dev);
+
+	spi_bitbang_stop(&sp->bitbang);
+	spi_master_put(sp->bitbang.master);
+
+	return 0;
+}
+
+/*
+ * Work with hotplug and coldplug
+ */
+MODULE_ALIAS("platform:ubicom32_spi_gpio");
+
+static struct platform_driver ubicom32_spi_gpio_drv = {
+	.probe		= ubicom32_spi_gpio_probe,
+        .remove		= ubicom32_spi_gpio_remove,
+        .driver		= {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+        },
+};
+
+/*
+ * ubicom32_spi_gpio_init
+ */
+static int __init ubicom32_spi_gpio_init(void)
+{
+        return platform_driver_register(&ubicom32_spi_gpio_drv);
+}
+
+/*
+ * ubicom32_spi_gpio_exit
+ */
+static void __exit ubicom32_spi_gpio_exit(void)
+{
+        platform_driver_unregister(&ubicom32_spi_gpio_drv);
+}
+
+module_init(ubicom32_spi_gpio_init);
+module_exit(ubicom32_spi_gpio_exit);
+
+MODULE_DESCRIPTION("Ubicom32 SPI-GPIO Driver");
+MODULE_AUTHOR("Pat Tjin, <@ubicom.com>");
+MODULE_LICENSE("GPL");
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -71,4 +71,12 @@ config UIO_SERCOS3
 
 	  If you compile this as a module, it will be called uio_sercos3.
 
+config UIO_UBICOM32RING
+	tristate "Ubicom32 Ring Buffer driver"
+	default n
+	help
+	  Userspace I/O interface for a Ubicom32 Ring Buffer.
+
+	  If you compile this as a module, it will be called uio_ubicom32ring
+
 endif
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_UIO_PDRV)	+= uio_pdrv.o
 obj-$(CONFIG_UIO_PDRV_GENIRQ)	+= uio_pdrv_genirq.o
 obj-$(CONFIG_UIO_SMX)	+= uio_smx.o
 obj-$(CONFIG_UIO_SERCOS3)	+= uio_sercos3.o
+obj-$(CONFIG_UIO_UBICOM32RING)	+= uio_ubicom32ring.o
--- /dev/null
+++ b/drivers/uio/uio_ubicom32ring.c
@@ -0,0 +1,289 @@
+/*
+ * drivers/uio/uio_ubicom32ring.c
+ *
+ * Userspace I/O platform driver for Ubicom32 ring buffers
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * Based on uio_ubicom32ring.c by Magnus Damm
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/uio_driver.h>
+#include <linux/spinlock.h>
+#include <linux/bitops.h>
+#include <linux/interrupt.h>
+#include <linux/stringify.h>
+
+#include <asm/ip5000.h>
+#include <asm/ubicom32ring.h>
+
+#define DRIVER_NAME "uio_ubicom32ring"
+
+struct uio_ubicom32ring_data {
+	struct uio_info			*uioinfo;
+
+	struct uio_ubicom32ring_regs	*regs;
+
+	/*
+	 * IRQ used to kick the ring buffer
+	 */
+	int				irq_tx;
+	int				irq_rx;
+
+	spinlock_t			lock;
+
+	unsigned long			flags;
+
+	char				name[0];
+};
+
+static irqreturn_t uio_ubicom32ring_handler(int irq, struct uio_info *dev_info)
+{
+	struct uio_ubicom32ring_data *priv = dev_info->priv;
+
+	/* Just disable the interrupt in the interrupt controller, and
+	 * remember the state so we can allow user space to enable it later.
+	 */
+
+	if (!test_and_set_bit(0, &priv->flags))
+		disable_irq_nosync(irq);
+
+	return IRQ_HANDLED;
+}
+
+static int uio_ubicom32ring_irqcontrol(struct uio_info *dev_info, s32 irq_on)
+{
+	struct uio_ubicom32ring_data *priv = dev_info->priv;
+	unsigned long flags;
+
+	/* Allow user space to enable and disable the interrupt
+	 * in the interrupt controller, but keep track of the
+	 * state to prevent per-irq depth damage.
+	 *
+	 * Serialize this operation to support multiple tasks.
+	 */
+
+	spin_lock_irqsave(&priv->lock, flags);
+
+	if (irq_on & 2) {
+		/*
+		 * Kick the ring buffer (if we can)
+		 */
+		if (priv->irq_tx != 0xFF) {
+			ubicom32_set_interrupt(priv->irq_tx);
+		}
+	}
+	
+	if (priv->irq_rx != 0xFF) {
+		if (irq_on & 1) {
+			if (test_and_clear_bit(0, &priv->flags))
+				enable_irq(dev_info->irq);
+		} else {
+			if (!test_and_set_bit(0, &priv->flags))
+				disable_irq(dev_info->irq);
+		}
+	}
+
+	spin_unlock_irqrestore(&priv->lock, flags);
+
+	return 0;
+}
+
+static int uio_ubicom32ring_probe(struct platform_device *pdev)
+{
+	struct uio_info *uioinfo;
+	struct uio_mem *uiomem;
+	struct uio_ubicom32ring_data *priv;
+	struct uio_ubicom32ring_regs *regs;
+	struct resource *mem_resource;
+	struct resource *irqtx_resource;
+	struct resource *irqrx_resource;
+	int ret = -EINVAL;
+	int i;
+
+	uioinfo = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
+	if (!uioinfo) {
+		dev_err(&pdev->dev, "unable to kmalloc\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * Allocate private data with some string space after
+	 */
+	i = sizeof(DRIVER_NAME) + 1;
+	i += pdev->dev.platform_data ? strlen(pdev->dev.platform_data) : 0;
+	priv = kzalloc(sizeof(struct uio_ubicom32ring_data) + i, GFP_KERNEL);
+	if (!priv) {
+		dev_err(&pdev->dev, "unable to kmalloc\n");
+		kfree(uioinfo);
+		return -ENOMEM;
+	}
+
+	strcpy(priv->name, DRIVER_NAME ":");
+	if (pdev->dev.platform_data) {
+		strcat(priv->name, pdev->dev.platform_data);
+	}
+	uioinfo->priv = priv;
+	uioinfo->name = priv->name;
+	uioinfo->version = "0.1";
+
+	priv->uioinfo = uioinfo;
+	spin_lock_init(&priv->lock);
+	priv->flags = 0; /* interrupt is enabled to begin with */
+
+	/*
+	 * Get our resources, the IRQ_TX and IRQ_RX are optional.
+	 */
+	priv->irq_tx = 0xFF;
+	irqtx_resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (irqtx_resource) {
+		priv->irq_tx = irqtx_resource->start;
+	}
+
+	uioinfo->irq = -1;
+	priv->irq_rx = 0xFF;
+	irqrx_resource = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
+	if (irqrx_resource) {
+		priv->irq_rx = irqrx_resource->start;
+		uioinfo->irq = priv->irq_rx;
+		uioinfo->handler = uio_ubicom32ring_handler;
+	}
+
+	mem_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!mem_resource || !mem_resource->start) {
+		dev_err(&pdev->dev, "No valid memory resource found\n");
+		ret = -ENODEV;
+		goto fail;
+	}
+	regs = (struct uio_ubicom32ring_regs *)mem_resource->start;
+	priv->regs = regs;
+
+	if (regs->version != UIO_UBICOM32RING_REG_VERSION) {
+		dev_err(&pdev->dev, "version %d not supported\n", regs->version);
+		ret = -ENODEV;
+		goto fail;
+	}
+
+	/*
+	 * First range is the shared register space, if we have any
+	 */
+	uiomem = &uioinfo->mem[0];
+	if (regs->regs_size) {
+		uiomem->memtype = UIO_MEM_PHYS;
+		uiomem->addr = (u32_t)regs->regs;
+		uiomem->size = regs->regs_size;
+		++uiomem;
+		dev_info(&pdev->dev, "regs:%p (%u) / rings: %d found\n", regs->regs, regs->regs_size, regs->num_rings);
+	} else {
+		dev_info(&pdev->dev, "rings: %d found\n", regs->num_rings);
+	}
+
+	/*
+	 * The rest of the range correspond to the rings
+	 */
+	for (i = 0; i < regs->num_rings; i++) {
+		dev_info(&pdev->dev, "\t%d: entries:%d ring:%p\n", 
+			 i, regs->rings[i]->entries, &(regs->rings[i]->ring));
+		if (uiomem >= &uioinfo->mem[MAX_UIO_MAPS]) {
+			dev_warn(&pdev->dev, "device has more than "
+					__stringify(MAX_UIO_MAPS)
+					" I/O memory resources.\n");
+			break;
+		}
+
+		uiomem->memtype = UIO_MEM_PHYS;
+		uiomem->addr = (u32_t)&(regs->rings[i]->head);
+		uiomem->size = (regs->rings[i]->entries * sizeof(u32_t)) + 
+				sizeof(struct uio_ubicom32ring_desc);
+		++uiomem;
+	}
+
+	while (uiomem < &uioinfo->mem[MAX_UIO_MAPS]) {
+		uiomem->size = 0;
+		++uiomem;
+	}
+
+	/* This driver requires no hardware specific kernel code to handle
+	 * interrupts. Instead, the interrupt handler simply disables the
+	 * interrupt in the interrupt controller. User space is responsible
+	 * for performing hardware specific acknowledge and re-enabling of
+	 * the interrupt in the interrupt controller.
+	 *
+	 * Interrupt sharing is not supported.
+	 */
+	uioinfo->irq_flags = IRQF_DISABLED;
+	uioinfo->irqcontrol = uio_ubicom32ring_irqcontrol;
+
+	ret = uio_register_device(&pdev->dev, priv->uioinfo);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to register uio device\n");
+		goto fail;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	dev_info(&pdev->dev, "'%s' using irq: rx %d tx %d, regs %p\n", 
+		 priv->name, priv->irq_rx, priv->irq_tx, priv->regs);
+
+	return 0;
+
+fail:
+	kfree(uioinfo);
+	kfree(priv);
+	return ret;
+}
+
+static int uio_ubicom32ring_remove(struct platform_device *pdev)
+{
+	struct uio_ubicom32ring_data *priv = platform_get_drvdata(pdev);
+
+	uio_unregister_device(priv->uioinfo);
+	kfree(priv->uioinfo);
+	kfree(priv);
+	return 0;
+}
+
+static struct platform_driver uio_ubicom32ring = {
+	.probe = uio_ubicom32ring_probe,
+	.remove = uio_ubicom32ring_remove,
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+
+static int __init uio_ubicom32ring_init(void)
+{
+	return platform_driver_register(&uio_ubicom32ring);
+}
+
+static void __exit uio_ubicom32ring_exit(void)
+{
+	platform_driver_unregister(&uio_ubicom32ring);
+}
+
+module_init(uio_ubicom32ring_init);
+module_exit(uio_ubicom32ring_exit);
+
+MODULE_AUTHOR("Patrick Tjin");
+MODULE_DESCRIPTION("Userspace I/O driver for Ubicom32 ring buffers");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" DRIVER_NAME);
+
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -154,6 +154,10 @@ ep_matches (
 			/* configure your hardware with enough buffering!! */
 		}
 		break;
+	
+	case USB_ENDPOINT_XFER_BULK:
+		if ((gadget->is_dualspeed) && (ep->maxpacket < 512))
+			return 0;
 	}
 
 	/* MATCH!! */
@@ -174,7 +178,7 @@ ep_matches (
 			return 0;
 		desc->bEndpointAddress |= epnum;
 	}
-
+	
 	/* report (variable) full speed bulk maxpacket */
 	if (USB_ENDPOINT_XFER_BULK == type) {
 		int size = ep->maxpacket;
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -22,6 +22,7 @@ config USB_ARCH_HAS_HCD
 	default y if PCMCIA && !M32R			# sl811_cs
 	default y if ARM				# SL-811
 	default y if SUPERH				# r8a66597-hcd
+	default y if UBICOM32				# Ubicom's onchip USB Duial role controller
 	default PCI
 
 # many non-PCI SOC chips embed OHCI
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -11,7 +11,7 @@ config USB_MUSB_HDRC
 	depends on (USB || USB_GADGET) && HAVE_CLK
 	depends on !SUPERH
 	select TWL4030_USB if MACH_OMAP_3430SDP
-	tristate 'Inventra Highspeed Dual Role Controller (TI, ...)'
+	tristate 'Inventra Highspeed Dual Role Controller (TI, Ubicom, ...)'
 	help
 	  Say Y here if your system has a dual role high speed USB
 	  controller based on the Mentor Graphics silicon IP.  Then
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -22,6 +22,10 @@ ifeq ($(CONFIG_ARCH_OMAP3430),y)
 	musb_hdrc-objs	+= omap2430.o
 endif
 
+ifeq ($(CONFIG_UBICOM32), y)
+        musb_hdrc-objs  += ubi32_usb.o
+endif
+
 ifeq ($(CONFIG_USB_GADGET_MUSB_HDRC),y)
 	musb_hdrc-objs		+= musb_gadget_ep0.o musb_gadget.o
 endif
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -105,6 +105,13 @@
 #include <asm/mach-types.h>
 #endif
 
+#ifdef CONFIG_UBICOM32
+#include <asm/ip5000.h>
+#include <asm/ubicom32-tio.h>
+extern void ubi32_usb_init(void);
+extern void ubi32_usb_int_clr(void);
+#endif
+
 #include "musb_core.h"
 
 
@@ -147,7 +154,7 @@ static inline struct musb *dev_to_musb(s
 }
 
 /*-------------------------------------------------------------------------*/
-
+#ifndef CONFIG_UBICOM32
 #ifndef CONFIG_USB_TUSB6010
 /*
  * Load an endpoint's FIFO
@@ -226,8 +233,38 @@ void musb_read_fifo(struct musb_hw_ep *h
 		readsb(fifo, dst, len);
 	}
 }
+#endif /* T6010 */
+#else /* UBICOM */
+
+/*
+ * Load an endpoint's FIFO
+ */
+void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 wCount, const u8 *pSource)
+{
+	void __iomem *fifo = hw_ep->fifo;
+
+	prefetch((u8 *)pSource);
+
+	DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
+			'T', hw_ep->epnum, fifo, wCount, pSource);
+
+	usb_tio_write_fifo((u32)fifo, (u32)pSource, wCount);
+
+}
 
-#endif	/* normal PIO */
+
+/*
+ * Unload an endpoint's FIFO
+ */
+void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 wCount, u8 *pDest)
+{
+
+	void __iomem *fifo = hw_ep->fifo;
+	DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
+			'R', hw_ep->epnum, fifo, wCount, pDest);
+	usb_tio_read_fifo((u32)fifo, (u32)pDest, wCount);
+}
+#endif /* CONFIG_UBICOM32 */
 
 
 /*-------------------------------------------------------------------------*/
@@ -872,12 +909,19 @@ void musb_start(struct musb *musb)
 	musb_writeb(regs, MUSB_TESTMODE, 0);
 
 	/* put into basic highspeed mode and start session */
+#ifndef CONFIG_UBICOM32
 	musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
 						| MUSB_POWER_SOFTCONN
 						| MUSB_POWER_HSENAB
 						/* ENSUSPEND wedges tusb */
 						/* | MUSB_POWER_ENSUSPEND */
 						);
+#else
+	musb_writeb(regs, MUSB_POWER,  MUSB_POWER_HSENAB
+						/* ENSUSPEND wedges tusb */
+						/* | MUSB_POWER_ENSUSPEND */
+						);
+#endif
 
 	musb->is_active = 0;
 	devctl = musb_readb(regs, MUSB_DEVCTL);
@@ -1079,6 +1123,7 @@ static struct fifo_cfg __initdata mode_4
 };
 
 
+#ifndef CONFIG_UBICOM32
 /*
  * configure a fifo; for non-shared endpoints, this may be called
  * once for a tx fifo and once for an rx fifo.
@@ -1238,7 +1283,7 @@ static int __init ep_config_from_table(s
 
 	return 0;
 }
-
+#endif /* CONFIG_UBICOM32 */
 
 /*
  * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
@@ -1253,13 +1298,23 @@ static int __init ep_config_from_hw(stru
 	DBG(2, "<== static silicon ep config\n");
 
 	/* FIXME pick up ep0 maxpacket size */
+#ifdef CONFIG_UBICOM32
+	/* set ep0 to shared_fifo, otherwise urb will be put to out_qh but ep0_irq try to get the urb from in_qh*/
+	hw_ep = musb->endpoints;
+	hw_ep->is_shared_fifo = true;
+#endif
 
 	for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
 		musb_ep_select(mbase, epnum);
 		hw_ep = musb->endpoints + epnum;
 
 		/* read from core using indexed model */
+#ifndef CONFIG_UBICOM32
 		reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE);
+#else
+		reg = musb_readb(musb->mregs, 0x10 + MUSB_FIFOSIZE);
+#endif
+
 		if (!reg) {
 			/* 0's returned when no more endpoints */
 			break;
@@ -1272,8 +1327,10 @@ static int __init ep_config_from_hw(stru
 		/* shared TX/RX FIFO? */
 		if ((reg & 0xf0) == 0xf0) {
 			hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx;
-			hw_ep->is_shared_fifo = true;
-			continue;
+			hw_ep->is_shared_fifo = true;			
+#ifndef CONFIG_UBICOM32
+			continue; /* For ubicom processors, shared ep is all we get */
+#endif
 		} else {
 			hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4);
 			hw_ep->is_shared_fifo = false;
@@ -1290,17 +1347,30 @@ static int __init ep_config_from_hw(stru
 		/* REVISIT:  this algorithm is lazy, we should at least
 		 * try to pick a double buffered endpoint.
 		 */
+#ifndef CONFIG_UBICOM32
 		if (musb->bulk_ep)
 			continue;
 		musb->bulk_ep = hw_ep;
+#else
+		if ((musb->bulk_ep_in) && (musb->bulk_ep_out))
+			continue;
+		/* Save theEP with 1024 Bytes FIFO for ISO */
+		if(hw_ep->max_packet_sz_tx == 512) {
+			if (!musb->bulk_ep_in) {
+				musb->bulk_ep_in = hw_ep;
+			} else if (!musb->bulk_ep_out) {
+				musb->bulk_ep_out = hw_ep;
+			}
+		}
+#endif /* CONFIG_UBICOM32 */
 #endif
 	}
 
 #ifdef CONFIG_USB_MUSB_HDRC_HCD
-	if (!musb->bulk_ep) {
+	if ((!musb->bulk_ep_in) || (!musb->bulk_ep_out)) {
 		pr_debug("%s: missing bulk\n", musb_driver_name);
 		return -EINVAL;
-	}
+	}	
 #endif
 
 	return 0;
@@ -1408,12 +1478,16 @@ static int __init musb_core_init(u16 mus
 	musb->epmask = 1;
 
 	if (reg & MUSB_CONFIGDATA_DYNFIFO) {
+#ifndef CONFIG_UBICOM32
 		if (musb->config->dyn_fifo)
 			status = ep_config_from_table(musb);
-		else {
+		else
+#endif
+		{
 			ERR("reconfigure software for Dynamic FIFOs\n");
 			status = -ENODEV;
 		}
+
 	} else {
 		if (!musb->config->dyn_fifo)
 			status = ep_config_from_hw(musb);
@@ -1477,8 +1551,8 @@ static int __init musb_core_init(u16 mus
 
 /*-------------------------------------------------------------------------*/
 
-#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
-
+#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_UBICOM32)
+static u32_t musb_int_count = 0;
 static irqreturn_t generic_interrupt(int irq, void *__hci)
 {
 	unsigned long	flags;
@@ -1487,10 +1561,17 @@ static irqreturn_t generic_interrupt(int
 
 	spin_lock_irqsave(&musb->lock, flags);
 
+#ifndef CONFIG_UBICOM32
 	musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
 	musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
 	musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
+#else
+	musb_read_int_status(&musb->int_usb, &musb->int_tx, &musb->int_rx);
+	//ubi32_usb_int_clr();
+	musb_int_count++;
+#endif
 
+	DBG(4, "usb %x, tx %x, rx %x", musb->int_usb, musb->int_tx, musb->int_rx);
 	if (musb->int_usb || musb->int_tx || musb->int_rx)
 		retval = musb_interrupt(musb);
 
@@ -2222,6 +2303,10 @@ static struct platform_driver musb_drive
 
 static int __init musb_init(void)
 {
+#ifdef CONFIG_UBICOM32
+	ubi32_usb_init();
+#endif
+
 #ifdef CONFIG_USB_MUSB_HDRC_HCD
 	if (usb_disabled())
 		return 0;
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -326,7 +326,9 @@ struct musb {
 	 * queue until it completes or NAKs too much; then we try the next
 	 * endpoint.
 	 */
-	struct musb_hw_ep	*bulk_ep;
+	//struct musb_hw_ep	*bulk_ep;
+	struct musb_hw_ep	*bulk_ep_in;	//ubicom
+	struct musb_hw_ep	*bulk_ep_out;
 
 	struct list_head	control;	/* of musb_qh */
 	struct list_head	in_bulk;	/* of musb_qh */
@@ -467,7 +469,7 @@ extern void musb_platform_disable(struct
 
 extern void musb_hnp_stop(struct musb *musb);
 
-extern void musb_platform_set_mode(struct musb *musb, u8 musb_mode);
+extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode);
 
 #if defined(CONFIG_USB_TUSB6010) || \
 	defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -421,7 +421,7 @@ void musb_g_tx(struct musb *musb, u8 epn
 		 * probably rates reporting as a host error
 		 */
 		if (csr & MUSB_TXCSR_P_SENTSTALL) {
-			csr |= MUSB_TXCSR_P_WZC_BITS;
+			csr &= ~(MUSB_TXCSR_P_WZC_BITS);
 			csr &= ~MUSB_TXCSR_P_SENTSTALL;
 			musb_writew(epio, MUSB_TXCSR, csr);
 			if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
@@ -437,7 +437,7 @@ void musb_g_tx(struct musb *musb, u8 epn
 
 		if (csr & MUSB_TXCSR_P_UNDERRUN) {
 			/* we NAKed, no big deal ... little reason to care */
-			csr |= MUSB_TXCSR_P_WZC_BITS;
+			csr &= ~(MUSB_TXCSR_P_WZC_BITS);
 			csr &= ~(MUSB_TXCSR_P_UNDERRUN
 					| MUSB_TXCSR_TXPKTRDY);
 			musb_writew(epio, MUSB_TXCSR, csr);
@@ -573,10 +573,16 @@ static void rxstate(struct musb *musb, s
 	u16			csr = 0;
 	const u8		epnum = req->epnum;
 	struct usb_request	*request = &req->request;
-	struct musb_ep		*musb_ep = &musb->endpoints[epnum].ep_out;
+	struct musb_ep		*musb_ep = NULL;
 	void __iomem		*epio = musb->endpoints[epnum].regs;
 	u16			fifo_count = 0;
-	u16			len = musb_ep->packet_sz;
+	u16			len = 0;
+	
+	if (musb->endpoints[epnum].is_shared_fifo)
+		musb_ep = &musb->endpoints[epnum].ep_in;
+	else
+		musb_ep = &musb->endpoints[epnum].ep_out;
+	len =  musb_ep->packet_sz;
 
 	csr = musb_readw(epio, MUSB_RXCSR);
 
@@ -715,7 +721,7 @@ static void rxstate(struct musb *musb, s
 			 */
 
 			/* ack the read! */
-			csr |= MUSB_RXCSR_P_WZC_BITS;
+			csr &= ~MUSB_RXCSR_P_WZC_BITS;
 			csr &= ~MUSB_RXCSR_RXPKTRDY;
 			musb_writew(epio, MUSB_RXCSR, csr);
 		}
@@ -734,10 +740,15 @@ void musb_g_rx(struct musb *musb, u8 epn
 	u16			csr;
 	struct usb_request	*request;
 	void __iomem		*mbase = musb->mregs;
-	struct musb_ep		*musb_ep = &musb->endpoints[epnum].ep_out;
+	struct musb_ep		*musb_ep = NULL;
 	void __iomem		*epio = musb->endpoints[epnum].regs;
 	struct dma_channel	*dma;
 
+	if (musb->endpoints[epnum].is_shared_fifo)
+		musb_ep = &musb->endpoints[epnum].ep_in;
+	else
+		musb_ep = &musb->endpoints[epnum].ep_out;
+	
 	musb_ep_select(mbase, epnum);
 
 	request = next_request(musb_ep);
@@ -1559,7 +1570,7 @@ init_peripheral_ep(struct musb *musb, st
 	ep->is_in = is_in;
 
 	INIT_LIST_HEAD(&ep->req_list);
-
+	
 	sprintf(ep->name, "ep%d%s", epnum,
 			(!epnum || hw_ep->is_shared_fifo) ? "" : (
 				is_in ? "in" : "out"));
@@ -1758,7 +1769,9 @@ int usb_gadget_register_driver(struct us
 			}
 		}
 	}
-
+#ifndef CONFIG_USB_MUSB_OTG
+	musb_pullup(musb, 1);
+#endif
 	return retval;
 }
 EXPORT_SYMBOL(usb_gadget_register_driver);
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -240,14 +240,14 @@ __acquires(musb->lock)
 		case USB_REQ_SET_ADDRESS:
 			/* change it after the status stage */
 			musb->set_address = true;
-			musb->address = (u8) (ctrlrequest->wValue & 0x7f);
+			musb->address = (u8) (le16_to_cpu(ctrlrequest->wValue) & 0x7f);
 			handled = 1;
 			break;
 
 		case USB_REQ_CLEAR_FEATURE:
 			switch (recip) {
 			case USB_RECIP_DEVICE:
-				if (ctrlrequest->wValue
+				if (le16_to_cpu(ctrlrequest->wValue)
 						!= USB_DEVICE_REMOTE_WAKEUP)
 					break;
 				musb->may_wakeup = 0;
@@ -261,8 +261,8 @@ __acquires(musb->lock)
 
 				if (num == 0
 						|| num >= MUSB_C_NUM_EPS
-						|| ctrlrequest->wValue
-							!= USB_ENDPOINT_HALT)
+						|| le16_to_cpu(ctrlrequest->wValue
+							!= USB_ENDPOINT_HALT))
 					break;
 
 				if (ctrlrequest->wIndex & USB_DIR_IN)
@@ -292,7 +292,7 @@ __acquires(musb->lock)
 			switch (recip) {
 			case USB_RECIP_DEVICE:
 				handled = 1;
-				switch (ctrlrequest->wValue) {
+				switch (le16_to_cpu(ctrlrequest->wValue)) {
 				case USB_DEVICE_REMOTE_WAKEUP:
 					musb->may_wakeup = 1;
 					break;
@@ -374,8 +374,8 @@ stall:
 
 				if (epnum == 0
 						|| epnum >= MUSB_C_NUM_EPS
-						|| ctrlrequest->wValue
-							!= USB_ENDPOINT_HALT)
+						|| le16_to_cpu(ctrlrequest->wValue
+							!= USB_ENDPOINT_HALT))
 					break;
 
 				ep = musb->endpoints + epnum;
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -139,7 +139,11 @@ static inline void musb_h_tx_start(struc
 	/* NOTE: no locks here; caller should lock and select EP */
 	if (ep->epnum) {
 		txcsr = musb_readw(ep->regs, MUSB_TXCSR);
-		txcsr |= MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_H_WZC_BITS;
+#ifndef CONFIG_UBICOM32
+		txcsr |= MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_H_WZC_BITS; 
+#else
+		txcsr |= (MUSB_TXCSR_TXPKTRDY & (~MUSB_TXCSR_H_WZC_BITS)); 
+#endif
 		musb_writew(ep->regs, MUSB_TXCSR, txcsr);
 	} else {
 		txcsr = MUSB_CSR0_H_SETUPPKT | MUSB_CSR0_TXPKTRDY;
@@ -198,8 +202,11 @@ musb_start_urb(struct musb *musb, int is
 		len = urb->iso_frame_desc[0].length;
 		break;
 	default:		/* bulk, interrupt */
-		buf = urb->transfer_buffer;
-		len = urb->transfer_buffer_length;
+		/* actual_length may be nonzero on retry paths */
+		if (urb->actual_length) 
+			DBG(3 ,"musb_start_urb: URB %p retried, len: %d\n", urb, urb->actual_length);
+		buf = urb->transfer_buffer + urb->actual_length;
+		len = urb->transfer_buffer_length - urb->actual_length;
 	}
 
 	DBG(4, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n",
@@ -318,13 +325,13 @@ musb_save_toggle(struct musb_hw_ep *ep, 
 	if (!is_in) {
 		csr = musb_readw(epio, MUSB_TXCSR);
 		usb_settoggle(udev, qh->epnum, 1,
-			(csr & MUSB_TXCSR_H_DATATOGGLE)
-				? 1 : 0);
+			((csr & MUSB_TXCSR_H_DATATOGGLE)
+				? 1 : 0));
 	} else {
 		csr = musb_readw(epio, MUSB_RXCSR);
 		usb_settoggle(udev, qh->epnum, 0,
-			(csr & MUSB_RXCSR_H_DATATOGGLE)
-				? 1 : 0);
+			((csr & MUSB_RXCSR_H_DATATOGGLE)
+				? 1 : 0));
 	}
 }
 
@@ -337,9 +344,11 @@ musb_giveback(struct musb_qh *qh, struct
 	struct musb		*musb = ep->musb;
 	int			ready = qh->is_ready;
 
+#ifndef CONFIG_UBICOM32 /* BUG! */
 	if (ep->is_shared_fifo)
 		is_in = 1;
 	else
+#endif
 		is_in = usb_pipein(urb->pipe);
 
 	/* save toggle eagerly, for paranoia */
@@ -538,7 +547,11 @@ musb_host_packet_rx(struct musb *musb, s
 	musb_read_fifo(hw_ep, length, buf);
 
 	csr = musb_readw(epio, MUSB_RXCSR);
+#ifndef CONFIG_UBICOM32
 	csr |= MUSB_RXCSR_H_WZC_BITS;
+#else
+	csr &= ~MUSB_RXCSR_H_WZC_BITS;
+#endif
 	if (unlikely(do_flush))
 		musb_h_flush_rxfifo(hw_ep, csr);
 	else {
@@ -572,14 +585,24 @@ musb_rx_reinit(struct musb *musb, struct
 
 	/* if programmed for Tx, put it in RX mode */
 	if (ep->is_shared_fifo) {
+#ifndef  CONFIG_UBICOM32
 		csr = musb_readw(ep->regs, MUSB_TXCSR);
 		if (csr & MUSB_TXCSR_MODE) {
 			musb_h_tx_flush_fifo(ep);
 			musb_writew(ep->regs, MUSB_TXCSR,
 					MUSB_TXCSR_FRCDATATOG);
 		}
+#else 
 		/* clear mode (and everything else) to enable Rx */
 		musb_writew(ep->regs, MUSB_TXCSR, 0);
+		/* scrub all previous state, clearing toggle */
+		csr = musb_readw(ep->regs, MUSB_RXCSR);
+		if (csr & MUSB_RXCSR_RXPKTRDY)
+			WARNING("rx%d, packet/%d ready?\n", ep->epnum,
+				musb_readw(ep->regs, MUSB_RXCOUNT));
+
+		musb_h_flush_rxfifo(ep, MUSB_RXCSR_CLRDATATOG);
+#endif
 
 	/* scrub all previous state, clearing toggle */
 	} else {
@@ -680,7 +703,7 @@ static void musb_ep_program(struct musb 
 			/* ASSERT:  TXCSR_DMAENAB was already cleared */
 
 			/* flush all old state, set default */
-			musb_h_tx_flush_fifo(hw_ep);
+				musb_h_tx_flush_fifo(hw_ep);
 			csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
 					| MUSB_TXCSR_DMAMODE
 					| MUSB_TXCSR_FRCDATATOG
@@ -1169,8 +1192,18 @@ void musb_host_tx(struct musb *musb, u8 
 	void __iomem		*mbase = musb->mregs;
 	struct dma_channel	*dma;
 
+#ifdef CONFIG_UBICOM32
+	if (hw_ep->is_shared_fifo) {
+		qh = hw_ep->in_qh;
+	}
+#ifdef CONFIG_USB_SERIAL_SIERRAWIRELESS
+	printk(KERN_DEBUG "OUT/TX%d end, csr %04x%s\n", epnum, tx_csr,
+			dma ? ", dma" : "");
+#endif
+#endif
 	urb = next_urb(qh);
 
+
 	musb_ep_select(mbase, epnum);
 	tx_csr = musb_readw(epio, MUSB_TXCSR);
 
@@ -1210,9 +1243,14 @@ void musb_host_tx(struct musb *musb, u8 
 		 * we have a candidate... NAKing is *NOT* an error
 		 */
 		musb_ep_select(mbase, epnum);
+#ifndef CONFIG_UBICOM32
 		musb_writew(epio, MUSB_TXCSR,
 				MUSB_TXCSR_H_WZC_BITS
 				| MUSB_TXCSR_TXPKTRDY);
+#else
+		musb_writew(epio, MUSB_TXCSR,
+				 MUSB_TXCSR_TXPKTRDY);
+#endif
 		goto finish;
 	}
 
@@ -1316,8 +1354,14 @@ void musb_host_tx(struct musb *musb, u8 
 		qh->segsize = wLength;
 
 		musb_ep_select(mbase, epnum);
+#ifndef CONFIG_UBICOM32
 		musb_writew(epio, MUSB_TXCSR,
-				MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY);
+				 MUSB_TXCSR_MODE | MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY);
+#else
+	 musb_writew(epio, MUSB_TXCSR,
+                                 MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY);
+#endif
+
 	} else
 		DBG(1, "not complete, but dma enabled?\n");
 
@@ -1365,6 +1409,49 @@ finish:
 
 #endif
 
+/* Schedule next QH from musb->in_bulk and move the current qh to
+ * the end; avoids starvation for other endpoints.
+ */
+static void musb_bulk_rx_nak_timeout(struct musb *musb, struct musb_hw_ep *ep)
+{
+	struct dma_channel	*dma;
+	struct urb		*urb;
+	void __iomem		*mbase = musb->mregs;
+	void __iomem		*epio = ep->regs;
+	struct musb_qh		*cur_qh, *next_qh;
+	u16			rx_csr;
+
+	musb_ep_select(mbase, ep->epnum);
+	dma = is_dma_capable() ? ep->rx_channel : NULL;
+	/* clear nak timeout bit */
+	rx_csr = musb_readw(epio, MUSB_RXCSR);
+	rx_csr &= ~MUSB_RXCSR_H_WZC_BITS;
+	rx_csr &= ~MUSB_RXCSR_DATAERROR;
+	musb_writew(epio, MUSB_RXCSR, rx_csr);
+
+	cur_qh = first_qh(&musb->in_bulk);
+	if (cur_qh) {
+		urb = next_urb(cur_qh);
+		if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
+			dma->status = MUSB_DMA_STATUS_CORE_ABORT;
+			musb->dma_controller->channel_abort(dma);
+			urb->actual_length += dma->actual_len;
+			dma->actual_len = 0L;
+		}
+		musb_save_toggle(ep, 1, urb);
+
+		/* move cur_qh to end of queue */
+		list_move_tail(&cur_qh->ring, &musb->in_bulk);
+
+		/* get the next qh from musb->in_bulk */
+		next_qh = first_qh(&musb->in_bulk);
+
+		/* set rx_reinit and schedule the next qh */
+		ep->rx_reinit = 1;
+		musb_start_urb(musb, 1, next_qh);
+	}
+}
+
 /*
  * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
  * and high-bandwidth IN transfer cases.
@@ -1383,7 +1470,7 @@ void musb_host_rx(struct musb *musb, u8 
 	bool			done = false;
 	u32			status;
 	struct dma_channel	*dma;
-
+	
 	musb_ep_select(mbase, epnum);
 
 	urb = next_urb(qh);
@@ -1407,6 +1494,13 @@ void musb_host_rx(struct musb *musb, u8 
 
 	pipe = urb->pipe;
 
+#ifdef CONFIG_UBICOM32
+#ifdef CONFIG_USB_SERIAL_SIERRAWIRELESS
+		printk(KERN_DEBUG  "RXCSR%d %04x, reqpkt, len %zu%s\n", epnum, rx_csr,
+				xfer_len, dma ? ", dma" : "");
+#endif
+#endif
+
 	DBG(5, "<== hw %d rxcsr %04x, urb actual %d (+dma %zu)\n",
 		epnum, rx_csr, urb->actual_length,
 		dma ? dma->actual_len : 0);
@@ -1428,18 +1522,30 @@ void musb_host_rx(struct musb *musb, u8 
 	} else if (rx_csr & MUSB_RXCSR_DATAERROR) {
 
 		if (USB_ENDPOINT_XFER_ISOC != qh->type) {
-			/* NOTE this code path would be a good place to PAUSE a
-			 * transfer, if there's some other (nonperiodic) rx urb
-			 * that could use this fifo.  (dma complicates it...)
+			DBG(6, "RX end %d NAK timeout\n", epnum);
+
+			/* NOTE: NAKing is *NOT* an error, so we want to
+			 * continue.  Except ... if there's a request for
+			 * another QH, use that instead of starving it.
 			 *
-			 * if (bulk && qh->ring.next != &musb->in_bulk), then
-			 * we have a candidate... NAKing is *NOT* an error
+			 * Devices like Ethernet and serial adapters keep
+			 * reads posted at all times, which will starve
+			 * other devices without this logic.
 			 */
-			DBG(6, "RX end %d NAK timeout\n", epnum);
+			if (usb_pipebulk(urb->pipe)
+					&& qh->mux == 1
+					&& !list_is_singular(&musb->in_bulk)) {
+				musb_bulk_rx_nak_timeout(musb, hw_ep);
+				return;
+			}
 			musb_ep_select(mbase, epnum);
+#ifndef CONFIG_UBICOM32
 			musb_writew(epio, MUSB_RXCSR,
 					MUSB_RXCSR_H_WZC_BITS
 					| MUSB_RXCSR_H_REQPKT);
+#else
+			musb_writew(epio, MUSB_RXCSR, (~(MUSB_RXCSR_H_WZC_BITS))| MUSB_RXCSR_H_REQPKT);
+#endif
 
 			goto finish;
 		} else {
@@ -1495,8 +1601,13 @@ void musb_host_rx(struct musb *musb, u8 
 		rx_csr &= ~MUSB_RXCSR_H_REQPKT;
 
 		musb_ep_select(mbase, epnum);
+#ifndef CONFIG_UBICOM32
 		musb_writew(epio, MUSB_RXCSR,
 				MUSB_RXCSR_H_WZC_BITS | rx_csr);
+#else
+		musb_writew(epio, MUSB_RXCSR,
+				(~MUSB_RXCSR_H_WZC_BITS) & rx_csr);
+#endif
 	}
 #endif
 	if (dma && (rx_csr & MUSB_RXCSR_DMAENAB)) {
@@ -1526,7 +1637,7 @@ void musb_host_rx(struct musb *musb, u8 
 			else
 				done = false;
 
-		} else  {
+		} else {
 		/* done if urb buffer is full or short packet is recd */
 		done = (urb->actual_length + xfer_len >=
 				urb->transfer_buffer_length
@@ -1743,8 +1854,12 @@ static int musb_schedule(
 		if (musb->periodic[epnum])
 			continue;
 		hw_ep = &musb->endpoints[epnum];
+#ifndef CONFIG_UBICOM32
 		if (hw_ep == musb->bulk_ep)
-			continue;
+#else
+		if ((hw_ep == musb->bulk_ep_in) || (hw_ep == musb->bulk_ep_out)) /* Ubicom */	
+#endif
+			continue; 
 
 		if (is_in)
 			diff = hw_ep->max_packet_sz_rx - qh->maxpacket;
@@ -1756,7 +1871,14 @@ static int musb_schedule(
 			best_end = epnum;
 		}
 	}
+
+#ifdef CONFIG_UBICOM32
+	if (((best_diff >= qh->maxpacket)) && ((qh->type == USB_ENDPOINT_XFER_BULK) && (!is_in)))
+		best_end = -1;
+#endif
+
 	/* use bulk reserved ep1 if no other ep is free */
+#ifndef CONFIG_UBICOM32
 	if (best_end < 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
 		hw_ep = musb->bulk_ep;
 		if (is_in)
@@ -1767,6 +1889,22 @@ static int musb_schedule(
 	} else if (best_end < 0) {
 		return -ENOSPC;
 	}
+#else
+	if (best_end < 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
+		/* hw_ep = musb->bulk_ep; */
+		if (is_in) {
+			head = &musb->in_bulk;
+			hw_ep = musb->bulk_ep_in; /* UBICOM */
+		}
+		else {
+			head = &musb->out_bulk;
+			hw_ep = musb->bulk_ep_out; /* UBICOM */
+		}
+		goto success;
+	} else if (best_end < 0) {
+		return -ENOSPC;
+	}
+#endif
 
 	idle = 1;
 	qh->mux = 0;
@@ -1779,6 +1917,13 @@ success:
 		list_add_tail(&qh->ring, head);
 		qh->mux = 1;
 	}
+	/*
+	 * It's not make sense to set NAK timeout when qh->mux = 0,
+	 * There is nothing else to schedule
+ 	 */
+	if ((qh->type == USB_ENDPOINT_XFER_BULK) && (qh->mux == 0))
+		qh->intv_reg = 0;
+
 	qh->hw_ep = hw_ep;
 	qh->hep->hcpriv = qh;
 	if (idle)
@@ -1884,6 +2029,15 @@ static int musb_urb_enqueue(
 	case USB_ENDPOINT_XFER_ISOC:
 		/* iso always uses log encoding */
 		break;
+#ifdef COMFIG_UBICOM32
+	case USB_ENDPOINT_XFER_BULK:
+		 if (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
+			interval = (USB_SPEED_HIGH == urb->dev->speed) ? 16: 2;
+ 		 else
+			interval = 0;
+		 break;
+#endif
+	
 	default:
 		/* REVISIT we actually want to use NAK limits, hinting to the
 		 * transfer scheduling logic to try some other qh, e.g. try
--- a/drivers/usb/musb/musb_io.h
+++ b/drivers/usb/musb/musb_io.h
@@ -56,6 +56,7 @@ static inline void writesb(const void __
 
 #endif
 
+#ifndef CONFIG_UBICOM32
 /* NOTE:  these offsets are all in bytes */
 
 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
@@ -70,7 +71,37 @@ static inline void musb_writew(void __io
 
 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
 	{ __raw_writel(data, addr + offset); }
+#else
+#include <asm/ubicom32-tio.h>
+static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
+{
+        u16 data;
+        usb_tio_read_u16((u32)(addr + offset), &data);
+        return data;
+}
 
+static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
+{
+        u8 data;
+        usb_tio_read_u8((u32)(addr + offset), &data);
+        return data;
+}
+
+static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
+{
+        usb_tio_write_u16((u32)(addr + offset), data);
+}
+
+static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
+{
+        usb_tio_write_u8((u32)(addr + offset), data);
+}
+
+static inline void  musb_read_int_status(u8_t *int_usb, u16_t *int_tx, u16_t *int_rx)
+{
+	return usb_tio_read_int_status(int_usb, int_tx, int_rx);
+}
+#endif /* CONFIG_UBICOM32 */
 
 #ifdef CONFIG_USB_TUSB6010
 
@@ -104,7 +135,7 @@ static inline void musb_writeb(void __io
 	__raw_writew(tmp, addr + (offset & ~1));
 }
 
-#else
+#elif !defined(CONFIG_UBICOM32)
 
 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
 	{ return __raw_readb(addr + offset); }
--- /dev/null
+++ b/drivers/usb/musb/ubi32_usb.c
@@ -0,0 +1,156 @@
+/*
+ * drivers/usb/musb/ubi32_usb.c
+ *   Ubicom32 usb controller driver.
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ * Copyright (C) 2005-2006 by Texas Instruments
+ *
+ * Derived from the Texas Instruments Inventra Controller Driver for Linux.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <asm/io.h>
+#include <asm/ip5000.h>
+#include "musb_core.h"
+
+void musb_platform_enable(struct musb *musb)
+{
+}
+void musb_platform_disable(struct musb *musb)
+{
+}
+
+int musb_platform_set_mode(struct musb *musb, u8 musb_mode) {
+	return 0;
+}
+
+static void ip5k_usb_hcd_vbus_power(struct musb *musb, int is_on, int sleeping)
+{
+}
+
+static void ip5k_usb_hcd_set_vbus(struct musb *musb, int is_on)
+{
+	u8		devctl;
+	/* HDRC controls CPEN, but beware current surges during device
+	 * connect.  They can trigger transient overcurrent conditions
+	 * that must be ignored.
+	 */
+
+	devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+
+	if (is_on) {
+		musb->is_active = 1;
+		musb->xceiv.default_a = 1;
+		musb->xceiv.state = OTG_STATE_A_WAIT_VRISE;
+		devctl |= MUSB_DEVCTL_SESSION;
+
+		MUSB_HST_MODE(musb);
+	} else {
+		musb->is_active = 0;
+
+		/* NOTE:  we're skipping A_WAIT_VFALL -> A_IDLE and
+		 * jumping right to B_IDLE...
+		 */
+
+		musb->xceiv.default_a = 0;
+		musb->xceiv.state = OTG_STATE_B_IDLE;
+		devctl &= ~MUSB_DEVCTL_SESSION;
+
+		MUSB_DEV_MODE(musb);
+	}
+	musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
+
+	DBG(1, "VBUS %s, devctl %02x "
+		/* otg %3x conf %08x prcm %08x */ "\n",
+		otg_state_string(musb),
+		musb_readb(musb->mregs, MUSB_DEVCTL));
+}
+static int ip5k_usb_hcd_set_power(struct otg_transceiver *x, unsigned mA)
+{
+	return 0;
+}
+
+static int musb_platform_resume(struct musb *musb);
+
+int __init musb_platform_init(struct musb *musb)
+{
+
+#ifdef CONFIG_UBICOM32_V4
+	u32_t chip_id;
+	asm volatile (
+		      "move.4	%0, CHIP_ID	\n\t"
+		      : "=r" (chip_id)
+	);
+	if (chip_id == 0x30001) {
+		*((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 30);
+		udelay(1);
+		*((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 31);
+	} else {
+		*((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 17);
+		udelay(1);
+		*((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 14);
+	}
+#endif
+
+	 *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_CFG)) |= ((1 << 14) | (1 <<15));
+
+	/* The i-clk is AUTO gated. Hence there is no need
+	 * to disable it until the driver is shutdown */
+
+	clk_enable(musb->clock);
+	musb_platform_resume(musb);
+
+	ip5k_usb_hcd_vbus_power(musb, musb->board_mode == MUSB_HOST, 1);
+
+	if (is_host_enabled(musb))
+		musb->board_set_vbus = ip5k_usb_hcd_set_vbus;
+	if (is_peripheral_enabled(musb))
+		musb->xceiv.set_power = ip5k_usb_hcd_set_power;
+
+	return 0;
+}
+
+
+int musb_platform_suspend(struct musb *musb)
+{
+	return 0;
+}
+int musb_platform_resume(struct musb *musb)
+{
+	return 0;
+}
+
+int musb_platform_exit(struct musb *musb)
+{
+	ip5k_usb_hcd_vbus_power(musb, 0 /*off*/, 1);
+	musb_platform_suspend(musb);
+	return 0;
+}
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -84,6 +84,14 @@ config LCD_TOSA
 	  If you have an Sharp SL-6000 Zaurus say Y to enable a driver
 	  for its LCD.
 
+config LCD_UBICOM32
+	tristate "Ubicom Backlight Driver"
+	depends on LCD_CLASS_DEVICE && UBICOM32
+	default n
+	help
+	  If you have a Ubicom32 based system with an LCD panel, say Y to enable
+	  the power control driver for it.
+
 #
 # Backlight
 #
@@ -214,3 +222,11 @@ config BACKLIGHT_SAHARA
 	help
 	  If you have a Tabletkiosk Sahara Touch-iT, say y to enable the
 	  backlight driver.
+
+config BACKLIGHT_UBICOM32
+	tristate "Ubicom Backlight Driver"
+	depends on BACKLIGHT_CLASS_DEVICE && UBICOM32
+	default n
+	help
+	  If you have a Ubicom32 based system with a backlight say Y to enable the
+	  backlight driver.
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -8,6 +8,8 @@ obj-$(CONFIG_LCD_PLATFORM)	   += platfor
 obj-$(CONFIG_LCD_VGG2432A4)	   += vgg2432a4.o
 obj-$(CONFIG_LCD_TDO24M)	   += tdo24m.o
 obj-$(CONFIG_LCD_TOSA)		   += tosa_lcd.o
+obj-$(CONFIG_LCD_LTV350QV)	   += ltv350qv.o
+obj-$(CONFIG_LCD_UBICOM32)	   += ubicom32lcd.o
 
 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
 obj-$(CONFIG_BACKLIGHT_ATMEL_PWM)    += atmel-pwm-bl.o
@@ -22,4 +24,4 @@ obj-$(CONFIG_BACKLIGHT_DA903X)	+= da903x
 obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
 obj-$(CONFIG_BACKLIGHT_TOSA)	+= tosa_bl.o
 obj-$(CONFIG_BACKLIGHT_SAHARA)	+= kb3886_bl.o
-
+obj-$(CONFIG_BACKLIGHT_UBICOM32) += ubicom32bl.o
--- /dev/null
+++ b/drivers/video/backlight/ubicom32bl.c
@@ -0,0 +1,378 @@
+/*
+ * drivers/video/backlight/ubicom32bl.c
+ *	Backlight driver for the Ubicom32 platform
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+
+#include <asm/ubicom32bl.h>
+#include <asm/ip5000.h>
+
+#define DRIVER_NAME			"ubicom32bl"
+#define UBICOM32BL_MAX_BRIGHTNESS	255
+
+struct ubicom32bl_data {
+	/*
+	 * Pointer to the platform data structure.  Keep this around since we need values
+	 * from it to set the backlight intensity.
+	 */
+	const struct ubicom32bl_platform_data	*pdata;
+
+	/*
+	 * Backlight device, we have to save this for use when we remove ourselves.
+	 */
+	struct backlight_device			*bldev;
+
+	/*
+	 * Current intensity, used for get_intensity.
+	 */
+	int					cur_intensity;
+
+	/*
+	 * Init function for PWM
+	 */
+	int (*init_fn)(struct ubicom32bl_data *);
+
+	/*
+	 * Set intensity function depending on the backlight type
+	 */
+	int (*set_intensity_fn)(struct ubicom32bl_data *, int);
+};
+
+/*
+ * ubicom32bl_set_intensity_gpio
+ */
+static int ubicom32bl_set_intensity_gpio(struct ubicom32bl_data *ud, int intensity)
+{
+	ud->cur_intensity = intensity ? 255 : 0;
+
+	if (intensity) {
+		// set gpio
+		return 0;
+	}
+
+	// clear gpio
+	return 0;
+}
+
+/*
+ * ubicom32bl_set_intensity_hw
+ */
+static int ubicom32bl_set_intensity_hw(struct ubicom32bl_data *ud, int intensity)
+{
+	u16_t period = ud->pdata->pwm_period;
+	u16_t duty;
+
+	/*
+	 * Calculate the new duty cycle
+	 */
+	duty = (period * intensity) / (UBICOM32BL_MAX_BRIGHTNESS + 1);
+
+	/*
+	 * Set the new duty cycle
+	 */
+	switch (ud->pdata->pwm_channel) {
+	case 0:
+		/*
+		 * Channel 0 is in the lower half of PORT C ctl0 and ctl1
+		 */
+		UBICOM32_IO_PORT(RC)->ctl1 = (ud->pdata->pwm_period << 16) | duty;
+		break;
+
+	case 1:
+		/*
+		 * Channel 1 is in the upper half of PORT C ctl0 and ctl2
+		 */
+		UBICOM32_IO_PORT(RC)->ctl2 = (ud->pdata->pwm_period << 16) | duty;
+		break;
+
+	case 2:
+		/*
+		 * Channel 2 is in PORT H ctl0 and ctl1
+		 */
+		UBICOM32_IO_PORT(RH)->ctl1 = (ud->pdata->pwm_period << 16) | duty;
+		break;
+	}
+
+	ud->cur_intensity = intensity;
+
+	return 0;
+}
+
+/*
+ * ubicom32bl_set_intensity
+ */
+static int ubicom32bl_set_intensity(struct backlight_device *bd)
+{
+	struct ubicom32bl_data *ud = (struct ubicom32bl_data *)bl_get_data(bd);
+	int intensity = bd->props.brightness;
+
+	/*
+	 * If we're blanked the the intensity doesn't matter.
+	 */
+	if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
+		intensity = 0;
+	}
+
+	/*
+	 * Check for inverted backlight.
+	 */
+	if (ud->pdata->invert) {
+		intensity = UBICOM32BL_MAX_BRIGHTNESS - intensity;
+	}
+
+	if (ud->set_intensity_fn) {
+		return ud->set_intensity_fn(ud, intensity);
+	}
+
+	return -ENXIO;
+}
+
+/*
+ * ubicom32bl_get_intensity
+ *	Return the current intensity of the backlight.
+ */
+static int ubicom32bl_get_intensity(struct backlight_device *bd)
+{
+	struct ubicom32bl_data *ud = (struct ubicom32bl_data *)bl_get_data(bd);
+
+	return ud->cur_intensity;
+}
+
+/*
+ * ubicom32bl_init_hw_pwm
+ *	Set the appropriate PWM registers
+ */
+static int ubicom32bl_init_hw_pwm(struct ubicom32bl_data *ud)
+{
+	/*
+	 * bit 13: enable
+	 */
+	u16_t pwm_cfg = (1 << 13) | (ud->pdata->pwm_prescale << 8) ;
+
+	switch (ud->pdata->pwm_channel) {
+	case 0:
+		/*
+		 * Channel 0 is in the lower half of PORT C ctl0 and ctl1
+		 */
+		UBICOM32_IO_PORT(RC)->ctl0 &= ~0xFFFF;
+		UBICOM32_IO_PORT(RC)->ctl0 |= pwm_cfg;
+		UBICOM32_IO_PORT(RC)->ctl1 = ud->pdata->pwm_period << 16;
+		break;
+
+	case 1:
+		/*
+		 * Channel 1 is in the upper half of PORT C ctl0 and ctl2
+		 */
+		UBICOM32_IO_PORT(RC)->ctl0 &= ~0xFFFF0000;
+		UBICOM32_IO_PORT(RC)->ctl0 |= (pwm_cfg << 16);
+		UBICOM32_IO_PORT(RC)->ctl2 = ud->pdata->pwm_period << 16;
+		break;
+
+	case 2:
+		/*
+		 * Channel 2 is in PORT H ctl0 and ctl1
+		 */
+		UBICOM32_IO_PORT(RH)->ctl0 &= ~0xFFFF0000;
+		UBICOM32_IO_PORT(RH)->ctl0 = pwm_cfg;
+		UBICOM32_IO_PORT(RH)->ctl1 = ud->pdata->pwm_period << 16;
+		break;
+	}
+
+	return 0;
+}
+
+/*
+ * ubicom32bl_init_gpio
+ *	Allocate the appropriate GPIO
+ */
+static int ubicom32bl_init_gpio(struct ubicom32bl_data *ud)
+{
+	return 0;
+}
+
+static struct backlight_ops ubicom32bl_ops = {
+	.get_brightness = ubicom32bl_get_intensity,
+	.update_status  = ubicom32bl_set_intensity,
+};
+
+/*
+ * ubicom32bl_probe
+ */
+static int ubicom32bl_probe(struct platform_device *pdev)
+{
+	const struct ubicom32bl_platform_data *pdata = pdev->dev.platform_data;
+	struct ubicom32bl_data *ud;
+	struct backlight_device *bldev;
+	int retval;
+
+	/*
+	 * Check to see if we have any platform data, if we don't then the backlight is not
+	 * configured on this device.
+	 */
+	if (!pdata) {
+		return -ENODEV;
+	}
+
+	/*
+	 * Allocate our private data
+	 */
+	ud = kzalloc(sizeof(struct ubicom32bl_data), GFP_KERNEL);
+	if (!ud) {
+		return -ENOMEM;
+	}
+
+	ud->pdata = pdata;
+
+	/*
+	 * Check to see that the platform data is valid for this driver
+	 */
+	switch (pdata->type) {
+	case UBICOM32BL_TYPE_PWM: 
+		{
+			/*
+			 * Make sure we have a PWM peripheral
+			 */
+			u32_t chipid;
+			asm volatile (
+				"move.4         %0, CHIP_ID     \n\t"
+				: "=r" (chipid)
+			);
+			if (chipid != 0x00030001) {
+				retval = -ENODEV;
+				goto fail;
+			}
+
+			if (pdata->pwm_channel > 3) {
+				retval = -ENODEV;
+				goto fail;
+			}
+			if (pdata->pwm_prescale > 16) {
+				retval = -EINVAL;
+				goto fail;
+			}
+
+			ud->init_fn = ubicom32bl_init_hw_pwm;
+			ud->set_intensity_fn = ubicom32bl_set_intensity_hw;
+			break;
+		}
+
+	case UBICOM32BL_TYPE_PWM_HRT:
+		// For now, PWM HRT devices are treated as binary lights.
+
+	case UBICOM32BL_TYPE_BINARY:
+		ud->init_fn = ubicom32bl_init_gpio;
+		ud->set_intensity_fn = ubicom32bl_set_intensity_gpio;
+		break;
+	}
+
+	/*
+	 * Register our backlight device
+	 */
+	bldev = backlight_device_register(DRIVER_NAME, &pdev->dev, ud, &ubicom32bl_ops);
+	if (IS_ERR(bldev)) {
+		retval = PTR_ERR(bldev);
+		goto fail;
+	}
+
+	ud->bldev = bldev;
+	ud->cur_intensity = pdata->default_intensity;
+	platform_set_drvdata(pdev, ud);
+
+	/* 
+	 * Start up the backlight at the prescribed default intensity
+	 */
+	bldev->props.power = FB_BLANK_UNBLANK;
+	bldev->props.max_brightness = UBICOM32BL_MAX_BRIGHTNESS;
+	bldev->props.brightness = pdata->default_intensity;
+
+	if (ud->init_fn) {
+		if (ud->init_fn(ud) != 0) {
+			retval = -ENODEV;
+			backlight_device_unregister(ud->bldev);
+			goto fail;
+		}
+	}
+	ubicom32bl_set_intensity(bldev);
+
+	printk(KERN_INFO DRIVER_NAME ": Backlight driver started\n");
+
+	return 0;
+
+fail:
+	platform_set_drvdata(pdev, NULL);
+	kfree(ud);
+	return retval;
+}
+
+/*
+ * ubicom32bl_remove
+ */
+static int __exit ubicom32bl_remove(struct platform_device *pdev)
+{
+	struct ubicom32bl_data *ud = platform_get_drvdata(pdev);
+
+	backlight_device_unregister(ud->bldev);
+	platform_set_drvdata(pdev, NULL);
+	kfree(ud);
+
+	return 0;
+}
+
+static struct platform_driver ubicom32bl_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+
+	.remove = __exit_p(ubicom32bl_remove),
+};
+
+/*
+ * ubicom32bl_init
+ */
+static int __init ubicom32bl_init(void)
+{
+	return platform_driver_probe(&ubicom32bl_driver, ubicom32bl_probe);
+}
+module_init(ubicom32bl_init);
+
+/*
+ * ubicom32bl_exit
+ */
+static void __exit ubicom32bl_exit(void)
+{
+	platform_driver_unregister(&ubicom32bl_driver);
+}
+module_exit(ubicom32bl_exit);
+
+MODULE_AUTHOR("Patrick Tjin <@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom32 backlight driver");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/drivers/video/backlight/ubicom32lcd.c
@@ -0,0 +1,194 @@
+/*
+ * drivers/vdeio/backlight/ubicom32lcd.c
+ *	LCD driver for the Ubicom32 platform
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/lcd.h>
+#include <linux/fb.h>
+#include <linux/gpio.h>
+
+#include <asm/ubicom32lcd.h>
+#include <asm/ip5000.h>
+
+#define DRIVER_NAME			"ubicom32lcd"
+
+struct ubicom32lcd_data {
+	/*
+	 * Pointer to the platform data structure.  Keep this around since we need values
+	 * from it to set the backlight intensity.
+	 */
+	const struct ubicom32lcd_platform_data	*pdata;
+
+	/*
+	 * LCD device, we have to save this for use when we remove ourselves.
+	 */
+	struct lcd_device			*lcddev;
+};
+
+/*
+ * ubicom32lcd_set_power
+ */
+static int ubicom32lcd_set_power(struct lcd_device *ld, int power)
+{
+	struct ubicom32lcd_data *ud = (struct ubicom32lcd_data *)lcd_get_data(ld);
+	if (power == FB_BLANK_UNBLANK) {
+		gpio_direction_output(ud->pdata->vgh_gpio, ud->pdata->vgh_polarity);
+		return 0;
+	}
+
+	gpio_direction_output(ud->pdata->vgh_gpio, !ud->pdata->vgh_polarity);
+	return 0;
+}
+
+/*
+ * ubicom32lcd_get_power
+ */
+static int ubicom32lcd_get_power(struct lcd_device *ld)
+{
+	struct ubicom32lcd_data *ud = (struct ubicom32lcd_data *)lcd_get_data(ld);
+	int vgh = gpio_get_value(ud->pdata->vgh_gpio);
+	if ((vgh && ud->pdata->vgh_polarity) || (!vgh && !ud->pdata->vgh_polarity)) {
+		return 1;
+	}
+
+	return 0;
+}
+
+static struct lcd_ops ubicom32lcd_ops = {
+	.get_power = ubicom32lcd_get_power,
+	.set_power = ubicom32lcd_set_power,
+};
+
+/*
+ * ubicom32lcd_probe
+ */
+static int ubicom32lcd_probe(struct platform_device *pdev)
+{
+	const struct ubicom32lcd_platform_data *pdata = pdev->dev.platform_data;
+	struct ubicom32lcd_data *ud;
+	struct lcd_device *lcddev;
+	int retval;
+
+	/*
+	 * Check to see if we have any platform data, if we don't have a LCD to control
+	 */
+	if (!pdata) {
+		return -ENODEV;
+	}
+
+	/*
+	 * Allocate our private data
+	 */
+	ud = kzalloc(sizeof(struct ubicom32lcd_data), GFP_KERNEL);
+	if (!ud) {
+		return -ENOMEM;
+	}
+
+	ud->pdata = pdata;
+
+	/*
+	 * Request our GPIOs
+	 */
+	retval = gpio_request(pdata->vgh_gpio, "vgh");
+	if (retval) {
+		dev_err(&pdev->dev, "Failed to allocate vgh GPIO\n");
+		goto fail_gpio;
+	}
+
+	/*
+	 * Register our lcd device
+	 */
+	lcddev = lcd_device_register(DRIVER_NAME, &pdev->dev, ud, &ubicom32lcd_ops);
+	if (IS_ERR(lcddev)) {
+		retval = PTR_ERR(lcddev);
+		goto fail;
+	}
+
+	ud->lcddev = lcddev;
+	platform_set_drvdata(pdev, ud);
+
+	ubicom32lcd_set_power(lcddev, FB_BLANK_UNBLANK);
+
+	printk(KERN_INFO DRIVER_NAME ": LCD driver started\n");
+
+	return 0;
+
+fail:
+	gpio_free(pdata->vgh_gpio);
+
+fail_gpio:
+	platform_set_drvdata(pdev, NULL);
+	kfree(ud);
+	return retval;
+}
+
+/*
+ * ubicom32lcd_remove
+ */
+static int __exit ubicom32lcd_remove(struct platform_device *pdev)
+{
+	struct ubicom32lcd_data *ud = platform_get_drvdata(pdev);
+
+	lcd_device_unregister(ud->lcddev);
+	platform_set_drvdata(pdev, NULL);
+	kfree(ud);
+
+	return 0;
+}
+
+static struct platform_driver ubicom32lcd_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+
+	.remove = __exit_p(ubicom32lcd_remove),
+};
+
+/*
+ * ubicom32lcd_init
+ */
+static int __init ubicom32lcd_init(void)
+{
+	return platform_driver_probe(&ubicom32lcd_driver, ubicom32lcd_probe);
+}
+module_init(ubicom32lcd_init);
+
+/*
+ * ubicom32lcd_exit
+ */
+static void __exit ubicom32lcd_exit(void)
+{
+	platform_driver_unregister(&ubicom32lcd_driver);
+}
+module_exit(ubicom32lcd_exit);
+
+MODULE_AUTHOR("Patrick Tjin <@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom32 backlight driver");
+MODULE_LICENSE("GPL");
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -609,6 +609,25 @@ config FB_BFIN_T350MCQB
 	 This display is a QVGA 320x240 24-bit RGB display interfaced by an 8-bit wide PPI
 	 It uses PPI[0..7] PPI_FS1, PPI_FS2 and PPI_CLK.
 
+config FB_UBICOM32
+	tristate "Ubicom32 Frame Buffer driver"
+	depends on FB && UBICOM32
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
+	select FONT_6x11 if FRAMEBUFFER_CONSOLE
+	help
+	 This is the framebuffer device driver for the Ubicom32 architecture.
+
+config FB_UBICOM32_VIRTUAL
+	tristate "Ubicom32 Virtual Frame Buffer driver"
+	depends on FB && UBICOM32
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
+	select FONT_6x11 if FRAMEBUFFER_CONSOLE
+	help
+	 This is a virtual framebuffer device driver for the Ubicom32 architecture.
 
 config FB_STI
 	tristate "HP STI frame buffer device support"
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -132,6 +132,7 @@ obj-$(CONFIG_FB_VGA16)            += vga
 obj-$(CONFIG_FB_OF)               += offb.o
 obj-$(CONFIG_FB_BF54X_LQ043)	  += bf54x-lq043fb.o
 obj-$(CONFIG_FB_BFIN_T350MCQB)	  += bfin-t350mcqb-fb.o
+obj-$(CONFIG_FB_UBICOM32)         += ubicom32fb.o
 
 # the test framebuffer is last
 obj-$(CONFIG_FB_VIRTUAL)          += vfb.o
--- /dev/null
+++ b/drivers/video/ubicom32fb.c
@@ -0,0 +1,777 @@
+/*
+ * drivers/video/ubicom32fb.c
+ *	Ubicom32 frame buffer driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+/*
+ * This driver was based on skeletonfb.c, Skeleton for a frame buffer device by
+ * Geert Uytterhoeven.
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/fb.h>
+#include <linux/init.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/device.h>
+#include <linux/uaccess.h>
+#include <linux/interrupt.h>
+
+#include <asm/io.h>
+#include <asm/ip5000.h>
+#include <asm/vdc_tio.h>
+#include <asm/ubicom32fb.h>
+
+#define DRIVER_NAME		"ubicom32fb"
+#define DRIVER_DESCRIPTION	"Ubicom32 frame buffer driver"
+
+#define PALETTE_ENTRIES_NO	16
+
+/*
+ * Option variables
+ *
+ * vram_size:	VRAM size in kilobytes, subject to alignment 
+ */
+static int vram_size = 0;
+module_param(vram_size, int, 0);
+MODULE_PARM_DESC(vram, "VRAM size, in kilobytes to allocate, should be at least the size of one screen, subject to alignment");
+static int init_value = 0;
+module_param(init_value, int, 0);
+MODULE_PARM_DESC(init, "Initial value of the framebuffer (16-bit number).");
+
+/*
+ * fb_fix_screeninfo defines the non-changeable properties of the VDC, depending on what mode it is in.
+ */
+static struct fb_fix_screeninfo ubicom32fb_fix = {
+	.id =		"Ubicom32",
+	.type =		FB_TYPE_PACKED_PIXELS,
+	.visual =	FB_VISUAL_TRUECOLOR,
+	.accel =	FB_ACCEL_NONE
+};
+
+/*
+ * Filled in at probe time when we find out what the hardware supports
+ */
+static struct fb_var_screeninfo ubicom32fb_var;
+
+/*
+ * Private data structure
+ */
+struct ubicom32fb_drvdata {
+	struct fb_info			*fbinfo;
+	bool				cmap_alloc;
+
+	/*
+	 * The address of the framebuffer in memory
+	 */
+	void				*fb;
+	void				*fb_aligned;
+
+	/*
+	 * Total size of vram including alignment allowance
+	 */
+	u32				total_vram_size;
+	
+	/*
+	 * Interrupt to set when changing registers
+	 */
+	u32				vp_int;
+
+	/*
+	 * Optional: Interrupt used by TIO to signal us
+	 */
+	u32				rx_int;
+	
+	/*
+	 * Base address of the regs for VDC_TIO
+	 */
+	volatile struct vdc_tio_vp_regs	*regs;
+
+	/*
+	 * non-zero if we are in yuv mode
+	 */
+	u8_t				is_yuv;
+
+	/* 
+	 * Fake palette of 16 colors
+	 */
+	u32				pseudo_palette[PALETTE_ENTRIES_NO];
+
+	/*
+	 * Wait queue and lock used to block when we need to wait 
+	 * for something to happen.
+	 */
+	wait_queue_head_t		waitq;
+	struct mutex			lock;
+
+};
+
+/*
+ * ubicom32fb_set_next_frame
+ *	Sets the next frame buffer to display
+ *
+ * if sync is TRUE then this function will block until the hardware 
+ * acknowledges the change
+ */
+static inline void ubicom32fb_set_next_frame(struct ubicom32fb_drvdata *ud, void *fb, u8_t sync)
+{
+	ud->regs->next_frame_flags = ud->is_yuv ? VDCTIO_NEXT_FRAME_FLAG_YUV : 0;
+	ud->regs->next_frame = (void *)((u32_t)fb | 1);
+
+	/*
+	 * If we have interrupts, then we can wait on it
+	 */
+	if (ud->rx_int != -1) {
+		DEFINE_WAIT(wait);
+		unsigned long flags;
+
+		spin_lock_irqsave(&ud->lock, flags);
+		prepare_to_wait(&ud->waitq, &wait, TASK_INTERRUPTIBLE);
+		spin_unlock_irqrestore(&ud->lock, flags);
+		schedule();
+		finish_wait(&ud->waitq, &wait);
+		return;
+	}
+
+	/*
+	 * No interrupt, we will just spin here
+	 */
+	while (sync && ((u32_t)ud->regs->next_frame & 1));
+}
+
+/*
+ * ubicom32fb_send_command
+ *	Sends a command/data pair to the VDC
+ */
+static inline void ubicom32fb_send_command(struct ubicom32fb_drvdata *ud, u16 command, u8_t block)
+{
+	ud->regs->command = command;
+	ubicom32_set_interrupt(ud->vp_int);
+	while (block && ud->regs->command);
+}
+
+/*
+ * ubicom32fb_ioctl
+ *	Handles any ioctls sent to us
+ */
+static int ubicom32fb_ioctl(struct fb_info *fbi, unsigned int cmd,
+		       unsigned long arg)
+{
+	struct ubicom32fb_drvdata *ud = (struct ubicom32fb_drvdata *)fbi->par;
+	void __user *argp = (void __user *)arg;
+	int retval = -EFAULT;
+
+	switch (cmd) {
+	case UBICOM32FB_IOCTL_SET_NEXT_FRAME_SYNC:
+		// check alignment, return -EINVAL if necessary
+		ubicom32fb_set_next_frame(ud, argp, 1);
+		retval = 0;
+		break;
+
+	case UBICOM32FB_IOCTL_SET_NEXT_FRAME:
+		// check alignment, return -EINVAL if necessary
+		ubicom32fb_set_next_frame(ud, argp, 0);
+		retval = 0;
+		break;
+
+	case UBICOM32FB_IOCTL_SET_MODE:
+		if (!(ud->regs->caps & VDCTIO_CAPS_SUPPORTS_SCALING)) {
+			break;
+		} else {
+			struct ubicom32fb_mode mode;
+			volatile struct vdc_tio_vp_regs *regs = ud->regs;
+			u32_t flags = 0;
+
+			if (copy_from_user(&mode, argp, sizeof(mode))) {
+				break;
+			}
+			
+			regs->x_in = mode.width;
+			regs->y_in = mode.height;
+			regs->x_out = regs->xres;
+			regs->y_out = regs->yres;
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV_SCAN_ORDER) {
+				flags |= VDCTIO_SCALE_FLAG_YUV_SCAN_ORDER;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV_BLOCK_ORDER) {
+				flags |= VDCTIO_SCALE_FLAG_YUV_BLOCK_ORDER;
+			}
+			ud->is_yuv = mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_YUV;
+			if (ud->is_yuv) {
+				flags |= VDCTIO_SCALE_FLAG_YUV;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_VRANGE_16_255) {
+				flags |= VDCTIO_SCALE_FLAG_VRANGE_16_255;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_VRANGE_0_255) {
+				flags |= VDCTIO_SCALE_FLAG_VRANGE_0_255;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_VSUB) {
+				flags |= VDCTIO_SCALE_FLAG_VSUB;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_HSUB_2_1) {
+				flags |= VDCTIO_SCALE_FLAG_HSUB_2_1;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_HSUB_1_1) {
+				flags |= VDCTIO_SCALE_FLAG_HSUB_1_1;
+			}
+			if (mode.flags & UBICOM32FB_IOCTL_SET_MODE_FLAG_SCALE_ENABLE) {
+				flags |= VDCTIO_SCALE_FLAG_ENABLE;
+			}
+			if (mode.next_frame) {
+				flags |= VDCTIO_SCALE_FLAG_SET_FRAME_BUFFER;
+				regs->next_frame = mode.next_frame;
+			}
+			
+			regs->scale_flags = flags;
+			ubicom32fb_send_command(ud, VDCTIO_COMMAND_SET_SCALE_MODE, 1);
+			retval = 0;
+			break;
+		}
+
+	default:
+		retval = -ENOIOCTLCMD;
+		break;
+	}
+
+	return retval;
+}
+
+/*
+ * ubicom32fb_interrupt
+ *	Called by the OS when the TIO has set the rx_int
+ */
+static irqreturn_t ubicom32fb_interrupt(int vec, void *appdata)
+{
+	struct ubicom32fb_drvdata *ud = (struct ubicom32fb_drvdata *)appdata;
+
+	spin_lock(&ud->lock);
+	if (waitqueue_active(&ud->waitq)) {
+		wake_up(&ud->waitq);
+	}
+	spin_unlock(&ud->lock);
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * ubicom32fb_pan_display
+ *	Pans the display to a given location.  Supports only y direction panning.
+ */
+static int ubicom32fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
+{
+	struct ubicom32fb_drvdata *ud = (struct ubicom32fb_drvdata *)fbi->par;
+	void *new_addr;
+
+	/*
+	 * Get the last y line that would be displayed.  Since we don't support YWRAP,
+	 * it must be less than our virtual y size.
+	 */
+	u32 lasty = var->yoffset + var->yres;
+	if (lasty > fbi->var.yres_virtual) {
+		/*
+		 * We would fall off the end of our frame buffer if we panned here.
+		 */
+		return -EINVAL;
+	}
+
+	if (var->xoffset) {
+		/*
+		 * We don't support panning in the x direction
+		 */
+		return -EINVAL;
+	}
+
+	/*
+	 * Everything looks sane, go ahead and pan
+	 *
+	 * We have to calculate a new address for the VDC to look at
+	 */
+	new_addr = ud->fb_aligned + (var->yoffset * fbi->fix.line_length);
+
+	/*
+	 * Send down the command.  The buffer will switch at the next vertical blank
+	 */
+	ubicom32fb_set_next_frame(ud, (void *)new_addr, 0);
+
+	return 0;
+}
+
+/*
+ * ubicom32fb_setcolreg
+ *	Sets a color in our virtual palette
+ */
+static int ubicom32fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
+{
+	u32 *palette = fbi->pseudo_palette;
+
+	if (regno >= PALETTE_ENTRIES_NO) {
+		return -EINVAL;
+	}
+
+	/*
+	 * We only use 8 bits from each color
+	 */
+	red >>= 8;
+	green >>= 8;
+	blue >>= 8;
+
+	/*
+	 * Convert any grayscale values
+	 */
+	if (fbi->var.grayscale) {
+		u16 gray = red + green + blue;
+		gray += (gray >> 2) + (gray >> 3) - (gray >> 7);
+		gray >>= 2;
+		if (gray > 255) {
+			gray = 255;
+		}
+		red = gray;
+		blue = gray;
+		green = gray;
+	}
+
+	palette[regno] = (red << fbi->var.red.offset) | (green << fbi->var.green.offset) |
+			 (blue << fbi->var.blue.offset);
+
+	return 0;
+}
+
+/*
+ * ubicom32fb_mmap
+ */
+static int ubicom32fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+	struct ubicom32fb_drvdata *drvdata = (struct ubicom32fb_drvdata *)info->par;
+
+	vma->vm_start = (unsigned long)(drvdata->fb_aligned);
+
+	vma->vm_end = vma->vm_start + info->fix.smem_len;
+
+	/* For those who don't understand how mmap works, go read
+	 *   Documentation/nommu-mmap.txt.
+	 * For those that do, you will know that the VM_MAYSHARE flag
+	 * must be set in the vma->vm_flags structure on noMMU
+	 *   Other flags can be set, and are documented in
+	 *   include/linux/mm.h
+	 */
+
+	vma->vm_flags |=  VM_MAYSHARE | VM_SHARED;
+
+	return 0;
+}
+
+/*
+ * ubicom32fb_blank
+ */
+static int ubicom32fb_blank(int blank_mode, struct fb_info *fbi)
+{
+	return 0;
+#if 0
+	struct ubicom32fb_drvdata *drvdata = to_ubicom32fb_drvdata(fbi);
+
+	switch (blank_mode) {
+	case FB_BLANK_UNBLANK:
+		/* turn on panel */
+		ubicom32fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default);
+		break;
+
+	case FB_BLANK_NORMAL:
+	case FB_BLANK_VSYNC_SUSPEND:
+	case FB_BLANK_HSYNC_SUSPEND:
+	case FB_BLANK_POWERDOWN:
+		/* turn off panel */
+		ubicom32fb_out_be32(drvdata, REG_CTRL, 0);
+	default:
+		break;
+
+	}
+	return 0; /* success */
+#endif
+}
+
+static struct fb_ops ubicom32fb_ops =
+{
+	.owner			= THIS_MODULE,
+	.fb_pan_display		= ubicom32fb_pan_display,
+	.fb_setcolreg		= ubicom32fb_setcolreg,
+	.fb_blank		= ubicom32fb_blank,
+	.fb_mmap		= ubicom32fb_mmap,
+	.fb_ioctl		= ubicom32fb_ioctl,
+	.fb_fillrect		= cfb_fillrect,
+	.fb_copyarea		= cfb_copyarea,
+	.fb_imageblit		= cfb_imageblit,
+};
+
+/*
+ * ubicom32fb_release
+ */
+static int ubicom32fb_release(struct device *dev)
+{
+	struct ubicom32fb_drvdata *ud = dev_get_drvdata(dev);
+
+#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
+	//ubicom32fb_blank(VESA_POWERDOWN, &drvdata->info);
+#endif
+
+	unregister_framebuffer(ud->fbinfo);
+
+	if (ud->cmap_alloc) {
+		fb_dealloc_cmap(&ud->fbinfo->cmap);
+	}
+
+	if (ud->fb) {
+		kfree(ud->fb);
+	}
+
+	if (ud->rx_int != -1) {
+		free_irq(ud->rx_int, ud);
+	}
+
+	/* 
+	 * Turn off the display 
+	 */
+	//ubicom32fb_out_be32(drvdata, REG_CTRL, 0);
+	//iounmap(drvdata->regs);
+
+	framebuffer_release(ud->fbinfo);
+	dev_set_drvdata(dev, NULL);
+
+	return 0;
+}
+
+/*
+ * ubicom32fb_platform_probe
+ */
+static int __init ubicom32fb_platform_probe(struct platform_device *pdev)
+{
+	struct ubicom32fb_drvdata *ud;
+	struct resource *irq_resource_rx;
+	struct resource *irq_resource_tx;
+	struct resource *mem_resource;
+	struct fb_info *fbinfo;
+	int rc;
+	size_t fbsize;
+	struct device *dev = &pdev->dev;
+	int offset;
+	struct vdc_tio_vp_regs *regs;
+
+	/*
+	 * Get our resources
+	 */
+	irq_resource_tx = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!irq_resource_tx) {
+		dev_err(dev, "No tx IRQ resource assigned\n");
+		return -ENODEV;
+	}
+
+	irq_resource_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
+	if (!irq_resource_rx) {
+		dev_err(dev, "No rx IRQ resource assigned\n");
+		return -ENODEV;
+	}
+
+	mem_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!mem_resource || !mem_resource->start) {
+		dev_err(dev, "No mem resource assigned\n");
+		return -ENODEV;
+	}
+	regs = (struct vdc_tio_vp_regs *)mem_resource->start;
+	if (regs->version != VDCTIO_VP_VERSION) {
+		dev_err(dev, "VDCTIO is not compatible with this driver tio:%x drv:%x\n", 
+			regs->version, VDCTIO_VP_VERSION);
+		return -ENODEV;
+	}
+
+	/*
+	 * This is the minimum VRAM size
+	 */
+	fbsize = regs->xres * regs->yres * (regs->bpp / 8);
+	if (!vram_size) {
+		vram_size = (fbsize + 1023) / 1024;
+	} else {
+		if (fbsize > (vram_size * 1024)) {
+			dev_err(dev, "Not enough VRAM for display, need >= %u bytes\n", fbsize);
+			return -ENOMEM; // should be ebadparam?
+		}
+	}
+
+	/*
+	 * Allocate the framebuffer instance + our private data
+	 */
+	fbinfo = framebuffer_alloc(sizeof(struct ubicom32fb_drvdata), &pdev->dev);
+	if (!fbinfo) {
+		dev_err(dev, "Not enough memory to allocate instance.\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * Fill in our private data.
+	 */
+	ud = (struct ubicom32fb_drvdata *)fbinfo->par;
+	ud->fbinfo = fbinfo;
+	ud->regs = (struct vdc_tio_vp_regs *)(mem_resource->start);
+	dev_set_drvdata(dev, ud);
+
+	ud->vp_int = irq_resource_tx->start;
+
+	/*
+	 * If we were provided an rx_irq then we need to init the appropriate
+	 * queues, locks, and functions.
+	 */
+	ud->rx_int = -1;
+	if (irq_resource_rx->start != DEVTREE_IRQ_NONE) {
+		init_waitqueue_head(&ud->waitq);
+		mutex_init(&ud->lock);
+		if (request_irq(ud->rx_int, ubicom32fb_interrupt, IRQF_SHARED, "ubicom32fb_rx", ud)) {
+			dev_err(dev, "Couldn't request rx IRQ\n");
+			rc = -ENOMEM;
+			goto fail;
+		}
+		ud->rx_int = irq_resource_rx->start;
+	}
+
+	/*
+	 * Allocate and align the requested amount of VRAM
+	 */
+	ud->total_vram_size = (vram_size * 1024) + regs->fb_align;
+	ud->fb = kmalloc(ud->total_vram_size, GFP_KERNEL);
+	if (ud->fb == NULL) {
+		dev_err(dev, "Couldn't allocate VRAM\n");
+		rc = -ENOMEM;
+		goto fail;
+	}
+
+	offset = (u32_t)ud->fb & (regs->fb_align - 1);
+	if (!offset) {
+		ud->fb_aligned = ud->fb;
+	} else {
+		offset = regs->fb_align - offset;
+		ud->fb_aligned = ud->fb + offset;
+	}
+
+	/*
+	 * Clear the entire frame buffer
+	 */
+	if (!init_value) {
+		memset(ud->fb_aligned, 0, vram_size * 1024);
+	} else {
+		unsigned short *p = ud->fb_aligned;
+		int i;
+		for (i = 0; i < ((vram_size * 1024) / sizeof(u16_t)); i++) {
+			*p++ = init_value;
+		}
+	}
+
+	/*
+	 * Fill in the fb_var_screeninfo structure
+	 */
+	memset(&ubicom32fb_var, 0, sizeof(ubicom32fb_var));
+	ubicom32fb_var.bits_per_pixel = regs->bpp;
+	ubicom32fb_var.red.offset = regs->rshift;
+	ubicom32fb_var.green.offset = regs->gshift;
+	ubicom32fb_var.blue.offset = regs->bshift;
+	ubicom32fb_var.red.length = regs->rbits;
+	ubicom32fb_var.green.length = regs->gbits;
+	ubicom32fb_var.blue.length = regs->bbits;
+	ubicom32fb_var.activate = FB_ACTIVATE_NOW;
+
+#if 0
+	/* 
+	 * Turn on the display 
+	 */
+	ud->reg_ctrl_default = REG_CTRL_ENABLE;
+	if (regs->rotate_screen)
+		ud->reg_ctrl_default |= REG_CTRL_ROTATE;
+	ubicom32fb_out_be32(ud, REG_CTRL, ud->reg_ctrl_default);
+#endif
+
+	/*
+	 * Fill in the fb_info structure
+	 */
+	ud->fbinfo->device = dev;
+	ud->fbinfo->screen_base = (void *)ud->fb_aligned;
+	ud->fbinfo->fbops = &ubicom32fb_ops;
+	ud->fbinfo->fix = ubicom32fb_fix;
+	ud->fbinfo->fix.smem_start = (u32)ud->fb_aligned;
+	ud->fbinfo->fix.smem_len = fbsize;
+	ud->fbinfo->fix.line_length = regs->xres * (regs->bpp / 8);
+
+	/*
+	 * We support panning in the y direction only
+	 */
+	ud->fbinfo->fix.xpanstep = 0;
+	ud->fbinfo->fix.ypanstep = 1;
+
+	ud->fbinfo->pseudo_palette = ud->pseudo_palette;
+	ud->fbinfo->flags = FBINFO_DEFAULT;
+	ud->fbinfo->var = ubicom32fb_var;
+	ud->fbinfo->var.xres = regs->xres;
+	ud->fbinfo->var.yres = regs->yres;
+
+	/*
+	 * We cannot pan in the X direction, so xres_virtual is regs->xres
+	 * We can pan in the Y direction, so yres_virtual is vram_size / ud->fbinfo->fix.line_length
+	 */
+	ud->fbinfo->var.xres_virtual = regs->xres;
+	ud->fbinfo->var.yres_virtual = (vram_size * 1024) / ud->fbinfo->fix.line_length;
+
+	//ud->fbinfo->var.height = regs->height_mm;
+	//ud->fbinfo->var.width = regs->width_mm;
+
+	/* 
+	 * Allocate a color map
+	 */
+	rc = fb_alloc_cmap(&ud->fbinfo->cmap, PALETTE_ENTRIES_NO, 0);
+	if (rc) {
+		dev_err(dev, "Fail to allocate colormap (%d entries)\n",
+			PALETTE_ENTRIES_NO);
+		goto fail;
+	}
+	ud->cmap_alloc = true;
+
+	/*
+	 * Register new frame buffer
+	 */
+	rc = register_framebuffer(ud->fbinfo);
+	if (rc) {
+		dev_err(dev, "Could not register frame buffer\n");
+		goto fail;
+	}
+
+	/*
+	 * Start up the VDC
+	 */
+	ud->regs->next_frame = ud->fb;
+	ubicom32fb_send_command(ud, VDCTIO_COMMAND_START, 0);
+
+	/*
+	 * Tell the log we are here
+	 */
+	dev_info(dev, "fbaddr=%p align=%p, size=%uKB screen(%ux%u) virt(%ux%u), regs=%p irqtx=%u irqrx=%u\n", 
+		ud->fb, ud->fb_aligned, vram_size, ud->fbinfo->var.xres, ud->fbinfo->var.yres, 
+		ud->fbinfo->var.xres_virtual, ud->fbinfo->var.yres_virtual, ud->regs,
+		irq_resource_tx->start, irq_resource_rx->start);
+
+	/* 
+	 * Success 
+	 */
+	return 0;
+
+fail:
+	ubicom32fb_release(dev);
+	return rc;
+}
+
+/*
+ * ubicom32fb_platform_remove
+ */
+static int ubicom32fb_platform_remove(struct platform_device *pdev)
+{
+	dev_info(&(pdev->dev), "Ubicom32 FB Driver Remove\n");
+	return ubicom32fb_release(&pdev->dev);
+}
+
+static struct platform_driver ubicom32fb_platform_driver = {
+	.probe		= ubicom32fb_platform_probe,
+	.remove		= ubicom32fb_platform_remove,
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+
+#ifndef MODULE
+/*
+ * ubicom32fb_setup
+ *	Process kernel boot options
+ */
+static int __init ubicom32fb_setup(char *options)
+{
+	char *this_opt;
+
+	if (!options || !*options) {
+		return 0;
+	}
+
+	while ((this_opt = strsep(&options, ",")) != NULL) {
+		if (!*this_opt) {
+			continue;
+		}
+
+		if (!strncmp(this_opt, "init_value=", 10)) {
+			init_value = simple_strtoul(this_opt + 11, NULL, 0);
+			continue;
+		}
+
+		if (!strncmp(this_opt, "vram_size=", 10)) {
+			vram_size = simple_strtoul(this_opt + 10, NULL, 0);
+			continue;
+		}
+	}
+	return 0;
+}
+#endif /* MODULE */
+
+/*
+ * ubicom32fb_init
+ */
+static int __devinit ubicom32fb_init(void)
+{
+#ifndef MODULE
+	/*
+	 * Get kernel boot options (in 'video=ubicom32fb:<options>')
+	 */
+	char *option = NULL;
+
+	if (fb_get_options(DRIVER_NAME, &option)) {
+		return -ENODEV;
+	}
+	ubicom32fb_setup(option);
+#endif /* MODULE */
+
+	return platform_driver_register(&ubicom32fb_platform_driver);
+}
+module_init(ubicom32fb_init);
+
+/*
+ * ubicom32fb_exit
+ */
+static void __exit ubicom32fb_exit(void)
+{
+	platform_driver_unregister(&ubicom32fb_platform_driver);
+}
+module_exit(ubicom32fb_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Patrick Tjin <@ubicom.com>");
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
--- /dev/null
+++ b/drivers/video/ubicom32vfb.c
@@ -0,0 +1,492 @@
+/*
+ * drivers/video/ubicom32vfb.c
+ *	Ubicom32 virtual frame buffer driver
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This driver was based on skeletonfb.c, Skeleton for a frame buffer device by
+ * Geert Uytterhoeven.
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/fb.h>
+#include <linux/init.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/device.h>
+#include <linux/uaccess.h>
+
+#define DRIVER_NAME		"ubicom32vfb"
+#define DRIVER_DESCRIPTION	"Ubicom32 virtual frame buffer driver"
+
+#define PALETTE_ENTRIES_NO	16
+
+/*
+ * Option variables
+ *
+ * vram_size:	VRAM size in kilobytes, subject to alignment 
+ */
+static int vram_size = 0;
+module_param(vram_size, int, 0);
+MODULE_PARM_DESC(vram_size, "VRAM size, in kilobytes to allocate, should be at least the size of one screen, subject to alignment");
+
+static int xres = 320;
+module_param(xres, int, 0);
+MODULE_PARM_DESC(xres, "x (horizontal) resolution");
+
+static int yres = 240;
+module_param(yres, int, 0);
+MODULE_PARM_DESC(yres, "y (vertical) resolution");
+
+static int bgr = 0;
+module_param(bgr, int, 0);
+MODULE_PARM_DESC(bgr, "display is BGR (Blue is MSB)");
+
+/*
+ * Buffer alignment, must not be 0
+ */
+#define UBICOM32VFB_ALIGNMENT 4
+
+/*
+ * fb_fix_screeninfo defines the non-changeable properties of the VDC, depending on what mode it is in.
+ */
+static struct fb_fix_screeninfo ubicom32vfb_fix = {
+	.id =		"Ubicom32",
+	.type =		FB_TYPE_PACKED_PIXELS,
+	.visual =	FB_VISUAL_TRUECOLOR,
+	.accel =	FB_ACCEL_NONE
+};
+
+/*
+ * Filled in at probe time when we find out what the hardware supports
+ */
+static struct fb_var_screeninfo ubicom32vfb_var;
+
+/*
+ * Private data structure
+ */
+struct ubicom32vfb_drvdata {
+	struct fb_info			*fbinfo;
+	bool				cmap_alloc;
+
+	/*
+	 * The address of the framebuffer in memory
+	 */
+	void				*fb;
+	void				*fb_aligned;
+
+	/*
+	 * Total size of vram including alignment allowance
+	 */
+	u32				total_vram_size;
+	
+	/* 
+	 * Fake palette of 16 colors
+	 */
+	u32				pseudo_palette[PALETTE_ENTRIES_NO];
+};
+
+/*
+ * ubicom32vfb_pan_display
+ *	Pans the display to a given location.  Supports only y direction panning.
+ */
+static int ubicom32vfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
+{
+	struct ubicom32vfb_drvdata *ud = (struct ubicom32vfb_drvdata *)fbi->par;
+	void *new_addr;
+
+	/*
+	 * Get the last y line that would be displayed.  Since we don't support YWRAP,
+	 * it must be less than our virtual y size.
+	 */
+	u32 lasty = var->yoffset + var->yres;
+	if (lasty > fbi->var.yres_virtual) {
+		/*
+		 * We would fall off the end of our frame buffer if we panned here.
+		 */
+		return -EINVAL;
+	}
+
+	if (var->xoffset) {
+		/*
+		 * We don't support panning in the x direction
+		 */
+		return -EINVAL;
+	}
+
+	/*
+	 * Everything looks sane, go ahead and pan
+	 *
+	 * We have to calculate a new address for the VDC to look at
+	 */
+	new_addr = ud->fb_aligned + (var->yoffset * fbi->fix.line_length);
+
+	return 0;
+}
+
+/*
+ * ubicom32vfb_setcolreg
+ *	Sets a color in our virtual palette
+ */
+static int ubicom32vfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
+{
+	u32 *palette = fbi->pseudo_palette;
+
+	if (regno >= PALETTE_ENTRIES_NO) {
+		return -EINVAL;
+	}
+
+	/*
+	 * We only use 8 bits from each color
+	 */
+	red >>= 8;
+	green >>= 8;
+	blue >>= 8;
+
+	/*
+	 * Convert any grayscale values
+	 */
+	if (fbi->var.grayscale) {
+		u16 gray = red + green + blue;
+		gray += (gray >> 2) + (gray >> 3) - (gray >> 7);
+		gray >>= 2;
+		if (gray > 255) {
+			gray = 255;
+		}
+		red = gray;
+		blue = gray;
+		green = gray;
+	}
+
+	palette[regno] = (red << fbi->var.red.offset) | (green << fbi->var.green.offset) |
+			 (blue << fbi->var.blue.offset);
+
+	return 0;
+}
+
+/*
+ * ubicom32vfb_mmap
+ */
+static int ubicom32vfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+	struct ubicom32vfb_drvdata *drvdata = (struct ubicom32vfb_drvdata *)info->par;
+
+	vma->vm_start = (unsigned long)(drvdata->fb_aligned);
+
+	vma->vm_end = vma->vm_start + info->fix.smem_len;
+
+	/* For those who don't understand how mmap works, go read
+	 *   Documentation/nommu-mmap.txt.
+	 * For those that do, you will know that the VM_MAYSHARE flag
+	 * must be set in the vma->vm_flags structure on noMMU
+	 *   Other flags can be set, and are documented in
+	 *   include/linux/mm.h
+	 */
+
+	vma->vm_flags |=  VM_MAYSHARE | VM_SHARED;
+
+	return 0;
+}
+
+static struct fb_ops ubicom32vfb_ops =
+{
+	.owner			= THIS_MODULE,
+	.fb_pan_display		= ubicom32vfb_pan_display,
+	.fb_setcolreg		= ubicom32vfb_setcolreg,
+	.fb_mmap		= ubicom32vfb_mmap,
+	.fb_fillrect		= cfb_fillrect,
+	.fb_copyarea		= cfb_copyarea,
+	.fb_imageblit		= cfb_imageblit,
+};
+
+/*
+ * ubicom32vfb_release
+ */
+static int ubicom32vfb_release(struct device *dev)
+{
+	struct ubicom32vfb_drvdata *ud = dev_get_drvdata(dev);
+
+	unregister_framebuffer(ud->fbinfo);
+
+	if (ud->cmap_alloc) {
+		fb_dealloc_cmap(&ud->fbinfo->cmap);
+	}
+
+	if (ud->fb) {
+		kfree(ud->fb);
+	}
+
+	framebuffer_release(ud->fbinfo);
+	dev_set_drvdata(dev, NULL);
+
+	return 0;
+}
+
+/*
+ * ubicom32vfb_platform_probe
+ */
+static int __init ubicom32vfb_platform_probe(struct platform_device *pdev)
+{
+	struct ubicom32vfb_drvdata *ud;
+	struct fb_info *fbinfo;
+	int rc;
+	size_t fbsize;
+	struct device *dev = &pdev->dev;
+	int offset;
+
+	/*
+	 * This is the minimum VRAM size
+	 */
+	fbsize = xres * yres * 2;
+	if (!vram_size) {
+		vram_size = (fbsize + 1023) / 1024;
+	} else {
+		if (fbsize > (vram_size * 1024)) {
+			dev_err(dev, "Not enough VRAM for display, need >= %u bytes\n", fbsize);
+			return -ENOMEM; // should be ebadparam?
+		}
+	}
+
+	/*
+	 * Allocate the framebuffer instance + our private data
+	 */
+	fbinfo = framebuffer_alloc(sizeof(struct ubicom32vfb_drvdata), &pdev->dev);
+	if (!fbinfo) {
+		dev_err(dev, "Not enough memory to allocate instance.\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * Fill in our private data.
+	 */
+	ud = (struct ubicom32vfb_drvdata *)fbinfo->par;
+	ud->fbinfo = fbinfo;
+	dev_set_drvdata(dev, ud);
+
+	/*
+	 * Allocate and align the requested amount of VRAM
+	 */
+	ud->total_vram_size = (vram_size * 1024) + UBICOM32VFB_ALIGNMENT;
+	ud->fb = kmalloc(ud->total_vram_size, GFP_KERNEL);
+	if (ud->fb == NULL) {
+		dev_err(dev, "Couldn't allocate VRAM\n");
+		rc = -ENOMEM;
+		goto fail;
+	}
+
+	offset = (u32_t)ud->fb & (UBICOM32VFB_ALIGNMENT - 1);
+	if (!offset) {
+		ud->fb_aligned = ud->fb;
+	} else {
+		offset =  UBICOM32VFB_ALIGNMENT - offset;
+		ud->fb_aligned = ud->fb + offset;
+	}
+
+	/*
+	 * Clear the entire frame buffer
+	 */
+	memset(ud->fb_aligned, 0, vram_size * 1024);
+
+	/*
+	 * Fill in the fb_var_screeninfo structure
+	 */
+	memset(&ubicom32vfb_var, 0, sizeof(ubicom32vfb_var));
+	ubicom32vfb_var.bits_per_pixel = 16;
+	ubicom32vfb_var.red.length = 5;
+	ubicom32vfb_var.green.length = 6;
+	ubicom32vfb_var.green.offset = 5;
+	ubicom32vfb_var.blue.length = 5;
+	ubicom32vfb_var.activate = FB_ACTIVATE_NOW;
+
+	if (bgr) {
+		ubicom32vfb_var.red.offset = 0;
+		ubicom32vfb_var.blue.offset = 11;
+	} else {
+		ubicom32vfb_var.red.offset = 11;
+		ubicom32vfb_var.blue.offset = 0;
+	}
+
+	/*
+	 * Fill in the fb_info structure
+	 */
+	ud->fbinfo->device = dev;
+	ud->fbinfo->screen_base = (void *)ud->fb_aligned;
+	ud->fbinfo->fbops = &ubicom32vfb_ops;
+	ud->fbinfo->fix = ubicom32vfb_fix;
+	ud->fbinfo->fix.smem_start = (u32)ud->fb_aligned;
+	ud->fbinfo->fix.smem_len = fbsize;
+	ud->fbinfo->fix.line_length = xres * 2;
+
+	/*
+	 * We support panning in the y direction only
+	 */
+	ud->fbinfo->fix.xpanstep = 0;
+	ud->fbinfo->fix.ypanstep = 1;
+
+	ud->fbinfo->pseudo_palette = ud->pseudo_palette;
+	ud->fbinfo->flags = FBINFO_DEFAULT;
+	ud->fbinfo->var = ubicom32vfb_var;
+	ud->fbinfo->var.xres = xres;
+	ud->fbinfo->var.yres = yres;
+
+	/*
+	 * We cannot pan in the X direction, so xres_virtual is xres
+	 * We can pan in the Y direction, so yres_virtual is vram_size / ud->fbinfo->fix.line_length
+	 */
+	ud->fbinfo->var.xres_virtual = xres;
+	ud->fbinfo->var.yres_virtual = (vram_size * 1024) / ud->fbinfo->fix.line_length;
+
+	/* 
+	 * Allocate a color map
+	 */
+	rc = fb_alloc_cmap(&ud->fbinfo->cmap, PALETTE_ENTRIES_NO, 0);
+	if (rc) {
+		dev_err(dev, "Fail to allocate colormap (%d entries)\n",
+			PALETTE_ENTRIES_NO);
+		goto fail;
+	}
+	ud->cmap_alloc = true;
+
+	/*
+	 * Register new frame buffer
+	 */
+	rc = register_framebuffer(ud->fbinfo);
+	if (rc) {
+		dev_err(dev, "Could not register frame buffer\n");
+		goto fail;
+	}
+
+	/*
+	 * Tell the log we are here
+	 */
+	dev_info(dev, "fbaddr=%p align=%p, size=%uKB screen(%ux%u) virt(%ux%u)\n",
+		ud->fb, ud->fb_aligned, vram_size, ud->fbinfo->var.xres, ud->fbinfo->var.yres, 
+		ud->fbinfo->var.xres_virtual, ud->fbinfo->var.yres_virtual);
+
+	/* 
+	 * Success 
+	 */
+	return 0;
+
+fail:
+	ubicom32vfb_release(dev);
+	return rc;
+}
+
+/*
+ * ubicom32vfb_platform_remove
+ */
+static int ubicom32vfb_platform_remove(struct platform_device *pdev)
+{
+	dev_info(&(pdev->dev), "Ubicom32 FB Driver Remove\n");
+	return ubicom32vfb_release(&pdev->dev);
+}
+
+static struct platform_driver ubicom32vfb_platform_driver = {
+	.probe		= ubicom32vfb_platform_probe,
+	.remove		= ubicom32vfb_platform_remove,
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+
+#ifndef MODULE
+/*
+ * ubicom32vfb_setup
+ *	Process kernel boot options
+ */
+static int __init ubicom32vfb_setup(char *options)
+{
+	char *this_opt;
+
+	if (!options || !*options) {
+		return 0;
+	}
+
+	while ((this_opt = strsep(&options, ",")) != NULL) {
+		if (!*this_opt) {
+			continue;
+		}
+
+		if (!strncmp(this_opt, "vram_size=", 10)) {
+			vram_size = simple_strtoul(this_opt + 10, NULL, 0);
+			continue;
+		}
+
+		if (!strncmp(this_opt, "bgr=", 4)) {
+			bgr = simple_strtoul(this_opt + 4, NULL, 0);
+			continue;
+		}
+
+		if (!strncmp(this_opt, "xres=", 5)) {
+			xres = simple_strtoul(this_opt + 5, NULL, 0);
+			continue;
+		}
+
+		if (!strncmp(this_opt, "yres=", 5)) {
+			yres = simple_strtoul(this_opt + 5, NULL, 0);
+			continue;
+		}
+	}
+	return 0;
+}
+#endif /* MODULE */
+
+/*
+ * ubicom32vfb_init
+ */
+static int __devinit ubicom32vfb_init(void)
+{
+#ifndef MODULE
+	/*
+	 * Get kernel boot options (in 'video=ubicom32vfb:<options>')
+	 */
+	char *option = NULL;
+
+	if (fb_get_options(DRIVER_NAME, &option)) {
+		return -ENODEV;
+	}
+	ubicom32vfb_setup(option);
+#endif /* MODULE */
+
+	return platform_driver_register(&ubicom32vfb_platform_driver);
+}
+module_init(ubicom32vfb_init);
+
+/*
+ * ubicom32vfb_exit
+ */
+static void __exit ubicom32vfb_exit(void)
+{
+	platform_driver_unregister(&ubicom32vfb_platform_driver);
+}
+module_exit(ubicom32vfb_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Patrick Tjin <@ubicom.com>");
+MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -856,6 +856,19 @@ config WATCHDOG_RIO
 	  machines.  The watchdog timeout period is normally one minute but
 	  can be changed with a boot-time parameter.
 
+# Ubicom32
+
+config UBI32_WDT
+	tristate "Ubicom32 Hardware Watchdog support"
+	depends on UBICOM32
+	---help---
+	  If you say yes here you will get support for the Ubicom32 On-Chip
+	  Watchdog Timer. If you have one of these processors and wish to
+	  have watchdog support enabled, say Y, otherwise say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ubi32_wdt.
+
 # XTENSA Architecture
 
 #
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -130,6 +130,9 @@ obj-$(CONFIG_SH_WDT) += shwdt.o
 obj-$(CONFIG_WATCHDOG_RIO)		+= riowd.o
 obj-$(CONFIG_WATCHDOG_CP1XXX)		+= cpwd.o
 
+# Ubicom32 Architecture
+obj-$(CONFIG_UBI32_WDT)			+= ubi32_wdt.o
+
 # XTENSA Architecture
 
 # Architecture Independant
--- /dev/null
+++ b/drivers/watchdog/ubi32_wdt.c
@@ -0,0 +1,630 @@
+/*
+ * drivers/watchdog/ubi32_wdt.c
+ *   Ubicom32 Watchdog Driver
+ *
+ * Originally based on softdog.c
+ * Copyright 2006-2007 Analog Devices Inc.
+ * Copyright 2006-2007 Michele d'Amico
+ * Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+#include <linux/timer.h>
+#include <linux/miscdevice.h>
+#include <linux/watchdog.h>
+#include <linux/fs.h>
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/uaccess.h>
+#include <asm/ip5000.h>
+
+#define WATCHDOG_NAME "ubi32-wdt"
+#define PFX WATCHDOG_NAME ": "
+
+#define OSC1_FREQ 12000000
+#define WATCHDOG_SEC_TO_CYC(x) (OSC1_FREQ * (x))
+#define WATCHDOG_MAX_SEC (0xffffffff / OSC1_FREQ)
+
+#define MIN_PROCESSOR_ADDRESS 0x03000000
+
+static DEFINE_SPINLOCK(ubi32_wdt_spinlock);
+
+#define WATCHDOG_TIMEOUT 20
+
+#if defined(CONFIG_WATCHDOG_NOWAYOUT)
+#define WATCHDOG_NOWAYOUT 1
+#else
+#define WATCHDOG_NOWAYOUT 0
+#endif
+
+static unsigned int timeout = WATCHDOG_TIMEOUT;
+static int nowayout = WATCHDOG_NOWAYOUT;
+static struct watchdog_info ubi32_wdt_info;
+static unsigned long open_check;
+static char expect_close;
+
+#if !defined(CONFIG_SMP)
+#define UBI32_WDT_LOCK(lock, flags) local_irq_save(flags)
+#define UBI32_WDT_UNLOCK(lock, flags) local_irq_restore(flags)
+#define UBI32_WDT_LOCK_CHECK()
+#else
+#define UBI32_WDT_LOCK(lock, flags) spin_lock_irqsave((lock), (flags));
+#define UBI32_WDT_UNLOCK(lock, flags) spin_unlock_irqrestore((lock), (flags));
+#define UBI32_WDT_LOCK_CHECK() BUG_ON(!spin_is_locked(&ubi32_wdt_spinlock));
+#endif
+
+/*
+ * ubi32_wdt_remaining()
+ * 	Return the approximate number of seconds remaining
+ */
+static int ubi32_wdt_remaining(void)
+{
+	int compare;
+	int curr;
+
+	UBI32_WDT_LOCK_CHECK();
+
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, TIMER_TKEYVAL);
+	compare = ubicom32_read_reg(&UBICOM32_IO_TIMER->wdcom);
+	curr = ubicom32_read_reg(&UBICOM32_IO_TIMER->mptval);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, 0);
+	return (compare - curr) / OSC1_FREQ;
+
+}
+
+/*
+ * ubi32_wdt_keepalive()
+ *	Keep the Userspace Watchdog Alive
+ *
+ * The Userspace watchdog got a KeepAlive: schedule the next timeout.
+ */
+static int ubi32_wdt_keepalive(void)
+{
+	UBI32_WDT_LOCK_CHECK();
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, TIMER_TKEYVAL);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->wdcom,
+			ubicom32_read_reg(&UBICOM32_IO_TIMER->mptval)
+			+ WATCHDOG_SEC_TO_CYC(timeout));
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, 0);
+	return 0;
+}
+
+/*
+ * ubi32_wdt_stop()
+ *	Stop the on-chip Watchdog
+ */
+static int ubi32_wdt_stop(void)
+{
+	UBI32_WDT_LOCK_CHECK();
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, TIMER_TKEYVAL);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->wdcfg, TIMER_WATCHDOG_DISABLE);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, 0);
+	return 0;
+}
+
+/*
+ * ubi32_wdt_start()
+ *	Start the on-chip Watchdog
+ */
+static int ubi32_wdt_start(void)
+{
+	UBI32_WDT_LOCK_CHECK();
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, TIMER_TKEYVAL);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->wdcom,
+			ubicom32_read_reg(&UBICOM32_IO_TIMER->mptval)
+			+ WATCHDOG_SEC_TO_CYC(timeout));
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->wdcfg, ~TIMER_WATCHDOG_DISABLE);
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, 0);
+	return 0;
+}
+
+/*
+ * ubi32_wdt_running()
+ * 	Return true if the watchdog is configured
+ */
+static int ubi32_wdt_running(void)
+{
+	int enabled;
+
+	UBI32_WDT_LOCK_CHECK();
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, TIMER_TKEYVAL);
+	enabled = ubicom32_read_reg(&UBICOM32_IO_TIMER->wdcfg) == ~TIMER_WATCHDOG_DISABLE;
+	ubicom32_write_reg(&UBICOM32_IO_TIMER->tkey, 0);
+	return enabled;
+}
+
+/*
+ * ubi32_wdt_set_timeout()
+ *	Set the Userspace Watchdog timeout
+ *
+ * - @t: new timeout value (in seconds)
+ */
+static int ubi32_wdt_set_timeout(unsigned long t)
+{
+	UBI32_WDT_LOCK_CHECK();
+
+	if (t > WATCHDOG_MAX_SEC) {
+		printk(KERN_WARNING PFX "request to large: %ld [1-%d] sec)\n", t, WATCHDOG_MAX_SEC);
+		return -EINVAL;
+	}
+
+	/*
+	 * If we are running, then reset the time value so
+	 * that the new value has an immediate effect.
+	 */
+	timeout = t;
+	if (ubi32_wdt_running()) {
+		ubi32_wdt_keepalive();
+	}
+	return 0;
+}
+
+/*
+ * ubi32_wdt_open()
+ *	Open the Device
+ */
+static int ubi32_wdt_open(struct inode *inode, struct file *file)
+{
+	unsigned long flags;
+
+	if (test_and_set_bit(0, &open_check))
+		return -EBUSY;
+
+	if (nowayout)
+		__module_get(THIS_MODULE);
+
+	spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+	ubi32_wdt_start();
+	spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+
+	return nonseekable_open(inode, file);
+}
+
+/*
+ * ubi32_wdt_close()
+ *	Close the Device
+ */
+static int ubi32_wdt_release(struct inode *inode, struct file *file)
+{
+	unsigned long flags;
+
+	/*
+	 * If we don't expect a close, then the watchdog continues
+	 * even though the device is closed.  The caller will have
+	 * a full timeout value to reopen the device and continue
+	 * stroking it.
+	 */
+	if (expect_close != 42) {
+		printk(KERN_CRIT PFX
+			"Unexpected close, not stopping watchdog!\n");
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ubi32_wdt_keepalive();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	} else {
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ubi32_wdt_stop();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	}
+
+	expect_close = 0;
+	clear_bit(0, &open_check);
+	return 0;
+}
+
+/*
+ * ubi32_wdt_write()
+ *	Write to Device
+ *
+ * If the user writes nothing, nothing happens.
+ * If the user writes a V, then we expect a close and allow a release.
+ * If the user writes anything else, it is ignored.
+ */
+static ssize_t ubi32_wdt_write(struct file *file, const char __user *data,
+						size_t len, loff_t *ppos)
+{
+	size_t i;
+	unsigned long flags;
+
+	/*
+	 * Every write resets the expect_close.  The last write
+	 * must be a V to allow shutdown on close.
+	 */
+	expect_close = 0;
+
+	/*
+	 * Empty writes still ping.
+	 */
+	if (!len) {
+		goto ping;
+	}
+
+	/*
+	 * If nowayout is set, it does not matter if the caller
+	 * is trying to send the magic 'V' we will not allow a
+	 * close to stop us.
+	 */
+	if (nowayout) {
+		goto ping;
+	}
+
+	/*
+	 * See if the program wrote a 'V' and if so disable
+	 * the watchdog on release.
+	 */
+	for (i = 0; i < len; i++) {
+		char c;
+		if (get_user(c, data + i)) {
+			return -EFAULT;
+		}
+
+		if (c == 'V') {
+			expect_close = 42;
+		}
+	}
+
+ping:
+	spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+	ubi32_wdt_keepalive();
+	spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	return len;
+}
+
+/*
+ * ubi32_wdt_ioctl()
+ *	Query the watchdog device.
+ *
+ * Query basic information from the device or ping it, as outlined by the
+ * watchdog API.
+ */
+static long ubi32_wdt_ioctl(struct file *file,
+				unsigned int cmd, unsigned long arg)
+{
+	void __user *argp = (void __user *)arg;
+	int __user *p = argp;
+
+	switch (cmd) {
+	case WDIOC_GETSUPPORT:
+		if (copy_to_user(argp, &ubi32_wdt_info, sizeof(ubi32_wdt_info))) {
+			return -EFAULT;
+		}
+		return 0;
+
+	case WDIOC_GETSTATUS: {
+		unsigned long flags;
+		int running;
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		running = ubi32_wdt_running();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+		return running;
+	}
+
+	case WDIOC_GETBOOTSTATUS:
+		return ubicom32_get_reset_reason();
+
+	case WDIOC_SETOPTIONS: {
+		unsigned long flags;
+		int options, ret = -EINVAL;
+
+		/*
+		 * The sample application does not pass a pointer
+		 * but directly passes a value of 1 or 2; however
+		 * all of the implementations (and thus probably
+		 * the real applications) pass a pointer to a value.
+		 *
+		 * It should be noted that  WDIOC_SETOPTIONS is defined as
+		 * _IOR(WATCHDOG_IOCTL_BASE, 4, int), which means
+		 * that it should be an int and NOT a pointer.
+		 *
+		 * TODO: Examine this code for future chips.
+		 * TODO: Report the sample code defect.
+		 */
+		if ((int)p < MIN_PROCESSOR_ADDRESS) {
+			options = (int)p;
+		} else {
+			if (get_user(options, p))
+			return -EFAULT;
+		}
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		if (options & WDIOS_DISABLECARD) {
+			ubi32_wdt_stop();
+			ret = 0;
+		}
+		if (options & WDIOS_ENABLECARD) {
+			ubi32_wdt_start();
+			ret = 0;
+		}
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+		return ret;
+	}
+
+	case WDIOC_KEEPALIVE: {
+		unsigned long flags;
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ubi32_wdt_keepalive();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+		return 0;
+	}
+
+	case WDIOC_SETTIMEOUT: {
+		int new_timeout;
+		unsigned long flags;
+		int ret  = 0;
+
+		if (get_user(new_timeout, p))
+			return -EFAULT;
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ret = ubi32_wdt_set_timeout(new_timeout);
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+		return ret;
+
+	}
+
+	case WDIOC_GETTIMEOUT:
+		return put_user(timeout, p);
+
+	case WDIOC_GETTIMELEFT: {
+		unsigned long flags;
+		int remaining = 0;
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		remaining = ubi32_wdt_remaining();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+		return put_user(remaining, p);
+	}
+
+	default:
+		return -ENOTTY;
+	}
+}
+
+/*
+ * ubi32_wdt_notify_sys()
+ *	Notification callback function for system events.
+ *
+ * Turn off the watchdog during a SYS_DOWN or SYS_HALT.
+ */
+static int ubi32_wdt_notify_sys(struct notifier_block *this,
+					unsigned long code, void *unused)
+{
+	if (code == SYS_DOWN || code == SYS_HALT) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ubi32_wdt_stop();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	}
+
+	return NOTIFY_DONE;
+}
+
+#ifdef CONFIG_PM
+static int state_before_suspend;
+
+/*
+ * ubi32_wdt_suspend()
+ * 	suspend the watchdog
+ *
+ * Remember if the watchdog was running and stop it.
+ */
+static int ubi32_wdt_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	unsigned long flags;
+	spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+	state_before_suspend = ubi32_wdt_running();
+	ubi32_wdt_stop();
+	spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+
+	return 0;
+}
+
+/*
+ * ubi32_wdt_resume()
+ * 	Resume the watchdog
+ *
+ * If the watchdog was running, turn it back on.
+ */
+static int ubi32_wdt_resume(struct platform_device *pdev)
+{
+	if (state_before_suspend) {
+		unsigned long flags;
+		spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+		ubi32_wdt_set_timeout(timeout);
+		ubi32_wdt_start();
+		spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	}
+
+	return 0;
+}
+#else
+# define ubi32_wdt_suspend NULL
+# define ubi32_wdt_resume NULL
+#endif
+
+static const struct file_operations ubi32_wdt_fops = {
+	.owner		= THIS_MODULE,
+	.llseek		= no_llseek,
+	.write    	= ubi32_wdt_write,
+	.unlocked_ioctl	= ubi32_wdt_ioctl,
+	.open		= ubi32_wdt_open,
+	.release	= ubi32_wdt_release,
+};
+
+static struct miscdevice ubi32_wdt_miscdev = {
+	.minor    = WATCHDOG_MINOR,
+	.name     = "watchdog",
+	.fops     = &ubi32_wdt_fops,
+};
+
+static struct watchdog_info ubi32_wdt_info = {
+	.identity = "Ubicom32 Watchdog",
+	.options  = WDIOF_SETTIMEOUT |
+		    WDIOF_KEEPALIVEPING |
+		    WDIOF_MAGICCLOSE,
+};
+
+static struct notifier_block ubi32_wdt_notifier = {
+	.notifier_call = ubi32_wdt_notify_sys,
+};
+
+/*
+ * ubi32_wdt_probe()
+ * 	Probe/register the watchdog module
+ *
+ * Registers the misc device and notifier handler.  Actual device
+ * initialization is handled by ubi32_wdt_open().
+ */
+static int __devinit ubi32_wdt_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = register_reboot_notifier(&ubi32_wdt_notifier);
+	if (ret) {
+		printk(KERN_ERR PFX
+			"cannot register reboot notifier (err=%d)\n", ret);
+		return ret;
+	}
+
+	ret = misc_register(&ubi32_wdt_miscdev);
+	if (ret) {
+		printk(KERN_ERR PFX
+			"cannot register miscdev on minor=%d (err=%d)\n",
+				WATCHDOG_MINOR, ret);
+		unregister_reboot_notifier(&ubi32_wdt_notifier);
+		return ret;
+	}
+
+	printk(KERN_INFO PFX "initialized: timeout=%d sec (nowayout=%d)\n",
+	       timeout, nowayout);
+
+	return 0;
+}
+
+/*
+ * ubi32_wdt_remove()
+ * 	Uninstall the module
+ *
+ * Unregisters the misc device and notifier handler.  Actual device
+ * deinitialization is handled by ubi32_wdt_close().
+ */
+static int __devexit ubi32_wdt_remove(struct platform_device *pdev)
+{
+	misc_deregister(&ubi32_wdt_miscdev);
+	unregister_reboot_notifier(&ubi32_wdt_notifier);
+	return 0;
+}
+
+static struct platform_device *ubi32_wdt_device;
+
+static struct platform_driver ubi32_wdt_driver = {
+	.probe     = ubi32_wdt_probe,
+	.remove    = __devexit_p(ubi32_wdt_remove),
+	.suspend   = ubi32_wdt_suspend,
+	.resume    = ubi32_wdt_resume,
+	.driver    = {
+		.name  = WATCHDOG_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+
+/*
+ * ubi32_wdt_init()
+ * 	Initialize the watchdog.
+ *
+ * Checks the module params and registers the platform device & driver.
+ * Real work is in the platform probe function.
+ */
+static int __init ubi32_wdt_init(void)
+{
+	unsigned long flags;
+	int ret;
+
+	/*
+	 * Check that the timeout value is within range
+	 */
+	spin_lock_irqsave(&ubi32_wdt_spinlock, flags);
+	ret = ubi32_wdt_set_timeout(timeout);
+	spin_unlock_irqrestore(&ubi32_wdt_spinlock, flags);
+	if (ret) {
+		return ret;
+	}
+
+	/*
+	 * Since this is an on-chip device and needs no board-specific
+	 * resources, we'll handle all the platform device stuff here.
+	 */
+	ret = platform_driver_register(&ubi32_wdt_driver);
+	if (ret) {
+		printk(KERN_ERR PFX "unable to register driver\n");
+		return ret;
+	}
+
+	ubi32_wdt_device = platform_device_register_simple(WATCHDOG_NAME, -1, NULL, 0);
+	if (IS_ERR(ubi32_wdt_device)) {
+		printk(KERN_ERR PFX "unable to register device\n");
+		platform_driver_unregister(&ubi32_wdt_driver);
+		return PTR_ERR(ubi32_wdt_device);
+	}
+
+	return 0;
+}
+
+/*
+ * ubi32_wdt_exit()
+ * 	Deinitialize module
+ *
+ * Back out the platform device & driver steps.  Real work is in the
+ * platform remove function.
+ */
+static void __exit ubi32_wdt_exit(void)
+{
+	platform_device_unregister(ubi32_wdt_device);
+	platform_driver_unregister(&ubi32_wdt_driver);
+}
+
+module_init(ubi32_wdt_init);
+module_exit(ubi32_wdt_exit);
+
+MODULE_AUTHOR("Sol Kavy<sol@ubicom.com>");
+MODULE_DESCRIPTION("Ubicom32 Watchdog Device Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
+
+module_param(timeout, uint, 0);
+MODULE_PARM_DESC(timeout,
+	"Watchdog timeout in seconds. (1<=timeout<=((2^32)/SCLK), default="
+		__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
+
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout,
+	"Watchdog cannot be stopped once started (default="
+		__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -54,6 +54,10 @@
 #define	DBG_FLT(a...)
 #endif
 
+#ifndef ARCH_FLAT_ALIGN
+#define ARCH_FLAT_ALIGN 0
+#endif
+
 #define RELOC_FAILED 0xff00ff01		/* Relocation incorrect somewhere */
 #define UNLOADED_LIB 0x7ff000ff		/* Placeholder for unused library */
 
@@ -127,10 +131,10 @@ static unsigned long create_flat_tables(
 		--sp; put_user((unsigned long) argv, sp);
 	}
 
-	put_user(argc,--sp);
+	--sp; put_user(argc,sp);
 	current->mm->arg_start = (unsigned long) p;
 	while (argc-->0) {
-		put_user((unsigned long) p, argv++);
+		put_user((unsigned long) p, argv); argv++;
 		do {
 			get_user(dummy, p); p++;
 		} while (dummy);
@@ -425,6 +429,7 @@ static int load_flat_file(struct linux_b
 	loff_t fpos;
 	unsigned long start_code, end_code;
 	int ret;
+	int flush_happened = 0;
 
 	hdr = ((struct flat_hdr *) bprm->buf);		/* exec-header */
 	inode = bprm->file->f_path.dentry->d_inode;
@@ -510,6 +515,7 @@ static int load_flat_file(struct linux_b
 
 		/* OK, This is the point of no return */
 		set_personality(PER_LINUX_32BIT);
+		flush_happened = 1;
 	}
 
 	/*
@@ -524,6 +530,12 @@ static int load_flat_file(struct linux_b
 	 * it all together.
 	 */
 	if ((flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP)) == 0) {
+
+#ifdef ARCH_FLAT_ALIGN_TEXT
+		printk("Unable to mmap rom with ARCH alignment requirements\n");
+		ret = -ENOEXEC;
+		goto err;
+#endif
 		/*
 		 * this should give us a ROM ptr,  but if it doesn't we don't
 		 * really care
@@ -542,7 +554,7 @@ static int load_flat_file(struct linux_b
 			goto err;
 		}
 
-		len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = data_len + extra + ALIGN(MAX_SHARED_LIBS * sizeof(unsigned long), ARCH_FLAT_ALIGN);
 		down_write(&current->mm->mmap_sem);
 		realdatastart = do_mmap(0, 0, len,
 			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
@@ -565,7 +577,7 @@ static int load_flat_file(struct linux_b
 			ret = realdatastart;
 			goto err;
 		}
-		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
+		datapos = realdatastart + ALIGN(MAX_SHARED_LIBS * sizeof(unsigned long), ARCH_FLAT_ALIGN);
 
 		DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
 				(int)(data_len + bss_len + stack_len), (int)datapos);
@@ -594,7 +606,11 @@ static int load_flat_file(struct linux_b
 
 	} else {
 
-		len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = text_len + data_len + extra + ALIGN(MAX_SHARED_LIBS * sizeof(unsigned long), ARCH_FLAT_ALIGN);
+#ifdef ARCH_FLAT_ALIGN_TEXT
+		/* Reserve space for the text alignment. */
+		len += ARCH_FLAT_ALIGN;
+#endif
 		down_write(&current->mm->mmap_sem);
 		textpos = do_mmap(0, 0, len,
 			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
@@ -617,11 +633,14 @@ static int load_flat_file(struct linux_b
 			goto err;
 		}
 
+		memp = textpos;
+#ifdef ARCH_FLAT_ALIGN_TEXT
+		textpos = ALIGN(textpos + sizeof(struct flat_hdr), ARCH_FLAT_ALIGN) - sizeof(struct flat_hdr);
+#endif
 		realdatastart = textpos + ntohl(hdr->data_start);
-		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
+		datapos = realdatastart + ALIGN(MAX_SHARED_LIBS * sizeof(unsigned long), ARCH_FLAT_ALIGN);
 		reloc = (unsigned long *) (textpos + ntohl(hdr->reloc_start) +
-				MAX_SHARED_LIBS * sizeof(unsigned long));
-		memp = textpos;
+					   ALIGN(MAX_SHARED_LIBS * sizeof(unsigned long), ARCH_FLAT_ALIGN));
 
 #ifdef CONFIG_BINFMT_ZFLAT
 		/*
@@ -657,7 +676,7 @@ static int load_flat_file(struct linux_b
 		}
 		if (result >= (unsigned long)-4096) {
 			printk("Unable to read code+data+bss, errno %d\n",(int)-result);
-			do_munmap(current->mm, textpos, text_len + data_len + extra +
+			do_munmap(current->mm, memp, text_len + data_len + extra +
 				MAX_SHARED_LIBS * sizeof(unsigned long));
 			ret = result;
 			goto err;
@@ -670,6 +689,9 @@ static int load_flat_file(struct linux_b
 
 	/* The main program needs a little extra setup in the task structure */
 	start_code = textpos + sizeof (struct flat_hdr);
+#ifdef ARCH_FLAT_ALIGN_TEXT
+	BUG_ON(ALIGN(start_code, ARCH_FLAT_ALIGN) != start_code);
+#endif
 	end_code = textpos + text_len;
 	if (id == 0) {
 		current->mm->start_code = start_code;
@@ -796,6 +818,13 @@ static int load_flat_file(struct linux_b
 
 	return 0;
 err:
+	if (flush_happened) {
+		/*
+		 * The parent process has already started running. We cannot allow the child to return back to user space
+		 * as this child is still uning the parent stack and 2 will clobber each other. We are going to kill this child.
+		 */
+		do_exit(SIGTERM);
+	}
 	return ret;
 }
 
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -30,7 +30,7 @@ config COMPAT_BINFMT_ELF
 config BINFMT_ELF_FDPIC
 	bool "Kernel support for FDPIC ELF binaries"
 	default y
-	depends on (FRV || BLACKFIN || (SUPERH32 && !MMU))
+	depends on (FRV || BLACKFIN || (SUPERH32 && !MMU) || UBICOM32)
 	help
 	  ELF FDPIC binaries are based on ELF, but allow the individual load
 	  segments of a binary to be located in memory independently of each
--- a/include/asm-generic/dma-mapping.h
+++ b/include/asm-generic/dma-mapping.h
@@ -255,7 +255,7 @@ dma_sync_sg_for_device(struct device *de
 }
 
 static inline int
-dma_error(dma_addr_t dma_addr)
+dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {
 	return 0;
 }
--- a/include/linux/elf-em.h
+++ b/include/linux/elf-em.h
@@ -41,6 +41,7 @@
  * up with a final number.
  */
 #define EM_ALPHA	0x9026
+#define EM_UBICOM32 	        0xde3d	/* Ubicom32; no ABI */
 
 /* Bogus old v850 magic number, used by old tools. */
 #define EM_CYGNUS_V850	0x9080
--- a/include/linux/oprofile.h
+++ b/include/linux/oprofile.h
@@ -100,6 +100,8 @@ void oprofile_add_sample(struct pt_regs 
  */
 void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
 				unsigned long event, int is_kernel);
+void oprofile_add_ext_sample_cpu(unsigned long pc, struct pt_regs * const regs,
+				unsigned long event, int is_kernel, int cpu);
 
 /* Use this instead when the PC value is not from the regs. Doesn't
  * backtrace. */
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -158,6 +158,9 @@
 /* SH-SCI */
 #define PORT_SCIFA	83
 
+/* Ubicom32 */
+#define PORT_UBI32_UARTTIO	84
+
 #ifdef __KERNEL__
 
 #include <linux/compiler.h>
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2624,6 +2624,9 @@ static int m_show(struct seq_file *m, vo
 	/* Used by oprofile and other similar tools. */
 	seq_printf(m, " 0x%p", mod->module_core);
 
+#ifdef ARCH_PROC_MODULES_EXTRA
+	ARCH_PROC_MODULES_EXTRA(m, mod);
+#endif
 	/* Taints info */
 	if (mod->taints)
 		seq_printf(m, " %s", module_flags(mod, buf));
--- a/kernel/sched_clock.c
+++ b/kernel/sched_clock.c
@@ -37,7 +37,7 @@
  */
 unsigned long long __attribute__((weak)) sched_clock(void)
 {
-	return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
+	return (get_jiffies_64() - INITIAL_JIFFIES) * (NSEC_PER_SEC / HZ);
 }
 
 static __read_mostly int sched_clock_running;
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -549,7 +549,7 @@ config FRAME_POINTER
 	bool "Compile the kernel with frame pointers"
 	depends on DEBUG_KERNEL && \
 		(X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || \
-		 AVR32 || SUPERH || BLACKFIN || MN10300)
+		 AVR32 || SUPERH || BLACKFIN || MN10300 || UBICOM32)
 	default y if DEBUG_INFO && UML
 	help
 	  If you say Y here the resulting kernel image will be slightly larger
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -34,3 +34,5 @@ obj-$(CONFIG_MIGRATION) += migrate.o
 obj-$(CONFIG_SMP) += allocpercpu.o
 obj-$(CONFIG_QUICKLIST) += quicklist.o
 obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o
+
+CFLAGS_slab.o := $(PROFILING) -O2
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -753,6 +753,15 @@ void handle_moddevtable(struct module *m
 			+ sym->st_value;
 	}
 
+	/*
+ 	 * somehow our gcc is not generating st_size correctly and set 0 for some symbols.
+ 	 * and 0 size will break do_table since it adjust size to (size - id_size)
+ 	 * this is to make sure st_size fall in range.
+ 	 */
+	if (sym->st_size == 0 || sym->st_size > info->sechdrs[sym->st_shndx].sh_size) {
+		sym->st_size = info->sechdrs[sym->st_shndx].sh_size;
+	}
+
 	if (sym_is(symname, "__mod_pci_device_table"))
 		do_table(symval, sym->st_size,
 			 sizeof(struct pci_device_id), "pci",
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -80,6 +80,8 @@ source "sound/parisc/Kconfig"
 
 source "sound/soc/Kconfig"
 
+source "sound/ubicom32/Kconfig"
+
 endif # SND
 
 menuconfig SOUND_PRIME
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmw
 obj-$(CONFIG_SOUND_PRIME) += oss/
 obj-$(CONFIG_DMASOUND) += oss/
 obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
-	sparc/ spi/ parisc/ pcmcia/ mips/ soc/
+	sparc/ spi/ parisc/ pcmcia/ mips/ soc/ ubicom32/
 obj-$(CONFIG_SND_AOA) += aoa/
 
 # This one must be compilable even if sound is configured out
--- /dev/null
+++ b/sound/ubicom32/Kconfig
@@ -0,0 +1,36 @@
+# ALSA Ubicom32 drivers
+
+menuconfig SND_UBI32
+	tristate "Ubicom32 sound devices"
+	select SND_PCM
+	default n
+	help
+	  Say Y here to include support for audio on the Ubicom32 platform.
+	  To compile this driver as a module, say M here: the module will be
+	  called snd_ubi32.
+	  
+if SND_UBI32
+
+config SND_UBI32_AUDIO_GENERIC
+	bool "Generic Codec Support"
+	default n
+	help
+	  Generic codecs
+
+comment "I2C Based Codecs"
+
+config SND_UBI32_AUDIO_CS4350
+	bool "Cirrus Logic CS4350 DAC"
+	depends on I2C
+	default n
+	help
+	  Support for the Cirrus Logic CS4350 DAC.
+
+config SND_UBI32_AUDIO_CS4384
+	bool "Cirrus Logic CS4384 DAC"
+	depends on I2C
+	default n
+	help
+	  Support for the Cirrus Logic CS4384 DAC.
+
+endif #SND_UBI32
--- /dev/null
+++ b/sound/ubicom32/Makefile
@@ -0,0 +1,39 @@
+#
+# sound/ubicom32/Makefile
+#	Makefile for ALSA
+#
+# (C) Copyright 2009, Ubicom, Inc.
+#
+# This file is part of the Ubicom32 Linux Kernel Port.
+#
+# The Ubicom32 Linux Kernel Port is free software: you can redistribute
+# it and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 2 of the
+# License, or (at your option) any later version.
+#
+# The Ubicom32 Linux Kernel Port is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Ubicom32 Linux Kernel Port.  If not, 
+# see <http://www.gnu.org/licenses/>.
+#
+# Ubicom32 implementation derived from (with many thanks):
+#   arch/m68knommu
+#   arch/blackfin
+#   arch/parisc
+#
+
+CFLAGS_ubi32.o += -O2
+snd-ubi32-pcm-objs := ubi32-pcm.o
+snd-ubi32-generic-objs := ubi32-generic.o
+snd-ubi32-cs4350-objs := ubi32-cs4350.o
+snd-ubi32-cs4384-objs := ubi32-cs4384.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_UBI32) += snd-ubi32-pcm.o
+obj-$(CONFIG_SND_UBI32_AUDIO_GENERIC) += snd-ubi32-generic.o
+obj-$(CONFIG_SND_UBI32_AUDIO_CS4350) += snd-ubi32-cs4350.o
+obj-$(CONFIG_SND_UBI32_AUDIO_CS4384) += snd-ubi32-cs4384.o
--- /dev/null
+++ b/sound/ubicom32/ubi32-cs4350.c
@@ -0,0 +1,286 @@
+/*
+ * sound/ubicom32/ubi32-cs4350.c
+ *	Interface to ubicom32 virtual audio peripheral - using CS4350 DAC
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include "ubi32.h"
+
+#define DRIVER_NAME "snd-ubi32-cs4350"
+
+/*
+ * Module properties
+ */
+static const struct i2c_device_id snd_ubi32_cs4350_id[] = {
+	{"cs4350", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ubicom32audio_id);
+
+static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
+
+/*
+ * snd_ubi32_cs4350_free
+ *	Card private data free function
+ */
+void snd_ubi32_cs4350_free(struct snd_card *card)
+{
+	//struct ubi32_snd_priv *ubi32_priv = card->private_data;
+
+	/*
+	 * Free all the fields in the snd_ubi32_priv struct
+	 */
+	// Nothing to free at this time because ubi32_priv just maintains pointers
+}
+
+/*
+ * snd_ubi32_cs4350_dac_init
+ */
+static int snd_ubi32_cs4350_dac_init(struct i2c_client *client, const struct i2c_device_id *id)
+{
+	int ret;
+	char send[2];
+	char recv[8];
+
+	/*
+	 * Initialize the CS4350 DAC over the I2C interface
+	 */
+	snd_printk(KERN_INFO "Initializing CS4350 DAC\n");
+
+	/*
+	 * Register 0x01: device/revid
+	 */
+	send[0] = 0x01;
+	ret = i2c_master_send(client, send, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed 1st attempt to write to CS4350 register 0x01\n");
+		goto fail;
+	}
+	ret = i2c_master_recv(client, recv, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed initial read of CS4350 registers\n");
+		goto fail;
+	}
+	snd_printk(KERN_INFO "CS4350 DAC Device/Rev: %08x\n", recv[0]);
+
+	/*
+	 * Register 0x02: Mode control
+	 *	I2S DIF[2:0] = 001, no De-Emphasis, Auto speed mode
+	 */
+	send[0] = 0x02;
+	send[1] = 0x10;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set CS4350 to I2S mode\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 0x05/0x06: Volume control
+	 *	Channel A volume set to -16 dB
+	 *	Channel B volume set to -16 dB
+	 */
+	send[0] = 0x05;
+	send[1] = 0x00;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set channel A volume on CS4350\n");
+		goto fail;
+	}
+
+	send[0] = 0x06;
+	send[1] = 0x00;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set channel A volume on CS4350\n");
+		goto fail;
+	}
+
+	/*
+	 * Make sure the changes took place, this helps verify we are talking to
+	 * the correct chip.
+	 */
+	send[0] = 0x81;
+	ret = i2c_master_send(client, send, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed to initiate readback\n");
+		goto fail;
+	}
+
+	ret = i2c_master_recv(client, recv, 8);
+	if (ret != 8) {
+		snd_printk(KERN_ERR "Failed second read of CS4350 registers\n");
+		goto fail;
+	}
+
+	if ((recv[1] != 0x10) || (recv[4] != 0x00) || (recv[5] != 0x00)) {
+		snd_printk(KERN_ERR "Failed to initialize CS4350 DAC\n");
+		goto fail;
+	}
+		       
+	snd_printk(KERN_INFO "CS4350 DAC Initialized\n");
+	return 0;
+
+fail:
+	return -ENODEV;
+}
+
+/*
+ * snd_ubi32_cs4350_i2c_probe
+ */
+static int snd_ubi32_cs4350_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+	int err, ret;
+	struct platform_device *pdev;
+
+	pdev = client->dev.platform_data;
+	if (!pdev) {
+		return -ENODEV;
+	}
+
+	/*
+	 * Initialize the CS4350 DAC
+	 */
+	ret = snd_ubi32_cs4350_dac_init(client, id);
+	if (ret < 0) {
+		/*
+		 * Initialization failed.  Propagate the error.
+		 */
+		return ret;
+	}
+
+	/*
+	 * Create a snd_card structure
+	 */
+	card = snd_card_new(index, "Ubi32-CS4350", THIS_MODULE, sizeof(struct ubi32_snd_priv));
+	if (card == NULL) {
+		return -ENOMEM;
+	}
+
+	card->private_free = snd_ubi32_cs4350_free; /* Not sure if correct */
+	ubi32_priv = card->private_data;
+
+	/*
+	 * CS4350 DAC has a minimum sample rate of 30khz and an
+	 * upper limit of 216khz for it's auto-detect.
+	 */
+	ubi32_priv->min_sample_rate = 30000;
+	ubi32_priv->max_sample_rate = 216000;
+
+	/*
+	 * Initialize the snd_card's private data structure
+	 */
+	ubi32_priv->card = card;
+
+	/*
+	 * Create the new PCM instance
+	 */
+	err = snd_ubi32_pcm_probe(ubi32_priv, pdev);
+	if (err < 0) {
+		snd_card_free(card);
+		return err; /* What is err?  Need to include correct file */
+	}
+
+	strcpy(card->driver, "Ubi32-CS4350");
+	strcpy(card->shortname, "Ubi32-CS4350");
+	sprintf(card->longname, "%s at sendirq=%d recvirq=%d", card->shortname, ubi32_priv->tx_irq, ubi32_priv->rx_irq);
+
+	snd_card_set_dev(card, &client->dev);
+
+	/*
+	 * Register the sound card 
+	 */
+	if ((err = snd_card_register(card)) != 0) {
+		snd_printk(KERN_INFO "snd_card_register error\n");
+	}
+
+	/* 
+	 * Store card for access from other methods 
+	 */
+	i2c_set_clientdata(client, card);
+
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4350_i2c_remove
+ */
+static int __devexit snd_ubi32_cs4350_i2c_remove(struct i2c_client *client)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+
+	card = i2c_get_clientdata(client);
+
+	ubi32_priv = card->private_data;
+	snd_ubi32_pcm_remove(ubi32_priv);
+
+	snd_card_free(i2c_get_clientdata(client));
+	i2c_set_clientdata(client, NULL);
+
+	return 0;
+}
+
+/*
+ * I2C driver description
+ */
+static struct i2c_driver snd_ubi32_cs4350_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.id_table	= snd_ubi32_cs4350_id,
+	.probe		= snd_ubi32_cs4350_i2c_probe,
+	.remove		= __devexit_p(snd_ubi32_cs4350_i2c_remove),
+};
+
+/*
+ * Driver init
+ */
+static int __init snd_ubi32_cs4350_init(void)
+{
+	return i2c_add_driver(&snd_ubi32_cs4350_driver);
+}
+module_init(snd_ubi32_cs4350_init);
+
+/*
+ * snd_ubi32_cs4350_exit
+ */
+static void __exit snd_ubi32_cs4350_exit(void)
+{
+	i2c_del_driver(&snd_ubi32_cs4350_driver);
+}
+module_exit(snd_ubi32_cs4350_exit);
+
+/*
+ * Module properties
+ */
+MODULE_ALIAS("i2c:" DRIVER_NAME);
+MODULE_AUTHOR("Patrick Tjin");
+MODULE_DESCRIPTION("Driver for Ubicom32 audio devices CS4350");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/sound/ubicom32/ubi32-cs4384.c
@@ -0,0 +1,982 @@
+/*
+ * sound/ubicom32/ubi32-cs4384.c
+ *	Interface to ubicom32 virtual audio peripheral - using CS4384 DAC
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/delay.h>
+#include <sound/core.h>
+#include <sound/tlv.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <asm/ip5000.h>
+#include <asm/gpio.h>
+#include <asm/audio_tio.h>
+#include <asm/ubi32-cs4384.h>
+#include "ubi32.h"
+
+#define DRIVER_NAME "snd-ubi32-cs4384"
+
+/*
+ * Module properties
+ */
+static const struct i2c_device_id snd_ubi32_cs4384_id[] = {
+	{"cs4384", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ubicom32audio_id);
+
+static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
+
+/*
+ * Mixer properties
+ */
+enum {
+	/*
+	 * Be careful of changing the order of these IDs, they
+	 * are used to index the volume array.
+	 */
+	SND_UBI32_CS4384_FRONT_ID,
+	SND_UBI32_CS4384_SURROUND_ID,
+	SND_UBI32_CS4384_CENTER_ID,
+	SND_UBI32_CS4384_LFE_ID,
+	SND_UBI32_CS4384_REAR_ID,
+
+	/*
+	 * This should be the last ID
+	 */
+	SND_UBI32_CS4384_LAST_ID,
+};
+static const u8_t snd_ubi32_cs4384_ch_ofs[] = {0, 2, 4, 5, 6};
+
+static const DECLARE_TLV_DB_SCALE(snd_ubi32_cs4384_db, -12750, 50, 0);
+
+#define snd_ubi32_cs4384_info_mute 	snd_ctl_boolean_stereo_info
+#define snd_ubi32_cs4384_info_mute_mono	snd_ctl_boolean_mono_info
+
+/*
+ * Mixer controls
+ */
+static int snd_ubi32_cs4384_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
+static int snd_ubi32_cs4384_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
+static int snd_ubi32_cs4384_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
+static int snd_ubi32_cs4384_get_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
+static int snd_ubi32_cs4384_put_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
+
+/*
+ * Make sure to update these if the structure below is changed
+ */
+#define SND_UBI32_MUTE_CTL_START	5
+#define SND_UBI32_MUTE_CTL_END		9
+static struct snd_kcontrol_new snd_ubi32_cs4384_controls[] __devinitdata = {
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Front Playback Volume",
+		.info = snd_ubi32_cs4384_info_volume,
+		.get = snd_ubi32_cs4384_get_volume,
+		.put = snd_ubi32_cs4384_put_volume,
+		.private_value = SND_UBI32_CS4384_FRONT_ID,
+		.tlv = {
+			.p = snd_ubi32_cs4384_db,
+		},
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Surround Playback Volume",
+		.info = snd_ubi32_cs4384_info_volume,
+		.get = snd_ubi32_cs4384_get_volume,
+		.put = snd_ubi32_cs4384_put_volume,
+		.private_value = SND_UBI32_CS4384_SURROUND_ID,
+		.tlv = {
+			.p = snd_ubi32_cs4384_db,
+		},
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Center Playback Volume",
+		.info = snd_ubi32_cs4384_info_volume,
+		.get = snd_ubi32_cs4384_get_volume,
+		.put = snd_ubi32_cs4384_put_volume,
+		.private_value = SND_UBI32_CS4384_CENTER_ID,
+		.tlv = {
+			.p = snd_ubi32_cs4384_db,
+		},
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "LFE Playback Volume",
+		.info = snd_ubi32_cs4384_info_volume,
+		.get = snd_ubi32_cs4384_get_volume,
+		.put = snd_ubi32_cs4384_put_volume,
+		.private_value = SND_UBI32_CS4384_LFE_ID,
+		.tlv = {
+			.p = snd_ubi32_cs4384_db,
+		},
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Rear Playback Volume",
+		.info = snd_ubi32_cs4384_info_volume,
+		.get = snd_ubi32_cs4384_get_volume,
+		.put = snd_ubi32_cs4384_put_volume,
+		.private_value = SND_UBI32_CS4384_REAR_ID,
+		.tlv = {
+			.p = snd_ubi32_cs4384_db,
+		},
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Front Playback Switch",
+		.info = snd_ubi32_cs4384_info_mute,
+		.get = snd_ubi32_cs4384_get_mute,
+		.put = snd_ubi32_cs4384_put_mute,
+		.private_value = SND_UBI32_CS4384_FRONT_ID,
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Surround Playback Switch",
+		.info = snd_ubi32_cs4384_info_mute,
+		.get = snd_ubi32_cs4384_get_mute,
+		.put = snd_ubi32_cs4384_put_mute,
+		.private_value = SND_UBI32_CS4384_SURROUND_ID,
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Center Playback Switch",
+		.info = snd_ubi32_cs4384_info_mute_mono,
+		.get = snd_ubi32_cs4384_get_mute,
+		.put = snd_ubi32_cs4384_put_mute,
+		.private_value = SND_UBI32_CS4384_CENTER_ID,
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "LFE Playback Switch",
+		.info = snd_ubi32_cs4384_info_mute_mono,
+		.get = snd_ubi32_cs4384_get_mute,
+		.put = snd_ubi32_cs4384_put_mute,
+		.private_value = SND_UBI32_CS4384_LFE_ID,
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+		.name = "Rear Playback Switch",
+		.info = snd_ubi32_cs4384_info_mute,
+		.get = snd_ubi32_cs4384_get_mute,
+		.put = snd_ubi32_cs4384_put_mute,
+		.private_value = SND_UBI32_CS4384_REAR_ID,
+	},
+};
+
+/*
+ * Our private data
+ */
+struct snd_ubi32_cs4384_priv {
+	/*
+	 * Array of current volumes
+	 *	(L, R, SL, SR, C, LFE, RL, RR)
+	 */
+	uint8_t	volume[8];
+
+	/*
+	 * Bitmask of mutes
+	 *	MSB (RR, RL, LFE, C, SR, SL, R, L) LSB
+	 */
+	uint8_t mute;
+
+	/*
+	 * Array of controls
+	 */
+	struct snd_kcontrol *kctls[ARRAY_SIZE(snd_ubi32_cs4384_controls)];
+
+	/*
+	 * Lock to protect our card
+	 */
+	spinlock_t lock;
+};
+
+/*
+ * snd_ubi32_cs4384_info_volume
+ */
+static int snd_ubi32_cs4384_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+	unsigned int id = (unsigned int)kcontrol->private_value;
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 1;
+	if ((id != SND_UBI32_CS4384_LFE_ID) && 
+	    (id != SND_UBI32_CS4384_CENTER_ID)) {
+		uinfo->count = 2;
+	}
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 255;
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_get_volume
+ */
+static int snd_ubi32_cs4384_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	unsigned int id = (unsigned int)kcontrol->private_value;
+	int ch = snd_ubi32_cs4384_ch_ofs[id];
+	unsigned long flags;
+
+	if (id >= SND_UBI32_CS4384_LAST_ID) {
+		return -EINVAL;
+	}
+
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+
+	spin_lock_irqsave(&cs4384_priv->lock, flags);
+
+	ucontrol->value.integer.value[0] = cs4384_priv->volume[ch];
+	if ((id != SND_UBI32_CS4384_LFE_ID) && 
+	    (id != SND_UBI32_CS4384_CENTER_ID)) {
+		ch++;
+		ucontrol->value.integer.value[1] = cs4384_priv->volume[ch];
+	}
+
+	spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_put_volume
+ */
+static int snd_ubi32_cs4384_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
+	struct i2c_client *client = (struct i2c_client *)priv->client;
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	unsigned int id = (unsigned int)kcontrol->private_value;
+	int ch = snd_ubi32_cs4384_ch_ofs[id];
+	unsigned long flags;
+	unsigned char send[3];
+	int nch;
+	int ret = -EINVAL;
+
+	if (id >= SND_UBI32_CS4384_LAST_ID) {
+		return -EINVAL;
+	}
+
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+
+	spin_lock_irqsave(&cs4384_priv->lock, flags);
+
+	send[0] = 0;
+	switch (id) {
+	case SND_UBI32_CS4384_REAR_ID:
+		send[0] = 0x06;
+
+		/*
+		 * Fall through
+		 */
+
+	case SND_UBI32_CS4384_SURROUND_ID:
+		send[0] += 0x03;
+
+		/*
+		 * Fall through
+		 */
+
+	case SND_UBI32_CS4384_FRONT_ID:
+		send[0] += 0x8B;
+		nch = 2;
+		send[1] = 255 - (ucontrol->value.integer.value[0] & 0xFF);
+		send[2] = 255 - (ucontrol->value.integer.value[1] & 0xFF);
+		cs4384_priv->volume[ch++] = send[1];
+		cs4384_priv->volume[ch] = send[2];
+		break;
+
+	case SND_UBI32_CS4384_LFE_ID:
+		send[0] = 0x81;
+
+		/*
+		 * Fall through
+		 */
+
+	case SND_UBI32_CS4384_CENTER_ID:
+		send[0] += 0x11;
+		nch = 1;
+		send[1] = 255 - (ucontrol->value.integer.value[0] & 0xFF);
+		cs4384_priv->volume[ch] = send[1];
+		break;
+
+	default:
+		spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+		goto done;
+
+	}
+
+	/*
+	 * Send the volume to the chip
+	 */
+	nch++;
+	ret = i2c_master_send(client, send, nch);
+	if (ret != nch) {
+		snd_printk(KERN_ERR "Failed to set volume on CS4384\n");
+	}
+
+done:
+	spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+
+	return ret;
+}
+
+/*
+ * snd_ubi32_cs4384_get_mute
+ */
+static int snd_ubi32_cs4384_get_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	unsigned int id = (unsigned int)kcontrol->private_value;
+	int ch = snd_ubi32_cs4384_ch_ofs[id];
+	unsigned long flags;
+
+	if (id >= SND_UBI32_CS4384_LAST_ID) {
+		return -EINVAL;
+	}
+
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+
+	spin_lock_irqsave(&cs4384_priv->lock, flags);
+
+	ucontrol->value.integer.value[0] = !(cs4384_priv->mute & (1 << ch));
+
+	if ((id != SND_UBI32_CS4384_LFE_ID) && 
+	    (id != SND_UBI32_CS4384_CENTER_ID)) {
+		ch++;
+		ucontrol->value.integer.value[1] = !(cs4384_priv->mute & (1 << ch));
+	}
+
+	spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_put_mute
+ */
+static int snd_ubi32_cs4384_put_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
+	struct i2c_client *client = (struct i2c_client *)priv->client;
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	unsigned int id = (unsigned int)kcontrol->private_value;
+	int ch = snd_ubi32_cs4384_ch_ofs[id];
+	unsigned long flags;
+	unsigned char send[2];
+	int ret = -EINVAL;
+
+	if (id >= SND_UBI32_CS4384_LAST_ID) {
+		return -EINVAL;
+	}
+
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+
+	spin_lock_irqsave(&cs4384_priv->lock, flags);
+
+	if (ucontrol->value.integer.value[0]) {
+		cs4384_priv->mute &= ~(1 << ch);
+	} else {
+		cs4384_priv->mute |= (1 << ch);
+	}
+
+	if ((id != SND_UBI32_CS4384_LFE_ID) && (id != SND_UBI32_CS4384_CENTER_ID)) {
+		ch++;
+		if (ucontrol->value.integer.value[1]) {
+			cs4384_priv->mute &= ~(1 << ch);
+		} else {
+			cs4384_priv->mute |= (1 << ch);
+		}
+	}
+
+	/*
+	 * Update the chip's mute reigster
+	 */
+	send[0] = 0x09;
+	send[1] = cs4384_priv->mute;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set mute on CS4384\n");
+	}
+
+	spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+
+	return ret;
+}
+
+/*
+ * snd_ubi32_cs4384_mixer
+ *	Setup the mixer controls
+ */
+static int __devinit snd_ubi32_cs4384_mixer(struct ubi32_snd_priv *priv)
+{
+	struct snd_card *card = priv->card;
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	int i;
+	
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+	for (i = 0; i < ARRAY_SIZE(snd_ubi32_cs4384_controls); i++) {
+		int err;
+
+		cs4384_priv->kctls[i] = snd_ctl_new1(&snd_ubi32_cs4384_controls[i], priv);
+		err = snd_ctl_add(card, cs4384_priv->kctls[i]);
+		if (err) {
+			snd_printk(KERN_WARNING "Failed to add control %d\n", i);
+			return err;
+		}
+	}
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_free
+ *	Card private data free function
+ */
+void snd_ubi32_cs4384_free(struct snd_card *card)
+{
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	struct ubi32_snd_priv *ubi32_priv;
+	
+	ubi32_priv = card->private_data;
+	cs4384_priv = snd_ubi32_priv_get_drv(ubi32_priv);
+	if (cs4384_priv) {
+		kfree(cs4384_priv);
+	}
+}
+
+/*
+ * snd_ubi32_cs4384_setup_mclk
+ */
+static int snd_ubi32_cs4384_setup_mclk(struct ubi32_cs4384_platform_data *pdata)
+{
+	struct ubicom32_io_port *ioa = (struct ubicom32_io_port *)RA;
+	struct ubicom32_io_port *ioc = (struct ubicom32_io_port *)RC;
+	struct ubicom32_io_port *ioh = (struct ubicom32_io_port *)RH;
+	unsigned int ctl0;
+	unsigned int ctlx;
+	unsigned int div;
+
+	div = pdata->mclk_entries[0].div;
+
+	ctl0 = (1 << 13);
+	ctlx = ((div - 1) << 16) | (div / 2);
+
+	switch (pdata->mclk_src) {
+	case UBI32_CS4384_MCLK_PWM_0:
+		ioc->function |= 2;
+		ioc->ctl0 |= ctl0;
+		ioc->ctl1 = ctlx;
+		return 0;
+
+	case UBI32_CS4384_MCLK_PWM_1:
+		ioc->function |= 2;
+		ioc->ctl0 |= ctl0 << 16;
+		ioc->ctl2 = ctlx;
+		return 0;
+
+	case UBI32_CS4384_MCLK_PWM_2:
+		ioh->ctl0 |= ctl0;
+		ioh->ctl1 = ctlx;
+		return 0;
+
+	case UBI32_CS4384_MCLK_CLKDIV_1:
+		ioa->gpio_mask &= (1 << 7);
+		ioa->ctl1 &= ~(0x7F << 14);
+		ioa->ctl1 |= ((div - 1) << 14);
+		return 0;
+
+	case UBI32_CS4384_MCLK_OTHER:
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
+ * snd_ubi32_cs4384_set_rate
+ */
+static int snd_ubi32_cs4384_set_rate(struct ubi32_snd_priv *priv, int rate)
+{
+	struct ubi32_cs4384_platform_data *cpd = priv->pdata->priv_data;
+	struct ubicom32_io_port *ioa = (struct ubicom32_io_port *)RA;
+	struct ubicom32_io_port *ioc = (struct ubicom32_io_port *)RC;
+	struct ubicom32_io_port *ioh = (struct ubicom32_io_port *)RH;
+	unsigned int ctl;
+	unsigned int div = 0;
+	const u16_t mult[] = {64, 96, 128, 192, 256, 384, 512, 768, 1024};
+	int i;
+	int j;
+	
+
+	for (i = 0; i < sizeof(mult) / sizeof(u16_t); i++) {
+		for (j = 0; j < cpd->n_mclk; j++) {
+			if (((unsigned int)rate * (unsigned int)mult[i]) == 
+			     cpd->mclk_entries[j].rate) {
+				div = cpd->mclk_entries[j].div;
+				break;
+			}
+		}
+	}
+
+	ctl = ((div - 1) << 16) | (div / 2);
+
+	switch (cpd->mclk_src) {
+	case UBI32_CS4384_MCLK_PWM_0:
+		ioc->ctl1 = ctl;
+		return 0;
+
+	case UBI32_CS4384_MCLK_PWM_1:
+		ioc->ctl2 = ctl;
+		return 0;
+
+	case UBI32_CS4384_MCLK_PWM_2:
+		ioh->ctl1 = ctl;
+		return 0;
+
+	case UBI32_CS4384_MCLK_CLKDIV_1:
+		ioa->ctl1 &= ~(0x7F << 14);
+		ioa->ctl1 |= ((div - 1) << 14);
+		return 0;
+
+	case UBI32_CS4384_MCLK_OTHER:
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
+ * snd_ubi32_cs4384_set_channels
+ *	Mute unused channels
+ */
+static int snd_ubi32_cs4384_set_channels(struct ubi32_snd_priv *priv, int channels)
+{
+	struct i2c_client *client = (struct i2c_client *)priv->client;
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+	unsigned char send[2];
+	int ret;
+	int i;
+	unsigned long flags;
+
+	/*
+	 * Only support 0, 2, 4, 6, 8 channels
+	 */
+	if ((channels > 8) || (channels & 1)) {
+		return -EINVAL;
+	}
+
+	cs4384_priv = snd_ubi32_priv_get_drv(priv);
+	spin_lock_irqsave(&cs4384_priv->lock, flags);
+
+	/*
+	 * Address 09h, Mute control
+	 */
+	send[0] = 0x09;
+	send[1] = (unsigned char)(0xFF << channels);
+
+	ret = i2c_master_send(client, send, 2);
+
+	spin_unlock_irqrestore(&cs4384_priv->lock, flags);
+
+	/*
+	 * Notify the system that we changed the mutes
+	 */
+	cs4384_priv->mute = (unsigned char)(0xFF << channels);
+
+	for (i = SND_UBI32_MUTE_CTL_START; i < SND_UBI32_MUTE_CTL_END; i++) {
+		snd_ctl_notify(priv->card, SNDRV_CTL_EVENT_MASK_VALUE,
+			       &cs4384_priv->kctls[i]->id);
+	}
+
+	if (ret != 2) {
+		return -ENXIO;
+	}
+
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_dac_init
+ */
+static int snd_ubi32_cs4384_dac_init(struct i2c_client *client, const struct i2c_device_id *id)
+{
+	int ret;
+	unsigned char send[2];
+	unsigned char recv[2];
+
+	/*
+	 * Initialize the CS4384 DAC over the I2C interface
+	 */
+	snd_printk(KERN_INFO "Initializing CS4384 DAC\n");
+
+	/*
+	 * Register 0x01: device/revid
+	 */
+	send[0] = 0x01;
+	ret = i2c_master_send(client, send, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed 1st attempt to write to CS4384 register 0x01\n");
+		goto fail;
+	}
+	ret = i2c_master_recv(client, recv, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed initial read of CS4384 registers\n");
+		goto fail;
+	}
+	snd_printk(KERN_INFO "CS4384 DAC Device/Rev: %08x\n", recv[0]);
+
+	/*
+	 * Register 0x02: Mode Control 1
+	 *	Control Port Enable, PCM, All DACs enabled, Power Down
+	 */
+	send[0] = 0x02;
+	send[1] = 0x81;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set CPEN CS4384\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 0x08: Ramp and Mute
+	 *	RMP_UP, RMP_DN, PAMUTE, DAMUTE
+	 */
+	send[0] = 0x08;
+	send[1] = 0xBC;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set CPEN CS4384\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 0x03: PCM Control
+	 *	I2S DIF[3:0] = 0001, no De-Emphasis, Auto speed mode
+	 */
+	send[0] = 0x03;
+	send[1] = 0x13;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to set CS4384 to I2S mode\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 0x0B/0x0C: Volume control A1/B1
+	 * Register 0x0E/0x0F: Volume control A2/B2
+	 * Register 0x11/0x12: Volume control A3/B3
+	 * Register 0x14/0x15: Volume control A4/B4
+	 */
+	send[0] = 0x80 | 0x0B;
+	send[1] = 0x00;
+	send[2] = 0x00;
+	ret = i2c_master_send(client, send, 3);
+	if (ret != 3) {
+		snd_printk(KERN_ERR "Failed to set ch1 volume on CS4384\n");
+		goto fail;
+	}
+
+	send[0] = 0x80 | 0x0E;
+	send[1] = 0x00;
+	send[2] = 0x00;
+	ret = i2c_master_send(client, send, 3);
+	if (ret != 3) {
+		snd_printk(KERN_ERR "Failed to set ch2 volume on CS4384\n");
+		goto fail;
+	}
+
+	send[0] = 0x80 | 0x11;
+	send[1] = 0x00;
+	send[2] = 0x00;
+	ret = i2c_master_send(client, send, 3);
+	if (ret != 3) {
+		snd_printk(KERN_ERR "Failed to set ch3 volume on CS4384\n");
+		goto fail;
+	}
+
+	send[0] = 0x80 | 0x14;
+	send[1] = 0x00;
+	send[2] = 0x00;
+	ret = i2c_master_send(client, send, 3);
+	if (ret != 3) {
+		snd_printk(KERN_ERR "Failed to set ch4 volume on CS4384\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 09h: Mute control
+	 *	Mute all (we will unmute channels as needed)
+	 */
+	send[0] = 0x09;
+	send[1] = 0xFF;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to power up CS4384\n");
+		goto fail;
+	}
+
+	/*
+	 * Register 0x02: Mode Control 1
+	 *	Control Port Enable, PCM, All DACs enabled, Power Up
+	 */
+	send[0] = 0x02;
+	send[1] = 0x80;
+	ret = i2c_master_send(client, send, 2);
+	if (ret != 2) {
+		snd_printk(KERN_ERR "Failed to power up CS4384\n");
+		goto fail;
+	}
+
+	/*
+	 * Make sure the changes took place, this helps verify we are talking to
+	 * the correct chip.
+	 */
+	send[0] = 0x80 | 0x03;
+	ret = i2c_master_send(client, send, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed to initiate readback\n");
+		goto fail;
+	}
+
+	ret = i2c_master_recv(client, recv, 1);
+	if (ret != 1) {
+		snd_printk(KERN_ERR "Failed second read of CS4384 registers\n");
+		goto fail;
+	}
+
+	if (recv[0] != 0x13) {
+		snd_printk(KERN_ERR "Failed to initialize CS4384 DAC\n");
+		goto fail;
+	}
+		       
+	snd_printk(KERN_INFO "CS4384 DAC Initialized\n");
+	return 0;
+
+fail:
+	return -ENODEV;
+}
+
+/*
+ * snd_ubi32_cs4384_i2c_probe
+ */
+static int snd_ubi32_cs4384_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+	int err, ret;
+	struct platform_device *pdev;
+	struct ubi32_cs4384_platform_data *pdata;
+	struct snd_ubi32_cs4384_priv *cs4384_priv;
+
+	/*
+	 * pdev is audio_tio
+	 */
+	pdev = client->dev.platform_data;
+	if (!pdev) {
+		return -ENODEV;
+	}
+
+	/*
+	 * pdev->dev.platform_data is ubi32-pcm platform_data
+	 */
+	pdata = audio_tio_priv(pdev);
+	if (!pdata) {
+		return -ENODEV;
+	}
+
+	/*
+	 * Initialize the CS4384 DAC
+	 */
+	ret = snd_ubi32_cs4384_dac_init(client, id);
+	if (ret < 0) {
+		/*
+		 * Initialization failed.  Propagate the error.
+		 */
+		return ret;
+	}
+
+	if (snd_ubi32_cs4384_setup_mclk(pdata)) {
+		return -EINVAL;
+	}
+
+	/*
+	 * Create a snd_card structure
+	 */
+	card = snd_card_new(index, "Ubi32-CS4384", THIS_MODULE, sizeof(struct ubi32_snd_priv));
+	if (card == NULL) {
+		return -ENOMEM;
+	}
+
+	card->private_free = snd_ubi32_cs4384_free;
+	ubi32_priv = card->private_data;
+
+	/*
+	 * Initialize the snd_card's private data structure
+	 */
+	ubi32_priv->card = card;
+	ubi32_priv->client = client;
+	ubi32_priv->set_channels = snd_ubi32_cs4384_set_channels;
+	ubi32_priv->set_rate = snd_ubi32_cs4384_set_rate;
+
+	/*
+	 * CS4384 DAC has a minimum sample rate of 4khz and an
+	 * upper limit of 216khz for it's auto-detect.
+	 */
+	ubi32_priv->min_sample_rate = 4000;
+	ubi32_priv->max_sample_rate = 216000;
+
+	/*
+	 * Create our private data (to manage volume, etc)
+	 */
+	cs4384_priv = kzalloc(sizeof(struct snd_ubi32_cs4384_priv), GFP_KERNEL);
+	if (!cs4384_priv) {
+		snd_card_free(card);
+		return -ENOMEM;
+	}
+	snd_ubi32_priv_set_drv(ubi32_priv, cs4384_priv);
+	spin_lock_init(&cs4384_priv->lock);
+
+	/*
+	 * We start off all muted and max volume
+	 */
+	cs4384_priv->mute = 0xFF;
+	memset(cs4384_priv->volume, 0xFF, 8);
+
+	/*
+	 * Create the new PCM instance
+	 */
+	err = snd_ubi32_pcm_probe(ubi32_priv, pdev);
+	if (err < 0) {
+		snd_card_free(card);
+		return err; /* What is err?  Need to include correct file */
+	}
+
+	strcpy(card->driver, "Ubi32-CS4384");
+	strcpy(card->shortname, "Ubi32-CS4384");
+	sprintf(card->longname, "%s at sendirq=%d recvirq=%d", card->shortname, ubi32_priv->tx_irq, ubi32_priv->rx_irq);
+
+	snd_card_set_dev(card, &client->dev);
+
+	/*
+	 * Set up the mixer
+	 */
+	snd_ubi32_cs4384_mixer(ubi32_priv);
+
+	/*
+	 * Register the sound card 
+	 */
+	if ((err = snd_card_register(card)) != 0) {
+		snd_printk(KERN_INFO "snd_card_register error\n");
+	}
+
+	/* 
+	 * Store card for access from other methods 
+	 */
+	i2c_set_clientdata(client, card);
+
+	return 0;
+}
+
+/*
+ * snd_ubi32_cs4384_i2c_remove
+ */
+static int __devexit snd_ubi32_cs4384_i2c_remove(struct i2c_client *client)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+
+	card = i2c_get_clientdata(client);
+
+	ubi32_priv = card->private_data;
+	snd_ubi32_pcm_remove(ubi32_priv);
+
+	snd_card_free(i2c_get_clientdata(client));
+	i2c_set_clientdata(client, NULL);
+
+	return 0;
+}
+
+/*
+ * I2C driver description
+ */
+static struct i2c_driver snd_ubi32_cs4384_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.id_table	= snd_ubi32_cs4384_id,
+	.probe		= snd_ubi32_cs4384_i2c_probe,
+	.remove		= __devexit_p(snd_ubi32_cs4384_i2c_remove),
+};
+
+/*
+ * Driver init
+ */
+static int __init snd_ubi32_cs4384_init(void)
+{
+	return i2c_add_driver(&snd_ubi32_cs4384_driver);
+}
+module_init(snd_ubi32_cs4384_init);
+
+/*
+ * snd_ubi32_cs4384_exit
+ */
+static void __exit snd_ubi32_cs4384_exit(void)
+{
+	i2c_del_driver(&snd_ubi32_cs4384_driver);
+}
+module_exit(snd_ubi32_cs4384_exit);
+
+/*
+ * Module properties
+ */
+MODULE_ALIAS("i2c:" DRIVER_NAME);
+MODULE_AUTHOR("Patrick Tjin");
+MODULE_DESCRIPTION("Driver for Ubicom32 audio devices CS4384");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/sound/ubicom32/ubi32-generic.c
@@ -0,0 +1,165 @@
+/*
+ * sound/ubicom32/ubi32-generic.c
+ *	Interface to ubicom32 virtual audio peripheral
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include "ubi32.h"
+
+#define DRIVER_NAME "snd-ubi32-generic"
+
+/*
+ * Module properties
+ */
+static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
+
+/*
+ * Card private data free function
+ */
+void snd_ubi32_generic_free(struct snd_card *card)
+{
+	//struct ubi32_snd_priv *ubi32_priv = card->private_data;
+
+	/*
+	 * Free all the fields in the snd_ubi32_priv struct
+	 */
+	// Nothing to free at this time because ubi32_priv just maintains pointers
+}
+
+/*
+ * Ubicom audio driver probe() method.  Args change depending on whether we use
+ * platform_device or i2c_device.
+ */
+static int snd_ubi32_generic_probe(struct platform_device *dev)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+	int err;
+
+	/*
+	 * Create a snd_card structure
+	 */
+	card = snd_card_new(index, "Ubi32-Generic", THIS_MODULE, sizeof(struct ubi32_snd_priv));
+
+	if (card == NULL) {
+		return -ENOMEM;
+	}
+
+	card->private_free = snd_ubi32_generic_free; /* Not sure if correct */
+	ubi32_priv = card->private_data;
+
+	/*
+	 * Initialize the snd_card's private data structure
+	 */
+	ubi32_priv->card = card;
+
+	/*
+	 * Create the new PCM instance
+	 */
+	err = snd_ubi32_pcm_probe(ubi32_priv, dev);
+	if (err < 0) {
+		snd_card_free(card);
+		return err;
+	}
+
+	strcpy(card->driver, "Ubi32-Generic");
+	strcpy(card->shortname, "Ubi32-Generic");
+	sprintf(card->longname, "%s at sendirq=%d recvirq=%d", card->shortname, ubi32_priv->tx_irq, ubi32_priv->rx_irq);
+
+	snd_card_set_dev(card, &dev->dev);
+
+	/* Register the sound card */
+	if ((err = snd_card_register(card)) != 0) {
+		snd_printk(KERN_INFO "snd_card_register error\n");
+	}
+
+	/* Store card for access from other methods */
+	platform_set_drvdata(dev, card);
+
+	return 0;
+}
+
+/*
+ * Ubicom audio driver remove() method
+ */
+static int __devexit snd_ubi32_generic_remove(struct platform_device *dev)
+{
+	struct snd_card *card;
+	struct ubi32_snd_priv *ubi32_priv;
+
+	card = platform_get_drvdata(dev);
+	ubi32_priv = card->private_data;
+	snd_ubi32_pcm_remove(ubi32_priv);
+
+	snd_card_free(platform_get_drvdata(dev));
+	platform_set_drvdata(dev, NULL);
+	return 0;
+}
+
+/*
+ * Platform driver definition
+ */
+static struct platform_driver snd_ubi32_generic_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = snd_ubi32_generic_probe,
+	.remove = __devexit_p(snd_ubi32_generic_remove),
+};
+
+/*
+ * snd_ubi32_generic_init
+ */
+static int __init snd_ubi32_generic_init(void)
+{
+	return platform_driver_register(&snd_ubi32_generic_driver);
+}
+module_init(snd_ubi32_generic_init);
+
+/*
+ * snd_ubi32_generic_exit
+ */
+static void __exit snd_ubi32_generic_exit(void)
+{
+	platform_driver_unregister(&snd_ubi32_generic_driver);
+}
+module_exit(snd_ubi32_generic_exit);
+
+/*
+ * Module properties
+ */
+//#if defined(CONFIG_SND_UBI32_AUDIO_I2C)
+//MODULE_ALIAS("i2c:snd-ubi32");
+//#endif
+MODULE_AUTHOR("Aaron Jow, Patrick Tjin");
+MODULE_DESCRIPTION("Driver for Ubicom32 audio devices");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/sound/ubicom32/ubi32.h
@@ -0,0 +1,96 @@
+/*
+ * sound/ubicom32/ubi32.h
+ *	Common header file for all ubi32- sound drivers
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _UBI32_H
+#define _UBI32_H
+
+#define SND_UBI32_DEBUG 0 // Debug flag
+
+#include <linux/platform_device.h>
+#include <asm/devtree.h>
+#include <asm/audio_tio.h>
+#include <asm/ubi32-pcm.h>
+
+struct ubi32_snd_priv;
+
+typedef int (*set_channels_t)(struct ubi32_snd_priv *priv, int channels);
+typedef int (*set_rate_t)(struct ubi32_snd_priv *priv, int rate);
+
+struct ubi32_snd_priv {
+	/*
+	 * Any variables that are needed locally here but NOT in
+	 * the VP itself should go in here.
+	 */
+	struct snd_card *card;
+	struct snd_pcm *pcm;
+
+	/*
+	 * DAC parameters.  These are the parameters for the specific
+	 * DAC we are driving.  The I2S component can run at a range
+	 * of frequencies, but the DAC may be limited.  We may want
+	 * to make this an array of some sort in the future?
+	 *
+	 * min/max_sample_rate if set to 0 are ignored.
+	 */
+	int max_sample_rate;
+	int min_sample_rate;
+
+	/*
+	 * The size a period (group) of audio samples.  The VP does
+	 * not need to know this; each DMA transfer is made to be
+	 * one period.
+	 */
+	u32_t period_size;
+
+	spinlock_t ubi32_lock;
+
+	struct audiotioregs *regs;
+	u8 tx_irq;
+	u8 rx_irq;
+
+	void *client;
+
+	/*
+	 * Operations which the base DAC driver can implement
+	 */
+	set_channels_t set_channels;
+	set_rate_t set_rate;
+
+	/*
+	 * platform data
+	 */
+	struct ubi32pcm_platform_data *pdata;
+
+	/*
+	 * Private driver data (used for DAC driver control, etc)
+	 */
+	void *drvdata;
+};
+
+#define snd_ubi32_priv_get_drv(priv) ((priv)->drvdata)
+#define snd_ubi32_priv_set_drv(priv, data) (((priv)->drvdata) = (void *)(data))
+
+extern int snd_ubi32_pcm_probe(struct ubi32_snd_priv *ubi32_priv, struct platform_device *pdev);
+extern void snd_ubi32_pcm_remove(struct ubi32_snd_priv *ubi32_priv);
+
+#endif
--- /dev/null
+++ b/sound/ubicom32/ubi32-pcm.c
@@ -0,0 +1,680 @@
+/*
+ * sound/ubicom32/ubi32-pcm.c
+ *	Interface to ubicom32 virtual audio peripheral
+ *
+ * (C) Copyright 2009, Ubicom, Inc.
+ *
+ * This file is part of the Ubicom32 Linux Kernel Port.
+ *
+ * The Ubicom32 Linux Kernel Port is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Ubicom32 Linux Kernel Port is distributed in the hope that it
+ * will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Ubicom32 Linux Kernel Port.  If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Ubicom32 implementation derived from (with many thanks):
+ *   arch/m68knommu
+ *   arch/blackfin
+ *   arch/parisc
+ */
+
+#include <linux/interrupt.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <asm/ip5000.h>
+#include <asm/ubi32-pcm.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include "ubi32.h"
+
+struct ubi32_snd_runtime_data {
+	dma_addr_t dma_buffer;		/* Physical address of DMA buffer */
+	dma_addr_t dma_buffer_end;	/* First address beyond end of DMA buffer */
+	size_t period_size;
+	dma_addr_t period_ptr;		/* Physical address of next period */
+	unsigned int flags;
+};
+
+static void snd_ubi32_vp_int_set(struct snd_pcm *pcm)
+{
+	struct ubi32_snd_priv *ubi32_priv = pcm->private_data;
+	ubicom32_set_interrupt(ubi32_priv->tx_irq);
+}
+
+static snd_pcm_uframes_t snd_ubi32_playback_pointer(struct snd_pcm_substream *substream)
+{
+	struct ubi32_snd_priv *ubi32_priv = snd_pcm_substream_chip(substream);
+	struct audiotioregs *regs = ubi32_priv->regs;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+
+	dma_addr_t read_pos;
+
+	snd_pcm_uframes_t frames;
+	if (!regs->current_read_pos) {
+		/*
+		 * If current_read_pos is NULL (e.g. right after the HW is started or
+		 * when the HW is stopped), then handle this case separately.
+		 */
+		return 0;
+	}
+
+	read_pos = (dma_addr_t)regs->current_read_pos;
+	frames = bytes_to_frames(runtime, read_pos - ubi32_rd->dma_buffer);
+	if (frames == runtime->buffer_size) {
+		frames = 0;
+	}
+	return frames;
+}
+
+/*
+ * Audio trigger
+ */
+static int snd_ubi32_playback_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	struct ubi32_snd_priv *ubi32_priv = substream->pcm->private_data;
+	struct audiotioregs *regs = ubi32_priv->regs;
+	struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+	int ret = 0;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_trigger cmd=%d=", cmd);
+#endif
+
+	if (regs->command != UBI32_AUDIO_CMD_NONE) {
+		snd_printk(KERN_WARNING "Can't send command to audio device at this time\n");
+		// Set a timer to call this function back later.  How to do this?
+		return 0;
+	}
+
+	/*
+	 * Set interrupt flag to indicate that we interrupted audio device
+	 * to send a command
+	 */
+	//regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "START\n");
+#endif
+		/*
+		 * Ready the DMA transfer
+		 */
+		ubi32_rd->period_ptr = ubi32_rd->dma_buffer;
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "trigger period_ptr=%lx\n", (unsigned long)ubi32_rd->period_ptr);
+#endif
+		regs->playback_xfer_requests[0].ptr = (void *)ubi32_rd->period_ptr;
+		regs->playback_xfer_requests[0].ctr = ubi32_rd->period_size;
+		regs->playback_xfer_requests[0].active = 1;
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "xfer_request 0 ptr=0x%x ctr=%u\n", ubi32_rd->period_ptr, ubi32_rd->period_size);
+#endif
+
+		ubi32_rd->period_ptr += ubi32_rd->period_size;
+		regs->playback_xfer_requests[1].ptr = (void *)ubi32_rd->period_ptr;
+		regs->playback_xfer_requests[1].ctr = ubi32_rd->period_size;
+		regs->playback_xfer_requests[1].active = 1;
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "xfer_request 1 ptr=0x%x ctr=%u\n", ubi32_rd->period_ptr, ubi32_rd->period_size);
+#endif
+
+		/*
+		 * Tell the VP that we want to begin playback by filling in the
+		 * command field and then interrupting the audio VP
+		 */
+		regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+		regs->command = UBI32_AUDIO_CMD_START;
+		snd_ubi32_vp_int_set(substream->pcm);
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "STOP\n");
+#endif
+
+		/*
+		 * Tell the VP that we want to stop playback by filling in the
+		 * command field and then interrupting the audio VP
+		 */
+		regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+		regs->command = UBI32_AUDIO_CMD_STOP;
+		snd_ubi32_vp_int_set(substream->pcm);
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "PAUSE_PUSH\n");
+#endif
+
+		/*
+		 * Tell the VP that we want to pause playback by filling in the
+		 * command field and then interrupting the audio VP
+		 */
+		regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+		regs->command = UBI32_AUDIO_CMD_PAUSE;
+		snd_ubi32_vp_int_set(substream->pcm);
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "PAUSE_RELEASE\n");
+#endif
+		/*
+		 * Tell the VP that we want to resume paused playback by filling
+		 * in the command field and then interrupting the audio VP
+		 */
+		regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+		regs->command = UBI32_AUDIO_CMD_RESUME;
+		snd_ubi32_vp_int_set(substream->pcm);
+		break;
+
+	default:
+		snd_printk(KERN_WARNING "Unhandled trigger\n");
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+/*
+ * Prepare to transfer an audio stream to the codec
+ */
+static int snd_ubi32_playback_prepare(struct snd_pcm_substream *substream)
+{
+	/*
+	 * Configure registers and setup the runtime instance for DMA transfers
+	 */
+	//struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+	struct ubi32_snd_priv *ubi32_priv = substream->pcm->private_data;
+	struct audiotioregs *regs = ubi32_priv->regs;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_prepare: sending STOP command to audio device\n");
+#endif
+
+	/*
+	 * Make sure the audio device is stopped
+	 */
+
+	/*
+	 * Set interrupt flag to indicate that we interrupted audio device
+	 * to send a command
+	 */
+	regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+	regs->command = UBI32_AUDIO_CMD_STOP;
+	snd_ubi32_vp_int_set(substream->pcm);
+
+	return 0;
+}
+
+/*
+ * Allocate DMA buffers from preallocated memory.
+ * Preallocation was done in snd_ubi32_pcm_new()
+ */
+static int snd_ubi32_playback_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *hw_params)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct ubi32_snd_priv *ubi32_priv = substream->pcm->private_data;
+	struct audiotioregs *regs = ubi32_priv->regs;
+	struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+
+	/*
+	 * Use pre-allocated memory from ubi32_snd_pcm_new() to satisfy
+	 * this memory request.
+	 */
+	int ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_hw_params\n");
+#endif
+
+	if (!(regs->channel_mask & (1 << params_channels(hw_params)))) {
+		snd_printk(KERN_INFO "snd_ubi32_playback_hw_params unsupported number of channels %d mask %08x\n", params_channels(hw_params), regs->channel_mask);
+		return -EINVAL;
+	}
+
+	if (ubi32_priv->set_channels) {
+		int ret = ubi32_priv->set_channels(ubi32_priv, params_channels(hw_params));
+		if (ret) {
+			snd_printk(KERN_WARNING "Unable to set channels to %d, ret=%d\n", params_channels(hw_params), ret);
+			return ret;
+		}
+	}
+
+	if (ubi32_priv->set_rate) {
+		int ret = ubi32_priv->set_rate(ubi32_priv, params_rate(hw_params));
+		if (ret) {
+			snd_printk(KERN_WARNING "Unable to set rate to %d, ret=%d\n", params_rate(hw_params), ret);
+			return ret;
+		}
+	}
+
+	if (ubi32_priv->pdata->set_rate) {
+		int ret = ubi32_priv->pdata->set_rate(ubi32_priv->pdata->appdata, params_rate(hw_params));
+		if (ret) {
+			snd_printk(KERN_WARNING "Unable to set rate to %d, ret=%d\n", params_rate(hw_params), ret);
+			return ret;
+		}
+	}
+
+	if (regs->command != UBI32_AUDIO_CMD_NONE) {
+		snd_printk(KERN_WARNING "snd_ubi32_playback_hw_params: tio busy\n");
+		return -EAGAIN;
+	}
+
+	if (params_format(hw_params) == SNDRV_PCM_FORMAT_S16_LE) {
+		regs->flags |= UBI32_CMD_SETUP_FLAG_LE;
+	} else {
+		regs->flags &= ~UBI32_CMD_SETUP_FLAG_LE;
+	}
+	regs->channels = params_channels(hw_params);
+	regs->sample_rate = params_rate(hw_params);
+	regs->command = UBI32_AUDIO_CMD_SETUP;
+	regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+	snd_ubi32_vp_int_set(substream->pcm);
+
+	/*
+	 * Wait for the command to complete
+	 */
+	while (regs->command != UBI32_AUDIO_CMD_NONE) {
+		udelay(1);
+	}
+
+	//snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+	//runtime->dma_bytes = params_buffer_bytes(hw_params);
+
+	/*
+	 * Put the DMA info into the DMA descriptor that we will
+	 * use to do transfers to our audio VP "hardware"
+	 */
+
+	/*
+	 * Mark both DMA transfers as not ready/inactive
+	 */
+	regs->playback_xfer_requests[0].active = 0;
+	regs->playback_xfer_requests[1].active = 0;
+
+	/*
+	 * Put the location of the buffer into the runtime data instance
+	 */
+	ubi32_rd->dma_buffer = (dma_addr_t)runtime->dma_area;
+	ubi32_rd->dma_buffer_end = (dma_addr_t)(runtime->dma_area + runtime->dma_bytes);
+
+	/*
+	 * Get the period size
+	 */
+	ubi32_rd->period_size = params_period_bytes(hw_params);
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "DMA for ubi32 audio initialized dma_area=0x%x dma_bytes=%d, period_size=%d\n", (unsigned int)runtime->dma_area, (unsigned int)runtime->dma_bytes, ubi32_rd->period_size);
+	snd_printk(KERN_INFO "Private buffer ubi32_rd: dma_buffer=0x%x dma_buffer_end=0x%x\n", ubi32_rd->dma_buffer, ubi32_rd->dma_buffer_end);
+#endif
+
+	return ret;
+}
+
+/*
+ * This is the reverse of snd_ubi32_playback_hw_params
+ */
+static int snd_ubi32_playback_hw_free(struct snd_pcm_substream *substream)
+{
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_hw_free\n");
+#endif
+	return snd_pcm_lib_free_pages(substream);
+}
+
+/*
+ * Audio virtual peripheral capabilities
+ */
+static struct snd_pcm_hardware snd_ubi32_playback_hw =
+{
+	/* FILL IN THIS STRUCT WITH HW PARAMS SPECIFIC TO IPI2SOUT */
+	// This is defined in include/sound/asound.h or
+	// include/sound/pcm.h
+	.info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
+		 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), // NOT SURE ABOUT THIS
+	//.info			= (SNDRV_PCM_INFO_INTERLEAVED |
+	//			   SNDRV_PCM_INFO_BLOCK_TRANSFER |
+	//			   SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
+	//			   SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
+	.buffer_bytes_max = (64*1024), // NOT SURE ABOUT THIS
+	.period_bytes_min	= 64,
+	.period_bytes_max	= 8184,//8184,//8176,
+	.periods_min = 2,
+	.periods_max = 255, // THIS WILL ALMOST CERTAINLY NEED TO BE CHANGED
+	.fifo_size = 0, // THIS IS IGNORED BY ALSA
+};
+
+/*
+ * We fill this in later
+ */
+static struct snd_pcm_hw_constraint_list ubi32_playback_rates;
+
+static int snd_ubi32_playback_close(struct snd_pcm_substream *substream)
+{
+	/* Disable codec, stop DMA, free private data structures */
+	//struct ubi32_snd_priv *ubi32_priv = snd_pcm_substream_chip(substream);
+	struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_close\n");
+#endif
+
+	substream->runtime->private_data = NULL;
+
+	kfree(ubi32_rd);
+	
+	return 0;
+}
+
+static int snd_ubi32_playback_open(struct snd_pcm_substream *substream)
+{
+	//struct ubi32_snd_priv *ubi32_priv = snd_pcm_substream_chip(substream);
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct ubi32_snd_runtime_data *ubi32_rd;
+	int ret = 0;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "ubi32 playback open\n");
+#endif
+
+	/* Associate capabilities with component */
+	runtime->hw = snd_ubi32_playback_hw;
+
+	/*
+	 * Inform ALSA about constraints of the audio device
+	 */
+	ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &ubi32_playback_rates);
+	if (ret < 0) {
+		snd_printk(KERN_INFO "invalid rate\n");
+		goto out;
+	}
+
+	/* Force the buffer size to be an integer multiple of period size */
+	ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+	if (ret < 0) {
+		snd_printk(KERN_INFO "invalid period\n");
+		goto out;
+	}
+	/* Initialize structures/registers */
+	ubi32_rd = kzalloc(sizeof(struct ubi32_snd_runtime_data), GFP_KERNEL);
+	if (ubi32_rd == NULL) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	runtime->private_data = ubi32_rd;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_open returned 0\n");
+#endif
+
+	return 0;
+out:
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "snd_ubi32_playback_open returned %d\n", ret);
+#endif
+
+	return ret;
+}
+
+static struct snd_pcm_ops snd_ubi32_playback_ops = {
+	.open = 	snd_ubi32_playback_open, /* Open */
+	.close = 	snd_ubi32_playback_close, /* Close */
+	.ioctl = 	snd_pcm_lib_ioctl, /* Generic IOCTL handler */
+	.hw_params = 	snd_ubi32_playback_hw_params, /* Hardware parameters/capabilities */
+	.hw_free = 	snd_ubi32_playback_hw_free, /* Free function for hw_params */
+	.prepare = 	snd_ubi32_playback_prepare,
+	.trigger = 	snd_ubi32_playback_trigger,
+	.pointer = 	snd_ubi32_playback_pointer,
+};
+
+/*
+ * Interrupt handler that gets called when the audio device
+ * interrupts Linux
+ */
+static irqreturn_t snd_ubi32_pcm_interrupt(int irq, void *appdata)
+{
+	struct snd_pcm *pcm = (struct snd_pcm *)appdata;
+	struct ubi32_snd_priv *ubi32_priv = pcm->private_data;
+	struct audiotioregs *regs = ubi32_priv->regs;
+
+	// Only one substream exists because our VP does not mix
+	// streams.  Therefore we don't have to search through
+	// substreams like the at91 driver does.
+	struct snd_pcm_substream *substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+	struct ubi32_snd_runtime_data *ubi32_rd = substream->runtime->private_data;
+	int dma_to_fill = 0;
+
+#if SND_UBI32_DEBUG
+	snd_printk(KERN_INFO "Ubi32 ALSA interrupt\n");
+#endif
+
+	if (!pcm) {
+		snd_printk(KERN_WARNING "pcm does not exist\n");
+		return IRQ_HANDLED;
+	}
+
+	if (ubi32_rd == NULL) {
+		snd_printk(KERN_WARNING "No runtime data\n");
+		return IRQ_HANDLED;
+	}
+	// Check interrupt cause
+	if (0) {
+		// Handle the underflow case
+	} else if ((regs->status & UBI32_AUDIO_STATUS_PLAY_DMA0_REQUEST) ||
+		   (regs->status & UBI32_AUDIO_STATUS_PLAY_DMA1_REQUEST)) {
+		if (regs->status & UBI32_AUDIO_STATUS_PLAY_DMA0_REQUEST) {
+			dma_to_fill = 0;
+			regs->status &= ~UBI32_AUDIO_STATUS_PLAY_DMA0_REQUEST;
+		} else if (regs->status & UBI32_AUDIO_STATUS_PLAY_DMA1_REQUEST) {
+			dma_to_fill = 1;
+			regs->status &= ~UBI32_AUDIO_STATUS_PLAY_DMA1_REQUEST;
+		}   
+		ubi32_rd->period_ptr += ubi32_rd->period_size;
+		if (ubi32_rd->period_ptr >= ubi32_rd->dma_buffer_end) {
+			ubi32_rd->period_ptr = ubi32_rd->dma_buffer;
+		}
+		regs->playback_xfer_requests[dma_to_fill].ptr = (void *)ubi32_rd->period_ptr;
+		regs->playback_xfer_requests[dma_to_fill].ctr = ubi32_rd->period_size;
+		regs->playback_xfer_requests[dma_to_fill].active = 1;
+#if SND_UBI32_DEBUG
+		snd_printk(KERN_INFO "xfer_request %d ptr=0x%x ctr=%u\n", dma_to_fill, ubi32_rd->period_ptr, ubi32_rd->period_size);
+#endif
+		regs->int_flags |= UBI32_AUDIO_INT_FLAG_MORE_SAMPLES;
+		snd_ubi32_vp_int_set(substream->pcm);
+	}
+	// If we are interrupted by the VP, that means we completed
+	// processing one period of audio.  We need to inform the upper
+	// layers of ALSA of this.
+	snd_pcm_period_elapsed(substream);
+
+	return IRQ_HANDLED;
+}
+
+void __devexit snd_ubi32_pcm_remove(struct ubi32_snd_priv *ubi32_priv)
+{
+	struct snd_pcm *pcm = ubi32_priv->pcm;
+	free_irq(ubi32_priv->rx_irq, pcm);
+}
+
+#if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
+#error "Change this table to match pcm.h"
+#endif
+static unsigned int rates[] __initdata = {5512, 8000, 11025, 16000, 22050, 
+					  32000, 44100, 48000, 64000, 88200, 
+					  96000, 176400, 192000};
+
+/*
+ * snd_ubi32_pcm_probe
+ */
+int __devinit snd_ubi32_pcm_probe(struct ubi32_snd_priv *ubi32_priv, struct platform_device *pdev)
+{
+	struct snd_pcm *pcm;
+	int ret, err;
+	int i;
+	int j;
+	int nrates;
+	unsigned int rate_max = 0;
+	unsigned int rate_min = 0xFFFFFFFF;
+	unsigned int rate_mask = 0;
+	struct audiotioregs *regs;
+	struct resource *res_regs;
+	struct resource *res_irq_tx;
+	struct resource *res_irq_rx;
+	struct ubi32pcm_platform_data *pdata;
+
+	pdata = pdev->dev.platform_data;
+	if (!pdata) {
+		return -ENODEV;
+	}
+
+	/*
+	 * Get our resources, regs is the hardware driver base address
+	 * and the tx and rx irqs are used to communicate with the
+	 * hardware driver.
+	 */
+	res_regs = platform_get_resource(pdev, IORESOURCE_MEM, AUDIOTIO_MEM_RESOURCE);
+	res_irq_tx = platform_get_resource(pdev, IORESOURCE_IRQ, AUDIOTIO_TX_IRQ_RESOURCE);
+	res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, AUDIOTIO_RX_IRQ_RESOURCE);
+	if (!res_regs || !res_irq_tx || !res_irq_rx) {
+		snd_printk(KERN_WARNING "Could not get resources");
+		return -ENODEV;
+	}
+
+	ubi32_priv->regs = (struct audiotioregs *)res_regs->start;
+	ubi32_priv->tx_irq = res_irq_tx->start;
+	ubi32_priv->rx_irq = res_irq_rx->start;
+
+	/*
+	 * Check the version
+	 */
+	regs = ubi32_priv->regs;
+	if (regs->version != AUDIOTIOREGS_VERSION) {
+		snd_printk(KERN_WARNING "This audiotioreg is not compatible with this driver\n");
+		return -ENODEV;
+	}
+
+	/*
+	 * Find out the standard rates, also find max and min rates
+	 */
+	for (i = 0; i < ARRAY_SIZE(rates); i++) {
+		int found = 0;
+		for (j = 0; j < regs->n_sample_rates; j++) {
+			if (rates[i] == regs->sample_rates[j]) {
+				/*
+				 * Check to see if it is supported by the dac
+				 */
+				if ((rates[i] >= ubi32_priv->min_sample_rate) &&
+				    (!ubi32_priv->max_sample_rate || 
+				     (ubi32_priv->max_sample_rate && (rates[i] <= ubi32_priv->max_sample_rate)))) {
+					found = 1;
+					rate_mask |= (1 << i);
+					nrates++;
+					if (rates[i] < rate_min) {
+						rate_min = rates[i];
+					}
+					if (rates[i] > rate_max) {
+						rate_max = rates[i];
+					}
+					break;
+				}
+			}
+		}
+		if (!found) {
+			rate_mask |= SNDRV_PCM_RATE_KNOT;
+		}
+	}
+
+	snd_ubi32_playback_hw.rates = rate_mask;
+	snd_ubi32_playback_hw.rate_min = rate_min;
+	snd_ubi32_playback_hw.rate_max = rate_max;
+	ubi32_playback_rates.count = regs->n_sample_rates;
+	ubi32_playback_rates.list = regs->sample_rates;
+	ubi32_playback_rates.mask = 0;
+
+	for (i = 0; i < 32; i++) {
+		if (regs->channel_mask & (1 << i)) {
+			if (!snd_ubi32_playback_hw.channels_min) {
+				snd_ubi32_playback_hw.channels_min = i;
+			}
+			snd_ubi32_playback_hw.channels_max = i;
+		}
+	}
+	snd_printk(KERN_INFO "Ubi32PCM: channels_min:%u channels_max:%u\n",
+		   snd_ubi32_playback_hw.channels_min,
+		   snd_ubi32_playback_hw.channels_max);
+
+	if (regs->caps & AUDIOTIONODE_CAP_BE) {
+		snd_ubi32_playback_hw.formats |= SNDRV_PCM_FMTBIT_S16_BE;
+	}
+	if (regs->caps & AUDIOTIONODE_CAP_LE) {
+		snd_ubi32_playback_hw.formats |= SNDRV_PCM_FMTBIT_S16_LE;
+	}
+	snd_printk(KERN_INFO "Ubi32PCM: rates:%08x min:%u max:%u count:%d fmts:%016llx\n",
+		   snd_ubi32_playback_hw.rates,
+		   snd_ubi32_playback_hw.rate_min,
+		   snd_ubi32_playback_hw.rate_max,
+		   ubi32_playback_rates.count,
+		   snd_ubi32_playback_hw.formats);
+
+	ret = snd_pcm_new(ubi32_priv->card, "Ubi32 PCM", 0, 1, 0, &pcm);
+	if (ret < 0) {
+		return ret;
+	}
+
+	pcm->private_data = ubi32_priv;
+	ubi32_priv->pcm = pcm;
+	ubi32_priv->pdata = pdata;
+
+	pcm->info_flags = 0; // What is this for?  Just copied from other drivers
+
+	strcpy(pcm->name, "Ubi32-PCM");
+
+	// How do we allocate the buffer for non PCI devices?
+	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
+					      snd_dma_continuous_data(GFP_KERNEL),
+					      45*1024, 64*1024); //NOT SURE ABOUT SIZE, CHECK LATER
+
+	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ubi32_playback_ops);
+
+	/*
+	 * Start up the TIO
+	 */
+	regs->int_flags |= UBI32_AUDIO_INT_FLAG_COMMAND;
+	regs->command = UBI32_AUDIO_CMD_ENABLE;
+	snd_ubi32_vp_int_set(pcm);
+
+	/* 
+	 * Request IRQ
+	 */
+	err = request_irq(ubi32_priv->rx_irq, snd_ubi32_pcm_interrupt, IRQF_DISABLED, pcm->name, pcm);
+	if (err) {
+		snd_printk(KERN_WARNING "request_irq failed: irq=%d err=%d\n", ubi32_priv->rx_irq, err);
+		return -ENODEV;
+	}
+
+	return ret;
+
+}
--- /dev/null
+++ b/arch/ubicom32/lib/ashldi3.c
@@ -0,0 +1,62 @@
+/* ashrdi3.c extracted from gcc-2.95.2/libgcc2.c which is: */
+/* Copyright (C) 1989, 92-98, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define BITS_PER_UNIT 8
+
+typedef		 int SItype	__attribute__ ((mode (SI)));
+typedef unsigned int USItype	__attribute__ ((mode (SI)));
+typedef		 int DItype	__attribute__ ((mode (DI)));
+typedef int word_type __attribute__ ((mode (__word__)));
+
+struct DIstruct {SItype high, low;};
+
+typedef union
+{
+  struct DIstruct s;
+  DItype ll;
+} DIunion;
+
+DItype
+__ashldi3 (DItype u, word_type b)
+{
+  DIunion w;
+  word_type bm;
+  DIunion uu;
+
+  if (b == 0)
+    return u;
+
+  uu.ll = u;
+
+  bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
+  if (bm <= 0)
+    {
+      w.s.low = 0;
+      w.s.high = (USItype)uu.s.low << -bm;
+    }
+  else
+    {
+      USItype carries = (USItype)uu.s.low >> bm;
+      w.s.low = (USItype)uu.s.low << b;
+      w.s.high = ((USItype)uu.s.high << b) | carries;
+    }
+
+  return w.ll;
+}
--- /dev/null
+++ b/arch/ubicom32/lib/ashrdi3.c
@@ -0,0 +1,63 @@
+/* ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define BITS_PER_UNIT 8
+
+typedef		 int SItype	__attribute__ ((mode (SI)));
+typedef unsigned int USItype	__attribute__ ((mode (SI)));
+typedef		 int DItype	__attribute__ ((mode (DI)));
+typedef int word_type __attribute__ ((mode (__word__)));
+
+struct DIstruct {SItype high, low;};
+
+typedef union
+{
+  struct DIstruct s;
+  DItype ll;
+} DIunion;
+
+DItype
+__ashrdi3 (DItype u, word_type b)
+{
+  DIunion w;
+  word_type bm;
+  DIunion uu;
+
+  if (b == 0)
+    return u;
+
+  uu.ll = u;
+
+  bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
+  if (bm <= 0)
+    {
+      /* w.s.high = 1..1 or 0..0 */
+      w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
+      w.s.low = uu.s.high >> -bm;
+    }
+  else
+    {
+      USItype carries = (USItype)uu.s.high << bm;
+      w.s.high = uu.s.high >> b;
+      w.s.low = ((USItype)uu.s.low >> b) | carries;
+    }
+
+  return w.ll;
+}
--- /dev/null
+++ b/arch/ubicom32/lib/divmod.c
@@ -0,0 +1,85 @@
+unsigned long
+udivmodsi4(unsigned long num, unsigned long den, int modwanted)
+{
+  unsigned long bit = 1;
+  unsigned long res = 0;
+
+  while (den < num && bit && !(den & (1L<<31)))
+    {
+      den <<=1;
+      bit <<=1;
+    }
+  while (bit)
+    {
+      if (num >= den)
+	{
+	  num -= den;
+	  res |= bit;
+	}
+      bit >>=1;
+      den >>=1;
+    }
+  if (modwanted) return num;
+  return res;
+}
+
+long
+__udivsi3 (long a, long b)
+{
+  return udivmodsi4 (a, b, 0);
+}
+
+long
+__umodsi3 (long a, long b)
+{
+  return udivmodsi4 (a, b, 1);
+}
+
+long
+__divsi3 (long a, long b)
+{
+  int neg = 0;
+  long res;
+
+  if (a < 0)
+    {
+      a = -a;
+      neg = !neg;
+    }
+
+  if (b < 0)
+    {
+      b = -b;
+      neg = !neg;
+    }
+
+  res = udivmodsi4 (a, b, 0);
+
+  if (neg)
+    res = -res;
+
+  return res;
+}
+
+long
+__modsi3 (long a, long b)
+{
+  int neg = 0;
+  long res;
+
+  if (a < 0)
+    {
+      a = -a;
+      neg = 1;
+    }
+
+  if (b < 0)
+    b = -b;
+
+  res = udivmodsi4 (a, b, 1);
+
+  if (neg)
+    res = -res;
+
+  return res;
+}
--- /dev/null
+++ b/arch/ubicom32/lib/lshrdi3.c
@@ -0,0 +1,62 @@
+/* lshrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define BITS_PER_UNIT 8
+
+typedef		 int SItype	__attribute__ ((mode (SI)));
+typedef unsigned int USItype	__attribute__ ((mode (SI)));
+typedef		 int DItype	__attribute__ ((mode (DI)));
+typedef int word_type __attribute__ ((mode (__word__)));
+
+struct DIstruct {SItype high, low;};
+
+typedef union
+{
+  struct DIstruct s;
+  DItype ll;
+} DIunion;
+
+DItype
+__lshrdi3 (DItype u, word_type b)
+{
+  DIunion w;
+  word_type bm;
+  DIunion uu;
+
+  if (b == 0)
+    return u;
+
+  uu.ll = u;
+
+  bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
+  if (bm <= 0)
+    {
+      w.s.high = 0;
+      w.s.low = (USItype)uu.s.high >> -bm;
+    }
+  else
+    {
+      USItype carries = (USItype)uu.s.high << bm;
+      w.s.high = (USItype)uu.s.high >> b;
+      w.s.low = ((USItype)uu.s.low >> b) | carries;
+    }
+
+  return w.ll;
+}
--- /dev/null
+++ b/arch/ubicom32/lib/muldi3.c
@@ -0,0 +1,87 @@
+/* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
+			   gcc-2.7.2.3/longlong.h which is: */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define UWtype          USItype
+#define UHWtype         USItype
+#define W_TYPE_SIZE     32
+#define __BITS4 (W_TYPE_SIZE / 4)
+#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
+#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
+#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
+
+#define umul_ppmm(w1, w0, u, v)                                         \
+  do {                                                                  \
+    UWtype __x0, __x1, __x2, __x3;                                      \
+    UHWtype __ul, __vl, __uh, __vh;                                     \
+                                                                        \
+    __ul = __ll_lowpart (u);                                            \
+    __uh = __ll_highpart (u);                                           \
+    __vl = __ll_lowpart (v);                                            \
+    __vh = __ll_highpart (v);                                           \
+                                                                        \
+    __x0 = (UWtype) __ul * __vl;                                        \
+    __x1 = (UWtype) __ul * __vh;                                        \
+    __x2 = (UWtype) __uh * __vl;                                        \
+    __x3 = (UWtype) __uh * __vh;                                        \
+                                                                        \
+    __x1 += __ll_highpart (__x0);/* this can't give carry */            \
+    __x1 += __x2;               /* but this indeed can */               \
+    if (__x1 < __x2)            /* did we get it? */                    \
+      __x3 += __ll_B;           /* yes, add it in the proper pos.  */   \
+                                                                        \
+    (w1) = __x3 + __ll_highpart (__x1);                                 \
+    (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0);          \
+  } while (0)
+
+
+#define __umulsidi3(u, v) \
+  ({DIunion __w;							\
+    umul_ppmm (__w.s.high, __w.s.low, u, v);				\
+    __w.ll; })
+
+typedef		 int SItype	__attribute__ ((mode (SI)));
+typedef unsigned int USItype	__attribute__ ((mode (SI)));
+typedef		 int DItype	__attribute__ ((mode (DI)));
+typedef int word_type __attribute__ ((mode (__word__)));
+
+struct DIstruct {SItype high, low;};
+
+typedef union
+{
+  struct DIstruct s;
+  DItype ll;
+} DIunion;
+
+DItype
+__muldi3 (DItype u, DItype v)
+{
+  DIunion w;
+  DIunion uu, vv;
+
+  uu.ll = u,
+  vv.ll = v;
+
+  w.ll = __umulsidi3 (uu.s.low, vv.s.low);
+  w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
+	       + (USItype) uu.s.high * (USItype) vv.s.low);
+
+  return w.ll;
+}