1 
2 /* Linux driver for Disk-On-Chip 2000       */
3 /* (c) 1999 Machine Vision Holdings, Inc.   */
4 /* Author: David Woodhouse <dwmw2@mvhi.com> */
5 /* $Id: doc2000.h,v 1.15 2001/09/19 00:22:15 dwmw2 Exp $ */
6 
7 #ifndef __MTD_DOC2000_H__
8 #define __MTD_DOC2000_H__
9 
10 #include <linux/mtd/mtd.h>
11 
12 #define DoC_Sig1 0
13 #define DoC_Sig2 1
14 
15 #define DoC_ChipID		0x1000
16 #define DoC_DOCStatus		0x1001
17 #define DoC_DOCControl		0x1002
18 #define DoC_FloorSelect		0x1003
19 #define DoC_CDSNControl		0x1004
20 #define DoC_CDSNDeviceSelect 	0x1005
21 #define DoC_ECCConf 		0x1006
22 #define DoC_2k_ECCStatus	0x1007
23 
24 #define DoC_CDSNSlowIO		0x100d
25 #define DoC_ECCSyndrome0	0x1010
26 #define DoC_ECCSyndrome1	0x1011
27 #define DoC_ECCSyndrome2	0x1012
28 #define DoC_ECCSyndrome3	0x1013
29 #define DoC_ECCSyndrome4	0x1014
30 #define DoC_ECCSyndrome5	0x1015
31 #define DoC_AliasResolution 	0x101b
32 #define DoC_ConfigInput		0x101c
33 #define DoC_ReadPipeInit 	0x101d
34 #define DoC_WritePipeTerm 	0x101e
35 #define DoC_LastDataRead 	0x101f
36 #define DoC_NOP 		0x1020
37 
38 #define DoC_Mil_CDSN_IO 	0x0800
39 #define DoC_2k_CDSN_IO 		0x1800
40 
41 /* How to access the device?
42  * On ARM, it'll be mmap'd directly with 32-bit wide accesses.
43  * On PPC, it's mmap'd and 16-bit wide.
44  * Others use readb/writeb
45  */
46 #if defined(__arm__)
47 #define ReadDOC_(adr, reg)      ((unsigned char)(*(__u32 *)(((unsigned long)adr)+((reg)<<2))))
48 #define WriteDOC_(d, adr, reg)  do{ *(__u32 *)(((unsigned long)adr)+((reg)<<2)) = (__u32)d; wmb();} while(0)
49 #define DOC_IOREMAP_LEN 0x8000
50 #elif defined(__ppc__)
51 #define ReadDOC_(adr, reg)      ((unsigned char)(*(__u16 *)(((unsigned long)adr)+((reg)<<1))))
52 #define WriteDOC_(d, adr, reg)  do{ *(__u16 *)(((unsigned long)adr)+((reg)<<1)) = (__u16)d; wmb();} while(0)
53 #define DOC_IOREMAP_LEN 0x4000
54 #else
55 #define ReadDOC_(adr, reg)      readb(((unsigned long)adr) + (reg))
56 #define WriteDOC_(d, adr, reg)  writeb(d, ((unsigned long)adr) + (reg))
57 #define DOC_IOREMAP_LEN 0x2000
58 
59 #endif
60 
61 #if defined(__i386__) || defined(__x86_64__)
62 #define USE_MEMCPY
63 #endif
64 
65 /* These are provided to directly use the DoC_xxx defines */
66 #define ReadDOC(adr, reg)      ReadDOC_(adr,DoC_##reg)
67 #define WriteDOC(d, adr, reg)  WriteDOC_(d,adr,DoC_##reg)
68 
69 #define DOC_MODE_RESET 		0
70 #define DOC_MODE_NORMAL 	1
71 #define DOC_MODE_RESERVED1 	2
72 #define DOC_MODE_RESERVED2 	3
73 
74 #define DOC_MODE_MDWREN 	4
75 #define DOC_MODE_CLR_ERR 	0x80
76 
77 #define DOC_ChipID_Doc2k 	0x20
78 #define DOC_ChipID_DocMil 	0x30
79 
80 #define CDSN_CTRL_FR_B 		0x80
81 #define CDSN_CTRL_ECC_IO 	0x20
82 #define CDSN_CTRL_FLASH_IO 	0x10
83 #define CDSN_CTRL_WP 		0x08
84 #define CDSN_CTRL_ALE 		0x04
85 #define CDSN_CTRL_CLE 		0x02
86 #define CDSN_CTRL_CE 		0x01
87 
88 #define DOC_ECC_RESET 		0
89 #define DOC_ECC_ERROR 		0x80
90 #define DOC_ECC_RW 		0x20
91 #define DOC_ECC__EN 		0x08
92 #define DOC_TOGGLE_BIT 		0x04
93 #define DOC_ECC_RESV 		0x02
94 #define DOC_ECC_IGNORE		0x01
95 
96 /* We have to also set the reserved bit 1 for enable */
97 #define DOC_ECC_EN (DOC_ECC__EN | DOC_ECC_RESV)
98 #define DOC_ECC_DIS (DOC_ECC_RESV)
99 
100 struct Nand {
101 	char floor, chip;
102 	unsigned long curadr;
103 	unsigned char curmode;
104 	/* Also some erase/write/pipeline info when we get that far */
105 };
106 
107 #define MAX_FLOORS 4
108 #define MAX_CHIPS 4
109 
110 #define MAX_FLOORS_MIL 4
111 #define MAX_CHIPS_MIL 1
112 
113 #define ADDR_COLUMN 1
114 #define ADDR_PAGE 2
115 #define ADDR_COLUMN_PAGE 3
116 
117 struct DiskOnChip {
118 	unsigned long physadr;
119 	unsigned long virtadr;
120 	unsigned long totlen;
121 	char ChipID; /* Type of DiskOnChip */
122 	int ioreg;
123 
124 	unsigned long mfr; /* Flash IDs - only one type of flash per device */
125 	unsigned long id;
126 	int chipshift;
127 	char page256;
128 	char pageadrlen;
129 	unsigned long erasesize;
130 
131 	int curfloor;
132 	int curchip;
133 
134 	int numchips;
135 	struct Nand *chips;
136 	struct mtd_info *nextdoc;
137 	struct semaphore lock;
138 };
139 
140 int doc_decode_ecc(unsigned char sector[512], unsigned char ecc1[6]);
141 
142 #endif /* __MTD_DOC2000_H__ */
143