onenand_base.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. /*
  2. * linux/drivers/mtd/onenand/onenand_base.c
  3. *
  4. * Copyright (C) 2005-2007 Samsung Electronics
  5. * Kyungmin Park <kyungmin.park@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <common.h>
  12. #include <linux/mtd/compat.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/onenand.h>
  15. #include <asm/io.h>
  16. #include <asm/errno.h>
  17. #include <malloc.h>
  18. /* It should access 16-bit instead of 8-bit */
  19. static inline void *memcpy_16(void *dst, const void *src, unsigned int len)
  20. {
  21. void *ret = dst;
  22. short *d = dst;
  23. const short *s = src;
  24. len >>= 1;
  25. while (len-- > 0)
  26. *d++ = *s++;
  27. return ret;
  28. }
  29. static const unsigned char ffchars[] = {
  30. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  31. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 16 */
  32. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  33. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 32 */
  34. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  35. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 48 */
  36. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  37. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 64 */
  38. };
  39. /**
  40. * onenand_readw - [OneNAND Interface] Read OneNAND register
  41. * @param addr address to read
  42. *
  43. * Read OneNAND register
  44. */
  45. static unsigned short onenand_readw(void __iomem * addr)
  46. {
  47. return readw(addr);
  48. }
  49. /**
  50. * onenand_writew - [OneNAND Interface] Write OneNAND register with value
  51. * @param value value to write
  52. * @param addr address to write
  53. *
  54. * Write OneNAND register with value
  55. */
  56. static void onenand_writew(unsigned short value, void __iomem * addr)
  57. {
  58. writew(value, addr);
  59. }
  60. /**
  61. * onenand_block_address - [DEFAULT] Get block address
  62. * @param device the device id
  63. * @param block the block
  64. * @return translated block address if DDP, otherwise same
  65. *
  66. * Setup Start Address 1 Register (F100h)
  67. */
  68. static int onenand_block_address(int device, int block)
  69. {
  70. if (device & ONENAND_DEVICE_IS_DDP) {
  71. /* Device Flash Core select, NAND Flash Block Address */
  72. int dfs = 0, density, mask;
  73. density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
  74. mask = (1 << (density + 6));
  75. if (block & mask)
  76. dfs = 1;
  77. return (dfs << ONENAND_DDP_SHIFT) | (block & (mask - 1));
  78. }
  79. return block;
  80. }
  81. /**
  82. * onenand_bufferram_address - [DEFAULT] Get bufferram address
  83. * @param device the device id
  84. * @param block the block
  85. * @return set DBS value if DDP, otherwise 0
  86. *
  87. * Setup Start Address 2 Register (F101h) for DDP
  88. */
  89. static int onenand_bufferram_address(int device, int block)
  90. {
  91. if (device & ONENAND_DEVICE_IS_DDP) {
  92. /* Device BufferRAM Select */
  93. int dbs = 0, density, mask;
  94. density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
  95. mask = (1 << (density + 6));
  96. if (block & mask)
  97. dbs = 1;
  98. return (dbs << ONENAND_DDP_SHIFT);
  99. }
  100. return 0;
  101. }
  102. /**
  103. * onenand_page_address - [DEFAULT] Get page address
  104. * @param page the page address
  105. * @param sector the sector address
  106. * @return combined page and sector address
  107. *
  108. * Setup Start Address 8 Register (F107h)
  109. */
  110. static int onenand_page_address(int page, int sector)
  111. {
  112. /* Flash Page Address, Flash Sector Address */
  113. int fpa, fsa;
  114. fpa = page & ONENAND_FPA_MASK;
  115. fsa = sector & ONENAND_FSA_MASK;
  116. return ((fpa << ONENAND_FPA_SHIFT) | fsa);
  117. }
  118. /**
  119. * onenand_buffer_address - [DEFAULT] Get buffer address
  120. * @param dataram1 DataRAM index
  121. * @param sectors the sector address
  122. * @param count the number of sectors
  123. * @return the start buffer value
  124. *
  125. * Setup Start Buffer Register (F200h)
  126. */
  127. static int onenand_buffer_address(int dataram1, int sectors, int count)
  128. {
  129. int bsa, bsc;
  130. /* BufferRAM Sector Address */
  131. bsa = sectors & ONENAND_BSA_MASK;
  132. if (dataram1)
  133. bsa |= ONENAND_BSA_DATARAM1; /* DataRAM1 */
  134. else
  135. bsa |= ONENAND_BSA_DATARAM0; /* DataRAM0 */
  136. /* BufferRAM Sector Count */
  137. bsc = count & ONENAND_BSC_MASK;
  138. return ((bsa << ONENAND_BSA_SHIFT) | bsc);
  139. }
  140. /**
  141. * onenand_command - [DEFAULT] Send command to OneNAND device
  142. * @param mtd MTD device structure
  143. * @param cmd the command to be sent
  144. * @param addr offset to read from or write to
  145. * @param len number of bytes to read or write
  146. *
  147. * Send command to OneNAND device. This function is used for middle/large page
  148. * devices (1KB/2KB Bytes per page)
  149. */
  150. static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr,
  151. size_t len)
  152. {
  153. struct onenand_chip *this = mtd->priv;
  154. int value, readcmd = 0;
  155. int block, page;
  156. /* Now we use page size operation */
  157. int sectors = 4, count = 4;
  158. /* Address translation */
  159. switch (cmd) {
  160. case ONENAND_CMD_UNLOCK:
  161. case ONENAND_CMD_LOCK:
  162. case ONENAND_CMD_LOCK_TIGHT:
  163. block = -1;
  164. page = -1;
  165. break;
  166. case ONENAND_CMD_ERASE:
  167. case ONENAND_CMD_BUFFERRAM:
  168. block = (int)(addr >> this->erase_shift);
  169. page = -1;
  170. break;
  171. default:
  172. block = (int)(addr >> this->erase_shift);
  173. page = (int)(addr >> this->page_shift);
  174. page &= this->page_mask;
  175. break;
  176. }
  177. /* NOTE: The setting order of the registers is very important! */
  178. if (cmd == ONENAND_CMD_BUFFERRAM) {
  179. /* Select DataRAM for DDP */
  180. value = onenand_bufferram_address(this->device_id, block);
  181. this->write_word(value,
  182. this->base + ONENAND_REG_START_ADDRESS2);
  183. /* Switch to the next data buffer */
  184. ONENAND_SET_NEXT_BUFFERRAM(this);
  185. return 0;
  186. }
  187. if (block != -1) {
  188. /* Write 'DFS, FBA' of Flash */
  189. value = onenand_block_address(this->device_id, block);
  190. this->write_word(value,
  191. this->base + ONENAND_REG_START_ADDRESS1);
  192. }
  193. if (page != -1) {
  194. int dataram;
  195. switch (cmd) {
  196. case ONENAND_CMD_READ:
  197. case ONENAND_CMD_READOOB:
  198. dataram = ONENAND_SET_NEXT_BUFFERRAM(this);
  199. readcmd = 1;
  200. break;
  201. default:
  202. dataram = ONENAND_CURRENT_BUFFERRAM(this);
  203. break;
  204. }
  205. /* Write 'FPA, FSA' of Flash */
  206. value = onenand_page_address(page, sectors);
  207. this->write_word(value,
  208. this->base + ONENAND_REG_START_ADDRESS8);
  209. /* Write 'BSA, BSC' of DataRAM */
  210. value = onenand_buffer_address(dataram, sectors, count);
  211. this->write_word(value, this->base + ONENAND_REG_START_BUFFER);
  212. if (readcmd) {
  213. /* Select DataRAM for DDP */
  214. value =
  215. onenand_bufferram_address(this->device_id, block);
  216. this->write_word(value,
  217. this->base +
  218. ONENAND_REG_START_ADDRESS2);
  219. }
  220. }
  221. /* Interrupt clear */
  222. this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT);
  223. /* Write command */
  224. this->write_word(cmd, this->base + ONENAND_REG_COMMAND);
  225. return 0;
  226. }
  227. /**
  228. * onenand_wait - [DEFAULT] wait until the command is done
  229. * @param mtd MTD device structure
  230. * @param state state to select the max. timeout value
  231. *
  232. * Wait for command done. This applies to all OneNAND command
  233. * Read can take up to 30us, erase up to 2ms and program up to 350us
  234. * according to general OneNAND specs
  235. */
  236. static int onenand_wait(struct mtd_info *mtd, int state)
  237. {
  238. struct onenand_chip *this = mtd->priv;
  239. unsigned int flags = ONENAND_INT_MASTER;
  240. unsigned int interrupt = 0;
  241. unsigned int ctrl, ecc;
  242. while (1) {
  243. interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
  244. if (interrupt & flags)
  245. break;
  246. }
  247. ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
  248. if (ctrl & ONENAND_CTRL_ERROR) {
  249. MTDDEBUG (MTD_DEBUG_LEVEL0,
  250. "onenand_wait: controller error = 0x%04x\n", ctrl);
  251. return -EAGAIN;
  252. }
  253. if (ctrl & ONENAND_CTRL_LOCK) {
  254. MTDDEBUG (MTD_DEBUG_LEVEL0,
  255. "onenand_wait: it's locked error = 0x%04x\n", ctrl);
  256. return -EIO;
  257. }
  258. if (interrupt & ONENAND_INT_READ) {
  259. ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
  260. if (ecc & ONENAND_ECC_2BIT_ALL) {
  261. MTDDEBUG (MTD_DEBUG_LEVEL0,
  262. "onenand_wait: ECC error = 0x%04x\n", ecc);
  263. return -EBADMSG;
  264. }
  265. }
  266. return 0;
  267. }
  268. /**
  269. * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
  270. * @param mtd MTD data structure
  271. * @param area BufferRAM area
  272. * @return offset given area
  273. *
  274. * Return BufferRAM offset given area
  275. */
  276. static inline int onenand_bufferram_offset(struct mtd_info *mtd, int area)
  277. {
  278. struct onenand_chip *this = mtd->priv;
  279. if (ONENAND_CURRENT_BUFFERRAM(this)) {
  280. if (area == ONENAND_DATARAM)
  281. return mtd->writesize;
  282. if (area == ONENAND_SPARERAM)
  283. return mtd->oobsize;
  284. }
  285. return 0;
  286. }
  287. /**
  288. * onenand_read_bufferram - [OneNAND Interface] Read the bufferram area
  289. * @param mtd MTD data structure
  290. * @param area BufferRAM area
  291. * @param buffer the databuffer to put/get data
  292. * @param offset offset to read from or write to
  293. * @param count number of bytes to read/write
  294. *
  295. * Read the BufferRAM area
  296. */
  297. static int onenand_read_bufferram(struct mtd_info *mtd, int area,
  298. unsigned char *buffer, int offset,
  299. size_t count)
  300. {
  301. struct onenand_chip *this = mtd->priv;
  302. void __iomem *bufferram;
  303. bufferram = this->base + area;
  304. bufferram += onenand_bufferram_offset(mtd, area);
  305. memcpy_16(buffer, bufferram + offset, count);
  306. return 0;
  307. }
  308. /**
  309. * onenand_sync_read_bufferram - [OneNAND Interface] Read the bufferram area with Sync. Burst mode
  310. * @param mtd MTD data structure
  311. * @param area BufferRAM area
  312. * @param buffer the databuffer to put/get data
  313. * @param offset offset to read from or write to
  314. * @param count number of bytes to read/write
  315. *
  316. * Read the BufferRAM area with Sync. Burst Mode
  317. */
  318. static int onenand_sync_read_bufferram(struct mtd_info *mtd, int area,
  319. unsigned char *buffer, int offset,
  320. size_t count)
  321. {
  322. struct onenand_chip *this = mtd->priv;
  323. void __iomem *bufferram;
  324. bufferram = this->base + area;
  325. bufferram += onenand_bufferram_offset(mtd, area);
  326. this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ);
  327. memcpy_16(buffer, bufferram + offset, count);
  328. this->mmcontrol(mtd, 0);
  329. return 0;
  330. }
  331. /**
  332. * onenand_write_bufferram - [OneNAND Interface] Write the bufferram area
  333. * @param mtd MTD data structure
  334. * @param area BufferRAM area
  335. * @param buffer the databuffer to put/get data
  336. * @param offset offset to read from or write to
  337. * @param count number of bytes to read/write
  338. *
  339. * Write the BufferRAM area
  340. */
  341. static int onenand_write_bufferram(struct mtd_info *mtd, int area,
  342. const unsigned char *buffer, int offset,
  343. size_t count)
  344. {
  345. struct onenand_chip *this = mtd->priv;
  346. void __iomem *bufferram;
  347. bufferram = this->base + area;
  348. bufferram += onenand_bufferram_offset(mtd, area);
  349. memcpy_16(bufferram + offset, buffer, count);
  350. return 0;
  351. }
  352. /**
  353. * onenand_check_bufferram - [GENERIC] Check BufferRAM information
  354. * @param mtd MTD data structure
  355. * @param addr address to check
  356. * @return 1 if there are valid data, otherwise 0
  357. *
  358. * Check bufferram if there is data we required
  359. */
  360. static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
  361. {
  362. struct onenand_chip *this = mtd->priv;
  363. int block, page;
  364. int i;
  365. block = (int)(addr >> this->erase_shift);
  366. page = (int)(addr >> this->page_shift);
  367. page &= this->page_mask;
  368. i = ONENAND_CURRENT_BUFFERRAM(this);
  369. /* Is there valid data? */
  370. if (this->bufferram[i].block == block &&
  371. this->bufferram[i].page == page && this->bufferram[i].valid)
  372. return 1;
  373. return 0;
  374. }
  375. /**
  376. * onenand_update_bufferram - [GENERIC] Update BufferRAM information
  377. * @param mtd MTD data structure
  378. * @param addr address to update
  379. * @param valid valid flag
  380. *
  381. * Update BufferRAM information
  382. */
  383. static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr,
  384. int valid)
  385. {
  386. struct onenand_chip *this = mtd->priv;
  387. int block, page;
  388. int i;
  389. block = (int)(addr >> this->erase_shift);
  390. page = (int)(addr >> this->page_shift);
  391. page &= this->page_mask;
  392. /* Invalidate BufferRAM */
  393. for (i = 0; i < MAX_BUFFERRAM; i++) {
  394. if (this->bufferram[i].block == block &&
  395. this->bufferram[i].page == page)
  396. this->bufferram[i].valid = 0;
  397. }
  398. /* Update BufferRAM */
  399. i = ONENAND_CURRENT_BUFFERRAM(this);
  400. this->bufferram[i].block = block;
  401. this->bufferram[i].page = page;
  402. this->bufferram[i].valid = valid;
  403. return 0;
  404. }
  405. /**
  406. * onenand_invalidate_bufferram - [GENERIC] Invalidate BufferRAM information
  407. * @param mtd MTD data structure
  408. * @param addr start address to invalidate
  409. * @param len length to invalidate
  410. *
  411. * Invalidate BufferRAM information
  412. */
  413. static void onenand_invalidate_bufferram(struct mtd_info *mtd, loff_t addr,
  414. unsigned int len)
  415. {
  416. struct onenand_chip *this = mtd->priv;
  417. int i;
  418. loff_t end_addr = addr + len;
  419. /* Invalidate BufferRAM */
  420. for (i = 0; i < MAX_BUFFERRAM; i++) {
  421. loff_t buf_addr = this->bufferram[i].block << this->erase_shift;
  422. if (buf_addr >= addr && buf_addr < end_addr)
  423. this->bufferram[i].valid = 0;
  424. }
  425. }
  426. /**
  427. * onenand_get_device - [GENERIC] Get chip for selected access
  428. * @param mtd MTD device structure
  429. * @param new_state the state which is requested
  430. *
  431. * Get the device and lock it for exclusive access
  432. */
  433. static void onenand_get_device(struct mtd_info *mtd, int new_state)
  434. {
  435. /* Do nothing */
  436. }
  437. /**
  438. * onenand_release_device - [GENERIC] release chip
  439. * @param mtd MTD device structure
  440. *
  441. * Deselect, release chip lock and wake up anyone waiting on the device
  442. */
  443. static void onenand_release_device(struct mtd_info *mtd)
  444. {
  445. /* Do nothing */
  446. }
  447. /**
  448. * onenand_read_ecc - [MTD Interface] Read data with ECC
  449. * @param mtd MTD device structure
  450. * @param from offset to read from
  451. * @param len number of bytes to read
  452. * @param retlen pointer to variable to store the number of read bytes
  453. * @param buf the databuffer to put data
  454. * @param oob_buf filesystem supplied oob data buffer
  455. * @param oobsel oob selection structure
  456. *
  457. * OneNAND read with ECC
  458. */
  459. static int onenand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  460. size_t * retlen, u_char * buf,
  461. u_char * oob_buf, struct nand_oobinfo *oobsel)
  462. {
  463. struct onenand_chip *this = mtd->priv;
  464. int read = 0, column;
  465. int thislen;
  466. int ret = 0;
  467. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_read_ecc: "
  468. "from = 0x%08x, len = %i\n",
  469. (unsigned int)from, (int)len);
  470. /* Do not allow reads past end of device */
  471. if ((from + len) > mtd->size) {
  472. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_read_ecc: "
  473. "Attempt read beyond end of device\n");
  474. *retlen = 0;
  475. return -EINVAL;
  476. }
  477. /* Grab the lock and see if the device is available */
  478. onenand_get_device(mtd, FL_READING);
  479. while (read < len) {
  480. thislen = min_t(int, mtd->writesize, len - read);
  481. column = from & (mtd->writesize - 1);
  482. if (column + thislen > mtd->writesize)
  483. thislen = mtd->writesize - column;
  484. if (!onenand_check_bufferram(mtd, from)) {
  485. this->command(mtd, ONENAND_CMD_READ, from,
  486. mtd->writesize);
  487. ret = this->wait(mtd, FL_READING);
  488. /* First copy data and check return value for ECC handling */
  489. onenand_update_bufferram(mtd, from, 1);
  490. }
  491. this->read_bufferram(mtd, ONENAND_DATARAM, buf, column,
  492. thislen);
  493. read += thislen;
  494. if (read == len)
  495. break;
  496. if (ret) {
  497. MTDDEBUG (MTD_DEBUG_LEVEL0,
  498. "onenand_read_ecc: read failed = %d\n", ret);
  499. break;
  500. }
  501. from += thislen;
  502. buf += thislen;
  503. }
  504. /* Deselect and wake up anyone waiting on the device */
  505. onenand_release_device(mtd);
  506. /*
  507. * Return success, if no ECC failures, else -EBADMSG
  508. * fs driver will take care of that, because
  509. * retlen == desired len and result == -EBADMSG
  510. */
  511. *retlen = read;
  512. return ret;
  513. }
  514. /**
  515. * onenand_read - [MTD Interface] MTD compability function for onenand_read_ecc
  516. * @param mtd MTD device structure
  517. * @param from offset to read from
  518. * @param len number of bytes to read
  519. * @param retlen pointer to variable to store the number of read bytes
  520. * @param buf the databuffer to put data
  521. *
  522. * This function simply calls onenand_read_ecc with oob buffer and oobsel = NULL
  523. */
  524. int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
  525. size_t * retlen, u_char * buf)
  526. {
  527. return onenand_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
  528. }
  529. /**
  530. * onenand_read_oob - [MTD Interface] OneNAND read out-of-band
  531. * @param mtd MTD device structure
  532. * @param from offset to read from
  533. * @param len number of bytes to read
  534. * @param retlen pointer to variable to store the number of read bytes
  535. * @param buf the databuffer to put data
  536. *
  537. * OneNAND read out-of-band data from the spare area
  538. */
  539. int onenand_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
  540. size_t * retlen, u_char * buf)
  541. {
  542. struct onenand_chip *this = mtd->priv;
  543. int read = 0, thislen, column;
  544. int ret = 0;
  545. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_read_oob: "
  546. "from = 0x%08x, len = %i\n",
  547. (unsigned int)from, (int)len);
  548. /* Initialize return length value */
  549. *retlen = 0;
  550. /* Do not allow reads past end of device */
  551. if (unlikely((from + len) > mtd->size)) {
  552. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_read_oob: "
  553. "Attempt read beyond end of device\n");
  554. return -EINVAL;
  555. }
  556. /* Grab the lock and see if the device is available */
  557. onenand_get_device(mtd, FL_READING);
  558. column = from & (mtd->oobsize - 1);
  559. while (read < len) {
  560. thislen = mtd->oobsize - column;
  561. thislen = min_t(int, thislen, len);
  562. this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
  563. onenand_update_bufferram(mtd, from, 0);
  564. ret = this->wait(mtd, FL_READING);
  565. /* First copy data and check return value for ECC handling */
  566. this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column,
  567. thislen);
  568. read += thislen;
  569. if (read == len)
  570. break;
  571. if (ret) {
  572. MTDDEBUG (MTD_DEBUG_LEVEL0,
  573. "onenand_read_oob: read failed = %d\n", ret);
  574. break;
  575. }
  576. buf += thislen;
  577. /* Read more? */
  578. if (read < len) {
  579. /* Page size */
  580. from += mtd->writesize;
  581. column = 0;
  582. }
  583. }
  584. /* Deselect and wake up anyone waiting on the device */
  585. onenand_release_device(mtd);
  586. *retlen = read;
  587. return ret;
  588. }
  589. #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
  590. /**
  591. * onenand_verify_page - [GENERIC] verify the chip contents after a write
  592. * @param mtd MTD device structure
  593. * @param buf the databuffer to verify
  594. *
  595. * Check DataRAM area directly
  596. */
  597. static int onenand_verify_page(struct mtd_info *mtd, u_char * buf,
  598. loff_t addr)
  599. {
  600. struct onenand_chip *this = mtd->priv;
  601. void __iomem *dataram0, *dataram1;
  602. int ret = 0;
  603. this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize);
  604. ret = this->wait(mtd, FL_READING);
  605. if (ret)
  606. return ret;
  607. onenand_update_bufferram(mtd, addr, 1);
  608. /* Check, if the two dataram areas are same */
  609. dataram0 = this->base + ONENAND_DATARAM;
  610. dataram1 = dataram0 + mtd->writesize;
  611. if (memcmp(dataram0, dataram1, mtd->writesize))
  612. return -EBADMSG;
  613. return 0;
  614. }
  615. #else
  616. #define onenand_verify_page(...) (0)
  617. #endif
  618. #define NOTALIGNED(x) ((x & (mtd->writesize - 1)) != 0)
  619. /**
  620. * onenand_write_ecc - [MTD Interface] OneNAND write with ECC
  621. * @param mtd MTD device structure
  622. * @param to offset to write to
  623. * @param len number of bytes to write
  624. * @param retlen pointer to variable to store the number of written bytes
  625. * @param buf the data to write
  626. * @param eccbuf filesystem supplied oob data buffer
  627. * @param oobsel oob selection structure
  628. *
  629. * OneNAND write with ECC
  630. */
  631. static int onenand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  632. size_t * retlen, const u_char * buf,
  633. u_char * eccbuf, struct nand_oobinfo *oobsel)
  634. {
  635. struct onenand_chip *this = mtd->priv;
  636. int written = 0;
  637. int ret = 0;
  638. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_write_ecc: "
  639. "to = 0x%08x, len = %i\n",
  640. (unsigned int)to, (int)len);
  641. /* Initialize retlen, in case of early exit */
  642. *retlen = 0;
  643. /* Do not allow writes past end of device */
  644. if (unlikely((to + len) > mtd->size)) {
  645. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_write_ecc: "
  646. "Attempt write to past end of device\n");
  647. return -EINVAL;
  648. }
  649. /* Reject writes, which are not page aligned */
  650. if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) {
  651. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_write_ecc: "
  652. "Attempt to write not page aligned data\n");
  653. return -EINVAL;
  654. }
  655. /* Grab the lock and see if the device is available */
  656. onenand_get_device(mtd, FL_WRITING);
  657. /* Loop until all data write */
  658. while (written < len) {
  659. int thislen = min_t(int, mtd->writesize, len - written);
  660. this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->writesize);
  661. this->write_bufferram(mtd, ONENAND_DATARAM, buf, 0, thislen);
  662. this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0,
  663. mtd->oobsize);
  664. this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
  665. onenand_update_bufferram(mtd, to, 1);
  666. ret = this->wait(mtd, FL_WRITING);
  667. if (ret) {
  668. MTDDEBUG (MTD_DEBUG_LEVEL0,
  669. "onenand_write_ecc: write filaed %d\n", ret);
  670. break;
  671. }
  672. written += thislen;
  673. /* Only check verify write turn on */
  674. ret = onenand_verify_page(mtd, (u_char *) buf, to);
  675. if (ret) {
  676. MTDDEBUG (MTD_DEBUG_LEVEL0,
  677. "onenand_write_ecc: verify failed %d\n", ret);
  678. break;
  679. }
  680. if (written == len)
  681. break;
  682. to += thislen;
  683. buf += thislen;
  684. }
  685. /* Deselect and wake up anyone waiting on the device */
  686. onenand_release_device(mtd);
  687. *retlen = written;
  688. return ret;
  689. }
  690. /**
  691. * onenand_write - [MTD Interface] compability function for onenand_write_ecc
  692. * @param mtd MTD device structure
  693. * @param to offset to write to
  694. * @param len number of bytes to write
  695. * @param retlen pointer to variable to store the number of written bytes
  696. * @param buf the data to write
  697. *
  698. * This function simply calls onenand_write_ecc
  699. * with oob buffer and oobsel = NULL
  700. */
  701. int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
  702. size_t * retlen, const u_char * buf)
  703. {
  704. return onenand_write_ecc(mtd, to, len, retlen, buf, NULL, NULL);
  705. }
  706. /**
  707. * onenand_write_oob - [MTD Interface] OneNAND write out-of-band
  708. * @param mtd MTD device structure
  709. * @param to offset to write to
  710. * @param len number of bytes to write
  711. * @param retlen pointer to variable to store the number of written bytes
  712. * @param buf the data to write
  713. *
  714. * OneNAND write out-of-band
  715. */
  716. int onenand_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
  717. size_t * retlen, const u_char * buf)
  718. {
  719. struct onenand_chip *this = mtd->priv;
  720. int column, status;
  721. int written = 0;
  722. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_write_oob: "
  723. "to = 0x%08x, len = %i\n",
  724. (unsigned int)to, (int)len);
  725. /* Initialize retlen, in case of early exit */
  726. *retlen = 0;
  727. /* Do not allow writes past end of device */
  728. if (unlikely((to + len) > mtd->size)) {
  729. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_write_oob: "
  730. "Attempt write to past end of device\n");
  731. return -EINVAL;
  732. }
  733. /* Grab the lock and see if the device is available */
  734. onenand_get_device(mtd, FL_WRITING);
  735. /* Loop until all data write */
  736. while (written < len) {
  737. int thislen = min_t(int, mtd->oobsize, len - written);
  738. column = to & (mtd->oobsize - 1);
  739. this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
  740. this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0,
  741. mtd->oobsize);
  742. this->write_bufferram(mtd, ONENAND_SPARERAM, buf, column,
  743. thislen);
  744. this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize);
  745. onenand_update_bufferram(mtd, to, 0);
  746. status = this->wait(mtd, FL_WRITING);
  747. if (status)
  748. break;
  749. written += thislen;
  750. if (written == len)
  751. break;
  752. to += thislen;
  753. buf += thislen;
  754. }
  755. /* Deselect and wake up anyone waiting on the device */
  756. onenand_release_device(mtd);
  757. *retlen = written;
  758. return 0;
  759. }
  760. /**
  761. * onenand_block_isbad_nolock - [GENERIC] Check if a block is marked bad
  762. * @param mtd MTD device structure
  763. * @param ofs offset from device start
  764. * @param allowbbt 1, if its allowed to access the bbt area
  765. *
  766. * Check, if the block is bad, Either by reading the bad block table or
  767. * calling of the scan function.
  768. */
  769. static int onenand_block_isbad_nolock(struct mtd_info *mtd, loff_t ofs, int allowbbt)
  770. {
  771. struct onenand_chip *this = mtd->priv;
  772. struct bbm_info *bbm = this->bbm;
  773. /* Return info from the table */
  774. return bbm->isbad_bbt(mtd, ofs, allowbbt);
  775. }
  776. /**
  777. * onenand_erase - [MTD Interface] erase block(s)
  778. * @param mtd MTD device structure
  779. * @param instr erase instruction
  780. *
  781. * Erase one ore more blocks
  782. */
  783. int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
  784. {
  785. struct onenand_chip *this = mtd->priv;
  786. unsigned int block_size;
  787. loff_t addr;
  788. int len;
  789. int ret = 0;
  790. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_erase: start = 0x%08x, len = %i\n",
  791. (unsigned int)instr->addr, (unsigned int)instr->len);
  792. block_size = (1 << this->erase_shift);
  793. /* Start address must align on block boundary */
  794. if (unlikely(instr->addr & (block_size - 1))) {
  795. MTDDEBUG (MTD_DEBUG_LEVEL0,
  796. "onenand_erase: Unaligned address\n");
  797. return -EINVAL;
  798. }
  799. /* Length must align on block boundary */
  800. if (unlikely(instr->len & (block_size - 1))) {
  801. MTDDEBUG (MTD_DEBUG_LEVEL0,
  802. "onenand_erase: Length not block aligned\n");
  803. return -EINVAL;
  804. }
  805. /* Do not allow erase past end of device */
  806. if (unlikely((instr->len + instr->addr) > mtd->size)) {
  807. MTDDEBUG (MTD_DEBUG_LEVEL0,
  808. "onenand_erase: Erase past end of device\n");
  809. return -EINVAL;
  810. }
  811. instr->fail_addr = 0xffffffff;
  812. /* Grab the lock and see if the device is available */
  813. onenand_get_device(mtd, FL_ERASING);
  814. /* Loop throught the pages */
  815. len = instr->len;
  816. addr = instr->addr;
  817. instr->state = MTD_ERASING;
  818. while (len) {
  819. /* TODO Check badblock */
  820. this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);
  821. onenand_invalidate_bufferram(mtd, addr, block_size);
  822. ret = this->wait(mtd, FL_ERASING);
  823. /* Check, if it is write protected */
  824. if (ret) {
  825. if (ret == -EPERM)
  826. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_erase: "
  827. "Device is write protected!!!\n");
  828. else
  829. MTDDEBUG (MTD_DEBUG_LEVEL0, "onenand_erase: "
  830. "Failed erase, block %d\n",
  831. (unsigned)(addr >> this->erase_shift));
  832. instr->state = MTD_ERASE_FAILED;
  833. instr->fail_addr = addr;
  834. goto erase_exit;
  835. }
  836. len -= block_size;
  837. addr += block_size;
  838. }
  839. instr->state = MTD_ERASE_DONE;
  840. erase_exit:
  841. ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
  842. /* Do call back function */
  843. if (!ret)
  844. mtd_erase_callback(instr);
  845. /* Deselect and wake up anyone waiting on the device */
  846. onenand_release_device(mtd);
  847. return ret;
  848. }
  849. /**
  850. * onenand_sync - [MTD Interface] sync
  851. * @param mtd MTD device structure
  852. *
  853. * Sync is actually a wait for chip ready function
  854. */
  855. void onenand_sync(struct mtd_info *mtd)
  856. {
  857. MTDDEBUG (MTD_DEBUG_LEVEL3, "onenand_sync: called\n");
  858. /* Grab the lock and see if the device is available */
  859. onenand_get_device(mtd, FL_SYNCING);
  860. /* Release it and go back */
  861. onenand_release_device(mtd);
  862. }
  863. /**
  864. * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
  865. * @param mtd MTD device structure
  866. * @param ofs offset relative to mtd start
  867. *
  868. * Check whether the block is bad
  869. */
  870. int onenand_block_isbad(struct mtd_info *mtd, loff_t ofs)
  871. {
  872. int ret;
  873. /* Check for invalid offset */
  874. if (ofs > mtd->size)
  875. return -EINVAL;
  876. onenand_get_device(mtd, FL_READING);
  877. ret = onenand_block_isbad_nolock(mtd,ofs, 0);
  878. onenand_release_device(mtd);
  879. return ret;
  880. }
  881. /**
  882. * onenand_block_markbad - [MTD Interface] Mark the block at the given offset as bad
  883. * @param mtd MTD device structure
  884. * @param ofs offset relative to mtd start
  885. *
  886. * Mark the block as bad
  887. */
  888. int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
  889. {
  890. struct onenand_chip *this = mtd->priv;
  891. int ret;
  892. ret = onenand_block_isbad(mtd, ofs);
  893. if (ret) {
  894. /* If it was bad already, return success and do nothing */
  895. if (ret > 0)
  896. return 0;
  897. return ret;
  898. }
  899. ret = this->block_markbad(mtd, ofs);
  900. return ret;
  901. }
  902. /**
  903. * onenand_unlock - [MTD Interface] Unlock block(s)
  904. * @param mtd MTD device structure
  905. * @param ofs offset relative to mtd start
  906. * @param len number of bytes to unlock
  907. *
  908. * Unlock one or more blocks
  909. */
  910. int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
  911. {
  912. struct onenand_chip *this = mtd->priv;
  913. int start, end, block, value, status;
  914. start = ofs >> this->erase_shift;
  915. end = len >> this->erase_shift;
  916. /* Continuous lock scheme */
  917. if (this->options & ONENAND_CONT_LOCK) {
  918. /* Set start block address */
  919. this->write_word(start,
  920. this->base + ONENAND_REG_START_BLOCK_ADDRESS);
  921. /* Set end block address */
  922. this->write_word(end - 1,
  923. this->base + ONENAND_REG_END_BLOCK_ADDRESS);
  924. /* Write unlock command */
  925. this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
  926. /* There's no return value */
  927. this->wait(mtd, FL_UNLOCKING);
  928. /* Sanity check */
  929. while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
  930. & ONENAND_CTRL_ONGO)
  931. continue;
  932. /* Check lock status */
  933. status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
  934. if (!(status & ONENAND_WP_US))
  935. printk(KERN_ERR "wp status = 0x%x\n", status);
  936. return 0;
  937. }
  938. /* Block lock scheme */
  939. for (block = start; block < end; block++) {
  940. /* Set start block address */
  941. this->write_word(block,
  942. this->base + ONENAND_REG_START_BLOCK_ADDRESS);
  943. /* Write unlock command */
  944. this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
  945. /* There's no return value */
  946. this->wait(mtd, FL_UNLOCKING);
  947. /* Sanity check */
  948. while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
  949. & ONENAND_CTRL_ONGO)
  950. continue;
  951. /* Set block address for read block status */
  952. value = onenand_block_address(this->device_id, block);
  953. this->write_word(value,
  954. this->base + ONENAND_REG_START_ADDRESS1);
  955. /* Check lock status */
  956. status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
  957. if (!(status & ONENAND_WP_US))
  958. printk(KERN_ERR "block = %d, wp status = 0x%x\n",
  959. block, status);
  960. }
  961. return 0;
  962. }
  963. /**
  964. * onenand_print_device_info - Print device ID
  965. * @param device device ID
  966. *
  967. * Print device ID
  968. */
  969. char * onenand_print_device_info(int device)
  970. {
  971. int vcc, demuxed, ddp, density;
  972. char *dev_info = malloc(80);
  973. vcc = device & ONENAND_DEVICE_VCC_MASK;
  974. demuxed = device & ONENAND_DEVICE_IS_DEMUX;
  975. ddp = device & ONENAND_DEVICE_IS_DDP;
  976. density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
  977. sprintf(dev_info, "%sOneNAND%s %dMB %sV 16-bit (0x%02x)",
  978. demuxed ? "" : "Muxed ",
  979. ddp ? "(DDP)" : "",
  980. (16 << density), vcc ? "2.65/3.3" : "1.8", device);
  981. return dev_info;
  982. }
  983. static const struct onenand_manufacturers onenand_manuf_ids[] = {
  984. {ONENAND_MFR_SAMSUNG, "Samsung"},
  985. {ONENAND_MFR_UNKNOWN, "Unknown"}
  986. };
  987. /**
  988. * onenand_check_maf - Check manufacturer ID
  989. * @param manuf manufacturer ID
  990. *
  991. * Check manufacturer ID
  992. */
  993. static int onenand_check_maf(int manuf)
  994. {
  995. int i;
  996. for (i = 0; onenand_manuf_ids[i].id; i++) {
  997. if (manuf == onenand_manuf_ids[i].id)
  998. break;
  999. }
  1000. #ifdef ONENAND_DEBUG
  1001. printk(KERN_DEBUG "OneNAND Manufacturer: %s (0x%0x)\n",
  1002. onenand_manuf_ids[i].name, manuf);
  1003. #endif
  1004. return (i != ONENAND_MFR_UNKNOWN);
  1005. }
  1006. /**
  1007. * onenand_probe - [OneNAND Interface] Probe the OneNAND device
  1008. * @param mtd MTD device structure
  1009. *
  1010. * OneNAND detection method:
  1011. * Compare the the values from command with ones from register
  1012. */
  1013. static int onenand_probe(struct mtd_info *mtd)
  1014. {
  1015. struct onenand_chip *this = mtd->priv;
  1016. int bram_maf_id, bram_dev_id, maf_id, dev_id;
  1017. int version_id;
  1018. int density;
  1019. /* Send the command for reading device ID from BootRAM */
  1020. this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM);
  1021. /* Read manufacturer and device IDs from BootRAM */
  1022. bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0);
  1023. bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2);
  1024. /* Check manufacturer ID */
  1025. if (onenand_check_maf(bram_maf_id))
  1026. return -ENXIO;
  1027. /* Reset OneNAND to read default register values */
  1028. this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM);
  1029. /* Wait reset */
  1030. this->wait(mtd, FL_RESETING);
  1031. /* Read manufacturer and device IDs from Register */
  1032. maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
  1033. dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
  1034. /* Check OneNAND device */
  1035. if (maf_id != bram_maf_id || dev_id != bram_dev_id)
  1036. return -ENXIO;
  1037. /* FIXME : Current OneNAND MTD doesn't support Flex-OneNAND */
  1038. if (dev_id & (1 << 9)) {
  1039. printk("Not yet support Flex-OneNAND\n");
  1040. return -ENXIO;
  1041. }
  1042. /* Flash device information */
  1043. mtd->name = onenand_print_device_info(dev_id);
  1044. this->device_id = dev_id;
  1045. density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
  1046. this->chipsize = (16 << density) << 20;
  1047. /* OneNAND page size & block size */
  1048. /* The data buffer size is equal to page size */
  1049. mtd->writesize =
  1050. this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE);
  1051. mtd->oobsize = mtd->writesize >> 5;
  1052. /* Pagers per block is always 64 in OneNAND */
  1053. mtd->erasesize = mtd->writesize << 6;
  1054. this->erase_shift = ffs(mtd->erasesize) - 1;
  1055. this->page_shift = ffs(mtd->writesize) - 1;
  1056. this->ppb_shift = (this->erase_shift - this->page_shift);
  1057. this->page_mask = (mtd->erasesize / mtd->writesize) - 1;
  1058. /* REVIST: Multichip handling */
  1059. mtd->size = this->chipsize;
  1060. /* Version ID */
  1061. version_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
  1062. #ifdef ONENAND_DEBUG
  1063. printk(KERN_DEBUG "OneNAND version = 0x%04x\n", version_id);
  1064. #endif
  1065. /* Lock scheme */
  1066. if (density <= ONENAND_DEVICE_DENSITY_512Mb &&
  1067. !(version_id >> ONENAND_VERSION_PROCESS_SHIFT)) {
  1068. printk(KERN_INFO "Lock scheme is Continues Lock\n");
  1069. this->options |= ONENAND_CONT_LOCK;
  1070. }
  1071. mtd->flags = MTD_CAP_NANDFLASH;
  1072. mtd->erase = onenand_erase;
  1073. mtd->read = onenand_read;
  1074. mtd->write = onenand_write;
  1075. mtd->read_oob = onenand_read_oob;
  1076. mtd->write_oob = onenand_write_oob;
  1077. mtd->sync = onenand_sync;
  1078. mtd->block_isbad = onenand_block_isbad;
  1079. mtd->block_markbad = onenand_block_markbad;
  1080. return 0;
  1081. }
  1082. /**
  1083. * onenand_scan - [OneNAND Interface] Scan for the OneNAND device
  1084. * @param mtd MTD device structure
  1085. * @param maxchips Number of chips to scan for
  1086. *
  1087. * This fills out all the not initialized function pointers
  1088. * with the defaults.
  1089. * The flash ID is read and the mtd/chip structures are
  1090. * filled with the appropriate values.
  1091. */
  1092. int onenand_scan(struct mtd_info *mtd, int maxchips)
  1093. {
  1094. struct onenand_chip *this = mtd->priv;
  1095. if (!this->read_word)
  1096. this->read_word = onenand_readw;
  1097. if (!this->write_word)
  1098. this->write_word = onenand_writew;
  1099. if (!this->command)
  1100. this->command = onenand_command;
  1101. if (!this->wait)
  1102. this->wait = onenand_wait;
  1103. if (!this->read_bufferram)
  1104. this->read_bufferram = onenand_read_bufferram;
  1105. if (!this->write_bufferram)
  1106. this->write_bufferram = onenand_write_bufferram;
  1107. if (onenand_probe(mtd))
  1108. return -ENXIO;
  1109. /* Set Sync. Burst Read after probing */
  1110. if (this->mmcontrol) {
  1111. printk(KERN_INFO "OneNAND Sync. Burst Read support\n");
  1112. this->read_bufferram = onenand_sync_read_bufferram;
  1113. }
  1114. onenand_unlock(mtd, 0, mtd->size);
  1115. return onenand_default_bbt(mtd);
  1116. }
  1117. /**
  1118. * onenand_release - [OneNAND Interface] Free resources held by the OneNAND device
  1119. * @param mtd MTD device structure
  1120. */
  1121. void onenand_release(struct mtd_info *mtd)
  1122. {
  1123. }