summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/patches-2.6.30/0002-rsdk-drivers-mtd.patch
blob: 46c99bbe339c293a11e5da0e2814c0978931cd40 (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
--- linux-2.6.30.9/drivers/mtd/chips/Kconfig	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/chips/Kconfig	2013-05-02 01:47:52.620227148 +0300
@@ -240,6 +240,12 @@ config MTD_XIP
 	  This allows MTD support to work with flash memory which is also
 	  used for XIP purposes.  If you're not sure what this is all about
 	  then say N.
+config RTL819X_SPI_FLASH
+        bool "RTL819x SPI flash support"
+        depends on MTD
+        help
+          Support SPI flash for MX25L,SST series
+
 
 endmenu
 
--- linux-2.6.30.9/drivers/mtd/chips/Makefile	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/chips/Makefile	2013-05-02 01:47:52.620227148 +0300
@@ -13,3 +13,4 @@ obj-$(CONFIG_MTD_JEDECPROBE)	+= jedec_pr
 obj-$(CONFIG_MTD_RAM)		+= map_ram.o
 obj-$(CONFIG_MTD_ROM)		+= map_rom.o
 obj-$(CONFIG_MTD_ABSENT)	+= map_absent.o
+obj-$(CONFIG_RTL819X_SPI_FLASH) += rtl819x/
--- linux-2.6.30.9/drivers/mtd/devices/doc2001.c	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/devices/doc2001.c	2013-05-02 01:47:52.629227147 +0300
@@ -10,8 +10,11 @@
 #include <asm/errno.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
+#include <linux/miscdevice.h>
+#include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/bitops.h>
@@ -20,6 +23,48 @@
 #include <linux/mtd/nand.h>
 #include <linux/mtd/doc2000.h>
 
+#ifdef CONFIG_RTL_819X
+/*porting for RTL865xC-RTL8190 SDK by alva_zhang@2007.11*/
+#include <linux/config.h>
+#include <linux/mtd/partitions.h>
+
+#define CALL_APP_TO_LOAD_DEFAULT	// call user program to load default
+extern int flash_hw_start;
+#define noCONFIG_MTD_DEBUG
+#define CONFIG_MTD_DEBUG_VERBOSE 3
+extern int flash_hw_start, flash_hw_len, flash_ds_start, flash_ds_len, flash_write_flag;
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+#define RTL_BOOTCODE_END (0x6000)
+static struct mtd_partition rtl8196_partitions[ ] = {
+        {
+                name:         "boot+cfg+linux",
+                size:           (CONFIG_RTL_ROOT_IMAGE_OFFSET-0),
+                offset:         0x00000000,
+        },
+        {
+                name:           "root fs",
+                   size:        (CONFIG_RTL_FLASH_SIZE-CONFIG_RTL_ROOT_IMAGE_OFFSET),
+                offset:         (CONFIG_RTL_ROOT_IMAGE_OFFSET),
+        }
+};
+#else
+static struct mtd_partition rtl8196_partitions[ ] = {
+        {
+                name:         "boot+cfg+linux",
+                size:           0xF0000,
+                offset:         0x00000000,
+        },
+        {
+                name:           "root fs",
+                   size:        0x110000,
+                offset:         0xF0000,
+        }
+};
+#endif
+#define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
+#endif /*#ifdef CONFIG_RTL_819X */
+
+
 /* #define ECC_DEBUG */
 
 /* I have no idea why some DoC chips can not use memcop_form|to_io().
@@ -32,12 +77,29 @@ static int doc_read(struct mtd_info *mtd
 		    size_t *retlen, u_char *buf);
 static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		     size_t *retlen, const u_char *buf);
+
+#ifdef CONFIG_RTL_819X
+/* Do nothing here*/
+#else
 static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
 			struct mtd_oob_ops *ops);
 static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
 			 struct mtd_oob_ops *ops);
+#endif
+
 static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
 
+#ifdef CONFIG_RTL_819X
+/*porting for RTL865xC-RTL8190 SDK by alva_zhang@2007.11*/
+static int erase_one_block(struct DiskOnChip *this, __u32 addr, __u32 len);
+#endif
+
+#ifdef CONFIG_RTL_819X
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+int find_section_boundary(struct mtd_info *mtd,unsigned int start, unsigned int end, unsigned int *rstart, unsigned *rend);
+#endif
+#endif
+
 static struct mtd_info *docmillist = NULL;
 
 /* Perform the required delay cycles by reading from the NOP register */
@@ -149,6 +211,10 @@ static inline void DoC_Address(void __io
 	DoC_Delay(docptr, 4);
 }
 
+#ifdef CONFIG_RTL_819X
+/*porting for RTL865xC-RTL8190 SDK by alva_zhang@2007.11*/
+/* Do nothing here*/
+#else
 /* DoC_SelectChip: Select a given flash chip within the current floor */
 static int DoC_SelectChip(void __iomem * docptr, int chip)
 {
@@ -281,6 +347,7 @@ static void DoC_ScanChips(struct DiskOnC
 	printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n",
 	       this->numchips ,this->totlen >> 20);
 }
