]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
cd5f6346 KP |
2 | /* |
3 | * linux/include/linux/mtd/onenand.h | |
4 | * | |
3cf60253 | 5 | * Copyright © 2005-2009 Samsung Electronics |
cd5f6346 | 6 | * Kyungmin Park <kyungmin.park@samsung.com> |
cd5f6346 KP |
7 | */ |
8 | ||
9 | #ifndef __LINUX_MTD_ONENAND_H | |
10 | #define __LINUX_MTD_ONENAND_H | |
11 | ||
12 | #include <linux/spinlock.h> | |
2c22120f | 13 | #include <linux/completion.h> |
30631cb8 | 14 | #include <linux/mtd/flashchip.h> |
cd5f6346 | 15 | #include <linux/mtd/onenand_regs.h> |
cdc00130 | 16 | #include <linux/mtd/bbm.h> |
cd5f6346 | 17 | |
5988af23 | 18 | #define MAX_DIES 2 |
cd5f6346 KP |
19 | #define MAX_BUFFERRAM 2 |
20 | ||
21 | /* Scan and identify a OneNAND device */ | |
22 | extern int onenand_scan(struct mtd_info *mtd, int max_chips); | |
23 | /* Free resources held by the OneNAND device */ | |
24 | extern void onenand_release(struct mtd_info *mtd); | |
25 | ||
cd5f6346 KP |
26 | /** |
27 | * struct onenand_bufferram - OneNAND BufferRAM Data | |
abf3c0f2 | 28 | * @blockpage: block & page address in BufferRAM |
cd5f6346 KP |
29 | */ |
30 | struct onenand_bufferram { | |
abf3c0f2 | 31 | int blockpage; |
cd5f6346 KP |
32 | }; |
33 | ||
34 | /** | |
35 | * struct onenand_chip - OneNAND Private Flash Chip Data | |
ea9b6dcc | 36 | * @base: [BOARDSPECIFIC] address to access OneNAND |
5988af23 RH |
37 | * @dies: [INTERN][FLEX-ONENAND] number of dies on chip |
38 | * @boundary: [INTERN][FLEX-ONENAND] Boundary of the dies | |
39 | * @diesize: [INTERN][FLEX-ONENAND] Size of the dies | |
ea9b6dcc | 40 | * @chipsize: [INTERN] the size of one chip for multichip arrays |
5988af23 RH |
41 | * FIXME For Flex-OneNAND, chipsize holds maximum possible |
42 | * device size ie when all blocks are considered MLC | |
ea9b6dcc RD |
43 | * @device_id: [INTERN] device ID |
44 | * @density_mask: chip density, used for DDP devices | |
45 | * @verstion_id: [INTERN] version ID | |
46 | * @options: [BOARDSPECIFIC] various chip options. They can | |
47 | * partly be set to inform onenand_scan about | |
48 | * @erase_shift: [INTERN] number of address bits in a block | |
49 | * @page_shift: [INTERN] number of address bits in a page | |
ea9b6dcc | 50 | * @page_mask: [INTERN] a page per block mask |
ee9745fc | 51 | * @writesize: [INTERN] a real page size |
ea9b6dcc RD |
52 | * @bufferram_index: [INTERN] BufferRAM index |
53 | * @bufferram: [INTERN] BufferRAM info | |
54 | * @readw: [REPLACEABLE] hardware specific function for read short | |
55 | * @writew: [REPLACEABLE] hardware specific function for write short | |
56 | * @command: [REPLACEABLE] hardware specific function for writing | |
57 | * commands to the chip | |
58 | * @wait: [REPLACEABLE] hardware specific function for wait on ready | |
31bb999e KP |
59 | * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready |
60 | * @unlock_all: [REPLACEABLE] hardware specific function for unlock all | |
ea9b6dcc RD |
61 | * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area |
62 | * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area | |
63 | * @read_word: [REPLACEABLE] hardware specific function for read | |
64 | * register of OneNAND | |
65 | * @write_word: [REPLACEABLE] hardware specific function for write | |
66 | * register of OneNAND | |
67 | * @mmcontrol: sync burst read function | |
ad0d363b | 68 | * @chip_probe: [REPLACEABLE] hardware specific function for chip probe |
ea9b6dcc RD |
69 | * @block_markbad: function to mark a block as bad |
70 | * @scan_bbt: [REPLACEALBE] hardware specific function for scanning | |
71 | * Bad block Table | |
72 | * @chip_lock: [INTERN] spinlock used to protect access to this | |
73 | * structure and the chip | |
74 | * @wq: [INTERN] wait queue to sleep on if a OneNAND | |
75 | * operation is in progress | |
76 | * @state: [INTERN] the current state of the OneNAND device | |
470bc844 KP |
77 | * @page_buf: [INTERN] page main data buffer |
78 | * @oob_buf: [INTERN] page oob data buffer | |
60d84f97 | 79 | * @subpagesize: [INTERN] holds the subpagesize |
ea9b6dcc RD |
80 | * @bbm: [REPLACEABLE] pointer to Bad Block Management |
81 | * @priv: [OPTIONAL] pointer to private chip date | |
cd5f6346 KP |
82 | */ |
83 | struct onenand_chip { | |
84 | void __iomem *base; | |
5988af23 RH |
85 | unsigned dies; |
86 | unsigned boundary[MAX_DIES]; | |
87 | loff_t diesize[MAX_DIES]; | |
cd5f6346 KP |
88 | unsigned int chipsize; |
89 | unsigned int device_id; | |
28b79ff9 | 90 | unsigned int version_id; |
5988af23 | 91 | unsigned int technology; |
83a36838 | 92 | unsigned int density_mask; |
cd5f6346 | 93 | unsigned int options; |
bfd15c90 | 94 | unsigned int badblockpos; |
cd5f6346 KP |
95 | |
96 | unsigned int erase_shift; | |
97 | unsigned int page_shift; | |
cd5f6346 | 98 | unsigned int page_mask; |
ee9745fc | 99 | unsigned int writesize; |
cd5f6346 KP |
100 | |
101 | unsigned int bufferram_index; | |
102 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; | |
103 | ||
104 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); | |
105 | int (*wait)(struct mtd_info *mtd, int state); | |
31bb999e KP |
106 | int (*bbt_wait)(struct mtd_info *mtd, int state); |
107 | void (*unlock_all)(struct mtd_info *mtd); | |
cd5f6346 KP |
108 | int (*read_bufferram)(struct mtd_info *mtd, int area, |
109 | unsigned char *buffer, int offset, size_t count); | |
110 | int (*write_bufferram)(struct mtd_info *mtd, int area, | |
111 | const unsigned char *buffer, int offset, size_t count); | |
112 | unsigned short (*read_word)(void __iomem *addr); | |
113 | void (*write_word)(unsigned short value, void __iomem *addr); | |
52b0eea7 | 114 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
ad0d363b | 115 | int (*chip_probe)(struct mtd_info *mtd); |
cdc00130 KP |
116 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
117 | int (*scan_bbt)(struct mtd_info *mtd); | |
cf24dc85 AH |
118 | int (*enable)(struct mtd_info *mtd); |
119 | int (*disable)(struct mtd_info *mtd); | |
cd5f6346 | 120 | |
2c22120f KP |
121 | struct completion complete; |
122 | int irq; | |
123 | ||
cd5f6346 KP |
124 | spinlock_t chip_lock; |
125 | wait_queue_head_t wq; | |
30631cb8 | 126 | flstate_t state; |
532a37cf | 127 | unsigned char *page_buf; |
470bc844 | 128 | unsigned char *oob_buf; |
4a8ce0b0 KP |
129 | #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE |
130 | unsigned char *verify_buf; | |
131 | #endif | |
cd5f6346 | 132 | |
60d84f97 | 133 | int subpagesize; |
cd5f6346 | 134 | |
5bd34c09 | 135 | void *bbm; |
cdc00130 | 136 | |
cd5f6346 | 137 | void *priv; |
3e3198f1 RT |
138 | |
139 | /* | |
140 | * Shows that the current operation is composed | |
141 | * of sequence of commands. For example, cache program. | |
142 | * Such command status OnGo bit is checked at the end of | |
143 | * sequence. | |
144 | */ | |
145 | unsigned int ongoing; | |
cd5f6346 KP |
146 | }; |
147 | ||
fcc31470 KP |
148 | /* |
149 | * Helper macros | |
150 | */ | |
3cf60253 AKS |
151 | #define ONENAND_PAGES_PER_BLOCK (1<<6) |
152 | ||
cd5f6346 KP |
153 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
154 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) | |
155 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) | |
a8de85d5 | 156 | #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) |
ee9745fc KP |
157 | #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) |
158 | #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) | |
cd5f6346 | 159 | |
5988af23 RH |
160 | #define FLEXONENAND(this) \ |
161 | (this->device_id & DEVICE_IS_FLEXONENAND) | |
fcc31470 KP |
162 | #define ONENAND_GET_SYS_CFG1(this) \ |
163 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) | |
164 | #define ONENAND_SET_SYS_CFG1(v, this) \ | |
165 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) | |
166 | ||
738d61f5 KP |
167 | #define ONENAND_IS_DDP(this) \ |
168 | (this->device_id & ONENAND_DEVICE_IS_DDP) | |
169 | ||
5988af23 RH |
170 | #define ONENAND_IS_MLC(this) \ |
171 | (this->technology & ONENAND_TECHNOLOGY_IS_MLC) | |
172 | ||
ee9745fc KP |
173 | #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM |
174 | #define ONENAND_IS_2PLANE(this) \ | |
175 | (this->options & ONENAND_HAS_2PLANE) | |
176 | #else | |
177 | #define ONENAND_IS_2PLANE(this) (0) | |
178 | #endif | |
179 | ||
3e3198f1 RT |
180 | #define ONENAND_IS_CACHE_PROGRAM(this) \ |
181 | (this->options & ONENAND_HAS_CACHE_PROGRAM) | |
182 | ||
e1c10243 KP |
183 | #define ONENAND_IS_NOP_1(this) \ |
184 | (this->options & ONENAND_HAS_NOP_1) | |
185 | ||
9c01f87d KP |
186 | /* Check byte access in OneNAND */ |
187 | #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) | |
188 | ||
bfd15c90 FS |
189 | #define ONENAND_BADBLOCK_POS 0 |
190 | ||
cd5f6346 KP |
191 | /* |
192 | * Options bits | |
193 | */ | |
28b79ff9 KP |
194 | #define ONENAND_HAS_CONT_LOCK (0x0001) |
195 | #define ONENAND_HAS_UNLOCK_ALL (0x0002) | |
ee9745fc | 196 | #define ONENAND_HAS_2PLANE (0x0004) |
6a88c47b | 197 | #define ONENAND_HAS_4KB_PAGE (0x0008) |
3e3198f1 | 198 | #define ONENAND_HAS_CACHE_PROGRAM (0x0010) |
e1c10243 | 199 | #define ONENAND_HAS_NOP_1 (0x0020) |
31bb999e | 200 | #define ONENAND_SKIP_UNLOCK_CHECK (0x0100) |
532a37cf | 201 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
470bc844 | 202 | #define ONENAND_OOBBUF_ALLOC (0x2000) |
b3dcfd35 | 203 | #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000) |
cd5f6346 | 204 | |
6a88c47b KP |
205 | #define ONENAND_IS_4KB_PAGE(this) \ |
206 | (this->options & ONENAND_HAS_4KB_PAGE) | |
207 | ||
cd5f6346 KP |
208 | /* |
209 | * OneNAND Flash Manufacturer ID Codes | |
210 | */ | |
211 | #define ONENAND_MFR_SAMSUNG 0xec | |
ee8f3768 | 212 | #define ONENAND_MFR_NUMONYX 0x20 |
cd5f6346 KP |
213 | |
214 | /** | |
ea9b6dcc RD |
215 | * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure |
216 | * @name: Manufacturer name | |
217 | * @id: manufacturer ID code of device. | |
cd5f6346 KP |
218 | */ |
219 | struct onenand_manufacturers { | |
220 | int id; | |
221 | char *name; | |
222 | }; | |
223 | ||
607d1cb1 AB |
224 | int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, |
225 | struct mtd_oob_ops *ops); | |
5988af23 RH |
226 | unsigned onenand_block(struct onenand_chip *this, loff_t addr); |
227 | loff_t onenand_addr(struct onenand_chip *this, int block); | |
228 | int flexonenand_region(struct mtd_info *mtd, loff_t addr); | |
607d1cb1 | 229 | |
778dbcc1 MD |
230 | struct mtd_partition; |
231 | ||
232 | struct onenand_platform_data { | |
233 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); | |
3328dc31 KP |
234 | int (*read_bufferram)(struct mtd_info *mtd, int area, |
235 | unsigned char *buffer, int offset, size_t count); | |
778dbcc1 MD |
236 | struct mtd_partition *parts; |
237 | unsigned int nr_parts; | |
238 | }; | |
239 | ||
cd5f6346 | 240 | #endif /* __LINUX_MTD_ONENAND_H */ |