nand.h 23 KB

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