+#endif /*#ifdef CONFIG_RTL_819X */
 
 static int DoCMil_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
 {
@@ -318,9 +385,16 @@ static int DoCMil_is_alias(struct DiskOn
 void DoCMil_init(struct mtd_info *mtd)
 {
 	struct DiskOnChip *this = mtd->priv;
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else
 	struct DiskOnChip *old = NULL;
+#endif
 
 	/* We must avoid being called twice for the same device. */
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else
 	if (docmillist)
 		old = docmillist->priv;
 
@@ -337,17 +411,31 @@ void DoCMil_init(struct mtd_info *mtd)
 		else
 			old = NULL;
 	}
+#endif /*CONFIG_RTL_819X*/
 
 	mtd->name = "DiskOnChip Millennium";
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else
 	printk(KERN_NOTICE "DiskOnChip Millennium found at address 0x%lX\n",
 	       this->physadr);
+#endif
+
+	mtd->type = MTD_NORFLASH;
+	mtd->flags = MTD_CAP_NORFLASH;
+#ifdef CONFIG_RTL_819X
+#else
+	mtd->ecctype = MTD_ECC_RS_DiskOnChip;
+#endif
 
-	mtd->type = MTD_NANDFLASH;
-	mtd->flags = MTD_CAP_NANDFLASH;
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else	
 	mtd->size = 0;
 
 	/* FIXME: erase size is not always 8KiB */
 	mtd->erasesize = 0x2000;
+#endif
 
 	mtd->writesize = 512;
 	mtd->oobsize = 16;
@@ -357,10 +445,19 @@ void DoCMil_init(struct mtd_info *mtd)
 	mtd->unpoint = NULL;
 	mtd->read = doc_read;
 	mtd->write = doc_write;
+
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else		
 	mtd->read_oob = doc_read_oob;
 	mtd->write_oob = doc_write_oob;
+#endif
+
 	mtd->sync = NULL;
 
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else	
 	this->totlen = 0;
 	this->numchips = 0;
 	this->curfloor = -1;
@@ -368,6 +465,7 @@ void DoCMil_init(struct mtd_info *mtd)
 
 	/* Ident all the chips present. */
 	DoC_ScanChips(this);
+#endif
 
 	if (!this->totlen) {
 		kfree(mtd);
@@ -376,15 +474,199 @@ void DoCMil_init(struct mtd_info *mtd)
 		this->nextdoc = docmillist;
 		docmillist = mtd;
 		mtd->size  = this->totlen;
+//#ifdef CONFIG_RTK_MTD_ROOT
+#ifdef CONFIG_RTL_819X
+		add_mtd_partitions(mtd, rtl8196_partitions,  NB_OF(rtl8196_partitions));
+#else
 		add_mtd_device(mtd);
+#endif
 		return;
 	}
 }
 EXPORT_SYMBOL_GPL(DoCMil_init);
 
+#ifdef CONFIG_RTL_819X 
+static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
+			  size_t *retlen, const u_char *buf, u_char *eccbuf)
+{
+	int i,ret;
+	struct DiskOnChip *this = (struct DiskOnChip *)mtd->priv;
+	unsigned long docptr =(unsigned long) this->virtadr;
+	unsigned int ofs;
+	unsigned short val,val1;
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+	unsigned int rstart,rend;
+	unsigned int start,end;
+#endif
+// david ------------
+unsigned long timeo, offset;
+unsigned long flags; 
+//-------------------
+
+	/* Don't allow write past end of device */
+	if (to >= this->totlen)
+	{
+// david
+//		printk("write to >= total len\n");
+	printk(KERN_WARNING "write to >= total len\n");
+		return -EINVAL;
+	}
+	DEBUG(MTD_DEBUG_LEVEL1,"going to write len=0x%x,to =0x%x\n", (int)len, (int)to);
+
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+	start=to;
+	end=0xFFFFFFF;
+	if(flash_write_flag & 1)
+	{
+		if(0 == start)
+			start = CONFIG_RTL_HW_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_HW_SETTING_OFFSET )
+			start = CONFIG_RTL_HW_SETTING_OFFSET;
+		end=CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+	}
+			
+	if(flash_write_flag & 2 )
+	{
+		if(0 == start)
+			start = CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_DEFAULT_SETTING_OFFSET )
+			start = CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+		
+		end = CONFIG_RTL_CURRENT_SETTING_OFFSET;
+	}
+			
+	if( flash_write_flag & 4 )
+	{
+		if(0 == start)
+			start = CONFIG_RTL_CURRENT_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_CURRENT_SETTING_OFFSET )
+			start = CONFIG_RTL_CURRENT_SETTING_OFFSET;	
+		end = CONFIG_RTL_WEB_PAGES_OFFSET;
+	}
+	find_section_boundary(mtd,start,end,&rstart,&rend);
+
+#endif
+
+	*retlen = len;
+	ofs = docptr + to;
+	for(i=0; i< len; i+=2)
+	{
+// david -----------------------------------------------------
+#if 0
+		val = *(unsigned short *)buf;
+
+		*(volatile unsigned short *)(0xbfc00000 + 0x555 * 2)= 0xaa;
+		*(volatile unsigned short *)(0xbfc00000 + 0x2aa * 2)= 0x55;
+		*(volatile unsigned short *)(0xbfc00000 + 0x555 * 2)= 0xa0;
+		*(volatile unsigned short *)(ofs )= val;
+
+	       	j=0xfffff1;
+        	do{
+                	val1=*(volatile unsigned short *)(ofs);
+  	            	if( ((val1^val) & 0x80)==0 )
+ 				break;
+
+       		}while(j--!=1);
+		if (j <= 2)
+			printk("program fails\n");
+#else
+
+//		if ( ofs < (docptr+CONFIG_MTD_DOCPROBE_ADDRESS) )
+//			goto next_word;
+
+		offset = (to >> this->chipshift)*(1 << this->chipshift);
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+		if(ofs <(docptr+rstart))
+			goto next_word;
+		if(ofs >= (docptr+rend))
+		{
+			return 0;
+		}
+#else
+#if !defined(COMPACK_SETTING) && !defined(NO_CHECK_REGION)
+		if ( flash_write_flag != 0x8000
+//#ifdef CONFIG_RTK_MTD_ROOT
+#ifdef CONFIG_RTL_819X
+			|| offset < (rtl8196_partitions[0].size+ rtl8196_partitions[0].offset)
+#endif
+			)
+		{
+
+			if ( (flash_write_flag & 1) && (ofs < (docptr+flash_hw_start)) )
+				goto next_word;
+
+			if ( (flash_write_flag & 2) && (ofs < (docptr+flash_ds_start)) )
+				goto next_word;
+
+			if ( (flash_write_flag & 4) && (ofs < (docptr+flash_ds_start+flash_ds_len)) )
+				goto next_word;
+		}
+#endif // COMPACK_SETTING && NO_CHECK_REGION
+#endif //CONFIG_RTL_FLASH_MAPPING_ENABLE
+		val = *(unsigned short *)buf;
+
+		mtd_save_flags(flags);mtd_cli(); // david
+		
+		*(volatile unsigned short *)(0xbfc00000 + offset + 0x555 * 2)= 0xaa;
+		*(volatile unsigned short *)(0xbfc00000 + offset + 0x2aa * 2)= 0x55;
+		*(volatile unsigned short *)(0xbfc00000 + offset + 0x555 * 2)= 0xa0;
+		*(volatile unsigned short *)(ofs )= val;
+		
+		mtd_restore_flags(flags); // david
+
+		timeo = jiffies + (HZ * 50);
+        	do{    		
+#if 0
+			val1=*(volatile unsigned short *)(ofs);
+			if ( val1 == val )
+				break;
+#endif
+			unsigned short val2;
+      	
+			val2=*(volatile unsigned short *)(ofs);
+			val1=*(volatile unsigned short *)(ofs);	
+			
+			if (((val1^val2) & 0x40) != 0)
+				continue;	 	        
+	 	        if (((val1^val) & 0x80) != 0)
+ 				continue;
+ 			if ( val1 == val )		
+				break;
+//--------------	      	    	
+		} while ( !time_after(jiffies, timeo) );
+
+		if ( time_after(jiffies, timeo)) {
+			printk(KERN_WARNING "program timeout!");
+			printk(KERN_WARNING " write: %x, read:%x, addr: %x\n", val, val1, ofs);
+			return -1;
+		}
+
+#ifndef COMPACK_SETTING
+next_word:
+#endif
+
+#endif
+//---------------------------------------------------------
+		ofs += 2;
+		buf += 2;
+	
+	}
+
+	ret = 0 ;
+//	printk("in doc_write_ecc ret=%08x\n", ret);
+	return ret;
+}
+#endif /* #ifdef CONFIG_RTL_819X  */
+
 static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
 		     size_t *retlen, u_char *buf)
 {
+#ifdef CONFIG_RTL_819X 
+static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
+			 size_t *retlen, u_char *buf, u_char *eccbuf);
+/* Just a special case of doc_read_ecc */
+	return doc_read_ecc(mtd, from, len, retlen, buf, NULL);
+#else
 	int i, ret;
 	volatile char dummy;
 	unsigned char syndrome[6], eccbuf[6];
