denali.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  1. /*
  2. * NAND Flash Controller Device Driver
  3. * Copyright © 2009-2010, Intel Corporation and its suppliers.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #include <linux/interrupt.h>
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/wait.h>
  23. #include <linux/mutex.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/module.h>
  28. #include "denali.h"
  29. MODULE_LICENSE("GPL");
  30. /* We define a module parameter that allows the user to override
  31. * the hardware and decide what timing mode should be used.
  32. */
  33. #define NAND_DEFAULT_TIMINGS -1
  34. static int onfi_timing_mode = NAND_DEFAULT_TIMINGS;
  35. module_param(onfi_timing_mode, int, S_IRUGO);
  36. MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting."
  37. " -1 indicates use default timings");
  38. #define DENALI_NAND_NAME "denali-nand"
  39. /* We define a macro here that combines all interrupts this driver uses into
  40. * a single constant value, for convenience. */
  41. #define DENALI_IRQ_ALL (INTR_STATUS__DMA_CMD_COMP | \
  42. INTR_STATUS__ECC_TRANSACTION_DONE | \
  43. INTR_STATUS__ECC_ERR | \
  44. INTR_STATUS__PROGRAM_FAIL | \
  45. INTR_STATUS__LOAD_COMP | \
  46. INTR_STATUS__PROGRAM_COMP | \
  47. INTR_STATUS__TIME_OUT | \
  48. INTR_STATUS__ERASE_FAIL | \
  49. INTR_STATUS__RST_COMP | \
  50. INTR_STATUS__ERASE_COMP)
  51. /* indicates whether or not the internal value for the flash bank is
  52. * valid or not */
  53. #define CHIP_SELECT_INVALID -1
  54. #define SUPPORT_8BITECC 1
  55. /* This macro divides two integers and rounds fractional values up
  56. * to the nearest integer value. */
  57. #define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y)))
  58. /* this macro allows us to convert from an MTD structure to our own
  59. * device context (denali) structure.
  60. */
  61. #define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
  62. /* These constants are defined by the driver to enable common driver
  63. * configuration options. */
  64. #define SPARE_ACCESS 0x41
  65. #define MAIN_ACCESS 0x42
  66. #define MAIN_SPARE_ACCESS 0x43
  67. #define DENALI_READ 0
  68. #define DENALI_WRITE 0x100
  69. /* types of device accesses. We can issue commands and get status */
  70. #define COMMAND_CYCLE 0
  71. #define ADDR_CYCLE 1
  72. #define STATUS_CYCLE 2
  73. /* this is a helper macro that allows us to
  74. * format the bank into the proper bits for the controller */
  75. #define BANK(x) ((x) << 24)
  76. /* List of platforms this NAND controller has be integrated into */
  77. static const struct pci_device_id denali_pci_ids[] = {
  78. { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
  79. { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
  80. { /* end: all zeroes */ }
  81. };
  82. /* forward declarations */
  83. static void clear_interrupts(struct denali_nand_info *denali);
  84. static uint32_t wait_for_irq(struct denali_nand_info *denali,
  85. uint32_t irq_mask);
  86. static void denali_irq_enable(struct denali_nand_info *denali,
  87. uint32_t int_mask);
  88. static uint32_t read_interrupt_status(struct denali_nand_info *denali);
  89. /* Certain operations for the denali NAND controller use
  90. * an indexed mode to read/write data. The operation is
  91. * performed by writing the address value of the command
  92. * to the device memory followed by the data. This function
  93. * abstracts this common operation.
  94. */
  95. static void index_addr(struct denali_nand_info *denali,
  96. uint32_t address, uint32_t data)
  97. {
  98. iowrite32(address, denali->flash_mem);
  99. iowrite32(data, denali->flash_mem + 0x10);
  100. }
  101. /* Perform an indexed read of the device */
  102. static void index_addr_read_data(struct denali_nand_info *denali,
  103. uint32_t address, uint32_t *pdata)
  104. {
  105. iowrite32(address, denali->flash_mem);
  106. *pdata = ioread32(denali->flash_mem + 0x10);
  107. }
  108. /* We need to buffer some data for some of the NAND core routines.
  109. * The operations manage buffering that data. */
  110. static void reset_buf(struct denali_nand_info *denali)
  111. {
  112. denali->buf.head = denali->buf.tail = 0;
  113. }
  114. static void write_byte_to_buf(struct denali_nand_info *denali, uint8_t byte)
  115. {
  116. BUG_ON(denali->buf.tail >= sizeof(denali->buf.buf));
  117. denali->buf.buf[denali->buf.tail++] = byte;
  118. }
  119. /* reads the status of the device */
  120. static void read_status(struct denali_nand_info *denali)
  121. {
  122. uint32_t cmd = 0x0;
  123. /* initialize the data buffer to store status */
  124. reset_buf(denali);
  125. cmd = ioread32(denali->flash_reg + WRITE_PROTECT);
  126. if (cmd)
  127. write_byte_to_buf(denali, NAND_STATUS_WP);
  128. else
  129. write_byte_to_buf(denali, 0);
  130. }
  131. /* resets a specific device connected to the core */
  132. static void reset_bank(struct denali_nand_info *denali)
  133. {
  134. uint32_t irq_status = 0;
  135. uint32_t irq_mask = INTR_STATUS__RST_COMP |
  136. INTR_STATUS__TIME_OUT;
  137. clear_interrupts(denali);
  138. iowrite32(1 << denali->flash_bank, denali->flash_reg + DEVICE_RESET);
  139. irq_status = wait_for_irq(denali, irq_mask);
  140. if (irq_status & INTR_STATUS__TIME_OUT)
  141. dev_err(denali->dev, "reset bank failed.\n");
  142. }
  143. /* Reset the flash controller */
  144. static uint16_t denali_nand_reset(struct denali_nand_info *denali)
  145. {
  146. uint32_t i;
  147. dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
  148. __FILE__, __LINE__, __func__);
  149. for (i = 0 ; i < denali->max_banks; i++)
  150. iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
  151. denali->flash_reg + INTR_STATUS(i));
  152. for (i = 0 ; i < denali->max_banks; i++) {
  153. iowrite32(1 << i, denali->flash_reg + DEVICE_RESET);
  154. while (!(ioread32(denali->flash_reg +
  155. INTR_STATUS(i)) &
  156. (INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT)))
  157. cpu_relax();
  158. if (ioread32(denali->flash_reg + INTR_STATUS(i)) &
  159. INTR_STATUS__TIME_OUT)
  160. dev_dbg(denali->dev,
  161. "NAND Reset operation timed out on bank %d\n", i);
  162. }
  163. for (i = 0; i < denali->max_banks; i++)
  164. iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
  165. denali->flash_reg + INTR_STATUS(i));
  166. return PASS;
  167. }
  168. /* this routine calculates the ONFI timing values for a given mode and
  169. * programs the clocking register accordingly. The mode is determined by
  170. * the get_onfi_nand_para routine.
  171. */
  172. static void nand_onfi_timing_set(struct denali_nand_info *denali,
  173. uint16_t mode)
  174. {
  175. uint16_t Trea[6] = {40, 30, 25, 20, 20, 16};
  176. uint16_t Trp[6] = {50, 25, 17, 15, 12, 10};
  177. uint16_t Treh[6] = {30, 15, 15, 10, 10, 7};
  178. uint16_t Trc[6] = {100, 50, 35, 30, 25, 20};
  179. uint16_t Trhoh[6] = {0, 15, 15, 15, 15, 15};
  180. uint16_t Trloh[6] = {0, 0, 0, 0, 5, 5};
  181. uint16_t Tcea[6] = {100, 45, 30, 25, 25, 25};
  182. uint16_t Tadl[6] = {200, 100, 100, 100, 70, 70};
  183. uint16_t Trhw[6] = {200, 100, 100, 100, 100, 100};
  184. uint16_t Trhz[6] = {200, 100, 100, 100, 100, 100};
  185. uint16_t Twhr[6] = {120, 80, 80, 60, 60, 60};
  186. uint16_t Tcs[6] = {70, 35, 25, 25, 20, 15};
  187. uint16_t TclsRising = 1;
  188. uint16_t data_invalid_rhoh, data_invalid_rloh, data_invalid;
  189. uint16_t dv_window = 0;
  190. uint16_t en_lo, en_hi;
  191. uint16_t acc_clks;
  192. uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt;
  193. dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
  194. __FILE__, __LINE__, __func__);
  195. en_lo = CEIL_DIV(Trp[mode], CLK_X);
  196. en_hi = CEIL_DIV(Treh[mode], CLK_X);
  197. #if ONFI_BLOOM_TIME
  198. if ((en_hi * CLK_X) < (Treh[mode] + 2))
  199. en_hi++;
  200. #endif
  201. if ((en_lo + en_hi) * CLK_X < Trc[mode])
  202. en_lo += CEIL_DIV((Trc[mode] - (en_lo + en_hi) * CLK_X), CLK_X);
  203. if ((en_lo + en_hi) < CLK_MULTI)
  204. en_lo += CLK_MULTI - en_lo - en_hi;
  205. while (dv_window < 8) {
  206. data_invalid_rhoh = en_lo * CLK_X + Trhoh[mode];
  207. data_invalid_rloh = (en_lo + en_hi) * CLK_X + Trloh[mode];
  208. data_invalid =
  209. data_invalid_rhoh <
  210. data_invalid_rloh ? data_invalid_rhoh : data_invalid_rloh;
  211. dv_window = data_invalid - Trea[mode];
  212. if (dv_window < 8)
  213. en_lo++;
  214. }
  215. acc_clks = CEIL_DIV(Trea[mode], CLK_X);
  216. while (((acc_clks * CLK_X) - Trea[mode]) < 3)
  217. acc_clks++;
  218. if ((data_invalid - acc_clks * CLK_X) < 2)
  219. dev_warn(denali->dev, "%s, Line %d: Warning!\n",
  220. __FILE__, __LINE__);
  221. addr_2_data = CEIL_DIV(Tadl[mode], CLK_X);
  222. re_2_we = CEIL_DIV(Trhw[mode], CLK_X);
  223. re_2_re = CEIL_DIV(Trhz[mode], CLK_X);
  224. we_2_re = CEIL_DIV(Twhr[mode], CLK_X);
  225. cs_cnt = CEIL_DIV((Tcs[mode] - Trp[mode]), CLK_X);
  226. if (!TclsRising)
  227. cs_cnt = CEIL_DIV(Tcs[mode], CLK_X);
  228. if (cs_cnt == 0)
  229. cs_cnt = 1;
  230. if (Tcea[mode]) {
  231. while (((cs_cnt * CLK_X) + Trea[mode]) < Tcea[mode])
  232. cs_cnt++;
  233. }
  234. #if MODE5_WORKAROUND
  235. if (mode == 5)
  236. acc_clks = 5;
  237. #endif
  238. /* Sighting 3462430: Temporary hack for MT29F128G08CJABAWP:B */
  239. if ((ioread32(denali->flash_reg + MANUFACTURER_ID) == 0) &&
  240. (ioread32(denali->flash_reg + DEVICE_ID) == 0x88))
  241. acc_clks = 6;
  242. iowrite32(acc_clks, denali->flash_reg + ACC_CLKS);
  243. iowrite32(re_2_we, denali->flash_reg + RE_2_WE);
  244. iowrite32(re_2_re, denali->flash_reg + RE_2_RE);
  245. iowrite32(we_2_re, denali->flash_reg + WE_2_RE);
  246. iowrite32(addr_2_data, denali->flash_reg + ADDR_2_DATA);
  247. iowrite32(en_lo, denali->flash_reg + RDWR_EN_LO_CNT);
  248. iowrite32(en_hi, denali->flash_reg + RDWR_EN_HI_CNT);
  249. iowrite32(cs_cnt, denali->flash_reg + CS_SETUP_CNT);
  250. }
  251. /* queries the NAND device to see what ONFI modes it supports. */
  252. static uint16_t get_onfi_nand_para(struct denali_nand_info *denali)
  253. {
  254. int i;
  255. /* we needn't to do a reset here because driver has already
  256. * reset all the banks before
  257. * */
  258. if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) &
  259. ONFI_TIMING_MODE__VALUE))
  260. return FAIL;
  261. for (i = 5; i > 0; i--) {
  262. if (ioread32(denali->flash_reg + ONFI_TIMING_MODE) &
  263. (0x01 << i))
  264. break;
  265. }
  266. nand_onfi_timing_set(denali, i);
  267. /* By now, all the ONFI devices we know support the page cache */
  268. /* rw feature. So here we enable the pipeline_rw_ahead feature */
  269. /* iowrite32(1, denali->flash_reg + CACHE_WRITE_ENABLE); */
  270. /* iowrite32(1, denali->flash_reg + CACHE_READ_ENABLE); */
  271. return PASS;
  272. }
  273. static void get_samsung_nand_para(struct denali_nand_info *denali,
  274. uint8_t device_id)
  275. {
  276. if (device_id == 0xd3) { /* Samsung K9WAG08U1A */
  277. /* Set timing register values according to datasheet */
  278. iowrite32(5, denali->flash_reg + ACC_CLKS);
  279. iowrite32(20, denali->flash_reg + RE_2_WE);
  280. iowrite32(12, denali->flash_reg + WE_2_RE);
  281. iowrite32(14, denali->flash_reg + ADDR_2_DATA);
  282. iowrite32(3, denali->flash_reg + RDWR_EN_LO_CNT);
  283. iowrite32(2, denali->flash_reg + RDWR_EN_HI_CNT);
  284. iowrite32(2, denali->flash_reg + CS_SETUP_CNT);
  285. }
  286. }
  287. static void get_toshiba_nand_para(struct denali_nand_info *denali)
  288. {
  289. uint32_t tmp;
  290. /* Workaround to fix a controller bug which reports a wrong */
  291. /* spare area size for some kind of Toshiba NAND device */
  292. if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) &&
  293. (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) {
  294. iowrite32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
  295. tmp = ioread32(denali->flash_reg + DEVICES_CONNECTED) *
  296. ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
  297. iowrite32(tmp,
  298. denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE);
  299. #if SUPPORT_15BITECC
  300. iowrite32(15, denali->flash_reg + ECC_CORRECTION);
  301. #elif SUPPORT_8BITECC
  302. iowrite32(8, denali->flash_reg + ECC_CORRECTION);
  303. #endif
  304. }
  305. }
  306. static void get_hynix_nand_para(struct denali_nand_info *denali,
  307. uint8_t device_id)
  308. {
  309. uint32_t main_size, spare_size;
  310. switch (device_id) {
  311. case 0xD5: /* Hynix H27UAG8T2A, H27UBG8U5A or H27UCG8VFA */
  312. case 0xD7: /* Hynix H27UDG8VEM, H27UCG8UDM or H27UCG8V5A */
  313. iowrite32(128, denali->flash_reg + PAGES_PER_BLOCK);
  314. iowrite32(4096, denali->flash_reg + DEVICE_MAIN_AREA_SIZE);
  315. iowrite32(224, denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
  316. main_size = 4096 *
  317. ioread32(denali->flash_reg + DEVICES_CONNECTED);
  318. spare_size = 224 *
  319. ioread32(denali->flash_reg + DEVICES_CONNECTED);
  320. iowrite32(main_size,
  321. denali->flash_reg + LOGICAL_PAGE_DATA_SIZE);
  322. iowrite32(spare_size,
  323. denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE);
  324. iowrite32(0, denali->flash_reg + DEVICE_WIDTH);
  325. #if SUPPORT_15BITECC
  326. iowrite32(15, denali->flash_reg + ECC_CORRECTION);
  327. #elif SUPPORT_8BITECC
  328. iowrite32(8, denali->flash_reg + ECC_CORRECTION);
  329. #endif
  330. break;
  331. default:
  332. dev_warn(denali->dev,
  333. "Spectra: Unknown Hynix NAND (Device ID: 0x%x)."
  334. "Will use default parameter values instead.\n",
  335. device_id);
  336. }
  337. }
  338. /* determines how many NAND chips are connected to the controller. Note for
  339. * Intel CE4100 devices we don't support more than one device.
  340. */
  341. static void find_valid_banks(struct denali_nand_info *denali)
  342. {
  343. uint32_t id[denali->max_banks];
  344. int i;
  345. denali->total_used_banks = 1;
  346. for (i = 0; i < denali->max_banks; i++) {
  347. index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90);
  348. index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0);
  349. index_addr_read_data(denali,
  350. (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]);
  351. dev_dbg(denali->dev,
  352. "Return 1st ID for bank[%d]: %x\n", i, id[i]);
  353. if (i == 0) {
  354. if (!(id[i] & 0x0ff))
  355. break; /* WTF? */
  356. } else {
  357. if ((id[i] & 0x0ff) == (id[0] & 0x0ff))
  358. denali->total_used_banks++;
  359. else
  360. break;
  361. }
  362. }
  363. if (denali->platform == INTEL_CE4100) {
  364. /* Platform limitations of the CE4100 device limit
  365. * users to a single chip solution for NAND.
  366. * Multichip support is not enabled.
  367. */
  368. if (denali->total_used_banks != 1) {
  369. dev_err(denali->dev,
  370. "Sorry, Intel CE4100 only supports "
  371. "a single NAND device.\n");
  372. BUG();
  373. }
  374. }
  375. dev_dbg(denali->dev,
  376. "denali->total_used_banks: %d\n", denali->total_used_banks);
  377. }
  378. /*
  379. * Use the configuration feature register to determine the maximum number of
  380. * banks that the hardware supports.
  381. */
  382. static void detect_max_banks(struct denali_nand_info *denali)
  383. {
  384. uint32_t features = ioread32(denali->flash_reg + FEATURES);
  385. denali->max_banks = 2 << (features & FEATURES__N_BANKS);
  386. }
  387. static void detect_partition_feature(struct denali_nand_info *denali)
  388. {
  389. /* For MRST platform, denali->fwblks represent the
  390. * number of blocks firmware is taken,
  391. * FW is in protect partition and MTD driver has no
  392. * permission to access it. So let driver know how many
  393. * blocks it can't touch.
  394. * */
  395. if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) {
  396. if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) &
  397. PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) {
  398. denali->fwblks =
  399. ((ioread32(denali->flash_reg + MIN_MAX_BANK(1)) &
  400. MIN_MAX_BANK__MIN_VALUE) *
  401. denali->blksperchip)
  402. +
  403. (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) &
  404. MIN_BLK_ADDR__VALUE);
  405. } else
  406. denali->fwblks = SPECTRA_START_BLOCK;
  407. } else
  408. denali->fwblks = SPECTRA_START_BLOCK;
  409. }
  410. static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
  411. {
  412. uint16_t status = PASS;
  413. uint32_t id_bytes[5], addr;
  414. uint8_t i, maf_id, device_id;
  415. dev_dbg(denali->dev,
  416. "%s, Line %d, Function: %s\n",
  417. __FILE__, __LINE__, __func__);
  418. /* Use read id method to get device ID and other
  419. * params. For some NAND chips, controller can't
  420. * report the correct device ID by reading from
  421. * DEVICE_ID register
  422. * */
  423. addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
  424. index_addr(denali, (uint32_t)addr | 0, 0x90);
  425. index_addr(denali, (uint32_t)addr | 1, 0);
  426. for (i = 0; i < 5; i++)
  427. index_addr_read_data(denali, addr | 2, &id_bytes[i]);
  428. maf_id = id_bytes[0];
  429. device_id = id_bytes[1];
  430. if (ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) &
  431. ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE) { /* ONFI 1.0 NAND */
  432. if (FAIL == get_onfi_nand_para(denali))
  433. return FAIL;
  434. } else if (maf_id == 0xEC) { /* Samsung NAND */
  435. get_samsung_nand_para(denali, device_id);
  436. } else if (maf_id == 0x98) { /* Toshiba NAND */
  437. get_toshiba_nand_para(denali);
  438. } else if (maf_id == 0xAD) { /* Hynix NAND */
  439. get_hynix_nand_para(denali, device_id);
  440. }
  441. dev_info(denali->dev,
  442. "Dump timing register values:"
  443. "acc_clks: %d, re_2_we: %d, re_2_re: %d\n"
  444. "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n"
  445. "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
  446. ioread32(denali->flash_reg + ACC_CLKS),
  447. ioread32(denali->flash_reg + RE_2_WE),
  448. ioread32(denali->flash_reg + RE_2_RE),
  449. ioread32(denali->flash_reg + WE_2_RE),
  450. ioread32(denali->flash_reg + ADDR_2_DATA),
  451. ioread32(denali->flash_reg + RDWR_EN_LO_CNT),
  452. ioread32(denali->flash_reg + RDWR_EN_HI_CNT),
  453. ioread32(denali->flash_reg + CS_SETUP_CNT));
  454. find_valid_banks(denali);
  455. detect_partition_feature(denali);
  456. /* If the user specified to override the default timings
  457. * with a specific ONFI mode, we apply those changes here.
  458. */
  459. if (onfi_timing_mode != NAND_DEFAULT_TIMINGS)
  460. nand_onfi_timing_set(denali, onfi_timing_mode);
  461. return status;
  462. }
  463. static void denali_set_intr_modes(struct denali_nand_info *denali,
  464. uint16_t INT_ENABLE)
  465. {
  466. dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
  467. __FILE__, __LINE__, __func__);
  468. if (INT_ENABLE)
  469. iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE);
  470. else
  471. iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE);
  472. }
  473. /* validation function to verify that the controlling software is making
  474. * a valid request
  475. */
  476. static inline bool is_flash_bank_valid(int flash_bank)
  477. {
  478. return (flash_bank >= 0 && flash_bank < 4);
  479. }
  480. static void denali_irq_init(struct denali_nand_info *denali)
  481. {
  482. uint32_t int_mask = 0;
  483. int i;
  484. /* Disable global interrupts */
  485. denali_set_intr_modes(denali, false);
  486. int_mask = DENALI_IRQ_ALL;
  487. /* Clear all status bits */
  488. for (i = 0; i < denali->max_banks; ++i)
  489. iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS(i));
  490. denali_irq_enable(denali, int_mask);
  491. }
  492. static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali)
  493. {
  494. denali_set_intr_modes(denali, false);
  495. free_irq(irqnum, denali);
  496. }
  497. static void denali_irq_enable(struct denali_nand_info *denali,
  498. uint32_t int_mask)
  499. {
  500. int i;
  501. for (i = 0; i < denali->max_banks; ++i)
  502. iowrite32(int_mask, denali->flash_reg + INTR_EN(i));
  503. }
  504. /* This function only returns when an interrupt that this driver cares about
  505. * occurs. This is to reduce the overhead of servicing interrupts
  506. */
  507. static inline uint32_t denali_irq_detected(struct denali_nand_info *denali)
  508. {
  509. return read_interrupt_status(denali) & DENALI_IRQ_ALL;
  510. }
  511. /* Interrupts are cleared by writing a 1 to the appropriate status bit */
  512. static inline void clear_interrupt(struct denali_nand_info *denali,
  513. uint32_t irq_mask)
  514. {
  515. uint32_t intr_status_reg = 0;
  516. intr_status_reg = INTR_STATUS(denali->flash_bank);
  517. iowrite32(irq_mask, denali->flash_reg + intr_status_reg);
  518. }
  519. static void clear_interrupts(struct denali_nand_info *denali)
  520. {
  521. uint32_t status = 0x0;
  522. spin_lock_irq(&denali->irq_lock);
  523. status = read_interrupt_status(denali);
  524. clear_interrupt(denali, status);
  525. denali->irq_status = 0x0;
  526. spin_unlock_irq(&denali->irq_lock);
  527. }
  528. static uint32_t read_interrupt_status(struct denali_nand_info *denali)
  529. {
  530. uint32_t intr_status_reg = 0;
  531. intr_status_reg = INTR_STATUS(denali->flash_bank);
  532. return ioread32(denali->flash_reg + intr_status_reg);
  533. }
  534. /* This is the interrupt service routine. It handles all interrupts
  535. * sent to this device. Note that on CE4100, this is a shared
  536. * interrupt.
  537. */
  538. static irqreturn_t denali_isr(int irq, void *dev_id)
  539. {
  540. struct denali_nand_info *denali = dev_id;
  541. uint32_t irq_status = 0x0;
  542. irqreturn_t result = IRQ_NONE;
  543. spin_lock(&denali->irq_lock);
  544. /* check to see if a valid NAND chip has
  545. * been selected.
  546. */
  547. if (is_flash_bank_valid(denali->flash_bank)) {
  548. /* check to see if controller generated
  549. * the interrupt, since this is a shared interrupt */
  550. irq_status = denali_irq_detected(denali);
  551. if (irq_status != 0) {
  552. /* handle interrupt */
  553. /* first acknowledge it */
  554. clear_interrupt(denali, irq_status);
  555. /* store the status in the device context for someone
  556. to read */
  557. denali->irq_status |= irq_status;
  558. /* notify anyone who cares that it happened */
  559. complete(&denali->complete);
  560. /* tell the OS that we've handled this */
  561. result = IRQ_HANDLED;
  562. }
  563. }
  564. spin_unlock(&denali->irq_lock);
  565. return result;
  566. }
  567. #define BANK(x) ((x) << 24)
  568. static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask)
  569. {
  570. unsigned long comp_res = 0;
  571. uint32_t intr_status = 0;
  572. bool retry = false;
  573. unsigned long timeout = msecs_to_jiffies(1000);
  574. do {
  575. comp_res =
  576. wait_for_completion_timeout(&denali->complete, timeout);
  577. spin_lock_irq(&denali->irq_lock);
  578. intr_status = denali->irq_status;
  579. if (intr_status & irq_mask) {
  580. denali->irq_status &= ~irq_mask;
  581. spin_unlock_irq(&denali->irq_lock);
  582. /* our interrupt was detected */
  583. break;
  584. } else {
  585. /* these are not the interrupts you are looking for -
  586. * need to wait again */
  587. spin_unlock_irq(&denali->irq_lock);
  588. retry = true;
  589. }
  590. } while (comp_res != 0);
  591. if (comp_res == 0) {
  592. /* timeout */
  593. printk(KERN_ERR "timeout occurred, status = 0x%x, mask = 0x%x\n",
  594. intr_status, irq_mask);
  595. intr_status = 0;
  596. }
  597. return intr_status;
  598. }
  599. /* This helper function setups the registers for ECC and whether or not
  600. * the spare area will be transferred. */
  601. static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
  602. bool transfer_spare)
  603. {
  604. int ecc_en_flag = 0, transfer_spare_flag = 0;
  605. /* set ECC, transfer spare bits if needed */
  606. ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
  607. transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0;
  608. /* Enable spare area/ECC per user's request. */
  609. iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE);
  610. iowrite32(transfer_spare_flag,
  611. denali->flash_reg + TRANSFER_SPARE_REG);
  612. }
  613. /* sends a pipeline command operation to the controller. See the Denali NAND
  614. * controller's user guide for more information (section 4.2.3.6).
  615. */
  616. static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
  617. bool ecc_en,
  618. bool transfer_spare,
  619. int access_type,
  620. int op)
  621. {
  622. int status = PASS;
  623. uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0,
  624. irq_mask = 0;
  625. if (op == DENALI_READ)
  626. irq_mask = INTR_STATUS__LOAD_COMP;
  627. else if (op == DENALI_WRITE)
  628. irq_mask = 0;
  629. else
  630. BUG();
  631. setup_ecc_for_xfer(denali, ecc_en, transfer_spare);
  632. /* clear interrupts */
  633. clear_interrupts(denali);
  634. addr = BANK(denali->flash_bank) | denali->page;
  635. if (op == DENALI_WRITE && access_type != SPARE_ACCESS) {
  636. cmd = MODE_01 | addr;
  637. iowrite32(cmd, denali->flash_mem);
  638. } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) {
  639. /* read spare area */
  640. cmd = MODE_10 | addr;
  641. index_addr(denali, (uint32_t)cmd, access_type);
  642. cmd = MODE_01 | addr;
  643. iowrite32(cmd, denali->flash_mem);
  644. } else if (op == DENALI_READ) {
  645. /* setup page read request for access type */
  646. cmd = MODE_10 | addr;
  647. index_addr(denali, (uint32_t)cmd, access_type);
  648. /* page 33 of the NAND controller spec indicates we should not
  649. use the pipeline commands in Spare area only mode. So we
  650. don't.
  651. */
  652. if (access_type == SPARE_ACCESS) {
  653. cmd = MODE_01 | addr;
  654. iowrite32(cmd, denali->flash_mem);
  655. } else {
  656. index_addr(denali, (uint32_t)cmd,
  657. 0x2000 | op | page_count);
  658. /* wait for command to be accepted
  659. * can always use status0 bit as the
  660. * mask is identical for each
  661. * bank. */
  662. irq_status = wait_for_irq(denali, irq_mask);
  663. if (irq_status == 0) {
  664. dev_err(denali->dev,
  665. "cmd, page, addr on timeout "
  666. "(0x%x, 0x%x, 0x%x)\n",
  667. cmd, denali->page, addr);
  668. status = FAIL;
  669. } else {
  670. cmd = MODE_01 | addr;
  671. iowrite32(cmd, denali->flash_mem);
  672. }
  673. }
  674. }
  675. return status;
  676. }
  677. /* helper function that simply writes a buffer to the flash */
  678. static int write_data_to_flash_mem(struct denali_nand_info *denali,
  679. const uint8_t *buf,
  680. int len)
  681. {
  682. uint32_t i = 0, *buf32;
  683. /* verify that the len is a multiple of 4. see comment in
  684. * read_data_from_flash_mem() */
  685. BUG_ON((len % 4) != 0);
  686. /* write the data to the flash memory */
  687. buf32 = (uint32_t *)buf;
  688. for (i = 0; i < len / 4; i++)
  689. iowrite32(*buf32++, denali->flash_mem + 0x10);
  690. return i*4; /* intent is to return the number of bytes read */
  691. }
  692. /* helper function that simply reads a buffer from the flash */
  693. static int read_data_from_flash_mem(struct denali_nand_info *denali,
  694. uint8_t *buf,
  695. int len)
  696. {
  697. uint32_t i = 0, *buf32;
  698. /* we assume that len will be a multiple of 4, if not
  699. * it would be nice to know about it ASAP rather than
  700. * have random failures...
  701. * This assumption is based on the fact that this
  702. * function is designed to be used to read flash pages,
  703. * which are typically multiples of 4...
  704. */
  705. BUG_ON((len % 4) != 0);
  706. /* transfer the data from the flash */
  707. buf32 = (uint32_t *)buf;
  708. for (i = 0; i < len / 4; i++)
  709. *buf32++ = ioread32(denali->flash_mem + 0x10);
  710. return i*4; /* intent is to return the number of bytes read */
  711. }
  712. /* writes OOB data to the device */
  713. static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
  714. {
  715. struct denali_nand_info *denali = mtd_to_denali(mtd);
  716. uint32_t irq_status = 0;
  717. uint32_t irq_mask = INTR_STATUS__PROGRAM_COMP |
  718. INTR_STATUS__PROGRAM_FAIL;
  719. int status = 0;
  720. denali->page = page;
  721. if (denali_send_pipeline_cmd(denali, false, false, SPARE_ACCESS,
  722. DENALI_WRITE) == PASS) {
  723. write_data_to_flash_mem(denali, buf, mtd->oobsize);
  724. /* wait for operation to complete */
  725. irq_status = wait_for_irq(denali, irq_mask);
  726. if (irq_status == 0) {
  727. dev_err(denali->dev, "OOB write failed\n");
  728. status = -EIO;
  729. }
  730. } else {
  731. dev_err(denali->dev, "unable to send pipeline command\n");
  732. status = -EIO;
  733. }
  734. return status;
  735. }
  736. /* reads OOB data from the device */
  737. static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
  738. {
  739. struct denali_nand_info *denali = mtd_to_denali(mtd);
  740. uint32_t irq_mask = INTR_STATUS__LOAD_COMP,
  741. irq_status = 0, addr = 0x0, cmd = 0x0;
  742. denali->page = page;
  743. if (denali_send_pipeline_cmd(denali, false, true, SPARE_ACCESS,
  744. DENALI_READ) == PASS) {
  745. read_data_from_flash_mem(denali, buf, mtd->oobsize);
  746. /* wait for command to be accepted
  747. * can always use status0 bit as the mask is identical for each
  748. * bank. */
  749. irq_status = wait_for_irq(denali, irq_mask);
  750. if (irq_status == 0)
  751. dev_err(denali->dev, "page on OOB timeout %d\n",
  752. denali->page);
  753. /* We set the device back to MAIN_ACCESS here as I observed
  754. * instability with the controller if you do a block erase
  755. * and the last transaction was a SPARE_ACCESS. Block erase
  756. * is reliable (according to the MTD test infrastructure)
  757. * if you are in MAIN_ACCESS.
  758. */
  759. addr = BANK(denali->flash_bank) | denali->page;
  760. cmd = MODE_10 | addr;
  761. index_addr(denali, (uint32_t)cmd, MAIN_ACCESS);
  762. }
  763. }
  764. /* this function examines buffers to see if they contain data that
  765. * indicate that the buffer is part of an erased region of flash.
  766. */
  767. bool is_erased(uint8_t *buf, int len)
  768. {
  769. int i = 0;
  770. for (i = 0; i < len; i++)
  771. if (buf[i] != 0xFF)
  772. return false;
  773. return true;
  774. }
  775. #define ECC_SECTOR_SIZE 512
  776. #define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)
  777. #define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET))
  778. #define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)
  779. #define ECC_ERROR_CORRECTABLE(x) (!((x) & ERR_CORRECTION_INFO__ERROR_TYPE))
  780. #define ECC_ERR_DEVICE(x) (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)
  781. #define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)
  782. static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
  783. uint32_t irq_status)
  784. {
  785. bool check_erased_page = false;
  786. if (irq_status & INTR_STATUS__ECC_ERR) {
  787. /* read the ECC errors. we'll ignore them for now */
  788. uint32_t err_address = 0, err_correction_info = 0;
  789. uint32_t err_byte = 0, err_sector = 0, err_device = 0;
  790. uint32_t err_correction_value = 0;
  791. denali_set_intr_modes(denali, false);
  792. do {
  793. err_address = ioread32(denali->flash_reg +
  794. ECC_ERROR_ADDRESS);
  795. err_sector = ECC_SECTOR(err_address);
  796. err_byte = ECC_BYTE(err_address);
  797. err_correction_info = ioread32(denali->flash_reg +
  798. ERR_CORRECTION_INFO);
  799. err_correction_value =
  800. ECC_CORRECTION_VALUE(err_correction_info);
  801. err_device = ECC_ERR_DEVICE(err_correction_info);
  802. if (ECC_ERROR_CORRECTABLE(err_correction_info)) {
  803. /* If err_byte is larger than ECC_SECTOR_SIZE,
  804. * means error happened in OOB, so we ignore
  805. * it. It's no need for us to correct it
  806. * err_device is represented the NAND error
  807. * bits are happened in if there are more
  808. * than one NAND connected.
  809. * */
  810. if (err_byte < ECC_SECTOR_SIZE) {
  811. int offset;
  812. offset = (err_sector *
  813. ECC_SECTOR_SIZE +
  814. err_byte) *
  815. denali->devnum +
  816. err_device;
  817. /* correct the ECC error */
  818. buf[offset] ^= err_correction_value;
  819. denali->mtd.ecc_stats.corrected++;
  820. }
  821. } else {
  822. /* if the error is not correctable, need to
  823. * look at the page to see if it is an erased
  824. * page. if so, then it's not a real ECC error
  825. * */
  826. check_erased_page = true;
  827. }
  828. } while (!ECC_LAST_ERR(err_correction_info));
  829. /* Once handle all ecc errors, controller will triger
  830. * a ECC_TRANSACTION_DONE interrupt, so here just wait
  831. * for a while for this interrupt
  832. * */
  833. while (!(read_interrupt_status(denali) &
  834. INTR_STATUS__ECC_TRANSACTION_DONE))
  835. cpu_relax();
  836. clear_interrupts(denali);
  837. denali_set_intr_modes(denali, true);
  838. }
  839. return check_erased_page;
  840. }
  841. /* programs the controller to either enable/disable DMA transfers */
  842. static void denali_enable_dma(struct denali_nand_info *denali, bool en)
  843. {
  844. uint32_t reg_val = 0x0;
  845. if (en)
  846. reg_val = DMA_ENABLE__FLAG;
  847. iowrite32(reg_val, denali->flash_reg + DMA_ENABLE);
  848. ioread32(denali->flash_reg + DMA_ENABLE);
  849. }
  850. /* setups the HW to perform the data DMA */
  851. static void denali_setup_dma(struct denali_nand_info *denali, int op)
  852. {
  853. uint32_t mode = 0x0;
  854. const int page_count = 1;
  855. dma_addr_t addr = denali->buf.dma_buf;
  856. mode = MODE_10 | BANK(denali->flash_bank);
  857. /* DMA is a four step process */
  858. /* 1. setup transfer type and # of pages */
  859. index_addr(denali, mode | denali->page, 0x2000 | op | page_count);
  860. /* 2. set memory high address bits 23:8 */
  861. index_addr(denali, mode | ((uint16_t)(addr >> 16) << 8), 0x2200);
  862. /* 3. set memory low address bits 23:8 */
  863. index_addr(denali, mode | ((uint16_t)addr << 8), 0x2300);
  864. /* 4. interrupt when complete, burst len = 64 bytes*/
  865. index_addr(denali, mode | 0x14000, 0x2400);
  866. }
  867. /* writes a page. user specifies type, and this function handles the
  868. * configuration details. */
  869. static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
  870. const uint8_t *buf, bool raw_xfer)
  871. {
  872. struct denali_nand_info *denali = mtd_to_denali(mtd);
  873. dma_addr_t addr = denali->buf.dma_buf;
  874. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  875. uint32_t irq_status = 0;
  876. uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
  877. INTR_STATUS__PROGRAM_FAIL;
  878. /* if it is a raw xfer, we want to disable ecc, and send
  879. * the spare area.
  880. * !raw_xfer - enable ecc
  881. * raw_xfer - transfer spare
  882. */
  883. setup_ecc_for_xfer(denali, !raw_xfer, raw_xfer);
  884. /* copy buffer into DMA buffer */
  885. memcpy(denali->buf.buf, buf, mtd->writesize);
  886. if (raw_xfer) {
  887. /* transfer the data to the spare area */
  888. memcpy(denali->buf.buf + mtd->writesize,
  889. chip->oob_poi,
  890. mtd->oobsize);
  891. }
  892. dma_sync_single_for_device(denali->dev, addr, size, DMA_TO_DEVICE);
  893. clear_interrupts(denali);
  894. denali_enable_dma(denali, true);
  895. denali_setup_dma(denali, DENALI_WRITE);
  896. /* wait for operation to complete */
  897. irq_status = wait_for_irq(denali, irq_mask);
  898. if (irq_status == 0) {
  899. dev_err(denali->dev,
  900. "timeout on write_page (type = %d)\n",
  901. raw_xfer);
  902. denali->status =
  903. (irq_status & INTR_STATUS__PROGRAM_FAIL) ?
  904. NAND_STATUS_FAIL : PASS;
  905. }
  906. denali_enable_dma(denali, false);
  907. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE);
  908. }
  909. /* NAND core entry points */
  910. /* this is the callback that the NAND core calls to write a page. Since
  911. * writing a page with ECC or without is similar, all the work is done
  912. * by write_page above.
  913. * */
  914. static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
  915. const uint8_t *buf)
  916. {
  917. /* for regular page writes, we let HW handle all the ECC
  918. * data written to the device. */
  919. write_page(mtd, chip, buf, false);
  920. }
  921. /* This is the callback that the NAND core calls to write a page without ECC.
  922. * raw access is similar to ECC page writes, so all the work is done in the
  923. * write_page() function above.
  924. */
  925. static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
  926. const uint8_t *buf)
  927. {
  928. /* for raw page writes, we want to disable ECC and simply write
  929. whatever data is in the buffer. */
  930. write_page(mtd, chip, buf, true);
  931. }
  932. static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
  933. int page)
  934. {
  935. return write_oob_data(mtd, chip->oob_poi, page);
  936. }
  937. static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
  938. int page, int sndcmd)
  939. {
  940. read_oob_data(mtd, chip->oob_poi, page);
  941. return 0; /* notify NAND core to send command to
  942. NAND device. */
  943. }
  944. static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
  945. uint8_t *buf, int page)
  946. {
  947. struct denali_nand_info *denali = mtd_to_denali(mtd);
  948. dma_addr_t addr = denali->buf.dma_buf;
  949. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  950. uint32_t irq_status = 0;
  951. uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
  952. INTR_STATUS__ECC_ERR;
  953. bool check_erased_page = false;
  954. if (page != denali->page) {
  955. dev_err(denali->dev, "IN %s: page %d is not"
  956. " equal to denali->page %d, investigate!!",
  957. __func__, page, denali->page);
  958. BUG();
  959. }
  960. setup_ecc_for_xfer(denali, true, false);
  961. denali_enable_dma(denali, true);
  962. dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
  963. clear_interrupts(denali);
  964. denali_setup_dma(denali, DENALI_READ);
  965. /* wait for operation to complete */
  966. irq_status = wait_for_irq(denali, irq_mask);
  967. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
  968. memcpy(buf, denali->buf.buf, mtd->writesize);
  969. check_erased_page = handle_ecc(denali, buf, irq_status);
  970. denali_enable_dma(denali, false);
  971. if (check_erased_page) {
  972. read_oob_data(&denali->mtd, chip->oob_poi, denali->page);
  973. /* check ECC failures that may have occurred on erased pages */
  974. if (check_erased_page) {
  975. if (!is_erased(buf, denali->mtd.writesize))
  976. denali->mtd.ecc_stats.failed++;
  977. if (!is_erased(buf, denali->mtd.oobsize))
  978. denali->mtd.ecc_stats.failed++;
  979. }
  980. }
  981. return 0;
  982. }
  983. static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
  984. uint8_t *buf, int page)
  985. {
  986. struct denali_nand_info *denali = mtd_to_denali(mtd);
  987. dma_addr_t addr = denali->buf.dma_buf;
  988. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  989. uint32_t irq_status = 0;
  990. uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP;
  991. if (page != denali->page) {
  992. dev_err(denali->dev, "IN %s: page %d is not"
  993. " equal to denali->page %d, investigate!!",
  994. __func__, page, denali->page);
  995. BUG();
  996. }
  997. setup_ecc_for_xfer(denali, false, true);
  998. denali_enable_dma(denali, true);
  999. dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
  1000. clear_interrupts(denali);
  1001. denali_setup_dma(denali, DENALI_READ);
  1002. /* wait for operation to complete */
  1003. irq_status = wait_for_irq(denali, irq_mask);
  1004. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
  1005. denali_enable_dma(denali, false);
  1006. memcpy(buf, denali->buf.buf, mtd->writesize);
  1007. memcpy(chip->oob_poi, denali->buf.buf + mtd->writesize, mtd->oobsize);
  1008. return 0;
  1009. }
  1010. static uint8_t denali_read_byte(struct mtd_info *mtd)
  1011. {
  1012. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1013. uint8_t result = 0xff;
  1014. if (denali->buf.head < denali->buf.tail)
  1015. result = denali->buf.buf[denali->buf.head++];
  1016. return result;
  1017. }
  1018. static void denali_select_chip(struct mtd_info *mtd, int chip)
  1019. {
  1020. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1021. spin_lock_irq(&denali->irq_lock);
  1022. denali->flash_bank = chip;
  1023. spin_unlock_irq(&denali->irq_lock);
  1024. }
  1025. static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip)
  1026. {
  1027. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1028. int status = denali->status;
  1029. denali->status = 0;
  1030. return status;
  1031. }
  1032. static void denali_erase(struct mtd_info *mtd, int page)
  1033. {
  1034. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1035. uint32_t cmd = 0x0, irq_status = 0;
  1036. /* clear interrupts */
  1037. clear_interrupts(denali);
  1038. /* setup page read request for access type */
  1039. cmd = MODE_10 | BANK(denali->flash_bank) | page;
  1040. index_addr(denali, (uint32_t)cmd, 0x1);
  1041. /* wait for erase to complete or failure to occur */
  1042. irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP |
  1043. INTR_STATUS__ERASE_FAIL);
  1044. denali->status = (irq_status & INTR_STATUS__ERASE_FAIL) ?
  1045. NAND_STATUS_FAIL : PASS;
  1046. }
  1047. static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
  1048. int page)
  1049. {
  1050. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1051. uint32_t addr, id;
  1052. int i;
  1053. switch (cmd) {
  1054. case NAND_CMD_PAGEPROG:
  1055. break;
  1056. case NAND_CMD_STATUS:
  1057. read_status(denali);
  1058. break;
  1059. case NAND_CMD_READID:
  1060. case NAND_CMD_PARAM:
  1061. reset_buf(denali);
  1062. /*sometimes ManufactureId read from register is not right
  1063. * e.g. some of Micron MT29F32G08QAA MLC NAND chips
  1064. * So here we send READID cmd to NAND insteand
  1065. * */
  1066. addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
  1067. index_addr(denali, (uint32_t)addr | 0, 0x90);
  1068. index_addr(denali, (uint32_t)addr | 1, 0);
  1069. for (i = 0; i < 5; i++) {
  1070. index_addr_read_data(denali,
  1071. (uint32_t)addr | 2,
  1072. &id);
  1073. write_byte_to_buf(denali, id);
  1074. }
  1075. break;
  1076. case NAND_CMD_READ0:
  1077. case NAND_CMD_SEQIN:
  1078. denali->page = page;
  1079. break;
  1080. case NAND_CMD_RESET:
  1081. reset_bank(denali);
  1082. break;
  1083. case NAND_CMD_READOOB:
  1084. /* TODO: Read OOB data */
  1085. break;
  1086. default:
  1087. printk(KERN_ERR ": unsupported command"
  1088. " received 0x%x\n", cmd);
  1089. break;
  1090. }
  1091. }
  1092. /* stubs for ECC functions not used by the NAND core */
  1093. static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data,
  1094. uint8_t *ecc_code)
  1095. {
  1096. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1097. dev_err(denali->dev,
  1098. "denali_ecc_calculate called unexpectedly\n");
  1099. BUG();
  1100. return -EIO;
  1101. }
  1102. static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data,
  1103. uint8_t *read_ecc, uint8_t *calc_ecc)
  1104. {
  1105. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1106. dev_err(denali->dev,
  1107. "denali_ecc_correct called unexpectedly\n");
  1108. BUG();
  1109. return -EIO;
  1110. }
  1111. static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
  1112. {
  1113. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1114. dev_err(denali->dev,
  1115. "denali_ecc_hwctl called unexpectedly\n");
  1116. BUG();
  1117. }
  1118. /* end NAND core entry points */
  1119. /* Initialization code to bring the device up to a known good state */
  1120. static void denali_hw_init(struct denali_nand_info *denali)
  1121. {
  1122. /* tell driver how many bit controller will skip before
  1123. * writing ECC code in OOB, this register may be already
  1124. * set by firmware. So we read this value out.
  1125. * if this value is 0, just let it be.
  1126. * */
  1127. denali->bbtskipbytes = ioread32(denali->flash_reg +
  1128. SPARE_AREA_SKIP_BYTES);
  1129. detect_max_banks(denali);
  1130. denali_nand_reset(denali);
  1131. iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED);
  1132. iowrite32(CHIP_EN_DONT_CARE__FLAG,
  1133. denali->flash_reg + CHIP_ENABLE_DONT_CARE);
  1134. iowrite32(0xffff, denali->flash_reg + SPARE_AREA_MARKER);
  1135. /* Should set value for these registers when init */
  1136. iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES);
  1137. iowrite32(1, denali->flash_reg + ECC_ENABLE);
  1138. denali_nand_timing_set(denali);
  1139. denali_irq_init(denali);
  1140. }
  1141. /* Althogh controller spec said SLC ECC is forceb to be 4bit,
  1142. * but denali controller in MRST only support 15bit and 8bit ECC
  1143. * correction
  1144. * */
  1145. #define ECC_8BITS 14
  1146. static struct nand_ecclayout nand_8bit_oob = {
  1147. .eccbytes = 14,
  1148. };
  1149. #define ECC_15BITS 26
  1150. static struct nand_ecclayout nand_15bit_oob = {
  1151. .eccbytes = 26,
  1152. };
  1153. static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
  1154. static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };
  1155. static struct nand_bbt_descr bbt_main_descr = {
  1156. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1157. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1158. .offs = 8,
  1159. .len = 4,
  1160. .veroffs = 12,
  1161. .maxblocks = 4,
  1162. .pattern = bbt_pattern,
  1163. };
  1164. static struct nand_bbt_descr bbt_mirror_descr = {
  1165. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1166. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1167. .offs = 8,
  1168. .len = 4,
  1169. .veroffs = 12,
  1170. .maxblocks = 4,
  1171. .pattern = mirror_pattern,
  1172. };
  1173. /* initialize driver data structures */
  1174. void denali_drv_init(struct denali_nand_info *denali)
  1175. {
  1176. denali->idx = 0;
  1177. /* setup interrupt handler */
  1178. /* the completion object will be used to notify
  1179. * the callee that the interrupt is done */
  1180. init_completion(&denali->complete);
  1181. /* the spinlock will be used to synchronize the ISR
  1182. * with any element that might be access shared
  1183. * data (interrupt status) */
  1184. spin_lock_init(&denali->irq_lock);
  1185. /* indicate that MTD has not selected a valid bank yet */
  1186. denali->flash_bank = CHIP_SELECT_INVALID;
  1187. /* initialize our irq_status variable to indicate no interrupts */
  1188. denali->irq_status = 0;
  1189. }
  1190. /* driver entry point */
  1191. static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1192. {
  1193. int ret = -ENODEV;
  1194. resource_size_t csr_base, mem_base;
  1195. unsigned long csr_len, mem_len;
  1196. struct denali_nand_info *denali;
  1197. denali = kzalloc(sizeof(*denali), GFP_KERNEL);
  1198. if (!denali)
  1199. return -ENOMEM;
  1200. ret = pci_enable_device(dev);
  1201. if (ret) {
  1202. printk(KERN_ERR "Spectra: pci_enable_device failed.\n");
  1203. goto failed_alloc_memery;
  1204. }
  1205. if (id->driver_data == INTEL_CE4100) {
  1206. /* Due to a silicon limitation, we can only support
  1207. * ONFI timing mode 1 and below.
  1208. */
  1209. if (onfi_timing_mode < -1 || onfi_timing_mode > 1) {
  1210. printk(KERN_ERR "Intel CE4100 only supports"
  1211. " ONFI timing mode 1 or below\n");
  1212. ret = -EINVAL;
  1213. goto failed_enable_dev;
  1214. }
  1215. denali->platform = INTEL_CE4100;
  1216. mem_base = pci_resource_start(dev, 0);
  1217. mem_len = pci_resource_len(dev, 1);
  1218. csr_base = pci_resource_start(dev, 1);
  1219. csr_len = pci_resource_len(dev, 1);
  1220. } else {
  1221. denali->platform = INTEL_MRST;
  1222. csr_base = pci_resource_start(dev, 0);
  1223. csr_len = pci_resource_len(dev, 0);
  1224. mem_base = pci_resource_start(dev, 1);
  1225. mem_len = pci_resource_len(dev, 1);
  1226. if (!mem_len) {
  1227. mem_base = csr_base + csr_len;
  1228. mem_len = csr_len;
  1229. }
  1230. }
  1231. /* Is 32-bit DMA supported? */
  1232. ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
  1233. if (ret) {
  1234. printk(KERN_ERR "Spectra: no usable DMA configuration\n");
  1235. goto failed_enable_dev;
  1236. }
  1237. denali->buf.dma_buf = dma_map_single(&dev->dev, denali->buf.buf,
  1238. DENALI_BUF_SIZE,
  1239. DMA_BIDIRECTIONAL);
  1240. if (dma_mapping_error(&dev->dev, denali->buf.dma_buf)) {
  1241. dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n");
  1242. goto failed_enable_dev;
  1243. }
  1244. pci_set_master(dev);
  1245. denali->dev = &dev->dev;
  1246. denali->mtd.dev.parent = &dev->dev;
  1247. ret = pci_request_regions(dev, DENALI_NAND_NAME);
  1248. if (ret) {
  1249. printk(KERN_ERR "Spectra: Unable to request memory regions\n");
  1250. goto failed_dma_map;
  1251. }
  1252. denali->flash_reg = ioremap_nocache(csr_base, csr_len);
  1253. if (!denali->flash_reg) {
  1254. printk(KERN_ERR "Spectra: Unable to remap memory region\n");
  1255. ret = -ENOMEM;
  1256. goto failed_req_regions;
  1257. }
  1258. denali->flash_mem = ioremap_nocache(mem_base, mem_len);
  1259. if (!denali->flash_mem) {
  1260. printk(KERN_ERR "Spectra: ioremap_nocache failed!");
  1261. ret = -ENOMEM;
  1262. goto failed_remap_reg;
  1263. }
  1264. denali_hw_init(denali);
  1265. denali_drv_init(denali);
  1266. /* denali_isr register is done after all the hardware
  1267. * initilization is finished*/
  1268. if (request_irq(dev->irq, denali_isr, IRQF_SHARED,
  1269. DENALI_NAND_NAME, denali)) {
  1270. printk(KERN_ERR "Spectra: Unable to allocate IRQ\n");
  1271. ret = -ENODEV;
  1272. goto failed_remap_mem;
  1273. }
  1274. /* now that our ISR is registered, we can enable interrupts */
  1275. denali_set_intr_modes(denali, true);
  1276. pci_set_drvdata(dev, denali);
  1277. denali->mtd.name = "denali-nand";
  1278. denali->mtd.owner = THIS_MODULE;
  1279. denali->mtd.priv = &denali->nand;
  1280. /* register the driver with the NAND core subsystem */
  1281. denali->nand.select_chip = denali_select_chip;
  1282. denali->nand.cmdfunc = denali_cmdfunc;
  1283. denali->nand.read_byte = denali_read_byte;
  1284. denali->nand.waitfunc = denali_waitfunc;
  1285. /* scan for NAND devices attached to the controller
  1286. * this is the first stage in a two step process to register
  1287. * with the nand subsystem */
  1288. if (nand_scan_ident(&denali->mtd, denali->max_banks, NULL)) {
  1289. ret = -ENXIO;
  1290. goto failed_req_irq;
  1291. }
  1292. /* MTD supported page sizes vary by kernel. We validate our
  1293. * kernel supports the device here.
  1294. */
  1295. if (denali->mtd.writesize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) {
  1296. ret = -ENODEV;
  1297. printk(KERN_ERR "Spectra: device size not supported by this "
  1298. "version of MTD.");
  1299. goto failed_req_irq;
  1300. }
  1301. /* support for multi nand
  1302. * MTD known nothing about multi nand,
  1303. * so we should tell it the real pagesize
  1304. * and anything necessery
  1305. */
  1306. denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED);
  1307. denali->nand.chipsize <<= (denali->devnum - 1);
  1308. denali->nand.page_shift += (denali->devnum - 1);
  1309. denali->nand.pagemask = (denali->nand.chipsize >>
  1310. denali->nand.page_shift) - 1;
  1311. denali->nand.bbt_erase_shift += (denali->devnum - 1);
  1312. denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift;
  1313. denali->nand.chip_shift += (denali->devnum - 1);
  1314. denali->mtd.writesize <<= (denali->devnum - 1);
  1315. denali->mtd.oobsize <<= (denali->devnum - 1);
  1316. denali->mtd.erasesize <<= (denali->devnum - 1);
  1317. denali->mtd.size = denali->nand.numchips * denali->nand.chipsize;
  1318. denali->bbtskipbytes *= denali->devnum;
  1319. /* second stage of the NAND scan
  1320. * this stage requires information regarding ECC and
  1321. * bad block management. */
  1322. /* Bad block management */
  1323. denali->nand.bbt_td = &bbt_main_descr;
  1324. denali->nand.bbt_md = &bbt_mirror_descr;
  1325. /* skip the scan for now until we have OOB read and write support */
  1326. denali->nand.bbt_options |= NAND_BBT_USE_FLASH;
  1327. denali->nand.options |= NAND_SKIP_BBTSCAN;
  1328. denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
  1329. /* Denali Controller only support 15bit and 8bit ECC in MRST,
  1330. * so just let controller do 15bit ECC for MLC and 8bit ECC for
  1331. * SLC if possible.
  1332. * */
  1333. if (denali->nand.cellinfo & 0xc &&
  1334. (denali->mtd.oobsize > (denali->bbtskipbytes +
  1335. ECC_15BITS * (denali->mtd.writesize /
  1336. ECC_SECTOR_SIZE)))) {
  1337. /* if MLC OOB size is large enough, use 15bit ECC*/
  1338. denali->nand.ecc.strength = 15;
  1339. denali->nand.ecc.layout = &nand_15bit_oob;
  1340. denali->nand.ecc.bytes = ECC_15BITS;
  1341. iowrite32(15, denali->flash_reg + ECC_CORRECTION);
  1342. } else if (denali->mtd.oobsize < (denali->bbtskipbytes +
  1343. ECC_8BITS * (denali->mtd.writesize /
  1344. ECC_SECTOR_SIZE))) {
  1345. printk(KERN_ERR "Your NAND chip OOB is not large enough to"
  1346. " contain 8bit ECC correction codes");
  1347. goto failed_req_irq;
  1348. } else {
  1349. denali->nand.ecc.strength = 8;
  1350. denali->nand.ecc.layout = &nand_8bit_oob;
  1351. denali->nand.ecc.bytes = ECC_8BITS;
  1352. iowrite32(8, denali->flash_reg + ECC_CORRECTION);
  1353. }
  1354. denali->nand.ecc.bytes *= denali->devnum;
  1355. denali->nand.ecc.strength *= denali->devnum;
  1356. denali->nand.ecc.layout->eccbytes *=
  1357. denali->mtd.writesize / ECC_SECTOR_SIZE;
  1358. denali->nand.ecc.layout->oobfree[0].offset =
  1359. denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes;
  1360. denali->nand.ecc.layout->oobfree[0].length =
  1361. denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes -
  1362. denali->bbtskipbytes;
  1363. /* Let driver know the total blocks number and
  1364. * how many blocks contained by each nand chip.
  1365. * blksperchip will help driver to know how many
  1366. * blocks is taken by FW.
  1367. * */
  1368. denali->totalblks = denali->mtd.size >>
  1369. denali->nand.phys_erase_shift;
  1370. denali->blksperchip = denali->totalblks / denali->nand.numchips;
  1371. /* These functions are required by the NAND core framework, otherwise,
  1372. * the NAND core will assert. However, we don't need them, so we'll stub
  1373. * them out. */
  1374. denali->nand.ecc.calculate = denali_ecc_calculate;
  1375. denali->nand.ecc.correct = denali_ecc_correct;
  1376. denali->nand.ecc.hwctl = denali_ecc_hwctl;
  1377. /* override the default read operations */
  1378. denali->nand.ecc.size = ECC_SECTOR_SIZE * denali->devnum;
  1379. denali->nand.ecc.read_page = denali_read_page;
  1380. denali->nand.ecc.read_page_raw = denali_read_page_raw;
  1381. denali->nand.ecc.write_page = denali_write_page;
  1382. denali->nand.ecc.write_page_raw = denali_write_page_raw;
  1383. denali->nand.ecc.read_oob = denali_read_oob;
  1384. denali->nand.ecc.write_oob = denali_write_oob;
  1385. denali->nand.erase_cmd = denali_erase;
  1386. if (nand_scan_tail(&denali->mtd)) {
  1387. ret = -ENXIO;
  1388. goto failed_req_irq;
  1389. }
  1390. ret = mtd_device_register(&denali->mtd, NULL, 0);
  1391. if (ret) {
  1392. dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n",
  1393. ret);
  1394. goto failed_req_irq;
  1395. }
  1396. return 0;
  1397. failed_req_irq:
  1398. denali_irq_cleanup(dev->irq, denali);
  1399. failed_remap_mem:
  1400. iounmap(denali->flash_mem);
  1401. failed_remap_reg:
  1402. iounmap(denali->flash_reg);
  1403. failed_req_regions:
  1404. pci_release_regions(dev);
  1405. failed_dma_map:
  1406. dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
  1407. DMA_BIDIRECTIONAL);
  1408. failed_enable_dev:
  1409. pci_disable_device(dev);
  1410. failed_alloc_memery:
  1411. kfree(denali);
  1412. return ret;
  1413. }
  1414. /* driver exit point */
  1415. static void denali_pci_remove(struct pci_dev *dev)
  1416. {
  1417. struct denali_nand_info *denali = pci_get_drvdata(dev);
  1418. nand_release(&denali->mtd);
  1419. denali_irq_cleanup(dev->irq, denali);
  1420. iounmap(denali->flash_reg);
  1421. iounmap(denali->flash_mem);
  1422. pci_release_regions(dev);
  1423. pci_disable_device(dev);
  1424. dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
  1425. DMA_BIDIRECTIONAL);
  1426. pci_set_drvdata(dev, NULL);
  1427. kfree(denali);
  1428. }
  1429. MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  1430. static struct pci_driver denali_pci_driver = {
  1431. .name = DENALI_NAND_NAME,
  1432. .id_table = denali_pci_ids,
  1433. .probe = denali_pci_probe,
  1434. .remove = denali_pci_remove,
  1435. };
  1436. static int __devinit denali_init(void)
  1437. {
  1438. printk(KERN_INFO "Spectra MTD driver\n");
  1439. return pci_register_driver(&denali_pci_driver);
  1440. }
  1441. /* Free memory */
  1442. static void __devexit denali_exit(void)
  1443. {
  1444. pci_unregister_driver(&denali_pci_driver);
  1445. }
  1446. module_init(denali_init);
  1447. module_exit(denali_exit);