staging/keucr: fix keucr ms coding style
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / keucr / ms.h
bloba3da4be3f55623e523ff1516d4fb40cd63c056d0
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) \
114 (((LogBlock) >= (pdx)->MS_Lib.NumberOfLogBlock) ? \
115 MS_STATUS_ERROR : (pdx)->MS_Lib.Log2PhyMap[LogBlock])
116 #define MS_LibConv2Logical(pdx, PhyBlock) \
117 (((PhyBlock) >= (pdx)->MS_Lib.NumberOfPhyBlock) ? \
118 MS_STATUS_ERROR : (pdx)->MS_Lib.Phy2LogMap[PhyBlock])
119 /*dphy->log table */
121 #define MS_LIB_CTRL_RDONLY 0
122 #define MS_LIB_CTRL_WRPROTECT 1
123 #define MS_LibCtrlCheck(pdx, Flag) ((pdx)->MS_Lib.flags & (1 << (Flag)))
125 #define MS_LibCtrlSet(pdx, Flag) ((pdx)->MS_Lib.flags |= (1 << (Flag)))
126 #define MS_LibCtrlReset(pdx, Flag) ((pdx)->MS_Lib.flags &= ~(1 << (Flag)))
127 #define MS_LibIsWritable(pdx) \
128 ((MS_LibCtrlCheck((pdx), MS_LIB_CTRL_RDONLY) == 0) && \
129 (MS_LibCtrlCheck(pdx, MS_LIB_CTRL_WRPROTECT) == 0))
131 #define MS_MAX_PAGES_PER_BLOCK 32
132 #define MS_LIB_BITS_PER_BYTE 8
134 #define MS_LibPageMapIdx(n) ((n) / MS_LIB_BITS_PER_BYTE)
135 #define MS_LibPageMapBit(n) (1 << ((n) % MS_LIB_BITS_PER_BYTE))
136 #define MS_LibCheckPageMapBit(pdx, n) \
137 ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] & MS_LibPageMapBit(n))
138 #define MS_LibSetPageMapBit(pdx, n) \
139 ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] |= MS_LibPageMapBit(n))
140 #define MS_LibResetPageMapBit(pdx, n) \
141 ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] &= ~MS_LibPageMapBit(n))
142 #define MS_LibClearPageMap(pdx) \
143 memset((pdx)->MS_Lib.pagemap, 0, sizeof((pdx)->MS_Lib.pagemap))
146 #define MemStickLogAddr(logadr1, logadr0) \
147 ((((WORD)(logadr1)) << 8) | (logadr0))
149 #define MS_BYTES_PER_PAGE 512
151 #define MS_MAX_INITIAL_ERROR_BLOCKS 10
152 #define MS_NUMBER_OF_PAGES_FOR_BOOT_BLOCK 3
153 #define MS_NUMBER_OF_PAGES_FOR_LPCTBL 2
155 #define MS_NUMBER_OF_BOOT_BLOCK 2
156 #define MS_NUMBER_OF_SYSTEM_BLOCK 4
157 #define MS_LOGICAL_BLOCKS_PER_SEGMENT 496
158 #define MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT 494
159 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT 0x200 /* 512 */
160 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK 0x1ff
162 #define MS_SECTOR_SIZE 512
163 #define MBR_SIGNATURE 0xAA55
164 #define PBR_SIGNATURE 0xAA55
166 #define PARTITION_FAT_12 1
167 #define PARTITION_FAT_16 2
169 #define MS_BOOT_BLOCK_ID 0x0001
170 #define MS_BOOT_BLOCK_FORMAT_VERSION 0x0100
171 #define MS_BOOT_BLOCK_DATA_ENTRIES 2
173 #define MS_SYSINF_MSCLASS_TYPE_1 1
174 #define MS_SYSINF_CARDTYPE_RDONLY 1
175 #define MS_SYSINF_CARDTYPE_RDWR 2
176 #define MS_SYSINF_CARDTYPE_HYBRID 3
177 #define MS_SYSINF_SECURITY 0x01
178 #define MS_SYSINF_SECURITY_NO_SUPPORT MS_SYSINF_SECURITY
179 #define MS_SYSINF_SECURITY_SUPPORT 0
180 #define MS_SYSINF_FORMAT_MAT 0 /* ? */
181 #define MS_SYSINF_FORMAT_FAT 1
182 #define MS_SYSINF_USAGE_GENERAL 0
183 #define MS_SYSINF_PAGE_SIZE MS_BYTES_PER_PAGE /* fixed */
184 #define MS_SYSINF_RESERVED1 1
185 #define MS_SYSINF_RESERVED2 1
187 #define MS_SYSENT_TYPE_INVALID_BLOCK 0x01
188 #define MS_SYSENT_TYPE_CIS_IDI 0x0a /* CIS/IDI */
190 #define SIZE_OF_KIRO 1024
192 /* BOOT BLOCK */
193 #define MS_NUMBER_OF_SYSTEM_ENTRY 4
196 * MemStickRegisters
198 /* Status registers (16 bytes) */
199 typedef struct {
200 BYTE Reserved0; /* 00 */
201 BYTE INTRegister; /* 01 */
202 BYTE StatusRegister0; /* 02 */
203 BYTE StatusRegister1; /* 03 */
204 BYTE Reserved1[12]; /* 04-0F */
205 } MemStickStatusRegisters;
207 /* Parameter registers (6 bytes) */
208 typedef struct {
209 BYTE SystemParameter; /* 10 */
210 BYTE BlockAddress2; /* 11 */
211 BYTE BlockAddress1; /* 12 */
212 BYTE BlockAddress0; /* 13 */
213 BYTE CMDParameter; /* 14 */
214 BYTE PageAddress; /* 15 */
215 } MemStickParameterRegisters;
217 /* Extra registers (9 bytes) */
218 typedef struct {
219 BYTE OverwriteFlag; /* 16 */
220 BYTE ManagementFlag; /* 17 */
221 BYTE LogicalAddress1; /* 18 */
222 BYTE LogicalAddress0; /* 19 */
223 BYTE ReservedArea[5]; /* 1A-1E */
224 } MemStickExtraDataRegisters;
226 /* All registers in Memory Stick (32 bytes, includes 1 byte padding) */
227 typedef struct {
228 MemStickStatusRegisters status;
229 MemStickParameterRegisters param;
230 MemStickExtraDataRegisters extra;
231 BYTE padding;
232 } MemStickRegisters, *PMemStickRegisters;
235 * MemStickBootBlockPage0
237 typedef struct {
238 WORD wBlockID;
239 WORD wFormatVersion;
240 BYTE bReserved1[184];
241 BYTE bNumberOfDataEntry;
242 BYTE bReserved2[179];
243 } MemStickBootBlockHeader;
245 typedef struct {
246 DWORD dwStart;
247 DWORD dwSize;
248 BYTE bType;
249 BYTE bReserved[3];
250 } MemStickBootBlockSysEntRec;
252 typedef struct {
253 MemStickBootBlockSysEntRec entry[MS_NUMBER_OF_SYSTEM_ENTRY];
254 } MemStickBootBlockSysEnt;
256 typedef struct {
257 BYTE bMsClass; /* must be 1 */
258 BYTE bCardType; /* see below */
259 WORD wBlockSize; /* n KB */
260 WORD wBlockNumber; /* number of physical block */
261 WORD wTotalBlockNumber; /* number of logical block */
262 WORD wPageSize; /* must be 0x200 */
263 BYTE bExtraSize; /* 0x10 */
264 BYTE bSecuritySupport;
265 BYTE bAssemblyDate[8];
266 BYTE bFactoryArea[4];
267 BYTE bAssemblyMakerCode;
268 BYTE bAssemblyMachineCode[3];
269 WORD wMemoryMakerCode;
270 WORD wMemoryDeviceCode;
271 WORD wMemorySize;
272 BYTE bReserved1;
273 BYTE bReserved2;
274 BYTE bVCC;
275 BYTE bVPP;
276 WORD wControllerChipNumber;
277 WORD wControllerFunction; /* New MS */
278 BYTE bReserved3[9]; /* New MS */
279 BYTE bParallelSupport; /* New MS */
280 WORD wFormatValue; /* New MS */
281 BYTE bFormatType;
282 BYTE bUsage;
283 BYTE bDeviceType;
284 BYTE bReserved4[22];
285 BYTE bFUValue3;
286 BYTE bFUValue4;
287 BYTE bReserved5[15];
288 } MemStickBootBlockSysInf;
290 typedef struct {
291 MemStickBootBlockHeader header;
292 MemStickBootBlockSysEnt sysent;
293 MemStickBootBlockSysInf sysinf;
294 } MemStickBootBlockPage0;
297 * MemStickBootBlockCIS_IDI
299 typedef struct {
300 BYTE bCistplDEVICE[6]; /* 0 */
301 BYTE bCistplDEVICE0C[6]; /* 6 */
302 BYTE bCistplJEDECC[4]; /* 12 */
303 BYTE bCistplMANFID[6]; /* 16 */
304 BYTE bCistplVER1[32]; /* 22 */
305 BYTE bCistplFUNCID[4]; /* 54 */
306 BYTE bCistplFUNCE0[4]; /* 58 */
307 BYTE bCistplFUNCE1[5]; /* 62 */
308 BYTE bCistplCONF[7]; /* 67 */
309 BYTE bCistplCFTBLENT0[10]; /* 74 */
310 BYTE bCistplCFTBLENT1[8]; /* 84 */
311 BYTE bCistplCFTBLENT2[12]; /* 92 */
312 BYTE bCistplCFTBLENT3[8]; /* 104 */
313 BYTE bCistplCFTBLENT4[17]; /* 112 */
314 BYTE bCistplCFTBLENT5[8]; /* 129 */
315 BYTE bCistplCFTBLENT6[17]; /* 137 */
316 BYTE bCistplCFTBLENT7[8]; /* 154 */
317 BYTE bCistplNOLINK[3]; /* 162 */
318 } MemStickBootBlockCIS;
320 typedef struct {
321 #define MS_IDI_GENERAL_CONF 0x848A
322 WORD wIDIgeneralConfiguration; /* 0 */
323 WORD wIDInumberOfCylinder; /* 1 */
324 WORD wIDIreserved0; /* 2 */
325 WORD wIDInumberOfHead; /* 3 */
326 WORD wIDIbytesPerTrack; /* 4 */
327 WORD wIDIbytesPerSector; /* 5 */
328 WORD wIDIsectorsPerTrack; /* 6 */
329 WORD wIDItotalSectors[2]; /* 7-8 high,low */
330 WORD wIDIreserved1[11]; /* 9-19 */
331 WORD wIDIbufferType; /* 20 */
332 WORD wIDIbufferSize; /* 21 */
333 WORD wIDIlongCmdECC; /* 22 */
334 WORD wIDIfirmVersion[4]; /* 23-26 */
335 WORD wIDImodelName[20]; /* 27-46 */
336 WORD wIDIreserved2; /* 47 */
337 WORD wIDIlongWordSupported; /* 48 */
338 WORD wIDIdmaSupported; /* 49 */
339 WORD wIDIreserved3; /* 50 */
340 WORD wIDIpioTiming; /* 51 */
341 WORD wIDIdmaTiming; /* 52 */
342 WORD wIDItransferParameter; /* 53 */
343 WORD wIDIformattedCylinder; /* 54 */
344 WORD wIDIformattedHead; /* 55 */
345 WORD wIDIformattedSectorsPerTrack; /* 56 */
346 WORD wIDIformattedTotalSectors[2]; /* 57-58 */
347 WORD wIDImultiSector; /* 59 */
348 WORD wIDIlbaSectors[2]; /* 60-61 */
349 WORD wIDIsingleWordDMA; /* 62 */
350 WORD wIDImultiWordDMA; /* 63 */
351 WORD wIDIreserved4[192]; /* 64-255 */
352 } MemStickBootBlockIDI;
354 typedef struct {
355 union {
356 MemStickBootBlockCIS cis;
357 BYTE dmy[256];
358 } cis;
360 union {
361 MemStickBootBlockIDI idi;
362 BYTE dmy[256];
363 } idi;
365 } MemStickBootBlockCIS_IDI;
368 * MS_LibControl
370 typedef struct {
371 BYTE reserved;
372 BYTE intr;
373 BYTE status0;
374 BYTE status1;
375 BYTE ovrflg;
376 BYTE mngflg;
377 WORD logadr;
378 } MS_LibTypeExtdat;
380 typedef struct {
381 DWORD flags;
382 DWORD BytesPerSector;
383 DWORD NumberOfCylinder;
384 DWORD SectorsPerCylinder;
385 WORD cardType; /* R/W, RO, Hybrid */
386 WORD blockSize;
387 WORD PagesPerBlock;
388 WORD NumberOfPhyBlock;
389 WORD NumberOfLogBlock;
390 WORD NumberOfSegment;
391 WORD *Phy2LogMap; /* phy2log table */
392 WORD *Log2PhyMap; /* log2phy table */
393 WORD wrtblk;
394 BYTE pagemap[(MS_MAX_PAGES_PER_BLOCK + (MS_LIB_BITS_PER_BYTE-1)) /
395 MS_LIB_BITS_PER_BYTE];
396 BYTE *blkpag;
397 MS_LibTypeExtdat *blkext;
398 BYTE copybuf[512];
399 } MS_LibControl;
401 #endif