@@ -491,11 +773,49 @@ static int doc_read (struct mtd_info *mt
 	WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
 
 	return ret;
+
+#endif /* #ifdef CONFIG_RTL_819X  */
+}
+
+#ifdef CONFIG_RTL_819X 
+static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
+			 size_t *retlen, u_char *buf, u_char *eccbuf)
+{
+	int i;
+	unsigned short tmp;
+	struct DiskOnChip *this = (struct DiskOnChip *)mtd->priv;
+	unsigned long docptr = this->virtadr+from;
+
+	/* Don't allow read past end of device */
+	if (from >= this->totlen)
+		return -EINVAL;
+	for(i=0; i< len; i+=2)
+	{
+		tmp = *(volatile unsigned short *)(docptr);
+		*(unsigned short *)buf = tmp;
+		buf += 2;
+		docptr +=2;
+	}
+	if (len & 0x01)
+	{
+		tmp = *(volatile unsigned long *)(docptr);
+        *(unsigned char *)buf = (tmp >> 8) & 0xff;
+	}
+
+	/* Let the caller know we completed it */
+	*retlen = len;
+
+	return 0;
 }
+#endif /*#ifdef CONFIG_RTL_819X */
 
 static int doc_write (struct mtd_info *mtd, loff_t to, size_t len,
 		      size_t *retlen, const u_char *buf)
 {
+#ifdef CONFIG_RTL_819X 
+       char eccbuf[6];
+	return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf);
+#else
 	int i,ret = 0;
 	char eccbuf[6];
 	volatile char dummy;
@@ -617,8 +937,12 @@ static int doc_write (struct mtd_info *m
 	*retlen = len;
 
 	return ret;
+#endif /*#ifdef CONFIG_RTL_819X  */
 }
 
