nand.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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. * @tALH_min: ALE hold time
  521. * @tADL_min: ALE to data loading time
  522. * @tALS_min: ALE setup time
  523. * @tAR_min: ALE to RE# delay
  524. * @tCEA_max: CE# access time
  525. * @tCEH_min:
  526. * @tCH_min: CE# hold time
  527. * @tCHZ_max: CE# high to output hi-Z
  528. * @tCLH_min: CLE hold time
  529. * @tCLR_min: CLE to RE# delay
  530. * @tCLS_min: CLE setup time
  531. * @tCOH_min: CE# high to output hold
  532. * @tCS_min: CE# setup time
  533. * @tDH_min: Data hold time
  534. * @tDS_min: Data setup time
  535. * @tFEAT_max: Busy time for Set Features and Get Features
  536. * @tIR_min: Output hi-Z to RE# low
  537. * @tITC_max: Interface and Timing Mode Change time
  538. * @tRC_min: RE# cycle time
  539. * @tREA_max: RE# access time
  540. * @tREH_min: RE# high hold time
  541. * @tRHOH_min: RE# high to output hold
  542. * @tRHW_min: RE# high to WE# low
  543. * @tRHZ_max: RE# high to output hi-Z
  544. * @tRLOH_min: RE# low to output hold
  545. * @tRP_min: RE# pulse width
  546. * @tRR_min: Ready to RE# low (data only)
  547. * @tRST_max: Device reset time, measured from the falling edge of R/B# to the
  548. * rising edge of R/B#.
  549. * @tWB_max: WE# high to SR[6] low
  550. * @tWC_min: WE# cycle time
  551. * @tWH_min: WE# high hold time
  552. * @tWHR_min: WE# high to RE# low
  553. * @tWP_min: WE# pulse width
  554. * @tWW_min: WP# transition to WE# low
  555. */
  556. struct nand_sdr_timings {
  557. u32 tALH_min;
  558. u32 tADL_min;
  559. u32 tALS_min;
  560. u32 tAR_min;
  561. u32 tCEA_max;
  562. u32 tCEH_min;
  563. u32 tCH_min;
  564. u32 tCHZ_max;
  565. u32 tCLH_min;
  566. u32 tCLR_min;
  567. u32 tCLS_min;
  568. u32 tCOH_min;
  569. u32 tCS_min;
  570. u32 tDH_min;
  571. u32 tDS_min;
  572. u32 tFEAT_max;
  573. u32 tIR_min;
  574. u32 tITC_max;
  575. u32 tRC_min;
  576. u32 tREA_max;
  577. u32 tREH_min;
  578. u32 tRHOH_min;
  579. u32 tRHW_min;
  580. u32 tRHZ_max;
  581. u32 tRLOH_min;
  582. u32 tRP_min;
  583. u32 tRR_min;
  584. u64 tRST_max;
  585. u32 tWB_max;
  586. u32 tWC_min;
  587. u32 tWH_min;
  588. u32 tWHR_min;
  589. u32 tWP_min;
  590. u32 tWW_min;
  591. };
  592. /**
  593. * enum nand_data_interface_type - NAND interface timing type
  594. * @NAND_SDR_IFACE: Single Data Rate interface
  595. */
  596. enum nand_data_interface_type {
  597. NAND_SDR_IFACE,
  598. };
  599. /**
  600. * struct nand_data_interface - NAND interface timing
  601. * @type: type of the timing
  602. * @timings: The timing, type according to @type
  603. */
  604. struct nand_data_interface {
  605. enum nand_data_interface_type type;
  606. union {
  607. struct nand_sdr_timings sdr;
  608. } timings;
  609. };
  610. /**
  611. * nand_get_sdr_timings - get SDR timing from data interface
  612. * @conf: The data interface
  613. */
  614. static inline const struct nand_sdr_timings *
  615. nand_get_sdr_timings(const struct nand_data_interface *conf)
  616. {
  617. if (conf->type != NAND_SDR_IFACE)
  618. return ERR_PTR(-EINVAL);
  619. return &conf->timings.sdr;
  620. }
  621. /**
  622. * struct nand_chip - NAND Private Flash Chip Data
  623. * @mtd: MTD device registered to the MTD framework
  624. * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the
  625. * flash device
  626. * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
  627. * flash device.
  628. * @read_byte: [REPLACEABLE] read one byte from the chip
  629. * @read_word: [REPLACEABLE] read one word from the chip
  630. * @write_byte: [REPLACEABLE] write a single byte to the chip on the
  631. * low 8 I/O lines
  632. * @write_buf: [REPLACEABLE] write data from the buffer to the chip
  633. * @read_buf: [REPLACEABLE] read data from the chip into the buffer
  634. * @select_chip: [REPLACEABLE] select chip nr
  635. * @block_bad: [REPLACEABLE] check if a block is bad, using OOB markers
  636. * @block_markbad: [REPLACEABLE] mark a block bad
  637. * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific function for controlling
  638. * ALE/CLE/nCE. Also used to write command and address
  639. * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accessing
  640. * device ready/busy line. If set to NULL no access to
  641. * ready/busy is available and the ready/busy information
  642. * is read from the chip status register.
  643. * @cmdfunc: [REPLACEABLE] hardwarespecific function for writing
  644. * commands to the chip.
  645. * @waitfunc: [REPLACEABLE] hardwarespecific function for wait on
  646. * ready.
  647. * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for
  648. * setting the read-retry mode. Mostly needed for MLC NAND.
  649. * @ecc: [BOARDSPECIFIC] ECC control structure
  650. * @buffers: buffer structure for read/write
  651. * @hwcontrol: platform-specific hardware control structure
  652. * @erase: [REPLACEABLE] erase function
  653. * @scan_bbt: [REPLACEABLE] function to scan bad block table
  654. * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring
  655. * data from array to read regs (tR).
  656. * @state: [INTERN] the current state of the NAND device
  657. * @oob_poi: "poison value buffer," used for laying out OOB data
  658. * before writing
  659. * @page_shift: [INTERN] number of address bits in a page (column
  660. * address bits).
  661. * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
  662. * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
  663. * @chip_shift: [INTERN] number of address bits in one chip
  664. * @options: [BOARDSPECIFIC] various chip options. They can partly
  665. * be set to inform nand_scan about special functionality.
  666. * See the defines for further explanation.
  667. * @bbt_options: [INTERN] bad block specific options. All options used
  668. * here must come from bbm.h. By default, these options
  669. * will be copied to the appropriate nand_bbt_descr's.
  670. * @badblockpos: [INTERN] position of the bad block marker in the oob
  671. * area.
  672. * @badblockbits: [INTERN] minimum number of set bits in a good block's
  673. * bad block marker position; i.e., BBM == 11110111b is
  674. * not bad when badblockbits == 7
  675. * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC.
  676. * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet.
  677. * Minimum amount of bit errors per @ecc_step_ds guaranteed
  678. * to be correctable. If unknown, set to zero.
  679. * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds,
  680. * also from the datasheet. It is the recommended ECC step
  681. * size, if known; if unknown, set to zero.
  682. * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is
  683. * set to the actually used ONFI mode if the chip is
  684. * ONFI compliant or deduced from the datasheet if
  685. * the NAND chip is not ONFI compliant.
  686. * @numchips: [INTERN] number of physical chips
  687. * @chipsize: [INTERN] the size of one chip for multichip arrays
  688. * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
  689. * @pagebuf: [INTERN] holds the pagenumber which is currently in
  690. * data_buf.
  691. * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is
  692. * currently in data_buf.
  693. * @subpagesize: [INTERN] holds the subpagesize
  694. * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded),
  695. * non 0 if ONFI supported.
  696. * @jedec_version: [INTERN] holds the chip JEDEC version (BCD encoded),
  697. * non 0 if JEDEC supported.
  698. * @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
  699. * supported, 0 otherwise.
  700. * @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is
  701. * supported, 0 otherwise.
  702. * @read_retries: [INTERN] the number of read retry modes supported
  703. * @onfi_set_features: [REPLACEABLE] set the features for ONFI nand
  704. * @onfi_get_features: [REPLACEABLE] get the features for ONFI nand
  705. * @setup_data_interface: [OPTIONAL] setup the data interface and timing
  706. * @bbt: [INTERN] bad block table pointer
  707. * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
  708. * lookup.
  709. * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
  710. * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial
  711. * bad block scan.
  712. * @controller: [REPLACEABLE] a pointer to a hardware controller
  713. * structure which is shared among multiple independent
  714. * devices.
  715. * @priv: [OPTIONAL] pointer to private chip data
  716. * @errstat: [OPTIONAL] hardware specific function to perform
  717. * additional error status checks (determine if errors are
  718. * correctable).
  719. * @write_page: [REPLACEABLE] High-level page write function
  720. */
  721. struct nand_chip {
  722. struct mtd_info mtd;
  723. void __iomem *IO_ADDR_R;
  724. void __iomem *IO_ADDR_W;
  725. uint8_t (*read_byte)(struct mtd_info *mtd);
  726. u16 (*read_word)(struct mtd_info *mtd);
  727. void (*write_byte)(struct mtd_info *mtd, uint8_t byte);
  728. void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  729. void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
  730. void (*select_chip)(struct mtd_info *mtd, int chip);
  731. int (*block_bad)(struct mtd_info *mtd, loff_t ofs);
  732. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  733. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  734. int (*dev_ready)(struct mtd_info *mtd);
  735. void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column,
  736. int page_addr);
  737. int(*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);
  738. int (*erase)(struct mtd_info *mtd, int page);
  739. int (*scan_bbt)(struct mtd_info *mtd);
  740. int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state,
  741. int status, int page);
  742. int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
  743. uint32_t offset, int data_len, const uint8_t *buf,
  744. int oob_required, int page, int cached, int raw);
  745. int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
  746. int feature_addr, uint8_t *subfeature_para);
  747. int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
  748. int feature_addr, uint8_t *subfeature_para);
  749. int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode);
  750. int (*setup_data_interface)(struct mtd_info *mtd,
  751. const struct nand_data_interface *conf,
  752. bool check_only);
  753. int chip_delay;
  754. unsigned int options;
  755. unsigned int bbt_options;
  756. int page_shift;
  757. int phys_erase_shift;
  758. int bbt_erase_shift;
  759. int chip_shift;
  760. int numchips;
  761. uint64_t chipsize;
  762. int pagemask;
  763. int pagebuf;
  764. unsigned int pagebuf_bitflips;
  765. int subpagesize;
  766. uint8_t bits_per_cell;
  767. uint16_t ecc_strength_ds;
  768. uint16_t ecc_step_ds;
  769. int onfi_timing_mode_default;
  770. int badblockpos;
  771. int badblockbits;
  772. int onfi_version;
  773. int jedec_version;
  774. union {
  775. struct nand_onfi_params onfi_params;
  776. struct nand_jedec_params jedec_params;
  777. };
  778. struct nand_data_interface *data_interface;
  779. int read_retries;
  780. flstate_t state;
  781. uint8_t *oob_poi;
  782. struct nand_hw_control *controller;
  783. struct nand_ecc_ctrl ecc;
  784. struct nand_buffers *buffers;
  785. struct nand_hw_control hwcontrol;
  786. uint8_t *bbt;
  787. struct nand_bbt_descr *bbt_td;
  788. struct nand_bbt_descr *bbt_md;
  789. struct nand_bbt_descr *badblock_pattern;
  790. void *priv;
  791. };
  792. extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
  793. extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
  794. static inline void nand_set_flash_node(struct nand_chip *chip,
  795. struct device_node *np)
  796. {
  797. mtd_set_of_node(&chip->mtd, np);
  798. }
  799. static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
  800. {
  801. return mtd_get_of_node(&chip->mtd);
  802. }
  803. static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
  804. {
  805. return container_of(mtd, struct nand_chip, mtd);
  806. }
  807. static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
  808. {
  809. return &chip->mtd;
  810. }
  811. static inline void *nand_get_controller_data(struct nand_chip *chip)
  812. {
  813. return chip->priv;
  814. }
  815. static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
  816. {
  817. chip->priv = priv;
  818. }
  819. /*
  820. * NAND Flash Manufacturer ID Codes
  821. */
  822. #define NAND_MFR_TOSHIBA 0x98
  823. #define NAND_MFR_ESMT 0xc8
  824. #define NAND_MFR_SAMSUNG 0xec
  825. #define NAND_MFR_FUJITSU 0x04
  826. #define NAND_MFR_NATIONAL 0x8f
  827. #define NAND_MFR_RENESAS 0x07
  828. #define NAND_MFR_STMICRO 0x20
  829. #define NAND_MFR_HYNIX 0xad
  830. #define NAND_MFR_MICRON 0x2c
  831. #define NAND_MFR_AMD 0x01
  832. #define NAND_MFR_MACRONIX 0xc2
  833. #define NAND_MFR_EON 0x92
  834. #define NAND_MFR_SANDISK 0x45
  835. #define NAND_MFR_INTEL 0x89
  836. #define NAND_MFR_ATO 0x9b
  837. /* The maximum expected count of bytes in the NAND ID sequence */
  838. #define NAND_MAX_ID_LEN 8
  839. /*
  840. * A helper for defining older NAND chips where the second ID byte fully
  841. * defined the chip, including the geometry (chip size, eraseblock size, page
  842. * size). All these chips have 512 bytes NAND page size.
  843. */
  844. #define LEGACY_ID_NAND(nm, devid, chipsz, erasesz, opts) \
  845. { .name = (nm), {{ .dev_id = (devid) }}, .pagesize = 512, \
  846. .chipsize = (chipsz), .erasesize = (erasesz), .options = (opts) }
  847. /*
  848. * A helper for defining newer chips which report their page size and
  849. * eraseblock size via the extended ID bytes.
  850. *
  851. * The real difference between LEGACY_ID_NAND and EXTENDED_ID_NAND is that with
  852. * EXTENDED_ID_NAND, manufacturers overloaded the same device ID so that the
  853. * device ID now only represented a particular total chip size (and voltage,
  854. * buswidth), and the page size, eraseblock size, and OOB size could vary while
  855. * using the same device ID.
  856. */
  857. #define EXTENDED_ID_NAND(nm, devid, chipsz, opts) \
  858. { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \
  859. .options = (opts) }
  860. #define NAND_ECC_INFO(_strength, _step) \
  861. { .strength_ds = (_strength), .step_ds = (_step) }
  862. #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds)
  863. #define NAND_ECC_STEP(type) ((type)->ecc.step_ds)
  864. /**
  865. * struct nand_flash_dev - NAND Flash Device ID Structure
  866. * @name: a human-readable name of the NAND chip
  867. * @dev_id: the device ID (the second byte of the full chip ID array)
  868. * @mfr_id: manufecturer ID part of the full chip ID array (refers the same
  869. * memory address as @id[0])
  870. * @dev_id: device ID part of the full chip ID array (refers the same memory
  871. * address as @id[1])
  872. * @id: full device ID array
  873. * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as
  874. * well as the eraseblock size) is determined from the extended NAND
  875. * chip ID array)
  876. * @chipsize: total chip size in MiB
  877. * @erasesize: eraseblock size in bytes (determined from the extended ID if 0)
  878. * @options: stores various chip bit options
  879. * @id_len: The valid length of the @id.
  880. * @oobsize: OOB size
  881. * @ecc: ECC correctability and step information from the datasheet.
  882. * @ecc.strength_ds: The ECC correctability from the datasheet, same as the
  883. * @ecc_strength_ds in nand_chip{}.
  884. * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the
  885. * @ecc_step_ds in nand_chip{}, also from the datasheet.
  886. * For example, the "4bit ECC for each 512Byte" can be set with
  887. * NAND_ECC_INFO(4, 512).
  888. * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND
  889. * reset. Should be deduced from timings described
  890. * in the datasheet.
  891. *
  892. */
  893. struct nand_flash_dev {
  894. char *name;
  895. union {
  896. struct {
  897. uint8_t mfr_id;
  898. uint8_t dev_id;
  899. };
  900. uint8_t id[NAND_MAX_ID_LEN];
  901. };
  902. unsigned int pagesize;
  903. unsigned int chipsize;
  904. unsigned int erasesize;
  905. unsigned int options;
  906. uint16_t id_len;
  907. uint16_t oobsize;
  908. struct {
  909. uint16_t strength_ds;
  910. uint16_t step_ds;
  911. } ecc;
  912. int onfi_timing_mode_default;
  913. };
  914. /**
  915. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  916. * @name: Manufacturer name
  917. * @id: manufacturer ID code of device.
  918. */
  919. struct nand_manufacturers {
  920. int id;
  921. char *name;
  922. };
  923. extern struct nand_flash_dev nand_flash_ids[];
  924. extern struct nand_manufacturers nand_manuf_ids[];
  925. int nand_default_bbt(struct mtd_info *mtd);
  926. int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);
  927. int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs);
  928. int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt);
  929. int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
  930. int allowbbt);
  931. int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len,
  932. size_t *retlen, uint8_t *buf);
  933. /**
  934. * struct platform_nand_chip - chip level device structure
  935. * @nr_chips: max. number of chips to scan for
  936. * @chip_offset: chip number offset
  937. * @nr_partitions: number of partitions pointed to by partitions (or zero)
  938. * @partitions: mtd partition list
  939. * @chip_delay: R/B delay value in us
  940. * @options: Option flags, e.g. 16bit buswidth
  941. * @bbt_options: BBT option flags, e.g. NAND_BBT_USE_FLASH
  942. * @part_probe_types: NULL-terminated array of probe types
  943. */
  944. struct platform_nand_chip {
  945. int nr_chips;
  946. int chip_offset;
  947. int nr_partitions;
  948. struct mtd_partition *partitions;
  949. int chip_delay;
  950. unsigned int options;
  951. unsigned int bbt_options;
  952. const char **part_probe_types;
  953. };
  954. /* Keep gcc happy */
  955. struct platform_device;
  956. /**
  957. * struct platform_nand_ctrl - controller level device structure
  958. * @probe: platform specific function to probe/setup hardware
  959. * @remove: platform specific function to remove/teardown hardware
  960. * @hwcontrol: platform specific hardware control structure
  961. * @dev_ready: platform specific function to read ready/busy pin
  962. * @select_chip: platform specific chip select function
  963. * @cmd_ctrl: platform specific function for controlling
  964. * ALE/CLE/nCE. Also used to write command and address
  965. * @write_buf: platform specific function for write buffer
  966. * @read_buf: platform specific function for read buffer
  967. * @read_byte: platform specific function to read one byte from chip
  968. * @priv: private data to transport driver specific settings
  969. *
  970. * All fields are optional and depend on the hardware driver requirements
  971. */
  972. struct platform_nand_ctrl {
  973. int (*probe)(struct platform_device *pdev);
  974. void (*remove)(struct platform_device *pdev);
  975. void (*hwcontrol)(struct mtd_info *mtd, int cmd);
  976. int (*dev_ready)(struct mtd_info *mtd);
  977. void (*select_chip)(struct mtd_info *mtd, int chip);
  978. void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
  979. void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
  980. void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
  981. unsigned char (*read_byte)(struct mtd_info *mtd);
  982. void *priv;
  983. };
  984. /**
  985. * struct platform_nand_data - container structure for platform-specific data
  986. * @chip: chip level chip structure
  987. * @ctrl: controller level device structure
  988. */
  989. struct platform_nand_data {
  990. struct platform_nand_chip chip;
  991. struct platform_nand_ctrl ctrl;
  992. };
  993. /* return the supported features. */
  994. static inline int onfi_feature(struct nand_chip *chip)
  995. {
  996. return chip->onfi_version ? le16_to_cpu(chip->onfi_params.features) : 0;
  997. }
  998. /* return the supported asynchronous timing mode. */
  999. static inline int onfi_get_async_timing_mode(struct nand_chip *chip)
  1000. {
  1001. if (!chip->onfi_version)
  1002. return ONFI_TIMING_MODE_UNKNOWN;
  1003. return le16_to_cpu(chip->onfi_params.async_timing_mode);
  1004. }
  1005. /* return the supported synchronous timing mode. */
  1006. static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
  1007. {
  1008. if (!chip->onfi_version)
  1009. return ONFI_TIMING_MODE_UNKNOWN;
  1010. return le16_to_cpu(chip->onfi_params.src_sync_timing_mode);
  1011. }
  1012. int onfi_init_data_interface(struct nand_chip *chip,
  1013. struct nand_data_interface *iface,
  1014. enum nand_data_interface_type type,
  1015. int timing_mode);
  1016. /*
  1017. * Check if it is a SLC nand.
  1018. * The !nand_is_slc() can be used to check the MLC/TLC nand chips.
  1019. * We do not distinguish the MLC and TLC now.
  1020. */
  1021. static inline bool nand_is_slc(struct nand_chip *chip)
  1022. {
  1023. return chip->bits_per_cell == 1;
  1024. }
  1025. /**
  1026. * Check if the opcode's address should be sent only on the lower 8 bits
  1027. * @command: opcode to check
  1028. */
  1029. static inline int nand_opcode_8bits(unsigned int command)
  1030. {
  1031. switch (command) {
  1032. case NAND_CMD_READID:
  1033. case NAND_CMD_PARAM:
  1034. case NAND_CMD_GET_FEATURES:
  1035. case NAND_CMD_SET_FEATURES:
  1036. return 1;
  1037. default:
  1038. break;
  1039. }
  1040. return 0;
  1041. }
  1042. /* return the supported JEDEC features. */
  1043. static inline int jedec_feature(struct nand_chip *chip)
  1044. {
  1045. return chip->jedec_version ? le16_to_cpu(chip->jedec_params.features)
  1046. : 0;
  1047. }
  1048. /* get timing characteristics from ONFI timing mode. */
  1049. const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode);
  1050. /* get data interface from ONFI timing mode 0, used after reset. */
  1051. const struct nand_data_interface *nand_get_default_data_interface(void);
  1052. int nand_check_erased_ecc_chunk(void *data, int datalen,
  1053. void *ecc, int ecclen,
  1054. void *extraoob, int extraooblen,
  1055. int threshold);
  1056. /* Default write_oob implementation */
  1057. int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
  1058. /* Default write_oob syndrome implementation */
  1059. int nand_write_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
  1060. int page);
  1061. /* Default read_oob implementation */
  1062. int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
  1063. /* Default read_oob syndrome implementation */
  1064. int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
  1065. int page);
  1066. /* Reset and initialize a NAND device */
  1067. int nand_reset(struct nand_chip *chip, int chipnr);
  1068. /* Free resources held by the NAND device */
  1069. void nand_cleanup(struct nand_chip *chip);
  1070. #endif /* __LINUX_MTD_NAND_H */