rawnand.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. /*
  2. * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
  3. * Steven J. Hill <sjhill@realitydiluted.com>
  4. * Thomas Gleixner <tglx@linutronix.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Info:
  11. * Contains standard defines and IDs for NAND flash devices
  12. *
  13. * Changelog:
  14. * See git changelog.
  15. */
  16. #ifndef __LINUX_MTD_RAWNAND_H
  17. #define __LINUX_MTD_RAWNAND_H
  18. #include <linux/wait.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/mtd/mtd.h>
  21. #include <linux/mtd/flashchip.h>
  22. #include <linux/mtd/bbm.h>
  23. #include <linux/of.h>
  24. #include <linux/types.h>
  25. struct nand_chip;
  26. /* The maximum number of NAND chips in an array */
  27. #define NAND_MAX_CHIPS 8
  28. /*
  29. * Constants for hardware specific CLE/ALE/NCE function
  30. *
  31. * These are bits which can be or'ed to set/clear multiple
  32. * bits in one go.
  33. */
  34. /* Select the chip by setting nCE to low */
  35. #define NAND_NCE 0x01
  36. /* Select the command latch by setting CLE to high */
  37. #define NAND_CLE 0x02
  38. /* Select the address latch by setting ALE to high */
  39. #define NAND_ALE 0x04
  40. #define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
  41. #define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
  42. #define NAND_CTRL_CHANGE 0x80
  43. /*
  44. * Standard NAND flash commands
  45. */
  46. #define NAND_CMD_READ0 0
  47. #define NAND_CMD_READ1 1
  48. #define NAND_CMD_RNDOUT 5
  49. #define NAND_CMD_PAGEPROG 0x10
  50. #define NAND_CMD_READOOB 0x50
  51. #define NAND_CMD_ERASE1 0x60
  52. #define NAND_CMD_STATUS 0x70
  53. #define NAND_CMD_SEQIN 0x80
  54. #define NAND_CMD_RNDIN 0x85
  55. #define NAND_CMD_READID 0x90
  56. #define NAND_CMD_ERASE2 0xd0
  57. #define NAND_CMD_PARAM 0xec
  58. #define NAND_CMD_GET_FEATURES 0xee
  59. #define NAND_CMD_SET_FEATURES 0xef
  60. #define NAND_CMD_RESET 0xff
  61. /* Extended commands for large page devices */
  62. #define NAND_CMD_READSTART 0x30
  63. #define NAND_CMD_RNDOUTSTART 0xE0
  64. #define NAND_CMD_CACHEDPROG 0x15
  65. #define NAND_CMD_NONE -1
  66. /* Status bits */
  67. #define NAND_STATUS_FAIL 0x01
  68. #define NAND_STATUS_FAIL_N1 0x02
  69. #define NAND_STATUS_TRUE_READY 0x20
  70. #define NAND_STATUS_READY 0x40
  71. #define NAND_STATUS_WP 0x80
  72. #define NAND_DATA_IFACE_CHECK_ONLY -1
  73. /*
  74. * Constants for ECC_MODES
  75. */
  76. typedef enum {
  77. NAND_ECC_NONE,
  78. NAND_ECC_SOFT,
  79. NAND_ECC_HW,
  80. NAND_ECC_HW_SYNDROME,
  81. NAND_ECC_HW_OOB_FIRST,
  82. NAND_ECC_ON_DIE,
  83. } nand_ecc_modes_t;
  84. enum nand_ecc_algo {
  85. NAND_ECC_UNKNOWN,
  86. NAND_ECC_HAMMING,
  87. NAND_ECC_BCH,
  88. NAND_ECC_RS,
  89. };
  90. /*
  91. * Constants for Hardware ECC
  92. */
  93. /* Reset Hardware ECC for read */
  94. #define NAND_ECC_READ 0
  95. /* Reset Hardware ECC for write */
  96. #define NAND_ECC_WRITE 1
  97. /* Enable Hardware ECC before syndrome is read back from flash */
  98. #define NAND_ECC_READSYN 2
  99. /*
  100. * Enable generic NAND 'page erased' check. This check is only done when
  101. * ecc.correct() returns -EBADMSG.
  102. * Set this flag if your implementation does not fix bitflips in erased
  103. * pages and you want to rely on the default implementation.
  104. */
  105. #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0)
  106. #define NAND_ECC_MAXIMIZE BIT(1)
  107. /*
  108. * Option constants for bizarre disfunctionality and real
  109. * features.
  110. */
  111. /* Buswidth is 16 bit */
  112. #define NAND_BUSWIDTH_16 0x00000002
  113. /* Chip has cache program function */
  114. #define NAND_CACHEPRG 0x00000008
  115. /*
  116. * Chip requires ready check on read (for auto-incremented sequential read).
  117. * True only for small page devices; large page devices do not support
  118. * autoincrement.
  119. */
  120. #define NAND_NEED_READRDY 0x00000100
  121. /* Chip does not allow subpage writes */
  122. #define NAND_NO_SUBPAGE_WRITE 0x00000200
  123. /* Device is one of 'new' xD cards that expose fake nand command set */
  124. #define NAND_BROKEN_XD 0x00000400
  125. /* Device behaves just like nand, but is readonly */
  126. #define NAND_ROM 0x00000800
  127. /* Device supports subpage reads */
  128. #define NAND_SUBPAGE_READ 0x00001000
  129. /*
  130. * Some MLC NANDs need data scrambling to limit bitflips caused by repeated
  131. * patterns.
  132. */
  133. #define NAND_NEED_SCRAMBLING 0x00002000
  134. /* Device needs 3rd row address cycle */
  135. #define NAND_ROW_ADDR_3 0x00004000
  136. /* Options valid for Samsung large page devices */
  137. #define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG
  138. /* Macros to identify the above */
  139. #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ))
  140. /* Non chip related options */
  141. /* This option skips the bbt scan during initialization. */
  142. #define NAND_SKIP_BBTSCAN 0x00010000
  143. /* Chip may not exist, so silence any errors in scan */
  144. #define NAND_SCAN_SILENT_NODEV 0x00040000
  145. /*
  146. * Autodetect nand buswidth with readid/onfi.
  147. * This suppose the driver will configure the hardware in 8 bits mode
  148. * when calling nand_scan_ident, and update its configuration
  149. * before calling nand_scan_tail.
  150. */
  151. #define NAND_BUSWIDTH_AUTO 0x00080000
  152. /*
  153. * This option could be defined by controller drivers to protect against
  154. * kmap'ed, vmalloc'ed highmem buffers being passed from upper layers
  155. */
  156. #define NAND_USE_BOUNCE_BUFFER 0x00100000
  157. /*
  158. * In case your controller is implementing ->legacy.cmd_ctrl() and is relying
  159. * on the default ->cmdfunc() implementation, you may want to let the core
  160. * handle the tCCS delay which is required when a column change (RNDIN or
  161. * RNDOUT) is requested.
  162. * If your controller already takes care of this delay, you don't need to set
  163. * this flag.
  164. */
  165. #define NAND_WAIT_TCCS 0x00200000
  166. /*
  167. * Whether the NAND chip is a boot medium. Drivers might use this information
  168. * to select ECC algorithms supported by the boot ROM or similar restrictions.
  169. */
  170. #define NAND_IS_BOOT_MEDIUM 0x00400000
  171. /* Options set by nand scan */
  172. /* Nand scan has allocated controller struct */
  173. #define NAND_CONTROLLER_ALLOC 0x80000000
  174. /* Cell info constants */
  175. #define NAND_CI_CHIPNR_MSK 0x03
  176. #define NAND_CI_CELLTYPE_MSK 0x0C
  177. #define NAND_CI_CELLTYPE_SHIFT 2
  178. /* ONFI version bits */
  179. #define ONFI_VERSION_1_0 BIT(1)
  180. #define ONFI_VERSION_2_0 BIT(2)
  181. #define ONFI_VERSION_2_1 BIT(3)
  182. #define ONFI_VERSION_2_2 BIT(4)
  183. #define ONFI_VERSION_2_3 BIT(5)
  184. #define ONFI_VERSION_3_0 BIT(6)
  185. #define ONFI_VERSION_3_1 BIT(7)
  186. #define ONFI_VERSION_3_2 BIT(8)
  187. #define ONFI_VERSION_4_0 BIT(9)
  188. /* ONFI features */
  189. #define ONFI_FEATURE_16_BIT_BUS (1 << 0)
  190. #define ONFI_FEATURE_EXT_PARAM_PAGE (1 << 7)
  191. /* ONFI timing mode, used in both asynchronous and synchronous mode */
  192. #define ONFI_TIMING_MODE_0 (1 << 0)
  193. #define ONFI_TIMING_MODE_1 (1 << 1)
  194. #define ONFI_TIMING_MODE_2 (1 << 2)
  195. #define ONFI_TIMING_MODE_3 (1 << 3)
  196. #define ONFI_TIMING_MODE_4 (1 << 4)
  197. #define ONFI_TIMING_MODE_5 (1 << 5)
  198. #define ONFI_TIMING_MODE_UNKNOWN (1 << 6)
  199. /* ONFI feature number/address */
  200. #define ONFI_FEATURE_NUMBER 256
  201. #define ONFI_FEATURE_ADDR_TIMING_MODE 0x1
  202. /* Vendor-specific feature address (Micron) */
  203. #define ONFI_FEATURE_ADDR_READ_RETRY 0x89
  204. #define ONFI_FEATURE_ON_DIE_ECC 0x90
  205. #define ONFI_FEATURE_ON_DIE_ECC_EN BIT(3)
  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 jedec_ecc_info {
  301. u8 ecc_bits;
  302. u8 codeword_size;
  303. __le16 bb_per_lun;
  304. __le16 block_endurance;
  305. u8 reserved[2];
  306. } __packed;
  307. /* JEDEC features */
  308. #define JEDEC_FEATURE_16_BIT_BUS (1 << 0)
  309. struct nand_jedec_params {
  310. /* rev info and features block */
  311. /* 'J' 'E' 'S' 'D' */
  312. u8 sig[4];
  313. __le16 revision;
  314. __le16 features;
  315. u8 opt_cmd[3];
  316. __le16 sec_cmd;
  317. u8 num_of_param_pages;
  318. u8 reserved0[18];
  319. /* manufacturer information block */
  320. char manufacturer[12];
  321. char model[20];
  322. u8 jedec_id[6];
  323. u8 reserved1[10];
  324. /* memory organization block */
  325. __le32 byte_per_page;
  326. __le16 spare_bytes_per_page;
  327. u8 reserved2[6];
  328. __le32 pages_per_block;
  329. __le32 blocks_per_lun;
  330. u8 lun_count;
  331. u8 addr_cycles;
  332. u8 bits_per_cell;
  333. u8 programs_per_page;
  334. u8 multi_plane_addr;
  335. u8 multi_plane_op_attr;
  336. u8 reserved3[38];
  337. /* electrical parameter block */
  338. __le16 async_sdr_speed_grade;
  339. __le16 toggle_ddr_speed_grade;
  340. __le16 sync_ddr_speed_grade;
  341. u8 async_sdr_features;
  342. u8 toggle_ddr_features;
  343. u8 sync_ddr_features;
  344. __le16 t_prog;
  345. __le16 t_bers;
  346. __le16 t_r;
  347. __le16 t_r_multi_plane;
  348. __le16 t_ccs;
  349. __le16 io_pin_capacitance_typ;
  350. __le16 input_pin_capacitance_typ;
  351. __le16 clk_pin_capacitance_typ;
  352. u8 driver_strength_support;
  353. __le16 t_adl;
  354. u8 reserved4[36];
  355. /* ECC and endurance block */
  356. u8 guaranteed_good_blocks;
  357. __le16 guaranteed_block_endurance;
  358. struct jedec_ecc_info ecc_info[4];
  359. u8 reserved5[29];
  360. /* reserved */
  361. u8 reserved6[148];
  362. /* vendor */
  363. __le16 vendor_rev_num;
  364. u8 reserved7[88];
  365. /* CRC for Parameter Page */
  366. __le16 crc;
  367. } __packed;
  368. /**
  369. * struct onfi_params - ONFI specific parameters that will be reused
  370. * @version: ONFI version (BCD encoded), 0 if ONFI is not supported
  371. * @tPROG: Page program time
  372. * @tBERS: Block erase time
  373. * @tR: Page read time
  374. * @tCCS: Change column setup time
  375. * @async_timing_mode: Supported asynchronous timing mode
  376. * @vendor_revision: Vendor specific revision number
  377. * @vendor: Vendor specific data
  378. */
  379. struct onfi_params {
  380. int version;
  381. u16 tPROG;
  382. u16 tBERS;
  383. u16 tR;
  384. u16 tCCS;
  385. u16 async_timing_mode;
  386. u16 vendor_revision;
  387. u8 vendor[88];
  388. };
  389. /**
  390. * struct nand_parameters - NAND generic parameters from the parameter page
  391. * @model: Model name
  392. * @supports_set_get_features: The NAND chip supports setting/getting features
  393. * @set_feature_list: Bitmap of features that can be set
  394. * @get_feature_list: Bitmap of features that can be get
  395. * @onfi: ONFI specific parameters
  396. */
  397. struct nand_parameters {
  398. /* Generic parameters */
  399. const char *model;
  400. bool supports_set_get_features;
  401. DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);
  402. DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);
  403. /* ONFI parameters */
  404. struct onfi_params *onfi;
  405. };
  406. /* The maximum expected count of bytes in the NAND ID sequence */
  407. #define NAND_MAX_ID_LEN 8
  408. /**
  409. * struct nand_id - NAND id structure
  410. * @data: buffer containing the id bytes.
  411. * @len: ID length.
  412. */
  413. struct nand_id {
  414. u8 data[NAND_MAX_ID_LEN];
  415. int len;
  416. };
  417. /**
  418. * struct nand_controller_ops - Controller operations
  419. *
  420. * @attach_chip: this method is called after the NAND detection phase after
  421. * flash ID and MTD fields such as erase size, page size and OOB
  422. * size have been set up. ECC requirements are available if
  423. * provided by the NAND chip or device tree. Typically used to
  424. * choose the appropriate ECC configuration and allocate
  425. * associated resources.
  426. * This hook is optional.
  427. * @detach_chip: free all resources allocated/claimed in
  428. * nand_controller_ops->attach_chip().
  429. * This hook is optional.
  430. */
  431. struct nand_controller_ops {
  432. int (*attach_chip)(struct nand_chip *chip);
  433. void (*detach_chip)(struct nand_chip *chip);
  434. };
  435. /**
  436. * struct nand_controller - Structure used to describe a NAND controller
  437. *
  438. * @lock: protection lock
  439. * @active: the mtd device which holds the controller currently
  440. * @wq: wait queue to sleep on if a NAND operation is in
  441. * progress used instead of the per chip wait queue
  442. * when a hw controller is available.
  443. * @ops: NAND controller operations.
  444. */
  445. struct nand_controller {
  446. spinlock_t lock;
  447. struct nand_chip *active;
  448. wait_queue_head_t wq;
  449. const struct nand_controller_ops *ops;
  450. };
  451. static inline void nand_controller_init(struct nand_controller *nfc)
  452. {
  453. nfc->active = NULL;
  454. spin_lock_init(&nfc->lock);
  455. init_waitqueue_head(&nfc->wq);
  456. }
  457. /**
  458. * struct nand_ecc_step_info - ECC step information of ECC engine
  459. * @stepsize: data bytes per ECC step
  460. * @strengths: array of supported strengths
  461. * @nstrengths: number of supported strengths
  462. */
  463. struct nand_ecc_step_info {
  464. int stepsize;
  465. const int *strengths;
  466. int nstrengths;
  467. };
  468. /**
  469. * struct nand_ecc_caps - capability of ECC engine
  470. * @stepinfos: array of ECC step information
  471. * @nstepinfos: number of ECC step information
  472. * @calc_ecc_bytes: driver's hook to calculate ECC bytes per step
  473. */
  474. struct nand_ecc_caps {
  475. const struct nand_ecc_step_info *stepinfos;
  476. int nstepinfos;
  477. int (*calc_ecc_bytes)(int step_size, int strength);
  478. };
  479. /* a shorthand to generate struct nand_ecc_caps with only one ECC stepsize */
  480. #define NAND_ECC_CAPS_SINGLE(__name, __calc, __step, ...) \
  481. static const int __name##_strengths[] = { __VA_ARGS__ }; \
  482. static const struct nand_ecc_step_info __name##_stepinfo = { \
  483. .stepsize = __step, \
  484. .strengths = __name##_strengths, \
  485. .nstrengths = ARRAY_SIZE(__name##_strengths), \
  486. }; \
  487. static const struct nand_ecc_caps __name = { \
  488. .stepinfos = &__name##_stepinfo, \
  489. .nstepinfos = 1, \
  490. .calc_ecc_bytes = __calc, \
  491. }
  492. /**
  493. * struct nand_ecc_ctrl - Control structure for ECC
  494. * @mode: ECC mode
  495. * @algo: ECC algorithm
  496. * @steps: number of ECC steps per page
  497. * @size: data bytes per ECC step
  498. * @bytes: ECC bytes per step
  499. * @strength: max number of correctible bits per ECC step
  500. * @total: total number of ECC bytes per page
  501. * @prepad: padding information for syndrome based ECC generators
  502. * @postpad: padding information for syndrome based ECC generators
  503. * @options: ECC specific options (see NAND_ECC_XXX flags defined above)
  504. * @priv: pointer to private ECC control data
  505. * @calc_buf: buffer for calculated ECC, size is oobsize.
  506. * @code_buf: buffer for ECC read from flash, size is oobsize.
  507. * @hwctl: function to control hardware ECC generator. Must only
  508. * be provided if an hardware ECC is available
  509. * @calculate: function for ECC calculation or readback from ECC hardware
  510. * @correct: function for ECC correction, matching to ECC generator (sw/hw).
  511. * Should return a positive number representing the number of
  512. * corrected bitflips, -EBADMSG if the number of bitflips exceed
  513. * ECC strength, or any other error code if the error is not
  514. * directly related to correction.
  515. * If -EBADMSG is returned the input buffers should be left
  516. * untouched.
  517. * @read_page_raw: function to read a raw page without ECC. This function
  518. * should hide the specific layout used by the ECC
  519. * controller and always return contiguous in-band and
  520. * out-of-band data even if they're not stored
  521. * contiguously on the NAND chip (e.g.
  522. * NAND_ECC_HW_SYNDROME interleaves in-band and
  523. * out-of-band data).
  524. * @write_page_raw: function to write a raw page without ECC. This function
  525. * should hide the specific layout used by the ECC
  526. * controller and consider the passed data as contiguous
  527. * in-band and out-of-band data. ECC controller is
  528. * responsible for doing the appropriate transformations
  529. * to adapt to its specific layout (e.g.
  530. * NAND_ECC_HW_SYNDROME interleaves in-band and
  531. * out-of-band data).
  532. * @read_page: function to read a page according to the ECC generator
  533. * requirements; returns maximum number of bitflips corrected in
  534. * any single ECC step, -EIO hw error
  535. * @read_subpage: function to read parts of the page covered by ECC;
  536. * returns same as read_page()
  537. * @write_subpage: function to write parts of the page covered by ECC.
  538. * @write_page: function to write a page according to the ECC generator
  539. * requirements.
  540. * @write_oob_raw: function to write chip OOB data without ECC
  541. * @read_oob_raw: function to read chip OOB data without ECC
  542. * @read_oob: function to read chip OOB data
  543. * @write_oob: function to write chip OOB data
  544. */
  545. struct nand_ecc_ctrl {
  546. nand_ecc_modes_t mode;
  547. enum nand_ecc_algo algo;
  548. int steps;
  549. int size;
  550. int bytes;
  551. int total;
  552. int strength;
  553. int prepad;
  554. int postpad;
  555. unsigned int options;
  556. void *priv;
  557. u8 *calc_buf;
  558. u8 *code_buf;
  559. void (*hwctl)(struct nand_chip *chip, int mode);
  560. int (*calculate)(struct nand_chip *chip, const uint8_t *dat,
  561. uint8_t *ecc_code);
  562. int (*correct)(struct nand_chip *chip, uint8_t *dat, uint8_t *read_ecc,
  563. uint8_t *calc_ecc);
  564. int (*read_page_raw)(struct nand_chip *chip, uint8_t *buf,
  565. int oob_required, int page);
  566. int (*write_page_raw)(struct nand_chip *chip, const uint8_t *buf,
  567. int oob_required, int page);
  568. int (*read_page)(struct nand_chip *chip, uint8_t *buf,
  569. int oob_required, int page);
  570. int (*read_subpage)(struct nand_chip *chip, uint32_t offs,
  571. uint32_t len, uint8_t *buf, int page);
  572. int (*write_subpage)(struct nand_chip *chip, uint32_t offset,
  573. uint32_t data_len, const uint8_t *data_buf,
  574. int oob_required, int page);
  575. int (*write_page)(struct nand_chip *chip, const uint8_t *buf,
  576. int oob_required, int page);
  577. int (*write_oob_raw)(struct nand_chip *chip, int page);
  578. int (*read_oob_raw)(struct nand_chip *chip, int page);
  579. int (*read_oob)(struct nand_chip *chip, int page);
  580. int (*write_oob)(struct nand_chip *chip, int page);
  581. };
  582. /**
  583. * struct nand_sdr_timings - SDR NAND chip timings
  584. *
  585. * This struct defines the timing requirements of a SDR NAND chip.
  586. * These information can be found in every NAND datasheets and the timings
  587. * meaning are described in the ONFI specifications:
  588. * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing
  589. * Parameters)
  590. *
  591. * All these timings are expressed in picoseconds.
  592. *
  593. * @tBERS_max: Block erase time
  594. * @tCCS_min: Change column setup time
  595. * @tPROG_max: Page program time
  596. * @tR_max: Page read time
  597. * @tALH_min: ALE hold time
  598. * @tADL_min: ALE to data loading time
  599. * @tALS_min: ALE setup time
  600. * @tAR_min: ALE to RE# delay
  601. * @tCEA_max: CE# access time
  602. * @tCEH_min: CE# high hold time
  603. * @tCH_min: CE# hold time
  604. * @tCHZ_max: CE# high to output hi-Z
  605. * @tCLH_min: CLE hold time
  606. * @tCLR_min: CLE to RE# delay
  607. * @tCLS_min: CLE setup time
  608. * @tCOH_min: CE# high to output hold
  609. * @tCS_min: CE# setup time
  610. * @tDH_min: Data hold time
  611. * @tDS_min: Data setup time
  612. * @tFEAT_max: Busy time for Set Features and Get Features
  613. * @tIR_min: Output hi-Z to RE# low
  614. * @tITC_max: Interface and Timing Mode Change time
  615. * @tRC_min: RE# cycle time
  616. * @tREA_max: RE# access time
  617. * @tREH_min: RE# high hold time
  618. * @tRHOH_min: RE# high to output hold
  619. * @tRHW_min: RE# high to WE# low
  620. * @tRHZ_max: RE# high to output hi-Z
  621. * @tRLOH_min: RE# low to output hold
  622. * @tRP_min: RE# pulse width
  623. * @tRR_min: Ready to RE# low (data only)
  624. * @tRST_max: Device reset time, measured from the falling edge of R/B# to the
  625. * rising edge of R/B#.
  626. * @tWB_max: WE# high to SR[6] low
  627. * @tWC_min: WE# cycle time
  628. * @tWH_min: WE# high hold time
  629. * @tWHR_min: WE# high to RE# low
  630. * @tWP_min: WE# pulse width
  631. * @tWW_min: WP# transition to WE# low
  632. */
  633. struct nand_sdr_timings {
  634. u64 tBERS_max;
  635. u32 tCCS_min;
  636. u64 tPROG_max;
  637. u64 tR_max;
  638. u32 tALH_min;
  639. u32 tADL_min;
  640. u32 tALS_min;
  641. u32 tAR_min;
  642. u32 tCEA_max;
  643. u32 tCEH_min;
  644. u32 tCH_min;
  645. u32 tCHZ_max;
  646. u32 tCLH_min;
  647. u32 tCLR_min;
  648. u32 tCLS_min;
  649. u32 tCOH_min;
  650. u32 tCS_min;
  651. u32 tDH_min;
  652. u32 tDS_min;
  653. u32 tFEAT_max;
  654. u32 tIR_min;
  655. u32 tITC_max;
  656. u32 tRC_min;
  657. u32 tREA_max;
  658. u32 tREH_min;
  659. u32 tRHOH_min;
  660. u32 tRHW_min;
  661. u32 tRHZ_max;
  662. u32 tRLOH_min;
  663. u32 tRP_min;
  664. u32 tRR_min;
  665. u64 tRST_max;
  666. u32 tWB_max;
  667. u32 tWC_min;
  668. u32 tWH_min;
  669. u32 tWHR_min;
  670. u32 tWP_min;
  671. u32 tWW_min;
  672. };
  673. /**
  674. * enum nand_data_interface_type - NAND interface timing type
  675. * @NAND_SDR_IFACE: Single Data Rate interface
  676. */
  677. enum nand_data_interface_type {
  678. NAND_SDR_IFACE,
  679. };
  680. /**
  681. * struct nand_data_interface - NAND interface timing
  682. * @type: type of the timing
  683. * @timings: The timing, type according to @type
  684. * @timings.sdr: Use it when @type is %NAND_SDR_IFACE.
  685. */
  686. struct nand_data_interface {
  687. enum nand_data_interface_type type;
  688. union {
  689. struct nand_sdr_timings sdr;
  690. } timings;
  691. };
  692. /**
  693. * nand_get_sdr_timings - get SDR timing from data interface
  694. * @conf: The data interface
  695. */
  696. static inline const struct nand_sdr_timings *
  697. nand_get_sdr_timings(const struct nand_data_interface *conf)
  698. {
  699. if (conf->type != NAND_SDR_IFACE)
  700. return ERR_PTR(-EINVAL);
  701. return &conf->timings.sdr;
  702. }
  703. /**
  704. * struct nand_manufacturer_ops - NAND Manufacturer operations
  705. * @detect: detect the NAND memory organization and capabilities
  706. * @init: initialize all vendor specific fields (like the ->read_retry()
  707. * implementation) if any.
  708. * @cleanup: the ->init() function may have allocated resources, ->cleanup()
  709. * is here to let vendor specific code release those resources.
  710. * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI parameter
  711. * page. This is called after the checksum is verified.
  712. */
  713. struct nand_manufacturer_ops {
  714. void (*detect)(struct nand_chip *chip);
  715. int (*init)(struct nand_chip *chip);
  716. void (*cleanup)(struct nand_chip *chip);
  717. void (*fixup_onfi_param_page)(struct nand_chip *chip,
  718. struct nand_onfi_params *p);
  719. };
  720. /**
  721. * struct nand_op_cmd_instr - Definition of a command instruction
  722. * @opcode: the command to issue in one cycle
  723. */
  724. struct nand_op_cmd_instr {
  725. u8 opcode;
  726. };
  727. /**
  728. * struct nand_op_addr_instr - Definition of an address instruction
  729. * @naddrs: length of the @addrs array
  730. * @addrs: array containing the address cycles to issue
  731. */
  732. struct nand_op_addr_instr {
  733. unsigned int naddrs;
  734. const u8 *addrs;
  735. };
  736. /**
  737. * struct nand_op_data_instr - Definition of a data instruction
  738. * @len: number of data bytes to move
  739. * @buf: buffer to fill
  740. * @buf.in: buffer to fill when reading from the NAND chip
  741. * @buf.out: buffer to read from when writing to the NAND chip
  742. * @force_8bit: force 8-bit access
  743. *
  744. * Please note that "in" and "out" are inverted from the ONFI specification
  745. * and are from the controller perspective, so a "in" is a read from the NAND
  746. * chip while a "out" is a write to the NAND chip.
  747. */
  748. struct nand_op_data_instr {
  749. unsigned int len;
  750. union {
  751. void *in;
  752. const void *out;
  753. } buf;
  754. bool force_8bit;
  755. };
  756. /**
  757. * struct nand_op_waitrdy_instr - Definition of a wait ready instruction
  758. * @timeout_ms: maximum delay while waiting for the ready/busy pin in ms
  759. */
  760. struct nand_op_waitrdy_instr {
  761. unsigned int timeout_ms;
  762. };
  763. /**
  764. * enum nand_op_instr_type - Definition of all instruction types
  765. * @NAND_OP_CMD_INSTR: command instruction
  766. * @NAND_OP_ADDR_INSTR: address instruction
  767. * @NAND_OP_DATA_IN_INSTR: data in instruction
  768. * @NAND_OP_DATA_OUT_INSTR: data out instruction
  769. * @NAND_OP_WAITRDY_INSTR: wait ready instruction
  770. */
  771. enum nand_op_instr_type {
  772. NAND_OP_CMD_INSTR,
  773. NAND_OP_ADDR_INSTR,
  774. NAND_OP_DATA_IN_INSTR,
  775. NAND_OP_DATA_OUT_INSTR,
  776. NAND_OP_WAITRDY_INSTR,
  777. };
  778. /**
  779. * struct nand_op_instr - Instruction object
  780. * @type: the instruction type
  781. * @ctx: extra data associated to the instruction. You'll have to use the
  782. * appropriate element depending on @type
  783. * @ctx.cmd: use it if @type is %NAND_OP_CMD_INSTR
  784. * @ctx.addr: use it if @type is %NAND_OP_ADDR_INSTR
  785. * @ctx.data: use it if @type is %NAND_OP_DATA_IN_INSTR
  786. * or %NAND_OP_DATA_OUT_INSTR
  787. * @ctx.waitrdy: use it if @type is %NAND_OP_WAITRDY_INSTR
  788. * @delay_ns: delay the controller should apply after the instruction has been
  789. * issued on the bus. Most modern controllers have internal timings
  790. * control logic, and in this case, the controller driver can ignore
  791. * this field.
  792. */
  793. struct nand_op_instr {
  794. enum nand_op_instr_type type;
  795. union {
  796. struct nand_op_cmd_instr cmd;
  797. struct nand_op_addr_instr addr;
  798. struct nand_op_data_instr data;
  799. struct nand_op_waitrdy_instr waitrdy;
  800. } ctx;
  801. unsigned int delay_ns;
  802. };
  803. /*
  804. * Special handling must be done for the WAITRDY timeout parameter as it usually
  805. * is either tPROG (after a prog), tR (before a read), tRST (during a reset) or
  806. * tBERS (during an erase) which all of them are u64 values that cannot be
  807. * divided by usual kernel macros and must be handled with the special
  808. * DIV_ROUND_UP_ULL() macro.
  809. *
  810. * Cast to type of dividend is needed here to guarantee that the result won't
  811. * be an unsigned long long when the dividend is an unsigned long (or smaller),
  812. * which is what the compiler does when it sees ternary operator with 2
  813. * different return types (picks the largest type to make sure there's no
  814. * loss).
  815. */
  816. #define __DIVIDE(dividend, divisor) ({ \
  817. (__typeof__(dividend))(sizeof(dividend) <= sizeof(unsigned long) ? \
  818. DIV_ROUND_UP(dividend, divisor) : \
  819. DIV_ROUND_UP_ULL(dividend, divisor)); \
  820. })
  821. #define PSEC_TO_NSEC(x) __DIVIDE(x, 1000)
  822. #define PSEC_TO_MSEC(x) __DIVIDE(x, 1000000000)
  823. #define NAND_OP_CMD(id, ns) \
  824. { \
  825. .type = NAND_OP_CMD_INSTR, \
  826. .ctx.cmd.opcode = id, \
  827. .delay_ns = ns, \
  828. }
  829. #define NAND_OP_ADDR(ncycles, cycles, ns) \
  830. { \
  831. .type = NAND_OP_ADDR_INSTR, \
  832. .ctx.addr = { \
  833. .naddrs = ncycles, \
  834. .addrs = cycles, \
  835. }, \
  836. .delay_ns = ns, \
  837. }
  838. #define NAND_OP_DATA_IN(l, b, ns) \
  839. { \
  840. .type = NAND_OP_DATA_IN_INSTR, \
  841. .ctx.data = { \
  842. .len = l, \
  843. .buf.in = b, \
  844. .force_8bit = false, \
  845. }, \
  846. .delay_ns = ns, \
  847. }
  848. #define NAND_OP_DATA_OUT(l, b, ns) \
  849. { \
  850. .type = NAND_OP_DATA_OUT_INSTR, \
  851. .ctx.data = { \
  852. .len = l, \
  853. .buf.out = b, \
  854. .force_8bit = false, \
  855. }, \
  856. .delay_ns = ns, \
  857. }
  858. #define NAND_OP_8BIT_DATA_IN(l, b, ns) \
  859. { \
  860. .type = NAND_OP_DATA_IN_INSTR, \
  861. .ctx.data = { \
  862. .len = l, \
  863. .buf.in = b, \
  864. .force_8bit = true, \
  865. }, \
  866. .delay_ns = ns, \
  867. }
  868. #define NAND_OP_8BIT_DATA_OUT(l, b, ns) \
  869. { \
  870. .type = NAND_OP_DATA_OUT_INSTR, \
  871. .ctx.data = { \
  872. .len = l, \
  873. .buf.out = b, \
  874. .force_8bit = true, \
  875. }, \
  876. .delay_ns = ns, \
  877. }
  878. #define NAND_OP_WAIT_RDY(tout_ms, ns) \
  879. { \
  880. .type = NAND_OP_WAITRDY_INSTR, \
  881. .ctx.waitrdy.timeout_ms = tout_ms, \
  882. .delay_ns = ns, \
  883. }
  884. /**
  885. * struct nand_subop - a sub operation
  886. * @instrs: array of instructions
  887. * @ninstrs: length of the @instrs array
  888. * @first_instr_start_off: offset to start from for the first instruction
  889. * of the sub-operation
  890. * @last_instr_end_off: offset to end at (excluded) for the last instruction
  891. * of the sub-operation
  892. *
  893. * Both @first_instr_start_off and @last_instr_end_off only apply to data or
  894. * address instructions.
  895. *
  896. * When an operation cannot be handled as is by the NAND controller, it will
  897. * be split by the parser into sub-operations which will be passed to the
  898. * controller driver.
  899. */
  900. struct nand_subop {
  901. const struct nand_op_instr *instrs;
  902. unsigned int ninstrs;
  903. unsigned int first_instr_start_off;
  904. unsigned int last_instr_end_off;
  905. };
  906. unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
  907. unsigned int op_id);
  908. unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
  909. unsigned int op_id);
  910. unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
  911. unsigned int op_id);
  912. unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
  913. unsigned int op_id);
  914. /**
  915. * struct nand_op_parser_addr_constraints - Constraints for address instructions
  916. * @maxcycles: maximum number of address cycles the controller can issue in a
  917. * single step
  918. */
  919. struct nand_op_parser_addr_constraints {
  920. unsigned int maxcycles;
  921. };
  922. /**
  923. * struct nand_op_parser_data_constraints - Constraints for data instructions
  924. * @maxlen: maximum data length that the controller can handle in a single step
  925. */
  926. struct nand_op_parser_data_constraints {
  927. unsigned int maxlen;
  928. };
  929. /**
  930. * struct nand_op_parser_pattern_elem - One element of a pattern
  931. * @type: the instructuction type
  932. * @optional: whether this element of the pattern is optional or mandatory
  933. * @ctx: address or data constraint
  934. * @ctx.addr: address constraint (number of cycles)
  935. * @ctx.data: data constraint (data length)
  936. */
  937. struct nand_op_parser_pattern_elem {
  938. enum nand_op_instr_type type;
  939. bool optional;
  940. union {
  941. struct nand_op_parser_addr_constraints addr;
  942. struct nand_op_parser_data_constraints data;
  943. } ctx;
  944. };
  945. #define NAND_OP_PARSER_PAT_CMD_ELEM(_opt) \
  946. { \
  947. .type = NAND_OP_CMD_INSTR, \
  948. .optional = _opt, \
  949. }
  950. #define NAND_OP_PARSER_PAT_ADDR_ELEM(_opt, _maxcycles) \
  951. { \
  952. .type = NAND_OP_ADDR_INSTR, \
  953. .optional = _opt, \
  954. .ctx.addr.maxcycles = _maxcycles, \
  955. }
  956. #define NAND_OP_PARSER_PAT_DATA_IN_ELEM(_opt, _maxlen) \
  957. { \
  958. .type = NAND_OP_DATA_IN_INSTR, \
  959. .optional = _opt, \
  960. .ctx.data.maxlen = _maxlen, \
  961. }
  962. #define NAND_OP_PARSER_PAT_DATA_OUT_ELEM(_opt, _maxlen) \
  963. { \
  964. .type = NAND_OP_DATA_OUT_INSTR, \
  965. .optional = _opt, \
  966. .ctx.data.maxlen = _maxlen, \
  967. }
  968. #define NAND_OP_PARSER_PAT_WAITRDY_ELEM(_opt) \
  969. { \
  970. .type = NAND_OP_WAITRDY_INSTR, \
  971. .optional = _opt, \
  972. }
  973. /**
  974. * struct nand_op_parser_pattern - NAND sub-operation pattern descriptor
  975. * @elems: array of pattern elements
  976. * @nelems: number of pattern elements in @elems array
  977. * @exec: the function that will issue a sub-operation
  978. *
  979. * A pattern is a list of elements, each element reprensenting one instruction
  980. * with its constraints. The pattern itself is used by the core to match NAND
  981. * chip operation with NAND controller operations.
  982. * Once a match between a NAND controller operation pattern and a NAND chip
  983. * operation (or a sub-set of a NAND operation) is found, the pattern ->exec()
  984. * hook is called so that the controller driver can issue the operation on the
  985. * bus.
  986. *
  987. * Controller drivers should declare as many patterns as they support and pass
  988. * this list of patterns (created with the help of the following macro) to
  989. * the nand_op_parser_exec_op() helper.
  990. */
  991. struct nand_op_parser_pattern {
  992. const struct nand_op_parser_pattern_elem *elems;
  993. unsigned int nelems;
  994. int (*exec)(struct nand_chip *chip, const struct nand_subop *subop);
  995. };
  996. #define NAND_OP_PARSER_PATTERN(_exec, ...) \
  997. { \
  998. .exec = _exec, \
  999. .elems = (struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }, \
  1000. .nelems = sizeof((struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }) / \
  1001. sizeof(struct nand_op_parser_pattern_elem), \
  1002. }
  1003. /**
  1004. * struct nand_op_parser - NAND controller operation parser descriptor
  1005. * @patterns: array of supported patterns
  1006. * @npatterns: length of the @patterns array
  1007. *
  1008. * The parser descriptor is just an array of supported patterns which will be
  1009. * iterated by nand_op_parser_exec_op() everytime it tries to execute an
  1010. * NAND operation (or tries to determine if a specific operation is supported).
  1011. *
  1012. * It is worth mentioning that patterns will be tested in their declaration
  1013. * order, and the first match will be taken, so it's important to order patterns
  1014. * appropriately so that simple/inefficient patterns are placed at the end of
  1015. * the list. Usually, this is where you put single instruction patterns.
  1016. */
  1017. struct nand_op_parser {
  1018. const struct nand_op_parser_pattern *patterns;
  1019. unsigned int npatterns;
  1020. };
  1021. #define NAND_OP_PARSER(...) \
  1022. { \
  1023. .patterns = (struct nand_op_parser_pattern[]) { __VA_ARGS__ }, \
  1024. .npatterns = sizeof((struct nand_op_parser_pattern[]) { __VA_ARGS__ }) / \
  1025. sizeof(struct nand_op_parser_pattern), \
  1026. }
  1027. /**
  1028. * struct nand_operation - NAND operation descriptor
  1029. * @instrs: array of instructions to execute
  1030. * @ninstrs: length of the @instrs array
  1031. *
  1032. * The actual operation structure that will be passed to chip->exec_op().
  1033. */
  1034. struct nand_operation {
  1035. const struct nand_op_instr *instrs;
  1036. unsigned int ninstrs;
  1037. };
  1038. #define NAND_OPERATION(_instrs) \
  1039. { \
  1040. .instrs = _instrs, \
  1041. .ninstrs = ARRAY_SIZE(_instrs), \
  1042. }
  1043. int nand_op_parser_exec_op(struct nand_chip *chip,
  1044. const struct nand_op_parser *parser,
  1045. const struct nand_operation *op, bool check_only);
  1046. /**
  1047. * struct nand_legacy - NAND chip legacy fields/hooks
  1048. * @IO_ADDR_R: address to read the 8 I/O lines of the flash device
  1049. * @IO_ADDR_W: address to write the 8 I/O lines of the flash device
  1050. * @read_byte: read one byte from the chip
  1051. * @write_byte: write a single byte to the chip on the low 8 I/O lines
  1052. * @write_buf: write data from the buffer to the chip
  1053. * @read_buf: read data from the chip into the buffer
  1054. * @cmd_ctrl: hardware specific function for controlling ALE/CLE/nCE. Also used
  1055. * to write command and address
  1056. * @cmdfunc: hardware specific function for writing commands to the chip.
  1057. * @dev_ready: hardware specific function for accessing device ready/busy line.
  1058. * If set to NULL no access to ready/busy is available and the
  1059. * ready/busy information is read from the chip status register.
  1060. * @waitfunc: hardware specific function for wait on ready.
  1061. * @block_bad: check if a block is bad, using OOB markers
  1062. * @block_markbad: mark a block bad
  1063. * @erase: erase function
  1064. * @set_features: set the NAND chip features
  1065. * @get_features: get the NAND chip features
  1066. * @chip_delay: chip dependent delay for transferring data from array to read
  1067. * regs (tR).
  1068. *
  1069. * If you look at this structure you're already wrong. These fields/hooks are
  1070. * all deprecated.
  1071. */
  1072. struct nand_legacy {
  1073. void __iomem *IO_ADDR_R;
  1074. void __iomem *IO_ADDR_W;
  1075. u8 (*read_byte)(struct nand_chip *chip);
  1076. void (*write_byte)(struct nand_chip *chip, u8 byte);
  1077. void (*write_buf)(struct nand_chip *chip, const u8 *buf, int len);
  1078. void (*read_buf)(struct nand_chip *chip, u8 *buf, int len);
  1079. void (*cmd_ctrl)(struct nand_chip *chip, int dat, unsigned int ctrl);
  1080. void (*cmdfunc)(struct nand_chip *chip, unsigned command, int column,
  1081. int page_addr);
  1082. int (*dev_ready)(struct nand_chip *chip);
  1083. int (*waitfunc)(struct nand_chip *chip);
  1084. int (*block_bad)(struct nand_chip *chip, loff_t ofs);
  1085. int (*block_markbad)(struct nand_chip *chip, loff_t ofs);
  1086. int (*erase)(struct nand_chip *chip, int page);
  1087. int (*set_features)(struct nand_chip *chip, int feature_addr,
  1088. u8 *subfeature_para);
  1089. int (*get_features)(struct nand_chip *chip, int feature_addr,
  1090. u8 *subfeature_para);
  1091. int chip_delay;
  1092. };
  1093. /**
  1094. * struct nand_chip - NAND Private Flash Chip Data
  1095. * @mtd: MTD device registered to the MTD framework
  1096. * @legacy: All legacy fields/hooks. If you develop a new driver,
  1097. * don't even try to use any of these fields/hooks, and if
  1098. * you're modifying an existing driver that is using those
  1099. * fields/hooks, you should consider reworking the driver
  1100. * avoid using them.
  1101. * @select_chip: [REPLACEABLE] select chip nr
  1102. * @exec_op: controller specific method to execute NAND operations.
  1103. * This method replaces ->cmdfunc(),
  1104. * ->legacy.{read,write}_{buf,byte,word}(),
  1105. * ->legacy.dev_ready() and ->waifunc().
  1106. * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for
  1107. * setting the read-retry mode. Mostly needed for MLC NAND.
  1108. * @ecc: [BOARDSPECIFIC] ECC control structure
  1109. * @buf_align: minimum buffer alignment required by a platform
  1110. * @dummy_controller: dummy controller implementation for drivers that can
  1111. * only control a single chip
  1112. * @state: [INTERN] the current state of the NAND device
  1113. * @oob_poi: "poison value buffer," used for laying out OOB data
  1114. * before writing
  1115. * @page_shift: [INTERN] number of address bits in a page (column
  1116. * address bits).
  1117. * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
  1118. * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
  1119. * @chip_shift: [INTERN] number of address bits in one chip
  1120. * @options: [BOARDSPECIFIC] various chip options. They can partly
  1121. * be set to inform nand_scan about special functionality.
  1122. * See the defines for further explanation.
  1123. * @bbt_options: [INTERN] bad block specific options. All options used
  1124. * here must come from bbm.h. By default, these options
  1125. * will be copied to the appropriate nand_bbt_descr's.
  1126. * @badblockpos: [INTERN] position of the bad block marker in the oob
  1127. * area.
  1128. * @badblockbits: [INTERN] minimum number of set bits in a good block's
  1129. * bad block marker position; i.e., BBM == 11110111b is
  1130. * not bad when badblockbits == 7
  1131. * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC.
  1132. * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet.
  1133. * Minimum amount of bit errors per @ecc_step_ds guaranteed
  1134. * to be correctable. If unknown, set to zero.
  1135. * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds,
  1136. * also from the datasheet. It is the recommended ECC step
  1137. * size, if known; if unknown, set to zero.
  1138. * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is
  1139. * set to the actually used ONFI mode if the chip is
  1140. * ONFI compliant or deduced from the datasheet if
  1141. * the NAND chip is not ONFI compliant.
  1142. * @numchips: [INTERN] number of physical chips
  1143. * @chipsize: [INTERN] the size of one chip for multichip arrays
  1144. * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
  1145. * @data_buf: [INTERN] buffer for data, size is (page size + oobsize).
  1146. * @pagebuf: [INTERN] holds the pagenumber which is currently in
  1147. * data_buf.
  1148. * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is
  1149. * currently in data_buf.
  1150. * @subpagesize: [INTERN] holds the subpagesize
  1151. * @id: [INTERN] holds NAND ID
  1152. * @parameters: [INTERN] holds generic parameters under an easily
  1153. * readable form.
  1154. * @max_bb_per_die: [INTERN] the max number of bad blocks each die of a
  1155. * this nand device will encounter their life times.
  1156. * @blocks_per_die: [INTERN] The number of PEBs in a die
  1157. * @data_interface: [INTERN] NAND interface timing information
  1158. * @read_retries: [INTERN] the number of read retry modes supported
  1159. * @setup_data_interface: [OPTIONAL] setup the data interface and timing. If
  1160. * chipnr is set to %NAND_DATA_IFACE_CHECK_ONLY this
  1161. * means the configuration should not be applied but
  1162. * only checked.
  1163. * @bbt: [INTERN] bad block table pointer
  1164. * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
  1165. * lookup.
  1166. * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
  1167. * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial
  1168. * bad block scan.
  1169. * @controller: [REPLACEABLE] a pointer to a hardware controller
  1170. * structure which is shared among multiple independent
  1171. * devices.
  1172. * @priv: [OPTIONAL] pointer to private chip data
  1173. * @manufacturer: [INTERN] Contains manufacturer information
  1174. * @manufacturer.desc: [INTERN] Contains manufacturer's description
  1175. * @manufacturer.priv: [INTERN] Contains manufacturer private information
  1176. */
  1177. struct nand_chip {
  1178. struct mtd_info mtd;
  1179. struct nand_legacy legacy;
  1180. void (*select_chip)(struct nand_chip *chip, int cs);
  1181. int (*exec_op)(struct nand_chip *chip,
  1182. const struct nand_operation *op,
  1183. bool check_only);
  1184. int (*setup_read_retry)(struct nand_chip *chip, int retry_mode);
  1185. int (*setup_data_interface)(struct nand_chip *chip, int chipnr,
  1186. const struct nand_data_interface *conf);
  1187. unsigned int options;
  1188. unsigned int bbt_options;
  1189. int page_shift;
  1190. int phys_erase_shift;
  1191. int bbt_erase_shift;
  1192. int chip_shift;
  1193. int numchips;
  1194. uint64_t chipsize;
  1195. int pagemask;
  1196. u8 *data_buf;
  1197. int pagebuf;
  1198. unsigned int pagebuf_bitflips;
  1199. int subpagesize;
  1200. uint8_t bits_per_cell;
  1201. uint16_t ecc_strength_ds;
  1202. uint16_t ecc_step_ds;
  1203. int onfi_timing_mode_default;
  1204. int badblockpos;
  1205. int badblockbits;
  1206. struct nand_id id;
  1207. struct nand_parameters parameters;
  1208. u16 max_bb_per_die;
  1209. u32 blocks_per_die;
  1210. struct nand_data_interface data_interface;
  1211. int read_retries;
  1212. flstate_t state;
  1213. uint8_t *oob_poi;
  1214. struct nand_controller *controller;
  1215. struct nand_ecc_ctrl ecc;
  1216. unsigned long buf_align;
  1217. struct nand_controller dummy_controller;
  1218. uint8_t *bbt;
  1219. struct nand_bbt_descr *bbt_td;
  1220. struct nand_bbt_descr *bbt_md;
  1221. struct nand_bbt_descr *badblock_pattern;
  1222. void *priv;
  1223. struct {
  1224. const struct nand_manufacturer *desc;
  1225. void *priv;
  1226. } manufacturer;
  1227. };
  1228. static inline int nand_exec_op(struct nand_chip *chip,
  1229. const struct nand_operation *op)
  1230. {
  1231. if (!chip->exec_op)
  1232. return -ENOTSUPP;
  1233. return chip->exec_op(chip, op, false);
  1234. }
  1235. extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
  1236. extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
  1237. static inline void nand_set_flash_node(struct nand_chip *chip,
  1238. struct device_node *np)
  1239. {
  1240. mtd_set_of_node(&chip->mtd, np);
  1241. }
  1242. static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
  1243. {
  1244. return mtd_get_of_node(&chip->mtd);
  1245. }
  1246. static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
  1247. {
  1248. return container_of(mtd, struct nand_chip, mtd);
  1249. }
  1250. static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
  1251. {
  1252. return &chip->mtd;
  1253. }
  1254. static inline void *nand_get_controller_data(struct nand_chip *chip)
  1255. {
  1256. return chip->priv;
  1257. }
  1258. static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
  1259. {
  1260. chip->priv = priv;
  1261. }
  1262. static inline void nand_set_manufacturer_data(struct nand_chip *chip,
  1263. void *priv)
  1264. {
  1265. chip->manufacturer.priv = priv;
  1266. }
  1267. static inline void *nand_get_manufacturer_data(struct nand_chip *chip)
  1268. {
  1269. return chip->manufacturer.priv;
  1270. }
  1271. /*
  1272. * NAND Flash Manufacturer ID Codes
  1273. */
  1274. #define NAND_MFR_TOSHIBA 0x98
  1275. #define NAND_MFR_ESMT 0xc8
  1276. #define NAND_MFR_SAMSUNG 0xec
  1277. #define NAND_MFR_FUJITSU 0x04
  1278. #define NAND_MFR_NATIONAL 0x8f
  1279. #define NAND_MFR_RENESAS 0x07
  1280. #define NAND_MFR_STMICRO 0x20
  1281. #define NAND_MFR_HYNIX 0xad
  1282. #define NAND_MFR_MICRON 0x2c
  1283. #define NAND_MFR_AMD 0x01
  1284. #define NAND_MFR_MACRONIX 0xc2
  1285. #define NAND_MFR_EON 0x92
  1286. #define NAND_MFR_SANDISK 0x45
  1287. #define NAND_MFR_INTEL 0x89
  1288. #define NAND_MFR_ATO 0x9b
  1289. #define NAND_MFR_WINBOND 0xef
  1290. /*
  1291. * A helper for defining older NAND chips where the second ID byte fully
  1292. * defined the chip, including the geometry (chip size, eraseblock size, page
  1293. * size). All these chips have 512 bytes NAND page size.
  1294. */
  1295. #define LEGACY_ID_NAND(nm, devid, chipsz, erasesz, opts) \
  1296. { .name = (nm), {{ .dev_id = (devid) }}, .pagesize = 512, \
  1297. .chipsize = (chipsz), .erasesize = (erasesz), .options = (opts) }
  1298. /*
  1299. * A helper for defining newer chips which report their page size and
  1300. * eraseblock size via the extended ID bytes.
  1301. *
  1302. * The real difference between LEGACY_ID_NAND and EXTENDED_ID_NAND is that with
  1303. * EXTENDED_ID_NAND, manufacturers overloaded the same device ID so that the
  1304. * device ID now only represented a particular total chip size (and voltage,
  1305. * buswidth), and the page size, eraseblock size, and OOB size could vary while
  1306. * using the same device ID.
  1307. */
  1308. #define EXTENDED_ID_NAND(nm, devid, chipsz, opts) \
  1309. { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \
  1310. .options = (opts) }
  1311. #define NAND_ECC_INFO(_strength, _step) \
  1312. { .strength_ds = (_strength), .step_ds = (_step) }
  1313. #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds)
  1314. #define NAND_ECC_STEP(type) ((type)->ecc.step_ds)
  1315. /**
  1316. * struct nand_flash_dev - NAND Flash Device ID Structure
  1317. * @name: a human-readable name of the NAND chip
  1318. * @dev_id: the device ID (the second byte of the full chip ID array)
  1319. * @mfr_id: manufecturer ID part of the full chip ID array (refers the same
  1320. * memory address as @id[0])
  1321. * @dev_id: device ID part of the full chip ID array (refers the same memory
  1322. * address as @id[1])
  1323. * @id: full device ID array
  1324. * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as
  1325. * well as the eraseblock size) is determined from the extended NAND
  1326. * chip ID array)
  1327. * @chipsize: total chip size in MiB
  1328. * @erasesize: eraseblock size in bytes (determined from the extended ID if 0)
  1329. * @options: stores various chip bit options
  1330. * @id_len: The valid length of the @id.
  1331. * @oobsize: OOB size
  1332. * @ecc: ECC correctability and step information from the datasheet.
  1333. * @ecc.strength_ds: The ECC correctability from the datasheet, same as the
  1334. * @ecc_strength_ds in nand_chip{}.
  1335. * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the
  1336. * @ecc_step_ds in nand_chip{}, also from the datasheet.
  1337. * For example, the "4bit ECC for each 512Byte" can be set with
  1338. * NAND_ECC_INFO(4, 512).
  1339. * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND
  1340. * reset. Should be deduced from timings described
  1341. * in the datasheet.
  1342. *
  1343. */
  1344. struct nand_flash_dev {
  1345. char *name;
  1346. union {
  1347. struct {
  1348. uint8_t mfr_id;
  1349. uint8_t dev_id;
  1350. };
  1351. uint8_t id[NAND_MAX_ID_LEN];
  1352. };
  1353. unsigned int pagesize;
  1354. unsigned int chipsize;
  1355. unsigned int erasesize;
  1356. unsigned int options;
  1357. uint16_t id_len;
  1358. uint16_t oobsize;
  1359. struct {
  1360. uint16_t strength_ds;
  1361. uint16_t step_ds;
  1362. } ecc;
  1363. int onfi_timing_mode_default;
  1364. };
  1365. /**
  1366. * struct nand_manufacturer - NAND Flash Manufacturer structure
  1367. * @name: Manufacturer name
  1368. * @id: manufacturer ID code of device.
  1369. * @ops: manufacturer operations
  1370. */
  1371. struct nand_manufacturer {
  1372. int id;
  1373. char *name;
  1374. const struct nand_manufacturer_ops *ops;
  1375. };
  1376. const struct nand_manufacturer *nand_get_manufacturer(u8 id);
  1377. static inline const char *
  1378. nand_manufacturer_name(const struct nand_manufacturer *manufacturer)
  1379. {
  1380. return manufacturer ? manufacturer->name : "Unknown";
  1381. }
  1382. extern struct nand_flash_dev nand_flash_ids[];
  1383. extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops;
  1384. extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;
  1385. extern const struct nand_manufacturer_ops hynix_nand_manuf_ops;
  1386. extern const struct nand_manufacturer_ops micron_nand_manuf_ops;
  1387. extern const struct nand_manufacturer_ops amd_nand_manuf_ops;
  1388. extern const struct nand_manufacturer_ops macronix_nand_manuf_ops;
  1389. int nand_create_bbt(struct nand_chip *chip);
  1390. int nand_markbad_bbt(struct nand_chip *chip, loff_t offs);
  1391. int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs);
  1392. int nand_isreserved_bbt(struct nand_chip *chip, loff_t offs);
  1393. int nand_isbad_bbt(struct nand_chip *chip, loff_t offs, int allowbbt);
  1394. int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
  1395. int allowbbt);
  1396. int onfi_fill_data_interface(struct nand_chip *chip,
  1397. enum nand_data_interface_type type,
  1398. int timing_mode);
  1399. /*
  1400. * Check if it is a SLC nand.
  1401. * The !nand_is_slc() can be used to check the MLC/TLC nand chips.
  1402. * We do not distinguish the MLC and TLC now.
  1403. */
  1404. static inline bool nand_is_slc(struct nand_chip *chip)
  1405. {
  1406. WARN(chip->bits_per_cell == 0,
  1407. "chip->bits_per_cell is used uninitialized\n");
  1408. return chip->bits_per_cell == 1;
  1409. }
  1410. /**
  1411. * Check if the opcode's address should be sent only on the lower 8 bits
  1412. * @command: opcode to check
  1413. */
  1414. static inline int nand_opcode_8bits(unsigned int command)
  1415. {
  1416. switch (command) {
  1417. case NAND_CMD_READID:
  1418. case NAND_CMD_PARAM:
  1419. case NAND_CMD_GET_FEATURES:
  1420. case NAND_CMD_SET_FEATURES:
  1421. return 1;
  1422. default:
  1423. break;
  1424. }
  1425. return 0;
  1426. }
  1427. int nand_check_erased_ecc_chunk(void *data, int datalen,
  1428. void *ecc, int ecclen,
  1429. void *extraoob, int extraooblen,
  1430. int threshold);
  1431. int nand_ecc_choose_conf(struct nand_chip *chip,
  1432. const struct nand_ecc_caps *caps, int oobavail);
  1433. /* Default write_oob implementation */
  1434. int nand_write_oob_std(struct nand_chip *chip, int page);
  1435. /* Default write_oob syndrome implementation */
  1436. int nand_write_oob_syndrome(struct nand_chip *chip, int page);
  1437. /* Default read_oob implementation */
  1438. int nand_read_oob_std(struct nand_chip *chip, int page);
  1439. /* Default read_oob syndrome implementation */
  1440. int nand_read_oob_syndrome(struct nand_chip *chip, int page);
  1441. /* Wrapper to use in order for controllers/vendors to GET/SET FEATURES */
  1442. int nand_get_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  1443. int nand_set_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  1444. /* Stub used by drivers that do not support GET/SET FEATURES operations */
  1445. int nand_get_set_features_notsupp(struct nand_chip *chip, int addr,
  1446. u8 *subfeature_param);
  1447. /* Default read_page_raw implementation */
  1448. int nand_read_page_raw(struct nand_chip *chip, uint8_t *buf, int oob_required,
  1449. int page);
  1450. int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf,
  1451. int oob_required, int page);
  1452. /* Default write_page_raw implementation */
  1453. int nand_write_page_raw(struct nand_chip *chip, const uint8_t *buf,
  1454. int oob_required, int page);
  1455. int nand_write_page_raw_notsupp(struct nand_chip *chip, const u8 *buf,
  1456. int oob_required, int page);
  1457. /* Reset and initialize a NAND device */
  1458. int nand_reset(struct nand_chip *chip, int chipnr);
  1459. /* NAND operation helpers */
  1460. int nand_reset_op(struct nand_chip *chip);
  1461. int nand_readid_op(struct nand_chip *chip, u8 addr, void *buf,
  1462. unsigned int len);
  1463. int nand_status_op(struct nand_chip *chip, u8 *status);
  1464. int nand_exit_status_op(struct nand_chip *chip);
  1465. int nand_erase_op(struct nand_chip *chip, unsigned int eraseblock);
  1466. int nand_read_page_op(struct nand_chip *chip, unsigned int page,
  1467. unsigned int offset_in_page, void *buf, unsigned int len);
  1468. int nand_change_read_column_op(struct nand_chip *chip,
  1469. unsigned int offset_in_page, void *buf,
  1470. unsigned int len, bool force_8bit);
  1471. int nand_read_oob_op(struct nand_chip *chip, unsigned int page,
  1472. unsigned int offset_in_page, void *buf, unsigned int len);
  1473. int nand_prog_page_begin_op(struct nand_chip *chip, unsigned int page,
  1474. unsigned int offset_in_page, const void *buf,
  1475. unsigned int len);
  1476. int nand_prog_page_end_op(struct nand_chip *chip);
  1477. int nand_prog_page_op(struct nand_chip *chip, unsigned int page,
  1478. unsigned int offset_in_page, const void *buf,
  1479. unsigned int len);
  1480. int nand_change_write_column_op(struct nand_chip *chip,
  1481. unsigned int offset_in_page, const void *buf,
  1482. unsigned int len, bool force_8bit);
  1483. int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
  1484. bool force_8bit);
  1485. int nand_write_data_op(struct nand_chip *chip, const void *buf,
  1486. unsigned int len, bool force_8bit);
  1487. /* Scan and identify a NAND device */
  1488. int nand_scan_with_ids(struct nand_chip *chip, unsigned int max_chips,
  1489. struct nand_flash_dev *ids);
  1490. static inline int nand_scan(struct nand_chip *chip, unsigned int max_chips)
  1491. {
  1492. return nand_scan_with_ids(chip, max_chips, NULL);
  1493. }
  1494. /* Internal helper for board drivers which need to override command function */
  1495. void nand_wait_ready(struct nand_chip *chip);
  1496. /*
  1497. * Free resources held by the NAND device, must be called on error after a
  1498. * sucessful nand_scan().
  1499. */
  1500. void nand_cleanup(struct nand_chip *chip);
  1501. /* Unregister the MTD device and calls nand_cleanup() */
  1502. void nand_release(struct nand_chip *chip);
  1503. /* Default extended ID decoding function */
  1504. void nand_decode_ext_id(struct nand_chip *chip);
  1505. /*
  1506. * External helper for controller drivers that have to implement the WAITRDY
  1507. * instruction and have no physical pin to check it.
  1508. */
  1509. int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms);
  1510. #endif /* __LINUX_MTD_RAWNAND_H */