+#ifdef CONFIG_RTL_819X 
+/*do nothing here*/
+#else
 static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
 			struct mtd_oob_ops *ops)
 {
@@ -753,9 +1077,229 @@ static int doc_write_oob(struct mtd_info
 
 	return ret;
 }
+#endif /*#ifdef CONFIG_RTL_819X  */
+
+#ifdef CONFIG_RTL_819X
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+int find_section_boundary(struct mtd_info *mtd,unsigned int start, unsigned int end, unsigned int *rstart, unsigned *rend)
+{
+	int i = 0;
+	int j = 0;
+	struct mtd_erase_region_info *regions = mtd->eraseregions;
+	while ((i < mtd->numeraseregions) &&
+		(start >= regions[i].offset)) {
+		i++;
+	}
+	i--;
+
+	j = 1;
+	while((j <= regions[i].numblocks) &&
+		(start >= (regions[i].offset+regions[i].erasesize*j))) {
+		j++;
+	}
+	*rstart=(regions[i].offset+regions[i].erasesize*(j-1));
+	
+	i=0;
+	while ((i < mtd->numeraseregions) &&
+		(end >= regions[i].offset)) {
+		 i++;
+	}
+	i--;
+
+	j = 1;
+	while((j <= regions[i].numblocks) &&
+		(end >= (regions[i].offset+regions[i].erasesize*j))) {
+		j++;
+	}
+	*rend=(regions[i].offset+regions[i].erasesize*j);
+	
+}
+#endif
+#endif
 
 int doc_erase (struct mtd_info *mtd, struct erase_info *instr)
 {
+#ifdef CONFIG_RTL_819X 
+
+struct DiskOnChip *this = (struct DiskOnChip *)mtd->priv;
+	unsigned long adr, len;
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE	
+	unsigned int rstart,rend;
+        unsigned int start,end;
+#endif
+	int i;
+	int first;
+	struct mtd_erase_region_info *regions = mtd->eraseregions;
+
+	DEBUG(MTD_DEBUG_LEVEL1, "going to erase sector addr=%08x,len=%08x\n",
+		instr->addr, instr->len);
+
+	if (instr->addr > mtd->size) {
+		printk(KERN_WARNING "Erase addr greater than max size (0x%x > 0x%x)\n",
+			instr->addr, mtd->size );
+		return -EINVAL;
+	}
+
+	if ((instr->len + instr->addr) > mtd->size) {
+		printk(KERN_WARNING "Erase size greater than max size (0x%x + 0x%x > 0x%x)\n",
+		       instr->addr, instr->len, mtd->size );
+		return -EINVAL;
+	}
+
+	/* Check that both start and end of the requested erase are
+	 * aligned with the erasesize at the appropriate addresses.
+	 */
+
+	i = 0;
+
+        /* Skip all erase regions which are ended before the start of
+           the requested erase. Actually, to save on the calculations,
+           we skip to the first erase region which starts after the
+           start of the requested erase, and then go back one.
+        */
+
+        while ((i < mtd->numeraseregions) &&
+	       (instr->addr >= regions[i].offset)) {
+               i++;
+	}
+        i--;
+
+	/* OK, now i is pointing at the erase region in which this
+	 * erase request starts. Check the start of the requested
+	 * erase range is aligned with the erase size which is in
+	 * effect here.
+	 */
+
+	if (instr->addr & (regions[i].erasesize-1)) {
+		return -EINVAL;
+	}
+
+	/* Remember the erase region we start on. */
+
+	first = i;
+
+	/* Next, check that the end of the requested erase is aligned
+	 * with the erase region at that address.
+	 */
+
+	while ((i < mtd->numeraseregions) &&
+	       ((instr->addr + instr->len) >= regions[i].offset)) {
+                i++;
+	}
+
+	/* As before, drop back one to point at the region in which
+	 * the address actually falls.
+	 */
+
+	i--;
+
+	if ((instr->addr + instr->len) & (regions[i].erasesize-1)) {
+                return -EINVAL;
+	}
+
+
+	adr = instr->addr;
+	len = instr->len;
+
+	i = first;
+	instr->state = MTD_ERASING;
+
+
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+	start=adr;
+	end=0xFFFFFFF;
+	if(flash_write_flag & 1)
+	{
+		if(0 == start)
+			start = CONFIG_RTL_HW_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_HW_SETTING_OFFSET )
+			start = CONFIG_RTL_HW_SETTING_OFFSET;
+		end = CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+	}
+			
+       if(flash_write_flag & 2 )
+       {
+    		if(0 == start)
+			start = CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_DEFAULT_SETTING_OFFSET )
+			start = CONFIG_RTL_DEFAULT_SETTING_OFFSET;
+		end = CONFIG_RTL_CURRENT_SETTING_OFFSET;
+    	}
+			
+    	if(flash_write_flag & 4 )
+   	{
+   		if(0 == start)
+			start = CONFIG_RTL_CURRENT_SETTING_OFFSET;
+		else if( start > CONFIG_RTL_CURRENT_SETTING_OFFSET )
+			start = CONFIG_RTL_CURRENT_SETTING_OFFSET;
+		
+		end = CONFIG_RTL_WEB_PAGES_OFFSET;
+   	}
+
+	find_section_boundary(mtd,start,end,&rstart,&rend);
+
+	//printk("line[%d] rstart 0x%x rend 0x%x\n",__LINE__,rstart,rend);
+	
+	/*don't erase bootcode*/
+	if(rstart < RTL_BOOTCODE_END)
+		rstart = RTL_BOOTCODE_END;
+	
+	//printk("line[%d] rstart 0x%x rend 0x%x\n",__LINE__,rstart,rend);
+#endif
+
+	while (len) {
+//		if (adr >= CONFIG_MTD_DOCPROBE_ADDRESS) {
+
+#if defined(COMPACK_SETTING) || defined(NO_CHECK_REGION)
+		if ( erase_one_block(this, adr, regions[i].erasesize) )
+			return -1;
+
+#else
+
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+	   if(adr >= rstart)
+#else
+		if ( ((flash_write_flag & 1) && (adr == flash_hw_start)) ||
+				((flash_write_flag & 2) &&(adr >= flash_ds_start && adr < (flash_ds_start+flash_ds_len))) 
+				|| ((flash_write_flag & 4) && (adr >= (flash_ds_start+flash_ds_len))) 
+//#ifdef CONFIG_RTK_MTD_ROOT
+#ifdef CONFIG_RTL_819X
+				|| (adr >= (rtl8196_partitions[0].size+ rtl8196_partitions[0].offset))
+#endif			
+				|| (flash_write_flag == 0x8000)
+				) 
+#endif	
+		{
+			if ( erase_one_block(this, adr, regions[i].erasesize) )
+				return -1;
+		}
+			
+#endif // COMPACK_SETTING || NO_CHECK_REGION
+
+		adr += regions[i].erasesize;
+		if (len < regions[i].erasesize)
+			len = 0;
+		else
+			len -= regions[i].erasesize;
+
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+		if(rend <= adr)
+		{
+			/*no need to erase other block*/
+			len=0;
+		}
+#endif
+		if ( adr >= (regions[i].offset + regions[i].erasesize*regions[i].numblocks))
+			i++;
+	}
+
+	instr->state = MTD_ERASE_DONE;
+	if (instr->callback) {
+		instr->callback(instr);
+	}
+
+	return 0;
+#else
 	volatile char dummy;
 	struct DiskOnChip *this = mtd->priv;
 	__u32 ofs = instr->addr;
