nand.h 22 KB

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