nand.h 21 KB

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