@@ -809,7 +1353,52 @@ int doc_erase (struct mtd_info *mtd, str
 	mtd_erase_callback(instr);
 
 	return 0;
+
+#endif /*#ifdef CONFIG_RTL_819X */
+}
+
+#ifdef CONFIG_RTL_819X 
+static int erase_one_block(struct DiskOnChip *this, __u32 addr, __u32 len)
+{
+	unsigned long timeo;
+	unsigned long docptr = this->virtadr;
+	__u32 ofs, offset;
+	unsigned long flags; // david
+
+
+	DEBUG(MTD_DEBUG_LEVEL1, "Erase sector, addr=0x%x, docptr=0x%x, len=0x%x\n",
+		(int)addr, (int)docptr, (int)len);
+
+	// issue erase command!
+	ofs = docptr + addr;
+
+	offset = (addr >> this->chipshift)*(1 << this->chipshift);
+
+	mtd_save_flags(flags);mtd_cli(); // david
+	*(volatile unsigned short *)(docptr + offset + 0x555 * 2) = 0xaa;
+	*(volatile unsigned short *)(docptr + offset + 0x2aa * 2) = 0x55;
+	*(volatile unsigned short *)(docptr + offset + 0x555 * 2) = 0x80;
+	*(volatile unsigned short *)(docptr + offset + 0x555 * 2) = 0xaa;
+	*(volatile unsigned short *)(docptr + offset + 0x2aa * 2) = 0x55;
+	*(volatile unsigned short *)(ofs ) = 0x30;
+	mtd_restore_flags(flags); // david
+
+	timeo = jiffies + (HZ * 40);
+
+	while (1) {
+     		if ((*(volatile unsigned short *)(ofs))==0xffff) {
+			DEBUG(MTD_DEBUG_LEVEL1, "Erase success!\n");
+			break;
+		}
+		if (time_after(jiffies, timeo)) {
+			printk(KERN_WARNING "Erase timeout!\n");
+			return -1;
+		}		
+		udelay(1);
+     	}
+	return 0;
 }
+#endif /*#ifdef CONFIG_RTL_819X */
 
 /****************************************************************************
  *
--- linux-2.6.30.9/drivers/mtd/devices/docprobe.c	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/devices/docprobe.c	2013-05-02 01:47:52.630227147 +0300
@@ -36,7 +36,7 @@
    <linux-mtd@lists.infradead.org>.
 */
 #define DOC_SINGLE_DRIVER
-
+#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <asm/errno.h>
@@ -56,10 +56,68 @@
 #define CONFIG_MTD_DOCPROBE_ADDRESS 0
 #endif
 
