nand.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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 640
  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_GET_FEATURES 0xee
  76. #define NAND_CMD_SET_FEATURES 0xef
  77. #define NAND_CMD_RESET 0xff
  78. #define NAND_CMD_LOCK 0x2a
  79. #define NAND_CMD_LOCK_TIGHT 0x2c
  80. #define NAND_CMD_UNLOCK1 0x23
  81. #define NAND_CMD_UNLOCK2 0x24
  82. #define NAND_CMD_LOCK_STATUS 0x7a
  83. /* Extended commands for large page devices */
  84. #define NAND_CMD_READSTART 0x30
  85. #define NAND_CMD_RNDOUTSTART 0xE0
  86. #define NAND_CMD_CACHEDPROG 0x15
  87. /* Extended commands for AG-AND device */
  88. /*
  89. * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but
  90. * there is no way to distinguish that from NAND_CMD_READ0
  91. * until the remaining sequence of commands has been completed
  92. * so add a high order bit and mask it off in the command.
  93. */
  94. #define NAND_CMD_DEPLETE1 0x100
  95. #define NAND_CMD_DEPLETE2 0x38
  96. #define NAND_CMD_STATUS_MULTI 0x71
  97. #define NAND_CMD_STATUS_ERROR 0x72
  98. /* multi-bank error status (banks 0-3) */
  99. #define NAND_CMD_STATUS_ERROR0 0x73
  100. #define NAND_CMD_STATUS_ERROR1 0x74
  101. #define NAND_CMD_STATUS_ERROR2 0x75
  102. #define NAND_CMD_STATUS_ERROR3 0x76
  103. #define NAND_CMD_STATUS_RESET 0x7f
  104. #define NAND_CMD_STATUS_CLEAR 0xff
  105. #define NAND_CMD_NONE -1
  106. /* Status bits */
  107. #define NAND_STATUS_FAIL 0x01
  108. #define NAND_STATUS_FAIL_N1 0x02
  109. #define NAND_STATUS_TRUE_READY 0x20
  110. #define NAND_STATUS_READY 0x40
  111. #define NAND_STATUS_WP 0x80
  112. /*
  113. * Constants for ECC_MODES
  114. */
  115. typedef enum {
  116. NAND_ECC_NONE,
  117. NAND_ECC_SOFT,
  118. NAND_ECC_HW,
  119. NAND_ECC_HW_SYNDROME,
  120. NAND_ECC_HW_OOB_FIRST,
  121. NAND_ECC_SOFT_BCH,
  122. } nand_ecc_modes_t;
  123. /*
  124. * Constants for Hardware ECC
  125. */
  126. /* Reset Hardware ECC for read */
  127. #define NAND_ECC_READ 0
  128. /* Reset Hardware ECC for write */
  129. #define NAND_ECC_WRITE 1
  130. /* Enable Hardware ECC before syndrome is read back from flash */
  131. #define NAND_ECC_READSYN 2
  132. /* Bit mask for flags passed to do_nand_read_ecc */
  133. #define NAND_GET_DEVICE 0x80
  134. /*
  135. * Option constants for bizarre disfunctionality and real
  136. * features.
  137. */
  138. /* Buswidth 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. /* Chip does not allow subpage writes */
  163. #define NAND_NO_SUBPAGE_WRITE 0x00000200
  164. /* Device is one of 'new' xD cards that expose fake nand command set */
  165. #define NAND_BROKEN_XD 0x00000400
  166. /* Device behaves just like nand, but is readonly */
  167. #define NAND_ROM 0x00000800
  168. /* Device supports subpage reads */
  169. #define NAND_SUBPAGE_READ 0x00001000
  170. /* Options valid for Samsung large page devices */
  171. #define NAND_SAMSUNG_LP_OPTIONS \
  172. (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
  173. /* Macros to identify the above */
  174. #define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING))
  175. #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
  176. #define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK))
  177. #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ))
  178. /* Non chip related options */
  179. /* This option skips the bbt scan during initialization. */
  180. #define NAND_SKIP_BBTSCAN 0x00010000
  181. /*
  182. * This option is defined if the board driver allocates its own buffers
  183. * (e.g. because it needs them DMA-coherent).
  184. */
  185. #define NAND_OWN_BUFFERS 0x00020000
  186. /* Chip may not exist, so silence any errors in scan */
  187. #define NAND_SCAN_SILENT_NODEV 0x00040000
  188. /* Options set by nand scan */
  189. /* bbt has already been read */
  190. #define NAND_BBT_SCANNED 0x40000000
  191. /* Nand scan has allocated controller struct */
  192. #define NAND_CONTROLLER_ALLOC 0x80000000
  193. /* Cell info constants */
  194. #define NAND_CI_CHIPNR_MSK 0x03
  195. #define NAND_CI_CELLTYPE_MSK 0x0C
  196. /* Keep gcc happy */
  197. struct nand_chip;
  198. /* ONFI timing mode, used in both asynchronous and synchronous mode */
  199. #define ONFI_TIMING_MODE_0 (1 << 0)
  200. #define ONFI_TIMING_MODE_1 (1 << 1)
  201. #define ONFI_TIMING_MODE_2 (1 << 2)
  202. #define ONFI_TIMING_MODE_3 (1 << 3)
  203. #define ONFI_TIMING_MODE_4 (1 << 4)
  204. #define ONFI_TIMING_MODE_5 (1 << 5)
  205. #define ONFI_TIMING_MODE_UNKNOWN (1 << 6)
  206. /* ONFI feature address */
  207. #define ONFI_FEATURE_ADDR_TIMING_MODE 0x1
  208. /* ONFI subfeature parameters length */
  209. #define ONFI_SUBFEATURE_PARAM_LEN 4
  210. struct nand_onfi_params {
  211. /* rev info and features block */
  212. /* 'O' 'N' 'F' 'I' */
  213. u8 sig[4];
  214. __le16 revision;
  215. __le16 features;
  216. __le16 opt_cmd;
  217. u8 reserved[22];
  218. /* manufacturer information block */
  219. char manufacturer[12];
  220. char model[20];
  221. u8 jedec_id;
  222. __le16 date_code;
  223. u8 reserved2[13];
  224. /* memory organization block */
  225. __le32 byte_per_page;
  226. __le16 spare_bytes_per_page;
  227. __le32 data_bytes_per_ppage;
  228. __le16 spare_bytes_per_ppage;
  229. __le32 pages_per_block;
  230. __le32 blocks_per_lun;
  231. u8 lun_count;
  232. u8 addr_cycles;
  233. u8 bits_per_cell;
  234. __le16 bb_per_lun;
  235. __le16 block_endurance;
  236. u8 guaranteed_good_blocks;
  237. __le16 guaranteed_block_endurance;
  238. u8 programs_per_page;
  239. u8 ppage_attr;
  240. u8 ecc_bits;
  241. u8 interleaved_bits;
  242. u8 interleaved_ops;
  243. u8 reserved3[13];
  244. /* electrical parameter block */
  245. u8 io_pin_capacitance_max;
  246. __le16 async_timing_mode;
  247. __le16 program_cache_timing_mode;
  248. __le16 t_prog;
  249. __le16 t_bers;
  250. __le16 t_r;
  251. __le16 t_ccs;
  252. __le16 src_sync_timing_mode;
  253. __le16 src_ssync_features;
  254. __le16 clk_pin_capacitance_typ;
  255. __le16 io_pin_capacitance_typ;
  256. __le16 input_pin_capacitance_typ;
  257. u8 input_pin_capacitance_max;
  258. u8 driver_strenght_support;
  259. __le16 t_int_r;
  260. __le16 t_ald;
  261. u8 reserved4[7];
  262. /* vendor */
  263. u8 reserved5[90];
  264. __le16 crc;
  265. } __attribute__((packed));
  266. #define ONFI_CRC_BASE 0x4F4E
  267. /**
  268. * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices
  269. * @lock: protection lock
  270. * @active: the mtd device which holds the controller currently
  271. * @wq: wait queue to sleep on if a NAND operation is in
  272. * progress used instead of the per chip wait queue
  273. * when a hw controller is available.
  274. */
  275. struct nand_hw_control {
  276. /* XXX U-BOOT XXX */
  277. #if 0
  278. spinlock_t lock;
  279. wait_queue_head_t wq;
  280. #endif
  281. struct nand_chip *active;
  282. };
  283. /**
  284. * struct nand_ecc_ctrl - Control structure for ECC
  285. * @mode: ECC mode
  286. * @steps: number of ECC steps per page
  287. * @size: data bytes per ECC step
  288. * @bytes: ECC bytes per step
  289. * @strength: max number of correctible bits per ECC step
  290. * @total: total number of ECC bytes per page
  291. * @prepad: padding information for syndrome based ECC generators
  292. * @postpad: padding information for syndrome based ECC generators
  293. * @layout: ECC layout control struct pointer
  294. * @priv: pointer to private ECC control data
  295. * @hwctl: function to control hardware ECC generator. Must only
  296. * be provided if an hardware ECC is available
  297. * @calculate: function for ECC calculation or readback from ECC hardware
  298. * @correct: function for ECC correction, matching to ECC generator (sw/hw)
  299. * @read_page_raw: function to read a raw page without ECC
  300. * @write_page_raw: function to write a raw page without ECC
  301. * @read_page: function to read a page according to the ECC generator
  302. * requirements; returns maximum number of bitflips corrected in
  303. * any single ECC step, 0 if bitflips uncorrectable, -EIO hw error
  304. * @read_subpage: function to read parts of the page covered by ECC;
  305. * returns same as read_page()
  306. * @write_page: function to write a page according to the ECC generator
  307. * requirements.
  308. * @write_oob_raw: function to write chip OOB data without ECC
  309. * @read_oob_raw: function to read chip OOB data without ECC
  310. * @read_oob: function to read chip OOB data
  311. * @write_oob: function to write chip OOB data
  312. */
  313. struct nand_ecc_ctrl {
  314. nand_ecc_modes_t mode;
  315. int steps;
  316. int size;
  317. int bytes;
  318. int total;
  319. int strength;
  320. int prepad;
  321. int postpad;
  322. struct nand_ecclayout *layout;
  323. void *priv;
  324. void (*hwctl)(struct mtd_info *mtd, int mode);
  325. int (*calculate)(struct mtd_info *mtd, const uint8_t *dat,
  326. uint8_t *ecc_code);
  327. int (*correct)(struct mtd_info *mtd, uint8_t *dat, uint8_t *read_ecc,
  328. uint8_t *calc_ecc);
  329. int (*read_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  330. uint8_t *buf, int oob_required, int page);
  331. int (*write_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  332. const uint8_t *buf, int oob_required);
  333. int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip,
  334. uint8_t *buf, int oob_required, int page);
  335. int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
  336. uint32_t offs, uint32_t len, uint8_t *buf);
  337. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  338. const uint8_t *buf, int oob_required);
  339. int (*write_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  340. int page);
  341. int (*read_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  342. int page);
  343. int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page);
  344. int (*write_oob)(struct mtd_info *mtd, struct nand_chip *chip,
  345. int page);
  346. };
  347. /**
  348. * struct nand_buffers - buffer structure for read/write
  349. * @ecccalc: buffer for calculated ECC
  350. * @ecccode: buffer for ECC read from flash
  351. * @databuf: buffer for data - dynamically sized
  352. *
  353. * Do not change the order of buffers. databuf and oobrbuf must be in
  354. * consecutive order.
  355. */
  356. struct nand_buffers {
  357. uint8_t ecccalc[ALIGN(NAND_MAX_OOBSIZE, ARCH_DMA_MINALIGN)];
  358. uint8_t ecccode[ALIGN(NAND_MAX_OOBSIZE, ARCH_DMA_MINALIGN)];
  359. uint8_t databuf[ALIGN(NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE,
  360. ARCH_DMA_MINALIGN)];
  361. };
  362. /**
  363. * struct nand_chip - NAND Private Flash Chip Data
  364. * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the
  365. * flash device
  366. * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
  367. * flash device.
  368. * @read_byte: [REPLACEABLE] read one byte from the chip
  369. * @read_word: [REPLACEABLE] read one word from the chip
  370. * @write_buf: [REPLACEABLE] write data from the buffer to the chip
  371. * @read_buf: [REPLACEABLE] read data from the chip into the buffer
  372. * @verify_buf: [REPLACEABLE] verify buffer contents against the chip
  373. * data.
  374. * @select_chip: [REPLACEABLE] select chip nr
  375. * @block_bad: [REPLACEABLE] check, if the block is bad
  376. * @block_markbad: [REPLACEABLE] mark the block bad
  377. * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific function for controlling
  378. * ALE/CLE/nCE. Also used to write command and address
  379. * @init_size: [BOARDSPECIFIC] hardwarespecific function for setting
  380. * mtd->oobsize, mtd->writesize and so on.
  381. * @id_data contains the 8 bytes values of NAND_CMD_READID.
  382. * Return with the bus width.
  383. * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accessing
  384. * device ready/busy line. If set to NULL no access to
  385. * ready/busy is available and the ready/busy information
  386. * is read from the chip status register.
  387. * @cmdfunc: [REPLACEABLE] hardwarespecific function for writing
  388. * commands to the chip.
  389. * @waitfunc: [REPLACEABLE] hardwarespecific function for wait on
  390. * ready.
  391. * @ecc: [BOARDSPECIFIC] ECC control structure
  392. * @buffers: buffer structure for read/write
  393. * @hwcontrol: platform-specific hardware control structure
  394. * @erase_cmd: [INTERN] erase command write function, selectable due
  395. * to AND support.
  396. * @scan_bbt: [REPLACEABLE] function to scan bad block table
  397. * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring
  398. * data from array to read regs (tR).
  399. * @state: [INTERN] the current state of the NAND device
  400. * @oob_poi: "poison value buffer," used for laying out OOB data
  401. * before writing
  402. * @page_shift: [INTERN] number of address bits in a page (column
  403. * address bits).
  404. * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
  405. * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
  406. * @chip_shift: [INTERN] number of address bits in one chip
  407. * @options: [BOARDSPECIFIC] various chip options. They can partly
  408. * be set to inform nand_scan about special functionality.
  409. * See the defines for further explanation.
  410. * @bbt_options: [INTERN] bad block specific options. All options used
  411. * here must come from bbm.h. By default, these options
  412. * will be copied to the appropriate nand_bbt_descr's.
  413. * @badblockpos: [INTERN] position of the bad block marker in the oob
  414. * area.
  415. * @badblockbits: [INTERN] minimum number of set bits in a good block's
  416. * bad block marker position; i.e., BBM == 11110111b is
  417. * not bad when badblockbits == 7
  418. * @cellinfo: [INTERN] MLC/multichip data from chip ident
  419. * @numchips: [INTERN] number of physical chips
  420. * @chipsize: [INTERN] the size of one chip for multichip arrays
  421. * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
  422. * @pagebuf: [INTERN] holds the pagenumber which is currently in
  423. * data_buf.
  424. * @subpagesize: [INTERN] holds the subpagesize
  425. * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded),
  426. * non 0 if ONFI supported.
  427. * @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
  428. * supported, 0 otherwise.
  429. * @onfi_set_features [REPLACEABLE] set the features for ONFI nand
  430. * @onfi_get_features [REPLACEABLE] get the features for ONFI nand
  431. * @ecclayout: [REPLACEABLE] the default ECC placement scheme
  432. * @bbt: [INTERN] bad block table pointer
  433. * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
  434. * lookup.
  435. * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
  436. * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial
  437. * bad block scan.
  438. * @controller: [REPLACEABLE] a pointer to a hardware controller
  439. * structure which is shared among multiple independent
  440. * devices.
  441. * @priv: [OPTIONAL] pointer to private chip data
  442. * @errstat: [OPTIONAL] hardware specific function to perform
  443. * additional error status checks (determine if errors are
  444. * correctable).
  445. * @write_page: [REPLACEABLE] High-level page write function
  446. */
  447. struct nand_chip {
  448. void __iomem *IO_ADDR_R;
  449. void __iomem *IO_ADDR_W;
  450. uint8_t (*read_byte)(struct mtd_info *mtd);
  451. u16 (*read_word)(struct mtd_info *mtd);
  452. void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  453. void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
  454. int (*verify_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  455. void (*select_chip)(struct mtd_info *mtd, int chip);
  456. int (*block_bad)(struct mtd_info *mtd, loff_t ofs, int getchip);
  457. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  458. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  459. int (*init_size)(struct mtd_info *mtd, struct nand_chip *this,
  460. u8 *id_data);
  461. int (*dev_ready)(struct mtd_info *mtd);
  462. void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column,
  463. int page_addr);
  464. int(*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);
  465. void (*erase_cmd)(struct mtd_info *mtd, int page);
  466. int (*scan_bbt)(struct mtd_info *mtd);
  467. int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state,
  468. int status, int page);
  469. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  470. const uint8_t *buf, int oob_required, int page,
  471. int cached, int raw);
  472. int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
  473. int feature_addr, uint8_t *subfeature_para);
  474. int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
  475. int feature_addr, uint8_t *subfeature_para);
  476. int chip_delay;
  477. unsigned int options;
  478. unsigned int bbt_options;
  479. int page_shift;
  480. int phys_erase_shift;
  481. int bbt_erase_shift;
  482. int chip_shift;
  483. int numchips;
  484. uint64_t chipsize;
  485. int pagemask;
  486. int pagebuf;
  487. int subpagesize;
  488. uint8_t cellinfo;
  489. int badblockpos;
  490. int badblockbits;
  491. int onfi_version;
  492. #ifdef CONFIG_SYS_NAND_ONFI_DETECTION
  493. struct nand_onfi_params onfi_params;
  494. #endif
  495. int state;
  496. uint8_t *oob_poi;
  497. struct nand_hw_control *controller;
  498. struct nand_ecclayout *ecclayout;
  499. struct nand_ecc_ctrl ecc;
  500. struct nand_buffers *buffers;
  501. struct nand_hw_control hwcontrol;
  502. uint8_t *bbt;
  503. struct nand_bbt_descr *bbt_td;
  504. struct nand_bbt_descr *bbt_md;
  505. struct nand_bbt_descr *badblock_pattern;
  506. void *priv;
  507. };
  508. /*
  509. * NAND Flash Manufacturer ID Codes
  510. */
  511. #define NAND_MFR_TOSHIBA 0x98
  512. #define NAND_MFR_SAMSUNG 0xec
  513. #define NAND_MFR_FUJITSU 0x04
  514. #define NAND_MFR_NATIONAL 0x8f
  515. #define NAND_MFR_RENESAS 0x07
  516. #define NAND_MFR_STMICRO 0x20
  517. #define NAND_MFR_HYNIX 0xad
  518. #define NAND_MFR_MICRON 0x2c
  519. #define NAND_MFR_AMD 0x01
  520. #define NAND_MFR_MACRONIX 0xc2
  521. #define NAND_MFR_EON 0x92
  522. /**
  523. * struct nand_flash_dev - NAND Flash Device ID Structure
  524. * @name: Identify the device type
  525. * @id: device ID code
  526. * @pagesize: Pagesize in bytes. Either 256 or 512 or 0
  527. * If the pagesize is 0, then the real pagesize
  528. * and the eraseize are determined from the
  529. * extended id bytes in the chip
  530. * @erasesize: Size of an erase block in the flash device.
  531. * @chipsize: Total chipsize in Mega Bytes
  532. * @options: Bitfield to store chip relevant options
  533. */
  534. struct nand_flash_dev {
  535. char *name;
  536. int id;
  537. unsigned long pagesize;
  538. unsigned long chipsize;
  539. unsigned long erasesize;
  540. unsigned long options;
  541. };
  542. /**
  543. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  544. * @name: Manufacturer name
  545. * @id: manufacturer ID code of device.
  546. */
  547. struct nand_manufacturers {
  548. int id;
  549. char *name;
  550. };
  551. extern const struct nand_flash_dev nand_flash_ids[];
  552. extern const struct nand_manufacturers nand_manuf_ids[];
  553. extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
  554. extern int nand_update_bbt(struct mtd_info *mtd, loff_t offs);
  555. extern int nand_default_bbt(struct mtd_info *mtd);
  556. extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt);
  557. extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
  558. int allowbbt);
  559. extern int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len,
  560. size_t *retlen, uint8_t *buf);
  561. /*
  562. * Constants for oob configuration
  563. */
  564. #define NAND_SMALL_BADBLOCK_POS 5
  565. #define NAND_LARGE_BADBLOCK_POS 0
  566. /**
  567. * struct platform_nand_chip - chip level device structure
  568. * @nr_chips: max. number of chips to scan for
  569. * @chip_offset: chip number offset
  570. * @nr_partitions: number of partitions pointed to by partitions (or zero)
  571. * @partitions: mtd partition list
  572. * @chip_delay: R/B delay value in us
  573. * @options: Option flags, e.g. 16bit buswidth
  574. * @bbt_options: BBT option flags, e.g. NAND_BBT_USE_FLASH
  575. * @ecclayout: ECC layout info structure
  576. * @part_probe_types: NULL-terminated array of probe types
  577. */
  578. struct platform_nand_chip {
  579. int nr_chips;
  580. int chip_offset;
  581. int nr_partitions;
  582. struct mtd_partition *partitions;
  583. struct nand_ecclayout *ecclayout;
  584. int chip_delay;
  585. unsigned int options;
  586. unsigned int bbt_options;
  587. const char **part_probe_types;
  588. };
  589. /* Keep gcc happy */
  590. struct platform_device;
  591. /**
  592. * struct platform_nand_ctrl - controller level device structure
  593. * @hwcontrol: platform specific hardware control structure
  594. * @dev_ready: platform specific function to read ready/busy pin
  595. * @select_chip: platform specific chip select function
  596. * @cmd_ctrl: platform specific function for controlling
  597. * ALE/CLE/nCE. Also used to write command and address
  598. * @priv: private data to transport driver specific settings
  599. *
  600. * All fields are optional and depend on the hardware driver requirements
  601. */
  602. struct platform_nand_ctrl {
  603. void (*hwcontrol)(struct mtd_info *mtd, int cmd);
  604. int (*dev_ready)(struct mtd_info *mtd);
  605. void (*select_chip)(struct mtd_info *mtd, int chip);
  606. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  607. unsigned char (*read_byte)(struct mtd_info *mtd);
  608. void *priv;
  609. };
  610. /**
  611. * struct platform_nand_data - container structure for platform-specific data
  612. * @chip: chip level chip structure
  613. * @ctrl: controller level device structure
  614. */
  615. struct platform_nand_data {
  616. struct platform_nand_chip chip;
  617. struct platform_nand_ctrl ctrl;
  618. };
  619. /* Some helpers to access the data structures */
  620. static inline
  621. struct platform_nand_chip *get_platform_nandchip(struct mtd_info *mtd)
  622. {
  623. struct nand_chip *chip = mtd->priv;
  624. return chip->priv;
  625. }
  626. /* Standard NAND functions from nand_base.c */
  627. void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len);
  628. void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
  629. void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
  630. void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
  631. uint8_t nand_read_byte(struct mtd_info *mtd);
  632. /* return the supported asynchronous timing mode. */
  633. #ifdef CONFIG_SYS_NAND_ONFI_DETECTION
  634. static inline int onfi_get_async_timing_mode(struct nand_chip *chip)
  635. {
  636. if (!chip->onfi_version)
  637. return ONFI_TIMING_MODE_UNKNOWN;
  638. return le16_to_cpu(chip->onfi_params.async_timing_mode);
  639. }
  640. /* return the supported synchronous timing mode. */
  641. static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
  642. {
  643. if (!chip->onfi_version)
  644. return ONFI_TIMING_MODE_UNKNOWN;
  645. return le16_to_cpu(chip->onfi_params.src_sync_timing_mode);
  646. }
  647. #endif
  648. #endif /* __LINUX_MTD_NAND_H */