rawnand.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  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, unsigned int max_chips,
  29. struct nand_flash_dev *ids);
  30. static inline int nand_scan(struct nand_chip *chip, unsigned 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 ->legacy.cmd_ctrl() and is relying
  173. * on the default ->cmdfunc() implementation, you may want to let the core
  174. * handle the tCCS delay which is required when a column change (RNDIN or
  175. * RNDOUT) is 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 nand_chip *chip, uint8_t *buf,
  581. int oob_required, int page);
  582. int (*write_page_raw)(struct nand_chip *chip, const uint8_t *buf,
  583. int oob_required, int page);
  584. int (*read_page)(struct nand_chip *chip, uint8_t *buf,
  585. int oob_required, int page);
  586. int (*read_subpage)(struct nand_chip *chip, uint32_t offs,
  587. uint32_t len, uint8_t *buf, int page);
  588. int (*write_subpage)(struct nand_chip *chip, uint32_t offset,
  589. uint32_t data_len, const uint8_t *data_buf,
  590. int oob_required, int page);
  591. int (*write_page)(struct nand_chip *chip, const uint8_t *buf,
  592. int oob_required, int page);
  593. int (*write_oob_raw)(struct nand_chip *chip, int page);
  594. int (*read_oob_raw)(struct nand_chip *chip, int page);
  595. int (*read_oob)(struct nand_chip *chip, int page);
  596. int (*write_oob)(struct nand_chip *chip, int page);
  597. };
  598. /**
  599. * struct nand_sdr_timings - SDR NAND chip timings
  600. *
  601. * This struct defines the timing requirements of a SDR NAND chip.
  602. * These information can be found in every NAND datasheets and the timings
  603. * meaning are described in the ONFI specifications:
  604. * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing
  605. * Parameters)
  606. *
  607. * All these timings are expressed in picoseconds.
  608. *
  609. * @tBERS_max: Block erase time
  610. * @tCCS_min: Change column setup time
  611. * @tPROG_max: Page program time
  612. * @tR_max: Page read time
  613. * @tALH_min: ALE hold time
  614. * @tADL_min: ALE to data loading time
  615. * @tALS_min: ALE setup time
  616. * @tAR_min: ALE to RE# delay
  617. * @tCEA_max: CE# access time
  618. * @tCEH_min: CE# high hold time
  619. * @tCH_min: CE# hold time
  620. * @tCHZ_max: CE# high to output hi-Z
  621. * @tCLH_min: CLE hold time
  622. * @tCLR_min: CLE to RE# delay
  623. * @tCLS_min: CLE setup time
  624. * @tCOH_min: CE# high to output hold
  625. * @tCS_min: CE# setup time
  626. * @tDH_min: Data hold time
  627. * @tDS_min: Data setup time
  628. * @tFEAT_max: Busy time for Set Features and Get Features
  629. * @tIR_min: Output hi-Z to RE# low
  630. * @tITC_max: Interface and Timing Mode Change time
  631. * @tRC_min: RE# cycle time
  632. * @tREA_max: RE# access time
  633. * @tREH_min: RE# high hold time
  634. * @tRHOH_min: RE# high to output hold
  635. * @tRHW_min: RE# high to WE# low
  636. * @tRHZ_max: RE# high to output hi-Z
  637. * @tRLOH_min: RE# low to output hold
  638. * @tRP_min: RE# pulse width
  639. * @tRR_min: Ready to RE# low (data only)
  640. * @tRST_max: Device reset time, measured from the falling edge of R/B# to the
  641. * rising edge of R/B#.
  642. * @tWB_max: WE# high to SR[6] low
  643. * @tWC_min: WE# cycle time
  644. * @tWH_min: WE# high hold time
  645. * @tWHR_min: WE# high to RE# low
  646. * @tWP_min: WE# pulse width
  647. * @tWW_min: WP# transition to WE# low
  648. */
  649. struct nand_sdr_timings {
  650. u64 tBERS_max;
  651. u32 tCCS_min;
  652. u64 tPROG_max;
  653. u64 tR_max;
  654. u32 tALH_min;
  655. u32 tADL_min;
  656. u32 tALS_min;
  657. u32 tAR_min;
  658. u32 tCEA_max;
  659. u32 tCEH_min;
  660. u32 tCH_min;
  661. u32 tCHZ_max;
  662. u32 tCLH_min;
  663. u32 tCLR_min;
  664. u32 tCLS_min;
  665. u32 tCOH_min;
  666. u32 tCS_min;
  667. u32 tDH_min;
  668. u32 tDS_min;
  669. u32 tFEAT_max;
  670. u32 tIR_min;
  671. u32 tITC_max;
  672. u32 tRC_min;
  673. u32 tREA_max;
  674. u32 tREH_min;
  675. u32 tRHOH_min;
  676. u32 tRHW_min;
  677. u32 tRHZ_max;
  678. u32 tRLOH_min;
  679. u32 tRP_min;
  680. u32 tRR_min;
  681. u64 tRST_max;
  682. u32 tWB_max;
  683. u32 tWC_min;
  684. u32 tWH_min;
  685. u32 tWHR_min;
  686. u32 tWP_min;
  687. u32 tWW_min;
  688. };
  689. /**
  690. * enum nand_data_interface_type - NAND interface timing type
  691. * @NAND_SDR_IFACE: Single Data Rate interface
  692. */
  693. enum nand_data_interface_type {
  694. NAND_SDR_IFACE,
  695. };
  696. /**
  697. * struct nand_data_interface - NAND interface timing
  698. * @type: type of the timing
  699. * @timings: The timing, type according to @type
  700. * @timings.sdr: Use it when @type is %NAND_SDR_IFACE.
  701. */
  702. struct nand_data_interface {
  703. enum nand_data_interface_type type;
  704. union {
  705. struct nand_sdr_timings sdr;
  706. } timings;
  707. };
  708. /**
  709. * nand_get_sdr_timings - get SDR timing from data interface
  710. * @conf: The data interface
  711. */
  712. static inline const struct nand_sdr_timings *
  713. nand_get_sdr_timings(const struct nand_data_interface *conf)
  714. {
  715. if (conf->type != NAND_SDR_IFACE)
  716. return ERR_PTR(-EINVAL);
  717. return &conf->timings.sdr;
  718. }
  719. /**
  720. * struct nand_manufacturer_ops - NAND Manufacturer operations
  721. * @detect: detect the NAND memory organization and capabilities
  722. * @init: initialize all vendor specific fields (like the ->read_retry()
  723. * implementation) if any.
  724. * @cleanup: the ->init() function may have allocated resources, ->cleanup()
  725. * is here to let vendor specific code release those resources.
  726. * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI parameter
  727. * page. This is called after the checksum is verified.
  728. */
  729. struct nand_manufacturer_ops {
  730. void (*detect)(struct nand_chip *chip);
  731. int (*init)(struct nand_chip *chip);
  732. void (*cleanup)(struct nand_chip *chip);
  733. void (*fixup_onfi_param_page)(struct nand_chip *chip,
  734. struct nand_onfi_params *p);
  735. };
  736. /**
  737. * struct nand_op_cmd_instr - Definition of a command instruction
  738. * @opcode: the command to issue in one cycle
  739. */
  740. struct nand_op_cmd_instr {
  741. u8 opcode;
  742. };
  743. /**
  744. * struct nand_op_addr_instr - Definition of an address instruction
  745. * @naddrs: length of the @addrs array
  746. * @addrs: array containing the address cycles to issue
  747. */
  748. struct nand_op_addr_instr {
  749. unsigned int naddrs;
  750. const u8 *addrs;
  751. };
  752. /**
  753. * struct nand_op_data_instr - Definition of a data instruction
  754. * @len: number of data bytes to move
  755. * @buf: buffer to fill
  756. * @buf.in: buffer to fill when reading from the NAND chip
  757. * @buf.out: buffer to read from when writing to the NAND chip
  758. * @force_8bit: force 8-bit access
  759. *
  760. * Please note that "in" and "out" are inverted from the ONFI specification
  761. * and are from the controller perspective, so a "in" is a read from the NAND
  762. * chip while a "out" is a write to the NAND chip.
  763. */
  764. struct nand_op_data_instr {
  765. unsigned int len;
  766. union {
  767. void *in;
  768. const void *out;
  769. } buf;
  770. bool force_8bit;
  771. };
  772. /**
  773. * struct nand_op_waitrdy_instr - Definition of a wait ready instruction
  774. * @timeout_ms: maximum delay while waiting for the ready/busy pin in ms
  775. */
  776. struct nand_op_waitrdy_instr {
  777. unsigned int timeout_ms;
  778. };
  779. /**
  780. * enum nand_op_instr_type - Definition of all instruction types
  781. * @NAND_OP_CMD_INSTR: command instruction
  782. * @NAND_OP_ADDR_INSTR: address instruction
  783. * @NAND_OP_DATA_IN_INSTR: data in instruction
  784. * @NAND_OP_DATA_OUT_INSTR: data out instruction
  785. * @NAND_OP_WAITRDY_INSTR: wait ready instruction
  786. */
  787. enum nand_op_instr_type {
  788. NAND_OP_CMD_INSTR,
  789. NAND_OP_ADDR_INSTR,
  790. NAND_OP_DATA_IN_INSTR,
  791. NAND_OP_DATA_OUT_INSTR,
  792. NAND_OP_WAITRDY_INSTR,
  793. };
  794. /**
  795. * struct nand_op_instr - Instruction object
  796. * @type: the instruction type
  797. * @ctx: extra data associated to the instruction. You'll have to use the
  798. * appropriate element depending on @type
  799. * @ctx.cmd: use it if @type is %NAND_OP_CMD_INSTR
  800. * @ctx.addr: use it if @type is %NAND_OP_ADDR_INSTR
  801. * @ctx.data: use it if @type is %NAND_OP_DATA_IN_INSTR
  802. * or %NAND_OP_DATA_OUT_INSTR
  803. * @ctx.waitrdy: use it if @type is %NAND_OP_WAITRDY_INSTR
  804. * @delay_ns: delay the controller should apply after the instruction has been
  805. * issued on the bus. Most modern controllers have internal timings
  806. * control logic, and in this case, the controller driver can ignore
  807. * this field.
  808. */
  809. struct nand_op_instr {
  810. enum nand_op_instr_type type;
  811. union {
  812. struct nand_op_cmd_instr cmd;
  813. struct nand_op_addr_instr addr;
  814. struct nand_op_data_instr data;
  815. struct nand_op_waitrdy_instr waitrdy;
  816. } ctx;
  817. unsigned int delay_ns;
  818. };
  819. /*
  820. * Special handling must be done for the WAITRDY timeout parameter as it usually
  821. * is either tPROG (after a prog), tR (before a read), tRST (during a reset) or
  822. * tBERS (during an erase) which all of them are u64 values that cannot be
  823. * divided by usual kernel macros and must be handled with the special
  824. * DIV_ROUND_UP_ULL() macro.
  825. *
  826. * Cast to type of dividend is needed here to guarantee that the result won't
  827. * be an unsigned long long when the dividend is an unsigned long (or smaller),
  828. * which is what the compiler does when it sees ternary operator with 2
  829. * different return types (picks the largest type to make sure there's no
  830. * loss).
  831. */
  832. #define __DIVIDE(dividend, divisor) ({ \
  833. (__typeof__(dividend))(sizeof(dividend) <= sizeof(unsigned long) ? \
  834. DIV_ROUND_UP(dividend, divisor) : \
  835. DIV_ROUND_UP_ULL(dividend, divisor)); \
  836. })
  837. #define PSEC_TO_NSEC(x) __DIVIDE(x, 1000)
  838. #define PSEC_TO_MSEC(x) __DIVIDE(x, 1000000000)
  839. #define NAND_OP_CMD(id, ns) \
  840. { \
  841. .type = NAND_OP_CMD_INSTR, \
  842. .ctx.cmd.opcode = id, \
  843. .delay_ns = ns, \
  844. }
  845. #define NAND_OP_ADDR(ncycles, cycles, ns) \
  846. { \
  847. .type = NAND_OP_ADDR_INSTR, \
  848. .ctx.addr = { \
  849. .naddrs = ncycles, \
  850. .addrs = cycles, \
  851. }, \
  852. .delay_ns = ns, \
  853. }
  854. #define NAND_OP_DATA_IN(l, b, ns) \
  855. { \
  856. .type = NAND_OP_DATA_IN_INSTR, \
  857. .ctx.data = { \
  858. .len = l, \
  859. .buf.in = b, \
  860. .force_8bit = false, \
  861. }, \
  862. .delay_ns = ns, \
  863. }
  864. #define NAND_OP_DATA_OUT(l, b, ns) \
  865. { \
  866. .type = NAND_OP_DATA_OUT_INSTR, \
  867. .ctx.data = { \
  868. .len = l, \
  869. .buf.out = b, \
  870. .force_8bit = false, \
  871. }, \
  872. .delay_ns = ns, \
  873. }
  874. #define NAND_OP_8BIT_DATA_IN(l, b, ns) \
  875. { \
  876. .type = NAND_OP_DATA_IN_INSTR, \
  877. .ctx.data = { \
  878. .len = l, \
  879. .buf.in = b, \
  880. .force_8bit = true, \
  881. }, \
  882. .delay_ns = ns, \
  883. }
  884. #define NAND_OP_8BIT_DATA_OUT(l, b, ns) \
  885. { \
  886. .type = NAND_OP_DATA_OUT_INSTR, \
  887. .ctx.data = { \
  888. .len = l, \
  889. .buf.out = b, \
  890. .force_8bit = true, \
  891. }, \
  892. .delay_ns = ns, \
  893. }
  894. #define NAND_OP_WAIT_RDY(tout_ms, ns) \
  895. { \
  896. .type = NAND_OP_WAITRDY_INSTR, \
  897. .ctx.waitrdy.timeout_ms = tout_ms, \
  898. .delay_ns = ns, \
  899. }
  900. /**
  901. * struct nand_subop - a sub operation
  902. * @instrs: array of instructions
  903. * @ninstrs: length of the @instrs array
  904. * @first_instr_start_off: offset to start from for the first instruction
  905. * of the sub-operation
  906. * @last_instr_end_off: offset to end at (excluded) for the last instruction
  907. * of the sub-operation
  908. *
  909. * Both @first_instr_start_off and @last_instr_end_off only apply to data or
  910. * address instructions.
  911. *
  912. * When an operation cannot be handled as is by the NAND controller, it will
  913. * be split by the parser into sub-operations which will be passed to the
  914. * controller driver.
  915. */
  916. struct nand_subop {
  917. const struct nand_op_instr *instrs;
  918. unsigned int ninstrs;
  919. unsigned int first_instr_start_off;
  920. unsigned int last_instr_end_off;
  921. };
  922. unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
  923. unsigned int op_id);
  924. unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
  925. unsigned int op_id);
  926. unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
  927. unsigned int op_id);
  928. unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
  929. unsigned int op_id);
  930. /**
  931. * struct nand_op_parser_addr_constraints - Constraints for address instructions
  932. * @maxcycles: maximum number of address cycles the controller can issue in a
  933. * single step
  934. */
  935. struct nand_op_parser_addr_constraints {
  936. unsigned int maxcycles;
  937. };
  938. /**
  939. * struct nand_op_parser_data_constraints - Constraints for data instructions
  940. * @maxlen: maximum data length that the controller can handle in a single step
  941. */
  942. struct nand_op_parser_data_constraints {
  943. unsigned int maxlen;
  944. };
  945. /**
  946. * struct nand_op_parser_pattern_elem - One element of a pattern
  947. * @type: the instructuction type
  948. * @optional: whether this element of the pattern is optional or mandatory
  949. * @ctx: address or data constraint
  950. * @ctx.addr: address constraint (number of cycles)
  951. * @ctx.data: data constraint (data length)
  952. */
  953. struct nand_op_parser_pattern_elem {
  954. enum nand_op_instr_type type;
  955. bool optional;
  956. union {
  957. struct nand_op_parser_addr_constraints addr;
  958. struct nand_op_parser_data_constraints data;
  959. } ctx;
  960. };
  961. #define NAND_OP_PARSER_PAT_CMD_ELEM(_opt) \
  962. { \
  963. .type = NAND_OP_CMD_INSTR, \
  964. .optional = _opt, \
  965. }
  966. #define NAND_OP_PARSER_PAT_ADDR_ELEM(_opt, _maxcycles) \
  967. { \
  968. .type = NAND_OP_ADDR_INSTR, \
  969. .optional = _opt, \
  970. .ctx.addr.maxcycles = _maxcycles, \
  971. }
  972. #define NAND_OP_PARSER_PAT_DATA_IN_ELEM(_opt, _maxlen) \
  973. { \
  974. .type = NAND_OP_DATA_IN_INSTR, \
  975. .optional = _opt, \
  976. .ctx.data.maxlen = _maxlen, \
  977. }
  978. #define NAND_OP_PARSER_PAT_DATA_OUT_ELEM(_opt, _maxlen) \
  979. { \
  980. .type = NAND_OP_DATA_OUT_INSTR, \
  981. .optional = _opt, \
  982. .ctx.data.maxlen = _maxlen, \
  983. }
  984. #define NAND_OP_PARSER_PAT_WAITRDY_ELEM(_opt) \
  985. { \
  986. .type = NAND_OP_WAITRDY_INSTR, \
  987. .optional = _opt, \
  988. }
  989. /**
  990. * struct nand_op_parser_pattern - NAND sub-operation pattern descriptor
  991. * @elems: array of pattern elements
  992. * @nelems: number of pattern elements in @elems array
  993. * @exec: the function that will issue a sub-operation
  994. *
  995. * A pattern is a list of elements, each element reprensenting one instruction
  996. * with its constraints. The pattern itself is used by the core to match NAND
  997. * chip operation with NAND controller operations.
  998. * Once a match between a NAND controller operation pattern and a NAND chip
  999. * operation (or a sub-set of a NAND operation) is found, the pattern ->exec()
  1000. * hook is called so that the controller driver can issue the operation on the
  1001. * bus.
  1002. *
  1003. * Controller drivers should declare as many patterns as they support and pass
  1004. * this list of patterns (created with the help of the following macro) to
  1005. * the nand_op_parser_exec_op() helper.
  1006. */
  1007. struct nand_op_parser_pattern {
  1008. const struct nand_op_parser_pattern_elem *elems;
  1009. unsigned int nelems;
  1010. int (*exec)(struct nand_chip *chip, const struct nand_subop *subop);
  1011. };
  1012. #define NAND_OP_PARSER_PATTERN(_exec, ...) \
  1013. { \
  1014. .exec = _exec, \
  1015. .elems = (struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }, \
  1016. .nelems = sizeof((struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }) / \
  1017. sizeof(struct nand_op_parser_pattern_elem), \
  1018. }
  1019. /**
  1020. * struct nand_op_parser - NAND controller operation parser descriptor
  1021. * @patterns: array of supported patterns
  1022. * @npatterns: length of the @patterns array
  1023. *
  1024. * The parser descriptor is just an array of supported patterns which will be
  1025. * iterated by nand_op_parser_exec_op() everytime it tries to execute an
  1026. * NAND operation (or tries to determine if a specific operation is supported).
  1027. *
  1028. * It is worth mentioning that patterns will be tested in their declaration
  1029. * order, and the first match will be taken, so it's important to order patterns
  1030. * appropriately so that simple/inefficient patterns are placed at the end of
  1031. * the list. Usually, this is where you put single instruction patterns.
  1032. */
  1033. struct nand_op_parser {
  1034. const struct nand_op_parser_pattern *patterns;
  1035. unsigned int npatterns;
  1036. };
  1037. #define NAND_OP_PARSER(...) \
  1038. { \
  1039. .patterns = (struct nand_op_parser_pattern[]) { __VA_ARGS__ }, \
  1040. .npatterns = sizeof((struct nand_op_parser_pattern[]) { __VA_ARGS__ }) / \
  1041. sizeof(struct nand_op_parser_pattern), \
  1042. }
  1043. /**
  1044. * struct nand_operation - NAND operation descriptor
  1045. * @instrs: array of instructions to execute
  1046. * @ninstrs: length of the @instrs array
  1047. *
  1048. * The actual operation structure that will be passed to chip->exec_op().
  1049. */
  1050. struct nand_operation {
  1051. const struct nand_op_instr *instrs;
  1052. unsigned int ninstrs;
  1053. };
  1054. #define NAND_OPERATION(_instrs) \
  1055. { \
  1056. .instrs = _instrs, \
  1057. .ninstrs = ARRAY_SIZE(_instrs), \
  1058. }
  1059. int nand_op_parser_exec_op(struct nand_chip *chip,
  1060. const struct nand_op_parser *parser,
  1061. const struct nand_operation *op, bool check_only);
  1062. /**
  1063. * struct nand_legacy - NAND chip legacy fields/hooks
  1064. * @IO_ADDR_R: address to read the 8 I/O lines of the flash device
  1065. * @IO_ADDR_W: address to write the 8 I/O lines of the flash device
  1066. * @read_byte: read one byte from the chip
  1067. * @write_byte: write a single byte to the chip on the low 8 I/O lines
  1068. * @write_buf: write data from the buffer to the chip
  1069. * @read_buf: read data from the chip into the buffer
  1070. * @cmd_ctrl: hardware specific function for controlling ALE/CLE/nCE. Also used
  1071. * to write command and address
  1072. * @cmdfunc: hardware specific function for writing commands to the chip.
  1073. * @dev_ready: hardware specific function for accessing device ready/busy line.
  1074. * If set to NULL no access to ready/busy is available and the
  1075. * ready/busy information is read from the chip status register.
  1076. * @waitfunc: hardware specific function for wait on ready.
  1077. * @block_bad: check if a block is bad, using OOB markers
  1078. * @block_markbad: mark a block bad
  1079. * @erase: erase function
  1080. * @set_features: set the NAND chip features
  1081. * @get_features: get the NAND chip features
  1082. *
  1083. * If you look at this structure you're already wrong. These fields/hooks are
  1084. * all deprecated.
  1085. */
  1086. struct nand_legacy {
  1087. void __iomem *IO_ADDR_R;
  1088. void __iomem *IO_ADDR_W;
  1089. u8 (*read_byte)(struct nand_chip *chip);
  1090. void (*write_byte)(struct nand_chip *chip, u8 byte);
  1091. void (*write_buf)(struct nand_chip *chip, const u8 *buf, int len);
  1092. void (*read_buf)(struct nand_chip *chip, u8 *buf, int len);
  1093. void (*cmd_ctrl)(struct nand_chip *chip, int dat, unsigned int ctrl);
  1094. void (*cmdfunc)(struct nand_chip *chip, unsigned command, int column,
  1095. int page_addr);
  1096. int (*dev_ready)(struct nand_chip *chip);
  1097. int (*waitfunc)(struct nand_chip *chip);
  1098. int (*block_bad)(struct nand_chip *chip, loff_t ofs);
  1099. int (*block_markbad)(struct nand_chip *chip, loff_t ofs);
  1100. int (*erase)(struct nand_chip *chip, int page);
  1101. int (*set_features)(struct nand_chip *chip, int feature_addr,
  1102. u8 *subfeature_para);
  1103. int (*get_features)(struct nand_chip *chip, int feature_addr,
  1104. u8 *subfeature_para);
  1105. };
  1106. /**
  1107. * struct nand_chip - NAND Private Flash Chip Data
  1108. * @mtd: MTD device registered to the MTD framework
  1109. * @legacy: All legacy fields/hooks. If you develop a new driver,
  1110. * don't even try to use any of these fields/hooks, and if
  1111. * you're modifying an existing driver that is using those
  1112. * fields/hooks, you should consider reworking the driver
  1113. * avoid using them.
  1114. * @select_chip: [REPLACEABLE] select chip nr
  1115. * @exec_op: controller specific method to execute NAND operations.
  1116. * This method replaces ->cmdfunc(),
  1117. * ->legacy.{read,write}_{buf,byte,word}(),
  1118. * ->legacy.dev_ready() and ->waifunc().
  1119. * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for
  1120. * setting the read-retry mode. Mostly needed for MLC NAND.
  1121. * @ecc: [BOARDSPECIFIC] ECC control structure
  1122. * @buf_align: minimum buffer alignment required by a platform
  1123. * @dummy_controller: dummy controller implementation for drivers that can
  1124. * only control a single chip
  1125. * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring
  1126. * data from array to read regs (tR).
  1127. * @state: [INTERN] the current state of the NAND device
  1128. * @oob_poi: "poison value buffer," used for laying out OOB data
  1129. * before writing
  1130. * @page_shift: [INTERN] number of address bits in a page (column
  1131. * address bits).
  1132. * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
  1133. * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
  1134. * @chip_shift: [INTERN] number of address bits in one chip
  1135. * @options: [BOARDSPECIFIC] various chip options. They can partly
  1136. * be set to inform nand_scan about special functionality.
  1137. * See the defines for further explanation.
  1138. * @bbt_options: [INTERN] bad block specific options. All options used
  1139. * here must come from bbm.h. By default, these options
  1140. * will be copied to the appropriate nand_bbt_descr's.
  1141. * @badblockpos: [INTERN] position of the bad block marker in the oob
  1142. * area.
  1143. * @badblockbits: [INTERN] minimum number of set bits in a good block's
  1144. * bad block marker position; i.e., BBM == 11110111b is
  1145. * not bad when badblockbits == 7
  1146. * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC.
  1147. * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet.
  1148. * Minimum amount of bit errors per @ecc_step_ds guaranteed
  1149. * to be correctable. If unknown, set to zero.
  1150. * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds,
  1151. * also from the datasheet. It is the recommended ECC step
  1152. * size, if known; if unknown, set to zero.
  1153. * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is
  1154. * set to the actually used ONFI mode if the chip is
  1155. * ONFI compliant or deduced from the datasheet if
  1156. * the NAND chip is not ONFI compliant.
  1157. * @numchips: [INTERN] number of physical chips
  1158. * @chipsize: [INTERN] the size of one chip for multichip arrays
  1159. * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
  1160. * @data_buf: [INTERN] buffer for data, size is (page size + oobsize).
  1161. * @pagebuf: [INTERN] holds the pagenumber which is currently in
  1162. * data_buf.
  1163. * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is
  1164. * currently in data_buf.
  1165. * @subpagesize: [INTERN] holds the subpagesize
  1166. * @id: [INTERN] holds NAND ID
  1167. * @parameters: [INTERN] holds generic parameters under an easily
  1168. * readable form.
  1169. * @max_bb_per_die: [INTERN] the max number of bad blocks each die of a
  1170. * this nand device will encounter their life times.
  1171. * @blocks_per_die: [INTERN] The number of PEBs in a die
  1172. * @data_interface: [INTERN] NAND interface timing information
  1173. * @read_retries: [INTERN] the number of read retry modes supported
  1174. * @setup_data_interface: [OPTIONAL] setup the data interface and timing. If
  1175. * chipnr is set to %NAND_DATA_IFACE_CHECK_ONLY this
  1176. * means the configuration should not be applied but
  1177. * only checked.
  1178. * @bbt: [INTERN] bad block table pointer
  1179. * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
  1180. * lookup.
  1181. * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
  1182. * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial
  1183. * bad block scan.
  1184. * @controller: [REPLACEABLE] a pointer to a hardware controller
  1185. * structure which is shared among multiple independent
  1186. * devices.
  1187. * @priv: [OPTIONAL] pointer to private chip data
  1188. * @manufacturer: [INTERN] Contains manufacturer information
  1189. * @manufacturer.desc: [INTERN] Contains manufacturer's description
  1190. * @manufacturer.priv: [INTERN] Contains manufacturer private information
  1191. */
  1192. struct nand_chip {
  1193. struct mtd_info mtd;
  1194. struct nand_legacy legacy;
  1195. void (*select_chip)(struct nand_chip *chip, int cs);
  1196. int (*exec_op)(struct nand_chip *chip,
  1197. const struct nand_operation *op,
  1198. bool check_only);
  1199. int (*setup_read_retry)(struct nand_chip *chip, int retry_mode);
  1200. int (*setup_data_interface)(struct nand_chip *chip, int chipnr,
  1201. const struct nand_data_interface *conf);
  1202. int chip_delay;
  1203. unsigned int options;
  1204. unsigned int bbt_options;
  1205. int page_shift;
  1206. int phys_erase_shift;
  1207. int bbt_erase_shift;
  1208. int chip_shift;
  1209. int numchips;
  1210. uint64_t chipsize;
  1211. int pagemask;
  1212. u8 *data_buf;
  1213. int pagebuf;
  1214. unsigned int pagebuf_bitflips;
  1215. int subpagesize;
  1216. uint8_t bits_per_cell;
  1217. uint16_t ecc_strength_ds;
  1218. uint16_t ecc_step_ds;
  1219. int onfi_timing_mode_default;
  1220. int badblockpos;
  1221. int badblockbits;
  1222. struct nand_id id;
  1223. struct nand_parameters parameters;
  1224. u16 max_bb_per_die;
  1225. u32 blocks_per_die;
  1226. struct nand_data_interface data_interface;
  1227. int read_retries;
  1228. flstate_t state;
  1229. uint8_t *oob_poi;
  1230. struct nand_controller *controller;
  1231. struct nand_ecc_ctrl ecc;
  1232. unsigned long buf_align;
  1233. struct nand_controller dummy_controller;
  1234. uint8_t *bbt;
  1235. struct nand_bbt_descr *bbt_td;
  1236. struct nand_bbt_descr *bbt_md;
  1237. struct nand_bbt_descr *badblock_pattern;
  1238. void *priv;
  1239. struct {
  1240. const struct nand_manufacturer *desc;
  1241. void *priv;
  1242. } manufacturer;
  1243. };
  1244. static inline int nand_exec_op(struct nand_chip *chip,
  1245. const struct nand_operation *op)
  1246. {
  1247. if (!chip->exec_op)
  1248. return -ENOTSUPP;
  1249. return chip->exec_op(chip, op, false);
  1250. }
  1251. extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
  1252. extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
  1253. static inline void nand_set_flash_node(struct nand_chip *chip,
  1254. struct device_node *np)
  1255. {
  1256. mtd_set_of_node(&chip->mtd, np);
  1257. }
  1258. static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
  1259. {
  1260. return mtd_get_of_node(&chip->mtd);
  1261. }
  1262. static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
  1263. {
  1264. return container_of(mtd, struct nand_chip, mtd);
  1265. }
  1266. static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
  1267. {
  1268. return &chip->mtd;
  1269. }
  1270. static inline void *nand_get_controller_data(struct nand_chip *chip)
  1271. {
  1272. return chip->priv;
  1273. }
  1274. static inline void nand_set_controller_data(struct nand_chip *chip, void *priv)
  1275. {
  1276. chip->priv = priv;
  1277. }
  1278. static inline void nand_set_manufacturer_data(struct nand_chip *chip,
  1279. void *priv)
  1280. {
  1281. chip->manufacturer.priv = priv;
  1282. }
  1283. static inline void *nand_get_manufacturer_data(struct nand_chip *chip)
  1284. {
  1285. return chip->manufacturer.priv;
  1286. }
  1287. /*
  1288. * NAND Flash Manufacturer ID Codes
  1289. */
  1290. #define NAND_MFR_TOSHIBA 0x98
  1291. #define NAND_MFR_ESMT 0xc8
  1292. #define NAND_MFR_SAMSUNG 0xec
  1293. #define NAND_MFR_FUJITSU 0x04
  1294. #define NAND_MFR_NATIONAL 0x8f
  1295. #define NAND_MFR_RENESAS 0x07
  1296. #define NAND_MFR_STMICRO 0x20
  1297. #define NAND_MFR_HYNIX 0xad
  1298. #define NAND_MFR_MICRON 0x2c
  1299. #define NAND_MFR_AMD 0x01
  1300. #define NAND_MFR_MACRONIX 0xc2
  1301. #define NAND_MFR_EON 0x92
  1302. #define NAND_MFR_SANDISK 0x45
  1303. #define NAND_MFR_INTEL 0x89
  1304. #define NAND_MFR_ATO 0x9b
  1305. #define NAND_MFR_WINBOND 0xef
  1306. /*
  1307. * A helper for defining older NAND chips where the second ID byte fully
  1308. * defined the chip, including the geometry (chip size, eraseblock size, page
  1309. * size). All these chips have 512 bytes NAND page size.
  1310. */
  1311. #define LEGACY_ID_NAND(nm, devid, chipsz, erasesz, opts) \
  1312. { .name = (nm), {{ .dev_id = (devid) }}, .pagesize = 512, \
  1313. .chipsize = (chipsz), .erasesize = (erasesz), .options = (opts) }
  1314. /*
  1315. * A helper for defining newer chips which report their page size and
  1316. * eraseblock size via the extended ID bytes.
  1317. *
  1318. * The real difference between LEGACY_ID_NAND and EXTENDED_ID_NAND is that with
  1319. * EXTENDED_ID_NAND, manufacturers overloaded the same device ID so that the
  1320. * device ID now only represented a particular total chip size (and voltage,
  1321. * buswidth), and the page size, eraseblock size, and OOB size could vary while
  1322. * using the same device ID.
  1323. */
  1324. #define EXTENDED_ID_NAND(nm, devid, chipsz, opts) \
  1325. { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \
  1326. .options = (opts) }
  1327. #define NAND_ECC_INFO(_strength, _step) \
  1328. { .strength_ds = (_strength), .step_ds = (_step) }
  1329. #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds)
  1330. #define NAND_ECC_STEP(type) ((type)->ecc.step_ds)
  1331. /**
  1332. * struct nand_flash_dev - NAND Flash Device ID Structure
  1333. * @name: a human-readable name of the NAND chip
  1334. * @dev_id: the device ID (the second byte of the full chip ID array)
  1335. * @mfr_id: manufecturer ID part of the full chip ID array (refers the same
  1336. * memory address as @id[0])
  1337. * @dev_id: device ID part of the full chip ID array (refers the same memory
  1338. * address as @id[1])
  1339. * @id: full device ID array
  1340. * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as
  1341. * well as the eraseblock size) is determined from the extended NAND
  1342. * chip ID array)
  1343. * @chipsize: total chip size in MiB
  1344. * @erasesize: eraseblock size in bytes (determined from the extended ID if 0)
  1345. * @options: stores various chip bit options
  1346. * @id_len: The valid length of the @id.
  1347. * @oobsize: OOB size
  1348. * @ecc: ECC correctability and step information from the datasheet.
  1349. * @ecc.strength_ds: The ECC correctability from the datasheet, same as the
  1350. * @ecc_strength_ds in nand_chip{}.
  1351. * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the
  1352. * @ecc_step_ds in nand_chip{}, also from the datasheet.
  1353. * For example, the "4bit ECC for each 512Byte" can be set with
  1354. * NAND_ECC_INFO(4, 512).
  1355. * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND
  1356. * reset. Should be deduced from timings described
  1357. * in the datasheet.
  1358. *
  1359. */
  1360. struct nand_flash_dev {
  1361. char *name;
  1362. union {
  1363. struct {
  1364. uint8_t mfr_id;
  1365. uint8_t dev_id;
  1366. };
  1367. uint8_t id[NAND_MAX_ID_LEN];
  1368. };
  1369. unsigned int pagesize;
  1370. unsigned int chipsize;
  1371. unsigned int erasesize;
  1372. unsigned int options;
  1373. uint16_t id_len;
  1374. uint16_t oobsize;
  1375. struct {
  1376. uint16_t strength_ds;
  1377. uint16_t step_ds;
  1378. } ecc;
  1379. int onfi_timing_mode_default;
  1380. };
  1381. /**
  1382. * struct nand_manufacturer - NAND Flash Manufacturer structure
  1383. * @name: Manufacturer name
  1384. * @id: manufacturer ID code of device.
  1385. * @ops: manufacturer operations
  1386. */
  1387. struct nand_manufacturer {
  1388. int id;
  1389. char *name;
  1390. const struct nand_manufacturer_ops *ops;
  1391. };
  1392. const struct nand_manufacturer *nand_get_manufacturer(u8 id);
  1393. static inline const char *
  1394. nand_manufacturer_name(const struct nand_manufacturer *manufacturer)
  1395. {
  1396. return manufacturer ? manufacturer->name : "Unknown";
  1397. }
  1398. extern struct nand_flash_dev nand_flash_ids[];
  1399. extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops;
  1400. extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;
  1401. extern const struct nand_manufacturer_ops hynix_nand_manuf_ops;
  1402. extern const struct nand_manufacturer_ops micron_nand_manuf_ops;
  1403. extern const struct nand_manufacturer_ops amd_nand_manuf_ops;
  1404. extern const struct nand_manufacturer_ops macronix_nand_manuf_ops;
  1405. int nand_create_bbt(struct nand_chip *chip);
  1406. int nand_markbad_bbt(struct nand_chip *chip, loff_t offs);
  1407. int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs);
  1408. int nand_isreserved_bbt(struct nand_chip *chip, loff_t offs);
  1409. int nand_isbad_bbt(struct nand_chip *chip, loff_t offs, int allowbbt);
  1410. int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
  1411. int allowbbt);
  1412. /**
  1413. * struct platform_nand_chip - chip level device structure
  1414. * @nr_chips: max. number of chips to scan for
  1415. * @chip_offset: chip number offset
  1416. * @nr_partitions: number of partitions pointed to by partitions (or zero)
  1417. * @partitions: mtd partition list
  1418. * @chip_delay: R/B delay value in us
  1419. * @options: Option flags, e.g. 16bit buswidth
  1420. * @bbt_options: BBT option flags, e.g. NAND_BBT_USE_FLASH
  1421. * @part_probe_types: NULL-terminated array of probe types
  1422. */
  1423. struct platform_nand_chip {
  1424. int nr_chips;
  1425. int chip_offset;
  1426. int nr_partitions;
  1427. struct mtd_partition *partitions;
  1428. int chip_delay;
  1429. unsigned int options;
  1430. unsigned int bbt_options;
  1431. const char **part_probe_types;
  1432. };
  1433. /* Keep gcc happy */
  1434. struct platform_device;
  1435. /**
  1436. * struct platform_nand_ctrl - controller level device structure
  1437. * @probe: platform specific function to probe/setup hardware
  1438. * @remove: platform specific function to remove/teardown hardware
  1439. * @dev_ready: platform specific function to read ready/busy pin
  1440. * @select_chip: platform specific chip select function
  1441. * @cmd_ctrl: platform specific function for controlling
  1442. * ALE/CLE/nCE. Also used to write command and address
  1443. * @write_buf: platform specific function for write buffer
  1444. * @read_buf: platform specific function for read buffer
  1445. * @priv: private data to transport driver specific settings
  1446. *
  1447. * All fields are optional and depend on the hardware driver requirements
  1448. */
  1449. struct platform_nand_ctrl {
  1450. int (*probe)(struct platform_device *pdev);
  1451. void (*remove)(struct platform_device *pdev);
  1452. int (*dev_ready)(struct nand_chip *chip);
  1453. void (*select_chip)(struct nand_chip *chip, int cs);
  1454. void (*cmd_ctrl)(struct nand_chip *chip, int dat, unsigned int ctrl);
  1455. void (*write_buf)(struct nand_chip *chip, const uint8_t *buf, int len);
  1456. void (*read_buf)(struct nand_chip *chip, uint8_t *buf, int len);
  1457. void *priv;
  1458. };
  1459. /**
  1460. * struct platform_nand_data - container structure for platform-specific data
  1461. * @chip: chip level chip structure
  1462. * @ctrl: controller level device structure
  1463. */
  1464. struct platform_nand_data {
  1465. struct platform_nand_chip chip;
  1466. struct platform_nand_ctrl ctrl;
  1467. };
  1468. /* return the supported asynchronous timing mode. */
  1469. static inline int onfi_get_async_timing_mode(struct nand_chip *chip)
  1470. {
  1471. if (!chip->parameters.onfi)
  1472. return ONFI_TIMING_MODE_UNKNOWN;
  1473. return chip->parameters.onfi->async_timing_mode;
  1474. }
  1475. int onfi_fill_data_interface(struct nand_chip *chip,
  1476. enum nand_data_interface_type type,
  1477. int timing_mode);
  1478. /*
  1479. * Check if it is a SLC nand.
  1480. * The !nand_is_slc() can be used to check the MLC/TLC nand chips.
  1481. * We do not distinguish the MLC and TLC now.
  1482. */
  1483. static inline bool nand_is_slc(struct nand_chip *chip)
  1484. {
  1485. WARN(chip->bits_per_cell == 0,
  1486. "chip->bits_per_cell is used uninitialized\n");
  1487. return chip->bits_per_cell == 1;
  1488. }
  1489. /**
  1490. * Check if the opcode's address should be sent only on the lower 8 bits
  1491. * @command: opcode to check
  1492. */
  1493. static inline int nand_opcode_8bits(unsigned int command)
  1494. {
  1495. switch (command) {
  1496. case NAND_CMD_READID:
  1497. case NAND_CMD_PARAM:
  1498. case NAND_CMD_GET_FEATURES:
  1499. case NAND_CMD_SET_FEATURES:
  1500. return 1;
  1501. default:
  1502. break;
  1503. }
  1504. return 0;
  1505. }
  1506. /* get timing characteristics from ONFI timing mode. */
  1507. const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode);
  1508. int nand_check_erased_ecc_chunk(void *data, int datalen,
  1509. void *ecc, int ecclen,
  1510. void *extraoob, int extraooblen,
  1511. int threshold);
  1512. int nand_ecc_choose_conf(struct nand_chip *chip,
  1513. const struct nand_ecc_caps *caps, int oobavail);
  1514. /* Default write_oob implementation */
  1515. int nand_write_oob_std(struct nand_chip *chip, int page);
  1516. /* Default write_oob syndrome implementation */
  1517. int nand_write_oob_syndrome(struct nand_chip *chip, int page);
  1518. /* Default read_oob implementation */
  1519. int nand_read_oob_std(struct nand_chip *chip, int page);
  1520. /* Default read_oob syndrome implementation */
  1521. int nand_read_oob_syndrome(struct nand_chip *chip, int page);
  1522. /* Wrapper to use in order for controllers/vendors to GET/SET FEATURES */
  1523. int nand_get_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  1524. int nand_set_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  1525. /* Stub used by drivers that do not support GET/SET FEATURES operations */
  1526. int nand_get_set_features_notsupp(struct nand_chip *chip, int addr,
  1527. u8 *subfeature_param);
  1528. /* Default read_page_raw implementation */
  1529. int nand_read_page_raw(struct nand_chip *chip, uint8_t *buf, int oob_required,
  1530. int page);
  1531. int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf,
  1532. int oob_required, int page);
  1533. /* Default write_page_raw implementation */
  1534. int nand_write_page_raw(struct nand_chip *chip, const uint8_t *buf,
  1535. int oob_required, int page);
  1536. int nand_write_page_raw_notsupp(struct nand_chip *chip, const u8 *buf,
  1537. int oob_required, int page);
  1538. /* Reset and initialize a NAND device */
  1539. int nand_reset(struct nand_chip *chip, int chipnr);
  1540. /* NAND operation helpers */
  1541. int nand_reset_op(struct nand_chip *chip);
  1542. int nand_readid_op(struct nand_chip *chip, u8 addr, void *buf,
  1543. unsigned int len);
  1544. int nand_status_op(struct nand_chip *chip, u8 *status);
  1545. int nand_exit_status_op(struct nand_chip *chip);
  1546. int nand_erase_op(struct nand_chip *chip, unsigned int eraseblock);
  1547. int nand_read_page_op(struct nand_chip *chip, unsigned int page,
  1548. unsigned int offset_in_page, void *buf, unsigned int len);
  1549. int nand_change_read_column_op(struct nand_chip *chip,
  1550. unsigned int offset_in_page, void *buf,
  1551. unsigned int len, bool force_8bit);
  1552. int nand_read_oob_op(struct nand_chip *chip, unsigned int page,
  1553. unsigned int offset_in_page, void *buf, unsigned int len);
  1554. int nand_prog_page_begin_op(struct nand_chip *chip, unsigned int page,
  1555. unsigned int offset_in_page, const void *buf,
  1556. unsigned int len);
  1557. int nand_prog_page_end_op(struct nand_chip *chip);
  1558. int nand_prog_page_op(struct nand_chip *chip, unsigned int page,
  1559. unsigned int offset_in_page, const void *buf,
  1560. unsigned int len);
  1561. int nand_change_write_column_op(struct nand_chip *chip,
  1562. unsigned int offset_in_page, const void *buf,
  1563. unsigned int len, bool force_8bit);
  1564. int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
  1565. bool force_8bit);
  1566. int nand_write_data_op(struct nand_chip *chip, const void *buf,
  1567. unsigned int len, bool force_8bit);
  1568. /*
  1569. * Free resources held by the NAND device, must be called on error after a
  1570. * sucessful nand_scan().
  1571. */
  1572. void nand_cleanup(struct nand_chip *chip);
  1573. /* Unregister the MTD device and calls nand_cleanup() */
  1574. void nand_release(struct nand_chip *chip);
  1575. /* Default extended ID decoding function */
  1576. void nand_decode_ext_id(struct nand_chip *chip);
  1577. /*
  1578. * External helper for controller drivers that have to implement the WAITRDY
  1579. * instruction and have no physical pin to check it.
  1580. */
  1581. int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms);
  1582. #endif /* __LINUX_MTD_RAWNAND_H */