blob: a3c0a30d6454f038fc8161c29d31679c5e607a0b [file] [log] [blame]
xf.libfc6e712025-02-07 01:54:34 -08001/*
2 * linux/include/linux/mtd/nand.h
3 *
4 * Copyright (c) 2000 David Woodhouse <dwmw2@infradead.org>
5 * Steven J. Hill <sjhill@realitydiluted.com>
6 * Thomas Gleixner <tglx@linutronix.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Info:
13 * Contains standard defines and IDs for NAND flash devices
14 *
15 * Changelog:
16 * See git changelog.
17 */
18#ifndef __LINUX_MTD_NAND_H
19#define __LINUX_MTD_NAND_H
20
21/* XXX U-BOOT XXX */
22#if 0
23#include <linux/wait.h>
24#include <linux/spinlock.h>
25#include <linux/mtd/mtd.h>
26#endif
27
28#include "config.h"
29
30#include "linux/mtd/compat.h"
31#include "linux/mtd/mtd.h"
32#include "linux/mtd/bbm.h"
33
34
35struct mtd_info;
36struct nand_flash_dev;
37/* Scan and identify a NAND device */
38extern int nand_scan (struct mtd_info *mtd, int max_chips);
39/* Separate phases of nand_scan(), allowing board driver to intervene
40 * and override command or ECC setup according to flash type */
41extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
42 const struct nand_flash_dev *table);
43extern int nand_scan_tail(struct mtd_info *mtd);
44
45/* Free resources held by the NAND device */
46extern void nand_release (struct mtd_info *mtd);
47
48/* Internal helper for board drivers which need to override command function */
49extern void nand_wait_ready(struct mtd_info *mtd);
50
51/* This constant declares the max. oobsize / page, which
52 * is supported now. If you add a chip with bigger oobsize/page
53 * adjust this accordingly.
54 */
55//#define NAND_MAX_OOBSIZE 218
56#define NAND_MAX_OOBSIZE 256
57#define NAND_MAX_PAGESIZE 4096
58
59/*
60 * Constants for hardware specific CLE/ALE/NCE function
61 *
62 * These are bits which can be or'ed to set/clear multiple
63 * bits in one go.
64 */
65/* Select the chip by setting nCE to low */
66#define NAND_NCE 0x01
67/* Select the command latch by setting CLE to high */
68#define NAND_CLE 0x02
69/* Select the address latch by setting ALE to high */
70#define NAND_ALE 0x04
71
72#define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
73#define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
74#define NAND_CTRL_CHANGE 0x80
75
76/*
77 * Standard NAND flash commands
78 */
79#define NAND_CMD_READ0 0
80#define NAND_CMD_READ1 1
81#define NAND_CMD_RNDOUT 5
82#define NAND_CMD_PAGEPROG 0x10
83#define NAND_CMD_READOOB 0x50
84#define NAND_CMD_ERASE1 0x60
85#define NAND_CMD_STATUS 0x70
86#define NAND_CMD_STATUS_MULTI 0x71
87#define NAND_CMD_SEQIN 0x80
88#define NAND_CMD_RNDIN 0x85
89#define NAND_CMD_READID 0x90
90#define NAND_CMD_PARAM 0xec
91#define NAND_CMD_ERASE2 0xd0
92#define NAND_CMD_RESET 0xff
93
94/* Extended commands for large page devices */
95#define NAND_CMD_READSTART 0x30
96#define NAND_CMD_RNDOUTSTART 0xE0
97#define NAND_CMD_CACHEDPROG 0x15
98
99/* Extended commands for AG-AND device */
100/*
101 * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but
102 * there is no way to distinguish that from NAND_CMD_READ0
103 * until the remaining sequence of commands has been completed
104 * so add a high order bit and mask it off in the command.
105 */
106#define NAND_CMD_DEPLETE1 0x100
107#define NAND_CMD_DEPLETE2 0x38
108#define NAND_CMD_STATUS_MULTI 0x71
109#define NAND_CMD_STATUS_ERROR 0x72
110/* multi-bank error status (banks 0-3) */
111#define NAND_CMD_STATUS_ERROR0 0x73
112#define NAND_CMD_STATUS_ERROR1 0x74
113#define NAND_CMD_STATUS_ERROR2 0x75
114#define NAND_CMD_STATUS_ERROR3 0x76
115#define NAND_CMD_STATUS_RESET 0x7f
116#define NAND_CMD_STATUS_CLEAR 0xff
117
118#define NAND_CMD_NONE -1
119
120/* Status bits */
121#define NAND_STATUS_FAIL 0x01
122#define NAND_STATUS_FAIL_N1 0x02
123#define NAND_STATUS_TRUE_READY 0x20
124#define NAND_STATUS_READY 0x40
125#define NAND_STATUS_WP 0x80
126
127/*
128 * Constants for ECC_MODES
129 */
130typedef enum {
131 NAND_ECC_NONE,
132 NAND_ECC_SOFT,
133 NAND_ECC_HW,
134 NAND_ECC_HW_SYNDROME,
135 NAND_ECC_HW_OOB_FIRST,
136} nand_ecc_modes_t;
137
138/*
139 * Constants for Hardware ECC
140 */
141/* Reset Hardware ECC for read */
142#define NAND_ECC_READ 0
143/* Reset Hardware ECC for write */
144#define NAND_ECC_WRITE 1
145/* Enable Hardware ECC before syndrom is read back from flash */
146#define NAND_ECC_READSYN 2
147
148/* Bit mask for flags passed to do_nand_read_ecc */
149#define NAND_GET_DEVICE 0x80
150
151
152/* Option constants for bizarre disfunctionality and real
153* features
154*/
155/* Chip can not auto increment pages */
156#define NAND_NO_AUTOINCR 0x00000001
157/* Buswitdh is 16 bit */
158#define NAND_BUSWIDTH_16 0x00000002
159/* Device supports partial programming without padding */
160#define NAND_NO_PADDING 0x00000004
161/* Chip has cache program function */
162#define NAND_CACHEPRG 0x00000008
163/* Chip has copy back function */
164#define NAND_COPYBACK 0x00000010
165/* AND Chip which has 4 banks and a confusing page / block
166 * assignment. See Renesas datasheet for further information */
167#define NAND_IS_AND 0x00000020
168/* Chip has a array of 4 pages which can be read without
169 * additional ready /busy waits */
170#define NAND_4PAGE_ARRAY 0x00000040
171/* Chip requires that BBT is periodically rewritten to prevent
172 * bits from adjacent blocks from 'leaking' in altering data.
173 * This happens with the Renesas AG-AND chips, possibly others. */
174#define BBT_AUTO_REFRESH 0x00000080
175/* Chip does not require ready check on read. True
176 * for all large page devices, as they do not support
177 * autoincrement.*/
178#define NAND_NO_READRDY 0x00000100
179/* Chip does not allow subpage writes */
180#define NAND_NO_SUBPAGE_WRITE 0x00000200
181
182
183/* Options valid for Samsung large page devices */
184#define NAND_SAMSUNG_LP_OPTIONS \
185 (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
186
187/* Macros to identify the above */
188#define NAND_CANAUTOINCR(chip) (!(chip->options & NAND_NO_AUTOINCR))
189#define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING))
190#define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
191#define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK))
192/* Large page NAND with SOFT_ECC should support subpage reads */
193#define NAND_SUBPAGE_READ(chip) ((chip->ecc.mode == NAND_ECC_SOFT) \
194 && (chip->page_shift > 9))
195
196/* Mask to zero out the chip options, which come from the id table */
197#define NAND_CHIPOPTIONS_MSK (0x0000ffff & ~NAND_NO_AUTOINCR)
198
199/* Non chip related options */
200/* Use a flash based bad block table. This option is passed to the
201 * default bad block table function. */
202#define NAND_USE_FLASH_BBT 0x00010000
203/* This option skips the bbt scan during initialization. */
204#define NAND_SKIP_BBTSCAN 0x00020000
205/* This option is defined if the board driver allocates its own buffers
206 (e.g. because it needs them DMA-coherent */
207#define NAND_OWN_BUFFERS 0x00040000
208/* Options set by nand scan */
209/* bbt has already been read */
210#define NAND_BBT_SCANNED 0x40000000
211/* Nand scan has allocated controller struct */
212#define NAND_CONTROLLER_ALLOC 0x80000000
213
214/* Cell info constants */
215#define NAND_CI_CHIPNR_MSK 0x03
216#define NAND_CI_CELLTYPE_MSK 0x0C
217
218/* Keep gcc happy */
219struct nand_chip;
220
221struct nand_onfi_params {
222 /* rev info and features block */
223 /* 'O' 'N' 'F' 'I' */
224 u8 sig[4];
225 __le16 revision;
226 __le16 features;
227 __le16 opt_cmd;
228 u8 reserved[22];
229
230 /* manufacturer information block */
231 char manufacturer[12];
232 char model[20];
233 u8 jedec_id;
234 __le16 date_code;
235 u8 reserved2[13];
236
237 /* memory organization block */
238 __le32 byte_per_page;
239 __le16 spare_bytes_per_page;
240 __le32 data_bytes_per_ppage;
241 __le16 spare_bytes_per_ppage;
242 __le32 pages_per_block;
243 __le32 blocks_per_lun;
244 u8 lun_count;
245 u8 addr_cycles;
246 u8 bits_per_cell;
247 __le16 bb_per_lun;
248 __le16 block_endurance;
249 u8 guaranteed_good_blocks;
250 __le16 guaranteed_block_endurance;
251 u8 programs_per_page;
252 u8 ppage_attr;
253 u8 ecc_bits;
254 u8 interleaved_bits;
255 u8 interleaved_ops;
256 u8 reserved3[13];
257
258 /* electrical parameter block */
259 u8 io_pin_capacitance_max;
260 __le16 async_timing_mode;
261 __le16 program_cache_timing_mode;
262 __le16 t_prog;
263 __le16 t_bers;
264 __le16 t_r;
265 __le16 t_ccs;
266 __le16 src_sync_timing_mode;
267 __le16 src_ssync_features;
268 __le16 clk_pin_capacitance_typ;
269 __le16 io_pin_capacitance_typ;
270 __le16 input_pin_capacitance_typ;
271 u8 input_pin_capacitance_max;
272 u8 driver_strenght_support;
273 __le16 t_int_r;
274 __le16 t_ald;
275 u8 reserved4[7];
276
277 /* vendor */
278 u8 reserved5[90];
279
280 __le16 crc;
281} __attribute__((packed));
282
283#define ONFI_CRC_BASE 0x4F4E
284
285
286/**
287 * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices
288 * @lock: protection lock
289 * @active: the mtd device which holds the controller currently
290 * @wq: wait queue to sleep on if a NAND operation is in progress
291 * used instead of the per chip wait queue when a hw controller is available
292 */
293struct nand_hw_control {
294/* XXX U-BOOT XXX */
295#if 0
296 spinlock_t lock;
297 wait_queue_head_t wq;
298#endif
299 struct nand_chip *active;
300};
301
302/**
303 * struct nand_ecc_ctrl - Control structure for ecc
304 * @mode: ecc mode
305 * @steps: number of ecc steps per page
306 * @size: data bytes per ecc step
307 * @bytes: ecc bytes per step
308 * @total: total number of ecc bytes per page
309 * @prepad: padding information for syndrome based ecc generators
310 * @postpad: padding information for syndrome based ecc generators
311 * @layout: ECC layout control struct pointer
312 * @hwctl: function to control hardware ecc generator. Must only
313 * be provided if an hardware ECC is available
314 * @calculate: function for ecc calculation or readback from ecc hardware
315 * @correct: function for ecc correction, matching to ecc generator (sw/hw)
316 * @read_page_raw: function to read a raw page without ECC
317 * @write_page_raw: function to write a raw page without ECC
318 * @read_page: function to read a page according to the ecc generator requirements
319 * @write_page: function to write a page according to the ecc generator requirements
320 * @read_oob: function to read chip OOB data
321 * @write_oob: function to write chip OOB data
322 */
323struct nand_ecc_ctrl {
324 nand_ecc_modes_t mode;
325 int steps;
326 int size;
327 int bytes;
328 int total;
329 int strength;
330 int prepad;
331 int postpad;
332 struct nand_ecclayout *layout;
333 void (*hwctl)(struct mtd_info *mtd, int mode);
334 int (*calculate)(struct mtd_info *mtd,
335 const uint8_t *dat,
336 uint8_t *ecc_code);
337 int (*correct)(struct mtd_info *mtd, uint8_t *dat,
338 uint8_t *read_ecc,
339 uint8_t *calc_ecc);
340 int (*read_page_raw)(struct mtd_info *mtd,
341 struct nand_chip *chip,
342 uint8_t *buf, int page);
343 void (*write_page_raw)(struct mtd_info *mtd,
344 struct nand_chip *chip,
345 const uint8_t *buf);
346 int (*read_page)(struct mtd_info *mtd,
347 struct nand_chip *chip,
348 uint8_t *buf, int page, struct mtd_oob_ops *ops);//zhouqi add ops
349 int (*read_subpage)(struct mtd_info *mtd,
350 struct nand_chip *chip,
351 uint32_t offs, uint32_t len,
352 uint8_t *buf);
353 void (*write_page)(struct mtd_info *mtd,
354 struct nand_chip *chip,
355 const uint8_t *buf, struct mtd_oob_ops *ops);//zhouqi add ops
356 int (*read_oob)(struct mtd_info *mtd,
357 struct nand_chip *chip,
358 int page,
359 int sndcmd);
360 int (*write_oob)(struct mtd_info *mtd,
361 struct nand_chip *chip,
362 int page);
363};
364
365/**
366 * struct nand_buffers - buffer structure for read/write
367 * @ecccalc: buffer for calculated ecc
368 * @ecccode: buffer for ecc read from flash
369 * @databuf: buffer for data - dynamically sized
370 *
371 * Do not change the order of buffers. databuf and oobrbuf must be in
372 * consecutive order.
373 */
374struct nand_buffers {
375 uint8_t ecccalc[NAND_MAX_OOBSIZE];
376 uint8_t ecccode[NAND_MAX_OOBSIZE];
377 uint8_t databuf[NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE];
378};
379
380/**
381 * struct nand_chip - NAND Private Flash Chip Data
382 * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the flash device
383 * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the flash device
384 * @read_byte: [REPLACEABLE] read one byte from the chip
385 * @read_word: [REPLACEABLE] read one word from the chip
386 * @write_buf: [REPLACEABLE] write data from the buffer to the chip
387 * @read_buf: [REPLACEABLE] read data from the chip into the buffer
388 * @verify_buf: [REPLACEABLE] verify buffer contents against the chip data
389 * @select_chip: [REPLACEABLE] select chip nr
390 * @block_bad: [REPLACEABLE] check, if the block is bad
391 * @block_markbad: [REPLACEABLE] mark the block bad
392 * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific funtion for controlling
393 * ALE/CLE/nCE. Also used to write command and address
394 * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accesing device ready/busy line
395 * If set to NULL no access to ready/busy is available and the ready/busy information
396 * is read from the chip status register
397 * @cmdfunc: [REPLACEABLE] hardwarespecific function for writing commands to the chip
398 * @waitfunc: [REPLACEABLE] hardwarespecific function for wait on ready
399 * @ecc: [BOARDSPECIFIC] ecc control ctructure
400 * @buffers: buffer structure for read/write
401 * @hwcontrol: platform-specific hardware control structure
402 * @ops: oob operation operands
403 * @erase_cmd: [INTERN] erase command write function, selectable due to AND support
404 * @scan_bbt: [REPLACEABLE] function to scan bad block table
405 * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transfering data from array to read regs (tR)
406 * @wq: [INTERN] wait queue to sleep on if a NAND operation is in progress
407 * @state: [INTERN] the current state of the NAND device
408 * @oob_poi: poison value buffer
409 * @page_shift: [INTERN] number of address bits in a page (column address bits)
410 * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
411 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
412 * @chip_shift: [INTERN] number of address bits in one chip
413 * @datbuf: [INTERN] internal buffer for one page + oob
414 * @oobbuf: [INTERN] oob buffer for one eraseblock
415 * @oobdirty: [INTERN] indicates that oob_buf must be reinitialized
416 * @data_poi: [INTERN] pointer to a data buffer
417 * @options: [BOARDSPECIFIC] various chip options. They can partly be set to inform nand_scan about
418 * special functionality. See the defines for further explanation
419 * @badblockpos: [INTERN] position of the bad block marker in the oob area
420 * @cellinfo: [INTERN] MLC/multichip data from chip ident
421 * @numchips: [INTERN] number of physical chips
422 * @chipsize: [INTERN] the size of one chip for multichip arrays
423 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
424 * @pagebuf: [INTERN] holds the pagenumber which is currently in data_buf
425 * @subpagesize: [INTERN] holds the subpagesize
426 * @ecclayout: [REPLACEABLE] the default ecc placement scheme
427 * @bbt: [INTERN] bad block table pointer
428 * @bbt_td: [REPLACEABLE] bad block table descriptor for flash lookup
429 * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
430 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial bad block scan
431 * @controller: [REPLACEABLE] a pointer to a hardware controller structure
432 * which is shared among multiple independend devices
433 * @priv: [OPTIONAL] pointer to private chip date
434 * @errstat: [OPTIONAL] hardware specific function to perform additional error status checks
435 * (determine if errors are correctable)
436 * @write_page: [REPLACEABLE] High-level page write function
437 */
438
439struct nand_chip {
440 void __iomem *IO_ADDR_R;
441 void __iomem *IO_ADDR_W;
442
443 uint8_t (*read_byte)(struct mtd_info *mtd);
444 u16 (*read_word)(struct mtd_info *mtd);
445 void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
446 void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
447 int (*verify_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
448 void (*select_chip)(struct mtd_info *mtd, int chip);
449 int (*block_bad)(struct mtd_info *mtd, loff_t ofs, int getchip);
450 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
451 void (*cmd_ctrl)(struct mtd_info *mtd, int dat,
452 unsigned int ctrl);
453 int (*dev_ready)(struct mtd_info *mtd);
454 void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, int page_addr);
455 int (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);
456 void (*erase_cmd)(struct mtd_info *mtd, int page);
457 int (*scan_bbt)(struct mtd_info *mtd);
458 int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
459 int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
460 const uint8_t *buf, int page, int cached, int raw, struct mtd_oob_ops *ops);//zhouqi add ops
461
462 int chip_delay;
463 unsigned int options;
464
465 int page_shift; //Ò³µØÖ·Æ«ÒÆ 2048--> 11
466 int phys_erase_shift; //¿éµØÖ·Æ«ÒÆ
467 int bbt_erase_shift;
468 int chip_shift;
469 int numchips;
470 uint64_t chipsize;
471 int pagemask;
472 int pagebuf;
473 int subpagesize;
474 uint8_t cellinfo;
475 int badblockpos;
476 int onfi_version;
477#ifdef CONFIG_SYS_NAND_ONFI_DETECTION
478 struct nand_onfi_params onfi_params;
479#endif
480
481 int state;
482
483 uint8_t *oob_poi; //OOB Êý¾ÝÁÙʱ´æ·ÅÇøµØÖ·Ö¸Õë
484 struct nand_hw_control *controller;
485 struct nand_ecclayout *ecclayout;
486
487 struct nand_ecc_ctrl ecc;
488 struct nand_buffers *buffers;
489
490 struct nand_hw_control hwcontrol;
491
492 struct mtd_oob_ops ops;
493
494 uint8_t *bbt;
495 struct nand_bbt_descr *bbt_td;
496 struct nand_bbt_descr *bbt_md;
497
498 struct nand_bbt_descr *badblock_pattern;
499
500 void *priv;
501};
502
503/*
504 * NAND Flash Manufacturer ID Codes
505 */
506#define NAND_MFR_TOSHIBA 0x98
507#define NAND_MFR_SAMSUNG 0xec
508#define NAND_MFR_FUJITSU 0x04
509#define NAND_MFR_NATIONAL 0x8f
510#define NAND_MFR_RENESAS 0x07
511#define NAND_MFR_STMICRO 0x20
512#define NAND_MFR_HYNIX 0xad
513#define NAND_MFR_MICRON 0x2c
514#define NAND_MFR_AMD 0x01
515#define NAND_MFR_GIGADEVICE 0xC8
516#define NAND_MFR_WINBOND 0xEF
517#define NAND_MFR_PARAGON 0xA1
518#define NAND_MFR_HEYANGTEK 0xC9
519#define NAND_MFR_ZETTA 0xBA
520#define NAND_MFR_DOSILICON 0xE5
521#define NAND_MFR_FUDANWEI 0xA1
522#define NAND_MFR_HOSIN 0xD6
523#define NAND_MFR_EMST 0xC8
524#define NAND_MFR_FORESEE 0xCD
525#define NAND_MFR_XTX 0x0B
526#define NAND_MFR_UNIM 0xB0
527
528
529#define NAND_DEVID_GD5F1GQ5R_1G 0x41
530
531#define NAND_DEVID_EMST_F50D1G41LB_1G 0x11
xf.lic1c1f422025-03-12 19:38:15 -0700532#define NAND_DEVID_GD5F4GM8 0x85
xf.libfc6e712025-02-07 01:54:34 -0800533
534#define NAND_DEVID_PARAGON_1G 0xC1
535#define NAND_DEVID_PARAGON_2G 0xC2
536
537#define NAND_DEVID_WINBOND_1G 0xBA
538#define NAND_DEVID_WINBOND_2G 0xBB
539
540#define NAND_DEVID_FDANWEI_1G 0xA5
541#define NAND_DEVID_DOSILICON_512M 0xA5
542
543#define NAND_DEVID_FORESEE_1G 0x61
544#define NAND_DEVID_FORESEE_512M 0x60
545
546
547#define BBT_INFO_OOB_OFFSET_PARAGON 64
548#define BBT_INFO_OOB_VER_OFFSET_PARAGON 68
549#define BBT_INFO_OOB_OFFSET_HEYANGTEK 32
550#define BBT_INFO_OOB_VER_OFFSET_HEYANGTEK 64
551
552#define NAND_DEVID_MICRON_MT29F2G01ABAGDWB 0x24
553
554/**
555 * struct nand_flash_dev - NAND Flash Device ID Structure
556 * @name: Identify the device type
557 * @id: device ID code
558 * @pagesize: Pagesize in bytes. Either 256 or 512 or 0
559 * If the pagesize is 0, then the real pagesize
560 * and the eraseize are determined from the
561 * extended id bytes in the chip
562 * @erasesize: Size of an erase block in the flash device.
563 * @chipsize: Total chipsize in Mega Bytes
564 * @options: Bitfield to store chip relevant options
565 */
566struct nand_flash_dev {
567 char *name;
568 int id;
569 unsigned long pagesize;
570 unsigned long chipsize;
571 unsigned long erasesize;
572 unsigned long options;
573};
574
575/**
576 * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
577 * @name: Manufacturer name
578 * @id: manufacturer ID code of device.
579*/
580struct nand_manufacturers {
581 int id;
582 char * name;
583};
584
585extern const struct nand_flash_dev nand_flash_ids[];
586extern const struct nand_manufacturers nand_manuf_ids[];
587
588extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
589extern int nand_update_bbt(struct mtd_info *mtd, loff_t offs);
590extern int nand_default_bbt(struct mtd_info *mtd);
591extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt);
592extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
593 int allowbbt);
594extern int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len,
595 size_t * retlen, uint8_t * buf);
596
597/*
598* Constants for oob configuration
599*/
600#define NAND_SMALL_BADBLOCK_POS 5
601#define NAND_LARGE_BADBLOCK_POS 0
602
603/**
604 * struct platform_nand_chip - chip level device structure
605 * @nr_chips: max. number of chips to scan for
606 * @chip_offset: chip number offset
607 * @nr_partitions: number of partitions pointed to by partitions (or zero)
608 * @partitions: mtd partition list
609 * @chip_delay: R/B delay value in us
610 * @options: Option flags, e.g. 16bit buswidth
611 * @ecclayout: ecc layout info structure
612 * @part_probe_types: NULL-terminated array of probe types
613 * @priv: hardware controller specific settings
614 */
615struct platform_nand_chip {
616 int nr_chips;
617 int chip_offset;
618 int nr_partitions;
619 struct mtd_partition *partitions;
620 struct nand_ecclayout *ecclayout;
621 int chip_delay;
622 unsigned int options;
623 const char **part_probe_types;
624 void *priv;
625};
626
627/**
628 * struct platform_nand_ctrl - controller level device structure
629 * @hwcontrol: platform specific hardware control structure
630 * @dev_ready: platform specific function to read ready/busy pin
631 * @select_chip: platform specific chip select function
632 * @cmd_ctrl: platform specific function for controlling
633 * ALE/CLE/nCE. Also used to write command and address
634 * @priv: private data to transport driver specific settings
635 *
636 * All fields are optional and depend on the hardware driver requirements
637 */
638struct platform_nand_ctrl {
639 void (*hwcontrol)(struct mtd_info *mtd, int cmd);
640 int (*dev_ready)(struct mtd_info *mtd);
641 void (*select_chip)(struct mtd_info *mtd, int chip);
642 void (*cmd_ctrl)(struct mtd_info *mtd, int dat,
643 unsigned int ctrl);
644 void *priv;
645};
646
647/**
648 * struct platform_nand_data - container structure for platform-specific data
649 * @chip: chip level chip structure
650 * @ctrl: controller level device structure
651 */
652struct platform_nand_data {
653 struct platform_nand_chip chip;
654 struct platform_nand_ctrl ctrl;
655};
656
657/* Some helpers to access the data structures */
658static inline
659struct platform_nand_chip *get_platform_nandchip(struct mtd_info *mtd)
660{
661 struct nand_chip *chip = mtd->priv;
662
663 return chip->priv;
664}
665
666#endif /* __LINUX_MTD_NAND_H */