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