mxc_nand.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. /*
  2. * Copyright 2004-2007 Freescale Semiconductor, Inc.
  3. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  4. * Copyright 2009 Ilya Yanok, <yanok@emcraft.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include <common.h>
  21. #include <nand.h>
  22. #include <linux/err.h>
  23. #include <asm/io.h>
  24. #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX35)
  25. #include <asm/arch/imx-regs.h>
  26. #endif
  27. #include <fsl_nfc.h>
  28. #define DRIVER_NAME "mxc_nand"
  29. struct mxc_nand_host {
  30. struct mtd_info mtd;
  31. struct nand_chip *nand;
  32. struct fsl_nfc_regs __iomem *regs;
  33. int spare_only;
  34. int status_request;
  35. int pagesize_2k;
  36. int clk_act;
  37. uint16_t col_addr;
  38. unsigned int page_addr;
  39. };
  40. static struct mxc_nand_host mxc_host;
  41. static struct mxc_nand_host *host = &mxc_host;
  42. /* Define delays in microsec for NAND device operations */
  43. #define TROP_US_DELAY 2000
  44. /* Macros to get byte and bit positions of ECC */
  45. #define COLPOS(x) ((x) >> 3)
  46. #define BITPOS(x) ((x) & 0xf)
  47. /* Define single bit Error positions in Main & Spare area */
  48. #define MAIN_SINGLEBIT_ERROR 0x4
  49. #define SPARE_SINGLEBIT_ERROR 0x1
  50. /* OOB placement block for use with hardware ecc generation */
  51. #if defined(MXC_NFC_V1)
  52. #ifndef CONFIG_SYS_NAND_LARGEPAGE
  53. static struct nand_ecclayout nand_hw_eccoob = {
  54. .eccbytes = 5,
  55. .eccpos = {6, 7, 8, 9, 10},
  56. .oobfree = { {0, 5}, {11, 5}, }
  57. };
  58. #else
  59. static struct nand_ecclayout nand_hw_eccoob2k = {
  60. .eccbytes = 20,
  61. .eccpos = {
  62. 6, 7, 8, 9, 10,
  63. 22, 23, 24, 25, 26,
  64. 38, 39, 40, 41, 42,
  65. 54, 55, 56, 57, 58,
  66. },
  67. .oobfree = { {2, 4}, {11, 11}, {27, 11}, {43, 11}, {59, 5} },
  68. };
  69. #endif
  70. #elif defined(MXC_NFC_V2_1)
  71. #ifndef CONFIG_SYS_NAND_LARGEPAGE
  72. static struct nand_ecclayout nand_hw_eccoob = {
  73. .eccbytes = 9,
  74. .eccpos = {7, 8, 9, 10, 11, 12, 13, 14, 15},
  75. .oobfree = { {2, 5} }
  76. };
  77. #else
  78. static struct nand_ecclayout nand_hw_eccoob2k = {
  79. .eccbytes = 36,
  80. .eccpos = {
  81. 7, 8, 9, 10, 11, 12, 13, 14, 15,
  82. 23, 24, 25, 26, 27, 28, 29, 30, 31,
  83. 39, 40, 41, 42, 43, 44, 45, 46, 47,
  84. 55, 56, 57, 58, 59, 60, 61, 62, 63,
  85. },
  86. .oobfree = { {2, 5}, {16, 7}, {32, 7}, {48, 7} },
  87. };
  88. #endif
  89. #endif
  90. #ifdef CONFIG_MX27
  91. static int is_16bit_nand(void)
  92. {
  93. struct system_control_regs *sc_regs =
  94. (struct system_control_regs *)IMX_SYSTEM_CTL_BASE;
  95. if (readl(&sc_regs->fmcr) & NF_16BIT_SEL)
  96. return 1;
  97. else
  98. return 0;
  99. }
  100. #elif defined(CONFIG_MX31)
  101. static int is_16bit_nand(void)
  102. {
  103. struct clock_control_regs *sc_regs =
  104. (struct clock_control_regs *)CCM_BASE;
  105. if (readl(&sc_regs->rcsr) & CCM_RCSR_NF16B)
  106. return 1;
  107. else
  108. return 0;
  109. }
  110. #elif defined(CONFIG_MX25) || defined(CONFIG_MX35)
  111. static int is_16bit_nand(void)
  112. {
  113. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  114. if (readl(&ccm->rcsr) & CCM_RCSR_NF_16BIT_SEL)
  115. return 1;
  116. else
  117. return 0;
  118. }
  119. #else
  120. #warning "8/16 bit NAND autodetection not supported"
  121. static int is_16bit_nand(void)
  122. {
  123. return 0;
  124. }
  125. #endif
  126. static uint32_t *mxc_nand_memcpy32(uint32_t *dest, uint32_t *source, size_t size)
  127. {
  128. uint32_t *d = dest;
  129. size >>= 2;
  130. while (size--)
  131. __raw_writel(__raw_readl(source++), d++);
  132. return dest;
  133. }
  134. /*
  135. * This function polls the NANDFC to wait for the basic operation to
  136. * complete by checking the INT bit of config2 register.
  137. */
  138. static void wait_op_done(struct mxc_nand_host *host, int max_retries,
  139. uint16_t param)
  140. {
  141. uint32_t tmp;
  142. while (max_retries-- > 0) {
  143. if (readw(&host->regs->config2) & NFC_INT) {
  144. tmp = readw(&host->regs->config2);
  145. tmp &= ~NFC_INT;
  146. writew(tmp, &host->regs->config2);
  147. break;
  148. }
  149. udelay(1);
  150. }
  151. if (max_retries < 0) {
  152. MTDDEBUG(MTD_DEBUG_LEVEL0, "%s(%d): INT not set\n",
  153. __func__, param);
  154. }
  155. }
  156. /*
  157. * This function issues the specified command to the NAND device and
  158. * waits for completion.
  159. */
  160. static void send_cmd(struct mxc_nand_host *host, uint16_t cmd)
  161. {
  162. MTDDEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x)\n", cmd);
  163. writew(cmd, &host->regs->flash_cmd);
  164. writew(NFC_CMD, &host->regs->config2);
  165. /* Wait for operation to complete */
  166. wait_op_done(host, TROP_US_DELAY, cmd);
  167. }
  168. /*
  169. * This function sends an address (or partial address) to the
  170. * NAND device. The address is used to select the source/destination for
  171. * a NAND command.
  172. */
  173. static void send_addr(struct mxc_nand_host *host, uint16_t addr)
  174. {
  175. MTDDEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x)\n", addr);
  176. writew(addr, &host->regs->flash_addr);
  177. writew(NFC_ADDR, &host->regs->config2);
  178. /* Wait for operation to complete */
  179. wait_op_done(host, TROP_US_DELAY, addr);
  180. }
  181. /*
  182. * This function requests the NANDFC to initiate the transfer
  183. * of data currently in the NANDFC RAM buffer to the NAND device.
  184. */
  185. static void send_prog_page(struct mxc_nand_host *host, uint8_t buf_id,
  186. int spare_only)
  187. {
  188. if (spare_only)
  189. MTDDEBUG(MTD_DEBUG_LEVEL1, "send_prog_page (%d)\n", spare_only);
  190. if (is_mxc_nfc_21()) {
  191. int i;
  192. /*
  193. * The controller copies the 64 bytes of spare data from
  194. * the first 16 bytes of each of the 4 64 byte spare buffers.
  195. * Copy the contiguous data starting in spare_area[0] to
  196. * the four spare area buffers.
  197. */
  198. for (i = 1; i < 4; i++) {
  199. void __iomem *src = &host->regs->spare_area[0][i * 16];
  200. void __iomem *dst = &host->regs->spare_area[i][0];
  201. mxc_nand_memcpy32(dst, src, 16);
  202. }
  203. }
  204. writew(buf_id, &host->regs->buf_addr);
  205. /* Configure spare or page+spare access */
  206. if (!host->pagesize_2k) {
  207. uint16_t config1 = readw(&host->regs->config1);
  208. if (spare_only)
  209. config1 |= NFC_SP_EN;
  210. else
  211. config1 &= ~NFC_SP_EN;
  212. writew(config1, &host->regs->config1);
  213. }
  214. writew(NFC_INPUT, &host->regs->config2);
  215. /* Wait for operation to complete */
  216. wait_op_done(host, TROP_US_DELAY, spare_only);
  217. }
  218. /*
  219. * Requests NANDFC to initiate the transfer of data from the
  220. * NAND device into in the NANDFC ram buffer.
  221. */
  222. static void send_read_page(struct mxc_nand_host *host, uint8_t buf_id,
  223. int spare_only)
  224. {
  225. MTDDEBUG(MTD_DEBUG_LEVEL3, "send_read_page (%d)\n", spare_only);
  226. writew(buf_id, &host->regs->buf_addr);
  227. /* Configure spare or page+spare access */
  228. if (!host->pagesize_2k) {
  229. uint32_t config1 = readw(&host->regs->config1);
  230. if (spare_only)
  231. config1 |= NFC_SP_EN;
  232. else
  233. config1 &= ~NFC_SP_EN;
  234. writew(config1, &host->regs->config1);
  235. }
  236. writew(NFC_OUTPUT, &host->regs->config2);
  237. /* Wait for operation to complete */
  238. wait_op_done(host, TROP_US_DELAY, spare_only);
  239. if (is_mxc_nfc_21()) {
  240. int i;
  241. /*
  242. * The controller copies the 64 bytes of spare data to
  243. * the first 16 bytes of each of the 4 spare buffers.
  244. * Make the data contiguous starting in spare_area[0].
  245. */
  246. for (i = 1; i < 4; i++) {
  247. void __iomem *src = &host->regs->spare_area[i][0];
  248. void __iomem *dst = &host->regs->spare_area[0][i * 16];
  249. mxc_nand_memcpy32(dst, src, 16);
  250. }
  251. }
  252. }
  253. /* Request the NANDFC to perform a read of the NAND device ID. */
  254. static void send_read_id(struct mxc_nand_host *host)
  255. {
  256. uint16_t tmp;
  257. /* NANDFC buffer 0 is used for device ID output */
  258. writew(0x0, &host->regs->buf_addr);
  259. /* Read ID into main buffer */
  260. tmp = readw(&host->regs->config1);
  261. tmp &= ~NFC_SP_EN;
  262. writew(tmp, &host->regs->config1);
  263. writew(NFC_ID, &host->regs->config2);
  264. /* Wait for operation to complete */
  265. wait_op_done(host, TROP_US_DELAY, 0);
  266. }
  267. /*
  268. * This function requests the NANDFC to perform a read of the
  269. * NAND device status and returns the current status.
  270. */
  271. static uint16_t get_dev_status(struct mxc_nand_host *host)
  272. {
  273. void __iomem *main_buf = host->regs->main_area[1];
  274. uint32_t store;
  275. uint16_t ret, tmp;
  276. /* Issue status request to NAND device */
  277. /* store the main area1 first word, later do recovery */
  278. store = readl(main_buf);
  279. /* NANDFC buffer 1 is used for device status */
  280. writew(1, &host->regs->buf_addr);
  281. /* Read status into main buffer */
  282. tmp = readw(&host->regs->config1);
  283. tmp &= ~NFC_SP_EN;
  284. writew(tmp, &host->regs->config1);
  285. writew(NFC_STATUS, &host->regs->config2);
  286. /* Wait for operation to complete */
  287. wait_op_done(host, TROP_US_DELAY, 0);
  288. /*
  289. * Status is placed in first word of main buffer
  290. * get status, then recovery area 1 data
  291. */
  292. ret = readw(main_buf);
  293. writel(store, main_buf);
  294. return ret;
  295. }
  296. /* This function is used by upper layer to checks if device is ready */
  297. static int mxc_nand_dev_ready(struct mtd_info *mtd)
  298. {
  299. /*
  300. * NFC handles R/B internally. Therefore, this function
  301. * always returns status as ready.
  302. */
  303. return 1;
  304. }
  305. static void _mxc_nand_enable_hwecc(struct mtd_info *mtd, int on)
  306. {
  307. struct nand_chip *nand_chip = mtd->priv;
  308. struct mxc_nand_host *host = nand_chip->priv;
  309. uint16_t tmp = readw(&host->regs->config1);
  310. if (on)
  311. tmp |= NFC_ECC_EN;
  312. else
  313. tmp &= ~NFC_ECC_EN;
  314. writew(tmp, &host->regs->config1);
  315. }
  316. #ifdef CONFIG_MXC_NAND_HWECC
  317. static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  318. {
  319. /*
  320. * If HW ECC is enabled, we turn it on during init. There is
  321. * no need to enable again here.
  322. */
  323. }
  324. #ifdef MXC_NFC_V2_1
  325. static int mxc_nand_read_oob_syndrome(struct mtd_info *mtd,
  326. struct nand_chip *chip,
  327. int page, int sndcmd)
  328. {
  329. struct mxc_nand_host *host = chip->priv;
  330. uint8_t *buf = chip->oob_poi;
  331. int length = mtd->oobsize;
  332. int eccpitch = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
  333. uint8_t *bufpoi = buf;
  334. int i, toread;
  335. MTDDEBUG(MTD_DEBUG_LEVEL0,
  336. "%s: Reading OOB area of page %u to oob %p\n",
  337. __FUNCTION__, host->page_addr, buf);
  338. chip->cmdfunc(mtd, NAND_CMD_READOOB, mtd->writesize, page);
  339. for (i = 0; i < chip->ecc.steps; i++) {
  340. toread = min_t(int, length, chip->ecc.prepad);
  341. if (toread) {
  342. chip->read_buf(mtd, bufpoi, toread);
  343. bufpoi += toread;
  344. length -= toread;
  345. }
  346. bufpoi += chip->ecc.bytes;
  347. host->col_addr += chip->ecc.bytes;
  348. length -= chip->ecc.bytes;
  349. toread = min_t(int, length, chip->ecc.postpad);
  350. if (toread) {
  351. chip->read_buf(mtd, bufpoi, toread);
  352. bufpoi += toread;
  353. length -= toread;
  354. }
  355. }
  356. if (length > 0)
  357. chip->read_buf(mtd, bufpoi, length);
  358. _mxc_nand_enable_hwecc(mtd, 0);
  359. chip->cmdfunc(mtd, NAND_CMD_READOOB,
  360. mtd->writesize + chip->ecc.prepad, page);
  361. bufpoi = buf + chip->ecc.prepad;
  362. length = mtd->oobsize - chip->ecc.prepad;
  363. for (i = 0; i < chip->ecc.steps; i++) {
  364. toread = min_t(int, length, chip->ecc.bytes);
  365. chip->read_buf(mtd, bufpoi, toread);
  366. bufpoi += eccpitch;
  367. length -= eccpitch;
  368. host->col_addr += chip->ecc.postpad + chip->ecc.prepad;
  369. }
  370. _mxc_nand_enable_hwecc(mtd, 1);
  371. return 1;
  372. }
  373. static int mxc_nand_read_page_raw_syndrome(struct mtd_info *mtd,
  374. struct nand_chip *chip,
  375. uint8_t *buf,
  376. int page)
  377. {
  378. struct mxc_nand_host *host = chip->priv;
  379. int eccsize = chip->ecc.size;
  380. int eccbytes = chip->ecc.bytes;
  381. int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
  382. uint8_t *oob = chip->oob_poi;
  383. int steps, size;
  384. int n;
  385. _mxc_nand_enable_hwecc(mtd, 0);
  386. chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, host->page_addr);
  387. for (n = 0, steps = chip->ecc.steps; steps > 0; n++, steps--) {
  388. host->col_addr = n * eccsize;
  389. chip->read_buf(mtd, buf, eccsize);
  390. buf += eccsize;
  391. host->col_addr = mtd->writesize + n * eccpitch;
  392. if (chip->ecc.prepad) {
  393. chip->read_buf(mtd, oob, chip->ecc.prepad);
  394. oob += chip->ecc.prepad;
  395. }
  396. chip->read_buf(mtd, oob, eccbytes);
  397. oob += eccbytes;
  398. if (chip->ecc.postpad) {
  399. chip->read_buf(mtd, oob, chip->ecc.postpad);
  400. oob += chip->ecc.postpad;
  401. }
  402. }
  403. size = mtd->oobsize - (oob - chip->oob_poi);
  404. if (size)
  405. chip->read_buf(mtd, oob, size);
  406. _mxc_nand_enable_hwecc(mtd, 1);
  407. return 0;
  408. }
  409. static int mxc_nand_read_page_syndrome(struct mtd_info *mtd,
  410. struct nand_chip *chip,
  411. uint8_t *buf,
  412. int page)
  413. {
  414. struct mxc_nand_host *host = chip->priv;
  415. int n, eccsize = chip->ecc.size;
  416. int eccbytes = chip->ecc.bytes;
  417. int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
  418. int eccsteps = chip->ecc.steps;
  419. uint8_t *p = buf;
  420. uint8_t *oob = chip->oob_poi;
  421. MTDDEBUG(MTD_DEBUG_LEVEL1, "Reading page %u to buf %p oob %p\n",
  422. host->page_addr, buf, oob);
  423. /* first read the data area and the available portion of OOB */
  424. for (n = 0; eccsteps; n++, eccsteps--, p += eccsize) {
  425. int stat;
  426. host->col_addr = n * eccsize;
  427. chip->read_buf(mtd, p, eccsize);
  428. host->col_addr = mtd->writesize + n * eccpitch;
  429. if (chip->ecc.prepad) {
  430. chip->read_buf(mtd, oob, chip->ecc.prepad);
  431. oob += chip->ecc.prepad;
  432. }
  433. stat = chip->ecc.correct(mtd, p, oob, NULL);
  434. if (stat < 0)
  435. mtd->ecc_stats.failed++;
  436. else
  437. mtd->ecc_stats.corrected += stat;
  438. oob += eccbytes;
  439. if (chip->ecc.postpad) {
  440. chip->read_buf(mtd, oob, chip->ecc.postpad);
  441. oob += chip->ecc.postpad;
  442. }
  443. }
  444. /* Calculate remaining oob bytes */
  445. n = mtd->oobsize - (oob - chip->oob_poi);
  446. if (n)
  447. chip->read_buf(mtd, oob, n);
  448. /* Then switch ECC off and read the OOB area to get the ECC code */
  449. _mxc_nand_enable_hwecc(mtd, 0);
  450. chip->cmdfunc(mtd, NAND_CMD_READOOB, mtd->writesize, host->page_addr);
  451. eccsteps = chip->ecc.steps;
  452. oob = chip->oob_poi + chip->ecc.prepad;
  453. for (n = 0; eccsteps; n++, eccsteps--, p += eccsize) {
  454. host->col_addr = mtd->writesize +
  455. n * eccpitch +
  456. chip->ecc.prepad;
  457. chip->read_buf(mtd, oob, eccbytes);
  458. oob += eccbytes + chip->ecc.postpad;
  459. }
  460. _mxc_nand_enable_hwecc(mtd, 1);
  461. return 0;
  462. }
  463. static int mxc_nand_write_oob_syndrome(struct mtd_info *mtd,
  464. struct nand_chip *chip, int page)
  465. {
  466. struct mxc_nand_host *host = chip->priv;
  467. int eccpitch = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
  468. int length = mtd->oobsize;
  469. int i, len, status, steps = chip->ecc.steps;
  470. const uint8_t *bufpoi = chip->oob_poi;
  471. chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page);
  472. for (i = 0; i < steps; i++) {
  473. len = min_t(int, length, eccpitch);
  474. chip->write_buf(mtd, bufpoi, len);
  475. bufpoi += len;
  476. length -= len;
  477. host->col_addr += chip->ecc.prepad + chip->ecc.postpad;
  478. }
  479. if (length > 0)
  480. chip->write_buf(mtd, bufpoi, length);
  481. chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
  482. status = chip->waitfunc(mtd, chip);
  483. return status & NAND_STATUS_FAIL ? -EIO : 0;
  484. }
  485. static void mxc_nand_write_page_raw_syndrome(struct mtd_info *mtd,
  486. struct nand_chip *chip,
  487. const uint8_t *buf)
  488. {
  489. struct mxc_nand_host *host = chip->priv;
  490. int eccsize = chip->ecc.size;
  491. int eccbytes = chip->ecc.bytes;
  492. int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
  493. uint8_t *oob = chip->oob_poi;
  494. int steps, size;
  495. int n;
  496. for (n = 0, steps = chip->ecc.steps; steps > 0; n++, steps--) {
  497. host->col_addr = n * eccsize;
  498. chip->write_buf(mtd, buf, eccsize);
  499. buf += eccsize;
  500. host->col_addr = mtd->writesize + n * eccpitch;
  501. if (chip->ecc.prepad) {
  502. chip->write_buf(mtd, oob, chip->ecc.prepad);
  503. oob += chip->ecc.prepad;
  504. }
  505. host->col_addr += eccbytes;
  506. oob += eccbytes;
  507. if (chip->ecc.postpad) {
  508. chip->write_buf(mtd, oob, chip->ecc.postpad);
  509. oob += chip->ecc.postpad;
  510. }
  511. }
  512. size = mtd->oobsize - (oob - chip->oob_poi);
  513. if (size)
  514. chip->write_buf(mtd, oob, size);
  515. }
  516. static void mxc_nand_write_page_syndrome(struct mtd_info *mtd,
  517. struct nand_chip *chip,
  518. const uint8_t *buf)
  519. {
  520. struct mxc_nand_host *host = chip->priv;
  521. int i, n, eccsize = chip->ecc.size;
  522. int eccbytes = chip->ecc.bytes;
  523. int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
  524. int eccsteps = chip->ecc.steps;
  525. const uint8_t *p = buf;
  526. uint8_t *oob = chip->oob_poi;
  527. chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
  528. for (i = n = 0;
  529. eccsteps;
  530. n++, eccsteps--, i += eccbytes, p += eccsize) {
  531. host->col_addr = n * eccsize;
  532. chip->write_buf(mtd, p, eccsize);
  533. host->col_addr = mtd->writesize + n * eccpitch;
  534. if (chip->ecc.prepad) {
  535. chip->write_buf(mtd, oob, chip->ecc.prepad);
  536. oob += chip->ecc.prepad;
  537. }
  538. chip->write_buf(mtd, oob, eccbytes);
  539. oob += eccbytes;
  540. if (chip->ecc.postpad) {
  541. chip->write_buf(mtd, oob, chip->ecc.postpad);
  542. oob += chip->ecc.postpad;
  543. }
  544. }
  545. /* Calculate remaining oob bytes */
  546. i = mtd->oobsize - (oob - chip->oob_poi);
  547. if (i)
  548. chip->write_buf(mtd, oob, i);
  549. }
  550. static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
  551. u_char *read_ecc, u_char *calc_ecc)
  552. {
  553. struct nand_chip *nand_chip = mtd->priv;
  554. struct mxc_nand_host *host = nand_chip->priv;
  555. uint32_t ecc_status = readl(&host->regs->ecc_status_result);
  556. int subpages = mtd->writesize / nand_chip->subpagesize;
  557. int pg2blk_shift = nand_chip->phys_erase_shift -
  558. nand_chip->page_shift;
  559. do {
  560. if ((ecc_status & 0xf) > 4) {
  561. static int last_bad = -1;
  562. if (last_bad != host->page_addr >> pg2blk_shift) {
  563. last_bad = host->page_addr >> pg2blk_shift;
  564. printk(KERN_DEBUG
  565. "MXC_NAND: HWECC uncorrectable ECC error"
  566. " in block %u page %u subpage %d\n",
  567. last_bad, host->page_addr,
  568. mtd->writesize / nand_chip->subpagesize
  569. - subpages);
  570. }
  571. return -1;
  572. }
  573. ecc_status >>= 4;
  574. subpages--;
  575. } while (subpages > 0);
  576. return 0;
  577. }
  578. #else
  579. #define mxc_nand_read_page_syndrome NULL
  580. #define mxc_nand_read_page_raw_syndrome NULL
  581. #define mxc_nand_read_oob_syndrome NULL
  582. #define mxc_nand_write_page_syndrome NULL
  583. #define mxc_nand_write_page_raw_syndrome NULL
  584. #define mxc_nand_write_oob_syndrome NULL
  585. static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
  586. u_char *read_ecc, u_char *calc_ecc)
  587. {
  588. struct nand_chip *nand_chip = mtd->priv;
  589. struct mxc_nand_host *host = nand_chip->priv;
  590. /*
  591. * 1-Bit errors are automatically corrected in HW. No need for
  592. * additional correction. 2-Bit errors cannot be corrected by
  593. * HW ECC, so we need to return failure
  594. */
  595. uint16_t ecc_status = readw(&host->regs->ecc_status_result);
  596. if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
  597. MTDDEBUG(MTD_DEBUG_LEVEL0,
  598. "MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
  599. return -1;
  600. }
  601. return 0;
  602. }
  603. #endif
  604. static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  605. u_char *ecc_code)
  606. {
  607. return 0;
  608. }
  609. #endif
  610. static u_char mxc_nand_read_byte(struct mtd_info *mtd)
  611. {
  612. struct nand_chip *nand_chip = mtd->priv;
  613. struct mxc_nand_host *host = nand_chip->priv;
  614. uint8_t ret = 0;
  615. uint16_t col;
  616. uint16_t __iomem *main_buf =
  617. (uint16_t __iomem *)host->regs->main_area[0];
  618. uint16_t __iomem *spare_buf =
  619. (uint16_t __iomem *)host->regs->spare_area[0];
  620. union {
  621. uint16_t word;
  622. uint8_t bytes[2];
  623. } nfc_word;
  624. /* Check for status request */
  625. if (host->status_request)
  626. return get_dev_status(host) & 0xFF;
  627. /* Get column for 16-bit access */
  628. col = host->col_addr >> 1;
  629. /* If we are accessing the spare region */
  630. if (host->spare_only)
  631. nfc_word.word = readw(&spare_buf[col]);
  632. else
  633. nfc_word.word = readw(&main_buf[col]);
  634. /* Pick upper/lower byte of word from RAM buffer */
  635. ret = nfc_word.bytes[host->col_addr & 0x1];
  636. /* Update saved column address */
  637. if (nand_chip->options & NAND_BUSWIDTH_16)
  638. host->col_addr += 2;
  639. else
  640. host->col_addr++;
  641. return ret;
  642. }
  643. static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
  644. {
  645. struct nand_chip *nand_chip = mtd->priv;
  646. struct mxc_nand_host *host = nand_chip->priv;
  647. uint16_t col, ret;
  648. uint16_t __iomem *p;
  649. MTDDEBUG(MTD_DEBUG_LEVEL3,
  650. "mxc_nand_read_word(col = %d)\n", host->col_addr);
  651. col = host->col_addr;
  652. /* Adjust saved column address */
  653. if (col < mtd->writesize && host->spare_only)
  654. col += mtd->writesize;
  655. if (col < mtd->writesize) {
  656. p = (uint16_t __iomem *)(host->regs->main_area[0] +
  657. (col >> 1));
  658. } else {
  659. p = (uint16_t __iomem *)(host->regs->spare_area[0] +
  660. ((col - mtd->writesize) >> 1));
  661. }
  662. if (col & 1) {
  663. union {
  664. uint16_t word;
  665. uint8_t bytes[2];
  666. } nfc_word[3];
  667. nfc_word[0].word = readw(p);
  668. nfc_word[1].word = readw(p + 1);
  669. nfc_word[2].bytes[0] = nfc_word[0].bytes[1];
  670. nfc_word[2].bytes[1] = nfc_word[1].bytes[0];
  671. ret = nfc_word[2].word;
  672. } else {
  673. ret = readw(p);
  674. }
  675. /* Update saved column address */
  676. host->col_addr = col + 2;
  677. return ret;
  678. }
  679. /*
  680. * Write data of length len to buffer buf. The data to be
  681. * written on NAND Flash is first copied to RAMbuffer. After the Data Input
  682. * Operation by the NFC, the data is written to NAND Flash
  683. */
  684. static void mxc_nand_write_buf(struct mtd_info *mtd,
  685. const u_char *buf, int len)
  686. {
  687. struct nand_chip *nand_chip = mtd->priv;
  688. struct mxc_nand_host *host = nand_chip->priv;
  689. int n, col, i = 0;
  690. MTDDEBUG(MTD_DEBUG_LEVEL3,
  691. "mxc_nand_write_buf(col = %d, len = %d)\n", host->col_addr,
  692. len);
  693. col = host->col_addr;
  694. /* Adjust saved column address */
  695. if (col < mtd->writesize && host->spare_only)
  696. col += mtd->writesize;
  697. n = mtd->writesize + mtd->oobsize - col;
  698. n = min(len, n);
  699. MTDDEBUG(MTD_DEBUG_LEVEL3,
  700. "%s:%d: col = %d, n = %d\n", __func__, __LINE__, col, n);
  701. while (n > 0) {
  702. void __iomem *p;
  703. if (col < mtd->writesize) {
  704. p = host->regs->main_area[0] + (col & ~3);
  705. } else {
  706. p = host->regs->spare_area[0] -
  707. mtd->writesize + (col & ~3);
  708. }
  709. MTDDEBUG(MTD_DEBUG_LEVEL3, "%s:%d: p = %p\n", __func__,
  710. __LINE__, p);
  711. if (((col | (unsigned long)&buf[i]) & 3) || n < 4) {
  712. union {
  713. uint32_t word;
  714. uint8_t bytes[4];
  715. } nfc_word;
  716. nfc_word.word = readl(p);
  717. nfc_word.bytes[col & 3] = buf[i++];
  718. n--;
  719. col++;
  720. writel(nfc_word.word, p);
  721. } else {
  722. int m = mtd->writesize - col;
  723. if (col >= mtd->writesize)
  724. m += mtd->oobsize;
  725. m = min(n, m) & ~3;
  726. MTDDEBUG(MTD_DEBUG_LEVEL3,
  727. "%s:%d: n = %d, m = %d, i = %d, col = %d\n",
  728. __func__, __LINE__, n, m, i, col);
  729. mxc_nand_memcpy32(p, (uint32_t *)&buf[i], m);
  730. col += m;
  731. i += m;
  732. n -= m;
  733. }
  734. }
  735. /* Update saved column address */
  736. host->col_addr = col;
  737. }
  738. /*
  739. * Read the data buffer from the NAND Flash. To read the data from NAND
  740. * Flash first the data output cycle is initiated by the NFC, which copies
  741. * the data to RAMbuffer. This data of length len is then copied to buffer buf.
  742. */
  743. static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  744. {
  745. struct nand_chip *nand_chip = mtd->priv;
  746. struct mxc_nand_host *host = nand_chip->priv;
  747. int n, col, i = 0;
  748. MTDDEBUG(MTD_DEBUG_LEVEL3,
  749. "mxc_nand_read_buf(col = %d, len = %d)\n", host->col_addr, len);
  750. col = host->col_addr;
  751. /* Adjust saved column address */
  752. if (col < mtd->writesize && host->spare_only)
  753. col += mtd->writesize;
  754. n = mtd->writesize + mtd->oobsize - col;
  755. n = min(len, n);
  756. while (n > 0) {
  757. void __iomem *p;
  758. if (col < mtd->writesize) {
  759. p = host->regs->main_area[0] + (col & ~3);
  760. } else {
  761. p = host->regs->spare_area[0] -
  762. mtd->writesize + (col & ~3);
  763. }
  764. if (((col | (int)&buf[i]) & 3) || n < 4) {
  765. union {
  766. uint32_t word;
  767. uint8_t bytes[4];
  768. } nfc_word;
  769. nfc_word.word = readl(p);
  770. buf[i++] = nfc_word.bytes[col & 3];
  771. n--;
  772. col++;
  773. } else {
  774. int m = mtd->writesize - col;
  775. if (col >= mtd->writesize)
  776. m += mtd->oobsize;
  777. m = min(n, m) & ~3;
  778. mxc_nand_memcpy32((uint32_t *)&buf[i], p, m);
  779. col += m;
  780. i += m;
  781. n -= m;
  782. }
  783. }
  784. /* Update saved column address */
  785. host->col_addr = col;
  786. }
  787. /*
  788. * Used by the upper layer to verify the data in NAND Flash
  789. * with the data in the buf.
  790. */
  791. static int mxc_nand_verify_buf(struct mtd_info *mtd,
  792. const u_char *buf, int len)
  793. {
  794. u_char tmp[256];
  795. uint bsize;
  796. while (len) {
  797. bsize = min(len, 256);
  798. mxc_nand_read_buf(mtd, tmp, bsize);
  799. if (memcmp(buf, tmp, bsize))
  800. return 1;
  801. buf += bsize;
  802. len -= bsize;
  803. }
  804. return 0;
  805. }
  806. /*
  807. * This function is used by upper layer for select and
  808. * deselect of the NAND chip
  809. */
  810. static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
  811. {
  812. struct nand_chip *nand_chip = mtd->priv;
  813. struct mxc_nand_host *host = nand_chip->priv;
  814. switch (chip) {
  815. case -1:
  816. /* TODO: Disable the NFC clock */
  817. if (host->clk_act)
  818. host->clk_act = 0;
  819. break;
  820. case 0:
  821. /* TODO: Enable the NFC clock */
  822. if (!host->clk_act)
  823. host->clk_act = 1;
  824. break;
  825. default:
  826. break;
  827. }
  828. }
  829. /*
  830. * Used by the upper layer to write command to NAND Flash for
  831. * different operations to be carried out on NAND Flash
  832. */
  833. void mxc_nand_command(struct mtd_info *mtd, unsigned command,
  834. int column, int page_addr)
  835. {
  836. struct nand_chip *nand_chip = mtd->priv;
  837. struct mxc_nand_host *host = nand_chip->priv;
  838. MTDDEBUG(MTD_DEBUG_LEVEL3,
  839. "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
  840. command, column, page_addr);
  841. /* Reset command state information */
  842. host->status_request = false;
  843. /* Command pre-processing step */
  844. switch (command) {
  845. case NAND_CMD_STATUS:
  846. host->col_addr = 0;
  847. host->status_request = true;
  848. break;
  849. case NAND_CMD_READ0:
  850. host->page_addr = page_addr;
  851. host->col_addr = column;
  852. host->spare_only = false;
  853. break;
  854. case NAND_CMD_READOOB:
  855. host->col_addr = column;
  856. host->spare_only = true;
  857. if (host->pagesize_2k)
  858. command = NAND_CMD_READ0; /* only READ0 is valid */
  859. break;
  860. case NAND_CMD_SEQIN:
  861. if (column >= mtd->writesize) {
  862. /*
  863. * before sending SEQIN command for partial write,
  864. * we need read one page out. FSL NFC does not support
  865. * partial write. It always sends out 512+ecc+512+ecc
  866. * for large page nand flash. But for small page nand
  867. * flash, it does support SPARE ONLY operation.
  868. */
  869. if (host->pagesize_2k) {
  870. /* call ourself to read a page */
  871. mxc_nand_command(mtd, NAND_CMD_READ0, 0,
  872. page_addr);
  873. }
  874. host->col_addr = column - mtd->writesize;
  875. host->spare_only = true;
  876. /* Set program pointer to spare region */
  877. if (!host->pagesize_2k)
  878. send_cmd(host, NAND_CMD_READOOB);
  879. } else {
  880. host->spare_only = false;
  881. host->col_addr = column;
  882. /* Set program pointer to page start */
  883. if (!host->pagesize_2k)
  884. send_cmd(host, NAND_CMD_READ0);
  885. }
  886. break;
  887. case NAND_CMD_PAGEPROG:
  888. send_prog_page(host, 0, host->spare_only);
  889. if (host->pagesize_2k && is_mxc_nfc_1()) {
  890. /* data in 4 areas */
  891. send_prog_page(host, 1, host->spare_only);
  892. send_prog_page(host, 2, host->spare_only);
  893. send_prog_page(host, 3, host->spare_only);
  894. }
  895. break;
  896. }
  897. /* Write out the command to the device. */
  898. send_cmd(host, command);
  899. /* Write out column address, if necessary */
  900. if (column != -1) {
  901. /*
  902. * MXC NANDFC can only perform full page+spare or
  903. * spare-only read/write. When the upper layers perform
  904. * a read/write buffer operation, we will use the saved
  905. * column address to index into the full page.
  906. */
  907. send_addr(host, 0);
  908. if (host->pagesize_2k)
  909. /* another col addr cycle for 2k page */
  910. send_addr(host, 0);
  911. }
  912. /* Write out page address, if necessary */
  913. if (page_addr != -1) {
  914. u32 page_mask = nand_chip->pagemask;
  915. do {
  916. send_addr(host, page_addr & 0xFF);
  917. page_addr >>= 8;
  918. page_mask >>= 8;
  919. } while (page_mask);
  920. }
  921. /* Command post-processing step */
  922. switch (command) {
  923. case NAND_CMD_RESET:
  924. break;
  925. case NAND_CMD_READOOB:
  926. case NAND_CMD_READ0:
  927. if (host->pagesize_2k) {
  928. /* send read confirm command */
  929. send_cmd(host, NAND_CMD_READSTART);
  930. /* read for each AREA */
  931. send_read_page(host, 0, host->spare_only);
  932. if (is_mxc_nfc_1()) {
  933. send_read_page(host, 1, host->spare_only);
  934. send_read_page(host, 2, host->spare_only);
  935. send_read_page(host, 3, host->spare_only);
  936. }
  937. } else {
  938. send_read_page(host, 0, host->spare_only);
  939. }
  940. break;
  941. case NAND_CMD_READID:
  942. host->col_addr = 0;
  943. send_read_id(host);
  944. break;
  945. case NAND_CMD_PAGEPROG:
  946. break;
  947. case NAND_CMD_STATUS:
  948. break;
  949. case NAND_CMD_ERASE2:
  950. break;
  951. }
  952. }
  953. #ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
  954. static u8 bbt_pattern[] = {'B', 'b', 't', '0' };
  955. static u8 mirror_pattern[] = {'1', 't', 'b', 'B' };
  956. static struct nand_bbt_descr bbt_main_descr = {
  957. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  958. NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  959. .offs = 0,
  960. .len = 4,
  961. .veroffs = 4,
  962. .maxblocks = 4,
  963. .pattern = bbt_pattern,
  964. };
  965. static struct nand_bbt_descr bbt_mirror_descr = {
  966. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  967. NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  968. .offs = 0,
  969. .len = 4,
  970. .veroffs = 4,
  971. .maxblocks = 4,
  972. .pattern = mirror_pattern,
  973. };
  974. #endif
  975. int board_nand_init(struct nand_chip *this)
  976. {
  977. struct mtd_info *mtd;
  978. #ifdef MXC_NFC_V2_1
  979. uint16_t tmp;
  980. #endif
  981. #ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
  982. this->options |= NAND_USE_FLASH_BBT;
  983. this->bbt_td = &bbt_main_descr;
  984. this->bbt_md = &bbt_mirror_descr;
  985. #endif
  986. /* structures must be linked */
  987. mtd = &host->mtd;
  988. mtd->priv = this;
  989. host->nand = this;
  990. /* 5 us command delay time */
  991. this->chip_delay = 5;
  992. this->priv = host;
  993. this->dev_ready = mxc_nand_dev_ready;
  994. this->cmdfunc = mxc_nand_command;
  995. this->select_chip = mxc_nand_select_chip;
  996. this->read_byte = mxc_nand_read_byte;
  997. this->read_word = mxc_nand_read_word;
  998. this->write_buf = mxc_nand_write_buf;
  999. this->read_buf = mxc_nand_read_buf;
  1000. this->verify_buf = mxc_nand_verify_buf;
  1001. host->regs = (struct fsl_nfc_regs __iomem *)CONFIG_MXC_NAND_REGS_BASE;
  1002. host->clk_act = 1;
  1003. #ifdef CONFIG_MXC_NAND_HWECC
  1004. this->ecc.calculate = mxc_nand_calculate_ecc;
  1005. this->ecc.hwctl = mxc_nand_enable_hwecc;
  1006. this->ecc.correct = mxc_nand_correct_data;
  1007. if (is_mxc_nfc_21()) {
  1008. this->ecc.mode = NAND_ECC_HW_SYNDROME;
  1009. this->ecc.read_page = mxc_nand_read_page_syndrome;
  1010. this->ecc.read_page_raw = mxc_nand_read_page_raw_syndrome;
  1011. this->ecc.read_oob = mxc_nand_read_oob_syndrome;
  1012. this->ecc.write_page = mxc_nand_write_page_syndrome;
  1013. this->ecc.write_page_raw = mxc_nand_write_page_raw_syndrome;
  1014. this->ecc.write_oob = mxc_nand_write_oob_syndrome;
  1015. this->ecc.bytes = 9;
  1016. this->ecc.prepad = 7;
  1017. } else {
  1018. this->ecc.mode = NAND_ECC_HW;
  1019. }
  1020. host->pagesize_2k = 0;
  1021. this->ecc.size = 512;
  1022. _mxc_nand_enable_hwecc(mtd, 1);
  1023. #else
  1024. this->ecc.layout = &nand_soft_eccoob;
  1025. this->ecc.mode = NAND_ECC_SOFT;
  1026. _mxc_nand_enable_hwecc(mtd, 0);
  1027. #endif
  1028. /* Reset NAND */
  1029. this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
  1030. /* NAND bus width determines access functions used by upper layer */
  1031. if (is_16bit_nand())
  1032. this->options |= NAND_BUSWIDTH_16;
  1033. #ifdef CONFIG_SYS_NAND_LARGEPAGE
  1034. host->pagesize_2k = 1;
  1035. this->ecc.layout = &nand_hw_eccoob2k;
  1036. #else
  1037. host->pagesize_2k = 0;
  1038. this->ecc.layout = &nand_hw_eccoob;
  1039. #endif
  1040. #ifdef MXC_NFC_V2_1
  1041. tmp = readw(&host->regs->config1);
  1042. tmp |= NFC_ONE_CYCLE;
  1043. tmp |= NFC_4_8N_ECC;
  1044. writew(tmp, &host->regs->config1);
  1045. if (host->pagesize_2k)
  1046. writew(64/2, &host->regs->spare_area_size);
  1047. else
  1048. writew(16/2, &host->regs->spare_area_size);
  1049. #endif
  1050. /*
  1051. * preset operation
  1052. * Unlock the internal RAM Buffer
  1053. */
  1054. writew(0x2, &host->regs->config);
  1055. /* Blocks to be unlocked */
  1056. writew(0x0, &host->regs->unlockstart_blkaddr);
  1057. /* Originally (Freescale LTIB 2.6.21) 0x4000 was written to the
  1058. * unlockend_blkaddr, but the magic 0x4000 does not always work
  1059. * when writing more than some 32 megabytes (on 2k page nands)
  1060. * However 0xFFFF doesn't seem to have this kind
  1061. * of limitation (tried it back and forth several times).
  1062. * The linux kernel driver sets this to 0xFFFF for the v2 controller
  1063. * only, but probably this was not tested there for v1.
  1064. * The very same limitation seems to apply to this kernel driver.
  1065. * This might be NAND chip specific and the i.MX31 datasheet is
  1066. * extremely vague about the semantics of this register.
  1067. */
  1068. writew(0xFFFF, &host->regs->unlockend_blkaddr);
  1069. /* Unlock Block Command for given address range */
  1070. writew(0x4, &host->regs->wrprot);
  1071. return 0;
  1072. }