nand.h revision 1.2.4.5 1 1.2.4.2 rmind /* $NetBSD: nand.h,v 1.2.4.5 2011/05/31 03:04:38 rmind Exp $ */
2 1.2.4.2 rmind
3 1.2.4.2 rmind /*-
4 1.2.4.2 rmind * Copyright (c) 2010 Department of Software Engineering,
5 1.2.4.2 rmind * University of Szeged, Hungary
6 1.2.4.2 rmind * Copyright (c) 2010 Adam Hoka <ahoka (at) NetBSD.org>
7 1.2.4.2 rmind * All rights reserved.
8 1.2.4.2 rmind *
9 1.2.4.2 rmind * This code is derived from software contributed to The NetBSD Foundation
10 1.2.4.2 rmind * by the Department of Software Engineering, University of Szeged, Hungary
11 1.2.4.2 rmind *
12 1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
13 1.2.4.2 rmind * modification, are permitted provided that the following conditions
14 1.2.4.2 rmind * are met:
15 1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
16 1.2.4.2 rmind * notice, this list of conditions and the following disclaimer.
17 1.2.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
18 1.2.4.2 rmind * notice, this list of conditions and the following disclaimer in the
19 1.2.4.2 rmind * documentation and/or other materials provided with the distribution.
20 1.2.4.2 rmind *
21 1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.2.4.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2.4.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2.4.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.2.4.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 1.2.4.2 rmind * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.2.4.2 rmind * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 1.2.4.2 rmind * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 1.2.4.2 rmind * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.2.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.2.4.2 rmind * SUCH DAMAGE.
32 1.2.4.2 rmind */
33 1.2.4.2 rmind
34 1.2.4.2 rmind #ifndef _NAND_H_
35 1.2.4.2 rmind #define _NAND_H_
36 1.2.4.2 rmind
37 1.2.4.2 rmind #include <sys/param.h>
38 1.2.4.2 rmind #include <sys/cdefs.h>
39 1.2.4.2 rmind
40 1.2.4.2 rmind #include <sys/bufq.h>
41 1.2.4.2 rmind #include <sys/buf.h>
42 1.2.4.2 rmind #include <sys/time.h>
43 1.2.4.2 rmind
44 1.2.4.4 rmind #include <dev/nand/onfi.h>
45 1.2.4.2 rmind #include <dev/flash/flash.h>
46 1.2.4.2 rmind
47 1.2.4.2 rmind #ifdef NAND_DEBUG
48 1.2.4.5 rmind #define DPRINTF(x) printf x
49 1.2.4.2 rmind #else
50 1.2.4.2 rmind #define DPRINTF(x)
51 1.2.4.2 rmind #endif
52 1.2.4.2 rmind
53 1.2.4.4 rmind //#define NAND_VERBOSE
54 1.2.4.2 rmind
55 1.2.4.2 rmind /* same as in linux for compatibility */
56 1.2.4.2 rmind enum {
57 1.2.4.2 rmind NAND_BAD_MARKER_OFFSET = 0,
58 1.2.4.2 rmind NAND_BAD_MARKER_OFFSET_SMALL = 5
59 1.2.4.2 rmind };
60 1.2.4.2 rmind
61 1.2.4.2 rmind /* feature flags use in nc_flags */
62 1.2.4.2 rmind enum {
63 1.2.4.2 rmind NC_BUSWIDTH_16 = (1<<0),
64 1.2.4.2 rmind NC_SOURCE_SYNC = (1<<2),
65 1.2.4.2 rmind NC_INTERLEAVED_PE = (1<<1),
66 1.2.4.2 rmind NC_INTERLEAVED_R = (1<<3),
67 1.2.4.2 rmind NC_EXTENDED_PARAM = (1<<4)
68 1.2.4.2 rmind };
69 1.2.4.2 rmind
70 1.2.4.2 rmind /* various quirks used in nc_quirks */
71 1.2.4.2 rmind enum {
72 1.2.4.2 rmind NC_QUIRK_NO_READ_START = (1<<0)
73 1.2.4.2 rmind };
74 1.2.4.2 rmind
75 1.2.4.2 rmind enum {
76 1.2.4.2 rmind NAND_ECC_READ,
77 1.2.4.2 rmind NAND_ECC_WRITE
78 1.2.4.2 rmind };
79 1.2.4.2 rmind
80 1.2.4.2 rmind enum {
81 1.2.4.2 rmind NAND_ECC_OK,
82 1.2.4.2 rmind NAND_ECC_CORRECTED,
83 1.2.4.2 rmind NAND_ECC_INVALID,
84 1.2.4.2 rmind NAND_ECC_TWOBIT
85 1.2.4.2 rmind };
86 1.2.4.2 rmind
87 1.2.4.2 rmind enum {
88 1.2.4.2 rmind NAND_ECC_TYPE_HW,
89 1.2.4.2 rmind NAND_ECC_TYPE_SW
90 1.2.4.2 rmind };
91 1.2.4.2 rmind
92 1.2.4.2 rmind struct nand_bbt {
93 1.2.4.2 rmind uint8_t *nbbt_bitmap;
94 1.2.4.2 rmind size_t nbbt_size;
95 1.2.4.2 rmind };
96 1.2.4.2 rmind
97 1.2.4.2 rmind struct nand_ecc {
98 1.2.4.2 rmind size_t necc_offset; /* offset of ecc data in oob */
99 1.2.4.2 rmind size_t necc_size; /* size of ecc data in oob */
100 1.2.4.2 rmind size_t necc_block_size; /* block size used in ecc calc */
101 1.2.4.2 rmind size_t necc_code_size; /* reduntant bytes per block */
102 1.2.4.2 rmind int necc_steps; /* pagesize / code size */
103 1.2.4.2 rmind int necc_type; /* type of the ecc engine */
104 1.2.4.2 rmind };
105 1.2.4.2 rmind
106 1.2.4.2 rmind /**
107 1.2.4.2 rmind * nand_chip: structure containing the required information
108 1.2.4.2 rmind * about the NAND chip.
109 1.2.4.2 rmind */
110 1.2.4.2 rmind struct nand_chip {
111 1.2.4.4 rmind struct nand_ecc *nc_ecc; /* ecc information */
112 1.2.4.2 rmind uint8_t *nc_oob_cache; /* buffer for oob cache */
113 1.2.4.2 rmind uint8_t *nc_page_cache; /* buffer for page cache */
114 1.2.4.2 rmind uint8_t *nc_ecc_cache;
115 1.2.4.2 rmind size_t nc_size; /* storage size in bytes */
116 1.2.4.2 rmind size_t nc_page_size; /* page size in bytes */
117 1.2.4.2 rmind size_t nc_block_pages; /* block size in pages */
118 1.2.4.2 rmind size_t nc_block_size; /* block size in bytes */
119 1.2.4.2 rmind size_t nc_spare_size; /* spare (oob) size in bytes */
120 1.2.4.4 rmind uint32_t nc_lun_blocks; /* LUN size in blocks */
121 1.2.4.2 rmind uint32_t nc_flags; /* bitfield flags */
122 1.2.4.2 rmind uint32_t nc_quirks; /* bitfield quirks */
123 1.2.4.2 rmind unsigned int nc_page_shift; /* page shift for page alignment */
124 1.2.4.2 rmind unsigned int nc_page_mask; /* page mask for page alignment */
125 1.2.4.2 rmind unsigned int nc_block_shift; /* write shift */
126 1.2.4.2 rmind unsigned int nc_block_mask; /* write mask */
127 1.2.4.4 rmind uint8_t nc_num_luns; /* number of LUNs */
128 1.2.4.2 rmind uint8_t nc_manf_id; /* manufacturer id */
129 1.2.4.2 rmind uint8_t nc_dev_id; /* device id */
130 1.2.4.2 rmind uint8_t nc_addr_cycles_row; /* row cycles for addressing */
131 1.2.4.2 rmind uint8_t nc_addr_cycles_column; /* column cycles for addressing */
132 1.2.4.2 rmind uint8_t nc_badmarker_offs; /* offset for marking bad blocks */
133 1.2.4.4 rmind bool nc_isonfi; /* if the device is onfi compliant */
134 1.2.4.2 rmind };
135 1.2.4.2 rmind
136 1.2.4.2 rmind struct nand_write_cache {
137 1.2.4.2 rmind struct bintime nwc_creation;
138 1.2.4.2 rmind struct bintime nwc_last_write;
139 1.2.4.2 rmind struct bufq_state *nwc_bufq;
140 1.2.4.2 rmind uint8_t *nwc_data;
141 1.2.4.2 rmind daddr_t nwc_block;
142 1.2.4.2 rmind kmutex_t nwc_lock;
143 1.2.4.2 rmind bool nwc_write_pending;
144 1.2.4.5 rmind struct lwp *nwc_thread;
145 1.2.4.5 rmind kcondvar_t nwc_cv;
146 1.2.4.5 rmind bool nwc_exiting;
147 1.2.4.2 rmind };
148 1.2.4.2 rmind
149 1.2.4.2 rmind /* driver softc for nand */
150 1.2.4.2 rmind struct nand_softc {
151 1.2.4.2 rmind device_t sc_dev;
152 1.2.4.4 rmind device_t controller_dev;
153 1.2.4.2 rmind struct nand_interface *nand_if;
154 1.2.4.2 rmind void *nand_softc;
155 1.2.4.2 rmind struct nand_chip sc_chip;
156 1.2.4.2 rmind struct nand_bbt sc_bbt;
157 1.2.4.2 rmind size_t sc_part_offset;
158 1.2.4.2 rmind size_t sc_part_size;
159 1.2.4.2 rmind kmutex_t sc_device_lock; /* serialize access to chip */
160 1.2.4.2 rmind struct nand_write_cache sc_cache;
161 1.2.4.2 rmind };
162 1.2.4.2 rmind
163 1.2.4.2 rmind /* structure holding the nand api */
164 1.2.4.2 rmind struct nand_interface
165 1.2.4.2 rmind {
166 1.2.4.4 rmind /* basic nand controller commands */
167 1.2.4.4 rmind void (*select) (device_t, bool); /* optional */
168 1.2.4.2 rmind void (*command) (device_t, uint8_t);
169 1.2.4.2 rmind void (*address) (device_t, uint8_t);
170 1.2.4.2 rmind void (*read_buf_byte) (device_t, void *, size_t);
171 1.2.4.2 rmind void (*read_buf_word) (device_t, void *, size_t);
172 1.2.4.2 rmind void (*read_byte) (device_t, uint8_t *);
173 1.2.4.2 rmind void (*read_word) (device_t, uint16_t *);
174 1.2.4.2 rmind void (*write_buf_byte) (device_t, const void *, size_t);
175 1.2.4.2 rmind void (*write_buf_word) (device_t, const void *, size_t);
176 1.2.4.2 rmind void (*write_byte) (device_t, uint8_t);
177 1.2.4.2 rmind void (*write_word) (device_t, uint16_t);
178 1.2.4.2 rmind void (*busy) (device_t);
179 1.2.4.2 rmind
180 1.2.4.4 rmind /* "smart" controllers may override read/program functions */
181 1.2.4.4 rmind int (*read_page) (device_t, size_t, uint8_t *); /* optional */
182 1.2.4.4 rmind int (*program_page) (device_t, size_t, const uint8_t *); /* optional */
183 1.2.4.4 rmind
184 1.2.4.2 rmind /* functions specific to ecc computation */
185 1.2.4.4 rmind int (*ecc_prepare)(device_t, int); /* optional */
186 1.2.4.2 rmind int (*ecc_compute)(device_t, const uint8_t *, uint8_t *);
187 1.2.4.2 rmind int (*ecc_correct)(device_t, uint8_t *, const uint8_t *,
188 1.2.4.2 rmind const uint8_t *);
189 1.2.4.2 rmind
190 1.2.4.4 rmind /* information for the ecc engine */
191 1.2.4.2 rmind struct nand_ecc ecc;
192 1.2.4.2 rmind
193 1.2.4.2 rmind /* flash partition information */
194 1.2.4.2 rmind const struct flash_partition *part_info;
195 1.2.4.2 rmind int part_num;
196 1.2.4.2 rmind };
197 1.2.4.2 rmind
198 1.2.4.2 rmind /* attach args */
199 1.2.4.2 rmind struct nand_attach_args {
200 1.2.4.2 rmind struct nand_interface *naa_nand_if;
201 1.2.4.2 rmind };
202 1.2.4.2 rmind
203 1.2.4.2 rmind static inline void
204 1.2.4.2 rmind nand_busy(device_t device)
205 1.2.4.2 rmind {
206 1.2.4.2 rmind struct nand_softc *sc = device_private(device);
207 1.2.4.2 rmind
208 1.2.4.2 rmind KASSERT(sc->nand_if->select != NULL);
209 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
210 1.2.4.2 rmind
211 1.2.4.4 rmind sc->nand_if->select(sc->controller_dev, true);
212 1.2.4.2 rmind
213 1.2.4.2 rmind if (sc->nand_if->busy != NULL) {
214 1.2.4.4 rmind sc->nand_if->busy(sc->controller_dev);
215 1.2.4.2 rmind }
216 1.2.4.2 rmind
217 1.2.4.4 rmind sc->nand_if->select(sc->controller_dev, false);
218 1.2.4.2 rmind }
219 1.2.4.2 rmind
220 1.2.4.2 rmind static inline void
221 1.2.4.2 rmind nand_select(device_t self, bool enable)
222 1.2.4.2 rmind {
223 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
224 1.2.4.2 rmind
225 1.2.4.2 rmind KASSERT(sc->nand_if->select != NULL);
226 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
227 1.2.4.2 rmind
228 1.2.4.4 rmind sc->nand_if->select(sc->controller_dev, enable);
229 1.2.4.2 rmind }
230 1.2.4.2 rmind
231 1.2.4.2 rmind static inline void
232 1.2.4.2 rmind nand_address(device_t self, uint32_t address)
233 1.2.4.2 rmind {
234 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
235 1.2.4.2 rmind
236 1.2.4.2 rmind KASSERT(sc->nand_if->address != NULL);
237 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
238 1.2.4.2 rmind
239 1.2.4.4 rmind sc->nand_if->address(sc->controller_dev, address);
240 1.2.4.2 rmind }
241 1.2.4.2 rmind
242 1.2.4.2 rmind static inline void
243 1.2.4.2 rmind nand_command(device_t self, uint8_t command)
244 1.2.4.2 rmind {
245 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
246 1.2.4.2 rmind
247 1.2.4.2 rmind KASSERT(sc->nand_if->command != NULL);
248 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
249 1.2.4.2 rmind
250 1.2.4.4 rmind sc->nand_if->command(sc->controller_dev, command);
251 1.2.4.2 rmind }
252 1.2.4.2 rmind
253 1.2.4.2 rmind static inline void
254 1.2.4.2 rmind nand_read_byte(device_t self, uint8_t *data)
255 1.2.4.2 rmind {
256 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
257 1.2.4.2 rmind
258 1.2.4.2 rmind KASSERT(sc->nand_if->read_byte != NULL);
259 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
260 1.2.4.2 rmind
261 1.2.4.4 rmind sc->nand_if->read_byte(sc->controller_dev, data);
262 1.2.4.2 rmind }
263 1.2.4.2 rmind
264 1.2.4.2 rmind static inline void
265 1.2.4.2 rmind nand_write_byte(device_t self, uint8_t data)
266 1.2.4.2 rmind {
267 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
268 1.2.4.2 rmind
269 1.2.4.2 rmind KASSERT(sc->nand_if->write_byte != NULL);
270 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
271 1.2.4.2 rmind
272 1.2.4.4 rmind sc->nand_if->write_byte(sc->controller_dev, data);
273 1.2.4.2 rmind }
274 1.2.4.2 rmind
275 1.2.4.2 rmind static inline void
276 1.2.4.2 rmind nand_read_word(device_t self, uint16_t *data)
277 1.2.4.2 rmind {
278 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
279 1.2.4.2 rmind
280 1.2.4.2 rmind KASSERT(sc->nand_if->read_word != NULL);
281 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
282 1.2.4.2 rmind
283 1.2.4.4 rmind sc->nand_if->read_word(sc->controller_dev, data);
284 1.2.4.2 rmind }
285 1.2.4.2 rmind
286 1.2.4.2 rmind static inline void
287 1.2.4.2 rmind nand_write_word(device_t self, uint16_t data)
288 1.2.4.2 rmind {
289 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
290 1.2.4.2 rmind
291 1.2.4.2 rmind KASSERT(sc->nand_if->write_word != NULL);
292 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
293 1.2.4.2 rmind
294 1.2.4.4 rmind sc->nand_if->write_word(sc->controller_dev, data);
295 1.2.4.2 rmind }
296 1.2.4.2 rmind
297 1.2.4.2 rmind static inline void
298 1.2.4.2 rmind nand_read_buf_byte(device_t self, void *buf, size_t size)
299 1.2.4.2 rmind {
300 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
301 1.2.4.2 rmind
302 1.2.4.2 rmind KASSERT(sc->nand_if->read_buf_byte != NULL);
303 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
304 1.2.4.2 rmind
305 1.2.4.4 rmind sc->nand_if->read_buf_byte(sc->controller_dev, buf, size);
306 1.2.4.2 rmind }
307 1.2.4.2 rmind
308 1.2.4.2 rmind static inline void
309 1.2.4.2 rmind nand_read_buf_word(device_t self, void *buf, size_t size)
310 1.2.4.2 rmind {
311 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
312 1.2.4.2 rmind
313 1.2.4.2 rmind KASSERT(sc->nand_if->read_buf_word != NULL);
314 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
315 1.2.4.2 rmind
316 1.2.4.4 rmind sc->nand_if->read_buf_word(sc->controller_dev, buf, size);
317 1.2.4.2 rmind }
318 1.2.4.2 rmind
319 1.2.4.2 rmind static inline void
320 1.2.4.2 rmind nand_write_buf_byte(device_t self, const void *buf, size_t size)
321 1.2.4.2 rmind {
322 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
323 1.2.4.2 rmind
324 1.2.4.2 rmind KASSERT(sc->nand_if->write_buf_byte != NULL);
325 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
326 1.2.4.4 rmind
327 1.2.4.4 rmind sc->nand_if->write_buf_byte(sc->controller_dev, buf, size);
328 1.2.4.2 rmind }
329 1.2.4.2 rmind
330 1.2.4.2 rmind static inline void
331 1.2.4.2 rmind nand_write_buf_word(device_t self, const void *buf, size_t size)
332 1.2.4.2 rmind {
333 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
334 1.2.4.2 rmind
335 1.2.4.2 rmind KASSERT(sc->nand_if->write_buf_word != NULL);
336 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
337 1.2.4.4 rmind
338 1.2.4.4 rmind sc->nand_if->write_buf_word(sc->controller_dev, buf, size);
339 1.2.4.2 rmind }
340 1.2.4.2 rmind
341 1.2.4.2 rmind static inline int
342 1.2.4.2 rmind nand_ecc_correct(device_t self, uint8_t *data, const uint8_t *oldcode,
343 1.2.4.2 rmind const uint8_t *newcode)
344 1.2.4.2 rmind {
345 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
346 1.2.4.2 rmind
347 1.2.4.2 rmind KASSERT(sc->nand_if->ecc_correct != NULL);
348 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
349 1.2.4.2 rmind
350 1.2.4.4 rmind return sc->nand_if->ecc_correct(sc->controller_dev, data, oldcode, newcode);
351 1.2.4.2 rmind }
352 1.2.4.2 rmind
353 1.2.4.2 rmind static inline void
354 1.2.4.2 rmind nand_ecc_compute(device_t self, const uint8_t *data, uint8_t *code)
355 1.2.4.2 rmind {
356 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
357 1.2.4.2 rmind
358 1.2.4.2 rmind KASSERT(sc->nand_if->ecc_compute != NULL);
359 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
360 1.2.4.2 rmind
361 1.2.4.4 rmind sc->nand_if->ecc_compute(sc->controller_dev, data, code);
362 1.2.4.2 rmind }
363 1.2.4.2 rmind
364 1.2.4.2 rmind static inline void
365 1.2.4.2 rmind nand_ecc_prepare(device_t self, int mode)
366 1.2.4.2 rmind {
367 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
368 1.2.4.2 rmind
369 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
370 1.2.4.4 rmind
371 1.2.4.2 rmind if (sc->nand_if->ecc_prepare != NULL)
372 1.2.4.4 rmind sc->nand_if->ecc_prepare(sc->controller_dev, mode);
373 1.2.4.4 rmind }
374 1.2.4.4 rmind
375 1.2.4.4 rmind static inline int
376 1.2.4.4 rmind nand_program_page(device_t self, size_t offset, const uint8_t *data)
377 1.2.4.4 rmind {
378 1.2.4.4 rmind struct nand_softc *sc = device_private(self);
379 1.2.4.4 rmind
380 1.2.4.4 rmind KASSERT(sc->nand_if->program_page != NULL);
381 1.2.4.4 rmind
382 1.2.4.4 rmind return sc->nand_if->program_page(self, offset, data);
383 1.2.4.4 rmind }
384 1.2.4.4 rmind
385 1.2.4.4 rmind static inline int
386 1.2.4.4 rmind nand_read_page(device_t self, size_t offset, uint8_t *data)
387 1.2.4.4 rmind {
388 1.2.4.4 rmind struct nand_softc *sc = device_private(self);
389 1.2.4.4 rmind
390 1.2.4.4 rmind KASSERT(sc->nand_if->read_page != NULL);
391 1.2.4.4 rmind
392 1.2.4.4 rmind return sc->nand_if->read_page(self, offset, data);
393 1.2.4.2 rmind }
394 1.2.4.2 rmind
395 1.2.4.2 rmind #if 0
396 1.2.4.2 rmind static inline bool
397 1.2.4.4 rmind nand_block_isbad(device_t self, flash_off_t block)
398 1.2.4.2 rmind {
399 1.2.4.2 rmind struct nand_softc *sc = device_private(self);
400 1.2.4.4 rmind
401 1.2.4.2 rmind KASSERT(sc->nand_if->block_isbad != NULL);
402 1.2.4.4 rmind KASSERT(sc->controller_dev != NULL);
403 1.2.4.4 rmind
404 1.2.4.4 rmind return sc->nand_if->block_isbad(sc->controller_dev, block);
405 1.2.4.2 rmind }
406 1.2.4.2 rmind #endif
407 1.2.4.2 rmind
408 1.2.4.2 rmind /* Manufacturer IDs defined by JEDEC */
409 1.2.4.2 rmind enum {
410 1.2.4.2 rmind NAND_MFR_UNKNOWN = 0x00,
411 1.2.4.2 rmind NAND_MFR_AMD = 0x01,
412 1.2.4.2 rmind NAND_MFR_FUJITSU = 0x04,
413 1.2.4.2 rmind NAND_MFR_RENESAS = 0x07,
414 1.2.4.2 rmind NAND_MFR_STMICRO = 0x20,
415 1.2.4.2 rmind NAND_MFR_MICRON = 0x2c,
416 1.2.4.2 rmind NAND_MFR_NATIONAL = 0x8f,
417 1.2.4.2 rmind NAND_MFR_TOSHIBA = 0x98,
418 1.2.4.2 rmind NAND_MFR_HYNIX = 0xad,
419 1.2.4.2 rmind NAND_MFR_SAMSUNG = 0xec
420 1.2.4.2 rmind };
421 1.2.4.2 rmind
422 1.2.4.2 rmind struct nand_manufacturer {
423 1.2.4.2 rmind int id;
424 1.2.4.2 rmind const char *name;
425 1.2.4.2 rmind };
426 1.2.4.2 rmind
427 1.2.4.2 rmind extern const struct nand_manufacturer nand_mfrs[];
428 1.2.4.2 rmind
429 1.2.4.4 rmind /*
430 1.2.4.4 rmind * Manufacturer specific parameter functions
431 1.2.4.4 rmind */
432 1.2.4.4 rmind int nand_read_parameters_micron(device_t, struct nand_chip *);
433 1.2.4.4 rmind
434 1.2.4.4 rmind /* debug inlines */
435 1.2.4.4 rmind
436 1.2.4.2 rmind static inline void
437 1.2.4.2 rmind nand_dump_data(const char *name, void *data, size_t len)
438 1.2.4.2 rmind {
439 1.2.4.2 rmind uint8_t *dump = data;
440 1.2.4.3 rmind int i;
441 1.2.4.3 rmind
442 1.2.4.3 rmind printf("dumping %s\n--------------\n", name);
443 1.2.4.3 rmind for (i = 0; i < len; i++) {
444 1.2.4.2 rmind printf("0x%.2hhx ", *dump);
445 1.2.4.2 rmind dump++;
446 1.2.4.2 rmind }
447 1.2.4.2 rmind printf("\n--------------\n");
448 1.2.4.2 rmind }
449 1.2.4.2 rmind
450 1.2.4.4 rmind /* flash interface implementation */
451 1.2.4.4 rmind int nand_flash_isbad(device_t, flash_off_t, bool *);
452 1.2.4.4 rmind int nand_flash_markbad(device_t, flash_off_t);
453 1.2.4.4 rmind int nand_flash_write(device_t, flash_off_t, size_t, size_t *, const u_char *);
454 1.2.4.4 rmind int nand_flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *);
455 1.2.4.4 rmind int nand_flash_erase(device_t, struct flash_erase_instruction *);
456 1.2.4.4 rmind
457 1.2.4.4 rmind /* nand specific functions */
458 1.2.4.4 rmind int nand_erase_block(device_t, size_t);
459 1.2.4.4 rmind
460 1.2.4.4 rmind int nand_io_submit(device_t, struct buf *);
461 1.2.4.4 rmind void nand_sync_thread(void *);
462 1.2.4.4 rmind int nand_sync_thread_start(device_t);
463 1.2.4.4 rmind void nand_sync_thread_stop(device_t);
464 1.2.4.4 rmind
465 1.2.4.4 rmind bool nand_isfactorybad(device_t, flash_off_t);
466 1.2.4.4 rmind bool nand_iswornoutbad(device_t, flash_off_t);
467 1.2.4.4 rmind bool nand_isbad(device_t, flash_off_t);
468 1.2.4.4 rmind void nand_markbad(device_t, size_t);
469 1.2.4.4 rmind
470 1.2.4.4 rmind //int nand_read_page(device_t, size_t, uint8_t *);
471 1.2.4.4 rmind int nand_read_oob(device_t, size_t, uint8_t *);
472 1.2.4.4 rmind //int nand_program_page(device_t, size_t, const uint8_t *);
473 1.2.4.4 rmind
474 1.2.4.4 rmind device_t nand_attach_mi(struct nand_interface *, device_t);
475 1.2.4.4 rmind void nand_init_interface(struct nand_interface *);
476 1.2.4.4 rmind
477 1.2.4.4 rmind /* controller drivers may use these functions to get info about the chip */
478 1.2.4.4 rmind void nand_read_id(device_t, uint8_t *, uint8_t *);
479 1.2.4.4 rmind int nand_read_parameter_page(device_t, struct onfi_parameter_page *);
480 1.2.4.4 rmind
481 1.2.4.4 rmind /*
482 1.2.4.4 rmind * default functions for driver development
483 1.2.4.4 rmind */
484 1.2.4.4 rmind void nand_default_select(device_t, bool);
485 1.2.4.4 rmind int nand_default_ecc_compute(device_t, const uint8_t *, uint8_t *);
486 1.2.4.4 rmind int nand_default_ecc_correct(device_t, uint8_t *, const uint8_t *,
487 1.2.4.4 rmind const uint8_t *);
488 1.2.4.4 rmind int nand_default_read_page(device_t, size_t, uint8_t *);
489 1.2.4.4 rmind int nand_default_program_page(device_t, size_t, const uint8_t *);
490 1.2.4.4 rmind
491 1.2.4.4 rmind static inline void nand_busy(device_t);
492 1.2.4.4 rmind static inline void nand_select(device_t, bool);
493 1.2.4.4 rmind static inline void nand_command(device_t, uint8_t);
494 1.2.4.4 rmind static inline void nand_address(device_t, uint32_t);
495 1.2.4.4 rmind static inline void nand_read_buf_byte(device_t, void *, size_t);
496 1.2.4.4 rmind static inline void nand_read_buf_word(device_t, void *, size_t);
497 1.2.4.4 rmind static inline void nand_read_byte(device_t, uint8_t *);
498 1.2.4.4 rmind static inline void nand_write_buf_byte(device_t, const void *, size_t);
499 1.2.4.4 rmind static inline void nand_write_buf_word(device_t, const void *, size_t);
500 1.2.4.4 rmind //static inline bool nand_block_isbad(device_t, off_t);
501 1.2.4.4 rmind //static inline void nand_block_markbad(device_t, off_t);
502 1.2.4.4 rmind //static inline bool nand_isbusy(device_t);
503 1.2.4.4 rmind
504 1.2.4.2 rmind #endif /* _NAND_H_ */
505