+#ifdef CONFIG_RTL_819X
+// david ----------------------
+/* MXIC */
+#define MANUFACTURER_MXIC	0x00C2
+#define MX29LV800B		0x225B
+#define MX29LV160AB		0x2249
+#define MX29LV320AB		0x22A8
+#define MX29LV640AB		0x22CB
+
+/*AMD*/
+#define MANUFACTURER_AMD	0x0001
+#define AM29LV800BB		0x225B
+#define AM29LV160DB		0x2249
+#define AM29LV320DB		0x22F9
+
+/*ST*/
+#define MANUFACTURER_ST		0x0020
+#define M29W160DB		0X2249
+
+/* ESMT */
+#define MANUFACTURER_ESMT	0x008C
+#define F49L160BA		0x2249
+
+/* SAMSUNG */
+#define MANUFACTURER_SAMSUNG	0x00EC
+#define K8D1716UBC		0x2277
+
+/* ESI */
+#define MANUFACTURER_ESI	0x004A
+#define ES29LV320D		0x22F9
+
+/* EON */
+#define MANUFACTURER_EON	0x007F
+#define EN29LV160A		0x2249
+
+#ifdef CONFIG_RTL8196B
+#define FLASH_BASE 0xbd000000
+#else
+#define FLASH_BASE 0xbe000000
+#endif
+
+struct flash_info {
+	const __u16 mfr_id;
+	const __u16 dev_id;
+	const char *name;
+	const u_long size;
+	const int shift;  // shift number of chip size
+	const int numeraseregions;
+	const struct mtd_erase_region_info regions[4];
+};
+
+static int probeChip(struct DiskOnChip *doc, struct mtd_info *mtd);
+//-----------------------------
+#endif /*#ifdef CONFIG_RTL_819X*/
+
+//static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
+//module_param(doc_config_location, ulong, 0);
+//MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
 
