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