blob: cd70b181f797950398656661d0ab6296194670f5 [file] [log] [blame]
Robert Jarzmikefa2ca72011-10-05 15:22:34 +02001/*
2 * Handles the M-Systems DiskOnChip G3 chip
3 *
4 * Copyright (C) 2011 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#ifndef _MTD_DOCG3_H
23#define _MTD_DOCG3_H
24
25/*
26 * Flash memory areas :
27 * - 0x0000 .. 0x07ff : IPL
28 * - 0x0800 .. 0x0fff : Data area
29 * - 0x1000 .. 0x17ff : Registers
30 * - 0x1800 .. 0x1fff : Unknown
31 */
32#define DOC_IOSPACE_IPL 0x0000
33#define DOC_IOSPACE_DATA 0x0800
34#define DOC_IOSPACE_SIZE 0x2000
35
36/*
37 * DOC G3 layout and adressing scheme
38 * A page address for the block "b", plane "P" and page "p":
39 * address = [bbbb bPpp pppp]
40 */
41
42#define DOC_ADDR_PAGE_MASK 0x3f
43#define DOC_ADDR_BLOCK_SHIFT 6
44#define DOC_LAYOUT_NBPLANES 2
45#define DOC_LAYOUT_PAGES_PER_BLOCK 64
46#define DOC_LAYOUT_PAGE_SIZE 512
47#define DOC_LAYOUT_OOB_SIZE 16
48#define DOC_LAYOUT_WEAR_SIZE 8
49#define DOC_LAYOUT_PAGE_OOB_SIZE \
50 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
51#define DOC_LAYOUT_WEAR_OFFSET (DOC_LAYOUT_PAGE_OOB_SIZE * 2)
52#define DOC_LAYOUT_BLOCK_SIZE \
53 (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
Robert Jarzmikd13d19e2011-11-19 16:02:55 +010054
55/*
56 * ECC related constants
57 */
58#define DOC_ECC_BCH_M 14
59#define DOC_ECC_BCH_T 4
60#define DOC_ECC_BCH_PRIMPOLY 0x4443
Robert Jarzmikefa2ca72011-10-05 15:22:34 +020061#define DOC_ECC_BCH_SIZE 7
62#define DOC_ECC_BCH_COVERED_BYTES \
63 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ + \
Robert Jarzmikd13d19e2011-11-19 16:02:55 +010064 DOC_LAYOUT_OOB_HAMMING_SZ)
65#define DOC_ECC_BCH_TOTAL_BYTES \
66 (DOC_ECC_BCH_COVERED_BYTES + DOC_LAYOUT_OOB_BCH_SZ)
Robert Jarzmikefa2ca72011-10-05 15:22:34 +020067
68/*
69 * Blocks distribution
70 */
71#define DOC_LAYOUT_BLOCK_BBT 0
72#define DOC_LAYOUT_BLOCK_OTP 0
73#define DOC_LAYOUT_BLOCK_FIRST_DATA 6
74
75#define DOC_LAYOUT_PAGE_BBT 4
76
77/*
78 * Extra page OOB (16 bytes wide) layout
79 */
80#define DOC_LAYOUT_OOB_PAGEINFO_OFS 0
81#define DOC_LAYOUT_OOB_HAMMING_OFS 7
82#define DOC_LAYOUT_OOB_BCH_OFS 8
83#define DOC_LAYOUT_OOB_UNUSED_OFS 15
84#define DOC_LAYOUT_OOB_PAGEINFO_SZ 7
85#define DOC_LAYOUT_OOB_HAMMING_SZ 1
86#define DOC_LAYOUT_OOB_BCH_SZ 7
87#define DOC_LAYOUT_OOB_UNUSED_SZ 1
88
89
90#define DOC_CHIPID_G3 0x200
91#define DOC_ERASE_MARK 0xaa
Robert Jarzmikae9d4932011-11-19 16:02:48 +010092#define DOC_MAX_NBFLOORS 4
Robert Jarzmikefa2ca72011-10-05 15:22:34 +020093/*
94 * Flash registers
95 */
96#define DOC_CHIPID 0x1000
97#define DOC_TEST 0x1004
98#define DOC_BUSLOCK 0x1006
99#define DOC_ENDIANCONTROL 0x1008
100#define DOC_DEVICESELECT 0x100a
101#define DOC_ASICMODE 0x100c
102#define DOC_CONFIGURATION 0x100e
103#define DOC_INTERRUPTCONTROL 0x1010
104#define DOC_READADDRESS 0x101a
105#define DOC_DATAEND 0x101e
106#define DOC_INTERRUPTSTATUS 0x1020
107
108#define DOC_FLASHSEQUENCE 0x1032
109#define DOC_FLASHCOMMAND 0x1034
110#define DOC_FLASHADDRESS 0x1036
111#define DOC_FLASHCONTROL 0x1038
112#define DOC_NOP 0x103e
113
114#define DOC_ECCCONF0 0x1040
115#define DOC_ECCCONF1 0x1042
116#define DOC_ECCPRESET 0x1044
117#define DOC_HAMMINGPARITY 0x1046
Robert Jarzmik34db8a52011-11-19 16:02:46 +0100118#define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 0))
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200119
120#define DOC_PROTECTION 0x1056
121#define DOC_DPS0_ADDRLOW 0x1060
122#define DOC_DPS0_ADDRHIGH 0x1062
123#define DOC_DPS1_ADDRLOW 0x1064
124#define DOC_DPS1_ADDRHIGH 0x1066
125#define DOC_DPS0_STATUS 0x106c
126#define DOC_DPS1_STATUS 0x106e
127
128#define DOC_ASICMODECONFIRM 0x1072
129#define DOC_CHIPID_INV 0x1074
Robert Jarzmike4b2a962011-11-19 16:02:56 +0100130#define DOC_POWERMODE 0x107c
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200131
132/*
133 * Flash sequences
134 * A sequence is preset before one or more commands are input to the chip.
135 */
136#define DOC_SEQ_RESET 0x00
137#define DOC_SEQ_PAGE_SIZE_532 0x03
138#define DOC_SEQ_SET_MODE 0x09
139#define DOC_SEQ_READ 0x12
140#define DOC_SEQ_SET_PLANE1 0x0e
141#define DOC_SEQ_SET_PLANE2 0x10
142#define DOC_SEQ_PAGE_SETUP 0x1d
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100143#define DOC_SEQ_ERASE 0x27
144#define DOC_SEQ_PLANES_STATUS 0x31
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200145
146/*
147 * Flash commands
148 */
149#define DOC_CMD_READ_PLANE1 0x00
150#define DOC_CMD_SET_ADDR_READ 0x05
151#define DOC_CMD_READ_ALL_PLANES 0x30
152#define DOC_CMD_READ_PLANE2 0x50
153#define DOC_CMD_READ_FLASH 0xe0
154#define DOC_CMD_PAGE_SIZE_532 0x3c
155
156#define DOC_CMD_PROG_BLOCK_ADDR 0x60
157#define DOC_CMD_PROG_CYCLE1 0x80
158#define DOC_CMD_PROG_CYCLE2 0x10
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100159#define DOC_CMD_PROG_CYCLE3 0x11
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200160#define DOC_CMD_ERASECYCLE2 0xd0
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100161#define DOC_CMD_READ_STATUS 0x70
162#define DOC_CMD_PLANES_STATUS 0x71
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200163
164#define DOC_CMD_RELIABLE_MODE 0x22
165#define DOC_CMD_FAST_MODE 0xa2
166
167#define DOC_CMD_RESET 0xff
168
169/*
170 * Flash register : DOC_FLASHCONTROL
171 */
172#define DOC_CTRL_VIOLATION 0x20
173#define DOC_CTRL_CE 0x10
174#define DOC_CTRL_UNKNOWN_BITS 0x08
175#define DOC_CTRL_PROTECTION_ERROR 0x04
176#define DOC_CTRL_SEQUENCE_ERROR 0x02
177#define DOC_CTRL_FLASHREADY 0x01
178
179/*
180 * Flash register : DOC_ASICMODE
181 */
182#define DOC_ASICMODE_RESET 0x00
183#define DOC_ASICMODE_NORMAL 0x01
184#define DOC_ASICMODE_POWERDOWN 0x02
185#define DOC_ASICMODE_MDWREN 0x04
186#define DOC_ASICMODE_BDETCT_RESET 0x08
187#define DOC_ASICMODE_RSTIN_RESET 0x10
188#define DOC_ASICMODE_RAM_WE 0x20
189
190/*
191 * Flash register : DOC_ECCCONF0
192 */
193#define DOC_ECCCONF0_READ_MODE 0x8000
194#define DOC_ECCCONF0_AUTO_ECC_ENABLE 0x4000
195#define DOC_ECCCONF0_HAMMING_ENABLE 0x1000
196#define DOC_ECCCONF0_BCH_ENABLE 0x0800
197#define DOC_ECCCONF0_DATA_BYTES_MASK 0x07ff
198
199/*
200 * Flash register : DOC_ECCCONF1
201 */
202#define DOC_ECCCONF1_BCH_SYNDROM_ERR 0x80
203#define DOC_ECCCONF1_UNKOWN1 0x40
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100204#define DOC_ECCCONF1_PAGE_IS_WRITTEN 0x20
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200205#define DOC_ECCCONF1_UNKOWN3 0x10
206#define DOC_ECCCONF1_HAMMING_BITS_MASK 0x0f
207
208/*
209 * Flash register : DOC_PROTECTION
210 */
211#define DOC_PROTECT_FOUNDRY_OTP_LOCK 0x01
212#define DOC_PROTECT_CUSTOMER_OTP_LOCK 0x02
213#define DOC_PROTECT_LOCK_INPUT 0x04
214#define DOC_PROTECT_STICKY_LOCK 0x08
215#define DOC_PROTECT_PROTECTION_ENABLED 0x10
216#define DOC_PROTECT_IPL_DOWNLOAD_LOCK 0x20
217#define DOC_PROTECT_PROTECTION_ERROR 0x80
218
219/*
220 * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
221 */
222#define DOC_DPS_OTP_PROTECTED 0x01
223#define DOC_DPS_READ_PROTECTED 0x02
224#define DOC_DPS_WRITE_PROTECTED 0x04
225#define DOC_DPS_HW_LOCK_ENABLED 0x08
226#define DOC_DPS_KEY_OK 0x80
227
228/*
229 * Flash register : DOC_CONFIGURATION
230 */
231#define DOC_CONF_IF_CFG 0x80
232#define DOC_CONF_MAX_ID_MASK 0x30
233#define DOC_CONF_VCCQ_3V 0x01
234
235/*
236 * Flash register : DOC_READADDRESS
237 */
238#define DOC_READADDR_INC 0x8000
239#define DOC_READADDR_ONE_BYTE 0x4000
240#define DOC_READADDR_ADDR_MASK 0x1fff
241
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100242/*
Robert Jarzmike4b2a962011-11-19 16:02:56 +0100243 * Flash register : DOC_POWERMODE
244 */
245#define DOC_POWERDOWN_READY 0x80
246
247/*
Robert Jarzmik376fbf22011-11-19 16:02:50 +0100248 * Status of erase and write operation
249 */
250#define DOC_PLANES_STATUS_FAIL 0x01
251#define DOC_PLANES_STATUS_PLANE0_KO 0x02
252#define DOC_PLANES_STATUS_PLANE1_KO 0x04
253
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200254/**
255 * struct docg3 - DiskOnChip driver private data
256 * @dev: the device currently under control
257 * @base: mapped IO space
258 * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
259 * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
260 * @bbt: bad block table cache
Robert Jarzmik316e6272011-11-19 16:02:51 +0100261 * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next
262 * page_write)
263 * @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC
264 * if 0, use all the 16 bytes.
265 * @oob_write_buf: prepared OOB for next page_write
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200266 * @debugfs_root: debugfs root node
267 */
268struct docg3 {
269 struct device *dev;
270 void __iomem *base;
271 unsigned int device_id:4;
272 unsigned int if_cfg:1;
273 int max_block;
274 u8 *bbt;
Robert Jarzmik316e6272011-11-19 16:02:51 +0100275 loff_t oob_write_ofs;
276 int oob_autoecc;
277 u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE];
Robert Jarzmikefa2ca72011-10-05 15:22:34 +0200278 struct dentry *debugfs_root;
279};
280
281#define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
282#define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
283#define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
284#define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
285
286#define DEBUGFS_RO_ATTR(name, show_fct) \
287 static int name##_open(struct inode *inode, struct file *file) \
288 { return single_open(file, show_fct, inode->i_private); } \
289 static const struct file_operations name##_fops = { \
290 .owner = THIS_MODULE, \
291 .open = name##_open, \
292 .llseek = seq_lseek, \
293 .read = seq_read, \
294 .release = single_release \
295 };
296#endif
297
298/*
299 * Trace events part
300 */
301#undef TRACE_SYSTEM
302#define TRACE_SYSTEM docg3
303
304#if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
305#define _MTD_DOCG3_TRACE
306
307#include <linux/tracepoint.h>
308
309TRACE_EVENT(docg3_io,
310 TP_PROTO(int op, int width, u16 reg, int val),
311 TP_ARGS(op, width, reg, val),
312 TP_STRUCT__entry(
313 __field(int, op)
314 __field(unsigned char, width)
315 __field(u16, reg)
316 __field(int, val)),
317 TP_fast_assign(
318 __entry->op = op;
319 __entry->width = width;
320 __entry->reg = reg;
321 __entry->val = val;),
322 TP_printk("docg3: %s%02d reg=%04x, val=%04x",
323 __entry->op ? "write" : "read", __entry->width,
324 __entry->reg, __entry->val)
325 );
326#endif
327
328/* This part must be outside protection */
329#undef TRACE_INCLUDE_PATH
330#undef TRACE_INCLUDE_FILE
331#define TRACE_INCLUDE_PATH .
332#define TRACE_INCLUDE_FILE docg3
333#include <trace/define_trace.h>