nand.h 22 KB

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