nand.h 40 KB

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