aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/storm/patches/007-mtd.patch
blob: bc9a03ee4aea59d2de3399dcc4a0f3f542ee41b3 (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
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -220,6 +220,13 @@ config MTD_ROM
 	  This option enables basic support for ROM chips accessed through
 	  a bus mapping driver.
 
+config MTD_SERIAL
+	tristate "Support for Serial chips in bus mapping"
+	depends on MTD
+	help
+	  This option enables basic support for Serial chips accessed through
+	  a bus mapping driver.
+
 config MTD_ABSENT
 	tristate "Support for absent chips in bus mapping"
 	help
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -39,10 +39,15 @@
 #include <linux/mtd/cfi.h>
 #include <linux/mtd/xip.h>
 
+//****** Storlink SoC ******
 #define AMD_BOOTLOC_BUG
-#define FORCE_WORD_WRITE 0
-
-#define MAX_WORD_RETRIES 3
+//#define FORCE_WORD_WRITE 0
+#define FORCE_WORD_WRITE 1
+#define FORCE_FAST_PROG 0
+
+//#define MAX_WORD_RETRIES 3
+#define MAX_WORD_RETRIES 3 // CONFIG_MTD_CFI_AMDSTD_RETRY
+//**************************
 
 #define MANUFACTURER_AMD	0x0001
 #define MANUFACTURER_ATMEL	0x001F
@@ -322,6 +327,13 @@ struct mtd_info *cfi_cmdset_0002(struct 
 #endif
 
 		bootloc = extp->TopBottom;
+//****** Storlink SoC ******
+		if(bootloc == 5)
+		{
+			bootloc = 3;
+			extp->TopBottom = 3;
+		}
+//**************************
 		if ((bootloc != 2) && (bootloc != 3)) {
 			printk(KERN_WARNING "%s: CFI does not contain boot "
 			       "bank location. Assuming top.\n", map->name);
@@ -340,6 +352,9 @@ struct mtd_info *cfi_cmdset_0002(struct 
 				cfi->cfiq->EraseRegionInfo[j] = swap;
 			}
 		}
+#ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
+		cfi->device_type = CFI_DEVICETYPE_X8;
+#endif
 		/* Set the default CFI lock/unlock addresses */
 		cfi->addr_unlock1 = 0x555;
 		cfi->addr_unlock2 = 0x2aa;
@@ -461,6 +476,7 @@ static int __xipram chip_ready(struct ma
 	map_word d, t;
 
 	d = map_read(map, addr);
+	udelay(20);	//Storlink SoC
 	t = map_read(map, addr);
 
 	return map_word_equal(map, d, t);
@@ -626,7 +642,9 @@ static void put_chip(struct map_info *ma
 	default:
 		printk(KERN_ERR "MTD: put_chip() called with oldstate %d!!\n", chip->oldstate);
 	}
+//****** Storlink SoC ******
 	wake_up(&chip->wq);
+//**************************
 }
 
 #ifdef CONFIG_MTD_XIP
@@ -940,7 +958,9 @@ static inline int do_read_secsi_onechip(
 	cfi_send_gen_cmd(0x90, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
 	cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
 
+//****** Storlink SoC ******
 	wake_up(&chip->wq);
+//**************************
 	spin_unlock(chip->mutex);
 
 	return 0;
@@ -1005,7 +1025,10 @@ static int __xipram do_write_oneword(str
 	 */
 	unsigned long uWriteTimeout = ( HZ / 1000 ) + 1;
 	int ret = 0;
-	map_word oldd;
+//****** Storlink SoC ******
+//	map_word oldd;
+	map_word oldd, tmp;
+//**************************
 	int retry_cnt = 0;
 
 	adr += chip->start;
@@ -1037,9 +1060,15 @@ static int __xipram do_write_oneword(str
 	ENABLE_VPP(map);
 	xip_disable(map, chip, adr);
  retry:
+//****** Storlink SoC ******
+#if FORCE_FAST_PROG  /* Unlock bypass */
+	cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
+#else
 	cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
 	cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
 	cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
+#endif
+//**************************
 	map_write(map, datum, adr);
 	chip->state = FL_WRITING;
 
@@ -1072,7 +1101,13 @@ static int __xipram do_write_oneword(str
 		}
 
 		if (chip_ready(map, adr))
-			break;
+		{
+			tmp = map_read(map, adr);
+			if(map_word_equal(map, tmp, datum))
+//				goto op_done;
+                break;
+
+		}
 
 		/* Latency issues. Drop the lock, wait a while and retry */
 		UDELAY(map, chip, adr, 1);
@@ -1084,8 +1119,17 @@ static int __xipram do_write_oneword(str
 		/* FIXME - should have reset delay before continuing */
 
 		if (++retry_cnt <= MAX_WORD_RETRIES)
+		{
+//****** Storlink SoC ******
+#if FORCE_FAST_PROG
+			cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
+		//udelay(1);
+#endif
+			udelay(1);
 			goto retry;
-
+		}
 		ret = -EIO;
 	}
 	xip_enable(map, chip, adr);
@@ -1171,7 +1215,14 @@ static int cfi_amdstd_write_words(struct
 				return 0;
 		}
 	}
-
+//****** Storlink SoC ******
+	map_write( map, CMD(0xF0), chipstart );
+#if FORCE_FAST_PROG
+		cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+		cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chipstart, map, cfi, cfi->device_type, NULL);
+		cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
+//**************************
 	/* We are now aligned, write as much as possible */
 	while(len >= map_bankwidth(map)) {
 		map_word datum;
@@ -1181,7 +1232,15 @@ static int cfi_amdstd_write_words(struct
 		ret = do_write_oneword(map, &cfi->chips[chipnum],
 				       ofs, datum);
 		if (ret)
+		{
+//****** Storlink SoC ******
+#if FORCE_FAST_PROG
+			/* Get out of unlock bypass mode */
+			cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 			return ret;
+		}
 
 		ofs += map_bankwidth(map);
 		buf += map_bankwidth(map);
@@ -1189,19 +1248,38 @@ static int cfi_amdstd_write_words(struct
 		len -= map_bankwidth(map);
 
 		if (ofs >> cfi->chipshift) {
+//****** Storlink SoC ******
+#if FORCE_FAST_PROG
+			/* Get out of unlock bypass mode */
+			cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 			chipnum ++;
 			ofs = 0;
 			if (chipnum == cfi->numchips)
 				return 0;
 			chipstart = cfi->chips[chipnum].start;
+#if FORCE_FAST_PROG
+			/* Go into unlock bypass mode for next set of chips */
+			cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chipstart, map, cfi, cfi->device_type, NULL);
+			cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 		}
 	}
 
+#if FORCE_FAST_PROG
+	/* Get out of unlock bypass mode */
+	cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL);
+	cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
+
 	/* Write the trailing bytes if any */
 	if (len & (map_bankwidth(map)-1)) {
 		map_word tmp_buf;
 
  retry1:
+
 		spin_lock(cfi->chips[chipnum].mutex);
 
 		if (cfi->chips[chipnum].state != FL_READY) {
@@ -1221,7 +1299,11 @@ static int cfi_amdstd_write_words(struct
 #endif
 			goto retry1;
 		}
-
+#if FORCE_FAST_PROG
+		cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+		cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chipstart, map, cfi, cfi->device_type, NULL);
+		cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 		tmp_buf = map_read(map, ofs + chipstart);
 
 		spin_unlock(cfi->chips[chipnum].mutex);
@@ -1231,11 +1313,23 @@ static int cfi_amdstd_write_words(struct
 		ret = do_write_oneword(map, &cfi->chips[chipnum],
 				ofs, tmp_buf);
 		if (ret)
+		{
+#if FORCE_FAST_PROG
+	/* Get out of unlock bypass mode */
+	cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL);
+	cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 			return ret;
-
+		}
+#if FORCE_FAST_PROG
+	/* Get out of unlock bypass mode */
+	cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL);
+	cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
+#endif
 		(*retlen) += len;
 	}
 
+	map_write( map, CMD(0xF0), chipstart );
 	return 0;
 }
 
@@ -1275,6 +1369,7 @@ static int __xipram do_write_buffer(stru
 	ENABLE_VPP(map);
 	xip_disable(map, chip, cmd_adr);
 
+	map_write( map, CMD(0xF0), chip->start );	//Storlink
 	cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
 	cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
 	//cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
@@ -1535,6 +1630,9 @@ static int __xipram do_erase_oneblock(st
 	DECLARE_WAITQUEUE(wait, current);
 	int ret = 0;
 
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_lock();				// sl2312 share pin lock
+#endif
 	adr += chip->start;
 
 	spin_lock(chip->mutex);
@@ -1613,6 +1711,9 @@ static int __xipram do_erase_oneblock(st
 	chip->state = FL_READY;
 	put_chip(map, chip, adr);
 	spin_unlock(chip->mutex);
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 	return ret;
 }
 
--- /dev/null
+++ b/drivers/mtd/chips/map_serial.c
@@ -0,0 +1,188 @@
+/*
+ * Common code to handle map devices which are simple ROM
+ * (C) 2000 Red Hat. GPL'd.
+ * $Id: map_serial.c,v 1.3 2006/06/05 02:34:54 middle Exp $
+ */
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <asm/io.h>
+
+#include <asm/byteorder.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+
+#include <asm/hardware.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/mtd.h>
+#include <linux/init.h> //add
+#include <asm/arch/sl2312.h>
+#include <asm/arch/flash.h>
+
+static int mapserial_erase(struct mtd_info *mtd, struct erase_info *instr);
+static int mapserial_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
+static int mapserial_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
+static void mapserial_nop (struct mtd_info *);
+struct mtd_info *map_serial_probe(struct map_info *map);
+
+extern int m25p80_sector_erase(__u32 address, __u32 schip_en);
+
+static struct mtd_chip_driver mapserial_chipdrv = {
+	probe: map_serial_probe,
+	name: "map_serial",
+	module: THIS_MODULE
+};
+
+struct mtd_info *map_serial_probe(struct map_info *map)
+{
+	struct mtd_info *mtd;
+
+	mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
+	if (!mtd)
+		return NULL;
+
+	memset(mtd, 0, sizeof(*mtd));
+
+	map->fldrv = &mapserial_chipdrv;
+	mtd->priv = map;
+	mtd->name = map->name;
+	mtd->type = MTD_OTHER;
+	mtd->erase = mapserial_erase;
+	mtd->size = map->size;
+	mtd->read = mapserial_read;
+	mtd->write = mapserial_write;
+	mtd->sync = mapserial_nop;
+	mtd->flags = (MTD_WRITEABLE|MTD_ERASEABLE);
+//	mtd->erasesize = 512; // page size;
+#ifdef CONFIG_MTD_SL2312_SERIAL_ST
+	mtd->erasesize = M25P80_SECTOR_SIZE; // block size;
+#else
+	mtd->erasesize = 0x1000; // block size;
+#endif
+
+	__module_get(THIS_MODULE);
+	//MOD_INC_USE_COUNT;
+	return mtd;
+}
+
+#define	FLASH_ACCESS_OFFSET	        		0x00000010
+#define	FLASH_ADDRESS_OFFSET            		0x00000014
+#define	FLASH_WRITE_DATA_OFFSET         		0x00000018
+#define	FLASH_READ_DATA_OFFSET          		0x00000018
+
+static __u32 readflash_ctrl_reg(__u32 ofs)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    return __raw_readl(base);
+}
+
+static void writeflash_ctrl_reg(__u32 data, __u32 ofs)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    __raw_writel(data, base);
+}
+
+static int mapserial_erase_block(struct map_info *map,unsigned int block)
+{
+
+	__u32 address;
+#ifdef CONFIG_MTD_SL2312_SERIAL_ST
+
+	if(!m25p80_sector_erase(block, 0))
+		return (MTD_ERASE_DONE);
+#else
+      __u32 opcode;
+      __u32 count=0;
+//      __u8  status;
+
+ //     printk("mapserial_erase_block : erase block %d \n",block);
+//      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | cmd;
+      opcode = 0x80000000 | 0x0200 | 0x50;
+      address = (block << 13);
+      writeflash_ctrl_reg(address,FLASH_ADDRESS_OFFSET);
+      writeflash_ctrl_reg(opcode,FLASH_ACCESS_OFFSET);
+      opcode=readflash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode = readflash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          count++;
+          if (count > 10000)
+          {
+            return (MTD_ERASE_FAILED);
+          }
+      }
+      return (MTD_ERASE_DONE);
+#endif
+}
+
+static int mapserial_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+	struct map_info *map = (struct map_info *)mtd->priv;
+    unsigned int    addr;
+    int             len;
+    unsigned int    block;
+    unsigned int    ret=0;
+
+	addr = instr->addr;
+	len = instr->len;
+    while (len > 0)
+    {
+        block = addr / mtd->erasesize;
+#ifdef CONFIG_MTD_SL2312_SERIAL_ST
+        ret = mapserial_erase_block(map,addr);
+#else
+		ret = mapserial_erase_block(map,block);
+#endif
+        addr = addr + mtd->erasesize;
+        len = len - mtd->erasesize;
+    }
+    return (ret);
+}
+
+static int mapserial_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
+{
+	struct map_info *map = (struct map_info *)mtd->priv;
+//        printk("mapserial_read : \n");
+	map->copy_from(map, buf, from, len);
+	*retlen = len;
+	return 0;
+}
+
+static void mapserial_nop(struct mtd_info *mtd)
+{
+	/* Nothing to see here */
+}
+
+static int mapserial_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
+{
+	struct map_info *map = (struct map_info *)mtd->priv;
+//	printk("mapserial_write : buf %x to %x len %x \n",(int)buf, (int)to, (int)len);
+	//map->copy_to(map, buf, to, len);
+	map->copy_to(map, to, buf, len);
+	*retlen = len;
+	return 0;
+}
+
+int __init map_serial_init(void)
+{
+	register_mtd_chip_driver(&mapserial_chipdrv);
+	return 0;
+}
+
+static void __exit map_serial_exit(void)
+{
+	unregister_mtd_chip_driver(&mapserial_chipdrv);
+}
+
+module_init(map_serial_init);
+module_exit(map_serial_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
+MODULE_DESCRIPTION("MTD chip driver for ROM chips");
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -614,5 +614,30 @@ config MTD_PLATRAM
 
 	  This selection automatically selects the map_ram driver.
 
+#***************************************************************************************
+# Storlink parallel/Serial Flash configuration
+#***************************************************************************************
+config MTD_SL2312_CFI
+        tristate "CFI Flash device mapped on SL2312"
+        depends on MTD_CFI
+        help
+          Map driver for SL2312 demo board.
+
+config MTD_SL2312_SERIAL_ATMEL
+        tristate "ATMEL Serial Flash device mapped on SL2312"
+        depends on MTD_PARTITIONS && ARCH_SL2312
+        help
+          Map driver for SL2312 demo board.
+
+config MTD_SL2312_SERIAL_ST
+        tristate "ST Serial Flash device mapped on SL2312"
+        depends on MTD_PARTITIONS && ARCH_SL2312
+        help
+          Map driver for SL2312 demo board.
+
+config SL2312_SHARE_PIN
+        tristate "Parallel Flash share pin on SL2312 ASIC"
+        depends on SL3516_ASIC
+
 endmenu
 
--- /dev/null
+++ b/drivers/mtd/maps/sl2312-flash-atmel.c
@@ -0,0 +1,554 @@
+/*
+ * $Id: sl2312-flash-atmel.c,v 1.2 2006/06/05 02:35:57 middle Exp $
+ *
+ * Flash and EPROM on Hitachi Solution Engine and similar boards.
+ *
+ * (C) 2001 Red Hat, Inc.
+ *
+ * GPL'd
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <asm/io.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+#include <asm/hardware.h>
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/flash.h>
+#include <linux/init.h> //add
+
+
+#define  g_page_addr  AT45DB321_PAGE_SHIFT    //321 : shift 10  ; 642 : shift 11
+#define  g_chipen     SERIAL_FLASH_CHIP0_EN   //atmel
+
+extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts);
+
+void address_to_page(__u32 address, __u16 *page, __u16 *offset)
+{
+    *page = address / SPAGE_SIZE;
+    *offset = address % SPAGE_SIZE;
+}
+
+static __u32 read_flash_ctrl_reg(__u32 ofs)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    return __raw_readl(base);
+}
+
+static void write_flash_ctrl_reg(__u32 ofs,__u32 data)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    __raw_writel(data, base);
+}
+
+void atmel_read_status(__u8 cmd, __u8 *data)
+{
+      __u32 opcode;
+      __u32 value;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | cmd | g_chipen;
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+
+      value=read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      *data = value & 0xff;
+}
+
+void main_memory_page_read(__u8 cmd, __u16 page, __u16 offset, __u8 *data)
+{
+      __u32 opcode;
+      __u32 address;
+      __u32 value;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS_4X_DATA | cmd | g_chipen;
+      address = (page << g_page_addr) + offset;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+
+      value=read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      *data = value & 0xff;
+}
+
+void buffer_to_main_memory(__u8 cmd, __u16 page)
+{
+      __u32 opcode;
+      __u32 address;
+      __u8  status;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | cmd | g_chipen;
+      address = (page << g_page_addr);
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      atmel_read_status(READ_STATUS_SPI, &status);
+      while(!(status&0x80))
+      {
+          atmel_read_status(READ_STATUS_SPI, &status);
+          flash_delay();
+          schedule();
+      }
+
+}
+
+
+void atmel_flash_read_page(__u32 address, __u8 *buffer, __u32 len)
+{
+    __u8  byte;
+    __u16 page, offset;
+    __u16 i;
+
+    address_to_page(address, &page, &offset);
+
+     for(i=0; i<len; i++,offset++)
+    {
+        main_memory_page_read(MAIN_MEMORY_PAGE_READ_SPI , page, offset, &byte);
+        buffer [i]= byte;
+    }
+}
+
+void atmel_flash_program_page(__u32 address, __u8 *buffer, __u32 len)
+{
+    __u8  pattern;
+    __u16 page, offset;
+    __u32 i;
+
+    address_to_page(address, &page, &offset);
+ //   printk("atmel_flash_program_page: offset %x len %x page %x \n", offset, len, page);
+
+    if(offset)
+ 	    main_memory_to_buffer(MAIN_MEMORY_TO_BUFFER1,page);
+
+    for(i=0; i<len; i++,offset++)
+    {
+        pattern = buffer[i];
+        atmel_buffer_write(BUFFER1_WRITE,offset,pattern);
+    }
+
+  //  printk("atmel_flash_program_page: offset %x \n", offset);
+    buffer_to_main_memory(BUFFER1_TO_MAIN_MEMORY, page);
+  //  printk("atmel_flash_program_page: buffer_to_main_memory %x page\n", page);
+
+}
+
+
+void main_memory_to_buffer(__u8 cmd, __u16 page)
+{
+      __u32 opcode;
+      __u32 address;
+      __u8  status;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | cmd | g_chipen;
+      address = (page << g_page_addr);
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      atmel_read_status(READ_STATUS_SPI, &status);
+      while(!(status&0x80))
+      {
+          atmel_read_status(READ_STATUS_SPI, &status);
+          flash_delay();
+          schedule();
+      }
+
+}
+
+void main_memory_page_program(__u8 cmd, __u16 page, __u16 offset, __u8 data)
+{
+      __u32 opcode;
+      __u32 address;
+      __u8  status;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS_DATA | cmd | g_chipen;
+      address = (page << g_page_addr) + offset;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_WRITE_DATA_OFFSET, data);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      atmel_read_status(READ_STATUS_SPI, &status);
+      while(!(status&0x80))
+      {
+          atmel_read_status(READ_STATUS_SPI, &status);
+          flash_delay();
+          schedule();
+      }
+}
+
+void atmel_buffer_write(__u8 cmd, __u16 offset, __u8 data)
+{
+      __u32 opcode;
+      __u32 address;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS_DATA | cmd  | g_chipen;
+      address = offset;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_WRITE_DATA_OFFSET, data);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+
+}
+
+void atmel_erase_page(__u8 cmd, __u16 page)
+{
+      __u32 opcode;
+      __u32 address;
+      __u8  status;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | cmd | g_chipen;
+      address = (page << g_page_addr);
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      atmel_read_status(READ_STATUS_SPI, &status);
+      while(!(status&0x80))
+      {
+          atmel_read_status(READ_STATUS_SPI, &status);
+          flash_delay();
+          schedule();
+      }
+
+}
+
+void atmel_erase_block(__u8 cmd, __u16 block)
+{
+      __u32 opcode;
+      __u32 address;
+      __u8  status;
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | cmd | g_chipen;
+      address = (block << 13);
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(opcode&0x80000000)
+      {
+          opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      atmel_read_status(READ_STATUS_SPI, &status);
+      while(!(status&0x80))
+      {
+          atmel_read_status(READ_STATUS_SPI, &status);
+          flash_delay();
+          schedule();
+      }
+
+}
+
+void flash_delay(void)
+{
+      int i;
+
+      for(i=0; i<50; i++)
+           i=i;
+}
+
+
+
+
+__u32 sl2312_read32(struct map_info *map, unsigned long ofs)
+{
+
+#if 0
+    __u16 page, offset;
+    __u32 pattern;
+    __u8  byte, i;
+
+     pattern = 0;
+     address_to_page(ofs, &page, &offset);
+     for(i=0; i<4; i++, offset++)
+    {
+        pattern = pattern << 8;
+        main_memory_page_read(MAIN_MEMORY_PAGE_READ_SPI , page, offset, &byte);
+//printk("sl2312_read32:: address = %08x  data = %c \n",ofs,byte);
+        pattern += byte;
+    }
+    return pattern;
+#else
+      return read_flash_ctrl_reg(ofs);
+#endif
+
+}
+
+__u8 sl2312_read8(struct map_info *map, unsigned long ofs)
+{
+    __u16 page, offset;
+    __u8  byte;
+
+     address_to_page(ofs, &page, &offset);
+     main_memory_page_read(MAIN_MEMORY_PAGE_READ_SPI , page, offset, &byte);
+	 //printk("sl2312_read8:: address = %08x  data = %c \n",ofs,byte);
+     return byte;
+
+}
+
+void sl2312_write32(struct map_info *map, __u32 d, unsigned long ofs)
+{
+#if 0
+    __u16 page, offset;
+    __u8  byte, i;
+
+     address_to_page(ofs, &page, &offset);
+     for(i=0; i<4; i++, offset++)
+    {
+    	byte = d & 0xff;
+        main_memory_page_program(MAIN_MEMORY_PROGRAM_BUFFER1, page, offset, byte);
+        d = d >> 8;
+//printk("sl2312_write32:: address = %08x  data = %c \n",ofs,byte);
+    }
+#else
+      write_flash_ctrl_reg(ofs, d);
+#endif
+}
+
+void sl2312_write8(struct map_info *map, __u8 d, unsigned long ofs)
+{
+     __u16 page, offset;
+
+     address_to_page(ofs, &page, &offset);
+     main_memory_page_program(MAIN_MEMORY_PROGRAM_BUFFER1, page, offset, d);
+//printk("sl2312_write8:: address = %08x  data = %c \n",ofs,d);
+
+}
+
+void sl2312_copy_from(struct map_info *map, void *buf, unsigned long ofs, ssize_t len)
+{
+     __u32 size;
+     __u8  *buffer;
+     __u32 length;//i, j,
+
+     //printk("sl2312_copy_from:: address = %08x  datalen = %d \n",ofs,len);
+
+     length = len;
+     buffer = (__u8 *)buf;
+     while(len)
+     {
+        size = SPAGE_SIZE - (ofs%SPAGE_SIZE);
+        if(size > len)
+            size = len;
+        atmel_flash_read_page(ofs, buffer, size);
+        buffer+=size;
+        ofs+=size;
+        len -= size;
+     }
+
+#if 0
+        buffer = (__u8 *)buf;
+        for(i=0; i<length; i+=16)
+       {
+          for(j=0; j<16; j++,buffer++)
+         {
+            if((i*16+j)<length)
+              printk("%x  ",(int)*buffer);
+	 }
+          printk("\n");
+       }
+
+       printk("\n");
+#endif
+
+}
+
+
+void sl2312_copy_to(struct map_info *map, unsigned long ofs, void *buf, ssize_t len)
+{
+     __u32 size;
+     __u8  *buffer;
+
+     buffer = (__u8 *)buf;
+     //printk("sl2312_copy_to:offset %x len %x \n", ofs, len);
+//     printk("sl2312_copy_to:buf is %x \n", (int)buf);
+
+     while(len)
+     {
+        size = SPAGE_SIZE - (ofs%SPAGE_SIZE);
+        if(size > len)
+            size = len;
+        atmel_flash_program_page(ofs, buffer, size);
+        buffer+=size;
+        ofs+=size;
+	len-=size;
+    }
+
+
+}
+
+
+static struct mtd_info *serial_mtd;
+
+static struct mtd_partition *parsed_parts;
+
+static struct map_info sl2312_serial_map = {
+//	name: "SL2312 serial flash",
+//	size: 4194304, //0x400000,
+//		//buswidth: 4,
+//	bankwidth: 4,
+//	phys:		 SL2312_FLASH_BASE,
+//#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
+//	//read32: sl2312_read32,
+//	//read8: sl2312_read8,
+//	copy_from: sl2312_copy_from,
+//	//write8: sl2312_write8,
+//	//write32: sl2312_write32,
+//	read: sl2312_read32,
+//	write: sl2312_write32,
+//	copy_to: sl2312_copy_to
+//#endif
+	.name = "SL2312 serial flash",
+	.size = 4194304, //0x400000,
+		//buswidth: 4,
+	.bankwidth = 4,
+	.phys =		 SL2312_FLASH_BASE,
+#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
+	//read32: sl2312_read32,
+	//read8: sl2312_read8,
+	.copy_from = sl2312_copy_from,
+	//write8: sl2312_write8,
+	//write32: sl2312_write32,
+	.read = sl2312_read32,
+	.write = sl2312_write32,
+	.copy_to = sl2312_copy_to
+#endif
+};
+
+
+
+static struct mtd_partition sl2312_partitions[] = {
+
+
+	///* boot code */
+	//{ name: "bootloader", offset: 0x00000000, size: 0x20000, },
+	///* kernel image */
+	//{ name: "kerel image", offset: 0x000020000, size: 0x2E0000 },
+	///* All else is writable (e.g. JFFS) */
+	//{ name: "user data", offset: 0x00300000, size: 0x00100000, },
+	/* boot code */
+	{ .name = "bootloader", .offset = 0x00000000, .size = 0x20000, },
+	/* kernel image */
+	{ .name = "kerel image", .offset = 0x000020000, .size = 0xE0000 },
+	/* All else is writable (e.g. JFFS) */
+	{ .name = "user data", .offset = 0x00100000, .size = 0x00300000, },
+
+
+};
+
+
+
+static int __init init_sl2312_maps(void)
+{
+	int nr_parts = 0;
+	struct mtd_partition *parts;
+
+	serial_mtd = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
+	if (!serial_mtd)
+		return NULL;
+
+	memset(serial_mtd, 0, sizeof(struct mtd_info));
+	//sl2312flash_map.virt = (unsigned long)ioremap(SL2312_FLASH_BASE, FLASH_SIZE);
+    //sl2312_serial_map.map_priv_1 = (unsigned long)ioremap(SL2312_FLASH_BASE, SFLASH_SIZE);//(unsigned long)FLASH_VBASE;
+    sl2312_serial_map.virt = (unsigned long)ioremap(SL2312_FLASH_BASE, SFLASH_SIZE);//(unsigned long)ioremap(FLASH_START, SFLASH_SIZE);
+    if (!sl2312_serial_map.virt) {
+		printk(" failed to ioremap \n");
+		return -EIO;
+	}
+	serial_mtd = do_map_probe("map_serial", &sl2312_serial_map);
+	if (serial_mtd) {
+		//serial_mtd->module = THIS_MODULE;
+		serial_mtd->owner = THIS_MODULE;
+
+	}
+
+#ifdef CONFIG_MTD_REDBOOT_PARTS
+	nr_parts = parse_redboot_partitions(serial_mtd, &parsed_parts);
+	if (nr_parts > 0)
+		printk(KERN_NOTICE "Found RedBoot partition table.\n");
+	else if (nr_parts < 0)
+		printk(KERN_NOTICE "Error looking for RedBoot partitions.\n");
+#else
+	parsed_parts = sl2312_partitions;
+	parts = sl2312_partitions;
+	nr_parts = sizeof(sl2312_partitions)/sizeof(*parts);
+	nr_parts = sizeof(sl2312_partitions)/sizeof(*parsed_parts);
+#endif /* CONFIG_MTD_REDBOOT_PARTS */
+
+	if (nr_parts > 0)
+	    add_mtd_partitions(serial_mtd, parsed_parts, nr_parts);
+	else
+	    add_mtd_device(serial_mtd);
+
+	return 0;
+}
+
+static void __exit cleanup_sl2312_maps(void)
+{
+	if (parsed_parts)
+	    del_mtd_partitions(serial_mtd);
+	else
+	    del_mtd_device(serial_mtd);
+
+	map_destroy(serial_mtd);
+
+
+}
+
+module_init(init_sl2312_maps);
+module_exit(cleanup_sl2312_maps);
+
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Plus Chen <plus@storlink.com.tw>");
+MODULE_DESCRIPTION("MTD map driver for Storlink Sword boards");
+
--- /dev/null
+++ b/drivers/mtd/maps/sl2312-flash-cfi.c
@@ -0,0 +1,370 @@
+/*======================================================================
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+======================================================================*/
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/string.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/arch/sl2312.h>
+#include <linux/mtd/kvctl.h>
+#include "sl2312_flashmap.h"
+
+
+//extern int parse_afs_partitions(struct mtd_info *, struct mtd_partition **);
+
+/* the base address of FLASH control register */
+#define FLASH_CONTROL_BASE_ADDR	    (IO_ADDRESS(SL2312_FLASH_CTRL_BASE))
+#define SL2312_GLOBAL_BASE_ADDR     (IO_ADDRESS(SL2312_GLOBAL_BASE))
+
+/* define read/write register utility */
+#define FLASH_READ_REG(offset)			(__raw_readl(offset+FLASH_CONTROL_BASE_ADDR))
+#define FLASH_WRITE_REG(offset,val) 	(__raw_writel(val,offset+FLASH_CONTROL_BASE_ADDR))
+
+/* the offset of FLASH control register */
+enum EMAC_REGISTER {
+	FLASH_ID     	= 0x0000,
+	FLASH_STATUS 	= 0x0008,
+	FLASH_TYPE   	= 0x000c,
+	FLASH_ACCESS	= 0x0020,
+	FLASH_ADDRESS   = 0x0024,
+	FLASH_DATA		= 0x0028,
+	FLASH_TIMING    = 0x002c,
+};
+
+//#define FLASH_BASE	FLASH_CONTROL_BASE_ADDR
+//#define FLASH_SIZE	0x00800000 //INTEGRATOR_FLASH_SIZE
+
+//#define FLASH_PART_SIZE 8388608
+
+static unsigned int flash_indirect_access = 0;
+
+#ifdef CONFIG_SL2312_SHARE_PIN
+static unsigned int chip_en = 0x00000000;
+
+void sl2312flash_enable_parallel_flash(void)
+{
+    unsigned int    reg_val;
+
+    reg_val = readl(SL2312_GLOBAL_BASE_ADDR + 0x30);
+    reg_val = reg_val & 0xfffffffd;
+    writel(reg_val,SL2312_GLOBAL_BASE_ADDR + 0x30);
+    return;
+}
+
+void sl2312flash_disable_parallel_flash(void)
+{
+    unsigned int    reg_val;
+
+    reg_val = readl(SL2312_GLOBAL_BASE_ADDR + 0x30);
+    reg_val = reg_val | 0x00000002;
+    writel(reg_val,SL2312_GLOBAL_BASE_ADDR + 0x30);
+    return;
+}
+#endif
+
+
+static struct map_info sl2312flash_map =
+{
+	name:		"SL2312 CFI Flash",
+	size:       FLASH_SIZE,
+	bankwidth:   2,
+	//bankwidth:   1, //for 8 bits width
+    phys:       SL2312_FLASH_BASE,
+};
+
+static struct mtd_info *mtd;
+#if 0
+static struct mtd_partition sl2312_partitions[] = {
+	/* boot code */
+	{
+		name: "bootloader",
+		offset: 0x00000000,
+		size: 0x20000,
+//		mask_flags: MTD_WRITEABLE,
+	},
+	/* kernel image */
+	{
+		name: "kerel image",
+		offset: 0x00020000,
+		size: 0x2E0000
+	},
+	/* All else is writable (e.g. JFFS) */
+	{
+		name: "user data",
+		offset: 0x00300000,
+		size: 0x00100000,
+	}
+};
+#endif
+
+
+
+static int __init sl2312flash_init(void)
+{
+	struct mtd_partition *parts;
+	int nr_parts = 0;
+	int ret;
+#ifndef CONFIG_SL2312_SHARE_PIN
+    unsigned int    reg_val;
+#endif
+
+    printk("SL2312 MTD Driver Init.......\n");
+
+#ifndef CONFIG_SL2312_SHARE_PIN
+	/* enable flash */
+    reg_val = readl(SL2312_GLOBAL_BASE_ADDR + 0x30);
+    reg_val = reg_val & 0xfffffffd;
+    writel(reg_val,SL2312_GLOBAL_BASE_ADDR + 0x30);
+#else
+    sl2312flash_enable_parallel_flash();      /* enable Parallel FLASH */
+#endif
+    FLASH_WRITE_REG(FLASH_ACCESS,0x00004000); /* parallel flash direct access mode */
+    ret = FLASH_READ_REG(FLASH_ACCESS);
+    if (ret == 0x00004000)
+    {
+        flash_indirect_access = 0;  /* parallel flash direct access */
+    }
+    else
+    {
+        flash_indirect_access = 1;  /* parallel flash indirect access */
+    }
+
+	/*
+	 * Also, the CFI layer automatically works out what size
+	 * of chips we have, and does the necessary identification
+	 * for us automatically.
+	 */
+#ifdef CONFIG_GEMINI_IPI
+	sl2312flash_map.virt = FLASH_VBASE;//(unsigned int *)ioremap(SL2312_FLASH_BASE, FLASH_SIZE);
+#else
+	sl2312flash_map.virt = (unsigned int *)ioremap(SL2312_FLASH_BASE, FLASH_SIZE);
+#endif
+	//printk("sl2312flash_map.virt  = %08x\n",(unsigned int)sl2312flash_map.virt);
+
+//	simple_map_init(&sl2312flash_map);
+
+	mtd = do_map_probe("cfi_probe", &sl2312flash_map);
+	if (!mtd)
+	{
+#ifdef CONFIG_SL2312_SHARE_PIN
+        sl2312flash_disable_parallel_flash();      /* disable Parallel FLASH */
+#endif
+		return -ENXIO;
+	}
+	mtd->owner = THIS_MODULE;
+//    mtd->erase = flash_erase;
+//    mtd->read = flash_read;
+//    mtd->write = flash_write;
+
+    parts = sl2312_partitions;
+	nr_parts = sizeof(sl2312_partitions)/sizeof(*parts);
+	ret = add_mtd_partitions(mtd, parts, nr_parts);
+	/*If we got an error, free all resources.*/
+	if (ret < 0) {
+		del_mtd_partitions(mtd);
+		map_destroy(mtd);
+	}
+#ifdef CONFIG_SL2312_SHARE_PIN
+    sl2312flash_disable_parallel_flash();      /* disable Parallel FLASH */
+#endif
+    printk("SL2312 MTD Driver Init Success ......\n");
+	return ret;
+}
+
+static void __exit sl2312flash_exit(void)
+{
+	if (mtd) {
+		del_mtd_partitions(mtd);
+		map_destroy(mtd);
+	}
+
+	if (sl2312flash_map.virt) {
+	    iounmap((void *)sl2312flash_map.virt);
+	    sl2312flash_map.virt = 0;
+	}
+}
+
+char chrtohex(char c)
+{
+  char val;
+  if ((c >= '0') && (c <= '9'))
+  {
+    val = c - '0';
+    return val;
+  }
+  else if ((c >= 'a') && (c <= 'f'))
+  {
+    val = 10 + (c - 'a');
+    return val;
+  }
+  else if ((c >= 'A') && (c <= 'F'))
+  {
+    val = 10 + (c - 'A');
+    return val;
+  }
+  printk("<1>Error number\n");
+  return 0;
+}
+
+
+int get_vlaninfo(vlaninfo* vlan)
+{
+	vctl_mheader head;
+	vctl_entry entry;
+	struct mtd_info *mymtd=NULL;
+	int i, j, loc = 0;
+	char *payload=0, *tmp1, *tmp2, tmp3[9];
+	size_t retlen;
+
+	#ifdef CONFIG_SL2312_SHARE_PIN
+	sl2312flash_enable_parallel_flash();
+	#endif
+	for(i=0;i<MAX_MTD_DEVICES;i++)
+	{
+		mymtd=get_mtd_device(NULL,i);
+		//    printk("mymtd->name: %s\n", mymtd->name);
+		if(mymtd && !strcmp(mymtd->name,"VCTL"))
+		{
+			//      printk("%s\n", mymtd->name);
+			break;
+		}
+	}
+	if( i >= MAX_MTD_DEVICES)
+	{
+		printk("Can't find version control\n");
+		#ifdef CONFIG_SL2312_SHARE_PIN
+		sl2312flash_disable_parallel_flash();
+		#endif
+		return 0;
+	}
+
+	if (!mymtd | !mymtd->read)
+	{
+		printk("<1>Can't read Version Configuration\n");
+		#ifdef CONFIG_SL2312_SHARE_PIN
+		sl2312flash_disable_parallel_flash();
+		#endif
+		return 0;
+	}
+
+	mymtd->read(mymtd, 0, VCTL_HEAD_SIZE, &retlen, (u_char*)&head);
+	//  printk("entry header: %c%c%c%c\n", head.header[0], head.header[1], head.header[2], head.header[3]);
+	//  printk("entry number: %x\n", head.entry_num);
+	if ( strncmp(head.header, "FLFM", 4) )
+	{
+		printk("VCTL is a erase block\n");
+		#ifdef CONFIG_SL2312_SHARE_PIN
+		sl2312flash_disable_parallel_flash();
+		#endif
+		return 0;
+	}
+	loc += retlen;
+	for (i = 0; i < head.entry_num; i++)
+	{
+		mymtd->read(mymtd, loc, VCTL_ENTRY_LEN, &retlen, (u_char*)&entry);
+		//    printk("type: %x\n", entry.type);
+		//    printk("size: %x\n", entry.size);
+		strncpy(tmp3, entry.header, 4);
+		if (entry.type == VCT_VLAN)
+		{
+			for (j = 0; j < 6 ; j++)
+			{
+				vlan[0].mac[j] = 0;
+				vlan[1].mac[j] = 0;
+			}
+			vlan[0].vlanid = 1;
+			vlan[1].vlanid = 2;
+			vlan[0].vlanmap = 0x7F;
+			vlan[1].vlanmap = 0x80;
+
+			payload = (char *)kmalloc(entry.size - VCTL_ENTRY_LEN, GFP_KERNEL);
+			loc += VCTL_ENTRY_LEN;
+			mymtd->read(mymtd, loc, entry.size - VCTL_ENTRY_LEN, &retlen, payload);
+			//      printk("%s\n", payload);
+			tmp1 = strstr(payload, "MAC1:");
+			tmp2 = strstr(payload, "MAC2:");
+			if(!tmp1||!tmp2){
+				kfree(payload);
+				#ifdef CONFIG_SL2312_SHARE_PIN
+				sl2312flash_disable_parallel_flash();
+				#endif
+				printk("Error VCTL format!!\n");
+				return 0;
+			}
+			tmp1 += 7;
+			tmp2 += 7;
+
+
+			for (j = 0; j < 6; j++)
+			{
+				vlan[0].mac[j] = chrtohex(tmp1[2*j])*16 + chrtohex(tmp1[(2*j)+1]);
+				vlan[1].mac[j] = chrtohex(tmp2[2*j])*16 + chrtohex(tmp2[(2*j)+1]);
+			}
+			tmp1 = strstr(payload, "ID1:");
+			tmp2 = strstr(payload, "ID2:");
+			tmp1 += 4;
+			tmp2 += 4;
+			vlan[0].vlanid = tmp1[0] - '0';
+			vlan[1].vlanid = tmp2[0] - '0';
+			tmp1 = strstr(payload, "MAP1:");
+			tmp2 = strstr(payload, "MAP2:");
+			tmp1 += 7;
+			tmp2 += 7;
+			vlan[0].vlanmap = chrtohex(tmp1[0]) * 16 + chrtohex(tmp1[1]);
+			vlan[1].vlanmap = chrtohex(tmp2[0]) * 16 + chrtohex(tmp2[1]);
+			//  printk("Vlan1 id:%x map:%02x mac:%x%x%x%x%x%x\n", vlan[0].vlanid, vlan[0].vlanmap, vlan[0].mac[0], vlan[0].mac[1], vlan[0].mac[2], vlan[0].mac[3], vlan[0].mac[4], vlan[0].mac[5]);
+			//  printk("Vlan2 id:%x map:%02x mac:%x%x%x%x%x%x\n", vlan[1].vlanid, vlan[1].vlanmap, vlan[1].mac[0], vlan[1].mac[1], vlan[1].mac[2], vlan[1].mac[3], vlan[1].mac[4], vlan[1].mac[5]);
+			break;
+		}
+		loc += entry.size;
+	}
+	if ( entry.type == VCT_VLAN )
+	{
+		#ifdef CONFIG_SL2312_SHARE_PIN
+		sl2312flash_disable_parallel_flash();
+		#endif
+		kfree(payload);
+		return 1;
+	}
+	if (i >= head.entry_num)
+	printk("Can't find vlan information\n");
+	#ifdef CONFIG_SL2312_SHARE_PIN
+	sl2312flash_disable_parallel_flash();
+	#endif
+	return 0;
+}
+
+EXPORT_SYMBOL(get_vlaninfo);
+
+
+module_init(sl2312flash_init);
+module_exit(sl2312flash_exit);
+
+MODULE_AUTHOR("Storlink Ltd");
+MODULE_DESCRIPTION("CFI map driver");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ b/drivers/mtd/maps/sl2312-flash-m25p80.c
@@ -0,0 +1,498 @@
+/*
+ * $Id: sl2312-flash-m25p80.c,v 1.2 2006/06/02 08:46:02 middle Exp $
+ *
+ * Flash and EPROM on Hitachi Solution Engine and similar boards.
+ *
+ * (C) 2001 Red Hat, Inc.
+ *
+ * GPL'd
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <asm/io.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+#include <asm/hardware.h>
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/flash.h>
+#include <linux/init.h> //add
+#define  g_chipen     SERIAL_FLASH_CHIP0_EN   //ST
+
+//static int m25p80_page_program(__u32 address, __u8 data, __u32 schip_en);
+static void m25p80_write_cmd(__u8 cmd, __u32 schip_en);
+extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts);
+
+
+static __u32 read_flash_ctrl_reg(__u32 ofs)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    return __raw_readl(base);
+}
+
+static void write_flash_ctrl_reg(__u32 ofs,__u32 data)
+{
+    __u32 *base;
+
+    base = (__u32 *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE + ofs));
+    __raw_writel(data, base);
+}
+
+static void m25p80_read(__u32 address, __u8 *data, __u32 schip_en)
+{
+      __u32 opcode,status;
+      __u32 value;
+
+      //opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | M25P80_READ;
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS_DATA | M25P80_READ;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+
+      	opcode|=g_chipen;
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      status=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(status&0x80000000)
+      {
+          status=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+
+      value=read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      *data = value & 0xff;
+}
+
+static int m25p80_page_program(__u32 address, __u8 *data, __u32 schip_en)
+{
+      __u32 opcode;
+      __u32  status;
+	  __u32 tmp;
+	  int res = FLASH_ERR_OK;
+	  //volatile FLASH_DATA_T* data_ptr = (volatile FLASH_DATA_T*) data;
+	  opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | M25P80_READ_STATUS;
+
+      	      opcode|=g_chipen;
+
+          write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+          tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+          //middle delay_ms(130);
+          status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+          if((status&0x02)==0x02)
+      	  {
+      	       //middle delay_ms(100);
+               m25p80_write_cmd(M25P80_WRITE_DISABLE, schip_en);
+          }
+
+
+      m25p80_write_cmd(M25P80_WRITE_ENABLE, schip_en);
+      ////middle delay_ms(10);
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS_DATA | M25P80_PAGE_PROGRAM;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      write_flash_ctrl_reg(FLASH_WRITE_DATA_OFFSET, *data);
+
+      //status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      //while(status!=data)
+      //{
+      //    status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      //    //middle delay_ms(10);
+      //}
+
+      	opcode|=g_chipen;
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+      //opcode=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | M25P80_READ_STATUS;
+
+      	opcode|=g_chipen;
+
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+      status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      //while(status&0xfd)
+      while(status&0x01)
+      {
+      	  //if((status&0x9c)!=0)
+      	  //	printf("  m25p80_page_program	Protect Status = %x\n",status);
+      	  write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      	  tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+          status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+          flash_delay();
+          schedule();
+          //middle delay_ms(50);
+      }
+      //printf("status = %x, data = %x\n",status,data);
+      if((status&0x02)==0x02)
+      {
+	  //middle delay_ms(100);
+          m25p80_write_cmd(M25P80_WRITE_DISABLE, schip_en);
+      }
+    //};//while (len > 0)
+    return res;
+}
+
+void m25p80_copy_from(struct map_info *map, void *buf, unsigned long ofs, ssize_t len)
+{
+//     __u32 size;
+     __u8  *buffer;
+     __u32 length;//i, j,
+
+	length = len;
+     buffer = (__u8 *)buf;
+     while(len)
+     {
+        m25p80_read(ofs, buffer, g_chipen);
+        buffer++;
+        ofs++;
+        len --;
+     }	;
+
+}
+
+__u32 m25p80_read32(struct map_info *map, unsigned long ofs)
+{
+
+      return read_flash_ctrl_reg(ofs);
+
+
+}
+
+void m25p80_write32(struct map_info *map, __u32 d, unsigned long ofs)
+{
+
+      write_flash_ctrl_reg(ofs, d);
+
+}
+
+void m25p80_copy_to(struct map_info *map, unsigned long ofs, void *buf, ssize_t len)
+{
+     __u32 size, i, ret;
+
+     while(len > 0)
+     {
+        if(len >= M25P80_PAGE_SIZE)
+			size = M25P80_PAGE_SIZE;
+		else
+			size = len;
+
+        for(i=0;i<size;i++)
+	    {
+	    	ret = m25p80_page_program( (ofs+i),  (buf+i),  g_chipen);
+	    }
+        buf+=M25P80_PAGE_SIZE;
+        ofs+=M25P80_PAGE_SIZE;
+		len-=M25P80_PAGE_SIZE;
+
+    };
+
+
+}
+
+static struct mtd_info *serial_mtd;
+
+static struct mtd_partition *parsed_parts;
+
+static struct map_info m25p80_map = {
+
+	.name = "SL2312 serial flash m25p80",
+	.size = 1048576, //0x100000,
+		//buswidth: 4,
+	.bankwidth = 4,
+	.phys =		 SL2312_FLASH_BASE,
+#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
+	.copy_from = m25p80_copy_from,
+	.read = m25p80_read32,
+	.write = m25p80_write32,
+	.copy_to = m25p80_copy_to
+#endif
+};
+
+
+
+static struct mtd_partition m25p80_partitions[] = {
+
+	/* boot code */
+	{ .name = "bootloader", .offset = 0x00000000, .size = 0x20000, },
+	/* kernel image */
+	{ .name = "kerel image", .offset = 0x000020000, .size = 0xC0000 },
+	/* All else is writable (e.g. JFFS) */
+	{ .name = "user data", .offset = 0x000E0000, .size = 0x00010000, },
+
+
+};
+
+void flash_delay()
+{
+	int i,j;
+	for(i=0;i<0x100;i++)
+		j=i*3+5;
+}
+
+int m25p80_sector_erase(__u32 address, __u32 schip_en)
+{
+      __u32 opcode;
+      __u32  status;
+      __u32 tmp;
+      int res = FLASH_ERR_OK;
+	//printf("\n-->m25p80_sector_erase");
+	if(address >= FLASH_START)
+		address-=FLASH_START;
+
+      m25p80_write_cmd(M25P80_WRITE_ENABLE, schip_en);
+      //printf("\n     m25p80_sector_erase : after we-en");
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_SHIFT_ADDRESS | M25P80_SECTOR_ERASE;
+      write_flash_ctrl_reg(FLASH_ADDRESS_OFFSET, address);
+      #ifdef MIDWAY_DIAG
+      	opcode|=schip_en;
+      #endif
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | M25P80_READ_STATUS;
+      #ifdef MIDWAY_DIAG
+      	opcode|=schip_en;
+      #endif
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+      status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      //while(status&0xfd)
+      while(status&0x01)
+      {
+      	  //if((status&0x9c)!=0)
+      	  //	printf("  m25p80_sector_erase	Protect Status = %x\n",status);
+      	  write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      	  tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+          status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+          flash_delay();
+          schedule();
+          //middle delay_ms(50);
+      }
+      if((status&0x02)==0x02)
+      {
+      	  //middle delay_ms(100);
+          m25p80_write_cmd(M25P80_WRITE_DISABLE, schip_en);
+      }
+      //printf("\n<--m25p80_sector_erase");
+      return res;
+}
+
+static void m25p80_write_cmd(__u8 cmd, __u32 schip_en)
+{
+      __u32 opcode,tmp;
+      __u32  status;
+
+
+
+
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE | cmd;
+
+      	opcode|=g_chipen;
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(tmp&0x80000000)
+      {
+          tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      //////
+      opcode = 0x80000000 | FLASH_ACCESS_ACTION_OPCODE_DATA | M25P80_READ_STATUS;
+
+      	opcode|=g_chipen;
+
+      write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      while(tmp&0x80000000)
+      {
+          tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+          flash_delay();
+          schedule();
+      }
+      //middle delay_ms(130);
+      status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      //printf("\ncmd =%x  status = %x",cmd,status);
+      if(cmd==M25P80_WRITE_ENABLE)
+      {
+      	//printf("\n**-->enable**  status = %x",status);
+      	//middle delay_ms(100);
+      	   while((status&0x03) != 2)
+      	   {
+      	   	//if((status&0x9c)!=0)
+      	  	//    printf("	M25P80_WRITE_ENABLE   Protect Status = %x\n",status);
+
+      	   	  write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      	   	  tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    //flash_delay();
+      			}
+      	       status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      	       //printf("\n**enable**  status = %x",status);
+      	       flash_delay();
+      	       schedule();
+      	       //middle delay_ms(100);
+      	   }
+      }
+      else if(cmd==M25P80_WRITE_DISABLE)
+      {
+      	   //while((status&0x03) == 2)
+      	   //   printf("\n**disable**  status = %x",status);
+      	   //middle delay_ms(100);
+      	   while((status&0x03) != 0)
+      	   {
+	       //m25p80_write_status((status&0xfd),schip_en);
+      	       write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      	       tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      		while(tmp&0x80000000)
+      		{
+      		    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      		    flash_delay();
+      		    schedule();
+      		}
+      	       status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      	       //printf("\n**disable**  status = %x",status);
+      	       flash_delay();
+      	       schedule();
+      	       //middle delay_ms(50);
+      	   }
+      }
+      else
+      {
+      	   //while((status&0x01) !=0)
+      	   while((status&0x01) !=0)
+      	   {
+      	   	  write_flash_ctrl_reg(FLASH_ACCESS_OFFSET, opcode);
+      	   	  tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			while(tmp&0x80000000)
+      			{
+      			    tmp=read_flash_ctrl_reg(FLASH_ACCESS_OFFSET);
+      			    flash_delay();
+      			    schedule();
+      			}
+      	       status = read_flash_ctrl_reg(FLASH_READ_DATA_OFFSET);
+      	       flash_delay();
+      	       schedule();
+      	       //middle delay_ms(50);
+      	   }
+      }
+      //////
+
+      //printf("\n<--  status = %x",status);
+}
+
+static int __init init_sl2312_m25p80(void)
+{
+	int nr_parts = 0;
+	struct mtd_partition *parts;
+
+	serial_mtd = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
+	if (!serial_mtd)
+		return NULL;
+
+	memset(serial_mtd, 0, sizeof(struct mtd_info));
+	m25p80_map.virt = (unsigned long)ioremap(SL2312_FLASH_BASE, SFLASH_SIZE);//(unsigned long)ioremap(FLASH_START, SFLASH_SIZE);
+    if (!m25p80_map.virt) {
+		printk(" failed to ioremap \n");
+		return -EIO;
+	}
+	serial_mtd = do_map_probe("map_serial", &m25p80_map);
+	if (serial_mtd) {
+		serial_mtd->owner = THIS_MODULE;
+
+	}
+
+#ifdef CONFIG_MTD_REDBOOT_PARTS
+	nr_parts = parse_redboot_partitions(serial_mtd, &parsed_parts);
+	if (nr_parts > 0)
+		printk(KERN_NOTICE "Found RedBoot partition table.\n");
+	else if (nr_parts < 0)
+		printk(KERN_NOTICE "Error looking for RedBoot partitions.\n");
+#else
+	parsed_parts = m25p80_partitions;
+	parts = m25p80_partitions;
+	nr_parts = sizeof(m25p80_partitions)/sizeof(*parts);
+	nr_parts = sizeof(m25p80_partitions)/sizeof(*parsed_parts);
+#endif /* CONFIG_MTD_REDBOOT_PARTS */
+
+	if (nr_parts > 0)
+	    add_mtd_partitions(serial_mtd, parsed_parts, nr_parts);
+	else
+	    add_mtd_device(serial_mtd);
+
+	return 0;
+}
+
+static void __exit cleanup_sl2312_m25p80(void)
+{
+	if (parsed_parts)
+	    del_mtd_partitions(serial_mtd);
+	else
+	    del_mtd_device(serial_mtd);
+
+	map_destroy(serial_mtd);
+
+
+}
+
+module_init(init_sl2312_m25p80);
+module_exit(cleanup_sl2312_m25p80);
+
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Plus Chen <plus@storlink.com.tw>");
+MODULE_DESCRIPTION("MTD map driver for Storlink Sword boards");
+
--- /dev/null
+++ b/drivers/mtd/maps/sl2312_flashmap.h
@@ -0,0 +1,20 @@
+/*
+ * Please note that the name are used in mkflash script. Therefore
+ * don't change them.  If you want to add different partitions, you
+ * will need to modify mkflash script as well so that the end image
+ * is what you include here!
+ *
+ * Also, the 7th item is always the size, so please don't add extra
+ * spaces in the name or other items.
+ *
+ *  - Alan
+ */
+
+static struct mtd_partition sl2312_partitions[] = {
+	{ name: "RedBoot", 	 offset: 0x00000000, size: 0x00020000, },
+	{ name: "kernel", 	 offset: 0x00020000, size: 0x00100000, },
+	{ name: "rootfs", 	 offset: 0x00120000, size: 0x006A0000, },
+	{ name: "VCTL", 	 offset: 0x007C0000, size: 0x00010000, },
+	{ name: "cfg", 	 	 offset: 0x007D0000, size: 0x00020000, },
+	{ name: "FIS directory", offset: 0x007F0000, size: 0x00010000, }
+};
--- /dev/null
+++ b/drivers/mtd/maps/sl2312_flashmap.h.16MB
@@ -0,0 +1,21 @@
+/*
+ * Please note that the name are used in mkflash script. Therefore
+ * don't change them.  If you want to add different partitions, you
+ * will need to modify mkflash script as well so that the end image
+ * is what you include here!
+ *
+ * Also, the 7th item is always the size, so please don't add extra
+ * spaces in the name or other items.
+ *
+ *  - Alan
+ */
+
+static struct mtd_partition sl2312_partitions[] = {
+	{ name: "RedBoot",     	 offset: 0x00000000, size: 0x00020000, },
+	{ name: "Kernel",      	 offset: 0x00020000, size: 0x00300000, },
+	{ name: "Ramdisk",     	 offset: 0x00320000, size: 0x00600000, },
+	{ name: "Application", 	 offset: 0x00920000, size: 0x00600000, },
+	{ name: "VCTL", 	 offset: 0x00F20000, size: 0x00020000, },
+	{ name: "CurConf", 	 offset: 0x00F40000, size: 0x000A0000, },
+	{ name: "FIS directory", offset: 0x00FE0000, size: 0x00020000, }
+};
--- /dev/null
+++ b/drivers/mtd/maps/sl2312_flashmap.h.8MB
@@ -0,0 +1,21 @@
+/*
+ * Please note that the name are used in mkflash script. Therefore
+ * don't change them.  If you want to add different partitions, you
+ * will need to modify mkflash script as well so that the end image
+ * is what you include here!
+ *
+ * Also, the 7th item is always the size, so please don't add extra
+ * spaces in the name or other items.
+ *
+ *  - Alan
+ */
+
+static struct mtd_partition sl2312_partitions[] = {
+	{ name: "RedBoot", 	 offset: 0x00000000, size: 0x00020000, },
+	{ name: "Kernel", 	 offset: 0x00020000, size: 0x00200000, },
+	{ name: "Ramdisk", 	 offset: 0x00220000, size: 0x00280000, },
+	{ name: "Application", 	 offset: 0x004A0000, size: 0x00300000, },
+	{ name: "VCTL", 	 offset: 0x007A0000, size: 0x00020000, },
+	{ name: "CurConf", 	 offset: 0x007C0000, size: 0x00020000, },
+	{ name: "FIS directory", offset: 0x007E0000, size: 0x00020000, }
+};
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -59,6 +59,77 @@ struct mtd_file_info {
 	enum mtd_file_modes mode;
 };
 
