Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Feb 10-13, 2025
Register
Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * Handles the M-Systems DiskOnChip G3 chip
  4 *
  5 * Copyright (C) 2011 Robert Jarzmik
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#ifndef _MTD_DOCG3_H
  9#define _MTD_DOCG3_H
 10
 11#include <linux/mtd/mtd.h>
 12
 13/*
 14 * Flash memory areas :
 15 *   - 0x0000 .. 0x07ff : IPL
 16 *   - 0x0800 .. 0x0fff : Data area
 17 *   - 0x1000 .. 0x17ff : Registers
 18 *   - 0x1800 .. 0x1fff : Unknown
 19 */
 20#define DOC_IOSPACE_IPL			0x0000
 21#define DOC_IOSPACE_DATA		0x0800
 22#define DOC_IOSPACE_SIZE		0x2000
 23
 24/*
 25 * DOC G3 layout and adressing scheme
 26 *   A page address for the block "b", plane "P" and page "p":
 27 *   address = [bbbb bPpp pppp]
 28 */
 29
 30#define DOC_ADDR_PAGE_MASK		0x3f
 31#define DOC_ADDR_BLOCK_SHIFT		6
 32#define DOC_LAYOUT_NBPLANES		2
 33#define DOC_LAYOUT_PAGES_PER_BLOCK	64
 34#define DOC_LAYOUT_PAGE_SIZE		512
 35#define DOC_LAYOUT_OOB_SIZE		16
 36#define DOC_LAYOUT_WEAR_SIZE		8
 37#define DOC_LAYOUT_PAGE_OOB_SIZE				\
 38	(DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
 39#define DOC_LAYOUT_WEAR_OFFSET		(DOC_LAYOUT_PAGE_OOB_SIZE * 2)
 40#define DOC_LAYOUT_BLOCK_SIZE					\
 41	(DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
 42
 43/*
 44 * ECC related constants
 45 */
 46#define DOC_ECC_BCH_M			14
 47#define DOC_ECC_BCH_T			4
 48#define DOC_ECC_BCH_PRIMPOLY		0x4443
 49#define DOC_ECC_BCH_SIZE		7
 50#define DOC_ECC_BCH_COVERED_BYTES				\
 51	(DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ +	\
 52	 DOC_LAYOUT_OOB_HAMMING_SZ)
 53#define DOC_ECC_BCH_TOTAL_BYTES					\
 54	(DOC_ECC_BCH_COVERED_BYTES + DOC_LAYOUT_OOB_BCH_SZ)
 55
 56/*
 57 * Blocks distribution
 58 */
 59#define DOC_LAYOUT_BLOCK_BBT		0
 60#define DOC_LAYOUT_BLOCK_OTP		0
 61#define DOC_LAYOUT_BLOCK_FIRST_DATA	6
 62
 63#define DOC_LAYOUT_PAGE_BBT		4
 64
 65/*
 66 * Extra page OOB (16 bytes wide) layout
 67 */
 68#define DOC_LAYOUT_OOB_PAGEINFO_OFS	0
 69#define DOC_LAYOUT_OOB_HAMMING_OFS	7
 70#define DOC_LAYOUT_OOB_BCH_OFS		8
 71#define DOC_LAYOUT_OOB_UNUSED_OFS	15
 72#define DOC_LAYOUT_OOB_PAGEINFO_SZ	7
 73#define DOC_LAYOUT_OOB_HAMMING_SZ	1
 74#define DOC_LAYOUT_OOB_BCH_SZ		7
 75#define DOC_LAYOUT_OOB_UNUSED_SZ	1
 76
 77
 78#define DOC_CHIPID_G3			0x200
 79#define DOC_ERASE_MARK			0xaa
 80#define DOC_MAX_NBFLOORS		4
 81/*
 82 * Flash registers
 83 */
 84#define DOC_CHIPID			0x1000
 85#define DOC_TEST			0x1004
 86#define DOC_BUSLOCK			0x1006
 87#define DOC_ENDIANCONTROL		0x1008
 88#define DOC_DEVICESELECT		0x100a
 89#define DOC_ASICMODE			0x100c
 90#define DOC_CONFIGURATION		0x100e
 91#define DOC_INTERRUPTCONTROL		0x1010
 92#define DOC_READADDRESS			0x101a
 93#define DOC_DATAEND			0x101e
 94#define DOC_INTERRUPTSTATUS		0x1020
 95
 96#define DOC_FLASHSEQUENCE		0x1032
 97#define DOC_FLASHCOMMAND		0x1034
 98#define DOC_FLASHADDRESS		0x1036
 99#define DOC_FLASHCONTROL		0x1038
100#define DOC_NOP				0x103e
101
102#define DOC_ECCCONF0			0x1040
103#define DOC_ECCCONF1			0x1042
104#define DOC_ECCPRESET			0x1044
105#define DOC_HAMMINGPARITY		0x1046
106#define DOC_BCH_HW_ECC(idx)		(0x1048 + idx)
107
108#define DOC_PROTECTION			0x1056
109#define DOC_DPS0_KEY			0x105c
110#define DOC_DPS1_KEY			0x105e
111#define DOC_DPS0_ADDRLOW		0x1060
112#define DOC_DPS0_ADDRHIGH		0x1062
113#define DOC_DPS1_ADDRLOW		0x1064
114#define DOC_DPS1_ADDRHIGH		0x1066
115#define DOC_DPS0_STATUS			0x106c
116#define DOC_DPS1_STATUS			0x106e
117
118#define DOC_ASICMODECONFIRM		0x1072
119#define DOC_CHIPID_INV			0x1074
120#define DOC_POWERMODE			0x107c
121
122/*
123 * Flash sequences
124 * A sequence is preset before one or more commands are input to the chip.
125 */
126#define DOC_SEQ_RESET			0x00
127#define DOC_SEQ_PAGE_SIZE_532		0x03
128#define DOC_SEQ_SET_FASTMODE		0x05
129#define DOC_SEQ_SET_RELIABLEMODE	0x09
130#define DOC_SEQ_READ			0x12
131#define DOC_SEQ_SET_PLANE1		0x0e
132#define DOC_SEQ_SET_PLANE2		0x10
133#define DOC_SEQ_PAGE_SETUP		0x1d
134#define DOC_SEQ_ERASE			0x27
135#define DOC_SEQ_PLANES_STATUS		0x31
136
137/*
138 * Flash commands
139 */
140#define DOC_CMD_READ_PLANE1		0x00
141#define DOC_CMD_SET_ADDR_READ		0x05
142#define DOC_CMD_READ_ALL_PLANES		0x30
143#define DOC_CMD_READ_PLANE2		0x50
144#define DOC_CMD_READ_FLASH		0xe0
145#define DOC_CMD_PAGE_SIZE_532		0x3c
146
147#define DOC_CMD_PROG_BLOCK_ADDR		0x60
148#define DOC_CMD_PROG_CYCLE1		0x80
149#define DOC_CMD_PROG_CYCLE2		0x10
150#define DOC_CMD_PROG_CYCLE3		0x11
151#define DOC_CMD_ERASECYCLE2		0xd0
152#define DOC_CMD_READ_STATUS		0x70
153#define DOC_CMD_PLANES_STATUS		0x71
154
155#define DOC_CMD_RELIABLE_MODE		0x22
156#define DOC_CMD_FAST_MODE		0xa2
157
158#define DOC_CMD_RESET			0xff
159
160/*
161 * Flash register : DOC_FLASHCONTROL
162 */
163#define DOC_CTRL_VIOLATION		0x20
164#define DOC_CTRL_CE			0x10
165#define DOC_CTRL_UNKNOWN_BITS		0x08
166#define DOC_CTRL_PROTECTION_ERROR	0x04
167#define DOC_CTRL_SEQUENCE_ERROR		0x02
168#define DOC_CTRL_FLASHREADY		0x01
169
170/*
171 * Flash register : DOC_ASICMODE
172 */
173#define DOC_ASICMODE_RESET		0x00
174#define DOC_ASICMODE_NORMAL		0x01
175#define DOC_ASICMODE_POWERDOWN		0x02
176#define DOC_ASICMODE_MDWREN		0x04
177#define DOC_ASICMODE_BDETCT_RESET	0x08
178#define DOC_ASICMODE_RSTIN_RESET	0x10
179#define DOC_ASICMODE_RAM_WE		0x20
180
181/*
182 * Flash register : DOC_ECCCONF0
183 */
184#define DOC_ECCCONF0_WRITE_MODE		0x0000
185#define DOC_ECCCONF0_READ_MODE		0x8000
186#define DOC_ECCCONF0_AUTO_ECC_ENABLE	0x4000
187#define DOC_ECCCONF0_HAMMING_ENABLE	0x1000
188#define DOC_ECCCONF0_BCH_ENABLE		0x0800
189#define DOC_ECCCONF0_DATA_BYTES_MASK	0x07ff
190
191/*
192 * Flash register : DOC_ECCCONF1
193 */
194#define DOC_ECCCONF1_BCH_SYNDROM_ERR	0x80
195#define DOC_ECCCONF1_UNKOWN1		0x40
196#define DOC_ECCCONF1_PAGE_IS_WRITTEN	0x20
197#define DOC_ECCCONF1_UNKOWN3		0x10
198#define DOC_ECCCONF1_HAMMING_BITS_MASK	0x0f
199
200/*
201 * Flash register : DOC_PROTECTION
202 */
203#define DOC_PROTECT_FOUNDRY_OTP_LOCK	0x01
204#define DOC_PROTECT_CUSTOMER_OTP_LOCK	0x02
205#define DOC_PROTECT_LOCK_INPUT		0x04
206#define DOC_PROTECT_STICKY_LOCK		0x08
207#define DOC_PROTECT_PROTECTION_ENABLED	0x10
208#define DOC_PROTECT_IPL_DOWNLOAD_LOCK	0x20
209#define DOC_PROTECT_PROTECTION_ERROR	0x80
210
211/*
212 * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
213 */
214#define DOC_DPS_OTP_PROTECTED		0x01
215#define DOC_DPS_READ_PROTECTED		0x02
216#define DOC_DPS_WRITE_PROTECTED		0x04
217#define DOC_DPS_HW_LOCK_ENABLED		0x08
218#define DOC_DPS_KEY_OK			0x80
219
220/*
221 * Flash register : DOC_CONFIGURATION
222 */
223#define DOC_CONF_IF_CFG			0x80
224#define DOC_CONF_MAX_ID_MASK		0x30
225#define DOC_CONF_VCCQ_3V		0x01
226
227/*
228 * Flash register : DOC_READADDRESS
229 */
230#define DOC_READADDR_INC		0x8000
231#define DOC_READADDR_ONE_BYTE		0x4000
232#define DOC_READADDR_ADDR_MASK		0x1fff
233
234/*
235 * Flash register : DOC_POWERMODE
236 */
237#define DOC_POWERDOWN_READY		0x80
238
239/*
240 * Status of erase and write operation
241 */
242#define DOC_PLANES_STATUS_FAIL		0x01
243#define DOC_PLANES_STATUS_PLANE0_KO	0x02
244#define DOC_PLANES_STATUS_PLANE1_KO	0x04
245
246/*
247 * DPS key management
248 *
249 * Each floor of docg3 has 2 protection areas: DPS0 and DPS1. These areas span
250 * across block boundaries, and define whether these blocks can be read or
251 * written.
252 * The definition is dynamically stored in page 0 of blocks (2,3) for DPS0, and
253 * page 0 of blocks (4,5) for DPS1.
254 */
255#define DOC_LAYOUT_DPS_KEY_LENGTH	8
256
257/**
258 * struct docg3_cascade - Cascade of 1 to 4 docg3 chips
259 * @floors: floors (ie. one physical docg3 chip is one floor)
260 * @base: IO space to access all chips in the cascade
261 * @bch: the BCH correcting control structure
262 * @lock: lock to protect docg3 IO space from concurrent accesses
263 */
264struct docg3_cascade {
265	struct mtd_info *floors[DOC_MAX_NBFLOORS];
266	void __iomem *base;
267	struct bch_control *bch;
268	struct mutex lock;
269};
270
271/**
272 * struct docg3 - DiskOnChip driver private data
273 * @dev: the device currently under control
274 * @cascade: the cascade this device belongs to
275 * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
276 * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
277
278 * @reliable: if 0, docg3 in normal mode, if 1 docg3 in fast mode, if 2 in
279 *            reliable mode
280 *            Fast mode implies more errors than normal mode.
281 *            Reliable mode implies that page 2*n and 2*n+1 are clones.
282 * @bbt: bad block table cache
283 * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next
284 *                 page_write)
285 * @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC
286 *               if 0, use all the 16 bytes.
287 * @oob_write_buf: prepared OOB for next page_write
 
288 */
289struct docg3 {
290	struct device *dev;
291	struct docg3_cascade *cascade;
292	unsigned int device_id:4;
293	unsigned int if_cfg:1;
294	unsigned int reliable:2;
295	int max_block;
296	u8 *bbt;
297	loff_t oob_write_ofs;
298	int oob_autoecc;
299	u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE];
 
300};
301
302#define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
303#define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
304#define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
305#define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
 
 
 
 
 
 
 
 
 
 
 
306#endif
307
308/*
309 * Trace events part
310 */
311#undef TRACE_SYSTEM
312#define TRACE_SYSTEM docg3
313
314#if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
315#define _MTD_DOCG3_TRACE
316
317#include <linux/tracepoint.h>
318
319TRACE_EVENT(docg3_io,
320	    TP_PROTO(int op, int width, u16 reg, int val),
321	    TP_ARGS(op, width, reg, val),
322	    TP_STRUCT__entry(
323		    __field(int, op)
324		    __field(unsigned char, width)
325		    __field(u16, reg)
326		    __field(int, val)),
327	    TP_fast_assign(
328		    __entry->op = op;
329		    __entry->width = width;
330		    __entry->reg = reg;
331		    __entry->val = val;),
332	    TP_printk("docg3: %s%02d reg=%04x, val=%04x",
333		      __entry->op ? "write" : "read", __entry->width,
334		      __entry->reg, __entry->val)
335	);
336#endif
337
338/* This part must be outside protection */
339#undef TRACE_INCLUDE_PATH
340#undef TRACE_INCLUDE_FILE
341#define TRACE_INCLUDE_PATH .
342#define TRACE_INCLUDE_FILE docg3
343#include <trace/define_trace.h>
v3.15
 
  1/*
  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#include <linux/mtd/mtd.h>
 26
 27/*
 28 * Flash memory areas :
 29 *   - 0x0000 .. 0x07ff : IPL
 30 *   - 0x0800 .. 0x0fff : Data area
 31 *   - 0x1000 .. 0x17ff : Registers
 32 *   - 0x1800 .. 0x1fff : Unknown
 33 */
 34#define DOC_IOSPACE_IPL			0x0000
 35#define DOC_IOSPACE_DATA		0x0800
 36#define DOC_IOSPACE_SIZE		0x2000
 37
 38/*
 39 * DOC G3 layout and adressing scheme
 40 *   A page address for the block "b", plane "P" and page "p":
 41 *   address = [bbbb bPpp pppp]
 42 */
 43
 44#define DOC_ADDR_PAGE_MASK		0x3f
 45#define DOC_ADDR_BLOCK_SHIFT		6
 46#define DOC_LAYOUT_NBPLANES		2
 47#define DOC_LAYOUT_PAGES_PER_BLOCK	64
 48#define DOC_LAYOUT_PAGE_SIZE		512
 49#define DOC_LAYOUT_OOB_SIZE		16
 50#define DOC_LAYOUT_WEAR_SIZE		8
 51#define DOC_LAYOUT_PAGE_OOB_SIZE				\
 52	(DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
 53#define DOC_LAYOUT_WEAR_OFFSET		(DOC_LAYOUT_PAGE_OOB_SIZE * 2)
 54#define DOC_LAYOUT_BLOCK_SIZE					\
 55	(DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
 56
 57/*
 58 * ECC related constants
 59 */
 60#define DOC_ECC_BCH_M			14
 61#define DOC_ECC_BCH_T			4
 62#define DOC_ECC_BCH_PRIMPOLY		0x4443
 63#define DOC_ECC_BCH_SIZE		7
 64#define DOC_ECC_BCH_COVERED_BYTES				\
 65	(DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ +	\
 66	 DOC_LAYOUT_OOB_HAMMING_SZ)
 67#define DOC_ECC_BCH_TOTAL_BYTES					\
 68	(DOC_ECC_BCH_COVERED_BYTES + DOC_LAYOUT_OOB_BCH_SZ)
 69
 70/*
 71 * Blocks distribution
 72 */
 73#define DOC_LAYOUT_BLOCK_BBT		0
 74#define DOC_LAYOUT_BLOCK_OTP		0
 75#define DOC_LAYOUT_BLOCK_FIRST_DATA	6
 76
 77#define DOC_LAYOUT_PAGE_BBT		4
 78
 79/*
 80 * Extra page OOB (16 bytes wide) layout
 81 */
 82#define DOC_LAYOUT_OOB_PAGEINFO_OFS	0
 83#define DOC_LAYOUT_OOB_HAMMING_OFS	7
 84#define DOC_LAYOUT_OOB_BCH_OFS		8
 85#define DOC_LAYOUT_OOB_UNUSED_OFS	15
 86#define DOC_LAYOUT_OOB_PAGEINFO_SZ	7
 87#define DOC_LAYOUT_OOB_HAMMING_SZ	1
 88#define DOC_LAYOUT_OOB_BCH_SZ		7
 89#define DOC_LAYOUT_OOB_UNUSED_SZ	1
 90
 91
 92#define DOC_CHIPID_G3			0x200
 93#define DOC_ERASE_MARK			0xaa
 94#define DOC_MAX_NBFLOORS		4
 95/*
 96 * Flash registers
 97 */
 98#define DOC_CHIPID			0x1000
 99#define DOC_TEST			0x1004
100#define DOC_BUSLOCK			0x1006
101#define DOC_ENDIANCONTROL		0x1008
102#define DOC_DEVICESELECT		0x100a
103#define DOC_ASICMODE			0x100c
104#define DOC_CONFIGURATION		0x100e
105#define DOC_INTERRUPTCONTROL		0x1010
106#define DOC_READADDRESS			0x101a
107#define DOC_DATAEND			0x101e
108#define DOC_INTERRUPTSTATUS		0x1020
109
110#define DOC_FLASHSEQUENCE		0x1032
111#define DOC_FLASHCOMMAND		0x1034
112#define DOC_FLASHADDRESS		0x1036
113#define DOC_FLASHCONTROL		0x1038
114#define DOC_NOP				0x103e
115
116#define DOC_ECCCONF0			0x1040
117#define DOC_ECCCONF1			0x1042
118#define DOC_ECCPRESET			0x1044
119#define DOC_HAMMINGPARITY		0x1046
120#define DOC_BCH_HW_ECC(idx)		(0x1048 + idx)
121
122#define DOC_PROTECTION			0x1056
123#define DOC_DPS0_KEY			0x105c
124#define DOC_DPS1_KEY			0x105e
125#define DOC_DPS0_ADDRLOW		0x1060
126#define DOC_DPS0_ADDRHIGH		0x1062
127#define DOC_DPS1_ADDRLOW		0x1064
128#define DOC_DPS1_ADDRHIGH		0x1066
129#define DOC_DPS0_STATUS			0x106c
130#define DOC_DPS1_STATUS			0x106e
131
132#define DOC_ASICMODECONFIRM		0x1072
133#define DOC_CHIPID_INV			0x1074
134#define DOC_POWERMODE			0x107c
135
136/*
137 * Flash sequences
138 * A sequence is preset before one or more commands are input to the chip.
139 */
140#define DOC_SEQ_RESET			0x00
141#define DOC_SEQ_PAGE_SIZE_532		0x03
142#define DOC_SEQ_SET_FASTMODE		0x05
143#define DOC_SEQ_SET_RELIABLEMODE	0x09
144#define DOC_SEQ_READ			0x12
145#define DOC_SEQ_SET_PLANE1		0x0e
146#define DOC_SEQ_SET_PLANE2		0x10
147#define DOC_SEQ_PAGE_SETUP		0x1d
148#define DOC_SEQ_ERASE			0x27
149#define DOC_SEQ_PLANES_STATUS		0x31
150
151/*
152 * Flash commands
153 */
154#define DOC_CMD_READ_PLANE1		0x00
155#define DOC_CMD_SET_ADDR_READ		0x05
156#define DOC_CMD_READ_ALL_PLANES		0x30
157#define DOC_CMD_READ_PLANE2		0x50
158#define DOC_CMD_READ_FLASH		0xe0
159#define DOC_CMD_PAGE_SIZE_532		0x3c
160
161#define DOC_CMD_PROG_BLOCK_ADDR		0x60
162#define DOC_CMD_PROG_CYCLE1		0x80
163#define DOC_CMD_PROG_CYCLE2		0x10
164#define DOC_CMD_PROG_CYCLE3		0x11
165#define DOC_CMD_ERASECYCLE2		0xd0
166#define DOC_CMD_READ_STATUS		0x70
167#define DOC_CMD_PLANES_STATUS		0x71
168
169#define DOC_CMD_RELIABLE_MODE		0x22
170#define DOC_CMD_FAST_MODE		0xa2
171
172#define DOC_CMD_RESET			0xff
173
174/*
175 * Flash register : DOC_FLASHCONTROL
176 */
177#define DOC_CTRL_VIOLATION		0x20
178#define DOC_CTRL_CE			0x10
179#define DOC_CTRL_UNKNOWN_BITS		0x08
180#define DOC_CTRL_PROTECTION_ERROR	0x04
181#define DOC_CTRL_SEQUENCE_ERROR		0x02
182#define DOC_CTRL_FLASHREADY		0x01
183
184/*
185 * Flash register : DOC_ASICMODE
186 */
187#define DOC_ASICMODE_RESET		0x00
188#define DOC_ASICMODE_NORMAL		0x01
189#define DOC_ASICMODE_POWERDOWN		0x02
190#define DOC_ASICMODE_MDWREN		0x04
191#define DOC_ASICMODE_BDETCT_RESET	0x08
192#define DOC_ASICMODE_RSTIN_RESET	0x10
193#define DOC_ASICMODE_RAM_WE		0x20
194
195/*
196 * Flash register : DOC_ECCCONF0
197 */
198#define DOC_ECCCONF0_WRITE_MODE		0x0000
199#define DOC_ECCCONF0_READ_MODE		0x8000
200#define DOC_ECCCONF0_AUTO_ECC_ENABLE	0x4000
201#define DOC_ECCCONF0_HAMMING_ENABLE	0x1000
202#define DOC_ECCCONF0_BCH_ENABLE		0x0800
203#define DOC_ECCCONF0_DATA_BYTES_MASK	0x07ff
204
205/*
206 * Flash register : DOC_ECCCONF1
207 */
208#define DOC_ECCCONF1_BCH_SYNDROM_ERR	0x80
209#define DOC_ECCCONF1_UNKOWN1		0x40
210#define DOC_ECCCONF1_PAGE_IS_WRITTEN	0x20
211#define DOC_ECCCONF1_UNKOWN3		0x10
212#define DOC_ECCCONF1_HAMMING_BITS_MASK	0x0f
213
214/*
215 * Flash register : DOC_PROTECTION
216 */
217#define DOC_PROTECT_FOUNDRY_OTP_LOCK	0x01
218#define DOC_PROTECT_CUSTOMER_OTP_LOCK	0x02
219#define DOC_PROTECT_LOCK_INPUT		0x04
220#define DOC_PROTECT_STICKY_LOCK		0x08
221#define DOC_PROTECT_PROTECTION_ENABLED	0x10
222#define DOC_PROTECT_IPL_DOWNLOAD_LOCK	0x20
223#define DOC_PROTECT_PROTECTION_ERROR	0x80
224
225/*
226 * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
227 */
228#define DOC_DPS_OTP_PROTECTED		0x01
229#define DOC_DPS_READ_PROTECTED		0x02
230#define DOC_DPS_WRITE_PROTECTED		0x04
231#define DOC_DPS_HW_LOCK_ENABLED		0x08
232#define DOC_DPS_KEY_OK			0x80
233
234/*
235 * Flash register : DOC_CONFIGURATION
236 */
237#define DOC_CONF_IF_CFG			0x80
238#define DOC_CONF_MAX_ID_MASK		0x30
239#define DOC_CONF_VCCQ_3V		0x01
240
241/*
242 * Flash register : DOC_READADDRESS
243 */
244#define DOC_READADDR_INC		0x8000
245#define DOC_READADDR_ONE_BYTE		0x4000
246#define DOC_READADDR_ADDR_MASK		0x1fff
247
248/*
249 * Flash register : DOC_POWERMODE
250 */
251#define DOC_POWERDOWN_READY		0x80
252
253/*
254 * Status of erase and write operation
255 */
256#define DOC_PLANES_STATUS_FAIL		0x01
257#define DOC_PLANES_STATUS_PLANE0_KO	0x02
258#define DOC_PLANES_STATUS_PLANE1_KO	0x04
259
260/*
261 * DPS key management
262 *
263 * Each floor of docg3 has 2 protection areas: DPS0 and DPS1. These areas span
264 * across block boundaries, and define whether these blocks can be read or
265 * written.
266 * The definition is dynamically stored in page 0 of blocks (2,3) for DPS0, and
267 * page 0 of blocks (4,5) for DPS1.
268 */
269#define DOC_LAYOUT_DPS_KEY_LENGTH	8
270
271/**
272 * struct docg3_cascade - Cascade of 1 to 4 docg3 chips
273 * @floors: floors (ie. one physical docg3 chip is one floor)
274 * @base: IO space to access all chips in the cascade
275 * @bch: the BCH correcting control structure
276 * @lock: lock to protect docg3 IO space from concurrent accesses
277 */
278struct docg3_cascade {
279	struct mtd_info *floors[DOC_MAX_NBFLOORS];
280	void __iomem *base;
281	struct bch_control *bch;
282	struct mutex lock;
283};
284
285/**
286 * struct docg3 - DiskOnChip driver private data
287 * @dev: the device currently under control
288 * @cascade: the cascade this device belongs to
289 * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
290 * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
291
292 * @reliable: if 0, docg3 in normal mode, if 1 docg3 in fast mode, if 2 in
293 *            reliable mode
294 *            Fast mode implies more errors than normal mode.
295 *            Reliable mode implies that page 2*n and 2*n+1 are clones.
296 * @bbt: bad block table cache
297 * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next
298 *                 page_write)
299 * @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC
300 *               if 0, use all the 16 bytes.
301 * @oob_write_buf: prepared OOB for next page_write
302 * @debugfs_root: debugfs root node
303 */
304struct docg3 {
305	struct device *dev;
306	struct docg3_cascade *cascade;
307	unsigned int device_id:4;
308	unsigned int if_cfg:1;
309	unsigned int reliable:2;
310	int max_block;
311	u8 *bbt;
312	loff_t oob_write_ofs;
313	int oob_autoecc;
314	u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE];
315	struct dentry *debugfs_root;
316};
317
318#define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
319#define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
320#define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
321#define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
322
323#define DEBUGFS_RO_ATTR(name, show_fct) \
324	static int name##_open(struct inode *inode, struct file *file) \
325	{ return single_open(file, show_fct, inode->i_private); }      \
326	static const struct file_operations name##_fops = { \
327		.owner = THIS_MODULE, \
328		.open = name##_open, \
329		.llseek = seq_lseek, \
330		.read = seq_read, \
331		.release = single_release \
332	};
333#endif
334
335/*
336 * Trace events part
337 */
338#undef TRACE_SYSTEM
339#define TRACE_SYSTEM docg3
340
341#if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
342#define _MTD_DOCG3_TRACE
343
344#include <linux/tracepoint.h>
345
346TRACE_EVENT(docg3_io,
347	    TP_PROTO(int op, int width, u16 reg, int val),
348	    TP_ARGS(op, width, reg, val),
349	    TP_STRUCT__entry(
350		    __field(int, op)
351		    __field(unsigned char, width)
352		    __field(u16, reg)
353		    __field(int, val)),
354	    TP_fast_assign(
355		    __entry->op = op;
356		    __entry->width = width;
357		    __entry->reg = reg;
358		    __entry->val = val;),
359	    TP_printk("docg3: %s%02d reg=%04x, val=%04x",
360		      __entry->op ? "write" : "read", __entry->width,
361		      __entry->reg, __entry->val)
362	);
363#endif
364
365/* This part must be outside protection */
366#undef TRACE_INCLUDE_PATH
367#undef TRACE_INCLUDE_FILE
368#define TRACE_INCLUDE_PATH .
369#define TRACE_INCLUDE_FILE docg3
370#include <trace/define_trace.h>