rawnand.h 52 KB

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