-static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
-module_param(doc_config_location, ulong, 0);
-MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
+#ifdef CONFIG_RTL_819X
+ /* Do nothing here*/
+#else
 
 static unsigned long __initdata doc_locations[] = {
 #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
@@ -76,6 +134,13 @@ static unsigned long __initdata doc_loca
 	0xe0000, 0xe2000, 0xe4000, 0xe6000,
 	0xe8000, 0xea000, 0xec000, 0xee000,
 #endif /*  CONFIG_MTD_DOCPROBE_HIGH */
+#elif defined(__PPC__)
+	0xe4000000,
+#elif defined(CONFIG_MOMENCO_OCELOT)
+	0x2f000000,
+        0xff000000,
+#elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C)
+        0xff000000,
 #else
 #warning Unknown architecture for DiskOnChip. No default probe locations defined
 #endif
@@ -217,8 +282,9 @@ static inline int __init doccheck(void _
 #endif
 	return 0;
 }
+#endif /*#ifdef CONFIG_RTL_819X*/
 
-static int docfound;
+//static int docfound;
 
 extern void DoC2k_init(struct mtd_info *);
 extern void DoCMil_init(struct mtd_info *);
@@ -229,11 +295,18 @@ static void __init DoC_Probe(unsigned lo
 	void __iomem *docptr;
 	struct DiskOnChip *this;
 	struct mtd_info *mtd;
-	int ChipID;
+	//int ChipID;
 	char namebuf[15];
 	char *name = namebuf;
+
+	
+	char *im_funcname = NULL;
+	char *im_modname = NULL;
+	
+	
 	void (*initroutine)(struct mtd_info *) = NULL;
 
+#ifndef CONFIG_RTL_819X
 	docptr = ioremap(physadr, DOC_IOREMAP_LEN);
 
 	if (!docptr)
@@ -302,8 +375,286 @@ static void __init DoC_Probe(unsigned lo
 		kfree(mtd);
 	}
 	iounmap(docptr);
+#else
+      docptr = FLASH_BASE;
+      //-----------------------------
+
+
+	mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
+
+	if (!mtd) {
+			printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
+			iounmap((void *)docptr);
+			return;
 }
 
+	this = (struct DiskOnChip *)(&mtd[1]);
+
+	memset((char *)mtd,0, sizeof(struct mtd_info));
+	memset((char *)this, 0, sizeof(struct DiskOnChip));
+
+	mtd->priv = this;
+	this->virtadr = docptr;
+	this->physadr = physadr;
+	this->ChipID = DOC_ChipID_DocMil;
+
+	name="Millennium";
+	im_funcname = "DoCMil_init";
+	im_modname = "doc2001";
+
+	if ( probeChip(this, mtd) == 0) // david added,
+		initroutine = &DoCMil_init;
+
+	if (initroutine) {
+		(*initroutine)(mtd);
+		return;
+	}
+	printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
+	iounmap((void *)docptr);
+
+#endif /*#ifdef CONFIG_RTL_819X*/
+}
+
+#ifdef CONFIG_RTL_819X
+// david -------------------------------------------------------------------
+static int probeChip(struct DiskOnChip *doc, struct mtd_info *mtd)
+{
+	/* Keep this table on the stack so that it gets deallocated after the
+	 * probe is done.
+	 */
+	const struct flash_info table[] = {
+	{
+		mfr_id: MANUFACTURER_MXIC,
+		dev_id: MX29LV800B,
+		name: "MXIC MX29LV800B",
+		size: 0x00100000,
+		shift: 20,
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 15 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_MXIC,
+		dev_id: MX29LV160AB,
+		name: "MXIC MX29LV160AB",
+		size: 0x00200000,
+		shift: 21,
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_MXIC,
+		dev_id: MX29LV320AB,
+		name: "MXIC MX29LV320AB",
+		size: 0x00400000,
+		shift: 22,
+		numeraseregions: 2,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x02000, numblocks:  8 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 63 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_AMD,
+		dev_id: AM29LV800BB,
+		name: "AMD AM29LV800BB",
+		size: 0x00100000,
+		shift: 20,
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 15 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_AMD,
+		dev_id: AM29LV160DB,
+		name: "AMD AM29LV160DB",
+		size: 0x00200000,
+		shift: 21,
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_AMD,
+		dev_id: AM29LV320DB,
+		name: "AMD AM29LV320DB",
+		size: 0x00400000,
+		shift: 22,
+		numeraseregions: 2,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x02000, numblocks:  8 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 63 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_ST,
+		dev_id: M29W160DB,
+		name: "ST M29W160DB",
+		size: 0x00200000,
+		shift: 21,/*21 bit=> that is 2 MByte size*/
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_MXIC,
+		dev_id: MX29LV640AB,
+		name: "MXIC MX29LV640AB",
+		size: 0x00800000,
+		shift: 23,/*22 bit=> that is 8 MByte size*/
+		numeraseregions: 2,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x02000, numblocks:   8 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 127 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_SAMSUNG,
+		dev_id: K8D1716UBC,
+		name: "SAMSUNG K8D1716UBC",
+		size: 0x00200000,
+		shift: 21,/*21 bit=> that is 2 MByte size*/
+		numeraseregions: 2,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x02000, numblocks:  8 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_ESMT,
+		dev_id: F49L160BA,
+		name: "ESMT F49L160BA",
+		size: 0x00200000,
+		shift: 21,/*21 bit=> that is 2 MByte size*/
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_ESI,
+		dev_id: ES29LV320D,
+		name: "ESI ES29LV320D",
+		size: 0x00400000,
+		shift: 22,/*22 bit=> that is 4 MByte size*/
+		numeraseregions: 2,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x02000, numblocks:  8 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 63 }
+		}
+	},
+	{
+		mfr_id: MANUFACTURER_EON,
+		dev_id: EN29LV160A,
+		name: "EON EN29LV160A",
+		size: 0x00200000,
+		shift: 21,
+		numeraseregions: 4,
+		regions: {
+			{ offset: 0x000000, erasesize: 0x04000, numblocks:  1 },
+			{ offset: 0x004000, erasesize: 0x02000, numblocks:  2 },
+			{ offset: 0x008000, erasesize: 0x08000, numblocks:  1 },
+			{ offset: 0x010000, erasesize: 0x10000, numblocks: 31 }
+		}
+	}
+	};
+
+	struct DiskOnChip *this = (struct DiskOnChip *)mtd->priv;
+	unsigned long docptr = this->virtadr;
+	__u16 mfid, devid;
+	int i, j, k, interleave=1, chipsize;
+
+	// issue reset and auto-selection command
+	*(volatile unsigned short *)(FLASH_BASE) = 0xf0;
+
+	*(volatile unsigned short *)(FLASH_BASE + 0x555 * 2) = 0xaa;
+	*(volatile unsigned short *)(FLASH_BASE + 0x2aa * 2) = 0x55;
+	*(volatile unsigned short *)(FLASH_BASE + 0x555 * 2) = 0x90;
+
+	mfid = *((volatile unsigned short *)docptr);
+	devid = *((volatile unsigned short *)(docptr + 1*2));
+
+        *(volatile unsigned short *)(FLASH_BASE) = 0xf0;
+
+	for (i=0; i< sizeof(table)/sizeof(table[0]); i++) {
+		if ( mfid==table[i].mfr_id && devid==table[i].dev_id)
+			break;
+	}
+	if ( i == sizeof(table)/sizeof(table[0]) )
+		return -1;
+
+	// Look for 2nd flash
+	*(volatile unsigned short *)(FLASH_BASE + table[i].size) = 0xf0;
+	*(volatile unsigned short *)(FLASH_BASE + table[i].size + 0x555 * 2) = 0xaa;
+	*(volatile unsigned short *)(FLASH_BASE + table[i].size + 0x2aa * 2) = 0x55;
+	*(volatile unsigned short *)(FLASH_BASE + table[i].size + 0x555 * 2) = 0x90;
+
+	mfid = *((volatile unsigned short *)(docptr + table[i].size));
+	devid = *((volatile unsigned short *)(docptr + table[i].size + 1*2));
+
+	*(volatile unsigned short *)(FLASH_BASE+table[i].size) = 0xf0;
+	if ( mfid==table[i].mfr_id && devid==table[i].dev_id) {
+		interleave++;
+	}
+
+	printk(KERN_NOTICE "Found %d x %ldM Byte %s at 0x%lx\n",
+		interleave, (table[i].size)/(1024*1024), table[i].name, docptr);
+
+	mtd->size = table[i].size*interleave;
+	mtd->numeraseregions = table[i].numeraseregions*interleave;
+
+	mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
+				    mtd->numeraseregions*interleave, GFP_KERNEL);
+	if (!mtd->eraseregions) {
+		printk(KERN_WARNING "Failed to allocate "
+		       "memory for MTD erase region info\n");
+		kfree(mtd);
+		return -1;
+	}
+
+	for (k=0, chipsize=0; interleave>0; interleave--, chipsize+=table[i].size) {
+		for (j=0; j<table[i].numeraseregions; j++, k++) {
+			mtd->eraseregions[k].offset = table[i].regions[j].offset+chipsize;
+			mtd->eraseregions[k].erasesize = table[i].regions[j].erasesize;
+			mtd->eraseregions[k].numblocks = table[i].regions[j].numblocks;
+			if (mtd->erasesize < mtd->eraseregions[k].erasesize)
+				mtd->erasesize = mtd->eraseregions[k].erasesize;
+		}
+	}
+
+	this->totlen = mtd->size;
+	this->numchips = interleave;
+	this->chipshift = table[i].shift;
+
+	return 0;
+}
+//---------------------------------------------------------------------------
+#endif /*#ifdef CONFIG_RTL_819X */
+
 
 /****************************************************************************
  *
@@ -313,6 +664,14 @@ static void __init DoC_Probe(unsigned lo
 
 static int __init init_doc(void)
 {
+#ifdef CONFIG_RTL_819X
+      printk(KERN_NOTICE "RealTek E-Flash System Driver. (C) 2002 RealTek Corp.\n");
+	DoC_Probe(CONFIG_MTD_DOCPROBE_ADDRESS);
+	/* So it looks like we've been used and we get unloaded */
+//	MOD_INC_USE_COUNT;
+//	MOD_DEC_USE_COUNT;
+	return 0;
+#else
 	int i;
 
 	if (doc_config_location) {
@@ -328,6 +687,7 @@ static int __init init_doc(void)
 	if (!docfound)
 		printk(KERN_INFO "No recognised DiskOnChip devices found\n");
 	return -EAGAIN;
+#endif	
 }
 
 module_init(init_doc);
