Merge remote-tracking branch 'cleancache/linux-next'
[linux-2.6/next.git] / drivers / staging / keucr / ms.h
blob4509db79298a5772389b6f8f0a934b166c359130
1 #ifndef MS_INCD
2 #define MS_INCD
4 #include <linux/blkdev.h>
5 #include "common.h"
7 // MemoryStick Register
8 // Status Register 0
9 #define MS_REG_ST0_MB 0x80 // media busy
10 #define MS_REG_ST0_FB0 0x40 // flush busy 0
11 #define MS_REG_ST0_BE 0x20 // buffer empty
12 #define MS_REG_ST0_BF 0x10 // buffer full
13 #define MS_REG_ST0_SL 0x02 // sleep
14 #define MS_REG_ST0_WP 0x01 // write protected
15 #define MS_REG_ST0_WP_ON MS_REG_ST0_WP
16 #define MS_REG_ST0_WP_OFF 0x00
18 // Status Register 1
19 #define MS_REG_ST1_MB 0x80 // media busy
20 #define MS_REG_ST1_FB1 0x40 // flush busy 1
21 #define MS_REG_ST1_DTER 0x20 // error on data(corrected)
22 #define MS_REG_ST1_UCDT 0x10 // unable to correct data
23 #define MS_REG_ST1_EXER 0x08 // error on extra(corrected)
24 #define MS_REG_ST1_UCEX 0x04 // unable to correct extra
25 #define MS_REG_ST1_FGER 0x02 // error on overwrite flag(corrected)
26 #define MS_REG_ST1_UCFG 0x01 // unable to correct overwrite flag
27 #define MS_REG_ST1_DEFAULT (MS_REG_ST1_MB | MS_REG_ST1_FB1 | \
28 MS_REG_ST1_DTER | MS_REG_ST1_UCDT | \
29 MS_REG_ST1_EXER | MS_REG_ST1_UCEX | \
30 MS_REG_ST1_FGER | MS_REG_ST1_UCFG)
32 // System Parameter
33 #define MS_REG_SYSPAR_BAMD 0x80 // block address mode
34 #define MS_REG_SYSPAR_BAND_LINEAR MS_REG_SYSPAR_BAMD // linear mode
35 #define MS_REG_SYSPAR_BAND_CHIP 0x00 // chip mode
36 #define MS_REG_SYSPAR_ATEN 0x40 // attribute ROM enable
37 #define MS_REG_SYSPAR_ATEN_ENABLE MS_REG_SYSPAR_ATEN // enable
38 #define MS_REG_SYSPAR_ATEN_DISABLE 0x00 // disable
39 #define MS_REG_SYSPAR_RESERVED 0x2f
41 // Command Parameter
42 #define MS_REG_CMDPAR_CP2 0x80
43 #define MS_REG_CMDPAR_CP1 0x40
44 #define MS_REG_CMDPAR_CP0 0x20
45 #define MS_REG_CMDPAR_BLOCK_ACCESS 0
46 #define MS_REG_CMDPAR_PAGE_ACCESS MS_REG_CMDPAR_CP0
47 #define MS_REG_CMDPAR_EXTRA_DATA MS_REG_CMDPAR_CP1
48 #define MS_REG_CMDPAR_OVERWRITE MS_REG_CMDPAR_CP2
49 #define MS_REG_CMDPAR_RESERVED 0x1f
51 // Overwrite Area
52 #define MS_REG_OVR_BKST 0x80 // block status
53 #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST // OK
54 #define MS_REG_OVR_BKST_NG 0x00 // NG
55 #define MS_REG_OVR_PGST0 0x40 // page status
56 #define MS_REG_OVR_PGST1 0x20
57 #define MS_REG_OVR_PGST_MASK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1)
58 #define MS_REG_OVR_PGST_OK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1) // OK
59 #define MS_REG_OVR_PGST_NG MS_REG_OVR_PGST1 // NG
60 #define MS_REG_OVR_PGST_DATA_ERROR 0x00 // data error
61 #define MS_REG_OVR_UDST 0x10 // update status
62 #define MS_REG_OVR_UDST_UPDATING 0x00 // updating
63 #define MS_REG_OVR_UDST_NO_UPDATE MS_REG_OVR_UDST
64 #define MS_REG_OVR_RESERVED 0x08
65 #define MS_REG_OVR_DEFAULT (MS_REG_OVR_BKST_OK | \
66 MS_REG_OVR_PGST_OK | \
67 MS_REG_OVR_UDST_NO_UPDATE | \
68 MS_REG_OVR_RESERVED)
69 // Management Flag
70 #define MS_REG_MNG_SCMS0 0x20 // serial copy management system
71 #define MS_REG_MNG_SCMS1 0x10
72 #define MS_REG_MNG_SCMS_MASK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
73 #define MS_REG_MNG_SCMS_COPY_OK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
74 #define MS_REG_MNG_SCMS_ONE_COPY MS_REG_MNG_SCMS1
75 #define MS_REG_MNG_SCMS_NO_COPY 0x00
76 #define MS_REG_MNG_ATFLG 0x08 // address transfer table flag
77 #define MS_REG_MNG_ATFLG_OTHER MS_REG_MNG_ATFLG // other
78 #define MS_REG_MNG_ATFLG_ATTBL 0x00 // address transfer table
79 #define MS_REG_MNG_SYSFLG 0x04 // system flag
80 #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG // user block
81 #define MS_REG_MNG_SYSFLG_BOOT 0x00 // system block
82 #define MS_REG_MNG_RESERVED 0xc3
83 #define MS_REG_MNG_DEFAULT (MS_REG_MNG_SCMS_COPY_OK | \
84 MS_REG_MNG_ATFLG_OTHER | \
85 MS_REG_MNG_SYSFLG_USER | \
86 MS_REG_MNG_RESERVED)
88 // Error codes
89 #define MS_STATUS_SUCCESS 0x0000
90 #define MS_ERROR_OUT_OF_SPACE 0x0103
91 #define MS_STATUS_WRITE_PROTECT 0x0106
92 #define MS_ERROR_READ_DATA 0x8002
93 #define MS_ERROR_FLASH_READ 0x8003
94 #define MS_ERROR_FLASH_WRITE 0x8004
95 #define MS_ERROR_FLASH_ERASE 0x8005
96 #define MS_ERROR_FLASH_COPY 0x8006
98 #define MS_STATUS_ERROR 0xfffe
99 #define MS_FIFO_ERROR 0xfffd
100 #define MS_UNDEFINED_ERROR 0xfffc
101 #define MS_KETIMEOUT_ERROR 0xfffb
102 #define MS_STATUS_INT_ERROR 0xfffa
103 #define MS_NO_MEMORY_ERROR 0xfff9
104 #define MS_NOCARD_ERROR 0xfff8
105 #define MS_LB_NOT_USED 0xffff
106 #define MS_LB_ERROR 0xfff0
107 #define MS_LB_BOOT_BLOCK 0xfff1
108 #define MS_LB_INITIAL_ERROR 0xfff2
109 #define MS_STATUS_SUCCESS_WITH_ECC 0xfff3
110 #define MS_LB_ACQUIRED_ERROR 0xfff4
111 #define MS_LB_NOT_USED_ERASED 0xfff5
113 #define MS_LibConv2Physical(pdx, LogBlock) (((LogBlock) >= (pdx)->MS_Lib.NumberOfLogBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Log2PhyMap[LogBlock])
114 #define MS_LibConv2Logical(pdx, PhyBlock) (((PhyBlock) >= (pdx)->MS_Lib.NumberOfPhyBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Phy2LogMap[PhyBlock]) //¬dphy->log table
116 #define MS_LIB_CTRL_RDONLY 0
117 #define MS_LIB_CTRL_WRPROTECT 1
118 #define MS_LibCtrlCheck(pdx, Flag) ((pdx)->MS_Lib.flags & (1 << (Flag)))
120 #define MS_LibCtrlSet(pdx, Flag) (pdx)->MS_Lib.flags |= (1 << (Flag))
121 #define MS_LibCtrlReset(pdx, Flag) (pdx)->MS_Lib.flags &= ~(1 << (Flag))
122 #define MS_LibIsWritable(pdx) ((MS_LibCtrlCheck((pdx), MS_LIB_CTRL_RDONLY) == 0) && (MS_LibCtrlCheck(pdx, MS_LIB_CTRL_WRPROTECT) == 0))
124 #define MS_MAX_PAGES_PER_BLOCK 32
125 #define MS_LIB_BITS_PER_BYTE 8
127 #define MS_LibPageMapIdx(n) ((n) / MS_LIB_BITS_PER_BYTE)
128 #define MS_LibPageMapBit(n) (1 << ((n) % MS_LIB_BITS_PER_BYTE))
129 #define MS_LibCheckPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] & MS_LibPageMapBit(n))
130 #define MS_LibSetPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] |= MS_LibPageMapBit(n))
131 #define MS_LibResetPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] &= ~MS_LibPageMapBit(n))
132 #define MS_LibClearPageMap(pdx) memset((pdx)->MS_Lib.pagemap, 0, sizeof((pdx)->MS_Lib.pagemap))
135 #define MemStickLogAddr(logadr1, logadr0) ((((WORD)(logadr1)) << 8) | (logadr0))
137 #define MS_BYTES_PER_PAGE 512
139 #define MS_MAX_INITIAL_ERROR_BLOCKS 10
140 #define MS_NUMBER_OF_PAGES_FOR_BOOT_BLOCK 3
141 #define MS_NUMBER_OF_PAGES_FOR_LPCTBL 2
143 #define MS_NUMBER_OF_BOOT_BLOCK 2
144 #define MS_NUMBER_OF_SYSTEM_BLOCK 4
145 #define MS_LOGICAL_BLOCKS_PER_SEGMENT 496
146 #define MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT 494
147 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT 0x200 // 512
148 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK 0x1ff
150 #define MS_SECTOR_SIZE 512
151 #define MBR_SIGNATURE 0xAA55
152 #define PBR_SIGNATURE 0xAA55
154 #define PARTITION_FAT_12 1
155 #define PARTITION_FAT_16 2
157 #define MS_BOOT_BLOCK_ID 0x0001
158 #define MS_BOOT_BLOCK_FORMAT_VERSION 0x0100
159 #define MS_BOOT_BLOCK_DATA_ENTRIES 2
161 #define MS_SYSINF_MSCLASS_TYPE_1 1
162 #define MS_SYSINF_CARDTYPE_RDONLY 1
163 #define MS_SYSINF_CARDTYPE_RDWR 2
164 #define MS_SYSINF_CARDTYPE_HYBRID 3
165 #define MS_SYSINF_SECURITY 0x01
166 #define MS_SYSINF_SECURITY_NO_SUPPORT MS_SYSINF_SECURITY
167 #define MS_SYSINF_SECURITY_SUPPORT 0
168 #define MS_SYSINF_FORMAT_MAT 0 // ?
169 #define MS_SYSINF_FORMAT_FAT 1
170 #define MS_SYSINF_USAGE_GENERAL 0
171 #define MS_SYSINF_PAGE_SIZE MS_BYTES_PER_PAGE // fixed
172 #define MS_SYSINF_RESERVED1 1
173 #define MS_SYSINF_RESERVED2 1
175 #define MS_SYSENT_TYPE_INVALID_BLOCK 0x01
176 #define MS_SYSENT_TYPE_CIS_IDI 0x0a // CIS/IDI
178 #define SIZE_OF_KIRO 1024
180 // BOOT BLOCK
181 #define MS_NUMBER_OF_SYSTEM_ENTRY 4
183 //----- MemStickRegisters --------------------------------------------
184 // Status registers (16 bytes)
185 typedef struct {
186 BYTE Reserved0; // 00
187 BYTE INTRegister; // 01
188 BYTE StatusRegister0; // 02
189 BYTE StatusRegister1; // 03
190 BYTE Reserved1[12]; // 04-0F
191 } MemStickStatusRegisters;
193 // Parameter registers (6 bytes)
194 typedef struct {
195 BYTE SystemParameter; // 10
196 BYTE BlockAddress2; // 11
197 BYTE BlockAddress1; // 12
198 BYTE BlockAddress0; // 13
199 BYTE CMDParameter; // 14
200 BYTE PageAddress; // 15
201 } MemStickParameterRegisters;
203 // Extra registers (9 bytes)
204 typedef struct {
205 BYTE OverwriteFlag; // 16
206 BYTE ManagementFlag; // 17
207 BYTE LogicalAddress1; // 18
208 BYTE LogicalAddress0; // 19
209 BYTE ReservedArea[5]; // 1A-1E
210 } MemStickExtraDataRegisters;
212 // All registers in Memory Stick (32 bytes, includes 1 byte padding)
213 typedef struct {
214 MemStickStatusRegisters status;
215 MemStickParameterRegisters param;
216 MemStickExtraDataRegisters extra;
217 BYTE padding;
218 } MemStickRegisters, *PMemStickRegisters;
220 //----- MemStickBootBlockPage0 ---------------------------------------
221 typedef struct {
222 WORD wBlockID;
223 WORD wFormatVersion;
224 BYTE bReserved1[184];
225 BYTE bNumberOfDataEntry;
226 BYTE bReserved2[179];
227 } MemStickBootBlockHeader;
229 typedef struct {
230 DWORD dwStart;
231 DWORD dwSize;
232 BYTE bType;
233 BYTE bReserved[3];
234 } MemStickBootBlockSysEntRec;
236 typedef struct {
237 MemStickBootBlockSysEntRec entry[MS_NUMBER_OF_SYSTEM_ENTRY];
238 } MemStickBootBlockSysEnt;
240 typedef struct {
241 BYTE bMsClass; // must be 1
242 BYTE bCardType; // see below
243 WORD wBlockSize; // n KB
244 WORD wBlockNumber; // number of physical block
245 WORD wTotalBlockNumber; // number of logical block
246 WORD wPageSize; // must be 0x200
247 BYTE bExtraSize; // 0x10
248 BYTE bSecuritySupport;
249 BYTE bAssemblyDate[8];
250 BYTE bFactoryArea[4];
251 BYTE bAssemblyMakerCode;
252 BYTE bAssemblyMachineCode[3];
253 WORD wMemoryMakerCode;
254 WORD wMemoryDeviceCode;
255 WORD wMemorySize;
256 BYTE bReserved1;
257 BYTE bReserved2;
258 BYTE bVCC;
259 BYTE bVPP;
260 WORD wControllerChipNumber;
261 WORD wControllerFunction; // New MS
262 BYTE bReserved3[9]; // New MS
263 BYTE bParallelSupport; // New MS
264 WORD wFormatValue; // New MS
265 BYTE bFormatType;
266 BYTE bUsage;
267 BYTE bDeviceType;
268 BYTE bReserved4[22];
269 BYTE bFUValue3;
270 BYTE bFUValue4;
271 BYTE bReserved5[15];
272 } MemStickBootBlockSysInf;
274 typedef struct {
275 MemStickBootBlockHeader header;
276 MemStickBootBlockSysEnt sysent;
277 MemStickBootBlockSysInf sysinf;
278 } MemStickBootBlockPage0;
280 //----- MemStickBootBlockCIS_IDI -------------------------------------
281 typedef struct {
282 BYTE bCistplDEVICE[6]; // 0
283 BYTE bCistplDEVICE0C[6]; // 6
284 BYTE bCistplJEDECC[4]; // 12
285 BYTE bCistplMANFID[6]; // 16
286 BYTE bCistplVER1[32]; // 22
287 BYTE bCistplFUNCID[4]; // 54
288 BYTE bCistplFUNCE0[4]; // 58
289 BYTE bCistplFUNCE1[5]; // 62
290 BYTE bCistplCONF[7]; // 67
291 BYTE bCistplCFTBLENT0[10]; // 74
292 BYTE bCistplCFTBLENT1[8]; // 84
293 BYTE bCistplCFTBLENT2[12]; // 92
294 BYTE bCistplCFTBLENT3[8]; // 104
295 BYTE bCistplCFTBLENT4[17]; // 112
296 BYTE bCistplCFTBLENT5[8]; // 129
297 BYTE bCistplCFTBLENT6[17]; // 137
298 BYTE bCistplCFTBLENT7[8]; // 154
299 BYTE bCistplNOLINK[3]; // 162
300 } MemStickBootBlockCIS;
302 typedef struct {
303 #define MS_IDI_GENERAL_CONF 0x848A
304 WORD wIDIgeneralConfiguration; // 0
305 WORD wIDInumberOfCylinder; // 1
306 WORD wIDIreserved0; // 2
307 WORD wIDInumberOfHead; // 3
308 WORD wIDIbytesPerTrack; // 4
309 WORD wIDIbytesPerSector; // 5
310 WORD wIDIsectorsPerTrack; // 6
311 WORD wIDItotalSectors[2]; // 7-8 high,low
312 WORD wIDIreserved1[11]; // 9-19
313 WORD wIDIbufferType; // 20
314 WORD wIDIbufferSize; // 21
315 WORD wIDIlongCmdECC; // 22
316 WORD wIDIfirmVersion[4]; // 23-26
317 WORD wIDImodelName[20]; // 27-46
318 WORD wIDIreserved2; // 47
319 WORD wIDIlongWordSupported; // 48
320 WORD wIDIdmaSupported; // 49
321 WORD wIDIreserved3; // 50
322 WORD wIDIpioTiming; // 51
323 WORD wIDIdmaTiming; // 52
324 WORD wIDItransferParameter; // 53
325 WORD wIDIformattedCylinder; // 54
326 WORD wIDIformattedHead; // 55
327 WORD wIDIformattedSectorsPerTrack; // 56
328 WORD wIDIformattedTotalSectors[2]; // 57-58
329 WORD wIDImultiSector; // 59
330 WORD wIDIlbaSectors[2]; // 60-61
331 WORD wIDIsingleWordDMA; // 62
332 WORD wIDImultiWordDMA; // 63
333 WORD wIDIreserved4[192]; // 64-255
334 } MemStickBootBlockIDI;
336 typedef struct {
337 union {
338 MemStickBootBlockCIS cis;
339 BYTE dmy[256];
340 } cis;
342 union {
343 MemStickBootBlockIDI idi;
344 BYTE dmy[256];
345 } idi;
347 } MemStickBootBlockCIS_IDI;
349 //----- MS_LibControl ------------------------------------------------
350 typedef struct {
351 BYTE reserved;
352 BYTE intr;
353 BYTE status0;
354 BYTE status1;
355 BYTE ovrflg;
356 BYTE mngflg;
357 WORD logadr;
358 } MS_LibTypeExtdat;
360 typedef struct {
361 DWORD flags;
362 DWORD BytesPerSector;
363 DWORD NumberOfCylinder;
364 DWORD SectorsPerCylinder;
365 WORD cardType; // R/W, RO, Hybrid
366 WORD blockSize;
367 WORD PagesPerBlock;
368 WORD NumberOfPhyBlock;
369 WORD NumberOfLogBlock;
370 WORD NumberOfSegment;
371 WORD *Phy2LogMap; // phy2log table
372 WORD *Log2PhyMap; // log2phy table
373 WORD wrtblk;
374 BYTE pagemap[(MS_MAX_PAGES_PER_BLOCK + (MS_LIB_BITS_PER_BYTE-1)) /
375 MS_LIB_BITS_PER_BYTE];
376 BYTE *blkpag;
377 MS_LibTypeExtdat *blkext;
378 BYTE copybuf[512];
379 } MS_LibControl;
381 #endif