rawnand.h 55 KB

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