summaryrefslogtreecommitdiff
path: root/packages/linux/linux-titan-sh4-2.6.16/titan-flash.patch
blob: fc633f3e0533ee5ffa4f0dbde6970a796122bb42 (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

Add the driver for onboard flash.
The quality of this driver means that it has not been included in the
upstream CVS.
This implements the block device translation layer to match what the 
onboard firmware implements.

diff -duNr linux-2.6.16-orig/drivers/block/Kconfig linux-2.6.16/drivers/block/Kconfig
--- linux-2.6.16-orig/drivers/block/Kconfig	2006-06-29 16:12:57.000000000 +1000
+++ linux-2.6.16/drivers/block/Kconfig	2006-06-29 16:13:27.000000000 +1000
@@ -190,6 +190,13 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called DAC960.
 
+config BLK_SSFDC
+	tristate "SmartMedia(TM) Driver (sm)"
+	depends on SH_TITAN
+	help
+	Say Y here if you want the SmartMedia chip enabled.
+	  Otherwise say N.
+
 config BLK_DEV_UMEM
 	tristate "Micro Memory MM5415 Battery Backed RAM support (EXPERIMENTAL)"
 	depends on PCI && EXPERIMENTAL
diff -duNr linux-2.6.16-orig/drivers/block/Makefile linux-2.6.16/drivers/block/Makefile
--- linux-2.6.16-orig/drivers/block/Makefile	2006-06-29 16:12:57.000000000 +1000
+++ linux-2.6.16/drivers/block/Makefile	2006-06-29 16:13:27.000000000 +1000
@@ -21,6 +21,7 @@
 obj-$(CONFIG_BLK_CPQ_DA)	+= cpqarray.o
 obj-$(CONFIG_BLK_CPQ_CISS_DA)  += cciss.o
 obj-$(CONFIG_BLK_DEV_DAC960)	+= DAC960.o
+obj-$(CONFIG_BLK_SSFDC)		+= ssfdc.o
 obj-$(CONFIG_CDROM_PKTCDVD)	+= pktcdvd.o
 
 obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
diff -duNr linux-2.6.16-orig/drivers/block/ssfdc.c linux-2.6.16/drivers/block/ssfdc.c
--- linux-2.6.16-orig/drivers/block/ssfdc.c	1970-01-01 10:00:00.000000000 +1000
+++ linux-2.6.16/drivers/block/ssfdc.c	2006-06-29 16:13:50.000000000 +1000
@@ -0,0 +1,2742 @@
+/* $id:   $
+ssfdc.c - Solid State Flopyy Disk Card
+
+Original source curtesy of Toshiba Corporation.
+
+Modification for use by Linux provided by Nimble Microsystems Inc.
+
+TODO:
+
+Modification History:
+	
+	March 2001 - Initial port of Toshiba sources by Bill Mann
+	May 2001 - Debug of staticly linked ssfdc driver, Bill Mann
+	Nov 2001 	- Reimplementation using tasklets and timers.
+	May 2002 - Partition support added.
+	Oct 2003 - Port to kernel 2.6.0
+	Mar 2004 - Stabilization refinements...
+
+Overview:  The kernel interfaces to the device via the "block_device_operations 
+	ssfdc_fops", the device's request handling function 
+	"do_ssfdc_request(request_queue_t * q)", or by the ioctl interface ssfdc_ioctl().
+
+	do_ssfdc_request() purpose is to kickstart ssfdc_thread via a wake_up call.  ssfdc_thread
+	then processes requests from the queue.
+
+	Blocks are mapped logically.  So a sector read/write results in the determination
+	of the logical block address of the block containing the desired sector and the
+	corresponding physical block being accessed.  Note the use of ReadBlock, WriteBlock,
+	and PhyBlock, Log2Phy[] etc.
+
+	This driver implements a wear leveling strategy where sector writes to the
+	SmartMedia causes the block which is the target of the write to be copied into a
+	new block, the new data written and the old block erased.  This makes the driver 
+	more complicated than a straightforward sector read/write.
+
+*/
+
+/* Section device headers */
+#define DEBUG_SSFDC					0
+#define DEBUG_SSFDC_STRUCT			0
+#define DEBUG_SSFDC_REQUEST			0
+#define DEBUG_SSFDC_READREDT		0
+#define DEBUG_SSFDC_WRITE			0
+#define DEBUG_SSFDC_WRITESECT		0
+#define DEBUG_SSFDC_WRITEBLKS		0
+#define DEBUG_SSFDC_READ			0
+#define DEBUG_SSFDC_ADDR			0
+#define DEBUG_SSFDC_ASSIGNRELEASE	0
+#define SSFDC_READINGTASKLET		0
+/* Edition Compilation Mode */
+
+#include <linux/module.h>
+
+#include <asm/delay.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+
+#include <linux/fs.h>
+#include <linux/hdreg.h>
+#include <linux/file.h>
+#include <linux/stat.h>
+#include <linux/time.h>
+#include <linux/errno.h>
+#include <linux/major.h>
+#include <linux/init.h>
+#include <linux/devfs_fs_kernel.h>
+#include <asm/uaccess.h>
+#include <asm/hardirq.h>
+#include <linux/bio.h>
+#include <linux/blkdev.h>
+#include <linux/slab.h>
+#include <linux/highmem.h>
+
+#include "ssfdc.h"
+
+#define SSFDC_MAJOR	240
+
+static int static_ssfdc_debug = 0;
+
+static DECLARE_WAIT_QUEUE_HEAD(ssfdc_wait);
+
+static struct gendisk *disks[MAX_SSFDC];
+static ssfdc_dev *ssfdc[MAX_SSFDC];
+
+static int ssfdc_open(struct inode *i_node, struct file *fptr);
+static int ssfdc_getgeo(struct block_device *bdev, struct hd_geometry *geo);
+static int ssfdc_release(struct inode *i_node, struct file *fptr);
+static int ssfdc_ioctl(struct inode *i_node, struct file *fptr, unsigned cmd, unsigned long arg);
+static int ssfdc_revalidate(struct gendisk *disk);
+void do_ssfdc_request(request_queue_t * q);
+
+static struct block_device_operations ssfdc_fops = {
+	.owner			= THIS_MODULE,
+	.open			= ssfdc_open,
+	.getgeo			= ssfdc_getgeo,
+	.release		= ssfdc_release,
+	.ioctl			= ssfdc_ioctl,
+	// bjm out .revalidate_disk	= ssfdc_revalidate,
+};
+
+
+/***************************************************************************
+	BIT Control Macro
+ ***************************************************************************/
+static char BitData[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 };
+#define	SetBit(a,b)	(a[(unsigned char)((b)/8)]|= BitData[(b)%8])
+#define	ClrBit(a,b)	(a[(unsigned char)((b)/8)]&=~BitData[(b)%8])
+#define	ChkBit(a,b)	(a[(unsigned char)((b)/8)] & BitData[(b)%8])
+
+/***************************************************************************/
+static int MediaReadSector(ssfdc_dev *, struct request *, char *, long,int);
+static int MediaWriteSector(ssfdc_dev *, struct request *, char *, long,int);
+
+/***************************************************************************/
+static int  CheckLogCHS(ssfdc_dev *,unsigned int *,unsigned char *,unsigned char *);
+static int  CheckMediaWP(ssfdc_dev *);
+static int  ConvMediaAddr(ssfdc_dev *,long);
+static int  IncMediaAddr(ssfdc_dev *);
+static int  WriteReqInCurrBlk(ssfdc_dev *, long, int *);
+/******************************************/
+/******************************************/
+static int  AssignWriteBlock(ssfdc_dev *, int);
+/******************************************/
+/******************************************/
+static int  SetPhyFmtValue(ssfdc_dev *);
+static int  SearchCIS(ssfdc_dev *,unsigned int *);
+static int  MakeLogTable(ssfdc_dev *,unsigned int);
+/******************************************/
+static int  MarkFailPhyOneBlock(ssfdc_dev *);
+
+static void _ReadSsfdcBuf(ssfdc_dev *, unsigned char *databuf,unsigned char *redundant); 
+static void _WriteSsfdcBuf(ssfdc_dev *,unsigned char *,unsigned char *);
+static void _ReadSsfdcWord(ssfdc_dev *,unsigned int *);
+static void _ReadRedtSsfdcBuf(ssfdc_dev *, unsigned char *redundant);
+static void _WriteRedtSsfdcBuf(ssfdc_dev*, unsigned char *redundant);
+
+/***************************************************************************/
+static void _SetSsfdcCmd(ssfdc_dev *, unsigned char);
+static void _SetSsfdcAddr(ssfdc_dev *, unsigned char);
+static void _SetSsfdcBlock(ssfdc_dev *);
+static void _SetSsfdcChip(ssfdc_dev *);
+static void _SetSsfdcStandby(ssfdc_dev *);
+static int  _CheckSsfdcBusy(ssfdc_dev *, unsigned int);
+static int  _CheckSsfdcStatus(ssfdc_dev *);
+static void _ResetSsfdcErr(ssfdc_dev *psm);
+static unsigned char _CheckDevCode(unsigned char);
+void SsfdcReset(ssfdc_dev *);
+void CntReset(ssfdc_dev *);
+
+static char BitCount(unsigned char);
+static char BitCountWord(unsigned int);
+
+static void _WaitTimer(long int);
+typedef void (*timeout_fn)(unsigned long);
+static void ssfdc_rw_request(ssfdc_dev *psm, struct request *req);
+static int ssfdc_end_request(ssfdc_dev *psm, struct request *req, int status);
+static void ssfdc_terminate_request(ssfdc_dev *psm, struct request *req);
+static struct request *ssfdc_get_request(ssfdc_dev *psm);
+
+/* debugging utils etc. */
+
+#if DEBUG_SSFDC
+static void dump_ssfdc_state(ssfdc_dev * psm);
+#endif
+
+/* end of debugging utils etc. */
+
+/* our tasklets */
+/* top level R/W initiation tasklet */
+static void initxfer(unsigned long);
+#if 0	// use thread and not a tasklet
+DECLARE_TASKLET(initxfer_tasklet0, initxfer, 0);
+#ifdef CONFIG_SH_NIMBLE_MINI
+DECLARE_TASKLET(initxfer_tasklet1, initxfer, 1);
+#endif
+#endif
+
+/* Sector Write Tasklets,  This group includes a readcopy tasklet for block copies...*/
+
+/* Tasklet to read a sector into a temporary buffer for later write */
+
+/* power is turned on, and then left on for TIMER_ON_TIMEOUT */
+// bjm debug struct timer_list mediachange_timer;
+// bjm debug static void mediachangetest(unsigned long);
+
+// bjm out
+// bjm out struct timer_list waiting_timer;
+static void waiting_timeout(unsigned long);
+
+/******************************************************************************/
+static void trans_result        \
+    (unsigned char,unsigned char,unsigned char *,unsigned char *);
+static void calculate_ecc           \
+    (unsigned char *,unsigned char *,unsigned char *,unsigned char *,unsigned char *);
+static unsigned char correct_data   \
+    (unsigned char *,unsigned char *,unsigned char,unsigned char,unsigned char);
+
+                                              /* CP0-CP5 code table           */
+static unsigned char ecctable[256] = {
+    0x00,0x55,0x56,0x03,0x59,0x0C,0x0F,0x5A,0x5A,0x0F,0x0C,0x59,0x03,0x56,0x55,0x00,
+    0x65,0x30,0x33,0x66,0x3C,0x69,0x6A,0x3F,0x3F,0x6A,0x69,0x3C,0x66,0x33,0x30,0x65,
+    0x66,0x33,0x30,0x65,0x3F,0x6A,0x69,0x3C,0x3C,0x69,0x6A,0x3F,0x65,0x30,0x33,0x66,
+    0x03,0x56,0x55,0x00,0x5A,0x0F,0x0C,0x59,0x59,0x0C,0x0F,0x5A,0x00,0x55,0x56,0x03,
+    0x69,0x3C,0x3F,0x6A,0x30,0x65,0x66,0x33,0x33,0x66,0x65,0x30,0x6A,0x3F,0x3C,0x69,
+    0x0C,0x59,0x5A,0x0F,0x55,0x00,0x03,0x56,0x56,0x03,0x00,0x55,0x0F,0x5A,0x59,0x0C,
+    0x0F,0x5A,0x59,0x0C,0x56,0x03,0x00,0x55,0x55,0x00,0x03,0x56,0x0C,0x59,0x5A,0x0F,
+    0x6A,0x3F,0x3C,0x69,0x33,0x66,0x65,0x30,0x30,0x65,0x66,0x33,0x69,0x3C,0x3F,0x6A,
+    0x6A,0x3F,0x3C,0x69,0x33,0x66,0x65,0x30,0x30,0x65,0x66,0x33,0x69,0x3C,0x3F,0x6A,
+    0x0F,0x5A,0x59,0x0C,0x56,0x03,0x00,0x55,0x55,0x00,0x03,0x56,0x0C,0x59,0x5A,0x0F,
+    0x0C,0x59,0x5A,0x0F,0x55,0x00,0x03,0x56,0x56,0x03,0x00,0x55,0x0F,0x5A,0x59,0x0C,
+    0x69,0x3C,0x3F,0x6A,0x30,0x65,0x66,0x33,0x33,0x66,0x65,0x30,0x6A,0x3F,0x3C,0x69,
+    0x03,0x56,0x55,0x00,0x5A,0x0F,0x0C,0x59,0x59,0x0C,0x0F,0x5A,0x00,0x55,0x56,0x03,
+    0x66,0x33,0x30,0x65,0x3F,0x6A,0x69,0x3C,0x3C,0x69,0x6A,0x3F,0x65,0x30,0x33,0x66,
+    0x65,0x30,0x33,0x66,0x3C,0x69,0x6A,0x3F,0x3F,0x6A,0x69,0x3C,0x66,0x33,0x30,0x65,
+    0x00,0x55,0x56,0x03,0x59,0x0C,0x0F,0x5A,0x5A,0x0F,0x0C,0x59,0x03,0x56,0x55,0x00
+};
+
+#define    BIT7    0x80
+#define    BIT6    0x40
+#define    BIT5    0x20
+#define    BIT4    0x10
+#define    BIT3    0x08
+#define    BIT2    0x04
+#define    BIT1    0x02
+#define    BIT0    0x01
+ 
+#define    BIT1BIT0    0x03
+#define    BIT23       0x00800000L
+#define    MASK_CPS    0x3f
+#define    CORRECTABLE 0x00555554L 
+
+/*
+    Transfer result
+    LP14,12,10,... & LP15,13,11,... -> LP15,14,13,... & LP7,6,5,..
+*/
+static void trans_result(reg2,reg3,ecc1,ecc2)
+unsigned char reg2;                           /* LP14,LP12,LP10,...           */
+unsigned char reg3;                           /* LP15,LP13,LP11,...           */
+unsigned char *ecc1;                          /* LP15,LP14,LP13,...           */
+unsigned char *ecc2;                          /* LP07,LP06,LP05,...           */
+{
+    unsigned char a;                          /* Working for reg2,reg3        */
+    unsigned char b;                          /* Working for ecc1,ecc2        */
+    unsigned char i;                          /* For counting                 */
+ 
+    a=BIT7; b=BIT7;                           /* 80h=10000000b                */
+    *ecc1=*ecc2=0;                            /* Clear ecc1,ecc2              */
+    for(i=0; i<4; ++i) {
+        if ((reg3&a)!=0) *ecc1|=b;            /* LP15,13,11,9 -> ecc1         */
+        b=b>>1;                               /* Right shift                  */
+        if ((reg2&a)!=0) *ecc1|=b;            /* LP14,12,10,8 -> ecc1         */
+        b=b>>1;                               /* Right shift                  */
+        a=a>>1;                               /* Right shift                  */
+    }
+    b=BIT7;                                   /* 80h=10000000b                */
+    for(i=0; i<4; ++i) {
+        if ((reg3&a)!=0) *ecc2|=b;            /* LP7,5,3,1 -> ecc2            */
+        b=b>>1;                               /* Right shift                  */
+        if ((reg2&a)!=0) *ecc2|=b;            /* LP6,4,2,0 -> ecc2            */
+        b=b>>1;                               /* Right shift                  */
+        a=a>>1;                               /* Right shift                  */
+    }
+}
+
+
+/*
+    Calculating ECC
+    data[0-255] -> ecc1,ecc2,ecc3 using CP0-CP5 code table[0-255]
+*/
+static void calculate_ecc(table,data,ecc1,ecc2,ecc3)
+unsigned char *table;                         /* CP0-CP5 code table           */
+unsigned char *data;                          /* DATA                         */
+unsigned char *ecc1;                          /* LP15,LP14,LP13,...           */
+unsigned char *ecc2;                          /* LP07,LP06,LP05,...           */
+unsigned char *ecc3;                          /* CP5,CP4,CP3,...,"1","1"      */
+{
+    unsigned int i;                           /* For counting                 */
+    unsigned char a;                          /* Working for table            */
+    unsigned char reg1;                       /* D-all,CP5,CP4,CP3,...        */
+    unsigned char reg2;                       /* LP14,LP12,L10,...            */
+    unsigned char reg3;                       /* LP15,LP13,L11,...            */
+ 
+    reg1=reg2=reg3=0;                         /* Clear parameter              */
+ 
+    for(i=0; i<256; ++i) {
+        a=table[data[i]];                     /* Get CP0-CP5 code from table  */
+        reg1^=(a&MASK_CPS);                   /* XOR with a                   */
+        if ((a&BIT6)!=0) {                    /* If D_all(all bit XOR) = 1    */
+            reg3^=(unsigned char)i;           /* XOR with counter             */
+            reg2^=~((unsigned char)i);        /* XOR with inv. of counter     */
+        }
+    }
+ 
+    /* Trans LP14,12,10,... & LP15,13,11,... -> LP15,14,13,... & LP7,6,5,..   */
+    trans_result(reg2,reg3,ecc1,ecc2);
+ 
+    *ecc1=~(*ecc1); *ecc2=~(*ecc2);           /* Inv. ecc2 & ecc3             */
+    *ecc3=((~reg1)<<2)|BIT1BIT0;              /* Make TEL format              */
+}
+ 
+static unsigned char correct_data(data,eccdata,ecc1,ecc2,ecc3)
+unsigned char *data;                          /* DATA                         */
+unsigned char *eccdata;                       /* ECC DATA                     */
+unsigned char ecc1;                           /* LP15,LP14,LP13,...           */
+unsigned char ecc2;                           /* LP07,LP06,LP05,...           */
+unsigned char ecc3;                           /* CP5,CP4,CP3,...,"1","1"      */
+{
+    unsigned long l;                          /* Working to check d           */
+    unsigned long d;                          /* Result of comparison         */
+    unsigned int i;                           /* For counting                 */
+    unsigned char d1,d2,d3;                   /* Result of comparison         */
+    unsigned char a;                          /* Working for add              */
+    unsigned char add;                        /* Byte address of cor. DATA    */
+    unsigned char b;                          /* Working for bit              */
+    unsigned char bit;                        /* Bit address of cor. DATA     */
+ 
+    d1=ecc1^eccdata[1]; d2=ecc2^eccdata[0];   /* Compare LP's                 */
+    d3=ecc3^eccdata[2];                       /* Comapre CP's                 */
+    d=((unsigned long)d1<<16)                 /* Result of comparison         */
+        +((unsigned long)d2<<8)
+        +(unsigned long)d3;
+ 
+    if (d==0) return(0);                      /* If No error, return          */
+    if (((d^(d>>1))&CORRECTABLE)==CORRECTABLE) {    /* If correctable         */
+        l=BIT23;
+        add=0;                                /* Clear parameter              */
+        a=BIT7;
+        for(i=0; i<8; ++i) {                  /* Checking 8 bit               */
+            if ((d&l)!=0) add|=a;             /* Make byte address from LP's  */
+            l>>=2; a>>=1;                     /* Right Shift                  */
+        }
+        bit=0;                                /* Clear parameter              */
+        b=BIT2;
+        for(i=0; i<3; ++i) {                  /* Checking 3 bit               */
+            if ((d&l)!=0) bit|=b;             /* Make bit address from CP's   */
+            l>>=2; b>>=1;                     /* Right shift                  */
+        }
+        b=BIT0;
+        data[add]^=(b<<bit);                  /* Put corrected data           */
+        return(1);
+    }
+    i=0;                                      /* Clear count                  */
+    d&=0x00ffffffL;                           /* Masking                      */
+    while(d) {                                /* If d=0 finish counting       */
+        if (d&BIT0) ++i;                      /* Count number of 1 bit        */
+        d>>=1;                                /* Right shift                  */
+    }
+    if (i==1) {                               /* If ECC error                 */
+        eccdata[1]=ecc1; eccdata[0]=ecc2;    /* Put right ECC code           */
+        eccdata[2]=ecc3;
+        return(2);
+    }
+    return(3);                                /* Uncorrectable error          */
+}
+/***************************************************************************
+    Common Subroutine
+ ***************************************************************************/
+char BitCount(unsigned char cdata)
+{
+    char bitcount=0;
+    while(cdata) {
+        bitcount+=(cdata &0x01);
+        cdata   /=2;
+    }
+    return(bitcount);
+}
+ 
+char BitCountWord(unsigned int cdata)
+{
+    char bitcount=0;
+    while(cdata) {
+        bitcount+=(cdata &0x01);
+        cdata   /=2;
+    }
+    return(bitcount);
+}
+
+/***************************************************************************/
+void StringCopy(char *stringA, char *stringB, int count)
+{
+    int i;
+    for(i=0; i<count; i++)
+        *stringA++ = *stringB++;
+}
+ 
+int StringCmp(char *stringA, char *stringB, int count)
+{
+    int i;
+    for (i=0;i<count;i++)
+        if (*stringA++ != *stringB++)   return(ERROR);
+    return(SUCCESS);
+}
+/***************************************************************************/
+int  CheckDataBlank(unsigned char *redundant)
+{
+    char i;
+    for(i=0; i<REDTSIZE; i++)
+        if(*redundant++!=0xFF)      return(ERROR);
+    return(SUCCESS);
+}
+
+int  CheckFailBlock(unsigned char *redundant)
+{
+    redundant+=REDT_BLOCK;
+    if(*redundant==0xFF)            return(SUCCESS);
+    if(! *redundant)                return(ERROR);
+    if(BitCount(*redundant)<7)     return(ERROR);
+    return(SUCCESS);
+}
+
+int  CheckCisBlock(unsigned char *redundant)
+{
+    if(! (*(redundant+REDT_ADDR1H)|*(redundant+REDT_ADDR1L)))
+        return(SUCCESS);
+    if(! (*(redundant+REDT_ADDR2H)|*(redundant+REDT_ADDR2L)))
+        return(SUCCESS);
+    return(ERROR);
+}
+
+int  CheckDataStatus(unsigned char *redundant)
+{
+    redundant+=REDT_DATA;
+    if(*redundant==0xFF)            return(SUCCESS);
+    if(! *redundant)                return(ERROR);
+    if(BitCount(*redundant)<5)     return(ERROR);
+    return(SUCCESS);
+}
+
+int  LoadLogBlockAddr(ssfdc_dev *psm)
+{
+    unsigned int addr1,addr2;
+    addr1=*(psm->Redundant+REDT_ADDR1H)*0x100+*(psm->Redundant+REDT_ADDR1L);
+    addr2=*(psm->Redundant+REDT_ADDR2H)*0x100+*(psm->Redundant+REDT_ADDR2L);
+    if(addr1==addr2)
+        if((addr1 &0xF000)==0x1000)
+            { psm->LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); }
+    if(BitCountWord(addr1^addr2)>1)            return(ERROR);
+    if((addr1 &0xF000)==0x1000)
+        if(! (BitCountWord(addr1) &0x0001))
+            { psm->LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); }
+    if((addr2 &0xF000)==0x1000)
+        if(! (BitCountWord(addr2) &0x0001))
+            { psm->LogBlock=(addr2 &0x0FFF)/2; return(SUCCESS); }
+    return(ERROR);
+}
+/***************************************************************************/
+void ClrRedundantData(unsigned char *redundant)
+{
+    char i;
+    for(i=0; i<REDTSIZE; i++)   *(redundant+i)=0xFF;
+}
+
+/***************************************************************************/
+void SetLogBlockAddr(ssfdc_dev *psm, unsigned char *redundant)
+{
+    unsigned int addr;
+    *(redundant+REDT_BLOCK)=0xFF;
+    *(redundant+REDT_DATA) =0xFF;
+    addr=psm->LogBlock*2+0x1000;
+    if((BitCountWord(addr)%2)) addr++;
+    *(redundant+REDT_ADDR1H)=*(redundant+REDT_ADDR2H)=addr/0x100;
+    *(redundant+REDT_ADDR1L)=*(redundant+REDT_ADDR2L)=(unsigned char)addr;
+}
+
+void SetFailBlock(unsigned char *redundant)
+{
+    char i;
+    for(i=0; i<REDTSIZE; i++)
+        *redundant++=((i==REDT_BLOCK)?0xF0:0xFF);
+}
+
+void SetDataStatus(unsigned char *redundant)
+{
+    redundant+=REDT_DATA;
+    *redundant=0x00;
+}
+
+
+/***************************************************************************
+    NAND Memory (SmartMedia) Control Subroutine
+ ***************************************************************************/
+static void _SetSsfdcCmd(ssfdc_dev *psm, unsigned char cmd)
+{
+    _HwSetCmd(psm);
+    _HwOutData(psm,cmd);
+    _HwSetData(psm);
+}
+ 
+static void _SetSsfdcAddr(ssfdc_dev *psm, unsigned char add)
+{
+    unsigned int addr;
+
+#if DEBUG_SSFDC_ADDR
+	printk(KERN_DEBUG "_SetSsfdcAddr() Zone %d LogBlock %d PhyBlock %d Sector %d\n",
+		psm->Zone,psm->LogBlock,psm->PhyBlock,psm->Sector);
+#endif
+    addr=(unsigned int)psm->Zone*psm->MaxBlocks+psm->PhyBlock;
+    addr=addr*(unsigned int)psm->MaxSectors+psm->Sector;
+    if((psm->Attribute &MPS)==PS256)       /* for 256byte/page */
+        addr=addr*2+(unsigned int)add;
+/*-----------------------------------------------*/
+    _HwSetAddr(psm);
+    _HwOutData(psm,0x00);
+    _HwOutData(psm,(unsigned char)addr);
+    _HwOutData(psm,(unsigned char)(addr/0x0100));
+    if((psm->Attribute &MADC)==AD4CYC)
+        _HwOutData(psm,(unsigned char)(psm->Zone/2)); /* Patch */
+    _HwSetData(psm);
+}
+
+static void _SetSsfdcBlock(ssfdc_dev *psm)
+{
+    unsigned int addr;
+#if DEBUG_SSFDC_ASSIGNRELEASE
+	printk(KERN_DEBUG "_SetSsfdcBlock() set card addr to PhyBlock %d\n", psm->PhyBlock);
+#endif
+    addr=(unsigned int)psm->Zone*psm->MaxBlocks+psm->PhyBlock;
+    addr=addr*(unsigned int)psm->MaxSectors;
+    if((psm->Attribute &MPS)==PS256)       /* for 256byte/page */
+        addr=addr*2;
+/*-----------------------------------------------*/
+    _HwSetAddr(psm);
+    _HwOutData(psm,(unsigned char)addr);
+    _HwOutData(psm,(unsigned char)(addr/0x0100));
+    if((psm->Attribute &MADC)==AD4CYC)
+        _HwOutData(psm,(unsigned char)(psm->Zone/2)); /* Patch */
+    _HwSetData(psm);
+}
+
+static inline void _SetSsfdcStandby(ssfdc_dev *psm)
+{
+    _HwSetStandby(psm);
+}
+
+static int _CheckSsfdcStatus(ssfdc_dev *psm)
+{
+	int status;
+    if((status=_HwInData(psm)) & WR_FAIL) {
+	   printk(KERN_DEBUG "_CheckSsfdcStatus() error %x\n", status);
+	   return(ERROR);
+	}
+    return(SUCCESS);
+} 
+
+static void _ResetSsfdcErr(ssfdc_dev *psm)
+{
+    _HwSetCmd(psm);
+    _HwOutData(psm,SSFDC_RST_CHIP);
+    _HwSetData(psm);
+   	while(1) {
+		udelay(30);
+		if(! _HwChkBusy(psm))     break;
+	}
+    _HwSetStandby(psm);
+}
+
+static void waiting_timeout(unsigned long psm)
+{
+	// enable the wakeup signal!
+	wake_up(&((ssfdc_dev *)psm)->thread_wq);
+}
+
+/*
+	_CheckSsfdcBusy()
+
+	set a timer in jiffies from int time x .1ms
+*/
+
+static int _CheckSsfdcBusy(ssfdc_dev *psm, unsigned int time)
+{
+	unsigned long	incr_div = 4;
+	unsigned long	incr_us = time / incr_div,
+					jticks=time/(MSEC * JIFFY_TICK_MS);
+	unsigned long 	tick_retried=0, wrap_flag, expires;
+
+	if (!jticks) {
+		// small delay first to test completion
+		do {
+			udelay(incr_us);
+			if (!_HwChkBusy(psm))
+				return(SUCCESS);
+		} while (incr_div--);
+		return(ERROR);
+	}
+
+	// Block the wakeup signal?
+
+one_more_time:
+	expires = jiffies + jticks;
+	wrap_flag = ( expires < jiffies);
+
+	do {
+		wait_event_interruptible_timeout(psm->thread_wq, 0, jticks);
+		if (!_HwChkBusy(psm)) {
+			return(SUCCESS);
+		}
+	} while (wrap_flag ? expires <= jiffies : expires >= jiffies);
+
+#if 1
+	// Is the chip not busy?  If so its an ERROR
+	if (!_HwChkBusy(psm)) {
+		return(SUCCESS);
+	}
+	else {
+		// if we came back, give us one more tick/time
+		if (! tick_retried ) {
+			tick_retried = 1;
+			jticks = 0;
+			printk(".");
+			goto one_more_time;
+		}
+		return(ERROR);
+	}
+#endif
+}
+
+static void _SetSsfdcChip(ssfdc_dev *psm)
+{
+    _HwSetAddr(psm);
+    _HwOutData(psm,0x00);
+    _HwSetData(psm);
+}
+/***************************************************************************
+    NAND Memory (SmartMedia)  Buffer Data Xfer Subroutine
+ ***************************************************************************/      
+static void _ReadSsfdcBuf(ssfdc_dev *psm,unsigned char *databuf,unsigned char *redundant)
+{
+    int i;
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x100:0x200);i++)
+        *databuf++   =_HwInData(psm);
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x08:0x10);i++)
+        *redundant++ =_HwInData(psm);
+}
+ 
+static void _WriteSsfdcBuf(ssfdc_dev *psm, unsigned char *databuf,unsigned char *redundant)
+{
+    int i;
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x100:0x200);i++)
+        _HwOutData(psm,*databuf++);
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x08:0x10);i++)
+        _HwOutData(psm,*redundant++);
+}
+
+static void _ReadSsfdcWord(ssfdc_dev *psm, unsigned int *pdata)
+{
+    *pdata =_HwInData(psm)*0x100;
+    *pdata|=(unsigned char)_HwInData(psm);
+}
+
+static void _ReadRedtSsfdcBuf(ssfdc_dev *psm,unsigned char *redundant)
+{
+    int i;
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x08:0x10);i++)
+        redundant[i] =_HwInData(psm);
+}
+ 
+static void _WriteRedtSsfdcBuf(ssfdc_dev *psm, unsigned char *redundant)
+{
+    char i;
+    for(i=0x00;i<(((psm->Attribute &MPS)==PS256)?0x08:0x10);i++)
+        _HwOutData(psm,*redundant++);
+}
+
+/***************************************************************************
+    Timer Control Subroutine
+ ***************************************************************************/
+#define SHORT_DELAY 1
+
+
+
+
+void _GetDateTime(char *date)
+{
+}
+
+/*
+_WaitTimer(long time) time is in ticks.
+*/
+
+static inline void _WaitTimer(long time)
+{
+}
+
+/***************************************************************************
+    SmartMedia Function Command Subroutine
+ ***************************************************************************/
+void SsfdcReset(ssfdc_dev *psm)
+{
+    _SetSsfdcCmd(psm, SSFDC_RST_CHIP);
+    _CheckSsfdcBusy(psm,BUSY_RESET);
+    _SetSsfdcCmd(psm,SSFDC_READ);
+    _CheckSsfdcBusy(psm,BUSY_READ);
+    _SetSsfdcStandby(psm);
+}
+
+void SsfdcWriteRedtMode(ssfdc_dev *psm)
+{
+    _SetSsfdcCmd(psm,SSFDC_RST_CHIP);
+    _CheckSsfdcBusy(psm,BUSY_RESET);
+    _SetSsfdcCmd(psm,SSFDC_READ_REDT);
+    _CheckSsfdcBusy(psm,BUSY_READ);
+    _SetSsfdcStandby(psm);
+}
+
+void SsfdcReadID(ssfdc_dev *psm, unsigned int *pid)
+{
+    _SetSsfdcCmd(psm,SSFDC_READ_ID);
+    _SetSsfdcChip(psm);
+    _ReadSsfdcWord(psm,pid);
+    _SetSsfdcStandby(psm);
+}
+
+int  SsfdcCheckStatus(ssfdc_dev *psm)
+{
+    _SetSsfdcCmd(psm,SSFDC_RDSTATUS);
+    if(_CheckSsfdcStatus(psm))
+        { _SetSsfdcStandby(psm);      return(ERROR); }
+    _SetSsfdcStandby(psm);
+    return(SUCCESS);
+}
+
+int  SsfdcReadSect(ssfdc_dev *psm, unsigned char *buf,unsigned char *redundant)
+{
+#if DEBUG_SSFDC_READ
+	 printk(KERN_DEBUG "SsfdcReadSect() - Zone %d LogBlock %d, PhyBlock %d, Sector %d\n",
+        psm->Zone, psm->LogBlock, psm->PhyBlock, psm->Sector);
+#endif
+    _SetSsfdcCmd(psm,SSFDC_READ);
+    _SetSsfdcAddr(psm, EVEN);
+    if(_CheckSsfdcBusy(psm,BUSY_READ))
+        { _ResetSsfdcErr(psm);        return(ERROR); }
+    _ReadSsfdcBuf(psm,buf,redundant);
+    if(_CheckSsfdcBusy(psm,BUSY_READ))
+        { _ResetSsfdcErr(psm);        return(ERROR); }
+    if((psm->Attribute &MPS)==PS256) {
+        _SetSsfdcCmd(psm,SSFDC_READ);
+        _SetSsfdcAddr(psm, ODD);
+        if(_CheckSsfdcBusy(psm,BUSY_READ))
+            { _ResetSsfdcErr(psm);    return(ERROR); }
+        _ReadSsfdcBuf(psm,buf+0x100,redundant+0x08);
+        if(_CheckSsfdcBusy(psm,BUSY_READ))
+            { _ResetSsfdcErr(psm);    return(ERROR); }
+    }
+    _SetSsfdcStandby(psm);
+    return(SUCCESS);
+}
+
+int  SsfdcWriteSect(ssfdc_dev *psm, unsigned char *buf, unsigned char *redundant)
+{
+#if DEBUG_SSFDC_WRITESECT
+	printk(KERN_DEBUG "SsfdcWriteSect() - Zone %d LogBlock %d, PhyBlock %d, Sector %d\n", \
+		psm->Zone, psm->LogBlock, psm->PhyBlock, psm->Sector);
+#endif
+    _SetSsfdcCmd(psm,SSFDC_WRDATA);
+    _SetSsfdcAddr(psm,EVEN);
+    _WriteSsfdcBuf(psm,buf,redundant);
+    _SetSsfdcCmd(psm,SSFDC_WRITE);
+    if(_CheckSsfdcBusy(psm,BUSY_PROG))
+        { _ResetSsfdcErr(psm); 
+#if DEBUG_SSFDC_WRITESECT
+			printk(KERN_DEBUG "SsfdcWriteSect() e 1\n");
+#endif
+		return(ERROR); }
+    if((psm->Attribute &MPS)==PS256) {
+        _SetSsfdcCmd(psm,SSFDC_RDSTATUS);
+        if(_CheckSsfdcStatus(psm))
+            { _SetSsfdcStandby(psm);  return(SUCCESS); }
+        _SetSsfdcCmd(psm,SSFDC_WRDATA);
+        _SetSsfdcAddr(psm,ODD);
+        _WriteSsfdcBuf(psm,buf+0x100,redundant+0x08);
+        _SetSsfdcCmd(psm,SSFDC_WRITE);
+        if(_CheckSsfdcBusy(psm,BUSY_PROG))
+            { _ResetSsfdcErr(psm);
+#if DEBUG_SSFDC_WRITESECT
+            printk(KERN_DEBUG "SsfdcWriteSect() e 2\n");
+#endif
+		    return(ERROR); }
+    }
+    _SetSsfdcStandby(psm);
+    return(SUCCESS);
+}
+
+int  SsfdcEraseBlock(ssfdc_dev *psm)
+{
+    _SetSsfdcCmd(psm,SSFDC_ERASE1);
+    _SetSsfdcBlock(psm);
+    _SetSsfdcCmd(psm,SSFDC_ERASE2);
+    if(_CheckSsfdcBusy(psm,BUSY_ERASE) || SsfdcCheckStatus(psm)) { 
+		_ResetSsfdcErr(psm);
+		return(ERROR);
+	}
+    _SetSsfdcStandby(psm);
+    return(SUCCESS);
+}
+
+int  SsfdcReadRedtData(ssfdc_dev *psm, unsigned char *redundant)
+{
+#if DEBUG_SSFDC_READREDT
+	printk(KERN_DEBUG " +");
+#endif
+    _SetSsfdcCmd(psm,SSFDC_READ_REDT);
+    _SetSsfdcAddr(psm,EVEN);
+    if(_CheckSsfdcBusy(psm,BUSY_READ))
+        { _ResetSsfdcErr(psm);        
+#if DEBUG_SSFDC_READREDT
+			printk(KERN_DEBUG " e 1\n");
+#endif
+		return(ERROR); }
+    _ReadRedtSsfdcBuf(psm, redundant);
+    if(_CheckSsfdcBusy(psm,BUSY_READ))
+        { _ResetSsfdcErr(psm);
+#if DEBUG_SSFDC_READREDT
+			printk(KERN_DEBUG " e 2\n");
+#endif
+	        return(ERROR); }
+    if((psm->Attribute &MPS)==PS256) {
+        _SetSsfdcCmd(psm,SSFDC_READ_REDT);
+        _SetSsfdcAddr(psm,ODD);
+        if(_CheckSsfdcBusy(psm,BUSY_READ))
+            { _ResetSsfdcErr(psm);
+#if DEBUG_SSFDC_READREDT
+				printk(KERN_DEBUG " e 3\n");
+#endif
+
+			    return(ERROR); }
+        _ReadRedtSsfdcBuf(psm, redundant+0x08);
+        if(_CheckSsfdcBusy(psm,BUSY_READ))
+            { _ResetSsfdcErr(psm);
+#if DEBUG_SSFDC_READREDT
+				printk(KERN_DEBUG " e 4\n");
+#endif
+			    return(ERROR); }
+    }
+    _SetSsfdcStandby(psm);
+#if DEBUG_SSFDC_READREDT
+	printk(KERN_DEBUG " -\n");
+#endif
+    return(SUCCESS);
+}
+
+int  SsfdcWriteRedtData(ssfdc_dev *psm, unsigned char *redundant)
+{
+    _SetSsfdcCmd(psm,SSFDC_WRDATA);
+    _SetSsfdcAddr(psm,EVEN);
+    _WriteRedtSsfdcBuf(psm,redundant);
+    _SetSsfdcCmd(psm,SSFDC_WRITE);
+    if(_CheckSsfdcBusy(psm,BUSY_PROG))
+        { _ResetSsfdcErr(psm);        return(ERROR); }
+    if((psm->Attribute &MPS)==PS256) {
+        _SetSsfdcCmd(psm,SSFDC_RDSTATUS);
+        if(_CheckSsfdcStatus(psm))
+            { _SetSsfdcStandby(psm);  return(SUCCESS); }
+        _SetSsfdcCmd(psm,SSFDC_WRDATA);
+        _SetSsfdcAddr(psm,ODD);
+        _WriteRedtSsfdcBuf(psm,redundant+0x08);
+        _SetSsfdcCmd(psm,SSFDC_WRITE);
+        if(_CheckSsfdcBusy(psm,BUSY_PROG))
+            { _ResetSsfdcErr(psm);    return(ERROR); }
+    }
+    _SetSsfdcStandby(psm);
+    return(SUCCESS);
+}
+
+/***************************************************************************
+    SmartMedia ID Code Check & Mode Set Subroutine
+ ***************************************************************************/
+int  SetSsfdcModel(ssfdc_dev *psm, unsigned char dcode)
+{
+    switch(_CheckDevCode(dcode))   {
+       	case SSFDC1MB:
+		psm->Model        = SSFDC1MB;
+		psm->Attribute    = FLASH | AD3CYC | BS16 | PS256;
+		psm->MaxZones     = 1;
+		psm->MaxBlocks    = 256;
+		psm->MaxLogBlocks = 250;
+		psm->MaxSectors   = 8;
+		break;
+       	case SSFDC2MB:
+		psm->Model        = SSFDC2MB;
+		psm->Attribute    = FLASH | AD3CYC | BS16 | PS256;
+		psm->MaxZones     = 1;
+		psm->MaxBlocks    = 512;
+		psm->MaxLogBlocks = 500;
+		psm->MaxSectors   = 8;
+		break;
+       	case SSFDC4MB:
+		psm->Model        = SSFDC4MB;
+		psm->Attribute    = FLASH | AD3CYC | BS16 | PS512;
+		psm->MaxZones     = 1;
+		psm->MaxBlocks    = 512;
+		psm->MaxLogBlocks = 500;
+		psm->MaxSectors   = 16;
+		break;
+       	case SSFDC8MB:
+		psm->Model        = SSFDC8MB;
+		psm->Attribute    = FLASH | AD3CYC | BS16 | PS512;
+		psm->MaxZones     = 1;
+		psm->MaxBlocks    = 1024;
+		psm->MaxLogBlocks = 1000;
+		psm->MaxSectors   = 16;
+		break;
+       	case SSFDC16MB:
+		psm->Model        = SSFDC16MB;
+		psm->Attribute    = FLASH | AD3CYC | BS32 | PS512;
+		psm->MaxZones     = 1;
+		psm->MaxBlocks    = 1024;
+		psm->MaxLogBlocks = 1000;
+		psm->MaxSectors   = 32;
+		break;
+       	case SSFDC32MB:
+		psm->Model        = SSFDC32MB;
+		psm->Attribute    = FLASH | AD3CYC | BS32 | PS512;
+		psm->MaxZones     = 2;
+		psm->MaxBlocks    = 1024;
+		psm->MaxLogBlocks = 1000;
+		psm->MaxSectors   = 32;
+		break;
+       	case SSFDC64MB:
+		psm->Model        = SSFDC64MB;
+		psm->Attribute    = FLASH | AD4CYC | BS32 | PS512;
+		psm->MaxZones     = 4;
+		psm->MaxBlocks    = 1024;
+		psm->MaxLogBlocks = 1000;
+		psm->MaxSectors   = 32;
+		break;
+	case SSFDC128MB:
+		psm->Model        = SSFDC128MB;
+		psm->Attribute    = FLASH | AD4CYC | BS32 | PS512;
+		psm->MaxZones     = 8;
+		psm->MaxBlocks    = 1024;
+		psm->MaxLogBlocks = 1000;
+		psm->MaxSectors   = 32;
+		break;
+	default:
+		psm->Model        = NOSSFDC;
+		return(ERROR);
+	}
+	return(SUCCESS);
+}
+
+/***************************************************************************/
+static unsigned char _CheckDevCode(unsigned char dcode)
+{
+    switch(dcode){
+        case 0x6E:
+        case 0xE8:
+        case 0xEC:  return(SSFDC1MB);       /*  8Mbit (1M) NAND */
+        case 0x64:
+        case 0xEA:  return(SSFDC2MB);       /* 16Mbit (2M) NAND */
+        case 0x6B:
+        case 0xE3:
+        case 0xE5:  return(SSFDC4MB);       /* 32Mbit (4M) NAND */
+        case 0xE6:  return(SSFDC8MB);       /* 64Mbit (8M) NAND */
+        case 0x73:  return(SSFDC16MB);      /*128Mbit (16M)NAND */
+        case 0x75:  return(SSFDC32MB);      /*256Mbit (32M)NAND */
+        case 0x76:  return(SSFDC64MB);      /*512Mbit (64M)NAND */
+        case 0x79:  return(SSFDC128MB);     /*  1Gbit(128M)NAND */
+        default:    return(ERROR);
+    }
+}
+/***************************************************************************
+    SmartMedia Power Control Subroutine
+ ***************************************************************************/
+void CntReset(ssfdc_dev *psm)
+{
+    _HwSetStandby(psm);
+    _HwVccOff(psm);
+}
+
+int  CntPowerOn(ssfdc_dev *psm)
+{
+    _HwVccOn(psm);
+    _WaitTimer(TIME_PON);
+    if(_HwChkPower(psm))
+        return(SUCCESS);
+    _HwVccOff(psm);
+    return(ERROR);
+}
+
+#if 0	// remove for now
+static void mediachangetest(unsigned long dev_idx)
+{
+	ssfdc_dev *psm = ssfdc[dev_idx];
+	unsigned int cardpresent;
+	unsigned long flags;
+
+	spin_lock_irqsave( &psm->req_queue_lock, flags );
+	// bjm spin_lock( &psm->req_queue_lock);
+
+	del_timer(&mediachange_timer);
+
+	// check current card presence
+	if ( ! (cardpresent = CntPowerOn(psm)) && psm->CardPresent ) {
+		psm->MediaChange = 1;
+		psm->DataBuf_Valid = 0;
+	}
+	psm->CardPresent = cardpresent;
+
+	// set up to run again...
+	mediachange_timer.function = mediachangetest;
+	mediachange_timer.expires = jiffies + (HZ / 2);
+	mediachange_timer.data = dev_idx;
+	add_timer(&mediachange_timer);
+
+	spin_unlock_irqrestore( &psm->req_queue_lock, flags );
+	// bjm spin_unlock( &psm->req_queue_lock);
+}
+#endif
+
+int  CheckCardExist(ssfdc_dev *psm)
+{
+    char i,j,k;
+    if(! _HwChkStatus(psm))                   /***** Not Status Change *****/
+        if(_HwChkCardIn(psm)) return(SUCCESS);    /* Card exist in Slot */
+    for(i=0,j=0,k=0; i<0x10; i++) {
+        if(_HwChkCardIn(psm))                 /***** Status Change *****/
+             { j++; k=0; }
+        else { j=0; k++; }
+        if(j>3)     return(SUCCESS);            /* Card exist in Slot */
+        if(k>3)     return(ERROR);              /* NO Card exist in Slot */
+        _WaitTimer(TIME_CDCHK);
+    }
+    return(ERROR);
+}
+
+int  CheckSsfdcWP(ssfdc_dev *psm)
+{   /* ERROR: WP, SUCCESS: Not WP */
+    char i;
+    for(i=0; i<0x08; i++) {
+        if(_HwChkWP(psm))
+            return(ERROR);
+        _WaitTimer(TIME_WPCHK);
+    }
+    return(SUCCESS);
+}
+
+/******************************************/
+int  CheckCISdata(unsigned char *buf,unsigned char *redundant)
+{
+    static unsigned char cis[]={ 0x01,0x03,0xD9,0x01,0xFF,0x18,0x02,0xDF,0x01,0x20 };
+    unsigned char ecc1,ecc2,ecc3;
+    unsigned int err;
+    calculate_ecc(ecctable,buf,&ecc1,&ecc2,&ecc3);
+    err=correct_data(buf,redundant+0x0D,ecc1,ecc2,ecc3);
+    if(err==0 || err==1 || err==2)
+        return(StringCmp(buf,cis,10));
+    buf+=0x100;
+    calculate_ecc(ecctable,buf,&ecc1,&ecc2,&ecc3);
+    err=correct_data(buf,redundant+0x08,ecc1,ecc2,ecc3);
+    if(err==0 || err==1 || err==2)
+        return(StringCmp(buf,cis,10));
+    return(ERROR);
+}
+
+int  CheckECCdata(unsigned char *buf,unsigned char *redundant)
+{
+    unsigned char ecc1,ecc2,ecc3;
+    unsigned int err, corr=SUCCESS;
+    calculate_ecc(ecctable,buf,&ecc1,&ecc2,&ecc3);
+    err=correct_data(buf,redundant+0x0D,ecc1,ecc2,ecc3);
+    if(err==1 || err==2)    corr=CORRECT;
+    else if(err)            return(ERROR);
+    buf+=0x100;
+    calculate_ecc(ecctable,buf,&ecc1,&ecc2,&ecc3);
+    err=correct_data(buf,redundant+0x08,ecc1,ecc2,ecc3);
+    if(err==1 || err==2)    corr=CORRECT;
+    else if(err)            return(ERROR);
+    return(corr);
+}
+
+void SetECCdata(unsigned char *buf,unsigned char *redundant)
+{
+    calculate_ecc(ecctable,buf,redundant+0x0E,redundant+0x0D,redundant+0x0F);
+    buf+=0x100;
+    calculate_ecc(ecctable,buf,redundant+0x09,redundant+0x08,redundant+0x0A);
+}
+
+/***************************************************************************
+	Power Control & Media Exist Check Function
+ ***************************************************************************/
+
+/***************************************************************************
+	SmartMedia Read/Write/Erase Function
+ ***************************************************************************/
+static int MediaReadSector(ssfdc_dev *psm, struct request *req,
+				char * bbuf, long start,int count)
+{
+	char *buf;
+	int i, err, request_complete, 
+		PrevBlock = NO_ASSIGN;
+	int read_status=0;
+
+	if (ConvMediaAddr(psm, start)) {
+		printk(KERN_ERR "MediaReadSector() - bad address conversion\n");
+		goto read_exit;
+	}
+
+	psm->ReqSectorSize = count;
+	psm->BufIndex = 0;
+	psm->RetryCount = 0;
+
+#if DEBUG_SSFDC_READ
+	printk(KERN_DEBUG "MediaReadSector() - read %d sectors @ %d\n", psm->ReqSectorSize, start);
+#endif
+	while (psm->ReqSectorSize) {
+    	// if this PhyBlock is not assigned, fill with dummy data and return
+    	// An assigned block results in a card access and readsector schedule...
+    		if (psm->PhyBlock == NO_ASSIGN) {
+#if DEBUG_SSFDC_READ
+			printk(KERN_DEBUG "Read NO_ASSIGN block %x\n", psm->PhyBlock);
+#endif
+			buf = bbuf + psm->BufIndex;
+			for(i=0; i<SSFDC_SECTSIZE; i++)
+				*buf++=DUMMY_DATA;
+		}
+	    else {
+			// send our command
+			if (PrevBlock != psm->PhyBlock) {
+#if DEBUG_SSFDC_READ
+	printk(KERN_DEBUG "Read block %x\n", psm->PhyBlock);
+#endif
+				PrevBlock = psm->PhyBlock;
+				_SetSsfdcCmd(psm,SSFDC_READ);
+				_SetSsfdcAddr(psm, EVEN);
+				for (i=0; i<5; ++i) {
+					if (!_HwChkBusy(psm))
+						break;
+					udelay(10);
+				}
+			}
+
+
+			if ( _HwChkBusy(psm) ) {
+				++psm->Sect_rd_errs_ttl;
+#if DEBUG_SSFDC_READ
+				printk(KERN_DEBUG "MediaReadSector() - Hardware busy!\n");
+#endif
+			}
+			else {
+				++psm->Sector_reads;
+				_ReadSsfdcBuf( psm, psm->SectBuf, psm->Redundant);
+
+				// verify the integrity of what was read
+				if (CheckDataStatus(psm->Redundant)) {
+#if DEBUG_SSFDC_READ
+					printk(KERN_DEBUG "Bad Data Status\n");
+#endif
+					goto error_state;
+				}
+
+				switch (err = CheckECCdata(psm->SectBuf,psm->Redundant))
+				{
+					case CORRECT:
+						// Correctable data, fix and copy like SUCCESS
+						SetECCdata(psm->SectBuf,psm->Redundant);
+					case SUCCESS:
+						memcpy(bbuf + psm->BufIndex, psm->SectBuf, SSFDC_SECTSIZE);
+						break;
+
+					case ERROR:
+error_state:
+						++psm->Sect_rd_errs_ttl;
+#if DEBUG_SSFDC_READ
+						printk(KERN_DEBUG "readsector() - err == ERROR\n");
+#endif
+						_ResetSsfdcErr(psm);
+						if (++psm->RetryCount < RD_RETRY_LIMIT) {
+							continue;
+						}
+						break;
+					default:
+						ssfdc_terminate_request( psm, req);
+						break;
+				}
+ 
+			}	// if ( _HwChkBusy(psm) )
+		}	// if (psm->PhyBlock == NO_ASSIGN)
+
+		// common req/buffer management code for either unassigned or assigned
+		// block from /dev/ssfdc
+		psm->RetryCount = 0;
+		psm->BufIndex += SSFDC_SECTSIZE;
+		request_complete = (--psm->ReqSectorSize == 0);
+        	if (request_complete) {
+			// completed the read, req->buffer now has requested sector(s).
+        		// End the request waking sleeping process and reschedule initxfer().
+#if DEBUG_SSFDC_READ
+			printk(KERN_DEBUG "readsector() - req %x complete\n", req);
+#endif
+			read_status = 1;
+		}
+		else if (IncMediaAddr(psm)) {
+			printk(KERN_DEBUG "readsector() - IncMediaAddr() error.\n");
+			goto read_exit;
+		}
+	}	// while (psm->ReqSectorSize)
+
+read_exit:
+	psm->XferState = xfer_idle;
+
+	return read_status;
+
+}
+
+/*
+	ReadBlkCopy(ssfdc_dev *psm, unsigned char *buf)
+*/
+int ReadBlkCopy(ssfdc_dev *psm, unsigned char *buf, char *rd_sector_status)
+{
+	int err, read_error=0, rw_retry=0;
+	unsigned long PrevBlock=NO_ASSIGN;
+
+	if ( ! buf ) {
+		printk(KERN_ERR "NULL buffer pointer\n");
+		return ERROR;
+	}
+
+	if (psm->PhyBlock == NO_ASSIGN) {
+		memset(buf, 0xff, psm->MaxSectors * SSFDC_SECTSIZE);
+		memset(rd_sector_status, 1, sizeof(char) * MAX_SECTNUM);
+		return SUCCESS;
+	}
+
+#if 0
+	printk(KERN_ERR "ReadBlkCopy() - LogBlk %d\n", psm->LogBlock);
+#endif
+
+	for (psm->Sector = 0; 
+		psm->PhyBlock != NO_ASSIGN && psm->Sector < psm->MaxSectors; 
+		++psm->Sector) 
+	{
+		if (PrevBlock != psm->PhyBlock) {
+			_SetSsfdcCmd(psm,SSFDC_READ);
+			_SetSsfdcAddr(psm, EVEN);
+			PrevBlock = psm->PhyBlock;
+			_CheckSsfdcBusy(psm, BUSY_ADDR_SET);
+		}
+
+		if ( _HwChkBusy(psm) ) {
+			printk(KERN_ERR "%s: HW busy during block copy!\n", MAJOR_NAME);
+			goto error_state;
+		}
+
+		_ReadSsfdcBuf( psm, psm->SectBuf, psm->Redundant);
+		if (CheckDataStatus(psm->Redundant)) {
+			printk("KERN_ERR reading Block %d, sector %d\n", psm->PhyBlock, psm->Sector);
+			goto error_state;
+		}
+
+		// Attempt to correct
+		switch (err = CheckECCdata(psm->SectBuf,psm->Redundant))
+		{
+			case CORRECT:
+#if DEBUG_SSFDC_WRITE
+				printk(KERN_DEBUG "ReadBlkCopy() - err == CORRECT\n");
+#endif
+				SetECCdata(psm->SectBuf,psm->Redundant);
+			case SUCCESS:
+				read_error = 0;
+				rw_retry = 0;
+				memcpy(buf + (psm->Sector * SSFDC_SECTSIZE), psm->SectBuf, SSFDC_SECTSIZE);
+				rd_sector_status[psm->Sector] = 1;
+				read_error = 0;
+				break;
+
+			case ERROR:
+error_state:
+/*bjm*/ printk("ERR - ECC error reading Block %d, Sector %d\n", psm->PhyBlock,psm->Sector);
+#if DEBUG_SSFDC_WRITE
+				printk(KERN_DEBUG "ReadBlkCopy() - err == ERROR\n");
+				printk("_ResetSsfdcErr(psm)\n");
+#endif
+				_ResetSsfdcErr(psm);
+				PrevBlock = NO_ASSIGN;
+				if (++rw_retry < RD_RETRY_LIMIT) {
+					// retry current Sector/loop counter on next loop iteration.
+					--psm->Sector;
+				}
+				else {
+					// set sector data in copy buf to the unassigned value 0xFF
+					// next loop iteration will read next Sector, zero RetryCount 
+					// for next sectors read
+					// map bad sector...
+					memset(buf + psm->Sector * SSFDC_SECTSIZE, 0xFF, SSFDC_SECTSIZE);
+					rw_retry = 0;
+					rd_sector_status[psm->Sector] = 0;
+					++psm->Sect_rd_errs_ttl;
+					read_error = 1;
+				}
+#if DEBUG_SSFDC_WRITE
+				printk(KERN_DEBUG "Unable to read Blk %d Sector %d\n", psm->PhyBlock, psm->Sector);
+#endif
+				break;
+		}
+	}
+	if (!read_error) {
+		if (SsfdcEraseBlock(psm)) {
+			MarkFailPhyOneBlock(psm);
+			++psm->Bad_blks_erase;
+		}
+		else {
+			ClrBit(psm->Assign[psm->Zone], psm->PhyBlock);
+		}
+	}
+	else {
+		printk("Read error block %d\n", psm->PhyBlock);
+		MarkFailPhyOneBlock(psm);
+	}
+	psm->Sector = 0;
+	return read_error ? ERROR : SUCCESS;
+}
+
+/*
+	WriteBlock()
+*/
+int WriteBlock(ssfdc_dev *psm, char *buf, char *wr_sector_status)
+{
+	int write_error=0, reassign_retry=0;
+
+	for ( reassign_retry = 0; reassign_retry < REASSIGN_RETRY_LIMIT; ++reassign_retry)
+	{
+		/*
+		assign new write block for write req
+			- set new write address
+			- write buffer to new block
+		*/
+#if DEBUG_SSFDC_WRITE
+		if (AssignWriteBlock(psm,1)) {
+#else
+		if (AssignWriteBlock(psm,0)) {
+#endif
+			write_error = 1;
+			printk(KERN_ERR "sm%dd Unable to assign new write block.\n", psm->sm_minor); 
+			memset(wr_sector_status, 1, sizeof(char) * MAX_SECTNUM); 
+			// ssfdc_terminate_request(psm, req);
+			return ERROR;
+		}
+
+#if 0
+		printk(KERN_ERR "WriteBlock() - LogBlock %d\n", psm->LogBlock);
+#endif
+
+		for (psm->Sector = 0; psm->Sector < psm->MaxSectors; ++psm->Sector)
+		{
+			memcpy(psm->SectBuf,buf+psm->Sector*SSFDC_SECTSIZE,SSFDC_SECTSIZE);
+
+			_SetSsfdcCmd(psm,SSFDC_WRDATA);
+			_SetSsfdcAddr(psm,EVEN);
+			ClrRedundantData(psm->Redundant);
+			SetLogBlockAddr(psm,psm->Redundant);
+			SetECCdata(psm->SectBuf,psm->Redundant);
+			_WriteSsfdcBuf(psm,psm->SectBuf,psm->Redundant);
+
+#if DEBUG_SSFDC_WRITE
+			printk("%d ", psm->Sector);
+#endif
+
+			_SetSsfdcCmd(psm, SSFDC_WRITE);
+			if ( ! _CheckSsfdcBusy(psm, BUSY_PROG) && !SsfdcCheckStatus(psm)) {
+#if DEBUG_SSFDC_WRITE
+				printk("\nMulti-Sector write OK!\n");
+#endif
+				_SetSsfdcStandby(psm);
+				// mark status a success
+				wr_sector_status[psm->Sector] = 1;
+
+#if 0	// bjm removed
+				{	unsigned char parbuf[SSFDC_SECTSIZE];
+					unsigned char redtpar[REDTSIZE];
+
+					_SetSsfdcCmd(psm,SSFDC_READ);
+					_SetSsfdcAddr(psm, EVEN);
+
+					udelay(30);
+					if ( _HwChkBusy(psm) ) {
+						_ResetSsfdcErr(psm);
+						printk("paranoid read failure\n");
+					}
+					else {
+						_ReadSsfdcBuf(psm, parbuf, redtpar);
+						if (CheckDataStatus(redtpar)) {
+							printk("paranoid read, bad data status\n");
+						}
+						else {
+							switch( err = CheckECCdata(parbuf,redtpar))
+							{
+								case CORRECT:
+									printk("paranoid correctable\n");
+									SetECCdata(parbuf,redtpar);
+								case SUCCESS:
+									if (memcmp(parbuf,psm->SectBuf, SSFDC_SECTSIZE))
+										write_error = 1;
+									else
+										write_error = 0;
+									break;
+								case ERROR:
+									MarkFailPhyOneBlock(psm);
+									write_error=1;
+									break;
+							}
+						}
+					}
+				}	// bjm end of paranoid read back test...
+#endif
+			}
+			else {
+#if DEBUG_SSFDC_WRITE
+				printk("\nMulti-Sector write FAILED!\n");
+#endif
+				// mark status a failure
+				wr_sector_status[psm->Sector] = 0;
+				_ResetSsfdcErr(psm);
+				write_error = 1;
+				break;
+			}	// for (psm->Sector ...)
+			if (write_error)
+				break;
+		}
+		if ( ! write_error ) {
+			psm->Log2Phy[psm->Zone][psm->LogBlock] = psm->WriteBlock;	
+			break;
+		}
+	}
+	psm->Sector = 0;
+	return write_error ? ERROR : SUCCESS;
+}
+
+/* 
+	MediaWriteSector()
+
+*/
+static int MediaWriteSector(ssfdc_dev *psm, struct request *req, char * bbuf, long start, int count)
+{
+	int write_error=0, unwritten_block=0;
+	char *buf;
+	unsigned long curr_sector, blksize, PrevBlock;
+	unsigned long writebuf_index, readbio_index;
+	int i, sector,  rw_retry=0;
+	int sectors_in_block;
+	char rd_sector_status[MAX_SECTNUM];
+	char wr_sector_status[MAX_SECTNUM];
+
+	// optimized write, new vars
+	int	bio_endios=0;
+	int	bio_bvecs=0;
+	struct bio *bio;
+	// optimized for write
+
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "+MediaWriteSector()\n");
+#endif
+
+	if (!count) {
+		printk("MediaWriteSector() count == 0!\n");
+		ssfdc_end_request(psm, req, 0);
+		return 1;
+	}
+
+	if (CheckMediaWP(psm)) {
+		printk(KERN_DEBUG "%s: write protected media.\n", MAJOR_NAME);
+		ssfdc_terminate_request( psm, req);
+		psm->XferState = xfer_idle;
+		return -EIO;
+	}
+
+	// allocate block size buffer
+	blksize = psm->MaxSectors * SSFDC_SECTSIZE;
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "%s: Allocate %d sized block.\n", MAJOR_NAME, blksize);
+#endif
+	if ((buf = kmalloc(blksize, GFP_ATOMIC)) == NULL) {
+		printk(KERN_ERR "%s: Null buffer allocated!\n", MAJOR_NAME);
+		ssfdc_terminate_request( psm, req);
+		goto the_exit;
+	}
+
+	/*
+		Loop to handle a request at the curr_sector of count sectors.
+		The write operation my encompas more than one phys block.
+	*/
+	curr_sector = start;
+	sectors_in_block = 0;
+	// zero out our sector R/W status array
+	memset(rd_sector_status, 1, sizeof(char) * MAX_SECTNUM);
+	memset(wr_sector_status, 1, sizeof(char) * MAX_SECTNUM);
+
+	// rangecheck this sector within the device.
+	if (ConvMediaAddr(psm, curr_sector)) {
+		ssfdc_terminate_request(psm, req);
+		printk(KERN_ERR "WriteSector: ConvMediaAddr() error\n");
+#if DEBUG_SSFDC_WRITE
+		printk(KERN_DEBUG "-MediaWriteSector()\n");
+#endif
+		return 0;
+	}
+	
+#if DEBUG_SSFDC_WRITE
+		printk(KERN_DEBUG "MediaWriteSector() Zone %d, LogBlock %d PhyBlock %d, Sector %d\n",
+						psm->Zone,psm->LogBlock, psm->PhyBlock,psm->Sector);
+#endif
+
+	PrevBlock = NO_ASSIGN;
+	rw_retry = 0;
+
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "Copy Zone %d, Phys %d\n", psm->Zone, psm->PhyBlock);
+#endif
+	// As a technique for wear leveling, a write to the SM results in the contents
+	// of the block to be copied into a blocksize buffer, the write data of the 
+	// write request being overlayed onto the buffer containing the copied block,
+	// a new logical to physical mapping defined, and the buffer written into this
+	// newly mapped (logically) physical block.
+
+	// read the physical block into the buffer.
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "ReadBlock = %d LogBlock %d\n", psm->PhyBlock, psm->LogBlock);
+#endif
+	if (ReadBlkCopy(psm, buf, rd_sector_status) != SUCCESS) {
+		printk(KERN_ERR "Unable to read block.\n");
+		goto the_exit;
+	}
+
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "Read from pending write request ");
+#endif
+		
+#if 0
+	int bio_idx=0;
+#endif
+	rq_for_each_bio(bio, req) {
+		struct bio_vec *bvec;
+		int i, break_flag=0;
+#if 0
+		int segment_idx;
+		printk(KERN_ERR "bio %d\n", bio_idx++);
+
+		segment_idx = 0;
+#endif
+		// bio_bvecs = 0;
+		bio_for_each_segment(bvec, bio, i) {
+#if 0
+			printk(KERN_ERR "segment %d\n", segment_idx++);
+#endif
+			// The conditions...
+			// bio fits within block
+			if (WriteReqInCurrBlk(psm,curr_sector + (bvec->bv_len >> 9) - 1,&sector)
+				&& WriteReqInCurrBlk(psm,curr_sector, &sector))
+			{
+#if 0
+				printk(KERN_ERR "LogBlk %d: write at %d, %d sectors\n", 
+							psm->LogBlock, curr_sector % psm->MaxSectors, bio_cur_sectors(bio));
+#endif
+				// write bio into copied block
+				++bio_bvecs;
+				writebuf_index = sector * SSFDC_SECTSIZE;
+#if 0
+				printk(KERN_ERR "memcpy buf at 0x%x, 0x%x bytes\n",
+						writebuf_index, bvec->bv_len);
+#endif
+				memcpy(buf + writebuf_index, 
+						page_address(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
+				unwritten_block = 1;
+				curr_sector += bvec->bv_len >> 9;
+			}
+			// bio fits partially within block
+			else if (WriteReqInCurrBlk(psm,curr_sector, &sector))
+			{
+				// put portion of bio in block
+				++bio_bvecs;
+				writebuf_index = sector * SSFDC_SECTSIZE;
+				sectors_in_block = psm->MaxSectors - sector;
+				readbio_index = sectors_in_block * SSFDC_SECTSIZE;
+#if 0
+				printk(KERN_ERR "memcpy buf at %x, %x bytes\n",
+						writebuf_index, readbio_index);
+#endif
+				memcpy(buf + writebuf_index, 
+					page_address(bvec->bv_page) + bvec->bv_offset, readbio_index);
+#if 0
+				printk(KERN_ERR "LogBlk %d: partial-write at %d, %d sectors first\n",
+								psm->LogBlock, curr_sector % psm->MaxSectors, sectors_in_block);
+#endif
+				// write block
+				unwritten_block = 0;
+				if (WriteBlock(psm, buf, wr_sector_status) != SUCCESS) {
+					printk(KERN_ERR "Unable to write block %d\n", psm->LogBlock);
+					// write_error - writing this block failed
+					break_flag = 1;
+					break;
+				}
+				// incr addr & read next block, 
+				curr_sector += sectors_in_block;
+				if (ConvMediaAddr(psm,curr_sector) != SUCCESS) {
+					printk(KERN_ERR "MediaWriteSector() IncMediaAddr() error!\n");
+					// write_error - address into next block is bogus
+					write_error = 1;
+					break_flag = 1;
+					break;
+				}
+				if (ReadBlkCopy(psm, buf, rd_sector_status) != SUCCESS) {
+					printk(KERN_ERR "MediaWriteSector() ReadBlkCopy() error!\n");
+					// write error - next block read error
+					write_error = 1;
+					break_flag =1;
+					break;
+				}
+				// write remainder of bio into block
+#if 0
+				printk(KERN_ERR "LogBlk %d: partial-write at %d, %d sectors, second write\n",
+					psm->LogBlock, curr_sector % psm->MaxSectors, (bvec->bv_len >> 9) - sectors_in_block);
+#endif
+#if 0
+				printk(KERN_ERR "memcpy buf at 0x%x, from bio 0x%x, for 0x%x bytes\n",
+						0, readbio_index, ((bvec->bv_len >> 9) - sectors_in_block) * SSFDC_SECTSIZE);
+#endif
+				memcpy(buf, (page_address(bvec->bv_page) + bvec->bv_offset) + readbio_index,
+								((bvec->bv_len >> 9) - sectors_in_block) * SSFDC_SECTSIZE);
+				writebuf_index = ((bvec->bv_len >> 9) - sectors_in_block) * SSFDC_SECTSIZE;
+				unwritten_block = 1;
+				curr_sector += (bvec->bv_len >> 9) - sectors_in_block;
+			}
+			// bio is not in block at all.  coplete unwritten block and exit loop.
+			else {
+				// write current block
+#if 0
+				printk(KERN_ERR "bio no longer in block\n");
+#endif
+				if (unwritten_block) {
+					if (WriteBlock(psm, buf, wr_sector_status) != SUCCESS) {
+						printk(KERN_ERR "MediaWriteSector() WriteBlock() error!\n");
+						// write_error
+					}
+					unwritten_block = 0;
+				}
+				break_flag = 1;
+				break;
+			}
+		}
+		// bjm if (bio_bvecs) +bio_bvecs;
+
+		if (break_flag)
+			break;
+	}
+
+	if (unwritten_block) {
+		if (WriteBlock(psm, buf, wr_sector_status) != SUCCESS) {
+			printk(KERN_ERR "MediaWriteSector() WriteBlock() error!\n");
+			write_error = 1;
+		}
+	}
+
+	if (!(bio_endios=bio_bvecs)) {
+		if (static_ssfdc_debug)
+			printk("no bios from request!\n");
+		++bio_endios;
+		write_error = 0;
+	}
+
+the_exit:
+	// log sector status for the copied/unmodified Sectors and flag any that have cpy errors
+	for (sector = 0; sector < psm->MaxSectors; ++sector) {
+		if ( ! rd_sector_status[sector] )
+			printk(KERN_ERR "%s: READ sector %d invalid for block %d!\n", \
+					MAJOR_NAME, sector, psm->LogBlock); 
+		if ( ! wr_sector_status[sector])
+			printk(KERN_ERR "%s: WRITTEN sector %d invalid for block %d!\n", \
+					MAJOR_NAME, sector, psm->LogBlock); 
+	}
+
+	// free our prev allocated block for copy...
+	if (buf)
+		kfree(buf);
+
+	psm->XferState = xfer_idle;
+
+#if DEBUG_SSFDC_WRITE
+	printk(KERN_DEBUG "-MediaWriteSector()\n");
+#endif
+	if (static_ssfdc_debug)
+		printk("end_request(%d) ", ! write_error);
+	for (i = 0; i < bio_endios; ++i) {
+		if (static_ssfdc_debug)
+			printk("%d ", i);
+		ssfdc_end_request(psm, req, ! write_error);
+	}
+	if (static_ssfdc_debug)
+		printk("\n");
+
+	return ! write_error;
+
+}
+
+
+/***************************************************************************
+	SmartMedia Logical Format Subroutine
+ ***************************************************************************/
+int CheckLogCHS(ssfdc_dev *psm, unsigned int *c,unsigned char *h,unsigned char *s)
+{
+	switch(psm->Model) {
+		case SSFDC1MB:  	*c=125;	*h= 4;	*s= 4;	break;
+		case SSFDC2MB:  	*c=125;	*h= 4;	*s= 8;	break;
+		case SSFDC4MB:  	*c=250;	*h= 4;	*s= 8;	break;
+		case SSFDC8MB:  	*c=250;	*h= 4;	*s=16;	break;
+		case SSFDC16MB: 	*c=500;	*h= 4;	*s=16;	break;
+		case SSFDC32MB: 	*c=500;	*h= 8;	*s=16;	break;
+		case SSFDC64MB: 	*c=500;	*h= 8;	*s=32;	break;
+		case SSFDC128MB:	*c=500;	*h=16;	*s=32;	break;
+		default:
+        	*c= 0; *h= 0; *s= 0;
+			psm->ErrCode=ERR_NoSmartMedia;
+			return(ERROR);
+	}
+	return(SUCCESS);
+}
+/***************************************************************************
+	Power Control & Media Exist Check Subroutine
+ ***************************************************************************/
+
+int CheckMediaWP(ssfdc_dev *psm)
+{
+	if(psm->Attribute &MWP)
+		{ psm->ErrCode=ERR_WrtProtect;	return(ERROR); }
+	return(SUCCESS);
+}
+
+/***************************************************************************
+	SmartMedia Physical Address Control Subroutine
+ ***************************************************************************/
+int ConvMediaAddr(ssfdc_dev *psm, long addr)
+{
+	long temp;
+	temp          =addr/psm->MaxSectors;
+	psm->Sector  =addr%psm->MaxSectors;
+	psm->LogBlock=temp%psm->MaxLogBlocks;
+	psm->Zone    =temp/psm->MaxLogBlocks;
+	if(psm->Zone<psm->MaxZones) {
+		ClrRedundantData(psm->Redundant);
+		SetLogBlockAddr(psm,psm->Redundant);
+		psm->PhyBlock=psm->Log2Phy[psm->Zone][psm->LogBlock];
+#if DEBUG_SSFDC_ASSIGNRELEASE
+		printk(KERN_DEBUG "ConvMediaAddr() LogBlock %d -> PhyBlock %d\n", 
+			psm->LogBlock, psm->PhyBlock);
+#endif
+		return(SUCCESS);
+	}
+	psm->ErrCode=ERR_OutOfLBA;
+	return(ERROR);
+}
+
+int IncMediaAddr(ssfdc_dev *psm)
+{
+	if(++psm->Sector<psm->MaxSectors)
+		return(SUCCESS);
+	psm->Sector=0;
+	if(++psm->LogBlock<psm->MaxLogBlocks) {
+		ClrRedundantData(psm->Redundant);
+		SetLogBlockAddr(psm,psm->Redundant);
+		psm->PhyBlock=psm->Log2Phy[psm->Zone][psm->LogBlock];
+#if DEBUG_SSFDC_ASSIGNRELEASE
+		printk(KERN_DEBUG "IncMediaAddr() PhyBlock %d <- LogBlock %d\n", 
+			psm->PhyBlock, psm->LogBlock);
+#endif
+		return(SUCCESS);
+	}
+	psm->LogBlock=0;
+	if(++psm->Zone<psm->MaxZones) {
+		ClrRedundantData(psm->Redundant);
+		SetLogBlockAddr(psm,psm->Redundant);
+		psm->PhyBlock=psm->Log2Phy[psm->Zone][psm->LogBlock];
+#if DEBUG_SSFDC_ASSIGNRELEASE
+		printk(KERN_DEBUG "IncMediaAddr() PhyBlock %d <- LogBlock %d\n", 
+			psm->PhyBlock, psm->LogBlock);
+#endif
+		return(SUCCESS);
+	}
+	psm->Zone=0;
+	psm->ErrCode=ERR_OutOfLBA;
+	return(ERROR);
+}
+
+/***************************************************************************/
+
+
+static int WriteReqInCurrBlk(ssfdc_dev *psm, long sector, int *blksector)
+{
+	long temp;
+	unsigned char   Zone;         /* Zone Number */
+	unsigned int    LogBlock;     /* Logical Block Number of Zone */
+
+	if (!psm)
+		return 0;
+
+	temp = sector / psm->MaxSectors;
+	*blksector = sector % psm->MaxSectors;
+	LogBlock = temp % psm->MaxLogBlocks;
+	Zone = temp / psm->MaxLogBlocks;
+
+	return (psm->LogBlock == LogBlock && psm->Zone == Zone);
+}
+
+/***************************************************************************
+	SmartMedia Read/Write Subroutine with Retry
+ ***************************************************************************/
+
+/***************************************************************************
+	SmartMedia Physical Block Assign/Release Subroutine
+ ***************************************************************************/
+int AssignWriteBlock(ssfdc_dev *psm, int verbose_flag)
+{
+	psm->ReadBlock=psm->PhyBlock;
+#if DEBUG_SSFDC_WRITE
+	int Zonesave=psm->Zone, ZoneIndex;
+#endif
+
+#if DEBUG_SSFDC_WRITE
+	if (verbose_flag) {
+		printk("AssignWriteBlock() verbose mode. psm->Zone %d\n",psm->Zone);
+		for (psm->Zone = 0; psm->Zone < psm->MaxZones; psm->Zone++) {
+			int free_blk=0;
+			printk("\tZone %d, AssignStart %d and ", psm->Zone, psm->AssignStart[psm->Zone]);
+			for (psm->WriteBlock=0; psm->WriteBlock < psm->MaxLogBlocks; psm->WriteBlock++)
+				if (! ChkBit(psm->Assign[psm->Zone],psm->WriteBlock)) ++free_blk;
+			printk("%d free blocks.\n", free_blk);
+		}
+		psm->Zone = Zonesave;
+	}
+#endif
+	for(psm->WriteBlock=psm->AssignStart[psm->Zone]; psm->WriteBlock<psm->MaxBlocks; psm->WriteBlock++)
+		if(! ChkBit(psm->Assign[psm->Zone],psm->WriteBlock)) {
+			SetBit(psm->Assign[psm->Zone],psm->WriteBlock);
+			psm->AssignStart[psm->Zone]=psm->WriteBlock+1;
+			psm->PhyBlock=psm->WriteBlock;
+			psm->SectCopyMode=REQ_ERASE;
+#if DEBUG_SSFDC_ASSIGNRELEASE
+    printk(KERN_DEBUG "AssignWriteBlock() - WriteBlock %d ReadBlock %d LogBlock %d\n",
+            psm->WriteBlock, psm->ReadBlock, psm->LogBlock);
+#endif
+			return(SUCCESS);
+		} 
+	for(psm->WriteBlock=0; psm->WriteBlock<psm->AssignStart[psm->Zone]; psm->WriteBlock++)
+		if(! ChkBit(psm->Assign[psm->Zone],psm->WriteBlock)) {
+			SetBit(psm->Assign[psm->Zone],psm->WriteBlock);
+			psm->AssignStart[psm->Zone]=psm->WriteBlock+1;
+			psm->PhyBlock=psm->WriteBlock;
+			psm->SectCopyMode=REQ_ERASE;
+#if DEBUG_SSFDC_ASSIGNRELEASE
+    printk(KERN_DEBUG "AssignWriteBlock() - WriteBlock %d PhyBlock %d LogBlock %d\n",
+            psm->WriteBlock, psm->PhyBlock, psm->LogBlock);
+#endif
+			return(SUCCESS);
+		}
+	psm->WriteBlock=NO_ASSIGN;
+	psm->ErrCode=ERR_WriteFault;
+	return(ERROR);
+}
+
+/***************************************************************************
+	SmartMedia Physical Format Check Local Subroutine
+ ***************************************************************************/
+static int SetPhyFmtValue(ssfdc_dev *psm)
+{
+	unsigned int idcode;
+	SsfdcReadID(psm, &idcode);
+	if(SetSsfdcModel(psm,(unsigned char)idcode))
+		return(ERROR);
+	if(CheckSsfdcWP(psm))
+	 	psm->Attribute|=WP;
+	return(SUCCESS);
+}
+
+static int SearchCIS(ssfdc_dev *psm, unsigned int *pcis)
+{
+	psm->Zone=0;	psm->Sector=0;
+	for(psm->PhyBlock=0; psm->PhyBlock<(psm->MaxBlocks-psm->MaxLogBlocks-1); psm->PhyBlock++) {
+		if(SsfdcReadRedtData(psm, psm->Redundant))
+			{ SsfdcReset(psm);	 	return(ERROR); }  
+		if(! CheckFailBlock(psm->Redundant)) {
+			if(CheckCisBlock(psm->Redundant))
+				{ SsfdcReset(psm);	return(ERROR); }  
+			break;
+		}
+	}
+	while(psm->Sector<psm->MaxSectors) {
+		if(psm->Sector)
+			if(SsfdcReadRedtData(psm, psm->Redundant))
+				{ SsfdcReset(psm);	return(ERROR); } 
+		if(! CheckDataStatus(psm->Redundant)) {
+			if(SsfdcReadSect(psm,psm->WorkBuf,psm->Redundant))
+				{ SsfdcReset(psm);	return(ERROR); } 
+			if(CheckCISdata(psm->WorkBuf,psm->Redundant))
+				{ SsfdcReset(psm);	return(ERROR); }
+			*pcis=psm->PhyBlock;
+			SsfdcReset(psm); 
+			return(SUCCESS);
+		}
+		psm->Sector++;
+	}
+	SsfdcReset(psm); 
+	return(ERROR);
+}
+
+/***************************************************************************/
+static int MakeLogTable(ssfdc_dev *psm, unsigned int start)
+{
+	unsigned int block;
+	unsigned int blk_total=0, blk_blank=0, blk_nologaddr=0,
+				 blk_fail=0, blk_assigned=0;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "MakeLogTable()\n");
+#endif
+	psm->DataBuf_Valid = 1;
+	psm->Sector=0;
+	for(psm->Zone=0; psm->Zone<psm->MaxZones; psm->Zone++) {
+		/* set all LogBlocks to NO_ASSIGN */
+		for(psm->LogBlock=0; psm->LogBlock<psm->MaxLogBlocks; psm->LogBlock++)
+			psm->Log2Phy[psm->Zone][psm->LogBlock]=NO_ASSIGN;
+		/* for all Assigns[zone][PhyBlock] = 0x00 */
+		for(psm->PhyBlock=0; psm->PhyBlock<(MAX_BLOCKNUM/8); psm->PhyBlock++)
+			psm->Assign[psm->Zone][psm->PhyBlock]=0x00;
+		/*******************************************************************/
+		for(psm->PhyBlock=0; psm->PhyBlock<psm->MaxBlocks; psm->PhyBlock++) {
+			if((! psm->Zone) && (psm->PhyBlock<start)) {
+				SetBit(psm->Assign[psm->Zone],psm->PhyBlock);
+				continue;
+			}
+			++blk_total;
+			if(SsfdcReadRedtData(psm,psm->Redundant)) {
+				SsfdcReset(psm);  
+#if 0
+				printk(KERN_ERR "error 1 PhyBlock %d\n", psm->PhyBlock); 
+#endif
+				return(ERROR);
+			}
+			if(! CheckDataBlank(psm->Redundant)) {
+				++blk_blank;
+				continue;
+			}
+			SetBit(psm->Assign[psm->Zone],psm->PhyBlock);
+			if(CheckFailBlock(psm->Redundant)) {
+#if 0
+				printk("Zone %d, Block %d failed\n", psm->Zone, psm->PhyBlock);
+#endif
+				++blk_fail;
+				continue;
+			}
+			if(LoadLogBlockAddr(psm)) {
+				++blk_nologaddr;
+				continue;
+			}
+			if(psm->LogBlock>=psm->MaxLogBlocks)
+				continue;
+			++blk_assigned;
+			if(psm->Log2Phy[psm->Zone][psm->LogBlock]==NO_ASSIGN) {
+#if DEBUG_SSFDC_ASSIGNRELEASE
+				if (psm->LogBlock == 0)
+    				printk(KERN_DEBUG "MakeLogTable() LogBlock %d = PhyBlock %d\n",
+            			psm->LogBlock, psm->PhyBlock);
+#endif
+				psm->Log2Phy[psm->Zone][psm->LogBlock]=psm->PhyBlock;
+				continue;
+			}
+			psm->Sector=psm->MaxSectors-1;
+			if(SsfdcReadRedtData(psm,psm->Redundant)) {
+				SsfdcReset(psm); 
+#if 0
+				printk(KERN_ERR "error 2\n"); 
+#endif
+				return(ERROR);
+			}
+			psm->Sector=0;
+			block=psm->LogBlock;
+			if(! LoadLogBlockAddr(psm)) 
+				if(psm->LogBlock==block) {
+#ifdef L2P_ERR_ERASE	/***************************************************/
+					block=psm->Log2Phy[psm->Zone][psm->LogBlock];
+					psm->Log2Phy[psm->Zone][psm->LogBlock]=psm->PhyBlock;
+					psm->PhyBlock=block;
+					if(!(psm->Attribute &MWP)) {
+						SsfdcReset(psm);
+						if(SsfdcEraseBlock(psm)) {
+							printk(KERN_ERR "error 3\n");
+							return(ERROR);
+						}
+						if(SsfdcCheckStatus(psm)) {
+							if(MarkFailPhyOneBlock(psm)) {
+								printk(KERN_ERR "error 4\n");
+								return(ERROR); 
+							}
+						}
+						else ClrBit(psm->Assign[psm->Zone],psm->PhyBlock);
+					}
+					psm->PhyBlock=psm->Log2Phy[psm->Zone][psm->LogBlock];
+#else	/*******************************************************************/
+					psm->Log2Phy[psm->Zone][psm->LogBlock]=psm->PhyBlock;
+#endif	/*******************************************************************/
+					continue;
+				}
+#ifdef L2P_ERR_ERASE	/***************************************************/
+			if(!(psm->Attribute &MWP)) {
+				SsfdcReset(psm);
+				if(SsfdcEraseBlock(psm)) {
+					printk(KERN_ERR "error 5\n"); 
+					return(ERROR);
+				}
+				if(SsfdcCheckStatus(psm)) {
+					if(MarkFailPhyOneBlock(psm)) {
+						printk(KERN_ERR "error 6\n");
+						return(ERROR);
+					}
+				}
+				else ClrBit(psm->Assign[psm->Zone],psm->PhyBlock);
+			}
+#endif	/*******************************************************************/
+		}
+		psm->AssignStart[psm->Zone]=0;
+	}
+	SsfdcReset(psm);
+#if 0
+	printk("MakeLogTable()\n");
+	printk("\t%d failed\n", blk_fail);
+	printk("\t%d blank\n", blk_blank);
+	printk("\t%d assigned\n", blk_assigned);
+	printk("\t%d no logical addr\n", blk_nologaddr);
+	printk("\n\t%d total\n", blk_total);
+	printk("\t%d sum total\n", blk_fail + blk_blank + blk_assigned + blk_nologaddr);
+#endif
+	return(SUCCESS);
+}
+
+/***************************************************************************/
+static int MarkFailPhyOneBlock(ssfdc_dev *psm)
+{
+	unsigned char sect;
+	sect=psm->Sector;
+	SetFailBlock(psm->WorkRedund);
+	SsfdcWriteRedtMode(psm); 
+	for(psm->Sector=0; psm->Sector<psm->MaxSectors; psm->Sector++)
+		if(SsfdcWriteRedtData(psm,psm->WorkRedund)) {
+			SsfdcReset(psm);
+			psm->Sector=sect;
+			psm->ErrCode=ERR_HwError;
+			return(ERROR);
+		}	/* NO Status Check */
+	SsfdcReset(psm);	
+	psm->Sector=sect;
+	return(SUCCESS);
+}
+
+/***************************************************************************
+	SmartMedia Control subroutine
+	Rev 0.30('98-06-30)  ***** BETA RELEASE *****
+	Copyright (c) 1997-98, Toshiba Corporation.  All rights reserved.
+ ***************************************************************************/
+
+
+/* Linux Driver Modifications */
+/*
+dump_ssfdc_state
+*/
+#if DEBUG_SSFDC
+void dump_ssfdc_state(ssfdc_dev * psm)
+{
+#if DEBUG_SSFDC_STRUCT
+	// misc structure dump information
+	printk(KERN_DEBUG "psm->\n");
+	/* unsigned long   */ printk(KERN_DEBUG "\t address %x\n", psm->address);
+    /* int             */ printk(KERN_DEBUG "\t sm_minor %d\n",psm->sm_minor);
+    /* struct dentry   printk(KERN_DEBUG "\t *sm_dentry %x\n",psm->sm_dentry );*/ 
+    /* kdev_t          */ printk(KERN_DEBUG "\t sm_device %x\n",psm->sm_device);
+    /* int             */ printk(KERN_DEBUG "\t sm_flags %x\n",psm->sm_flags);
+    /* unsigned int    */ printk(KERN_DEBUG "\t UseCount %d\n",psm->UseCount);
+    /* unsigned int    */ printk(KERN_DEBUG "\t ErrCode %d\n",psm->ErrCode);
+    /* unsigned int    */ printk(KERN_DEBUG "\t MediaChange %d\n",psm->MediaChange);
+    /* unsigned int    */ printk(KERN_DEBUG "\t SectCopyMode %d\n",psm->SectCopyMode);                                                                              
+    /* unsigned int    */ printk(KERN_DEBUG "\t HostCyl %d\n",psm->HostCyl );
+    /* unsigned char   */ printk(KERN_DEBUG "\t HostHead %d\n",psm->HostHead );
+    /* unsigned char   */ printk(KERN_DEBUG "\t HostSect %d\n",psm->HostSect );
+    /* unsigned int  */ printk(KERN_DEBUG "\t ReadBlock %d\n",psm->ReadBlock );
+    /* unsigned int  */ printk(KERN_DEBUG "\t WriteBlock %d\n",psm->WriteBlock );
+ 
+    /* Card attributes */
+    /* unsigned char */ printk(KERN_DEBUG "\t Model %d\n",psm->Model );
+    /* unsigned char */ printk(KERN_DEBUG "\t Attribute %x\n",psm->Attribute );
+    /* unsigned char */ printk(KERN_DEBUG "\t MaxZones %d\n",psm->MaxZones );
+    /* unsigned char */ printk(KERN_DEBUG "\t MaxSectors %d\n",psm->MaxSectors );
+    /* unsigned int  */ printk(KERN_DEBUG "\t MaxBlocks %d\n",psm->MaxBlocks );
+    /* unsigned int  */ printk(KERN_DEBUG "\t MaxLogBlocks %d\n",psm->MaxLogBlocks );
+    /* unsigned char */ printk(KERN_DEBUG "\t Zone %d\n",psm->Zone );
+    /* unsigned char */ printk(KERN_DEBUG "\t Sector %d\n",psm->Sector );
+    /* unsigned int  */ printk(KERN_DEBUG "\t PhyBlock %d\n",psm->PhyBlock );
+    /* unsigned int  */ printk(KERN_DEBUG "\t LogBlock %d\n",psm->LogBlock );
+#endif
+}
+#endif
+
+typedef struct {
+	int sm_error;
+	int lnx_error;
+	char *smerrstr;
+} errmap;
+
+static errmap error_map_table [] = {
+	{ NO_ERROR,	0x0000, ""},
+	{ ERR_WriteFault,	EIO, "Peripheral Device Write Fault	"},
+	{ ERR_HwError,	EIO, "Hardware Error"},
+	{ ERR_DataStatus,	EIO, "DataStatus Error"},
+	{ ERR_EccReadErr, EIO, "Unrecovered Read Error" },
+	{ ERR_CorReadErr, EIO, "Recovered Read Data with ECC" },
+	{ ERR_OutOfLBA, EIO, "Illegal Logical Block Address" },
+	{ ERR_WrtProtect, EROFS, "Write Protected" },
+	{ ERR_ChangedMedia, EIO, "Medium Changed" },
+	{ ERR_UnknownMedia, EIO, "Incompatible Medium Installed" },
+	{ ERR_IllegalFmt, EIO, "Medium Format Corrupted" },
+	{ ERR_NoSmartMedia, EIO, "Medium Not Present" } 
+};
+
+static int ssfdc_maperror(int ssfdc_error) {
+	int loopus=0;
+
+	if (!ssfdc_error) return 0;
+
+	do {
+		if (error_map_table[loopus].sm_error == ssfdc_error) {
+			printk("%s\n", error_map_table[loopus].smerrstr);
+			return -error_map_table[loopus].lnx_error;
+		}
+	} while (++loopus < (sizeof(error_map_table) / (sizeof(errmap))));
+
+	printk(KERN_ERR "%s: error code %d is not mapped, EIO\n", MAJOR_NAME, ssfdc_error);
+	return -EIO;
+}
+
+static int ssfdc_thread(void * arg)
+{
+	ssfdc_dev *psm = arg;
+	unsigned long flags;
+
+	daemonize("sm%dd",psm->sm_minor);
+
+	spin_lock_irqsave(&current->sighand->siglock,flags); // _irq
+	sigfillset(&current->blocked);
+	recalc_sigpending();
+	spin_unlock_irqrestore(&current->sighand->siglock,flags); // _irq
+
+	while (!psm->exiting) {
+		if ( ssfdc_get_request(psm) )
+			initxfer(psm->sm_minor);
+
+		spin_lock_irqsave(&psm->req_queue_lock,flags); // _irq
+		// bjm spin_lock(&psm->req_queue_lock); // _irq
+		psm->waiting = 0;
+		spin_unlock_irqrestore(&psm->req_queue_lock,flags); // _irq
+		// bjm spin_unlock(&psm->req_queue_lock); // _irq
+		if (wait_event_interruptible(psm->thread_wq,ssfdc_get_request(psm)))
+			printk("ssfdc_thread() interrupted\n");
+		// wait_event(psm->thread_wq,ssfdc_get_request(psm));
+		spin_lock_irqsave(&psm->req_queue_lock,flags); // _irq
+		// bjm spin_lock(&psm->req_queue_lock); // _irq
+		psm->waiting = 1;
+		spin_unlock_irqrestore(&psm->req_queue_lock,flags); // _irq
+		// bjm spin_unlock(&psm->req_queue_lock); // _irq
+	}
+
+	printk("ssfdcd Exiting!\n");
+
+	complete_and_exit(&psm->thread_dead, 0);
+
+}
+
+/*
+ssfdc_init_device(ssfdc_dev *, int minor, unsigned long baseaddr, int removable)
+	reset and initialize the ssfdc_dev structure
+*/
+static int ssfdc_init_device(ssfdc_dev *psm, int minor, unsigned long baseaddr)
+{
+	int pid;
+
+	// Establish ssfdc state
+	psm->XferState = xfer_idle;
+	psm->ErrCode = NO_ERROR;
+	psm->MediaChange = SUCCESS;
+	psm->SectCopyMode = COMPLETED;
+	psm->UseCount = 0; 
+	psm->DataBuf_Valid = 0;
+
+	// set minor number
+	psm->sm_minor = minor;
+	// io address
+	psm->address = baseaddr;
+	if (!request_region(psm->address, 3, "sm")) {
+		printk(KERN_ERR "sm: memory already in use!\n");
+		return ERROR;
+	}
+	spin_lock_init(&psm->req_queue_lock);
+
+	// thread related inititializations...
+	init_completion(&psm->thread_dead);
+	init_waitqueue_head(&psm->thread_wq);
+
+	pid = kernel_thread(ssfdc_thread, psm, CLONE_KERNEL);
+	if (pid < 0)
+		printk("ssfdc: ERROR starting thread!\n");
+	else
+		printk("ssfdc: started kernel thread sm%dd pid %d\n", psm->sm_minor, pid);
+
+	// switch on power to device, and set basic attributes of card (no logical to phys mapping)
+	if ( ! CntPowerOn(psm) && ! CheckCardExist(psm) ) {
+		SetPhyFmtValue(psm);
+	}
+	else {
+		printk(KERN_ERR "ssfdc_init_device() unable to SetPhyFmtValue()\n");
+	}
+
+#if DEBUG_SSFDC
+	dump_ssfdc_state(psm);
+#endif
+
+	return SUCCESS;
+}
+
+static int ssfdc_dev_blk_size(ssfdc_dev *psm)
+{
+	if (!psm)
+		return 0;
+
+	// because of the physical to logical block mapping, not as many blocks
+	// as expected...
+	switch(psm->Model) {
+		case SSFDC1MB:
+			return (250 * 8 * 512) / SSFDC_BLKSIZE;
+		case SSFDC2MB:
+			return (500 * 8 * 512) / SSFDC_BLKSIZE;
+		case SSFDC4MB:
+			return (500 * 16 * 512) / SSFDC_BLKSIZE;
+		case SSFDC8MB:
+			return (1000 * 16 * 512) / SSFDC_BLKSIZE;
+		case SSFDC16MB:
+			return (1000 * 32 * 512) / SSFDC_BLKSIZE;
+		case SSFDC32MB:
+			return (2000 * 32 * 512) / SSFDC_BLKSIZE;
+		case SSFDC64MB:
+			return (4000 * 32 * 512) / SSFDC_BLKSIZE;
+		case SSFDC128MB:
+			return (8000 * 32 * 512) / SSFDC_BLKSIZE;
+		default:
+			return 0;
+	}
+}
+
+inline int ssfdc_dev_sectors(ssfdc_dev *psm) {
+	return ssfdc_dev_blk_size(psm) * (SSFDC_BLKSIZE/SSFDC_SECTSIZE);
+}
+
+static int ssfdc_open(struct inode *in, struct file *fptr) 
+{ 
+	int error_code=NO_ERROR;
+	ssfdc_dev *psm = in->i_bdev->bd_disk->private_data;
+	unsigned long flags;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "+ssfdc_open()\n");
+#endif
+
+	if (!fptr) {
+		return -EIO;
+	}
+
+	spin_lock_irqsave(&psm->req_queue_lock,flags);
+	// bjm spin_lock(&psm->req_queue_lock);
+	// Power up smartmedia device, check for card, check media
+	if ((error_code=CntPowerOn(psm))) {
+		printk(KERN_ERR "%s PowerUP error\n", MAJOR_NAME);
+	}
+	else if ((error_code=CheckCardExist(psm))) {// Check the existence of a card
+		printk(KERN_ERR "%s No Card!\n", MAJOR_NAME);
+	}
+	else if ( ! psm->UseCount++ ) {
+		spin_unlock_irqrestore(&psm->req_queue_lock,flags);
+		// bjm spin_unlock(&psm->req_queue_lock);
+		check_disk_change(in->i_bdev);
+		spin_lock_irqsave(&psm->req_queue_lock,flags);
+		// bjm spin_lock(&psm->req_queue_lock);
+	}
+
+	if ( ! psm->ErrCode ) {
+		// check our open mode against that of removable media's
+		if (WRITE_PROTECTED(psm)) {
+			printk(KERN_ERR "mount read only detected.\n");
+		}
+	}
+
+#if DEBUG_SSFDC
+	dump_ssfdc_state(psm);
+    printk(KERN_DEBUG "-ssfdc_open() error_code %d\n", error_code);
+#endif
+
+	spin_unlock_irqrestore(&psm->req_queue_lock,flags);
+
+#if DEBUG_SSFDC
+	printk("-ssfdc_open()\n");
+#endif
+
+	return ssfdc_maperror(error_code);
+}
+
+static int ssfdc_release(struct inode *i_node, struct file *fptr)
+{
+	int drive;
+    ssfdc_dev *psm=NULL;
+	unsigned long flags;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "+ssfdc_release("); 
+#endif
+
+	psm = (ssfdc_dev *) i_node->i_bdev->bd_disk->private_data;
+	drive = psm->sm_minor;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "%d)\n", drive); 
+#endif
+	if (drive < 0 || drive >= MAX_SSFDC)
+        	return -ENODEV;
+  
+	spin_lock_irqsave(&psm->req_queue_lock,flags);
+	// bjm spin_lock(&psm->req_queue_lock);
+
+	if (!psm->UseCount)
+		printk(KERN_ERR "sm: Zero use count!\n");
+	else {
+		--psm->UseCount;
+	}
+
+#if DEBUG_SSFDC
+	dump_ssfdc_state(psm);
+#endif
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "-ssfdc_release()\n");
+#endif
+
+	spin_unlock_irqrestore(&psm->req_queue_lock,flags);
+	// bjm spin_unlock(&psm->req_queue_lock);
+
+	return 0;
+}
+
+static int ssfdc_ioctl(struct inode *i_node, struct file *fptr, unsigned cmd, unsigned long arg)
+{
+	int drive, int_val;
+	ssfdc_dev *psm;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "ssfdc_ioctl(%d)", cmd);
+#endif
+
+	if (i_node == NULL)
+		return -EINVAL;
+
+	psm = (ssfdc_dev *) i_node->i_bdev->bd_disk->private_data;
+ 	drive = psm->sm_minor;
+	
+	if (drive < 0 || drive >= MAX_SSFDC)
+        	return -ENODEV;                                                                         
+	switch(cmd) {
+		case BLKROSET: /* set device read-only (0 = read-write) */
+			if (!capable(CAP_SYS_ADMIN))
+				return -EACCES;
+			if (copy_from_user((void *) &int_val, (int *)arg, sizeof(int_val)))
+				return -EFAULT;
+			if (int_val)
+				psm->Attribute |= MWP;
+			else
+				psm->Attribute &= ~MWP;
+			return 0;
+			
+		case BLKROGET:/* get read-only status (0 = read_write) */
+			int_val = psm->Attribute & MWP;
+			copy_to_user(arg, (void *) &int_val, sizeof(int_val));
+			return 0;
+
+		/* case BLKRRPART: */		/* re-read partition table */
+
+		case BLKGETSIZE:
+#if DEBUG_SSFDC
+			printk(KERN_DEBUG "BLKGETSIZE");
+#else
+			printk(KERN_DEBUG "ssfdc_ioctl(BLKGETSIZE) not handled.\n");
+#endif
+			break;
+	}
+	return -EINVAL;
+}
+
+
+static int ssfdc_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+	unsigned char heads, sectors;
+	unsigned int cylinders;
+	struct gendisk *disk = bdev->bd_disk;
+	ssfdc_dev *psm = disk->private_data;
+	int drive = psm->sm_minor;
+	int err;
+
+	if (drive < 0 || drive >= MAX_SSFDC)
+        	return -ENODEV;                                                                         
+
+	err = CheckLogCHS(psm, &cylinders, &heads, &sectors);
+	if (err)
+		return ssfdc_maperror(err);
+	
+	geo->heads = heads;
+	geo->sectors = sectors;
+	geo->cylinders = cylinders;
+	return 0;
+}
+
+
+static int ssfdc_revalidate(struct gendisk *disk)
+{
+    unsigned int cis;
+    ssfdc_dev *psm=NULL;
+    int error_code=NO_ERROR;
+	unsigned long flags;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "ssfdc_revalidate()\n");
+#endif
+
+	psm = disk->private_data;
+
+	spin_lock_irqsave(&psm->req_queue_lock,flags);
+	// bjm spin_lock(&psm->req_queue_lock);
+
+	if ( ! psm->DataBuf_Valid ) {
+		if ((error_code=SetPhyFmtValue(psm)))
+			printk(KERN_ERR "ssfdc_revalidate() SetPhyFmtValue error\n");
+		else if ((error_code=SearchCIS(psm,&cis)))
+			printk(KERN_ERR "ssfdc_revalidate() SearchCIS error\n");
+		else if ((error_code=MakeLogTable(psm,cis+1)))
+			printk(KERN_ERR "ssfdc_revalidate() MakeLogTable error\n");
+	}
+	spin_unlock_irqrestore(&psm->req_queue_lock,flags); 
+	// bjm spin_unlock(&psm->req_queue_lock); 
+
+	return ssfdc_maperror(error_code);
+}
+
+int __init ssfdc_init(void)
+{
+	int i;
+	int err = 0;
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "+ssfdc_init()\n");
+#endif
+
+	memset(disks, 0, sizeof(struct gendisk *) * MAX_SSFDC);
+	memset(ssfdc, 0, sizeof(struct ssfdc_dev *) * MAX_SSFDC);
+	for (i=0; i<MAX_SSFDC; ++i) {
+		disks[i] = alloc_disk(1 << SSFDC_PARTN_BITS);
+		ssfdc[i] = kmalloc(sizeof(ssfdc_dev), GFP_KERNEL);
+		if (!disks[i]  || !ssfdc[i]) {
+			err = -ENOMEM; 
+			goto no_memory_error;
+		}
+		memset( ssfdc[i], 0, sizeof(ssfdc_dev));
+	}
+
+	if (register_blkdev(SSFDC_MAJOR, "smartmedia")) {
+		printk(KERN_ERR "Unable to get major number %d for ssfdc device\n", 
+                       SSFDC_MAJOR);
+                err = -EBUSY;
+		goto busy_error;
+	}
+
+	devfs_mk_dir("sm");
+
+	for ( i=0; i < MAX_SSFDC; ++i) {
+		disks[i]->major = SSFDC_MAJOR;
+		disks[i]->first_minor = i << SSFDC_PARTN_BITS;
+		disks[i]->fops = &ssfdc_fops;
+		sprintf(disks[i]->disk_name, "sm%d", i);
+		sprintf(disks[i]->devfs_name, "sm/%d", i);
+		disks[i]->private_data = ssfdc[i];
+		ssfdc_init_device(ssfdc[i], i << SSFDC_PARTN_BITS,
+			CPLD_BASE_ADDRESS + SMART_MEDIA_ONE_OFFSET);
+
+		disks[i]->queue = ssfdc[i]->req_queue = 
+					blk_init_queue(do_ssfdc_request, &ssfdc[i]->req_queue_lock);
+		ssfdc[i]->req_queue->queuedata = ssfdc[i];
+
+		set_capacity(disks[i], ssfdc_dev_sectors(ssfdc[i]));
+		// bjm blk_queue_max_sectors(disks[i]->queue, 32);
+		// bjm blk_queue_max_phys_segments(disks[i]->queue, 4);
+		blk_queue_max_segment_size(disks[i]->queue, (ssfdc[i]->MaxSectors / 2) * K_BYTE);
+		add_disk(disks[i]);
+	}
+
+#if 0	// bjm debug
+#ifndef CONFIG_SH_NIMBLE_MINI
+	mediachangetest(0L);
+#else
+	mediachangetest(1L);
+#endif
+#endif	// bjm debug
+
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "-ssfdc_init(0)\n");
+#endif
+	return 0;
+
+busy_error:
+no_memory_error:
+	for (i=0; i < MAX_SSFDC; ++i) {
+		if (disks[i] && disks[i]->queue)
+			kfree(disks[i]->queue);
+		put_disk(disks[i]);
+		if (ssfdc[i])
+			kfree(ssfdc[i]);
+	}
+#if DEBUG_SSFDC
+	printk(KERN_DEBUG "-ssfdc_init(%d)\n", -ENOMEM);
+#endif
+	return -ENOMEM;
+}
+
+void __init ssfdc_clean(void)
+{
+	int i;
+
+	printk(KERN_DEBUG "SSFDC exit code\n");
+
+	for (i=0; i < MAX_SSFDC; ++i) {
+		if (disks[i] != NULL) {
+			blk_cleanup_queue(disks[i]->queue);
+			del_gendisk(disks[i]);
+			put_disk(disks[i]);
+		}
+
+		if (ssfdc[i]) {
+			// signal thread to exit...
+			ssfdc[i]->exiting = 1;
+			wake_up(&ssfdc[i]->thread_wq);
+			wait_for_completion(&ssfdc[i]->thread_dead);
+
+			if (ssfdc[i]->address)
+				release_region(ssfdc[i]->address, 3);
+			kfree(ssfdc[i]);
+		}
+	}
+
+	if (unregister_blkdev(SSFDC_MAJOR, "smartmedia"))
+		printk(KERN_WARNING "smartmedia: cannot unregister blkdev\n");
+	devfs_remove("sm");
+}
+
+#if DEBUG_SSFDC
+void dump_request(struct request *req)
+{
+#if DEBUG_SSFDC_REQUEST && DEBUG_SSFDC_REQUEST
+	printk(KERN_DEBUG "req->\n");
+	/* int */	printk(KERN_DEBUG "\t req->cmd %x\n", req->cmd);		/* READ or WRITE */
+	/* int errors */	printk(KERN_DEBUG "\t req->errors %d\n", req->errors);
+	/* unsigned long */	printk(KERN_DEBUG "\t req->sector %d\n", req->sector);
+	/* unsigned long */	printk(KERN_DEBUG "\t req->nr_sectors %d\n",req->nr_sectors);
+	/* unsigned long */	printk(KERN_DEBUG "\t req->hard_sector %d\n", req->hard_sector);
+	/* unsigned int */	printk(KERN_DEBUG "\t req->nr_hw_segments %d\n",req->nr_hw_segments);
+	/* unsigned long */	printk(KERN_DEBUG "\t req->current_nr_sectors %d\n",req->current_nr_sectors);
+
+#endif
+}
+#endif
+
+void do_ssfdc_request(request_queue_t * rq)
+{
+	ssfdc_dev *psm = rq->queuedata;
+
+	if ( ! psm->waiting )
+		wake_up(&psm->thread_wq);
+}
+
+static struct request * ssfdc_get_request(ssfdc_dev *psm)
+{
+	struct request *treq;
+	unsigned long flags;
+
+	spin_lock_irqsave(&psm->req_queue_lock, flags);
+	// bjm spin_lock(&psm->req_queue_lock);
+	treq = elv_next_request(psm->req_queue);
+	spin_unlock_irqrestore(&psm->req_queue_lock, flags);
+	// bjm spin_unlock(&psm->req_queue_lock);
+	
+	return treq;
+}
+
+static void ssfdc_terminate_request(ssfdc_dev *psm, struct request *req)
+{
+	unsigned long flags;
+
+	if (psm && req) {
+		spin_lock_irqsave(&psm->req_queue_lock, flags);
+		// bjm spin_lock(&psm->req_queue_lock);
+		end_request(req,0);
+		spin_unlock_irqrestore(&psm->req_queue_lock, flags);
+		// bjm spin_unlock(&psm->req_queue_lock);
+	}
+}
+
+
+static int ssfdc_end_request(ssfdc_dev *psm, struct request *req, int status)
+{
+	unsigned long flags;
+
+	if (!psm || !req) {
+		printk(KERN_DEBUG "ssfdc_end_request() NULL psm or req!\n");
+		return 0;
+	}
+
+#if DEBUG_SSFDC_REQUEST
+	printk("ssfdc_end_request(%p)\n", req);
+#endif
+
+	spin_lock_irqsave(&psm->req_queue_lock,flags);
+	// bjm spin_lock(&psm->req_queue_lock);
+	end_request(req,status);
+	spin_unlock_irqrestore(&psm->req_queue_lock,flags);
+	// bjm spin_unlock(&psm->req_queue_lock);
+    return 0;
+}
+
+void initxfer(unsigned long dev_idx)
+{
+	ssfdc_dev *psm = ssfdc[dev_idx];
+	struct request *req;
+	int error_code;
+	unsigned int cis;
+
+#if	DEBUG_SSFDC
+	// printk(KERN_DEBUG "+initxfer(%d)", dev_idx);
+#endif
+	// get device lock, and check idle flag, setting if not busy
+
+	req = ssfdc_get_request(psm);
+
+	// if the device is idle, setup a read or write operation
+	if (psm->XferState == xfer_idle) {
+		// get the current request from our device's request list.
+		if (!req) {
+#if DEBUG_SSFDC
+//			printk(KERN_DEBUG "initxfer() terminate, no schedule.\n");
+#endif
+		}
+		// Absence of power indicates absence of card.
+		// terminate request and exit...
+		if ( ! _HwChkPower(psm) ) {
+			printk(KERN_DEBUG "initxfer() - Media power NOT!\n");
+			ssfdc_terminate_request(psm,req);
+			return;
+		}
+
+		// We have a request and we have a card.  Is the Log2Phys mapping still valid?
+		if ( ! psm->DataBuf_Valid ) {
+			if ((error_code = SetPhyFmtValue(psm)))
+				printk(KERN_DEBUG "%s SetPhyFmtValue error\n", MAJOR_NAME);
+			else if ((error_code = SearchCIS(psm,&cis)))
+				printk(KERN_DEBUG "%s SearchCIS error\n", MAJOR_NAME);
+			else if ((error_code = MakeLogTable(psm,cis+1)))
+				printk(KERN_DEBUG "%s MakeLogTable error\n", MAJOR_NAME);
+			if (error_code) {
+				printk(KERN_DEBUG "%s error %d\n", MAJOR_NAME, error_code);
+				ssfdc_terminate_request(psm,req);
+				return;
+			}
+		}
+
+		psm->XferState = xfer_busy;
+#if DEBUG_SSFDC
+		printk(KERN_DEBUG " initxfer() - do the request %x\n", req);
+#endif
+		ssfdc_rw_request(psm, req); 
+	}
+#if DEBUG_SSFDC
+	else {
+		printk(KERN_DEBUG "initxfer(%d) dev is busy, no reschedule.\n", dev_idx);
+	}
+#endif
+
+}
+
+
+void ssfdc_rw_request(ssfdc_dev *psm, struct request *req)
+{
+	int (*rwsector)(ssfdc_dev *, struct request *, char *, long, int);
+	unsigned sector, count;
+	int rw_return=1;
+
+	if (rq_data_dir(req) == WRITE)
+		rwsector = MediaWriteSector;
+	else if (rq_data_dir(req) == READ)
+		rwsector = MediaReadSector;
+	else {
+		printk(KERN_DEBUG "%s: command %d not implemented!\n", MAJOR_NAME, (int) rq_data_dir(req));
+		goto terminal_error;
+	}
+
+	/*
+	*/
+	sector = req->sector;
+	count = req->nr_sectors;
+
+	// check that the request does not extend past ssfdc's max size
+	if ( (sector + count) > ssfdc_dev_sectors(psm) ) {
+		printk(KERN_ERR "Attempt to read past end of device!");
+		goto terminal_error;
+	}
+	else {
+
+		// for each segment in each bio_vec R/W from/to device.
+
+		count = req->current_nr_sectors;
+		rw_return = rwsector(psm, req, req->buffer, sector, count);
+
+		if (rq_data_dir(req) == READ)
+			ssfdc_end_request(psm, req, rw_return);
+	}
+
+	// things appear OK...
+	return;
+
+terminal_error:
+	ssfdc_terminate_request( psm, req);
+	psm->XferState = xfer_idle;
+}
+
+module_init(ssfdc_init);
+module_exit(ssfdc_clean);
+
+MODULE_LICENSE("GPL");
+
+/* End of Linux Driver Modifications */
diff -duNr linux-2.6.16-orig/drivers/block/ssfdc.h linux-2.6.16/drivers/block/ssfdc.h
--- linux-2.6.16-orig/drivers/block/ssfdc.h	1970-01-01 10:00:00.000000000 +1000
+++ linux-2.6.16/drivers/block/ssfdc.h	2006-06-29 16:13:27.000000000 +1000
@@ -0,0 +1,372 @@
+/* $id:   $ */
+#ifndef _SSFDC_H
+#define _SSFDC_H
+
+/*
+	Linux related defines
+*/
+
+#ifdef CONFIG_SH_NIMBLE_MINI
+#define MAX_SSFDC	2		/* two drives */
+#else
+#define MAX_SSFDC	1		/* only one drive */
+#endif
+
+#define SSFDC_MAJOR_NAME  "sm"   
+#define MAJOR_NAME  SSFDC_MAJOR_NAME
+#define SSFDC_PARTN_BITS  4   /* number of minor dev bits for partitions */
+#define PARTN_MASK  ((1<<SSFDC_PARTN_BITS)-1) /* a useful bit mask */
+#define MAX_DRIVES  MAX_SSFDC
+
+/***************************************************************************
+	SmartMedia Controll Header
+	Rev 0.30('98-06-30)  ***** BETA RELEASE *****
+	Copyright (c) 1997-98, Toshiba Corporation.  All rights reserved.
+ ***************************************************************************/
+
+/***************************************************************************
+	Define Difinetion
+ ***************************************************************************/
+#define	SUCCESS			 0			/* SUCCESS     */
+#define	ERROR 			-1			/* ERROR       */
+#define	CORRECT 		 1			/* CORRECTABLE */
+
+/***************************************************************************/
+#define	NO_ERROR			0x0000	/* NO ERROR							   */
+#define	ERR_WriteFault		0x0003	/* Peripheral Device Write Fault	   */
+#define	ERR_HwError   		0x0004	/* Hardware Error					   */
+#define	ERR_DataStatus		0x0010	/* DataStatus Error					   */
+#define	ERR_EccReadErr		0x0011	/* Unrecovered Read Error			   */
+#define	ERR_CorReadErr		0x0018	/* Recovered Read Data with ECC		   */
+#define	ERR_OutOfLBA  		0x0021	/* Illegal Logical Block Address	   */
+#define	ERR_WrtProtect		0x0027	/* Write Protected					   */
+#define	ERR_ChangedMedia	0x0028	/* Medium Changed					   */
+#define	ERR_UnknownMedia	0x0030	/* Incompatible Medium Installed	   */
+#define	ERR_IllegalFmt		0x0031	/* Medium Format Corrupted			   */
+#define	ERR_NoSmartMedia	0x003A	/* Medium Not Present				   */
+
+/***************************************************************************
+	Common Controll Header
+	Rev 1.30('98-06-30)  ***** BETA RELEASE *****
+	Copyright (c) 1997-98, Toshiba Corporation.  All rights reserved.
+ ***************************************************************************/
+
+/***************************************************************************
+	SmartMedia Controller Definition
+ ***************************************************************************/
+/* I/O Mode Address */
+#define	DATA(p)		(p->address+0x00)	/* R/W	Data Reg */
+#define	STATUS(p)		(p->address+0x02)	/* R/-	Status Reg */
+#define	MODE(p)		(p->address+0x02)	/* -/W	Mode Reg */
+
+/* Controller Status Reg (Read Only) */
+#define	STS_BUSY	0x80
+#define	STS_VCC		0x10
+#define	STS_SCHG	0x08
+#define	STS_WP		0x01
+#define	STS_CENB	0x04
+
+#ifdef CONFIG_SH_TITAN
+/* Controller Mode Reg (Write Only) */
+/* keep PCI clock running on bit 3 */
+/* CE# on bit 2, CLE on bit 1 and ALE on bit 0 */
+#define	STANDBY		(0x00 | 0x00 | 0x08)
+#define	WR_DATA		(0x00 | 0x04 | 0x08)
+#define	WR_CMD		(0x02 | 0x04 | 0x08)
+#define	WR_ADR		(0x01 | 0x04 | 0x08)
+#else
+/* Controller Mode Reg (Write Only) */
+#define	STANDBY		0x00
+#define	WR_DATA		0x10
+#define	WR_CMD		0x11
+#define	WR_ADR		0x12
+#define	PW_OFF		0x80
+#define	PW_ON		0x88
+#endif
+
+/***************************************************************************/
+#define	_HwSetData(p) 		ctrl_outb(WR_DATA,MODE(p))
+#define	_HwSetCmd(p)		ctrl_outb(WR_CMD,MODE(p))
+#define	_HwSetAddr(p)		ctrl_outb(WR_ADR,MODE(p))
+#define	_HwSetStandby(p)	ctrl_outb(STANDBY,MODE(p))
+
+#define _HwInData(p)        ctrl_inb(DATA(p))
+#define	_HwOutData(p,a)		ctrl_outb((a),DATA(p))
+
+#ifdef	CONFIG_SH_TITAN
+#define	_HwVccOn(p)	
+#define	_HwVccOff(p)
+#else
+#define	_HwVccOn(p)			ctrl_outb(PW_ON,MODE(p))
+#define	_HwVccOff(p)		ctrl_outb(PW_OFF,MODE(p))
+#endif
+
+#ifdef CONFIG_SH_TITAN
+#define _HwChkCardIn(p)		(1)
+#define _HwChkStatus(p)		(0)
+#define _HwChkWP(p)		(0)
+#define _HwChkPower(p)		(1)
+#define _HwChkBusy(p)		(ctrl_inb(STATUS(p))&STS_BUSY)
+
+#else
+
+#define	_HwChkCardIn(p)		(ctrl_inb(STATUS(p))&STS_CENB)
+#define	_HwChkStatus(p)		(ctrl_inb(STATUS(p))&(STS_SCHG))
+#define	_HwChkWP(p)			(ctrl_inb(STATUS(p))&(STS_WP))
+#define	_HwChkPower(p)		(ctrl_inb(STATUS(p))&(STS_VCC))
+#define	_HwChkBusy(p)		(ctrl_inb(STATUS(p))&STS_BUSY)
+
+#endif
+
+#define	_HwRdStatus(p)		(ctrl_inb(STATUS(p)))
+/***************************************************************************/
+#ifdef CONFIG_SH_NIMBLE_MINI
+#define CPLD_BASE_ADDRESS		0xB4030000L
+#define SMART_MEDIA_ONE_OFFSET		0x08	// The "built-in" SmartMedia
+#define SMART_MEDIA_TWO_OFFSET		0x00	// The "removable" SmartMedia
+#elif CONFIG_SH_TITAN
+#define CPLD_BASE_ADDRESS		0xA4000000L
+#define SMART_MEDIA_ONE_OFFSET		0x00
+#else
+#define CPLD_BASE_ADDRESS		0xB8030000L
+#define SMART_MEDIA_ONE_OFFSET      	0x00    // The "built-in" SmartMedia
+#endif
+
+/***************************************************************************
+	Program & Macro for SmartMedia Controller
+	Rev 0.30('98-06-30)  ***** BETA RELEASE *****
+	Copyright (c) 1997-98, Toshiba Corporation.  All rights reserved.
+ ***************************************************************************/
+/***************************************************************************
+	Define Definition
+ ***************************************************************************/
+#define	K_BYTE				1024	/* Kilo Byte */
+#define	SSFDC_SECTSIZE 		512		/* Sector buffer size */
+#define SSFDC_BLKSIZE		(K_BYTE * 4)
+#define	REDTSIZE			16		/* Redundant buffer size */
+
+/***************************************************************************/
+#define	DUMMY_DATA		0xFF	/* No Assign Sector Read Data */
+
+/***************************************************************************
+	Max Zone/Block/Sectors Data Definition
+ ***************************************************************************/
+#define	MAX_ZONENUM		0x08	/* Max Zone Numbers in a SmartMedia */
+#define	MAX_BLOCKNUM	0x0400	/* Max Block Numbers in a Zone */
+#define	MAX_SECTNUM		0x20	/* Max Sector Numbers in a Block */
+#define	MAX_LOGBLOCK	1000	/* Max Logical Block Numbers in a Zone */
+
+/***************************************************************************
+	Logical to Physical Block Table Data Definition
+ ***************************************************************************/
+#define	NO_ASSIGN		0xFFFF	/* No Assign Logical Block Address */
+
+/***************************************************************************
+	'SectCopyMode' Data
+ ***************************************************************************/
+#define	COMPLETED		 0			/* Sector Copy Completed     */
+#define	REQ_ERASE		 1			/* Request Read Block Erase  */
+#define	REQ_FAIL		 2			/* Request Read Block Failed */
+
+/***************************************************************************
+	Retry Counter Definition
+ ***************************************************************************/
+#define	RDERR_REASSIGN	1		/* Reassign with Read Error */
+#define	L2P_ERR_ERASE	1		/* BlockErase for Contradicted L2P Table */
+
+/***************************************************************************
+	SmartMedia Command & Status Definition
+ ***************************************************************************/
+/* SmartMedia Command */
+#define	SSFDC_WRDATA		0x80
+#define	SSFDC_READ			0x00
+#define	SSFDC_READ_REDT		0x50
+#define	SSFDC_READ1			0x00
+#define	SSFDC_READ2			0x01
+#define	SSFDC_READ3			0x50
+#define	SSFDC_RST_CHIP		0xFF
+#define	SSFDC_WRITE			0x10
+#define	SSFDC_DUMMY_WRITE	0x11
+#define SSFDC_MULTI_WRITE   0x15
+#define	SSFDC_ERASE1		0x60
+#define	SSFDC_ERASE2		0xD0
+#define	SSFDC_RDSTATUS		0x70
+#define	SSFDC_READ_ID		0x90
+
+/* SmartMedia Status */
+#define	WR_FAIL		0x01	/* 0:Pass,          1:Fail */
+#define	SUSPENDED	0x20	/* 0:Not Suspended, 1:Suspended */
+#define	READY		0x40	/* 0:Busy,          1:Ready */
+#define	WR_PRTCT	0x80	/* 0:Protect,       1:Not Protect */
+
+#define USEC		1
+#define	MSEC		1000 * USEC
+#define JIFFY_TICK_MS	(MSEC / HZ)
+
+// #define	BUSY_PROG	20 * MSEC	/* 200-1000us -----	Program Time */
+#define	BUSY_PROG	1000 * USEC	/* 200-1000us -----	Program Time */
+#define BUSY_DUMMY_WRITE	10 * USEC	/*	2-10us	dummy write */
+#define BUSY_MULTI_WRITE	1000 * USEC	/*	200 - 1000 usec */
+#define	BUSY_ERASE	10 * MSEC	/* 2-10ms -----	Block Erase Time */
+#define	BUSY_READ	100 * USEC	/* tR     : 100us -----	Data transfer Time */
+#define	BUSY_RESET	10 * USEC	/* tRST   :   10us -----	Device Resetting Time  */
+#define BUSY_ADDR_SET	25 * USEC
+
+#define	TIME_PON	30		/* 300ms ------	Power On Wait Time */
+#define	TIME_CDCHK	2			/*  20ms ------	Card Check Interval Timer */
+#define	TIME_WPCHK	1			/*   5ms ------	WP Check Interval Timer */
+
+/* Power On Timeout */
+#define POWER_ON_TIMEOUT	(HZ*2)
+
+/* Default retry limit for Read/Write */
+#define RD_RETRY_LIMIT	3
+#define WR_RETRY_LIMIT	4
+#define BLOCK_READ_RETRY_LIMIT	2
+#define BLOCK_WRITE_RETRY_LIMIT 3
+#define REASSIGN_RETRY_LIMIT 	4
+
+/***************************************************************************
+	Redundant Data
+ ***************************************************************************/
+#define	REDT_DATA	0x04
+#define	REDT_BLOCK	0x05
+
+#define	REDT_ADDR1H	0x06
+#define	REDT_ADDR1L	0x07
+#define	REDT_ADDR2H	0x0B
+#define	REDT_ADDR2L	0x0C
+
+#define	REDT_ECC10	0x0D
+#define	REDT_ECC11	0x0E
+#define	REDT_ECC12	0x0F
+
+#define	REDT_ECC20	0x08
+#define	REDT_ECC21	0x09
+#define	REDT_ECC22	0x0A
+
+/***************************************************************************
+	SmartMedia Model & Attribute
+ ***************************************************************************/
+/* SmartMedia Attribute */
+#define	NOWP		0x00	/* 0... .... No Write Protect */
+#define	WP  		0x80	/* 1... .... Write Protected */
+#define	MASK		0x00	/* .00. .... NAND MASK ROM Model */
+#define	FLASH		0x20	/* .01. .... NAND Flash ROM Model */
+#define	AD3CYC		0x00	/* ...0 .... Address 3-cycle */
+#define	AD4CYC		0x10	/* ...1 .... Address 4-cycle */
+#define	BS16		0x00	/* .... 00.. 16page/block */
+#define	BS32		0x04	/* .... 01.. 32page/block */
+#define	PS256		0x00	/* .... ..00 256byte/page */
+#define	PS512		0x01	/* .... ..01 512byte/page */
+
+#define	MWP			0x80	/* WriteProtect mask */
+#define	MFLASH		0x60	/* Flash Rom mask */
+#define	MADC		0x10	/* Address Cycle */
+#define	MBS			0x0C	/* BlockSize mask */
+#define	MPS			0x03	/* PageSize mask */
+
+/* SmartMedia Model */
+#define	NOSSFDC			0x00	/*   NO SmartMedia */
+#define	SSFDC1MB		0x01	/*  1MB SmartMedia */
+#define	SSFDC2MB		0x02	/*  2MB SmartMedia */
+#define	SSFDC4MB		0x03	/*  4MB SmartMedia */
+#define	SSFDC8MB		0x04	/*  8MB SmartMedia */
+#define	SSFDC16MB		0x05	/* 16MB SmartMedia */
+#define	SSFDC32MB		0x06	/* 32MB SmartMedia */
+#define	SSFDC64MB		0x07	/* 64MB SmartMedia */
+#define	SSFDC128MB		0x08	/*128MB SmartMedia */
+
+#define EVEN             0          /* Even Page for 256byte/page */
+#define ODD              1          /* Odd  Page for 256byte/page */
+
+/***************************************************************************
+	Struct Definition
+ ***************************************************************************/
+/* Linux kernel additions */
+
+/* device buffer xfer status */
+typedef enum { xfer_idle, xfer_busy} xfer_states;
+
+/* Smartmedia device structure */
+typedef struct {
+	unsigned long		address;
+	int 				sm_minor;
+	int					sm_flags;
+	int					busy;
+	int					waiting;
+
+	/* queue of io requests for the device */
+	spinlock_t			req_queue_lock;
+	request_queue_t 	*req_queue;
+
+	/* our thread related parameters */
+	struct completion 	thread_dead;
+	int 				exiting;
+	wait_queue_head_t 	thread_wq;
+
+	/* accounting variables for each buffer io operation
+		each request may have a chain of buffers, each of
+		which may require I/O of multiple sectors */
+	unsigned int		ReqSectorSize;
+	unsigned int		BufIndex;
+	unsigned int		SectorWriteIndex;
+
+	/* CHS parameters */
+	unsigned int		HostCyl;
+	unsigned char		HostHead;
+	unsigned char		HostSect;
+
+	/* State Information */
+	xfer_states			XferState;
+	unsigned int  		UseCount;
+	unsigned int  		RetryCount;
+	unsigned int  		ErrCode;
+	unsigned int  		MediaChange;
+	unsigned int  		CardPresent;
+	unsigned int  		SectCopyMode;
+
+	/* Working Databuf Area */
+	unsigned char 		SectBuf[SSFDC_SECTSIZE];
+	unsigned char 		WorkBuf[SSFDC_SECTSIZE];
+	unsigned char 		Redundant[REDTSIZE];
+	unsigned char 		WorkRedund[REDTSIZE];
+	unsigned int  		DataBuf_Valid;
+	unsigned int  		Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK];
+	unsigned char 		Assign[MAX_ZONENUM][MAX_BLOCKNUM/8];
+	unsigned int  		AssignStart[MAX_ZONENUM];
+	unsigned int  		ReadBlock;
+	unsigned int  		WriteBlock;
+
+	/* Card attributes */
+	unsigned char 		Model;
+	unsigned char 		Attribute;
+	unsigned char 		MaxZones;
+	unsigned char 		MaxSectors;
+	unsigned int  		MaxBlocks;
+	unsigned int  		MaxLogBlocks; 
+
+	/* Address of current access (Media) */
+	unsigned char		Zone;         /* Zone Number */
+	unsigned char		Sector;       /* Sector(512byte) Number on Block */
+	unsigned int		PhyBlock;     /* Physical Block Number on Zone */
+	unsigned int		LogBlock;     /* Logical Block Number of Zone */               
+
+	/* device statistics */
+	unsigned int		Sector_reads;
+	unsigned int		Sector_writes;
+	unsigned int		Sect_rd_errs_ttl;
+	unsigned int		Sect_wr_errs_ttl;
+	unsigned int		Bad_blks_rd;
+	unsigned int		Bad_blks_wr;
+	unsigned int		Bad_blks_erase;
+} ssfdc_dev;
+
+
+/****************************************************************************/
+/*	Handy defines															*/
+/****************************************************************************/
+#define WRITE_PROTECTED(p)	(p->Attribute & WP)
+
+/* End of Linux kernel additions */
+#endif	/* #ifndef _SSFDC_H */