blob: a3cfe6bdd9def539cbf06d21975b7a04b4879d38 [file] [log] [blame]
William Juulcfa460a2007-10-31 13:53:06 +01001/*
2 * Linux driver for Disk-On-Chip devices
3 *
Tom Rini78e9e712015-10-23 09:37:47 -04004 * Copyright © 1999 Machine Vision Holdings, Inc.
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2002-2003 Greg Ungerer <gerg@snapgear.com>
7 * Copyright © 2002-2003 SnapGear Inc
William Juulcfa460a2007-10-31 13:53:06 +01008 *
Tom Rini78e9e712015-10-23 09:37:47 -04009 * SPDX-License-Identifier: GPL-2.0+
10 *
William Juulcfa460a2007-10-31 13:53:06 +010011 */
wdenk012771d2002-03-08 21:31:05 +000012
13#ifndef __MTD_DOC2000_H__
14#define __MTD_DOC2000_H__
15
William Juulcfa460a2007-10-31 13:53:06 +010016#include <linux/mtd/mtd.h>
17#if 0
18#include <linux/mutex.h>
19#endif
wdenk012771d2002-03-08 21:31:05 +000020
21#define DoC_Sig1 0
22#define DoC_Sig2 1
23
24#define DoC_ChipID 0x1000
25#define DoC_DOCStatus 0x1001
26#define DoC_DOCControl 0x1002
27#define DoC_FloorSelect 0x1003
28#define DoC_CDSNControl 0x1004
Wolfgang Denk53677ef2008-05-20 16:00:29 +020029#define DoC_CDSNDeviceSelect 0x1005
30#define DoC_ECCConf 0x1006
wdenk012771d2002-03-08 21:31:05 +000031#define DoC_2k_ECCStatus 0x1007
32
33#define DoC_CDSNSlowIO 0x100d
34#define DoC_ECCSyndrome0 0x1010
35#define DoC_ECCSyndrome1 0x1011
36#define DoC_ECCSyndrome2 0x1012
37#define DoC_ECCSyndrome3 0x1013
38#define DoC_ECCSyndrome4 0x1014
39#define DoC_ECCSyndrome5 0x1015
Wolfgang Denk53677ef2008-05-20 16:00:29 +020040#define DoC_AliasResolution 0x101b
wdenk012771d2002-03-08 21:31:05 +000041#define DoC_ConfigInput 0x101c
Wolfgang Denk53677ef2008-05-20 16:00:29 +020042#define DoC_ReadPipeInit 0x101d
43#define DoC_WritePipeTerm 0x101e
44#define DoC_LastDataRead 0x101f
45#define DoC_NOP 0x1020
wdenk012771d2002-03-08 21:31:05 +000046
Wolfgang Denk53677ef2008-05-20 16:00:29 +020047#define DoC_Mil_CDSN_IO 0x0800
48#define DoC_2k_CDSN_IO 0x1800
wdenk012771d2002-03-08 21:31:05 +000049
William Juulcfa460a2007-10-31 13:53:06 +010050#define DoC_Mplus_NOP 0x1002
51#define DoC_Mplus_AliasResolution 0x1004
52#define DoC_Mplus_DOCControl 0x1006
53#define DoC_Mplus_AccessStatus 0x1008
54#define DoC_Mplus_DeviceSelect 0x1008
55#define DoC_Mplus_Configuration 0x100a
56#define DoC_Mplus_OutputControl 0x100c
57#define DoC_Mplus_FlashControl 0x1020
58#define DoC_Mplus_FlashSelect 0x1022
59#define DoC_Mplus_FlashCmd 0x1024
60#define DoC_Mplus_FlashAddress 0x1026
61#define DoC_Mplus_FlashData0 0x1028
62#define DoC_Mplus_FlashData1 0x1029
63#define DoC_Mplus_ReadPipeInit 0x102a
64#define DoC_Mplus_LastDataRead 0x102c
65#define DoC_Mplus_LastDataRead1 0x102d
66#define DoC_Mplus_WritePipeTerm 0x102e
67#define DoC_Mplus_ECCSyndrome0 0x1040
68#define DoC_Mplus_ECCSyndrome1 0x1041
69#define DoC_Mplus_ECCSyndrome2 0x1042
70#define DoC_Mplus_ECCSyndrome3 0x1043
71#define DoC_Mplus_ECCSyndrome4 0x1044
72#define DoC_Mplus_ECCSyndrome5 0x1045
73#define DoC_Mplus_ECCConf 0x1046
74#define DoC_Mplus_Toggle 0x1046
75#define DoC_Mplus_DownloadStatus 0x1074
76#define DoC_Mplus_CtrlConfirm 0x1076
77#define DoC_Mplus_Power 0x1fff
wdenk012771d2002-03-08 21:31:05 +000078
William Juulcfa460a2007-10-31 13:53:06 +010079/* How to access the device?
80 * On ARM, it'll be mmap'd directly with 32-bit wide accesses.
81 * On PPC, it's mmap'd and 16-bit wide.
82 * Others use readb/writeb
83 */
84#if defined(__arm__)
85#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u32 *)(((unsigned long)adr)+((reg)<<2))))
86#define WriteDOC_(d, adr, reg) do{ *(volatile __u32 *)(((unsigned long)adr)+((reg)<<2)) = (__u32)d; wmb();} while(0)
87#define DOC_IOREMAP_LEN 0x8000
88#elif defined(__ppc__)
89#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u16 *)(((unsigned long)adr)+((reg)<<1))))
90#define WriteDOC_(d, adr, reg) do{ *(volatile __u16 *)(((unsigned long)adr)+((reg)<<1)) = (__u16)d; wmb();} while(0)
91#define DOC_IOREMAP_LEN 0x4000
92#else
93#define ReadDOC_(adr, reg) readb((void __iomem *)(adr) + (reg))
94#define WriteDOC_(d, adr, reg) writeb(d, (void __iomem *)(adr) + (reg))
95#define DOC_IOREMAP_LEN 0x2000
96
97#endif
98
99#if defined(__i386__) || defined(__x86_64__)
100#define USE_MEMCPY
101#endif
wdenk012771d2002-03-08 21:31:05 +0000102
103/* These are provided to directly use the DoC_xxx defines */
104#define ReadDOC(adr, reg) ReadDOC_(adr,DoC_##reg)
105#define WriteDOC(d, adr, reg) WriteDOC_(d,adr,DoC_##reg)
106
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200107#define DOC_MODE_RESET 0
108#define DOC_MODE_NORMAL 1
109#define DOC_MODE_RESERVED1 2
110#define DOC_MODE_RESERVED2 3
wdenk012771d2002-03-08 21:31:05 +0000111
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200112#define DOC_MODE_CLR_ERR 0x80
William Juulcfa460a2007-10-31 13:53:06 +0100113#define DOC_MODE_RST_LAT 0x10
114#define DOC_MODE_BDECT 0x08
115#define DOC_MODE_MDWREN 0x04
wdenk012771d2002-03-08 21:31:05 +0000116
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200117#define DOC_ChipID_Doc2k 0x20
William Juulcfa460a2007-10-31 13:53:06 +0100118#define DOC_ChipID_Doc2kTSOP 0x21 /* internal number for MTD */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200119#define DOC_ChipID_DocMil 0x30
William Juulcfa460a2007-10-31 13:53:06 +0100120#define DOC_ChipID_DocMilPlus32 0x40
121#define DOC_ChipID_DocMilPlus16 0x41
wdenk012771d2002-03-08 21:31:05 +0000122
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200123#define CDSN_CTRL_FR_B 0x80
William Juulcfa460a2007-10-31 13:53:06 +0100124#define CDSN_CTRL_FR_B0 0x40
125#define CDSN_CTRL_FR_B1 0x80
126
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200127#define CDSN_CTRL_ECC_IO 0x20
128#define CDSN_CTRL_FLASH_IO 0x10
129#define CDSN_CTRL_WP 0x08
130#define CDSN_CTRL_ALE 0x04
131#define CDSN_CTRL_CLE 0x02
132#define CDSN_CTRL_CE 0x01
wdenk012771d2002-03-08 21:31:05 +0000133
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200134#define DOC_ECC_RESET 0
135#define DOC_ECC_ERROR 0x80
136#define DOC_ECC_RW 0x20
137#define DOC_ECC__EN 0x08
138#define DOC_TOGGLE_BIT 0x04
139#define DOC_ECC_RESV 0x02
wdenk012771d2002-03-08 21:31:05 +0000140#define DOC_ECC_IGNORE 0x01
141
William Juulcfa460a2007-10-31 13:53:06 +0100142#define DOC_FLASH_CE 0x80
143#define DOC_FLASH_WP 0x40
144#define DOC_FLASH_BANK 0x02
145
wdenk012771d2002-03-08 21:31:05 +0000146/* We have to also set the reserved bit 1 for enable */
147#define DOC_ECC_EN (DOC_ECC__EN | DOC_ECC_RESV)
148#define DOC_ECC_DIS (DOC_ECC_RESV)
149
Marian Balakowicz2fc000d2006-04-05 20:46:41 +0200150struct Nand {
151 char floor, chip;
152 unsigned long curadr;
153 unsigned char curmode;
154 /* Also some erase/write/pipeline info when we get that far */
155};
156
William Juulcfa460a2007-10-31 13:53:06 +0100157#define MAX_FLOORS 4
158#define MAX_CHIPS 4
159
160#define MAX_FLOORS_MIL 1
161#define MAX_CHIPS_MIL 1
162
163#define MAX_FLOORS_MPLUS 2
164#define MAX_CHIPS_MPLUS 1
165
166#define ADDR_COLUMN 1
167#define ADDR_PAGE 2
168#define ADDR_COLUMN_PAGE 3
169
wdenk012771d2002-03-08 21:31:05 +0000170struct DiskOnChip {
171 unsigned long physadr;
William Juulcfa460a2007-10-31 13:53:06 +0100172 void __iomem *virtadr;
wdenk012771d2002-03-08 21:31:05 +0000173 unsigned long totlen;
William Juulcfa460a2007-10-31 13:53:06 +0100174 unsigned char ChipID; /* Type of DiskOnChip */
wdenk012771d2002-03-08 21:31:05 +0000175 int ioreg;
176
wdenk012771d2002-03-08 21:31:05 +0000177 unsigned long mfr; /* Flash IDs - only one type of flash per device */
178 unsigned long id;
179 int chipshift;
180 char page256;
181 char pageadrlen;
William Juulcfa460a2007-10-31 13:53:06 +0100182 char interleave; /* Internal interleaving - Millennium Plus style */
wdenk012771d2002-03-08 21:31:05 +0000183 unsigned long erasesize;
184
185 int curfloor;
186 int curchip;
187
188 int numchips;
189 struct Nand *chips;
William Juulcfa460a2007-10-31 13:53:06 +0100190 struct mtd_info *nextdoc;
191/* XXX U-BOOT XXX */
192#if 0
193 struct mutex lock;
194#endif
wdenk012771d2002-03-08 21:31:05 +0000195};
196
wdenk012771d2002-03-08 21:31:05 +0000197int doc_decode_ecc(unsigned char sector[512], unsigned char ecc1[6]);
198
William Juulcfa460a2007-10-31 13:53:06 +0100199/* XXX U-BOOT XXX */
200#if 1
Marian Balakowicz2fc000d2006-04-05 20:46:41 +0200201/*
202 * NAND Flash Manufacturer ID Codes
203 */
William Juulcfa460a2007-10-31 13:53:06 +0100204#define NAND_MFR_TOSHIBA 0x98
205#define NAND_MFR_SAMSUNG 0xec
206#endif
Marian Balakowicz2fc000d2006-04-05 20:46:41 +0200207
wdenk012771d2002-03-08 21:31:05 +0000208#endif /* __MTD_DOC2000_H__ */