nand.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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. struct device_node;
  28. /* Scan and identify a NAND device */
  29. int nand_scan(struct mtd_info *mtd, int max_chips);
  30. /*
  31. * Separate phases of nand_scan(), allowing board driver to intervene
  32. * and override command or ECC setup according to flash type.
  33. */
  34. int nand_scan_ident(struct mtd_info *mtd, int max_chips,
  35. struct nand_flash_dev *table);
  36. int nand_scan_tail(struct mtd_info *mtd);
  37. /* Unregister the MTD device and free resources held by the NAND device */
  38. void nand_release(struct mtd_info *mtd);
  39. /* Internal helper for board drivers which need to override command function */
  40. void nand_wait_ready(struct mtd_info *mtd);
  41. /* locks all blocks present in the device */
  42. int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  43. /* unlocks specified locked blocks */
  44. int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  45. /* The maximum number of NAND chips in an array */
  46. #define NAND_MAX_CHIPS 8
  47. /*
  48. * Constants for hardware specific CLE/ALE/NCE function
  49. *
  50. * These are bits which can be or'ed to set/clear multiple
  51. * bits in one go.
  52. */
  53. /* Select the chip by setting nCE to low */
  54. #define NAND_NCE 0x01
  55. /* Select the command latch by setting CLE to high */
  56. #define NAND_CLE 0x02
  57. /* Select the address latch by setting ALE to high */
  58. #define NAND_ALE 0x04
  59. #define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
  60. #define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
  61. #define NAND_CTRL_CHANGE 0x80
  62. /*
  63. * Standard NAND flash commands
  64. */
  65. #define NAND_CMD_READ0 0
  66. #define NAND_CMD_READ1 1
  67. #define NAND_CMD_RNDOUT 5
  68. #define NAND_CMD_PAGEPROG 0x10
  69. #define NAND_CMD_READOOB 0x50
  70. #define NAND_CMD_ERASE1 0x60
  71. #define NAND_CMD_STATUS 0x70
  72. #define NAND_CMD_SEQIN 0x80
  73. #define NAND_CMD_RNDIN 0x85
  74. #define NAND_CMD_READID 0x90
  75. #define NAND_CMD_ERASE2 0xd0
  76. #define NAND_CMD_PARAM 0xec
  77. #define NAND_CMD_GET_FEATURES 0xee
  78. #define NAND_CMD_SET_FEATURES 0xef
  79. #define NAND_CMD_RESET 0xff
  80. #define NAND_CMD_LOCK 0x2a
  81. #define NAND_CMD_UNLOCK1 0x23
  82. #define NAND_CMD_UNLOCK2 0x24
  83. /* Extended commands for large page devices */
  84. #define NAND_CMD_READSTART 0x30
  85. #define NAND_CMD_RNDOUTSTART 0xE0
  86. #define NAND_CMD_CACHEDPROG 0x15
  87. #define NAND_CMD_NONE -1
  88. /* Status bits */
  89. #define NAND_STATUS_FAIL 0x01
  90. #define NAND_STATUS_FAIL_N1 0x02
  91. #define NAND_STATUS_TRUE_READY 0x20
  92. #define NAND_STATUS_READY 0x40
  93. #define NAND_STATUS_WP 0x80
  94. /*
  95. * Constants for ECC_MODES
  96. */
  97. typedef enum {
  98. NAND_ECC_NONE,
  99. NAND_ECC_SOFT,
  100. NAND_ECC_HW,
  101. NAND_ECC_HW_SYNDROME,
  102. NAND_ECC_HW_OOB_FIRST,
  103. } nand_ecc_modes_t;
  104. enum nand_ecc_algo {
  105. NAND_ECC_UNKNOWN,
  106. NAND_ECC_HAMMING,
  107. NAND_ECC_BCH,
  108. };
  109. /*
  110. * Constants for Hardware ECC
  111. */
  112. /* Reset Hardware ECC for read */
  113. #define NAND_ECC_READ 0
  114. /* Reset Hardware ECC for write */
  115. #define NAND_ECC_WRITE 1
  116. /* Enable Hardware ECC before syndrome is read back from flash */
  117. #define NAND_ECC_READSYN 2
  118. /*
  119. * Enable generic NAND 'page erased' check. This check is only done when
  120. * ecc.correct() returns -EBADMSG.
  121. * Set this flag if your implementation does not fix bitflips in erased
  122. * pages and you want to rely on the default implementation.
  123. */
  124. #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0)
  125. #define NAND_ECC_MAXIMIZE BIT(1)
  126. /* Bit mask for flags passed to do_nand_read_ecc */
  127. #define NAND_GET_DEVICE 0x80
  128. /*
  129. * Option constants for bizarre disfunctionality and real
  130. * features.
  131. */
  132. /* Buswidth is 16 bit */
  133. #define NAND_BUSWIDTH_16 0x00000002
  134. /* Chip has cache program function */
  135. #define NAND_CACHEPRG 0x00000008
  136. /*
  137. * Chip requires ready check on read (for auto-incremented sequential read).
  138. * True only for small page devices; large page devices do not support
  139. * autoincrement.
  140. */
  141. #define NAND_NEED_READRDY 0x00000100
  142. /* Chip does not allow subpage writes */
  143. #define NAND_NO_SUBPAGE_WRITE 0x00000200
  144. /* Device is one of 'new' xD cards that expose fake nand command set */
  145. #define NAND_BROKEN_XD 0x00000400
  146. /* Device behaves just like nand, but is readonly */
  147. #define NAND_ROM 0x00000800
  148. /* Device supports subpage reads */
  149. #define NAND_SUBPAGE_READ 0x00001000
  150. /*
  151. * Some MLC NANDs need data scrambling to limit bitflips caused by repeated
  152. * patterns.
  153. */
  154. #define NAND_NEED_SCRAMBLING 0x00002000
  155. /* Options valid for Samsung large page devices */
  156. #define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG
  157. /* Macros to identify the above */
  158. #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
  159. #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ))
  160. /* Non chip related options */
  161. /* This option skips the bbt scan during initialization. */
  162. #define NAND_SKIP_BBTSCAN 0x00010000
  163. /*
  164. * This option is defined if the board driver allocates its own buffers
  165. * (e.g. because it needs them DMA-coherent).
  166. */
  167. #define NAND_OWN_BUFFERS 0x00020000
  168. /* Chip may not exist, so silence any errors in scan */
  169. #define NAND_SCAN_SILENT_NODEV 0x00040000
  170. /*
  171. * Autodetect nand buswidth with readid/onfi.
  172. * This suppose the driver will configure the hardware in 8 bits mode
  173. * when calling nand_scan_ident, and update its configuration
  174. * before calling nand_scan_tail.
  175. */
  176. #define NAND_BUSWIDTH_AUTO 0x00080000
  177. /*
  178. * This option could be defined by controller drivers to protect against
  179. * kmap'ed, vmalloc'ed highmem buffers being passed from upper layers
  180. */
  181. #define NAND_USE_BOUNCE_BUFFER 0x00100000
  182. /* Options set by nand scan */
  183. /* Nand scan has allocated controller struct */
  184. #define NAND_CONTROLLER_ALLOC 0x80000000
  185. /* Cell info constants */
  186. #define NAND_CI_CHIPNR_MSK 0x03
  187. #define NAND_CI_CELLTYPE_MSK 0x0C
  188. #define NAND_CI_CELLTYPE_SHIFT 2
  189. /* Keep gcc happy */
  190. struct nand_chip;
  191. /* ONFI features */
  192. #define ONFI_FEATURE_16_BIT_BUS (1 << 0)
  193. #define ONFI_FEATURE_EXT_PARAM_PAGE (1 << 7)
  194. /* ONFI timing mode, used in both asynchronous and synchronous mode */
  195. #define ONFI_TIMING_MODE_0 (1 << 0)
  196. #define ONFI_TIMING_MODE_1 (1 << 1)
  197. #define ONFI_TIMING_MODE_2 (1 << 2)
  198. #define ONFI_TIMING_MODE_3 (1 << 3)
  199. #define ONFI_TIMING_MODE_4 (1 << 4)
  200. #define ONFI_TIMING_MODE_5 (1 << 5)
  201. #define ONFI_TIMING_MODE_UNKNOWN (1 << 6)
  202. /* ONFI feature address */
  203. #define ONFI_FEATURE_ADDR_TIMING_MODE 0x1
  204. /* Vendor-specific feature address (Micron) */
  205. #define ONFI_FEATURE_ADDR_READ_RETRY 0x89
  206. /* ONFI subfeature parameters length */
  207. #define ONFI_SUBFEATURE_PARAM_LEN 4
  208. /* ONFI optional commands SET/GET FEATURES supported? */
  209. #define ONFI_OPT_CMD_SET_GET_FEATURES (1 << 2)
  210. struct nand_onfi_params {
  211. /* rev info and features block */
  212. /* 'O' 'N' 'F' 'I' */
  213. u8 sig[4];
  214. __le16 revision;
  215. __le16 features;
  216. __le16 opt_cmd;
  217. u8 reserved0[2];
  218. __le16 ext_param_page_length; /* since ONFI 2.1 */
  219. u8 num_of_param_pages; /* since ONFI 2.1 */
  220. u8 reserved1[17];
  221. /* manufacturer information block */
  222. char manufacturer[12];
  223. char model[20];
  224. u8 jedec_id;
  225. __le16 date_code;
  226. u8 reserved2[13];
  227. /* memory organization block */
  228. __le32 byte_per_page;
  229. __le16 spare_bytes_per_page;
  230. __le32 data_bytes_per_ppage;
  231. __le16 spare_bytes_per_ppage;
  232. __le32 pages_per_block;
  233. __le32 blocks_per_lun;
  234. u8 lun_count;
  235. u8 addr_cycles;
  236. u8 bits_per_cell;
  237. __le16 bb_per_lun;
  238. __le16 block_endurance;
  239. u8 guaranteed_good_blocks;
  240. __le16 guaranteed_block_endurance;
  241. u8 programs_per_page;
  242. u8 ppage_attr;
  243. u8 ecc_bits;
  244. u8 interleaved_bits;
  245. u8 interleaved_ops;
  246. u8 reserved3[13];
  247. /* electrical parameter block */
  248. u8 io_pin_capacitance_max;
  249. __le16 async_timing_mode;
  250. __le16 program_cache_timing_mode;
  251. __le16 t_prog;
  252. __le16 t_bers;
  253. __le16 t_r;
  254. __le16 t_ccs;
  255. __le16 src_sync_timing_mode;
  256. u8 src_ssync_features;
  257. __le16 clk_pin_capacitance_typ;
  258. __le16 io_pin_capacitance_typ;
  259. __le16 input_pin_capacitance_typ;
  260. u8 input_pin_capacitance_max;
  261. u8 driver_strength_support;
  262. __le16 t_int_r;
  263. __le16 t_adl;
  264. u8 reserved4[8];
  265. /* vendor */
  266. __le16 vendor_revision;
  267. u8 vendor[88];
  268. __le16 crc;
  269. } __packed;
  270. #define ONFI_CRC_BASE 0x4F4E
  271. /* Extended ECC information Block Definition (since ONFI 2.1) */
  272. struct onfi_ext_ecc_info {
  273. u8 ecc_bits;
  274. u8 codeword_size;
  275. __le16 bb_per_lun;
  276. __le16 block_endurance;
  277. u8 reserved[2];
  278. } __packed;
  279. #define ONFI_SECTION_TYPE_0 0 /* Unused section. */
  280. #define ONFI_SECTION_TYPE_1 1 /* for additional sections. */
  281. #define ONFI_SECTION_TYPE_2 2 /* for ECC information. */
  282. struct onfi_ext_section {
  283. u8 type;
  284. u8 length;
  285. } __packed;
  286. #define ONFI_EXT_SECTION_MAX 8
  287. /* Extended Parameter Page Definition (since ONFI 2.1) */
  288. struct onfi_ext_param_page {
  289. __le16 crc;
  290. u8 sig[4]; /* 'E' 'P' 'P' 'S' */
  291. u8 reserved0[10];
  292. struct onfi_ext_section sections[ONFI_EXT_SECTION_MAX];
  293. /*
  294. * The actual size of the Extended Parameter Page is in
  295. * @ext_param_page_length of nand_onfi_params{}.
  296. * The following are the variable length sections.
  297. * So we do not add any fields below. Please see the ONFI spec.
  298. */
  299. } __packed;
  300. struct nand_onfi_vendor_micron {
  301. u8 two_plane_read;
  302. u8 read_cache;
  303. u8 read_unique_id;
  304. u8 dq_imped;
  305. u8 dq_imped_num_settings;
  306. u8 dq_imped_feat_addr;
  307. u8 rb_pulldown_strength;
  308. u8 rb_pulldown_strength_feat_addr;
  309. u8 rb_pulldown_strength_num_settings;
  310. u8 otp_mode;
  311. u8 otp_page_start;
  312. u8 otp_data_prot_addr;
  313. u8 otp_num_pages;
  314. u8 otp_feat_addr;
  315. u8 read_retry_options;
  316. u8 reserved[72];
  317. u8 param_revision;
  318. } __packed;
  319. struct jedec_ecc_info {
  320. u8 ecc_bits;
  321. u8 codeword_size;
  322. __le16 bb_per_lun;
  323. __le16 block_endurance;
  324. u8 reserved[2];
  325. } __packed;
  326. /* JEDEC features */
  327. #define JEDEC_FEATURE_16_BIT_BUS (1 << 0)
  328. struct nand_jedec_params {
  329. /* rev info and features block */
  330. /* 'J' 'E' 'S' 'D' */
  331. u8 sig[4];
  332. __le16 revision;
  333. __le16 features;
  334. u8 opt_cmd[3];
  335. __le16 sec_cmd;
  336. u8 num_of_param_pages;
  337. u8 reserved0[18];
  338. /* manufacturer information block */
  339. char manufacturer[12];
  340. char model[20];
  341. u8 jedec_id[6];
  342. u8 reserved1[10];
  343. /* memory organization block */
  344. __le32 byte_per_page;
  345. __le16 spare_bytes_per_page;
  346. u8 reserved2[6];
  347. __le32 pages_per_block;
  348. __le32 blocks_per_lun;
  349. u8 lun_count;
  350. u8 addr_cycles;
  351. u8 bits_per_cell;
  352. u8 programs_per_page;
  353. u8 multi_plane_addr;
  354. u8 multi_plane_op_attr;
  355. u8 reserved3[38];
  356. /* electrical parameter block */
  357. __le16 async_sdr_speed_grade;
  358. __le16 toggle_ddr_speed_grade;
  359. __le16 sync_ddr_speed_grade;
  360. u8 async_sdr_features;
  361. u8 toggle_ddr_features;
  362. u8 sync_ddr_features;
  363. __le16 t_prog;
  364. __le16 t_bers;
  365. __le16 t_r;
  366. __le16 t_r_multi_plane;
  367. __le16 t_ccs;
  368. __le16 io_pin_capacitance_typ;
  369. __le16 input_pin_capacitance_typ;
  370. __le16 clk_pin_capacitance_typ;
  371. u8 driver_strength_support;
  372. __le16 t_adl;
  373. u8 reserved4[36];
  374. /* ECC and endurance block */
  375. u8 guaranteed_good_blocks;
  376. __le16 guaranteed_block_endurance;
  377. struct jedec_ecc_info ecc_info[4];
  378. u8 reserved5[29];
  379. /* reserved */
  380. u8 reserved6[148];
  381. /* vendor */
  382. __le16 vendor_rev_num;
  383. u8 reserved7[88];
  384. /* CRC for Parameter Page */
  385. __le16 crc;
  386. } __packed;
  387. /**
  388. * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices
  389. * @lock: protection lock
  390. * @active: the mtd device which holds the controller currently
  391. * @wq: wait queue to sleep on if a NAND operation is in
  392. * progress used instead of the per chip wait queue
  393. * when a hw controller is available.
  394. */
  395. struct nand_hw_control {
  396. spinlock_t lock;
  397. struct nand_chip *active;
  398. wait_queue_head_t wq;
  399. };
  400. static inline void nand_hw_control_init(struct nand_hw_control *nfc)
  401. {
  402. nfc->active = NULL;
  403. spin_lock_init(&nfc->lock);
  404. init_waitqueue_head(&nfc->wq);
  405. }
  406. /**
  407. * struct nand_ecc_ctrl - Control structure for ECC
  408. * @mode: ECC mode
  409. * @algo: ECC algorithm
  410. * @steps: number of ECC steps per page
  411. * @size: data bytes per ECC step
  412. * @bytes: ECC bytes per step
  413. * @strength: max number of correctible bits per ECC step
  414. * @total: total number of ECC bytes per page
  415. * @prepad: padding information for syndrome based ECC generators
  416. * @postpad: padding information for syndrome based ECC generators
  417. * @options: ECC specific options (see NAND_ECC_XXX flags defined above)
  418. * @priv: pointer to private ECC control data
  419. * @hwctl: function to control hardware ECC generator. Must only
  420. * be provided if an hardware ECC is available
  421. * @calculate: function for ECC calculation or readback from ECC hardware
  422. * @correct: function for ECC correction, matching to ECC generator (sw/hw).
  423. * Should return a positive number representing the number of
  424. * corrected bitflips, -EBADMSG if the number of bitflips exceed
  425. * ECC strength, or any other error code if the error is not
  426. * directly related to correction.
  427. * If -EBADMSG is returned the input buffers should be left
  428. * untouched.
  429. * @read_page_raw: function to read a raw page without ECC. This function
  430. * should hide the specific layout used by the ECC
  431. * controller and always return contiguous in-band and
  432. * out-of-band data even if they're not stored
  433. * contiguously on the NAND chip (e.g.
  434. * NAND_ECC_HW_SYNDROME interleaves in-band and
  435. * out-of-band data).
  436. * @write_page_raw: function to write a raw page without ECC. This function
  437. * should hide the specific layout used by the ECC
  438. * controller and consider the passed data as contiguous
  439. * in-band and out-of-band data. ECC controller is
  440. * responsible for doing the appropriate transformations
  441. * to adapt to its specific layout (e.g.
  442. * NAND_ECC_HW_SYNDROME interleaves in-band and
  443. * out-of-band data).
  444. * @read_page: function to read a page according to the ECC generator
  445. * requirements; returns maximum number of bitflips corrected in
  446. * any single ECC step, 0 if bitflips uncorrectable, -EIO hw error
  447. * @read_subpage: function to read parts of the page covered by ECC;
  448. * returns same as read_page()
  449. * @write_subpage: function to write parts of the page covered by ECC.
  450. * @write_page: function to write a page according to the ECC generator
  451. * requirements.
  452. * @write_oob_raw: function to write chip OOB data without ECC
  453. * @read_oob_raw: function to read chip OOB data without ECC
  454. * @read_oob: function to read chip OOB data
  455. * @write_oob: function to write chip OOB data
  456. */
  457. struct nand_ecc_ctrl {
  458. nand_ecc_modes_t mode;
  459. enum nand_ecc_algo algo;
  460. int steps;
  461. int size;
  462. int bytes;
  463. int total;
  464. int strength;
  465. int prepad;
  466. int postpad;
  467. unsigned int options;
  468. void *priv;
  469. void (*hwctl)(struct mtd_info *mtd, int mode);
  470. int (*calculate)(struct mtd_info *mtd, const uint8_t *dat,
  471. uint8_t *ecc_code);
  472. int (*correct)(struct mtd_info *mtd, uint8_t *dat, uint8_t *read_ecc,
  473. uint8_t *calc_ecc);
  474. int (*read_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  475. uint8_t *buf, int oob_required, int page);
  476. int (*write_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  477. const uint8_t *buf, int oob_required, int page);
  478. int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip,
  479. uint8_t *buf, int oob_required, int page);
  480. int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
  481. uint32_t offs, uint32_t len, uint8_t *buf, int page);
  482. int (*write_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
  483. uint32_t offset, uint32_t data_len,
  484. const uint8_t *data_buf, int oob_required, int page);
  485. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  486. const uint8_t *buf, int oob_required, int page);
  487. int (*write_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  488. int page);
  489. int (*read_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
  490. int page);
  491. int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page);
  492. int (*write_oob)(struct mtd_info *mtd, struct nand_chip *chip,
  493. int page);
  494. };
  495. /**
  496. * struct nand_buffers - buffer structure for read/write
  497. * @ecccalc: buffer pointer for calculated ECC, size is oobsize.
  498. * @ecccode: buffer pointer for ECC read from flash, size is oobsize.
  499. * @databuf: buffer pointer for data, size is (page size + oobsize).
  500. *
  501. * Do not change the order of buffers. databuf and oobrbuf must be in
  502. * consecutive order.
  503. */
  504. struct nand_buffers {
  505. uint8_t *ecccalc;
  506. uint8_t *ecccode;
  507. uint8_t *databuf;
  508. };
  509. /**
  510. * struct nand_sdr_timings - SDR NAND chip timings
  511. *
  512. * This struct defines the timing requirements of a SDR NAND chip.
  513. * These information can be found in every NAND datasheets and the timings
  514. * meaning are described in the ONFI specifications:
  515. * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing
  516. * Parameters)
  517. *
  518. * All these timings are expressed in picoseconds.
  519. *
  520. * @tBERS_max: Block erase time
  521. * @tCCS_min: Change column setup time
  522. * @tPROG_max: Page program time
  523. * @tR_max: Page read time
  524. * @tALH_min: ALE hold time
  525. * @tADL_min: ALE to data loading time
  526. * @tALS_min: ALE setup time
  527. * @tAR_min: ALE to RE# delay
  528. * @tCEA_max: CE# access time
  529. * @tCEH_min:
  530. * @tCH_min: CE# hold time
  531. * @tCHZ_max: CE# high to output hi-Z
  532. * @tCLH_min: CLE hold time
  533. * @tCLR_min: CLE to RE# delay
  534. * @tCLS_min: CLE setup time
  535. * @tCOH_min: CE# high to output hold
  536. * @tCS_min: CE# setup time
  537. * @tDH_min: Data hold time
  538. * @tDS_min: Data setup time
  539. * @tFEAT_max: Busy time for Set Features and Get Features
  540. * @tIR_min: Output hi-Z to RE# low
  541. * @tITC_max: Interface and Timing Mode Change time
  542. * @tRC_min: RE# cycle time
  543. * @tREA_max: RE# access time
  544. * @tREH_min: RE# high hold time
  545. * @tRHOH_min: RE# high to output hold
  546. * @tRHW_min: RE# high to WE# low
  547. * @tRHZ_max: RE# high to output hi-Z
  548. * @tRLOH_min: RE# low to output hold
  549. * @tRP_min: RE# pulse width
  550. * @tRR_min: Ready to RE# low (data only)
  551. * @tRST_max: Device reset time, measured from the falling edge of R/B# to the
  552. * rising edge of R/B#.
  553. * @tWB_max: WE# high to SR[6] low
  554. * @tWC_min: WE# cycle time
  555. * @tWH_min: WE# high hold time
  556. * @tWHR_min: WE# high to RE# low
  557. * @tWP_min: WE# pulse width
  558. * @tWW_min: WP# transition to WE# low
  559. */
  560. struct nand_sdr_timings {
  561. u32 tBERS_max;
  562. u32 tCCS_min;
  563. u32 tPROG_max;
  564. u32 tR_max;
  565. u32 tALH_min;
  566. u32 tADL_min;
  567. u32 tALS_min;
  568. u32 tAR_min;
  569. u32 tCEA_max;
  570. u32 tCEH_min;
  571. u32 tCH_min;
  572. u32 tCHZ_max;
  573. u32 tCLH_min;
  574. u32 tCLR_min;
  575. u32 tCLS_min;
  576. u32 tCOH_min;
  577. u32 tCS_min;
  578. u32 tDH_min;
  579. u32 tDS_min;
  580. u32 tFEAT_max;
  581. u32 tIR_min;
  582. u32 tITC_max;
  583. u32 tRC_min;
  584. u32 tREA_max;
  585. u32 tREH_min;
  586. u32 tRHOH_min;
  587. u32 tRHW_min;
  588. u32 tRHZ_max;
  589. u32 tRLOH_min;
  590. u32 tRP_min;
  591. u32 tRR_min;
  592. u64 tRST_max;
  593. u32 tWB_max;
  594. u32 tWC_min;
  595. u32 tWH_min;
  596. u32 tWHR_min;
  597. u32 tWP_min;
  598. u32 tWW_min;
  599. };
  600. /**
  601. * enum nand_data_interface_type - NAND interface timing type
  602. * @NAND_SDR_IFACE: Single Data Rate interface
  603. */
  604. enum nand_data_interface_type {
  605. NAND_SDR_IFACE,
  606. };
  607. /**
  608. * struct nand_data_interface - NAND interface timing
  609. * @type: type of the timing
  610. * @timings: The timing, type according to @type
  611. */
  612. struct nand_data_interface {
  613. enum nand_data_interface_type type;
  614. union {
  615. struct nand_sdr_timings sdr;
  616. } timings;
  617. };
  618. /**
  619. * nand_get_sdr_timings - get SDR timing from data interface
  620. * @conf: The data interface
  621. */
  622. static inline const struct nand_sdr_timings *
  623. nand_get_sdr_timings(const struct nand_data_interface *conf)
  624. {
  625. if (conf->type != NAND_SDR_IFACE)
  626. return ERR_PTR(-EINVAL);
  627. return &conf->timings.sdr;
  628. }
  629. /**
  630. * struct nand_chip - NAND Private Flash Chip Data
  631. * @mtd: MTD device registered to the MTD framework
  632. * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the
  633. * flash device
  634. * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
  635. * flash device.
  636. * @read_byte: [REPLACEABLE] read one byte from the chip
  637. * @read_word: [REPLACEABLE] read one word from the chip
  638. * @write_byte: [REPLACEABLE] write a single byte to the chip on the
  639. * low 8 I/O lines
  640. * @write_buf: [REPLACEABLE] write data from the buffer to the chip
  641. * @read_buf: [REPLACEABLE] read data from the chip into the buffer
  642. * @select_chip: [REPLACEABLE] select chip nr
  643. * @block_bad: [REPLACEABLE] check if a block is bad, using OOB markers
  644. * @block_markbad: [REPLACEABLE] mark a block bad
  645. * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific function for controlling
  646. * ALE/CLE/nCE. Also used to write command and address
  647. * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accessing
  648. * device ready/busy line. If set to NULL no access to
  649. * ready/busy is available and the ready/busy information
  650. * is read from the chip status register.
  651. * @cmdfunc: [REPLACEABLE] hardwarespecific function for writing
  652. * commands to the chip.
  653. * @waitfunc: [REPLACEABLE] hardwarespecific function for wait on
  654. * ready.
  655. * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for
  656. * setting the read-retry mode. Mostly needed for MLC NAND.
  657. * @ecc: [BOARDSPECIFIC] ECC control structure
  658. * @buffers: buffer structure for read/write
  659. * @hwcontrol: platform-specific hardware control structure
  660. * @erase: [REPLACEABLE] erase function
  661. * @scan_bbt: [REPLACEABLE] function to scan bad block table
  662. * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring
  663. * data from array to read regs (tR).
  664. * @state: [INTERN] the current state of the NAND device
  665. * @oob_poi: "poison value buffer," used for laying out OOB data
  666. * before writing
  667. * @page_shift: [INTERN] number of address bits in a page (column
  668. * address bits).
  669. * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
  670. * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
  671. * @chip_shift: [INTERN] number of address bits in one chip
  672. * @options: [BOARDSPECIFIC] various chip options. They can partly
  673. * be set to inform nand_scan about special functionality.
  674. * See the defines for further explanation.
  675. * @bbt_options: [INTERN] bad block specific options. All options used
  676. * here must come from bbm.h. By default, these options
  677. * will be copied to the appropriate nand_bbt_descr's.
  678. * @badblockpos: [INTERN] position of the bad block marker in the oob
  679. * area.
  680. * @badblockbits: [INTERN] minimum number of set bits in a good block's
  681. * bad block marker position; i.e., BBM == 11110111b is
  682. * not bad when badblockbits == 7
  683. * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC.
  684. * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet.
  685. * Minimum amount of bit errors per @ecc_step_ds guaranteed
  686. * to be correctable. If unknown, set to zero.
  687. * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds,
  688. * also from the datasheet. It is the recommended ECC step
  689. * size, if known; if unknown, set to zero.
  690. * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is
  691. * set to the actually used ONFI mode if the chip is
  692. * ONFI compliant or deduced from the datasheet if
  693. * the NAND chip is not ONFI compliant.
  694. * @numchips: [INTERN] number of physical chips
  695. * @chipsize: [INTERN] the size of one chip for multichip arrays
  696. * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
  697. * @pagebuf: [INTERN] holds the pagenumber which is currently in
  698. * data_buf.
  699. * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is
  700. * currently in data_buf.
  701. * @subpagesize: [INTERN] holds the subpagesize
  702. * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded),
  703. * non 0 if ONFI supported.
  704. * @jedec_version: [INTERN] holds the chip JEDEC version (BCD encoded),
  705. * non 0 if JEDEC supported.
  706. * @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
  707. * supported, 0 otherwise.
  708. * @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is
  709. * supported, 0 otherwise.
  710. * @read_retries: [INTERN] the number of read retry modes supported
  711. * @onfi_set_features: [REPLACEABLE] set the features for ONFI nand
  712. * @onfi_get_features: [REPLACEABLE] get the features for ONFI nand
  713. * @setup_data_interface: [OPTIONAL] setup the data interface and timing
  714. * @bbt: [INTERN] bad block table pointer
  715. * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
  716. * lookup.
  717. * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
  718. * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial
  719. * bad block scan.
  720. * @controller: [REPLACEABLE] a pointer to a hardware controller
  721. * structure which is shared among multiple independent
  722. * devices.
  723. * @priv: [OPTIONAL] pointer to private chip data
  724. * @errstat: [OPTIONAL] hardware specific function to perform
  725. * additional error status checks (determine if errors are
  726. * correctable).
  727. * @write_page: [REPLACEABLE] High-level page write function
  728. */
  729. struct nand_chip {
  730. struct mtd_info mtd;
  731. void __iomem *IO_ADDR_R;
  732. void __iomem *IO_ADDR_W;
  733. uint8_t (*read_byte)(struct mtd_info *mtd);
  734. u16 (*read_word)(struct mtd_info *mtd);
  735. void (*write_byte)(struct mtd_info *mtd, uint8_t byte);
  736. void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  737. void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
  738. void (*select_chip)(struct mtd_info *mtd, int chip);
  739. int (*block_bad)(struct mtd_info *mtd, loff_t ofs);
  740. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  741. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  742. int (*dev_ready)(struct mtd_info *mtd);
  743. void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column,
  744. int page_addr);
  745. int(*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);
  746. int (*erase)(struct mtd_info *mtd, int page);
  747. int (*scan_bbt)(struct mtd_info *mtd);
  748. int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state,
  749. int status, int page);
  750. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  751. uint32_t offset, int data_len, const uint8_t *buf,
  752. int oob_required, int page, int cached, int raw);
  753. int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
  754. int feature_addr, uint8_t *subfeature_para);
  755. int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
  756. int feature_addr, uint8_t *subfeature_para);
  757. int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode);
  758. int (*setup_data_interface)(struct mtd_info *mtd,
  759. const struct nand_data_interface *conf,
  760. bool check_only);
  761. int chip_delay;
  762. unsigned int options;
  763. unsigned int bbt_options;
  764. int page_shift;
  765. int phys_erase_shift;
  766. int bbt_erase_shift;
  767. int chip_shift;
  768. int numchips;
  769. uint64_t chipsize;
  770. int pagemask;
  771. int pagebuf;
  772. unsigned int pagebuf_bitflips;
  773. int subpagesize;
  774. uint8_t bits_per_cell;
  775. uint16_t ecc_strength_ds;
  776. uint16_t ecc_step_ds;
  777. int onfi_timing_mode_default;
  778. int badblockpos;
  779. int badblockbits;
  780. int onfi_version;
  781. int jedec_version;
  782. union {
  783. struct nand_onfi_params onfi_params;
  784. struct nand_jedec_params jedec_params;
  785. };
  786. struct nand_data_interface *data_interface;
  787. int read_retries;
  788. flstate_t state;
  789. uint8_t *oob_poi;
  790. struct nand_hw_control *controller;
  791. struct nand_ecc_ctrl ecc;
  792. struct nand_buffers *buffers;
  793. struct nand_hw_control hwcontrol;
  794. uint8_t *bbt;
  795. struct nand_bbt_descr *bbt_td;
  796. struct nand_bbt_descr *bbt_md;
  797. struct nand_bbt_descr *badblock_pattern;
  798. void *priv;
  799. };
  800. extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
  801. extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
  802. static inline void nand_set_flash_node(struct nand_chip *chip,
  803. struct device_node *np)
  804. {
  805. mtd_set_of_node(&chip->mtd, np);
  806. }
  807. static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
  808. {
  809. return mtd_get_of_node(&chip->mtd);
  810. }
  811. static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
  812. {
  813. return container_of(mtd, struct nand_chip, mtd);
  814. }
  815. static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
  816. {
  817. return &chip->mtd;
  818. }
  819. static inline void *nand_get_controller_data(struct nand_chip *chip)
  820. {
  821. return chip->priv;
  822. }
  823. static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
  824. {
  825. chip->priv = priv;
  826. }
  827. /*
  828. * NAND Flash Manufacturer ID Codes
  829. */
  830. #define NAND_MFR_TOSHIBA 0x98
  831. #define NAND_MFR_ESMT 0xc8
  832. #define NAND_MFR_SAMSUNG 0xec
  833. #define NAND_MFR_FUJITSU 0x04
  834. #define NAND_MFR_NATIONAL 0x8f
  835. #define NAND_MFR_RENESAS 0x07
  836. #define NAND_MFR_STMICRO 0x20
  837. #define NAND_MFR_HYNIX 0xad
  838. #define NAND_MFR_MICRON 0x2c
  839. #define NAND_MFR_AMD 0x01
  840. #define NAND_MFR_MACRONIX 0xc2
  841. #define NAND_MFR_EON 0x92
  842. #define NAND_MFR_SANDISK 0x45
  843. #define NAND_MFR_INTEL 0x89
  844. #define NAND_MFR_ATO 0x9b
  845. /* The maximum expected count of bytes in the NAND ID sequence */
  846. #define NAND_MAX_ID_LEN 8
  847. /*
  848. * A helper for defining older NAND chips where the second ID byte fully
  849. * defined the chip, including the geometry (chip size, eraseblock size, page
  850. * size). All these chips have 512 bytes NAND page size.
  851. */
  852. #define LEGACY_ID_NAND(nm, devid, chipsz, erasesz, opts) \
  853. { .name = (nm), {{ .dev_id = (devid) }}, .pagesize = 512, \
  854. .chipsize = (chipsz), .erasesize = (erasesz), .options = (opts) }
  855. /*
  856. * A helper for defining newer chips which report their page size and
  857. * eraseblock size via the extended ID bytes.
  858. *
  859. * The real difference between LEGACY_ID_NAND and EXTENDED_ID_NAND is that with
  860. * EXTENDED_ID_NAND, manufacturers overloaded the same device ID so that the
  861. * device ID now only represented a particular total chip size (and voltage,
  862. * buswidth), and the page size, eraseblock size, and OOB size could vary while
  863. * using the same device ID.
  864. */
  865. #define EXTENDED_ID_NAND(nm, devid, chipsz, opts) \
  866. { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \
  867. .options = (opts) }
  868. #define NAND_ECC_INFO(_strength, _step) \
  869. { .strength_ds = (_strength), .step_ds = (_step) }
  870. #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds)
  871. #define NAND_ECC_STEP(type) ((type)->ecc.step_ds)
  872. /**
  873. * struct nand_flash_dev - NAND Flash Device ID Structure
  874. * @name: a human-readable name of the NAND chip
  875. * @dev_id: the device ID (the second byte of the full chip ID array)
  876. * @mfr_id: manufecturer ID part of the full chip ID array (refers the same
  877. * memory address as @id[0])
  878. * @dev_id: device ID part of the full chip ID array (refers the same memory
  879. * address as @id[1])
  880. * @id: full device ID array
  881. * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as
  882. * well as the eraseblock size) is determined from the extended NAND
  883. * chip ID array)
  884. * @chipsize: total chip size in MiB
  885. * @erasesize: eraseblock size in bytes (determined from the extended ID if 0)
  886. * @options: stores various chip bit options
  887. * @id_len: The valid length of the @id.
  888. * @oobsize: OOB size
  889. * @ecc: ECC correctability and step information from the datasheet.
  890. * @ecc.strength_ds: The ECC correctability from the datasheet, same as the
  891. * @ecc_strength_ds in nand_chip{}.
  892. * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the
  893. * @ecc_step_ds in nand_chip{}, also from the datasheet.
  894. * For example, the "4bit ECC for each 512Byte" can be set with
  895. * NAND_ECC_INFO(4, 512).
  896. * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND
  897. * reset. Should be deduced from timings described
  898. * in the datasheet.
  899. *
  900. */
  901. struct nand_flash_dev {
  902. char *name;
  903. union {
  904. struct {
  905. uint8_t mfr_id;
  906. uint8_t dev_id;
  907. };
  908. uint8_t id[NAND_MAX_ID_LEN];
  909. };
  910. unsigned int pagesize;
  911. unsigned int chipsize;
  912. unsigned int erasesize;
  913. unsigned int options;
  914. uint16_t id_len;
  915. uint16_t oobsize;
  916. struct {
  917. uint16_t strength_ds;
  918. uint16_t step_ds;
  919. } ecc;
  920. int onfi_timing_mode_default;
  921. };
  922. /**
  923. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  924. * @name: Manufacturer name
  925. * @id: manufacturer ID code of device.
  926. */
  927. struct nand_manufacturers {
  928. int id;
  929. char *name;
  930. };
  931. extern struct nand_flash_dev nand_flash_ids[];
  932. extern struct nand_manufacturers nand_manuf_ids[];
  933. int nand_default_bbt(struct mtd_info *mtd);
  934. int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);
  935. int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs);
  936. int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt);
  937. int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
  938. int allowbbt);
  939. int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len,
  940. size_t *retlen, uint8_t *buf);
  941. /**
  942. * struct platform_nand_chip - chip level device structure
  943. * @nr_chips: max. number of chips to scan for
  944. * @chip_offset: chip number offset
  945. * @nr_partitions: number of partitions pointed to by partitions (or zero)
  946. * @partitions: mtd partition list
  947. * @chip_delay: R/B delay value in us
  948. * @options: Option flags, e.g. 16bit buswidth
  949. * @bbt_options: BBT option flags, e.g. NAND_BBT_USE_FLASH
  950. * @part_probe_types: NULL-terminated array of probe types
  951. */
  952. struct platform_nand_chip {
  953. int nr_chips;
  954. int chip_offset;
  955. int nr_partitions;
  956. struct mtd_partition *partitions;
  957. int chip_delay;
  958. unsigned int options;
  959. unsigned int bbt_options;
  960. const char **part_probe_types;
  961. };
  962. /* Keep gcc happy */
  963. struct platform_device;
  964. /**
  965. * struct platform_nand_ctrl - controller level device structure
  966. * @probe: platform specific function to probe/setup hardware
  967. * @remove: platform specific function to remove/teardown hardware
  968. * @hwcontrol: platform specific hardware control structure
  969. * @dev_ready: platform specific function to read ready/busy pin
  970. * @select_chip: platform specific chip select function
  971. * @cmd_ctrl: platform specific function for controlling
  972. * ALE/CLE/nCE. Also used to write command and address
  973. * @write_buf: platform specific function for write buffer
  974. * @read_buf: platform specific function for read buffer
  975. * @read_byte: platform specific function to read one byte from chip
  976. * @priv: private data to transport driver specific settings
  977. *
  978. * All fields are optional and depend on the hardware driver requirements
  979. */
  980. struct platform_nand_ctrl {
  981. int (*probe)(struct platform_device *pdev);
  982. void (*remove)(struct platform_device *pdev);
  983. void (*hwcontrol)(struct mtd_info *mtd, int cmd);
  984. int (*dev_ready)(struct mtd_info *mtd);
  985. void (*select_chip)(struct mtd_info *mtd, int chip);
  986. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  987. void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  988. void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
  989. unsigned char (*read_byte)(struct mtd_info *mtd);
  990. void *priv;
  991. };
  992. /**
  993. * struct platform_nand_data - container structure for platform-specific data
  994. * @chip: chip level chip structure
  995. * @ctrl: controller level device structure
  996. */
  997. struct platform_nand_data {
  998. struct platform_nand_chip chip;
  999. struct platform_nand_ctrl ctrl;
  1000. };
  1001. /* return the supported features. */
  1002. static inline int onfi_feature(struct nand_chip *chip)
  1003. {
  1004. return chip->onfi_version ? le16_to_cpu(chip->onfi_params.features) : 0;
  1005. }
  1006. /* return the supported asynchronous timing mode. */
  1007. static inline int onfi_get_async_timing_mode(struct nand_chip *chip)
  1008. {
  1009. if (!chip->onfi_version)
  1010. return ONFI_TIMING_MODE_UNKNOWN;
  1011. return le16_to_cpu(chip->onfi_params.async_timing_mode);
  1012. }
  1013. /* return the supported synchronous timing mode. */
  1014. static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
  1015. {
  1016. if (!chip->onfi_version)
  1017. return ONFI_TIMING_MODE_UNKNOWN;
  1018. return le16_to_cpu(chip->onfi_params.src_sync_timing_mode);
  1019. }
  1020. int onfi_init_data_interface(struct nand_chip *chip,
  1021. struct nand_data_interface *iface,
  1022. enum nand_data_interface_type type,
  1023. int timing_mode);
  1024. /*
  1025. * Check if it is a SLC nand.
  1026. * The !nand_is_slc() can be used to check the MLC/TLC nand chips.
  1027. * We do not distinguish the MLC and TLC now.
  1028. */
  1029. static inline bool nand_is_slc(struct nand_chip *chip)
  1030. {
  1031. return chip->bits_per_cell == 1;
  1032. }
  1033. /**
  1034. * Check if the opcode's address should be sent only on the lower 8 bits
  1035. * @command: opcode to check
  1036. */
  1037. static inline int nand_opcode_8bits(unsigned int command)
  1038. {
  1039. switch (command) {
  1040. case NAND_CMD_READID:
  1041. case NAND_CMD_PARAM:
  1042. case NAND_CMD_GET_FEATURES:
  1043. case NAND_CMD_SET_FEATURES:
  1044. return 1;
  1045. default:
  1046. break;
  1047. }
  1048. return 0;
  1049. }
  1050. /* return the supported JEDEC features. */
  1051. static inline int jedec_feature(struct nand_chip *chip)
  1052. {
  1053. return chip->jedec_version ? le16_to_cpu(chip->jedec_params.features)
  1054. : 0;
  1055. }
  1056. /* get timing characteristics from ONFI timing mode. */
  1057. const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode);
  1058. /* get data interface from ONFI timing mode 0, used after reset. */
  1059. const struct nand_data_interface *nand_get_default_data_interface(void);
  1060. int nand_check_erased_ecc_chunk(void *data, int datalen,
  1061. void *ecc, int ecclen,
  1062. void *extraoob, int extraooblen,
  1063. int threshold);
  1064. /* Default write_oob implementation */
  1065. int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
  1066. /* Default write_oob syndrome implementation */
  1067. int nand_write_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
  1068. int page);
  1069. /* Default read_oob implementation */
  1070. int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
  1071. /* Default read_oob syndrome implementation */
  1072. int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
  1073. int page);
  1074. /* Reset and initialize a NAND device */
  1075. int nand_reset(struct nand_chip *chip);
  1076. /* Free resources held by the NAND device */
  1077. void nand_cleanup(struct nand_chip *chip);
  1078. #endif /* __LINUX_MTD_NAND_H */