--- linux-2.6.30.9/drivers/mtd/maps/Makefile	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/maps/Makefile	2013-05-02 01:47:52.636227146 +0300
@@ -62,3 +62,4 @@ obj-$(CONFIG_MTD_INTEL_VR_NOR)	+= intel_
 obj-$(CONFIG_MTD_BFIN_ASYNC)	+= bfin-async-flash.o
 obj-$(CONFIG_MTD_RBTX4939)	+= rbtx4939-flash.o
 obj-$(CONFIG_MTD_VMU)		+= vmu-flash.o
+obj-$(CONFIG_RTL819X_SPI_FLASH) += rtl819x_flash.o
--- linux-2.6.30.9/drivers/mtd/mtdblock.c	2009-10-05 18:38:08.000000000 +0300
+++ linux-2.6.30.9-rsdk/drivers/mtd/mtdblock.c	2013-05-02 01:47:52.649227145 +0300
@@ -18,6 +18,26 @@
 #include <linux/mtd/blktrans.h>
 #include <linux/mutex.h>
 
+#include <linux/config.h>
+
+#ifdef CONFIG_RTL_819X
+// david ---------------
+//#define CONFIG_MTD_DEBUG
+#define CONFIG_MTD_DEBUG_VERBOSE 3
+
+
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+int flash_write_flag=0;		// 1: hw setting 2: default setting, 4: current setting, 8: system image
+#else
+int flash_hw_start=0x6000;	// hw setting start address
+int flash_hw_len=0x2000;	// hw setting length
+int flash_ds_start=0x8000;	// default & current setting start address
+int flash_ds_len=0x8000;	// default & current setting length
+
+int flash_write_flag=0;		// 1: hw setting 2: default setting, 4: current setting, 8: system image
+#endif
+#endif /*#ifdef CONFIG_RTL_819X */
+
 
 static struct mtdblk_dev {
 	struct mtd_info *mtd;
@@ -134,6 +154,58 @@ static int do_cached_write (struct mtdbl
 	DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n",
 		mtd->name, pos, len);
 
+	
+#ifdef CONFIG_RTL_819X
+#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE
+	/*since len is normal 0x200 less than every section*/
+	if(flash_write_flag != 0x8000) 
+	{
+		flash_write_flag = 0;
+		if ( pos >= CONFIG_RTL_HW_SETTING_OFFSET && pos < CONFIG_RTL_DEFAULT_SETTING_OFFSET ) {
+			flash_write_flag |= 1;
+			if ((pos+len) > CONFIG_RTL_DEFAULT_SETTING_OFFSET ) {
+				flash_write_flag |= 2;
+				if ((pos+len) > CONFIG_RTL_CURRENT_SETTING_OFFSET )
+					flash_write_flag |= 4;
+			}
+		}
+		if ( pos >= CONFIG_RTL_DEFAULT_SETTING_OFFSET && pos < CONFIG_RTL_CURRENT_SETTING_OFFSET ) {
+			flash_write_flag |= 2;
+			if ((pos+len) > CONFIG_RTL_CURRENT_SETTING_OFFSET ) {
+				flash_write_flag |= 4;
+			}
+		}
+		else if ( pos >= CONFIG_RTL_CURRENT_SETTING_OFFSET && pos < CONFIG_RTL_WEB_PAGES_OFFSET ){
+			flash_write_flag |= 4;
+		}
+	}
+#else
+// david --------------
+	if ( flash_write_flag != 0x8000) 
+	{
+		flash_write_flag = 0;
+		if (pos >= flash_hw_start && pos < (flash_hw_start+flash_hw_len) ) {
+			flash_write_flag |= 1;
+			if ((len - flash_hw_len) > 0) {
+				flash_write_flag |= 2;
+				if ((len - flash_ds_len -flash_hw_len) > 0)
+					flash_write_flag |= 4;
+			}
+		}
+		if (pos >= flash_ds_start && pos < (flash_ds_start+flash_ds_len) ) {
+			flash_write_flag |= 2;
+			if ((len - flash_ds_len) > 0) {
+				flash_write_flag |= 4;
+			}
+		}
+		else if ( pos >= (flash_ds_start+flash_ds_len) ){
+			flash_write_flag |= 4;
+		}
+	}
+//---------------------
+#endif //CONFIG_RTL_FLASH_MAPPING_ENABLE
+#endif
+
 	if (!sect_size)
 		return mtd->write(mtd, pos, len, &retlen, buf);