+/***********************************************************************
+/*             Storlink SoC -- flash
+/***********************************************************************/
+#ifdef CONFIG_SL2312_SHARE_PIN
+unsigned int share_pin_flag=0;		// bit0:FLASH, bit1:UART, bit2:EMAC, bit3-4:IDE
+unsigned int check_sleep_flag=0;	// bit0:FLASH, bit1:IDE
+static spinlock_t sl2312_flash_lock = SPIN_LOCK_UNLOCKED;
+EXPORT_SYMBOL(share_pin_flag);
+int dbg=0;
+DECLARE_WAIT_QUEUE_HEAD(wq);
+extern struct wait_queue_head_t *flash_wait;
+unsigned int flash_req=0;
+void mtd_lock()
+{
+	struct task_struct *tsk = current;
+	unsigned int value ;
+	unsigned long flags;
+	flash_req = 1;
+	DECLARE_WAITQUEUE(wait, tsk);
+	add_wait_queue(&wq, &wait);
+	for(;;)
+	{
+		set_task_state(tsk, TASK_INTERRUPTIBLE);
+		spin_lock_irqsave(&sl2312_flash_lock,flags);
+		if((share_pin_flag&0x1E)){//||(check_sleep_flag&0x00000002)) {
+			spin_unlock_irqrestore(&sl2312_flash_lock, flags);
+			check_sleep_flag |= 0x00000001;
+			if(dbg)
+				printk("mtd yield %x %x\n",share_pin_flag,check_sleep_flag);
+			wake_up_interruptible(&flash_wait);
+			schedule();
+		}
+		else {
+			check_sleep_flag &= ~0x01;
+			share_pin_flag |= 0x00000001 ;			// set share pin flag
+			spin_unlock_irqrestore(&sl2312_flash_lock, flags);
+			value = readl(IO_ADDRESS((SL2312_GLOBAL_BASE+GLOBAL_MISC_REG)));
+			value = value & (~PFLASH_SHARE_BIT) ;
+			writel(value,IO_ADDRESS((SL2312_GLOBAL_BASE+GLOBAL_MISC_REG)));
+			if(dbg)
+				printk("mtd Go %x %x\n",share_pin_flag,check_sleep_flag);
+			tsk->state = TASK_RUNNING;
+			remove_wait_queue(&wq, &wait);
+			return ;
+		}
+	}
+}
+
+void mtd_unlock()
+{
+	unsigned int value ;
+	unsigned long flags;
+
+	spin_lock_irqsave(&sl2312_flash_lock,flags);		// Disable IRQ
+	value = readl(IO_ADDRESS((SL2312_GLOBAL_BASE+GLOBAL_MISC_REG)));
+	value = value | PFLASH_SHARE_BIT ;				// Disable Flash PADs
+	writel(value,IO_ADDRESS((SL2312_GLOBAL_BASE+GLOBAL_MISC_REG)));
+	share_pin_flag &= ~(0x00000001);			// clear share pin flag
+	check_sleep_flag &= ~0x00000001;
+	spin_unlock_irqrestore(&sl2312_flash_lock, flags);	// Restore IRQ
+	if (check_sleep_flag & 0x00000002)
+	{
+		check_sleep_flag &= ~(0x00000002);
+		wake_up_interruptible(&flash_wait);
+	}
+	DEBUG(MTD_DEBUG_LEVEL0, "Flash Unlock...\n");
+	flash_req = 0;
+}
+#endif
+/***********************************************************************/
+
 static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
 {
 	struct mtd_file_info *mfi = file->private_data;
@@ -162,13 +233,21 @@ static ssize_t mtd_read(struct file *fil
 	int len;
 	char *kbuf;
 
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_lock();				// sl2312 share pin lock
+#endif
+
 	DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n");
 
 	if (*ppos + count > mtd->size)
 		count = mtd->size - *ppos;
 
-	if (!count)
+	if (!count){
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 		return 0;
+	}
 
 	/* FIXME: Use kiovec in 2.5 to lock down the user's buffers
 	   and pass them directly to the MTD functions */
@@ -178,8 +257,12 @@ static ssize_t mtd_read(struct file *fil
 	else
 		kbuf=kmalloc(count, GFP_KERNEL);
 
-	if (!kbuf)
+	if (!kbuf) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 		return -ENOMEM;
+	}
 
 	while (count) {
 
@@ -224,6 +307,9 @@ static ssize_t mtd_read(struct file *fil
 			*ppos += retlen;
 			if (copy_to_user(buf, kbuf, retlen)) {
 				kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+				mtd_unlock();				// sl2312 share pin lock
+#endif
 				return -EFAULT;
 			}
 			else
@@ -235,13 +321,19 @@ static ssize_t mtd_read(struct file *fil
 				count = 0;
 		}
 		else {
-			kfree(kbuf);
+	 		kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return ret;
 		}
 
 	}
 
 	kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 	return total_retlen;
 } /* mtd_read */
 
@@ -255,24 +347,40 @@ static ssize_t mtd_write(struct file *fi
 	int ret=0;
 	int len;
 
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_lock();				// sl2312 share pin lock
+#endif
+
 	DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n");
 
-	if (*ppos == mtd->size)
+	if (*ppos == mtd->size){
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 		return -ENOSPC;
+	}
 
 	if (*ppos + count > mtd->size)
 		count = mtd->size - *ppos;
 
-	if (!count)
+	if (!count){
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 		return 0;
+	}
 
 	if (count > MAX_KMALLOC_SIZE)
 		kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
 	else
 		kbuf=kmalloc(count, GFP_KERNEL);
 
-	if (!kbuf)
+	if (!kbuf) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+		mtd_unlock();				// sl2312 share pin lock
+#endif
 		return -ENOMEM;
+	}
 
 	while (count) {
 
@@ -283,6 +391,9 @@ static ssize_t mtd_write(struct file *fi
 
 		if (copy_from_user(kbuf, buf, len)) {
 			kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
 		}
 
@@ -323,11 +434,17 @@ static ssize_t mtd_write(struct file *fi
 		}
 		else {
 			kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return ret;
 		}
 	}
 
 	kfree(kbuf);
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
 	return total_retlen;
 } /* mtd_write */
 
@@ -381,36 +498,67 @@ static int mtd_ioctl(struct inode *inode
 	u_long size;
 	struct mtd_info_user info;
 
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_lock();				// sl2312 share pin lock
+#endif
+
 	DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
 
 	size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
 	if (cmd & IOC_IN) {
 		if (!access_ok(VERIFY_READ, argp, size))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 	}
 	if (cmd & IOC_OUT) {
 		if (!access_ok(VERIFY_WRITE, argp, size))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 	}
 
 	switch (cmd) {
 	case MEMGETREGIONCOUNT:
 		if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int)))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 		break;
 
 	case MEMGETREGIONINFO:
 	{
 		struct region_info_user ur;
 
-		if (copy_from_user(&ur, argp, sizeof(struct region_info_user)))
+		if (copy_from_user(&ur, argp, sizeof(struct region_info_user))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
-		if (ur.regionindex >= mtd->numeraseregions)
+		if (ur.regionindex >= mtd->numeraseregions) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EINVAL;
+		}
 		if (copy_to_user(argp, &(mtd->eraseregions[ur.regionindex]),
-				sizeof(struct mtd_erase_region_info)))
+				sizeof(struct mtd_erase_region_info))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 		break;
 	}
 
