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