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