@@ -433,7 +581,12 @@ static int mtd_ioctl(struct inode *inode
 		struct erase_info *erase;
 
 		if(!(file->f_mode & 2))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EPERM;
+		}
 
 		erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
 		if (!erase)
@@ -447,6 +600,9 @@ static int mtd_ioctl(struct inode *inode
 			if (copy_from_user(&erase->addr, argp,
 				    sizeof(struct erase_info_user))) {
 				kfree(erase);
+#ifdef CONFIG_SL2312_SHARE_PIN
+				mtd_unlock();				// sl2312 share pin lock
+#endif
 				return -EFAULT;
 			}
 			erase->mtd = mtd;
@@ -484,14 +640,26 @@ static int mtd_ioctl(struct inode *inode
 		struct mtd_oob_buf buf;
 		struct mtd_oob_ops ops;
 
-		if(!(file->f_mode & 2))
+		if(!(file->f_mode & 2)) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EPERM;
+		}
 
-		if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
+		if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
-		if (buf.length > 4096)
+		if (buf.length > 4096) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EINVAL;
+		}
 
 		if (!mtd->write_oob)
 			ret = -EOPNOTSUPP;
@@ -499,8 +667,12 @@ static int mtd_ioctl(struct inode *inode
 			ret = access_ok(VERIFY_READ, buf.ptr,
 					buf.length) ? 0 : EFAULT;
 
-		if (ret)
+		if (ret) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return ret;
+		}
 
 		ops.ooblen = buf.length;
 		ops.ooboffs = buf.start & (mtd->oobsize - 1);
