nand.h 24 KB

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