@@ -536,19 +708,35 @@ static int mtd_ioctl(struct inode *inode
 		struct mtd_oob_buf buf;
 		struct mtd_oob_ops ops;
 
-		if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
+		if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
-		if (buf.length > 4096)
+		if (buf.length > 4096) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EINVAL;
+		}
 
-		if (!mtd->read_oob)
+		if (!mtd->read_oob) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			ret = -EOPNOTSUPP;
+		}
 		else
 			ret = access_ok(VERIFY_WRITE, buf.ptr,
 					buf.length) ? 0 : -EFAULT;
-		if (ret)
+		if (ret) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return ret;
+		}
 
 		ops.ooblen = buf.length;
 		ops.ooboffs = buf.start & (mtd->oobsize - 1);
@@ -580,7 +768,12 @@ static int mtd_ioctl(struct inode *inode
 		struct erase_info_user info;
 
 		if (copy_from_user(&info, argp, sizeof(info)))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
 		if (!mtd->lock)
 			ret = -EOPNOTSUPP;
@@ -594,7 +787,12 @@ static int mtd_ioctl(struct inode *inode
 		struct erase_info_user info;
 
 		if (copy_from_user(&info, argp, sizeof(info)))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
 		if (!mtd->unlock)
 			ret = -EOPNOTSUPP;
@@ -629,11 +827,21 @@ static int mtd_ioctl(struct inode *inode
 		loff_t offs;
 
 		if (copy_from_user(&offs, argp, sizeof(loff_t)))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 		if (!mtd->block_isbad)
 			ret = -EOPNOTSUPP;
 		else
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return mtd->block_isbad(mtd, offs);
+		}
 		break;
 	}
 
@@ -642,11 +850,21 @@ static int mtd_ioctl(struct inode *inode
 		loff_t offs;
 
 		if (copy_from_user(&offs, argp, sizeof(loff_t)))
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 		if (!mtd->block_markbad)
 			ret = -EOPNOTSUPP;
 		else
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return mtd->block_markbad(mtd, offs);
+		}
 		break;
 	}
 
@@ -654,8 +872,12 @@ static int mtd_ioctl(struct inode *inode
 	case OTPSELECT:
 	{
 		int mode;
-		if (copy_from_user(&mode, argp, sizeof(int)))
+		if (copy_from_user(&mode, argp, sizeof(int))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
+		}
 
 		mfi->mode = MTD_MODE_NORMAL;
 
@@ -670,7 +892,12 @@ static int mtd_ioctl(struct inode *inode
 	{
 		struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
 		if (!buf)
+		{
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -ENOMEM;
+		}
 		ret = -EOPNOTSUPP;
 		switch (mfi->mode) {
 		case MTD_MODE_OTP_FACTORY:
@@ -701,12 +928,24 @@ static int mtd_ioctl(struct inode *inode
 	{
 		struct otp_info info;
 
-		if (mfi->mode != MTD_MODE_OTP_USER)
+		if (mfi->mode != MTD_MODE_OTP_USER) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EINVAL;
-		if (copy_from_user(&info, argp, sizeof(info)))
+		}
+		if (copy_from_user(&info, argp, sizeof(info))) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EFAULT;
-		if (!mtd->lock_user_prot_reg)
+		}
+		if (!mtd->lock_user_prot_reg) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+			mtd_unlock();				// sl2312 share pin lock
+#endif
 			return -EOPNOTSUPP;
+		}
 		ret = mtd->lock_user_prot_reg(mtd, info.start, info.length);
 		break;
 	}
@@ -742,8 +981,12 @@ static int mtd_ioctl(struct inode *inode
 			break;
 
 		case MTD_MODE_RAW:
-			if (!mtd->read_oob || !mtd->write_oob)
+			if (!mtd->read_oob || !mtd->write_oob) {
+#ifdef CONFIG_SL2312_SHARE_PIN
+				mtd_unlock();				// sl2312 share pin lock
+#endif
 				return -EOPNOTSUPP;
+			}
 			mfi->mode = arg;
 
 		case MTD_MODE_NORMAL:
@@ -766,6 +1009,10 @@ static int mtd_ioctl(struct inode *inode
 		ret = -ENOTTY;
 	}
 
+#ifdef CONFIG_SL2312_SHARE_PIN
+	mtd_unlock();				// sl2312 share pin lock
+#endif
+
 	return ret;
 } /* memory_ioctl */
 
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -44,6 +44,13 @@ config MTD_NAND_AUTCPU12
 	  This enables the driver for the autronix autcpu12 board to
 	  access the SmartMediaCard.
 
+config MTD_NAND_SL2312
+	tristate "NAND Flash device on Storlink board"
+	depends on ARM && MTD_NAND && ARCH_SL2312
+	help
+	  This enables the driver for the Storlink board to
+	  access the nand device.
+
 config MTD_NAND_EDB7312
 	tristate "Support for Cirrus Logic EBD7312 evaluation board"
 	depends on ARCH_EDB7312
--- /dev/null
+++ b/drivers/mtd/nand/sl2312-flash-nand.c
@@ -0,0 +1,2287 @@
+/*
+ *  drivers/mtd/sl2312.c
+ *
+ * $Id: sl2312-flash-nand.c,v 1.5 2006/06/15 07:02:29 middle Exp $
+ *
+ * Copyright (C) 2001 Toshiba Corporation
+ *
+ * 2003 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/partitions.h>
+#include <linux/delay.h>
+#include <asm/io.h>
+#include <asm/hardware.h>
+#include <asm/arch/sl2312.h>
+#include "sl2312-flash-nand.h"
+
+
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/mtd/compatmac.h>
+#include <linux/interrupt.h>
+#include <linux/bitops.h>
+
+
+/*
+ * NAND low-level MTD interface functions
+ */
+static void sl2312_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len);
+static void sl2312_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len);
+static int sl2312_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len);
+
+static int sl2312_nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf);
+static int sl2312_nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel);
+static int sl2312_nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf);
+static int sl2312_nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf);
+static int sl2312_nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
+			   size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel);
+static int sl2312_nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char *buf);
+static int sl2312_nand_writev (struct mtd_info *mtd, const struct kvec *vecs,
+			unsigned long count, loff_t to, size_t * retlen);
+static int sl2312_nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs,
+			unsigned long count, loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
+static int sl2312_nand_erase (struct mtd_info *mtd, struct erase_info *instr, int allowbbt);
+static void sl2312_nand_sync (struct mtd_info *mtd);
+static int sl2312_nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf,  struct nand_oobinfo *oobsel);
+static int sl2312_nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt);
+static int sl2312_nand_erase_block(struct mtd_info *mtd, int page);
+
+/*
+ * MTD structure for sl2312 NDFMC
+ */
+static struct mtd_info *sl2312_mtd = NULL;
+static int nand_page=0,nand_col=0;
+
+/* Define default oob placement schemes for large and small page devices */
+static struct nand_oobinfo nand_oob_8 = {
+	.useecc = MTD_NANDECC_AUTOPLACE,
+	.eccbytes = 3,
+	.eccpos = {0, 1, 2},
+	.oobfree = { {3, 2}, {6, 2} }
+};
+
+static struct nand_oobinfo nand_oob_16 = {
+	.useecc = MTD_NANDECC_AUTOPLACE,
+	.eccbytes = 6,
+	.eccpos = {0, 1, 2, 3, 6, 7},
+	.oobfree = { {8, 8} }
+};
+
+static struct nand_oobinfo nand_oob_64 = {
+	.useecc = MTD_NANDECC_AUTOPLACE,
+	.eccbytes = 24,
+	.eccpos = {
+		40, 41, 42, 43, 44, 45, 46, 47,
+		48, 49, 50, 51, 52, 53, 54, 55,
+		56, 57, 58, 59, 60, 61, 62, 63},
+	.oobfree = { {2, 38} }
+};
+
+
+/*
+ * Define partitions for flash device
+ */
+/* the base address of FLASH control register */
+#define FLASH_CONTROL_BASE_ADDR	    (IO_ADDRESS(SL2312_FLASH_CTRL_BASE))
+#define SL2312_GLOBAL_BASE_ADDR     (IO_ADDRESS(SL2312_GLOBAL_BASE))
+//#define SL2312_FLASH_BASE_ADDR      (IO_ADDRESS(SL2312_FLASH_BASE))
+#define SL2312_FLASH_BASE_ADDR       FLASH_VADDR(SL2312_FLASH_BASE)
+static unsigned int CHIP_EN;
+/* define read/write register utility */
+//#define FLASH_READ_REG(offset)			(__raw_readl(offset+FLASH_CONTROL_BASE_ADDR))
+//#define FLASH_WRITE_REG(offset,val) 	(__raw_writel(val,offset+FLASH_CONTROL_BASE_ADDR))
+//#define FLASH_READ_DATA(offset)			(__raw_readb(offset+SL2312_FLASH_BASE_ADDR))
+//#define FLASH_WRITE_DATA(offset,val) 	(__raw_writeb(val,offset+SL2312_FLASH_BASE_ADDR))
+
+unsigned int FLASH_READ_REG(unsigned int addr)
+{
+    unsigned int *base;
+    unsigned int data;
+
+    base = (unsigned int *)(FLASH_CONTROL_BASE_ADDR + addr);
+    data = *base;
+    return (data);
+}
+
+void FLASH_WRITE_REG(unsigned int addr,unsigned int data)
+{
+    unsigned int *base;
+
+    base = (unsigned int *)(FLASH_CONTROL_BASE_ADDR + addr);
+    *base = data;
+    return;
+}
+
+unsigned int FLASH_READ_DATA(unsigned int addr)
+{
+    unsigned char *base;
+    unsigned int data;
+
+    base = (unsigned char *)(SL2312_FLASH_BASE_ADDR + addr);
+    data = *base;
+    return (data);
+}
+
+void FLASH_WRITE_DATA(unsigned int addr,unsigned int data)
+{
+    unsigned char *base;
+
+    base = (unsigned char *)(SL2312_FLASH_BASE_ADDR + addr);
+    *base = data;
+    return;
+}
+
+/* the offset of FLASH control register */
+enum NFLASH_REGISTER {
+	NFLASH_ID     			= 0x0000,
+	NFLASH_STATUS 			= 0x0008,
+	NFLASH_TYPE   			= 0x000c,
+	NFLASH_ACCESS			= 0x0030,
+	NFLASH_COUNT			= 0x0034,
+	NFLASH_CMD_ADDR 		= 0x0038,
+	NFLASH_ADDRESS			= 0x003C,
+	NFLASH_DATA				= 0x0040,
+	NFLASH_TIMING   		= 0x004C,
+	NFLASH_ECC_STATUS		= 0x0050,
+	NFLASH_ECC_CONTROL		= 0x0054,
+	NFLASH_ECC_OOB			= 0x005c,
+	NFLASH_ECC_CODE_GEN0	= 0x0060,
+	NFLASH_ECC_CODE_GEN1	= 0x0064,
+	NFLASH_ECC_CODE_GEN2	= 0x0068,
+	NFLASH_ECC_CODE_GEN3	= 0x006C,
+	NFLASH_FIFO_CONTROL		= 0x0070,
+	NFLASH_FIFO_STATUS		= 0x0074,
+	NFLASH_FIFO_ADDRESS		= 0x0078,
+	NFLASH_FIFO_DATA		= 0x007c,
+};
+
+
+
+//#define FLASH_BASE	FLASH_CONTROL_BASE_ADDR
+//#define FLASH_SIZE	0x00800000 //INTEGRATOR_FLASH_SIZE
+
+//#define FLASH_PART_SIZE 8388608
+
+//static unsigned int flash_indirect_access = 0;
+
+
+#ifdef CONFIG_SL2312_SHARE_PIN
+void sl2312flash_enable_nand_flash(void)
+{
+    unsigned int    reg_val;
+
+    reg_val = readl(SL2312_GLOBAL_BASE_ADDR + 0x30);
+    reg_val = reg_val & 0xfffffffb;
+    writel(reg_val,SL2312_GLOBAL_BASE_ADDR + 0x30);
+    return;
+}
+
+void sl2312flash_disable_nand_flash(void)
+{
+    unsigned int    reg_val;
+
+    reg_val = readl(SL2312_GLOBAL_BASE_ADDR + 0x30);
+    reg_val = reg_val | 0x00000004;
+    writel(reg_val,SL2312_GLOBAL_BASE_ADDR + 0x30);
+    return;
+}
+#endif
+
+extern struct nand_oobinfo jffs2_oobinfo;
+/*
+ * Define partitions for flash devices
+ */
+
+static struct mtd_partition sl2312_partitions[] = {
+	{ name: "RedBoot", offset: 0x00000000, size: 0x0020000, },
+	{ name: "Kernel", offset: 0x00020000, size: 0x00200000, },
+	{ name: "Ramdisk", offset: 0x00220000, size: 0x00280000, },
+	{ name: "Application", offset: 0x004A0000, size: 0x00320000, },
+	{ name: "VCTL", offset: 0x007C0000, size: 0x20000, },
+	{ name: "CurConf", offset: 0x007E0000, size: 0x20000, },
+	{ name: "FIS directory", offset: 0x007e0000, size: 0x00020000, }
+
+};
+
+
+/*
+ *	hardware specific access to control-lines
+*/
+static void sl2312_hwcontrol(struct mtd_info *mtd, int cmd)
+{
+
+	return ;
+}
+
+static int sl2312_nand_scan_bbt(struct mtd_info *mtd)
+{
+	return 0;
+}
+
+/**
+ * nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
+ * @mtd:	MTD device structure
+ * @ofs:	offset relative to mtd start
+ */
+static int sl2312_nand_block_isbad (struct mtd_info *mtd, loff_t ofs)
+{
+	/* Check for invalid offset */
+	if (ofs > mtd->size)
+		return -EINVAL;
+
+	return sl2312_nand_block_checkbad (mtd, ofs, 1, 0);
+}
+
+/**
+ * nand_block_checkbad - [GENERIC] Check if a block is marked bad
+ * @mtd:	MTD device structure
+ * @ofs:	offset from device start
+ * @getchip:	0, if the chip is already selected
+ * @allowbbt:	1, if its allowed to access the bbt area
+ *
+ * Check, if the block is bad. Either by reading the bad block table or
+ * calling of the scan function.
+ */
+
+static int sl2312_nand_erase_block(struct mtd_info *mtd, int page)
+{
+	int opcode;
+	/* Send commands to erase a page */
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+
+		if(mtd->oobblock > 528)
+		    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f0fff21);  // 3 address & 2 command
+		else
+		    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f0fff11);  // 2 address & 2 command
+
+		FLASH_WRITE_REG(NFLASH_CMD_ADDR, 0x0000d060); // write read id command
+		FLASH_WRITE_REG(NFLASH_ADDRESS, page); //write address 0x00
+
+
+
+		/* read maker code */
+		opcode = 0x80003000|DWIDTH|CHIP_EN; //set start bit & 8bits write command
+		FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+
+		while(opcode&0x80000000) //polling flash access 31b
+      	{
+           opcode=FLASH_READ_REG(NFLASH_ACCESS);
+           //sl2312_flash_delay();
+           schedule();
+           //cond_resched();
+      	}
+}
+
+void sl2312_flash_delay(void)
+{
+      int i;
+
+      for(i=0; i<50; i++)
+           i=i;
+}
+
+static int sl2312_nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt)
+{
+	struct nand_chip *this = mtd->priv;
+
+	if (!this->bbt)
+		return this->block_bad(mtd, ofs, getchip);
+
+	/* Return info from the table */
+	return nand_isbad_bbt (mtd, ofs, allowbbt);
+}
+
+/**
+ * nand_block_markbad - [MTD Interface] Mark the block at the given offset as bad
+ * @mtd:	MTD device structure
+ * @ofs:	offset relative to mtd start
+ */
+static int sl2312_nand_block_markbad (struct mtd_info *mtd, loff_t ofs)
+{
+	struct nand_chip *this = mtd->priv;
+	int ret;
+
+        if ((ret = sl2312_nand_block_isbad(mtd, ofs))) {
+        	/* If it was bad already, return success and do nothing. */
+		if (ret > 0)
+			return 0;
+        	return ret;
+        }
+
+	return this->block_markbad(mtd, ofs);
+}
+
+/*
+ *	Get chip for selected access
+ */
+static inline void sl2312_nand_get_chip (struct nand_chip *this, struct mtd_info *mtd, int new_state, int *erase_state)
+{
+
+	DECLARE_WAITQUEUE (wait, current);
+
+	/*
+	 * Grab the lock and see if the device is available
+	 * For erasing, we keep the spinlock until the
+	 * erase command is written.
+	*/
+retry:
+	spin_lock_bh (&this->chip_lock);
+
+	if (this->state == FL_READY) {
+		this->state = new_state;
+		if (new_state != FL_ERASING)
+			spin_unlock_bh (&this->chip_lock);
+		return;
+	}
+
+	if (this->state == FL_ERASING) {
+		if (new_state != FL_ERASING) {
+			this->state = new_state;
+			spin_unlock_bh (&this->chip_lock);
+			this->select_chip(mtd, 0);	/* select in any case */
+			this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+			return;
+		}
+	}
+
+	set_current_state (TASK_UNINTERRUPTIBLE);
+	add_wait_queue (&this->wq, &wait);
+	spin_unlock_bh (&this->chip_lock);
+	schedule ();
+	remove_wait_queue (&this->wq, &wait);
+	goto retry;
+}
+
+/*
+*	read device ready pin
+*/
+static int sl2312_device_ready(struct mtd_info *mtd)
+{
+	int ready;
+
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+	FLASH_WRITE_REG(NFLASH_COUNT, 0x7f000070); //set only command no address and two data
+
+	FLASH_WRITE_REG(NFLASH_CMD_ADDR, 0x00000070); //write read status command
+
+
+	ready = 0x80002000|DWIDTH|CHIP_EN; //set start bit & 8bits read command
+	FLASH_WRITE_REG(NFLASH_ACCESS, ready);
+
+	while(ready&0x80000000) //polling flash access 31b
+    {
+        ready=FLASH_READ_REG(NFLASH_ACCESS);
+        //sl2312_flash_delay();
+		schedule();
+    }
+    FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+      	ready=FLASH_READ_REG(NFLASH_DATA)&0xff;
+	return ready;
+}
+void sl2312_enable_hwecc(struct mtd_info *mtd, int mode)
+{
+	/* reset first */
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x80000001); //set 31b = 0
+
+}
+
+
+void sl2312_device_setup(void)
+{
+
+}
+static u_char sl2312_nand_read_byte(struct mtd_info *mtd)
+{
+
+        unsigned int    data=0, page=0, col=0, tmp, i;
+
+        printk ("**************************sl2312_nand_read_byte !! \n");
+        //page = FLASH_READ_REG(NFLASH_ADDRESS)&0xffffff00;
+        //col  = FLASH_READ_REG(NFLASH_ADDRESS)&0x000000ff;
+        page = nand_page;
+        col  = nand_col;
+        for(i=0;i<(mtd->oobblock+mtd->oobsize);i++)
+        {
+        	if(i==col)
+				data = FLASH_READ_DATA(page*mtd->oobblock +i);
+			else
+				tmp = FLASH_READ_DATA(page*mtd->oobblock +i);
+        }
+        return data&0xff;
+}
+
+static void sl2312_nand_write_byte(struct mtd_info *mtd, u_char byte)
+{
+        //struct nand_chip *this = mtd->priv;
+        unsigned int    page=0, col=0, i;
+        u_char *databuf,oobbuf[mtd->oobsize];
+        size_t  retlen;
+        retlen=0;
+		printk ("********************sl2312_nand_write_byte !! \n");
+		page = nand_page;
+        col  = nand_col;
+		databuf = kmalloc (mtd->oobsize+mtd->oobblock,GFP_KERNEL);
+
+		if (!databuf) {
+			printk ("sl2312_nand_write_byte : Unable to allocate SL2312 NAND MTD device structure.\n");
+
+		}
+
+		 for(i=0;i<(mtd->oobblock+mtd->oobsize);i++)
+           	databuf[i] = FLASH_READ_DATA(page*mtd->oobblock +i);
+
+        databuf[col] = byte;
+        sl2312_nand_write_ecc (mtd, page, mtd->oobblock, &retlen, databuf, oobbuf, NULL);
+
+}
+
+static void sl2312_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
+{
+	int i, page=0,col=0;
+	struct nand_chip *this = mtd->priv;
+	u_char *databuf, *oobbuf;
+        size_t  retlen;
+        retlen=0;
+
+
+		printk ("***********************sl2312_nand_write_buf !! \n");
+		databuf = &(this->data_buf[0]);
+		oobbuf = &(this->data_buf[mtd->oobblock]);
+		for (i = 0; i < mtd->oobsize; i++)
+			oobbuf[i] = 0xff;
+
+	if(len < mtd->oobblock)
+	{
+		//addr = FLASH_READ_REG(NFLASH_ADDRESS);
+		//page = FLASH_READ_REG(NFLASH_ADDRESS)&0xffffff00;
+		//col  = FLASH_READ_REG(NFLASH_ADDRESS)&0x000000ff;
+		page = nand_page;
+        col  = nand_col;
+
+		sl2312_nand_read_ecc (mtd, page, mtd->oobblock , &retlen, databuf, oobbuf, NULL);
+
+        for(i=col;i<len;i++)
+        	databuf[col+i] = buf[i];
+
+        sl2312_nand_write_ecc (mtd, page, mtd->oobblock, &retlen, databuf, oobbuf, NULL);
+
+	}
+
+}
+
+static void sl2312_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
+{
+	int i, page=0,col=0,addr=0,tmp=0;
+	//struct nand_chip *this = mtd->priv;
+	printk ("********************sl2312_nand_read_buf !! \n");
+	if(len < mtd->oobblock)
+	{
+		//addr = FLASH_READ_REG(NFLASH_ADDRESS);
+		//page = FLASH_READ_REG(NFLASH_ADDRESS)&0xffffff00;
+		//col  = FLASH_READ_REG(NFLASH_ADDRESS)&0x000000ff;
+		page = nand_page;
+        col  = nand_col;
+		for (i=col; i<((mtd->oobblock+mtd->oobsize)-col); i++)
+		{
+			if(i<len)
+				buf[i] = FLASH_READ_DATA(addr+i);
+			else
+				tmp = FLASH_READ_DATA(addr+i);
+		}
+	}
+}
+
+static int sl2312_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
+{
+	int i;
+	//struct nand_chip *this = mtd->priv;
+	u_char *datatmp, *oobtmp;
+	size_t  retlen;
+	retlen=0;
+
+	datatmp = kmalloc (mtd->oobblock,GFP_KERNEL);
+	oobtmp = kmalloc (mtd->oobsize,GFP_KERNEL);
+
+	if ((!datatmp)||(!oobtmp)) {
+		printk ("sl2312_nand_verify_buf : Unable to allocate SL2312 NAND MTD device structure.\n");
+
+	}
+	//page = nand_page;
+	for(i=0;i<mtd->oobblock;i++)
+		datatmp[i] = FLASH_READ_DATA(nand_page*mtd->oobblock +i);
+	/* read oobdata */
+	for (i = 0; i <  mtd->oobsize; i++)
+		oobtmp[i] = FLASH_READ_DATA(nand_page*mtd->oobblock + mtd->oobblock + i);
+
+	if(len==mtd->oobblock)
+	{
+		for (i=0; i<len; i++)
+		{
+			if (buf[i] != datatmp[i])
+			{
+				kfree(datatmp);
+				kfree(oobtmp);
+				printk("Data verify error -> page: %x, byte: %x \n",nand_page,i);
+				return i;
+			}
+		}
+	}
+	else if(len == mtd->oobsize)
+	{
+		for (i=0; i<len; i++)
+		{
+			if (buf[i] != oobtmp[i])
+			{
+				kfree(datatmp);
+				kfree(oobtmp);
+				printk("OOB verify error -> page: %x, byte: %x \n",nand_page,i);
+				return i;
+			}
+		}
+	}
+	else
+	{
+		printk (KERN_WARNING "sl2312_nand_verify_buf : verify length not match 0x%08x\n", len);
+		kfree(datatmp);
+		kfree(oobtmp);
+		return -1;
+	}
+
+	kfree(datatmp);
+	kfree(oobtmp);
+	return 0;
+}
+
+/*
+ * Send command to NAND device
+ */
+static void sl2312_nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
+{
+	register struct nand_chip *this = mtd->priv;
+	int opcode;
+
+
+	/*
+	 * program and erase have their own busy handlers
+	 * status and sequential in needs no delay
+	*/
+	switch (command) {
+
+	case NAND_CMD_PAGEPROG:
+	case NAND_CMD_ERASE1:
+	case NAND_CMD_ERASE2:
+	case NAND_CMD_SEQIN:
+	case NAND_CMD_STATUS:
+	case NAND_CMD_READ0:
+
+		/*
+		 * Write out the command to the device.
+		 */
+		if (column != -1 || page_addr != -1) {
+
+			/* Serially input address */
+			if (column != -1)
+				//FLASH_WRITE_REG(NFLASH_ADDRESS,column);
+				nand_col=column;
+
+			opcode = FLASH_READ_REG(NFLASH_ADDRESS);
+
+			if (page_addr != -1)
+				//FLASH_WRITE_REG(NFLASH_ADDRESS,opcode|(page_addr<<8));
+				nand_page = page_addr;
+
+		}
+		return;
+
+	case NAND_CMD_RESET:
+		if (this->dev_ready)
+			break;
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+		FLASH_WRITE_REG(NFLASH_COUNT, 0x7f0fff70); //set only command and no other data
+		FLASH_WRITE_REG(NFLASH_CMD_ADDR, NAND_CMD_RESET); //write reset command
+
+		opcode = 0x80002000|DWIDTH|CHIP_EN; //set start bit & 8bits read command
+		FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+
+		while(opcode&0x80000000) //polling flash access 31b
+      	{
+           opcode=FLASH_READ_REG(NFLASH_ACCESS);
+           //sl2312_flash_delay();
+           schedule();
+      	}
+		while ( !(sl2312_device_ready(mtd) & 0x40));
+		{
+			FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+			//sl2312_flash_delay();
+			schedule();
+			return;
+		}
+	/* This applies to read commands */
+	default:
+		/*
+		 * If we don't have access to the busy pin, we apply the given
+		 * command delay
+		*/
+		if (!this->dev_ready) {
+			udelay (this->chip_delay);
+			FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+			return;
+		}
+	}
+
+	/* wait until command is processed */
+	while (!this->dev_ready(mtd));
+
+}
+/*Add function*/
+static void nand_read_id(int chip_no, unsigned char *id)
+{
+	unsigned int opcode, i;
+
+	if(chip_no==0)
+		CHIP_EN = NFLASH_CHIP0_EN;
+	else
+		CHIP_EN = NFLASH_CHIP1_EN;
+
+	opcode = FLASH_READ_REG(NFLASH_TYPE);
+
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+	if((opcode&0x00000300)<=0x00000100)
+	    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f000100); //set only command & address and two data
+	else
+	    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f000300); //set only command & address and 4 data
+
+	FLASH_WRITE_REG(NFLASH_CMD_ADDR, 0x00000090); //write read id command
+	FLASH_WRITE_REG(NFLASH_ADDRESS, 0x00000000); //write address 0x00
+
+	/* read maker code */
+	opcode = 0x80002000|DWIDTH|CHIP_EN;//|chip0_en; //set start bit & 8bits read command
+	FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+	opcode=FLASH_READ_REG(NFLASH_ACCESS);
+		while(opcode&0x80000000) //polling flash access 31b
+      	{
+           opcode=FLASH_READ_REG(NFLASH_ACCESS);
+           //sl2312_flash_delay();
+           schedule();
+      	}
+
+    opcode = FLASH_READ_REG(NFLASH_DATA);
+    if(DWIDTH==NFLASH_WiDTH16)
+    {
+      		id[0] = opcode&0xff;
+      		id[1] = (opcode&0xff00)>>8;
+    }
+    else
+    {
+    	    id[0] = opcode&0xff;
+    	    opcode = 0x80002000|DWIDTH|CHIP_EN;//|chip0_en; //set start bit & 8bits read command
+			FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+			opcode=FLASH_READ_REG(NFLASH_ACCESS);
+			while(opcode&0x80000000) //polling flash access 31b
+    	  	{
+    	       opcode=FLASH_READ_REG(NFLASH_ACCESS);
+    	       //sl2312_flash_delay();
+    	       schedule();
+    	  	}
+    		opcode = FLASH_READ_REG(NFLASH_DATA);
+      		id[1] = (opcode&0xff00)>>8;
+
+      		opcode=FLASH_READ_REG(NFLASH_TYPE);
+      		if((opcode&0x300)>0x100)
+      		{
+      		    for(i=0;i<2;i++)
+      		    {
+      				//data cycle 3 & 4 ->not use
+      				opcode = 0x80002000|DWIDTH|CHIP_EN;//set start bit & 8bits read command
+					FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+					opcode=FLASH_READ_REG(NFLASH_ACCESS);
+      				while(opcode&0x80000000) //polling flash access 31b
+      				{
+        			   opcode=FLASH_READ_REG(NFLASH_ACCESS);
+        			   //sl2312_flash_delay();
+        			   schedule();
+      				}
+
+      				opcode=FLASH_READ_REG(NFLASH_DATA);
+      				id[2+i] = (opcode&(0xff0000<<i*8))>>(8*(2+i));
+      		    }
+      		}
+    }
+    FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+}
+
+/*
+ * NAND erase a block
+ */
+static int sl2312_nand_erase (struct mtd_info *mtd, struct erase_info *instr, int allowbbt)
+{
+	int page, len, status, pages_per_block, ret, chipnr;
+	struct nand_chip *this = mtd->priv;
+
+	DEBUG (MTD_DEBUG_LEVEL3,
+	       "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
+
+	/* Start address must align on block boundary */
+	if (instr->addr & ((1 << this->phys_erase_shift) - 1)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n");
+		return -EINVAL;
+	}
+
+	/* Length must align on block boundary */
+	if (instr->len & ((1 << this->phys_erase_shift) - 1)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n");
+		return -EINVAL;
+	}
+
+	/* Do not allow erase past end of device */
+	if ((instr->len + instr->addr) > mtd->size) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n");
+		return -EINVAL;
+	}
+
+	instr->fail_addr = 0xffffffff;
+
+	/* Grab the lock and see if the device is available */
+	sl2312_nand_get_chip (this, mtd, FL_ERASING, NULL);
+
+	/* Shift to get first page */
+	page = (int) (instr->addr >> this->page_shift);
+	chipnr = (int) (instr->addr >> this->chip_shift);
+
+	/* Calculate pages in each block */
+	pages_per_block = 1 << (this->phys_erase_shift - this->page_shift);
+
+	/* Select the NAND device */
+	//this->select_chip(mtd, chipnr);
+	this->select_chip(mtd, 0);
+
+	/* Check the WP bit */
+	/* Check, if it is write protected */
+	status = sl2312_device_ready(mtd);
+	if (!(status & 0x80)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n");
+		instr->state = MTD_ERASE_FAILED;
+		goto erase_exit;
+	}
+
+	/* Loop through the pages */
+	len = instr->len;
+
+	instr->state = MTD_ERASING;
+
+	while (len) {
+		/* Check if we have a bad block, we do not erase bad blocks ! */
+		if (this->block_bad(mtd, ((loff_t) page) << this->page_shift, 0)) {
+			printk (KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page);
+			//instr->state = MTD_ERASE_FAILED;
+			//goto erase_exit;
+		}
+
+		/* Invalidate the page cache, if we erase the block which contains
+		   the current cached page */
+		if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block))
+			this->pagebuf = -1;
+		/////////
+
+		///* Send commands to erase a page */
+		//FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+	    //
+		//if(mtd->oobblock > 528)
+		//    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f0fff21);  // 3 address & 2 command
+		//else
+		//    FLASH_WRITE_REG(NFLASH_COUNT, 0x7f0fff11);  // 2 address & 2 command
+		//
+		//FLASH_WRITE_REG(NFLASH_CMD_ADDR, 0x0000d060); // write read id command
+		//FLASH_WRITE_REG(NFLASH_ADDRESS, page); //write address 0x00
+		//
+		//
+		//
+		///* read maker code */
+		//opcode = 0x80003000|DWIDTH|CHIP_EN; //set start bit & 8bits write command
+		//FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+		//
+		//while(opcode&0x80000000) //polling flash access 31b
+      	//{
+        //   opcode=FLASH_READ_REG(NFLASH_ACCESS);
+        //   //sl2312_flash_delay();
+        //   schedule();
+        //   //cond_resched();
+      	//}
+      	sl2312_nand_erase_block(mtd, page);
+      	//////////////
+		status = this->waitfunc (mtd, this, FL_ERASING);
+		/* See if block erase succeeded */
+		if (status & 0x01) {
+			DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page);
+			instr->state = MTD_ERASE_FAILED;
+			instr->fail_addr = (page << this->page_shift);
+			goto erase_exit;
+		}
+
+		/* Increment page address and decrement length */
+		len -= (1 << this->phys_erase_shift);
+		page += pages_per_block;
+
+		/* Check, if we cross a chip boundary */
+		if (len && !(page & this->pagemask)) {
+			chipnr++;
+			this->select_chip(mtd, 0);
+			this->select_chip(mtd, 0);
+		}
+		//sl2312_flash_delay();
+           schedule();
+           //cond_resched();
+	}
+	instr->state = MTD_ERASE_DONE;
+
+erase_exit:
+	/* De-select the NAND device */
+	this->select_chip(mtd, 0);
+	spin_unlock_bh (&this->chip_lock);
+
+	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;;
+	/* Do call back function */
+	if (!ret && instr->callback)
+		instr->callback (instr);
+
+	/* The device is ready */
+	spin_lock_bh (&this->chip_lock);
+	this->state = FL_READY;
+	spin_unlock_bh (&this->chip_lock);
+	FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+	/* Return more or less happy */
+	return ret;
+}
+
+static void sl2312_nand_select_chip(struct mtd_info *mtd, int chip)
+{
+	//struct nand_chip *this = mtd->priv;
+
+	switch(chip) {
+	case -1:
+		CHIP_EN = NFLASH_CHIP0_EN;
+		break;
+	case 0:
+		CHIP_EN = NFLASH_CHIP0_EN;
+		break;
+	case 1:
+		CHIP_EN = NFLASH_CHIP1_EN;
+		break;
+	default:
+			CHIP_EN = NFLASH_CHIP0_EN;
+			break;
+	}
+}
+
+/**
+ * nand_default_block_markbad - [DEFAULT] mark a block bad
+ * @mtd:	MTD device structure
+ * @ofs:	offset from device start
+ *
+ * This is the default implementation, which can be overridden by
+ * a hardware specific driver.
+*/
+static int sl2312_nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
+{
+	struct nand_chip *this = mtd->priv;
+	u_char buf[2] = {0, 0};
+	size_t	retlen;
+	int block;
+
+	/* Get block number */
+	block = ((int) ofs) >> this->bbt_erase_shift;
+	this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
+
+	/* Do we have a flash based bad block table ? */
+	if (this->options & NAND_USE_FLASH_BBT)
+		return nand_update_bbt (mtd, ofs);
+
+	/* We write two bytes, so we dont have to mess with 16 bit access */
+	ofs += mtd->oobsize + (this->badblockpos & ~0x01);
+	return sl2312_nand_write_oob (mtd, ofs , 2, &retlen, buf);
+}
+
+/* Appropriate chip should already be selected */
+static int sl2312_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)//(struct mtd_info *mtd, unsigned long page, )
+{
+	u_char *buf, *oobbuf;
+	size_t  retlen;
+	unsigned long page, chipnr;
+	struct nand_chip *this = mtd->priv;
+
+	if (getchip) {
+		page = (int)(ofs >> this->page_shift);
+		chipnr = (int)(ofs >> this->chip_shift);
+
+		/* Grab the lock and see if the device is available */
+		sl2312_nand_get_chip (this, mtd, FL_READING, NULL);
+		/* Select the NAND device */
+		this->select_chip(mtd, chipnr);
+	} else
+		page = (int) ofs;
+
+	buf = kmalloc (mtd->oobblock,GFP_KERNEL);
+	oobbuf = kmalloc (mtd->oobsize,GFP_KERNEL);
+
+	if ((!buf)||(!oobbuf)) {
+		printk ("sl2312_nand_block_bad : Unable to allocate SL2312 NAND MTD device structure.\n");
+
+	}
+
+	sl2312_nand_read_ecc (mtd, page, mtd->oobblock , &retlen, buf, oobbuf, NULL);
+
+
+	if(((mtd->oobblock < 528)&&(oobbuf[5] != 0xff))||((mtd->oobblock > 528)&&(oobbuf[0] != 0xff)))
+	{
+		kfree(buf);
+		kfree(oobbuf);
+		return 1;
+	}
+
+	kfree(buf);
+	kfree(oobbuf);
+	return 0;
+}
+
+/*
+*	Use NAND read ECC
+*/
+static int sl2312_nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf)
+{
+	return sl2312_nand_read_ecc (mtd, from, len, retlen, buf, NULL, NULL);
+}
+
+/*
+ * NAND read with ECC
+ */
+static int sl2312_nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
+			  size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel)
+{
+	int j, col, page, opcode, i;
+	int end=0;//, ecc=0;//, end_page=0;
+	int erase_state = 0;
+	int read = 0, oob = 0, ecc_failed = 0;//, ecc_status = 0
+	struct nand_chip *this = mtd->priv;
+	u_char *data_poi, *oob_data = oob_buf;
+	//u_char ecc_calc[6];
+	//u_char ecc_code[6];
+	int 	eccmode;
+	int	*oob_config;
+
+
+
+	// use chip default if zero
+	if (oobsel == NULL)
+		oobsel = &mtd->oobinfo;
+
+	eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE;
+	oob_config = oobsel->eccpos;
+
+	DEBUG (MTD_DEBUG_LEVEL3, "nand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
+
+	/* Do not allow reads past end of device */
+	if ((from + len) > mtd->size) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: Attempt read beyond end of device\n");
+		*retlen = 0;
+		return -EINVAL;
+	}
+
+	/* Grab the lock and see if the device is available */
+	sl2312_nand_get_chip (this, mtd ,FL_READING, &erase_state);
+
+	/* Select the NAND device */
+	this->select_chip(mtd, 0);
+
+	/* First we calculate the starting page */
+	page = from >> this->page_shift;
+
+	//end_page = mtd->oobblock + mtd->oobsize;
+	end = mtd->oobblock;
+	//ecc = mtd->eccsize;
+	/* Get raw starting column */
+	col = (from & (mtd->oobblock - 1));
+
+
+	/* Send the read command */
+	//this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page);
+
+	/* Loop until all data read */
+	FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+	while (read < len) {
+
+		//udelay(1200);
+		/* If we have consequent page reads, apply delay or wait for ready/busy pin */
+		if (read) {
+			if (!this->dev_ready)
+				udelay (this->chip_delay);
+			else
+				while (!this->dev_ready(mtd));
+		}
+
+		/*
+		 * If the read is not page aligned, we have to read into data buffer
+		 * due to ecc, else we read into return buffer direct
+		 */
+		if (!col && (len - read) >= end)
+			data_poi = &buf[read];
+		else
+			data_poi = this->data_buf;
+
+		/* get oob area, if we have no oob buffer from fs-driver */
+		if (!oob_buf) {
+			oob_data = &this->data_buf[end];
+			oob = 0;
+		}
+
+		j = 0;
+		switch (eccmode) {
+			case NAND_ECC_NONE: {	/* No ECC, Read in a page */
+				FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+				break;
+			}
+
+			case NAND_ECC_SOFT:	/* Software ECC 3/256: Read in a page + oob data */
+				break;
+
+			case NAND_ECC_HW3_256: /* Hardware ECC 3 byte /256 byte data: Read in first 256 byte, get ecc, */
+				break;
+
+			case NAND_ECC_HW3_512:
+			case NAND_ECC_HW6_512: /* Hardware ECC 3/6 byte / 512 byte data : Read in a page  */
+				FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x80000001); //set 31b = 0
+				break;
+
+			default:
+				printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode);
+				FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0);
+				//BUG();
+		}//end switch
+
+			for(i=0;i<end;i++)
+			{
+				//udelay(7);
+				data_poi[i] = FLASH_READ_DATA(page*mtd->oobblock +i);
+			}
+			/* read oobdata */
+			for (i = 0; i <  mtd->oobsize; i++)
+			{
+				//udelay(7);
+				oob_data[oob + i] = FLASH_READ_DATA(page*mtd->oobblock +end+i);
+			}
+
+		/* Skip ECC, if not active */
+			if (eccmode == NAND_ECC_NONE)
+				goto readdata;
+
+			// compare ecc and correct data
+
+				opcode=FLASH_READ_REG(NFLASH_ECC_STATUS);
+				while(!(opcode&0x80000000)) //polling flash access 31b
+      			{
+        			   opcode=FLASH_READ_REG(NFLASH_ECC_STATUS);
+        			   //sl2312_flash_delay();
+        			   schedule();
+      			}
+      			for(j=0;j<(end/512);j++)
+      			{//for 2k page
+
+					opcode = 0x00000000|oob_data[mtd->oobsize-3-4*j]<<16|oob_data[mtd->oobsize-2-4*j]<<8|oob_data[mtd->oobsize-1-4*j];
+
+					//opcode=FLASH_READ_REG(NFLASH_ECC_CODE_GEN0+(j*4));
+
+					FLASH_WRITE_REG(NFLASH_ECC_OOB, opcode);
+					opcode = 0x00000000|(j<<8); //select ECC code generation 0
+					FLASH_WRITE_REG(NFLASH_ECC_CONTROL, opcode); //???
+
+					opcode=FLASH_READ_REG(NFLASH_ECC_STATUS);
+					if((opcode&0x00000003)==0x03)
+					{
+						printk (KERN_WARNING "\nPageRead Uncorrectable error !!\n");
+						ecc_failed++;
+					}
+					else if((opcode&0x00000003)==0x01)
+					{
+						printk (KERN_WARNING "\nPageRead One bit data error !!");
+						// correct data
+						if((data_poi[(opcode&0xff80)>>7]>>((opcode&0x38)>>3))%1)
+							data_poi[(opcode&0xff80)>>7] &= ~(1<<((opcode&0x38)>>3));
+						else
+							data_poi[(opcode&0xff80)>>7] |= (1<<((opcode&0x38)>>3));
+
+					}
+					else if((opcode&0x00000003)==0x02)
+					{
+						printk (KERN_WARNING "\nPageRead One bit ECC error !!\n");
+					}
+					else if((opcode&0x00000003)==0x00)
+					{
+
+					}
+
+				}//for 2k page
+readdata:
+		if (col || (len - read) < end) {
+			for (j = col; j < end && read < len; j++)
+				buf[read++] = data_poi[j];
+		} else
+			read += mtd->oobblock;
+		/* For subsequent reads align to page boundary. */
+		col = 0;
+		/* Increment page address */
+		page++;
+		schedule();
+	}
+	/* De-select the NAND device */
+	//this->select_chip(mtd, -1);
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+	FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_INDIRECT);
+	/* Wake up anyone waiting on the device */
+	spin_lock_bh (&this->chip_lock);
+	this->state = FL_READY;
+	wake_up (&this->wq);
+	spin_unlock_bh (&this->chip_lock);
+
+	/*
+	 * Return success, if no ECC failures, else -EIO
+	 * fs driver will take care of that, because
+	 * retlen == desired len and result == -EIO
+	 */
+	*retlen = read;
+	return ecc_failed ? -EIO : 0;
+}
+
+/*
+ * Wait for command done. This applies to erase and program only
+ * Erase can take up to 400ms and program up to 20ms according to
+ * general NAND and SmartMedia specs
+ *
+*/
+static int sl2312_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this, int state)
+{
+	unsigned long	timeo = jiffies;
+	int	status, opcode;
+
+	if (state == FL_ERASING)
+		 timeo += (HZ * 400) / 1000;
+	else
+		 timeo += (HZ * 20) / 1000;
+
+	spin_lock_bh (&this->chip_lock);
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000); //set 31b = 0
+	FLASH_WRITE_REG(NFLASH_COUNT, 0x007f000070); //set only command no address and two data
+
+	FLASH_WRITE_REG(NFLASH_CMD_ADDR, 0x00000070); //write read status command
+
+
+	opcode = 0x80002000|DWIDTH|CHIP_EN; //set start bit & 8bits read command
+	FLASH_WRITE_REG(NFLASH_ACCESS, opcode);
+
+	while(opcode&0x80000000) //polling flash access 31b
+    {
+        opcode=FLASH_READ_REG(NFLASH_ACCESS);
+        //sl2312_flash_delay();
+        schedule();
+    }
+
+	while (time_before(jiffies, timeo)) {
+		/* Check, if we were interrupted */
+		if (this->state != state) {
+			spin_unlock_bh (&this->chip_lock);
+			FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+			return 0;
+		}
+		if (this->dev_ready) {
+			if (this->dev_ready(mtd))
+				break;
+		}
+		if (FLASH_READ_REG(NFLASH_DATA) & 0x40)
+			break;
+
+		spin_unlock_bh (&this->chip_lock);
+		yield ();
+		spin_lock_bh (&this->chip_lock);
+	}
+	status = FLASH_READ_REG(NFLASH_DATA)&0xff;
+	spin_unlock_bh (&this->chip_lock);
+	FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+	return status;
+}
+
+static int sl2312_nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf)
+{
+	int i, col, page, j=0;
+	//int erase_state = 0;
+	struct nand_chip *this = mtd->priv;
+	u_char *databuf, *oobbuf;
+
+	databuf = &this->data_buf[0];
+	oobbuf = &this->data_buf[mtd->oobblock];
+		for (i = 0; i < mtd->oobsize; i++)
+			oobbuf[i] = 0xff;
+
+	DEBUG (MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
+
+	/* Shift to get page */
+	page = ((int) from) >> this->page_shift;
+
+	/* Mask to get column */
+	col = from & (mtd->oobsize-1);  //0x0f;
+
+	/* Initialize return length value */
+	*retlen = 0;
+	sl2312_nand_read_ecc (mtd, page, mtd->oobblock , retlen, databuf, oobbuf, NULL);
+	for(i=col,j=0;i<mtd->oobsize||i<(col+len);i++,j++)
+		buf[j] = oobbuf[i];
+
+	*retlen = j ;
+	return 0;
+}
+
+#define NOTALIGNED(x) (x & (mtd->oobblock-1)) != 0
+/*
+*	Use NAND write ECC
+*/
+static int sl2312_nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf)
+{
+	return (sl2312_nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL));
+}
+
+/*
+ * NAND write with ECC
+ */
+static int sl2312_nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
+			   size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel)
+{
+	int page, ret = 0, oob = 0, written = 0;
+	struct nand_chip *this = mtd->priv;
+
+	DEBUG (MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
+
+
+	/* Do not allow write past end of device */
+	if ((to + len) > mtd->size) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: Attempt to write past end of page\n");
+		return -EINVAL;
+	}
+
+	/* reject writes, which are not page aligned */
+	if (NOTALIGNED (to) || NOTALIGNED(len)) {
+		printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
+		return -EINVAL;
+	}
+
+	// if oobsel is NULL, use chip defaults
+	if (oobsel == NULL)
+		oobsel = &mtd->oobinfo;
+
+	/* Shift to get page */
+	page = ((int) to) >> this->page_shift;
+
+	/* Grab the lock and see if the device is available */
+	sl2312_nand_get_chip (this, mtd, FL_WRITING, NULL);
+
+	/* Select the NAND device */
+	this->select_chip(mtd, 0);
+
+	/* Check the WP bit */
+	if (!(sl2312_device_ready(mtd) & 0x80)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: Device is write protected!!!\n");
+		ret = -EIO;
+		goto out;
+	}
+
+	/* Loop until all data is written */
+	while (written < len) {
+		//udelay(100);
+		int cnt = mtd->oobblock;
+		this->data_poi = (u_char*) &buf[written];
+		/* We use the same function for write and writev */
+		if (eccbuf) {
+			ret = sl2312_nand_write_page (mtd, this, page, &eccbuf[oob], oobsel);
+			oob += mtd->oobsize;
+		} else
+			ret = sl2312_nand_write_page (mtd, this, page, NULL, oobsel);
+
+		if (ret)
+			goto out;
+
+		/* Update written bytes count */
+		written += cnt;
+		/* Increment page address */
+		page++;
+	}
+
+out:
+	/* De-select the NAND device */
+	//this->select_chip(mtd, -1);
+
+	/* Wake up anyone waiting on the device */
+	spin_lock_bh (&this->chip_lock);
+	this->state = FL_READY;
+	wake_up (&this->wq);
+	spin_unlock_bh (&this->chip_lock);
+
+	*retlen = written;
+	return ret;
+}
+
+/*
+ *	Nand_page_program function is used for write and writev !
+ *	This function will always program a full page of data
+ *	If you call it with a non page aligned buffer, you're lost :)
+ */
+static int sl2312_nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf,  struct nand_oobinfo *oobsel)
+{
+	int 	i, j, status, opcode;
+	u_char	ecc_code[16], *oob_data;
+	int	eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE;
+	//int  	*oob_config = oobsel->eccpos;
+
+	/* pad oob area, if we have no oob buffer from fs-driver */
+	if (!oob_buf) {
+		oob_data = &this->data_buf[mtd->oobblock];
+		for (i = 0; i < mtd->oobsize; i++)
+			oob_data[i] = 0xff;
+	} else
+		oob_data = oob_buf;
+
+	/* Send command to begin auto page programming */
+
+	memset(oob_data,0xff,mtd->oobsize);
+	/* Write out complete page of data, take care of eccmode */
+	switch (eccmode) {
+	/* No ecc and software ecc 3/256, write all */
+	case NAND_ECC_NONE:
+		printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+		break;
+	case NAND_ECC_SOFT:
+		break;
+
+	/* Hardware ecc 3 byte / 256 data, write first half, get ecc, then second, if 512 byte pagesize */
+	case NAND_ECC_HW3_256:
+		break;
+
+	/* Hardware ecc 3 byte / 512 byte data, write full page */
+	case NAND_ECC_HW3_512:
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x80000001); //set 31b = 0
+
+	/* Hardware ecc 6 byte / 512 byte data, write full page */
+	case NAND_ECC_HW6_512:
+		break;
+
+	default:
+		printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode);
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+		//BUG();
+	}
+
+	FLASH_WRITE_REG(NFLASH_ACCESS, NFLASH_DIRECT);
+
+	for(i=0;i<mtd->oobblock;i++)
+	{
+		//udelay(5);
+		FLASH_WRITE_DATA((page*mtd->oobblock)+i,this->data_poi[i]);
+	}
+	///////////////
+	if(eccmode!=NAND_ECC_NONE)
+	{
+		opcode=FLASH_READ_REG(NFLASH_ECC_STATUS);
+		while(!(opcode&0x80000000)) //polling flash access 31b
+    	{
+    	 	   opcode=FLASH_READ_REG(NFLASH_ECC_STATUS);
+    	 	   //sl2312_flash_delay();
+    	 	   schedule();
+    	}
+
+
+    	for(i=0;i<(mtd->oobblock/512);i++)
+    	{
+    		opcode=FLASH_READ_REG(NFLASH_ECC_CODE_GEN0+(i*4));
+
+    		for(j=3;j>0;j--)
+    		      oob_data[(mtd->oobsize-j-(i*4))] = (opcode<<((4-j)*8)) >>24;
+
+    		for(j=0;j<4;j++)
+    		{
+    			ecc_code[15-i*4] = opcode;
+    			ecc_code[15-i*4-1] = opcode>>8;
+    			ecc_code[15-i*4-2] = opcode>>16;
+    		}
+    	}
+
+    	//disable ecc
+    	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x00000000);
+
+    	/* Write out OOB data */
+    	for(i=0;i<mtd->oobsize;i++)
+    	{
+    		//udelay(5);
+			FLASH_WRITE_DATA((page*mtd->oobblock)+mtd->oobblock+i,oob_data[i]);
+		}
+    }
+    else
+    {
+    	for(i=0;i<mtd->oobsize;i++)
+    	{
+    		//udelay(5);
+			FLASH_WRITE_DATA((page*mtd->oobblock)+mtd->oobblock+i,0xff);
+		}
+    }
+
+
+	/* call wait ready function */
+	status = this->waitfunc (mtd, this, FL_WRITING);
+	FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+	/* See if device thinks it succeeded */
+	if (status & 0x01) {
+		DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page);
+		FLASH_WRITE_REG(NFLASH_ECC_CONTROL, 0x0); //set 31b = 0
+		return -EIO;
+	}
+
+#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
+	/*
+	 * The NAND device assumes that it is always writing to
+	 * a cleanly erased page. Hence, it performs its internal
+	 * write verification only on bits that transitioned from
+	 * 1 to 0. The device does NOT verify the whole page on a
+	 * byte by byte basis. It is possible that the page was
+	 * not completely erased or the page is becoming unusable
+	 * due to wear. The read with ECC would catch the error
+	 * later when the ECC page check fails, but we would rather
+	 * catch it early in the page write stage. Better to write
+	 * no data than invalid data.
+	 */
+
+	/* Send command to read back the page */
+	this->cmdfunc (mtd, NAND_CMD_READ0, 0, page);
+	/* Loop through and verify the data */
+	if (this->verify_buf(mtd, this->data_poi, mtd->oobblock)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
+		return -EIO;
+	}
+
+	/* check, if we have a fs-supplied oob-buffer */
+	if (oob_buf) {
+		if (this->verify_buf(mtd, oob_data, mtd->oobsize)) {
+			DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
+			return -EIO;
+		}
+	} else {
+		if (eccmode != NAND_ECC_NONE) {
+			int ecc_bytes = 0;
+
+			switch (this->eccmode) {
+			case NAND_ECC_SOFT:
+			case NAND_ECC_HW3_256: ecc_bytes = (mtd->oobblock == 512) ? 6 : 3; break;
+			case NAND_ECC_HW3_512: ecc_bytes = 3; break;
+			case NAND_ECC_HW6_512: ecc_bytes = 6; break;
+			}
+
+
+
+			for(i=0;i < (mtd->oobblock+mtd->oobsize);i++)
+			{
+				if(i>=mtd->oobblock)
+					oob_data[i-mtd->oobblock] = FLASH_READ_DATA((page*mtd->oobblock) +i);
+				else
+					oob_data[0] = FLASH_READ_DATA((page*mtd->oobblock) +i);
+			}
+
+			if(this->eccmode == NAND_ECC_HW3_512)
+			{
+				for(i=0;i<(mtd->oobblock/512);i++)
+    			{
+    				for(j=0;j<3;j++)
+    				{
+    				    if (oob_data[mtd->oobsize-1-j-4*i] != ecc_code[15-j-4*i]) {
+							DEBUG (MTD_DEBUG_LEVEL0,
+							       "%s: Failed ECC write "
+						       "verify, page 0x%08x, " "%6i bytes were succesful\n", __FUNCTION__, page, i);
+							return -EIO;
+						}
+    				}
+    			}
+			}
+		}//eccmode != NAND_ECC_NONE
+	}
+	/*
+	 * Terminate the read command. This is faster than sending a reset command or
+	 * applying a 20us delay before issuing the next programm sequence.
+	 * This is not a problem for all chips, but I have found a bunch of them.
+	 */
+	//this->select_chip(mtd, -1);
+	//this->select_chip(mtd, 0);
+#endif
+
+	return 0;
+}
+
+/*
+ * NAND write with iovec
+ */
+static int sl2312_nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
+		loff_t to, size_t * retlen)
+{
+	return (sl2312_nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, 0));
+}
+
+static int sl2312_nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
+		loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel)
+{
+	int i, page, len, total_len, ret = 0, written = 0;
+	struct nand_chip *this = mtd->priv;
+
+	/* Calculate total length of data */
+	total_len = 0;
+	for (i = 0; i < count; i++)
+		total_len += (int) vecs[i].iov_len;
+
+	DEBUG (MTD_DEBUG_LEVEL3,
+	       "nand_writev: to = 0x%08x, len = %i, count = %ld\n", (unsigned int) to, (unsigned int) total_len, count);
+
+	/* Do not allow write past end of page */
+	if ((to + total_len) > mtd->size) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_writev: Attempted write past end of device\n");
+		return -EINVAL;
+	}
+
+	/* reject writes, which are not page aligned */
+	if (NOTALIGNED (to) || NOTALIGNED(total_len)) {
+		printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
+		return -EINVAL;
+	}
+
+	// if oobsel is NULL, use chip defaults
+	if (oobsel == NULL)
+		oobsel = &mtd->oobinfo;
+
+	/* Shift to get page */
+	page = ((int) to) >> this->page_shift;
+
+	/* Grab the lock and see if the device is available */
+	sl2312_nand_get_chip (this, mtd, FL_WRITING, NULL);
+
+	/* Select the NAND device */
+	this->select_chip(mtd, 0);
+
+	/* Check the WP bit */
+	if (!(sl2312_device_ready(mtd) & 0x80)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "sl2312_nand_writev_ecc: Device is write protected!!!\n");
+		ret = -EIO;
+		goto out;
+	}
+
+	/* Loop until all iovecs' data has been written */
+	len = 0;
+	while (count) {
+		/*
+		 *  Check, if the tuple gives us not enough data for a
+		 *  full page write. Then we can use the iov direct,
+		 *  else we have to copy into data_buf.
+		 */
+		if ((vecs->iov_len - len) >= mtd->oobblock) {
+			this->data_poi = (u_char *) vecs->iov_base;
+			this->data_poi += len;
+			len += mtd->oobblock;
+			/* Check, if we have to switch to the next tuple */
+			if (len >= (int) vecs->iov_len) {
+				vecs++;
+				len = 0;
+				count--;
+			}
+		} else {
+			/*
+			 * Read data out of each tuple until we have a full page
+			 * to write or we've read all the tuples.
+		 	*/
+			int cnt = 0;
+			while ((cnt < mtd->oobblock) && count) {
+				if (vecs->iov_base != NULL && vecs->iov_len) {
+					this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++];
+				}
+				/* Check, if we have to switch to the next tuple */
+				if (len >= (int) vecs->iov_len) {
+					vecs++;
+					len = 0;
+					count--;
+				}
+			}
+			this->data_poi = this->data_buf;
+		}
+
+		/* We use the same function for write and writev !) */
+		ret = sl2312_nand_write_page (mtd, this, page, NULL, oobsel);
+		if (ret)
+			goto out;
+
+		/* Update written bytes count */
+		written += mtd->oobblock;;
+
+		/* Increment page address */
+		page++;
+	}
+
+out:
+	/* De-select the NAND device */
+	//this->select_chip(mtd, -1);
+
+	/* Wake up anyone waiting on the device */
+	spin_lock_bh (&this->chip_lock);
+	this->state = FL_READY;
+	wake_up (&this->wq);
+	spin_unlock_bh (&this->chip_lock);
+
+	*retlen = written;
+	return ret;
+}
+
+/*
+static u_char ffchars[] = {
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+*/
+/*
+ * NAND write out-of-band
+ */
+static int sl2312_nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf)
+{
+	int column, page, status, ret = 0, j=0;
+	struct nand_chip *this = mtd->priv;
+	u_char *databuf, *oobbuf;
+
+
+		databuf = &this->data_buf[0];
+		oobbuf = &this->data_buf[mtd->oobblock];
+		for (j = 0; j < mtd->oobsize; j++)
+			oobbuf[j] = 0xff;
+//#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
+//	int 	i;
+//#endif
+
+	DEBUG (MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
+
+	/* Shift to get page */
+	page = ((int) to) >> this->page_shift;
+
+	/* Mask to get column */
+	column = to & 0x1f;
+
+	/* Initialize return length value */
+	*retlen = 0;
+
+	/* Do not allow write past end of page */
+	if ((column + len) > mtd->oobsize) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: Attempt to write past end of page\n");
+		return -EINVAL;
+	}
+
+	/* Grab the lock and see if the device is available */
+	sl2312_nand_get_chip (this, mtd, FL_WRITING, NULL);
+
+	/* Select the NAND device */
+	this->select_chip(mtd, 0);
+
+	/* Reset the chip. Some chips (like the Toshiba TC5832DC found
+	   in one of my DiskOnChip 2000 test units) will clear the whole
+	   data page too if we don't do this. I have no clue why, but
+	   I seem to have 'fixed' it in the doc2000 driver in
+	   August 1999.  dwmw2. */
+	this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
+	/* Check the WP bit */
+	if (!(sl2312_device_ready(mtd) & 0x80)) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: Device is write protected!!!\n");
+		ret = -EIO;
+		goto out;
+	}
+	/* Write out desired data */
+	this->cmdfunc (mtd, NAND_CMD_SEQIN, mtd->oobblock, page);
+
+	sl2312_nand_read_ecc (mtd, page, mtd->oobblock , retlen, databuf, oobbuf, NULL);
+
+    for(j=column;j<(column+len);j++)
+    	oobbuf[j] = buf[j-column];
+    sl2312_nand_write_ecc (mtd, page, mtd->oobblock, retlen, databuf, oobbuf, NULL);
+
+	status = this->waitfunc (mtd, this, FL_WRITING);
+
+	/* See if device thinks it succeeded */
+	if (status & 0x01) {
+		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page);
+		ret = -EIO;
+		goto out;
+	}
+	/* Return happy */
+	*retlen = len;
+
+
+out:
+	/* De-select the NAND device */
+	//this->select_chip(mtd, -1);
+
+	/* Wake up anyone waiting on the device */
+	spin_lock_bh (&this->chip_lock);
+	this->state = FL_READY;
+	wake_up (&this->wq);
+	spin_unlock_bh (&this->chip_lock);
+
+	return ret;
+}
+
+/*
+ * NAND sync
+ */
+static void sl2312_nand_sync (struct mtd_info *mtd)
+{
+	struct nand_chip *this = mtd->priv;
+	DECLARE_WAITQUEUE (wait, current);
+
+	DEBUG (MTD_DEBUG_LEVEL3, "nand_sync: called\n");
+
+retry:
+	/* Grab the spinlock */
+	spin_lock_bh (&this->chip_lock);
+
+	/* See what's going on */
+	switch (this->state) {
+	case FL_READY:
+	case FL_SYNCING:
+		this->state = FL_SYNCING;
+		spin_unlock_bh (&this->chip_lock);
+		break;
+
+	default:
+		/* Not an idle state */
+		add_wait_queue (&this->wq, &wait);
+		spin_unlock_bh (&this->chip_lock);
+		schedule ();
+
+		remove_wait_queue (&this->wq, &wait);
+		goto retry;
+	}
+
+	/* Lock the device */
+	spin_lock_bh (&this->chip_lock);
+
+	/* Set the device to be ready again */
+	if (this->state == FL_SYNCING) {
+		this->state = FL_READY;
+		wake_up (&this->wq);
+	}
+
+	/* Unlock the device */
+	spin_unlock_bh (&this->chip_lock);
+}
+
+
+/*
+ * Scan for the NAND device
+ */
+int sl2312_nand_scan (struct mtd_info *mtd, int maxchips)
+{
+	int i, j, nand_maf_id, nand_dev_id, busw;
+	struct nand_chip *this = mtd->priv;
+	unsigned char id[4];
+
+	/* Get buswidth to select the correct functions*/
+	busw = this->options & NAND_BUSWIDTH_16;
+
+	/* check for proper chip_delay setup, set 20us if not */
+	if (!this->chip_delay)
+		this->chip_delay = 20;
+
+	/* check, if a user supplied command function given */
+	if (this->cmdfunc == NULL)
+		this->cmdfunc = sl2312_nand_command;
+
+	/* check, if a user supplied wait function given */
+	if (this->waitfunc == NULL)
+		this->waitfunc = sl2312_nand_waitfunc;
+
+	if (!this->select_chip)
+		this->select_chip = sl2312_nand_select_chip;
+	if (!this->write_byte)
+		this->write_byte = sl2312_nand_write_byte; //busw ? nand_write_byte16 : nand_write_byte;
+	if (!this->read_byte)
+		this->read_byte = sl2312_nand_read_byte; //busw ? nand_read_byte16 : nand_read_byte;
+//	if (!this->write_word)
+//		this->write_word = nand_write_word;
+//	if (!this->read_word)
+//		this->read_word = nand_read_word;
+//	if (!this->block_bad)
+		this->block_bad = sl2312_nand_block_bad; //nand_block_bad;
+	if (!this->block_markbad)
+		this->block_markbad = sl2312_nand_default_block_markbad;
+	if (!this->write_buf)
+		this->write_buf = sl2312_nand_write_buf; //busw ? nand_write_buf16 : nand_write_buf;
+	if (!this->read_buf)
+		this->read_buf = sl2312_nand_read_buf; //busw ? nand_read_buf16 : nand_read_buf;
+	if (!this->verify_buf)
+		this->verify_buf = sl2312_nand_verify_buf; //busw ? nand_verify_buf16 : nand_verify_buf;
+	if (!this->scan_bbt)
+		this->scan_bbt = sl2312_nand_scan_bbt;
+
+	/* Select the device */
+	this->select_chip(mtd, 0);
+
+	/* Read manufacturer and device IDs */
+	nand_read_id(0,id);
+
+	nand_maf_id = id[0];
+	nand_dev_id = id[1];
+
+	/* Print and store flash device information */
+	for (i = 0; nand_flash_ids[i].name != NULL; i++) {
+
+		if (nand_dev_id != nand_flash_ids[i].id)
+			continue;
+
+		if (!mtd->name) mtd->name = nand_flash_ids[i].name;
+		this->chipsize = nand_flash_ids[i].chipsize << 20;
+
+		/* New devices have all the information in additional id bytes */
+		if (!nand_flash_ids[i].pagesize) {
+			int extid;
+
+			/* The 4th id byte is the important one */
+			extid = id[3];
+			/* Calc pagesize */
+			mtd->oobblock = 1024 << (extid & 0x3);
+			extid >>= 2;
+			/* Calc oobsize */
+			mtd->oobsize = (8 << (extid & 0x03)) * (mtd->oobblock / 512);
+			extid >>= 2;
+			/* Calc blocksize. Blocksize is multiples of 64KiB */
+			mtd->erasesize = (64 * 1024)  << (extid & 0x03);
+			extid >>= 2;
+			/* Get buswidth information */
+			busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0;
+
+		} else {
+			/* Old devices have this data hardcoded in the
+			 * device id table */
+			mtd->erasesize = nand_flash_ids[i].erasesize;
+			mtd->oobblock = nand_flash_ids[i].pagesize;
+			mtd->oobsize = mtd->oobblock / 32;
+			busw = nand_flash_ids[i].options & NAND_BUSWIDTH_16;
+		}
+
+		/* Check, if buswidth is correct. Hardware drivers should set
+		 * this correct ! */
+		if (busw != (this->options & NAND_BUSWIDTH_16)) {
+			printk (KERN_INFO "NAND device: Manufacturer ID:"
+				" 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
+				nand_manuf_ids[i].name , mtd->name);
+			printk (KERN_WARNING
+				"NAND bus width %d instead %d bit\n",
+					(this->options & NAND_BUSWIDTH_16) ? 16 : 8,
+					busw ? 16 : 8);
+			this->select_chip(mtd, -1);
+			return 1;
+		}
+
+		/* Calculate the address shift from the page size */
+		this->page_shift = ffs(mtd->oobblock) - 1;
+		this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1;
+		this->chip_shift = ffs(this->chipsize) - 1;
+
+		/* Set the bad block position */
+		this->badblockpos = mtd->oobblock > 512 ?
+			NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
+
+		/* Get chip options, preserve non chip based options */
+		this->options &= ~NAND_CHIPOPTIONS_MSK;
+		this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK;
+		/* Set this as a default. Board drivers can override it, if neccecary */
+		this->options |= NAND_NO_AUTOINCR;
+		/* Check if this is a not a samsung device. Do not clear the options
+		 * for chips which are not having an extended id.
+		 */
+		if (nand_maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize)
+			this->options &= ~NAND_SAMSUNG_LP_OPTIONS;
+
+		/* Check for AND chips with 4 page planes */
+	//	if (this->options & NAND_4PAGE_ARRAY)
+	//		this->erase_cmd = multi_erase_cmd;
+	//	else
+	//		this->erase_cmd = single_erase_cmd;
+
+		/* Do not replace user supplied command function ! */
+	//	if (mtd->oobblock > 512 && this->cmdfunc == nand_command)
+	//		this->cmdfunc = nand_command_lp;
+
+		/* Try to identify manufacturer */
+		for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
+			if (nand_manuf_ids[j].id == nand_maf_id)
+				break;
+		}
+		printk (KERN_INFO "NAND device: Manufacturer ID:"
+			" 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
+			nand_manuf_ids[j].name , nand_flash_ids[i].name);
+		break;
+	}
+	/////////////////////////////
+
+	for (i=1; i < maxchips; i++) {
+		this->select_chip(mtd, i);
+
+		/* Send the command for reading device ID */
+		nand_read_id(1,id);
+
+		/* Read manufacturer and device IDs */
+		if (nand_maf_id != id[0] ||
+		    nand_dev_id != id[1])
+			break;
+	}
+	if (i > 1)
+		printk(KERN_INFO "%d NAND chips detected\n", i);
+
+	/* Allocate buffers, if neccecary */
+	if (!this->oob_buf) {
+		size_t len;
+		len = mtd->oobsize << (this->phys_erase_shift - this->page_shift);
+		this->oob_buf = kmalloc (len, GFP_KERNEL);
+		if (!this->oob_buf) {
+			printk (KERN_ERR "nand_scan(): Cannot allocate oob_buf\n");
+			return -ENOMEM;
+		}
+		this->options |= NAND_OOBBUF_ALLOC;
+	}
+
+	if (!this->data_buf) {
+		size_t len;
+		len = mtd->oobblock + mtd->oobsize;
+		this->data_buf = kmalloc (len, GFP_KERNEL);
+		if (!this->data_buf) {
+			if (this->options & NAND_OOBBUF_ALLOC)
+				kfree (this->oob_buf);
+			printk (KERN_ERR "nand_scan(): Cannot allocate data_buf\n");
+			return -ENOMEM;
+		}
+		this->options |= NAND_DATABUF_ALLOC;
+	}
+
+	/* Store the number of chips and calc total size for mtd */
+	this->numchips = i;
+	mtd->size = i * this->chipsize;
+	/* Convert chipsize to number of pages per chip -1. */
+	this->pagemask = (this->chipsize >> this->page_shift) - 1;
+	/* Preset the internal oob buffer */
+	memset(this->oob_buf, 0xff, mtd->oobsize << (this->phys_erase_shift - this->page_shift));
+
+	/* If no default placement scheme is given, select an
+	 * appropriate one */
+	if (!this->autooob) {
+		/* Select the appropriate default oob placement scheme for
+		 * placement agnostic filesystems */
+		switch (mtd->oobsize) {
+		case 8:
+			this->autooob = &nand_oob_8;
+			break;
+		case 16:
+			this->autooob = &nand_oob_16;
+			break;
+		case 64:
+			this->autooob = &nand_oob_64;
+			break;
+		default:
+			printk (KERN_WARNING "No oob scheme defined for oobsize %d\n",
+				mtd->oobsize);
+			BUG();
+		}
+	}
+
+	/* The number of bytes available for the filesystem to place fs dependend
+	 * oob data */
+	if (this->options & NAND_BUSWIDTH_16) {
+		mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 2);
+		if (this->autooob->eccbytes & 0x01)
+			mtd->oobavail--;
+	} else
+		mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 1);
+
+
+	/*
+	 * check ECC mode, default to software
+	 * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize
+	 * fallback to software ECC
+	*/
+	this->eccsize = 256;	/* set default eccsize */
+	this->eccbytes = 3;
+
+	switch (this->eccmode) {
+	case NAND_ECC_HW12_2048:
+		if (mtd->oobblock < 2048) {
+			printk(KERN_WARNING "2048 byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
+			       mtd->oobblock);
+			this->eccmode = NAND_ECC_SOFT;
+			this->calculate_ecc = nand_calculate_ecc;
+			this->correct_data = nand_correct_data;
+		} else
+			this->eccsize = 2048;
+		break;
+
+	case NAND_ECC_HW3_512:
+	case NAND_ECC_HW6_512:
+	case NAND_ECC_HW8_512:
+		if (mtd->oobblock == 256) {
+			printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n");
+			this->eccmode = NAND_ECC_SOFT;
+			this->calculate_ecc = nand_calculate_ecc;
+			this->correct_data = nand_correct_data;
+		} else
+			this->eccsize = 512; /* set eccsize to 512 */
+		break;
+
+	case NAND_ECC_HW3_256:
+		break;
+
+	case NAND_ECC_NONE:
+		printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n");
+		this->eccmode = NAND_ECC_NONE;
+		break;
+
+	case NAND_ECC_SOFT:
+		this->calculate_ecc = nand_calculate_ecc;
+		this->correct_data = nand_correct_data;
+		break;
+
+	default:
+		printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode);
+		BUG();
+	}
+
+	/* Check hardware ecc function availability and adjust number of ecc bytes per
+	 * calculation step
+	*/
+	switch (this->eccmode) {
+	case NAND_ECC_HW12_2048:
+		this->eccbytes += 4;
+	case NAND_ECC_HW8_512:
+		this->eccbytes += 2;
+	case NAND_ECC_HW6_512:
+		this->eccbytes += 3;
+//	case NAND_ECC_HW3_512:
+	case NAND_ECC_HW3_256:
+		if (this->calculate_ecc && this->correct_data && this->enable_hwecc)
+			break;
+		printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n");
+		BUG();
+	}
+
+	mtd->eccsize = this->eccsize;
+
+	/* Set the number of read / write steps for one page to ensure ECC generation */
+	switch (this->eccmode) {
+	case NAND_ECC_HW12_2048:
+		this->eccsteps = mtd->oobblock / 2048;
+		break;
+	case NAND_ECC_HW3_512:
+	case NAND_ECC_HW6_512:
+	case NAND_ECC_HW8_512:
+		this->eccsteps = mtd->oobblock / 512;
+		break;
+	case NAND_ECC_HW3_256:
+	case NAND_ECC_SOFT:
+		this->eccsteps = mtd->oobblock / 256;
+		break;
+
+	case NAND_ECC_NONE:
+		this->eccsteps = 1;
+		break;
+	}
+
+	/* Initialize state, waitqueue and spinlock */
+	this->state = FL_READY;
+	init_waitqueue_head (&this->wq);
+	spin_lock_init (&this->chip_lock);
+
+	/* De-select the device */
+	this->select_chip(mtd, 0);
+
+	/* Print warning message for no device */
+	if (!mtd->size) {
+		printk (KERN_WARNING "No NAND device found!!!\n");
+		return 1;
+	}
+
+	/* Fill in remaining MTD driver data */
+	mtd->type = MTD_NANDFLASH;
+	mtd->flags = MTD_CAP_NANDFLASH | MTD_ECC;
+	mtd->ecctype = MTD_ECC_SW;
+	mtd->erase = sl2312_nand_erase;
+	mtd->point = NULL;
+	mtd->unpoint = NULL;
+	mtd->read = sl2312_nand_read;
+	mtd->write = sl2312_nand_write;
+	mtd->read_ecc = sl2312_nand_read_ecc;
+	mtd->write_ecc = sl2312_nand_write_ecc;
+	mtd->read_oob = sl2312_nand_read_oob;
+	mtd->write_oob = sl2312_nand_write_oob;
+	mtd->readv = NULL;
+	mtd->writev = sl2312_nand_writev;
+	mtd->writev_ecc = sl2312_nand_writev_ecc;
+	mtd->sync = sl2312_nand_sync;
+	mtd->lock = NULL;
+	mtd->unlock = NULL;
+	mtd->suspend = NULL;
+	mtd->resume = NULL;
+	mtd->block_isbad = sl2312_nand_block_isbad;
+	mtd->block_markbad = sl2312_nand_block_markbad;
+
+	/* and make the autooob the default one */
+	memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
+
+	mtd->owner = THIS_MODULE;
+
+	/* Build bad block table */
+	return this->scan_bbt (mtd);
+}
+
+/*End Add function*/
+
+/*
+ * Main initialization routine
+ */
+extern int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
+
+int __init sl2312_mtd_init (void)
+{
+	struct nand_chip *this;
+	int err = 0;
+	struct mtd_partition *parts;
+	int nr_parts = 0;
+	int ret, data, *base;
+
+	printk("NAND MTD Driver Start Init ......\n");
+
+    	base = (unsigned int *)(IO_ADDRESS(SL2312_GLOBAL_BASE) + 0x30);
+    	data = *base;
+    	data&=0xffffffeb;
+    	data|=0x3; //disable p & s flash
+        *base = data;
+
+	/* Allocate memory for MTD device structure and private data */
+	sl2312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
+	if (!sl2312_mtd) {
+		printk ("Unable to allocate SL2312 NAND MTD device structure.\n");
+		err = -ENOMEM;
+		goto out;
+	}
+
+      //  sl2312_device_setup();
+
+	/* io is indirect via a register so don't need to ioremap address */
+
+	/* Get pointer to private data */
+	this = (struct nand_chip *) (&sl2312_mtd[1]);
+
+	/* Initialize structures */
+	memset((char *) sl2312_mtd, 0, sizeof(struct mtd_info));
+	memset((char *) this, 0, sizeof(struct nand_chip));
+
+	/* Link the private data with the MTD structure */
+	sl2312_mtd->priv = this;
+	sl2312_mtd->name = "sl2312-nand";
+
+	/* Set address of NAND IO lines */
+	this->IO_ADDR_R = (void __iomem *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE+NFLASH_DATA)); //(unsigned long)&(sl2312_ndfmcptr->dtr);
+	this->IO_ADDR_W = (void __iomem *)IO_ADDRESS((SL2312_FLASH_CTRL_BASE+NFLASH_DATA)); //(unsigned long)&(sl2312_ndfmcptr->dtr);
+	this->read_byte = sl2312_nand_read_byte;
+    this->write_byte = sl2312_nand_write_byte;
+    this->write_buf = sl2312_nand_write_buf;
+	this->read_buf = sl2312_nand_read_buf;
+	this->verify_buf = sl2312_nand_verify_buf;
+	this->select_chip = sl2312_nand_select_chip;
+	this->block_bad = sl2312_nand_block_bad;
+	this->hwcontrol = sl2312_hwcontrol;
+	this->dev_ready = sl2312_device_ready;
+	this->cmdfunc = sl2312_nand_command;
+	this->waitfunc = sl2312_nand_waitfunc;
+	//this->calculate_ecc = sl2312_readecc;
+	this->enable_hwecc = sl2312_enable_hwecc;
+	this->eccmode = NAND_ECC_HW3_512;
+	/*this->eccsize = 512;	*/
+	/* 20 us command delay time */
+	this->chip_delay = 20;
+
+	this->correct_data = nand_correct_data;
+//	this->scan_bbt = sl2312_nand_scan_bbt;
+
+	/* Allocate memory for internal data buffer */
+	this->data_buf = kmalloc (sizeof(u_char) * (sl2312_mtd->oobblock + sl2312_mtd->oobsize), GFP_KERNEL);
+	if (!this->data_buf) {
+		printk ("Unable to allocate NAND data buffer.\n");
+		err = -ENOMEM;
+		goto out_ior;
+	}
+
+	/* Scan to find existance of the device */
+	if (sl2312_nand_scan(sl2312_mtd, 1)) {
+		err = -ENXIO;
+		goto out_ior;
+	}
+
+	/* Register the partitions */
+	parts = sl2312_partitions;
+	nr_parts = sizeof(sl2312_partitions)/sizeof(*parts);
+
+	ret = add_mtd_partitions(sl2312_mtd, sl2312_partitions, nr_parts);
+	/*If we got an error, free all resources.*/
+	if (ret < 0) {
+		del_mtd_partitions(sl2312_mtd);
+		map_destroy(sl2312_mtd);
+	}
+	goto out;
+
+//out_buf:
+//	kfree (this->data_buf);
+out_ior:
+out:
+	printk("NAND MTD Driver Init Success ......\n");
+	return err;
+}
+
+module_init(sl2312_mtd_init);
+
+/*
+ * Clean up routine
+ */
+#ifdef MODULE
+static void __exit sl2312_cleanup (void)
+{
+	struct nand_chip *this = (struct nand_chip *) &sl2312_mtd[1];
+
+	/* Unregister partitions */
+	del_mtd_partitions(sl2312_mtd);
+
+	/* Unregister the device */
+	del_mtd_device (sl2312_mtd);
+
+	/* Free internal data buffers */
+	kfree (this->data_buf);
+
+	/* Free the MTD device structure */
+	kfree (sl2312_mtd);
+}
+module_exit(sl2312_cleanup);
+#endif
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
+MODULE_DESCRIPTION("Glue layer for SmartMediaCard on Toshiba RBsl2312");
--- /dev/null
+++ b/drivers/mtd/nand/sl2312-flash-nand.h
@@ -0,0 +1,24 @@
+#ifndef SL2312_FLASH_NAND_H
+#define SL2312_FLASH_NAND_H
+
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+
+/*Add function*/
+static void nand_read_id(int chip_no,unsigned char *id);
+
+
+
+#define	NFLASH_WiDTH8              0x00000000
+#define	NFLASH_WiDTH16             0x00000400
+#define	NFLASH_WiDTH32             0x00000800
+#define NFLASH_CHIP0_EN            0x00000000  // 16th bit = 0
+#define NFLASH_CHIP1_EN            0x00010000  // 16th bit = 1
+#define	NFLASH_DIRECT              0x00004000
+#define	NFLASH_INDIRECT            0x00000000
+
+
+#define	DWIDTH             NFLASH_WiDTH8
+
+
+#endif /* SL2312_FLASH_NAND_H */
--- /dev/null
+++ b/include/linux/mtd/kvctl.h
@@ -0,0 +1,40 @@
+#ifndef KVCTL_H
+#define KVCTL_H
+
+#define VCTL_HEAD_SIZE	8
+#define VCTL_ENTRY_LEN	20
+
+typedef struct
+{
+  char header[4];
+  unsigned int entry_num;
+} vctl_mheader;
+
+typedef struct
+{
+  char header[4];
+  unsigned int size;
+  unsigned int type;
+  char majorver[4];
+  char minorver[4];
+  unsigned char *payload;
+} vctl_entry;
+
+typedef struct
+{
+  unsigned char mac[6];
+  unsigned char vlanid;
+  unsigned char vlanmap;
+} vlaninfo;
+
+#define VCT_VENDORSPEC		0
+#define VCT_BOOTLOADER		1
+#define VCT_KERNEL		2
+#define VCT_VERCTL		3
+#define VCT_CURRCONF		4
+#define VCT_DEFAULTCONF		5
+#define VCT_ROOTFS		6
+#define VCT_APP			7
+#define VCT_VLAN		8
+
+#endif
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -71,3 +71,7 @@ obj-$(CONFIG_MTD_PLATRAM)	+= plat-ram.o
 obj-$(CONFIG_MTD_OMAP_NOR)	+= omap_nor.o
 obj-$(CONFIG_MTD_MTX1)		+= mtx-1_flash.o
 obj-$(CONFIG_MTD_TQM834x)	+= tqm834x.o
+###### for Storlink Soc #######
+obj-$(CONFIG_MTD_SL2312_CFI) += sl2312-flash-cfi.o
+obj-$(CONFIG_MTD_SL2312_SERIAL_ATMEL) += sl2312-flash-atmel.o
+obj-$(CONFIG_MTD_SL2312_SERIAL_ST) += sl2312-flash-m25p80.o