denali.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  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 < LLD_MAX_FLASH_BANKS; i++)
  150. iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
  151. denali->flash_reg + INTR_STATUS(i));
  152. for (i = 0 ; i < LLD_MAX_FLASH_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 < LLD_MAX_FLASH_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[LLD_MAX_FLASH_BANKS];
  344. int i;
  345. denali->total_used_banks = 1;
  346. for (i = 0; i < LLD_MAX_FLASH_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. static void detect_partition_feature(struct denali_nand_info *denali)
  379. {
  380. /* For MRST platform, denali->fwblks represent the
  381. * number of blocks firmware is taken,
  382. * FW is in protect partition and MTD driver has no
  383. * permission to access it. So let driver know how many
  384. * blocks it can't touch.
  385. * */
  386. if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) {
  387. if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) &
  388. PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) {
  389. denali->fwblks =
  390. ((ioread32(denali->flash_reg + MIN_MAX_BANK(1)) &
  391. MIN_MAX_BANK__MIN_VALUE) *
  392. denali->blksperchip)
  393. +
  394. (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) &
  395. MIN_BLK_ADDR__VALUE);
  396. } else
  397. denali->fwblks = SPECTRA_START_BLOCK;
  398. } else
  399. denali->fwblks = SPECTRA_START_BLOCK;
  400. }
  401. static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
  402. {
  403. uint16_t status = PASS;
  404. uint32_t id_bytes[5], addr;
  405. uint8_t i, maf_id, device_id;
  406. dev_dbg(denali->dev,
  407. "%s, Line %d, Function: %s\n",
  408. __FILE__, __LINE__, __func__);
  409. /* Use read id method to get device ID and other
  410. * params. For some NAND chips, controller can't
  411. * report the correct device ID by reading from
  412. * DEVICE_ID register
  413. * */
  414. addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
  415. index_addr(denali, (uint32_t)addr | 0, 0x90);
  416. index_addr(denali, (uint32_t)addr | 1, 0);
  417. for (i = 0; i < 5; i++)
  418. index_addr_read_data(denali, addr | 2, &id_bytes[i]);
  419. maf_id = id_bytes[0];
  420. device_id = id_bytes[1];
  421. if (ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) &
  422. ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE) { /* ONFI 1.0 NAND */
  423. if (FAIL == get_onfi_nand_para(denali))
  424. return FAIL;
  425. } else if (maf_id == 0xEC) { /* Samsung NAND */
  426. get_samsung_nand_para(denali, device_id);
  427. } else if (maf_id == 0x98) { /* Toshiba NAND */
  428. get_toshiba_nand_para(denali);
  429. } else if (maf_id == 0xAD) { /* Hynix NAND */
  430. get_hynix_nand_para(denali, device_id);
  431. }
  432. dev_info(denali->dev,
  433. "Dump timing register values:"
  434. "acc_clks: %d, re_2_we: %d, re_2_re: %d\n"
  435. "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n"
  436. "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
  437. ioread32(denali->flash_reg + ACC_CLKS),
  438. ioread32(denali->flash_reg + RE_2_WE),
  439. ioread32(denali->flash_reg + RE_2_RE),
  440. ioread32(denali->flash_reg + WE_2_RE),
  441. ioread32(denali->flash_reg + ADDR_2_DATA),
  442. ioread32(denali->flash_reg + RDWR_EN_LO_CNT),
  443. ioread32(denali->flash_reg + RDWR_EN_HI_CNT),
  444. ioread32(denali->flash_reg + CS_SETUP_CNT));
  445. find_valid_banks(denali);
  446. detect_partition_feature(denali);
  447. /* If the user specified to override the default timings
  448. * with a specific ONFI mode, we apply those changes here.
  449. */
  450. if (onfi_timing_mode != NAND_DEFAULT_TIMINGS)
  451. nand_onfi_timing_set(denali, onfi_timing_mode);
  452. return status;
  453. }
  454. static void denali_set_intr_modes(struct denali_nand_info *denali,
  455. uint16_t INT_ENABLE)
  456. {
  457. dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
  458. __FILE__, __LINE__, __func__);
  459. if (INT_ENABLE)
  460. iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE);
  461. else
  462. iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE);
  463. }
  464. /* validation function to verify that the controlling software is making
  465. * a valid request
  466. */
  467. static inline bool is_flash_bank_valid(int flash_bank)
  468. {
  469. return (flash_bank >= 0 && flash_bank < 4);
  470. }
  471. static void denali_irq_init(struct denali_nand_info *denali)
  472. {
  473. uint32_t int_mask = 0;
  474. int i;
  475. /* Disable global interrupts */
  476. denali_set_intr_modes(denali, false);
  477. int_mask = DENALI_IRQ_ALL;
  478. /* Clear all status bits */
  479. for (i = 0; i < LLD_MAX_FLASH_BANKS; ++i)
  480. iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS(i));
  481. denali_irq_enable(denali, int_mask);
  482. }
  483. static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali)
  484. {
  485. denali_set_intr_modes(denali, false);
  486. free_irq(irqnum, denali);
  487. }
  488. static void denali_irq_enable(struct denali_nand_info *denali,
  489. uint32_t int_mask)
  490. {
  491. int i;
  492. for (i = 0; i < LLD_MAX_FLASH_BANKS; ++i)
  493. iowrite32(int_mask, denali->flash_reg + INTR_EN(i));
  494. }
  495. /* This function only returns when an interrupt that this driver cares about
  496. * occurs. This is to reduce the overhead of servicing interrupts
  497. */
  498. static inline uint32_t denali_irq_detected(struct denali_nand_info *denali)
  499. {
  500. return read_interrupt_status(denali) & DENALI_IRQ_ALL;
  501. }
  502. /* Interrupts are cleared by writing a 1 to the appropriate status bit */
  503. static inline void clear_interrupt(struct denali_nand_info *denali,
  504. uint32_t irq_mask)
  505. {
  506. uint32_t intr_status_reg = 0;
  507. intr_status_reg = INTR_STATUS(denali->flash_bank);
  508. iowrite32(irq_mask, denali->flash_reg + intr_status_reg);
  509. }
  510. static void clear_interrupts(struct denali_nand_info *denali)
  511. {
  512. uint32_t status = 0x0;
  513. spin_lock_irq(&denali->irq_lock);
  514. status = read_interrupt_status(denali);
  515. clear_interrupt(denali, status);
  516. denali->irq_status = 0x0;
  517. spin_unlock_irq(&denali->irq_lock);
  518. }
  519. static uint32_t read_interrupt_status(struct denali_nand_info *denali)
  520. {
  521. uint32_t intr_status_reg = 0;
  522. intr_status_reg = INTR_STATUS(denali->flash_bank);
  523. return ioread32(denali->flash_reg + intr_status_reg);
  524. }
  525. /* This is the interrupt service routine. It handles all interrupts
  526. * sent to this device. Note that on CE4100, this is a shared
  527. * interrupt.
  528. */
  529. static irqreturn_t denali_isr(int irq, void *dev_id)
  530. {
  531. struct denali_nand_info *denali = dev_id;
  532. uint32_t irq_status = 0x0;
  533. irqreturn_t result = IRQ_NONE;
  534. spin_lock(&denali->irq_lock);
  535. /* check to see if a valid NAND chip has
  536. * been selected.
  537. */
  538. if (is_flash_bank_valid(denali->flash_bank)) {
  539. /* check to see if controller generated
  540. * the interrupt, since this is a shared interrupt */
  541. irq_status = denali_irq_detected(denali);
  542. if (irq_status != 0) {
  543. /* handle interrupt */
  544. /* first acknowledge it */
  545. clear_interrupt(denali, irq_status);
  546. /* store the status in the device context for someone
  547. to read */
  548. denali->irq_status |= irq_status;
  549. /* notify anyone who cares that it happened */
  550. complete(&denali->complete);
  551. /* tell the OS that we've handled this */
  552. result = IRQ_HANDLED;
  553. }
  554. }
  555. spin_unlock(&denali->irq_lock);
  556. return result;
  557. }
  558. #define BANK(x) ((x) << 24)
  559. static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask)
  560. {
  561. unsigned long comp_res = 0;
  562. uint32_t intr_status = 0;
  563. bool retry = false;
  564. unsigned long timeout = msecs_to_jiffies(1000);
  565. do {
  566. comp_res =
  567. wait_for_completion_timeout(&denali->complete, timeout);
  568. spin_lock_irq(&denali->irq_lock);
  569. intr_status = denali->irq_status;
  570. if (intr_status & irq_mask) {
  571. denali->irq_status &= ~irq_mask;
  572. spin_unlock_irq(&denali->irq_lock);
  573. /* our interrupt was detected */
  574. break;
  575. } else {
  576. /* these are not the interrupts you are looking for -
  577. * need to wait again */
  578. spin_unlock_irq(&denali->irq_lock);
  579. retry = true;
  580. }
  581. } while (comp_res != 0);
  582. if (comp_res == 0) {
  583. /* timeout */
  584. printk(KERN_ERR "timeout occurred, status = 0x%x, mask = 0x%x\n",
  585. intr_status, irq_mask);
  586. intr_status = 0;
  587. }
  588. return intr_status;
  589. }
  590. /* This helper function setups the registers for ECC and whether or not
  591. * the spare area will be transferred. */
  592. static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
  593. bool transfer_spare)
  594. {
  595. int ecc_en_flag = 0, transfer_spare_flag = 0;
  596. /* set ECC, transfer spare bits if needed */
  597. ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
  598. transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0;
  599. /* Enable spare area/ECC per user's request. */
  600. iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE);
  601. iowrite32(transfer_spare_flag,
  602. denali->flash_reg + TRANSFER_SPARE_REG);
  603. }
  604. /* sends a pipeline command operation to the controller. See the Denali NAND
  605. * controller's user guide for more information (section 4.2.3.6).
  606. */
  607. static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
  608. bool ecc_en,
  609. bool transfer_spare,
  610. int access_type,
  611. int op)
  612. {
  613. int status = PASS;
  614. uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0,
  615. irq_mask = 0;
  616. if (op == DENALI_READ)
  617. irq_mask = INTR_STATUS__LOAD_COMP;
  618. else if (op == DENALI_WRITE)
  619. irq_mask = 0;
  620. else
  621. BUG();
  622. setup_ecc_for_xfer(denali, ecc_en, transfer_spare);
  623. /* clear interrupts */
  624. clear_interrupts(denali);
  625. addr = BANK(denali->flash_bank) | denali->page;
  626. if (op == DENALI_WRITE && access_type != SPARE_ACCESS) {
  627. cmd = MODE_01 | addr;
  628. iowrite32(cmd, denali->flash_mem);
  629. } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) {
  630. /* read spare area */
  631. cmd = MODE_10 | addr;
  632. index_addr(denali, (uint32_t)cmd, access_type);
  633. cmd = MODE_01 | addr;
  634. iowrite32(cmd, denali->flash_mem);
  635. } else if (op == DENALI_READ) {
  636. /* setup page read request for access type */
  637. cmd = MODE_10 | addr;
  638. index_addr(denali, (uint32_t)cmd, access_type);
  639. /* page 33 of the NAND controller spec indicates we should not
  640. use the pipeline commands in Spare area only mode. So we
  641. don't.
  642. */
  643. if (access_type == SPARE_ACCESS) {
  644. cmd = MODE_01 | addr;
  645. iowrite32(cmd, denali->flash_mem);
  646. } else {
  647. index_addr(denali, (uint32_t)cmd,
  648. 0x2000 | op | page_count);
  649. /* wait for command to be accepted
  650. * can always use status0 bit as the
  651. * mask is identical for each
  652. * bank. */
  653. irq_status = wait_for_irq(denali, irq_mask);
  654. if (irq_status == 0) {
  655. dev_err(denali->dev,
  656. "cmd, page, addr on timeout "
  657. "(0x%x, 0x%x, 0x%x)\n",
  658. cmd, denali->page, addr);
  659. status = FAIL;
  660. } else {
  661. cmd = MODE_01 | addr;
  662. iowrite32(cmd, denali->flash_mem);
  663. }
  664. }
  665. }
  666. return status;
  667. }
  668. /* helper function that simply writes a buffer to the flash */
  669. static int write_data_to_flash_mem(struct denali_nand_info *denali,
  670. const uint8_t *buf,
  671. int len)
  672. {
  673. uint32_t i = 0, *buf32;
  674. /* verify that the len is a multiple of 4. see comment in
  675. * read_data_from_flash_mem() */
  676. BUG_ON((len % 4) != 0);
  677. /* write the data to the flash memory */
  678. buf32 = (uint32_t *)buf;
  679. for (i = 0; i < len / 4; i++)
  680. iowrite32(*buf32++, denali->flash_mem + 0x10);
  681. return i*4; /* intent is to return the number of bytes read */
  682. }
  683. /* helper function that simply reads a buffer from the flash */
  684. static int read_data_from_flash_mem(struct denali_nand_info *denali,
  685. uint8_t *buf,
  686. int len)
  687. {
  688. uint32_t i = 0, *buf32;
  689. /* we assume that len will be a multiple of 4, if not
  690. * it would be nice to know about it ASAP rather than
  691. * have random failures...
  692. * This assumption is based on the fact that this
  693. * function is designed to be used to read flash pages,
  694. * which are typically multiples of 4...
  695. */
  696. BUG_ON((len % 4) != 0);
  697. /* transfer the data from the flash */
  698. buf32 = (uint32_t *)buf;
  699. for (i = 0; i < len / 4; i++)
  700. *buf32++ = ioread32(denali->flash_mem + 0x10);
  701. return i*4; /* intent is to return the number of bytes read */
  702. }
  703. /* writes OOB data to the device */
  704. static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
  705. {
  706. struct denali_nand_info *denali = mtd_to_denali(mtd);
  707. uint32_t irq_status = 0;
  708. uint32_t irq_mask = INTR_STATUS__PROGRAM_COMP |
  709. INTR_STATUS__PROGRAM_FAIL;
  710. int status = 0;
  711. denali->page = page;
  712. if (denali_send_pipeline_cmd(denali, false, false, SPARE_ACCESS,
  713. DENALI_WRITE) == PASS) {
  714. write_data_to_flash_mem(denali, buf, mtd->oobsize);
  715. /* wait for operation to complete */
  716. irq_status = wait_for_irq(denali, irq_mask);
  717. if (irq_status == 0) {
  718. dev_err(denali->dev, "OOB write failed\n");
  719. status = -EIO;
  720. }
  721. } else {
  722. dev_err(denali->dev, "unable to send pipeline command\n");
  723. status = -EIO;
  724. }
  725. return status;
  726. }
  727. /* reads OOB data from the device */
  728. static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
  729. {
  730. struct denali_nand_info *denali = mtd_to_denali(mtd);
  731. uint32_t irq_mask = INTR_STATUS__LOAD_COMP,
  732. irq_status = 0, addr = 0x0, cmd = 0x0;
  733. denali->page = page;
  734. if (denali_send_pipeline_cmd(denali, false, true, SPARE_ACCESS,
  735. DENALI_READ) == PASS) {
  736. read_data_from_flash_mem(denali, buf, mtd->oobsize);
  737. /* wait for command to be accepted
  738. * can always use status0 bit as the mask is identical for each
  739. * bank. */
  740. irq_status = wait_for_irq(denali, irq_mask);
  741. if (irq_status == 0)
  742. dev_err(denali->dev, "page on OOB timeout %d\n",
  743. denali->page);
  744. /* We set the device back to MAIN_ACCESS here as I observed
  745. * instability with the controller if you do a block erase
  746. * and the last transaction was a SPARE_ACCESS. Block erase
  747. * is reliable (according to the MTD test infrastructure)
  748. * if you are in MAIN_ACCESS.
  749. */
  750. addr = BANK(denali->flash_bank) | denali->page;
  751. cmd = MODE_10 | addr;
  752. index_addr(denali, (uint32_t)cmd, MAIN_ACCESS);
  753. }
  754. }
  755. /* this function examines buffers to see if they contain data that
  756. * indicate that the buffer is part of an erased region of flash.
  757. */
  758. bool is_erased(uint8_t *buf, int len)
  759. {
  760. int i = 0;
  761. for (i = 0; i < len; i++)
  762. if (buf[i] != 0xFF)
  763. return false;
  764. return true;
  765. }
  766. #define ECC_SECTOR_SIZE 512
  767. #define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)
  768. #define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET))
  769. #define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)
  770. #define ECC_ERROR_CORRECTABLE(x) (!((x) & ERR_CORRECTION_INFO__ERROR_TYPE))
  771. #define ECC_ERR_DEVICE(x) (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)
  772. #define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)
  773. static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
  774. uint32_t irq_status)
  775. {
  776. bool check_erased_page = false;
  777. if (irq_status & INTR_STATUS__ECC_ERR) {
  778. /* read the ECC errors. we'll ignore them for now */
  779. uint32_t err_address = 0, err_correction_info = 0;
  780. uint32_t err_byte = 0, err_sector = 0, err_device = 0;
  781. uint32_t err_correction_value = 0;
  782. denali_set_intr_modes(denali, false);
  783. do {
  784. err_address = ioread32(denali->flash_reg +
  785. ECC_ERROR_ADDRESS);
  786. err_sector = ECC_SECTOR(err_address);
  787. err_byte = ECC_BYTE(err_address);
  788. err_correction_info = ioread32(denali->flash_reg +
  789. ERR_CORRECTION_INFO);
  790. err_correction_value =
  791. ECC_CORRECTION_VALUE(err_correction_info);
  792. err_device = ECC_ERR_DEVICE(err_correction_info);
  793. if (ECC_ERROR_CORRECTABLE(err_correction_info)) {
  794. /* If err_byte is larger than ECC_SECTOR_SIZE,
  795. * means error happened in OOB, so we ignore
  796. * it. It's no need for us to correct it
  797. * err_device is represented the NAND error
  798. * bits are happened in if there are more
  799. * than one NAND connected.
  800. * */
  801. if (err_byte < ECC_SECTOR_SIZE) {
  802. int offset;
  803. offset = (err_sector *
  804. ECC_SECTOR_SIZE +
  805. err_byte) *
  806. denali->devnum +
  807. err_device;
  808. /* correct the ECC error */
  809. buf[offset] ^= err_correction_value;
  810. denali->mtd.ecc_stats.corrected++;
  811. }
  812. } else {
  813. /* if the error is not correctable, need to
  814. * look at the page to see if it is an erased
  815. * page. if so, then it's not a real ECC error
  816. * */
  817. check_erased_page = true;
  818. }
  819. } while (!ECC_LAST_ERR(err_correction_info));
  820. /* Once handle all ecc errors, controller will triger
  821. * a ECC_TRANSACTION_DONE interrupt, so here just wait
  822. * for a while for this interrupt
  823. * */
  824. while (!(read_interrupt_status(denali) &
  825. INTR_STATUS__ECC_TRANSACTION_DONE))
  826. cpu_relax();
  827. clear_interrupts(denali);
  828. denali_set_intr_modes(denali, true);
  829. }
  830. return check_erased_page;
  831. }
  832. /* programs the controller to either enable/disable DMA transfers */
  833. static void denali_enable_dma(struct denali_nand_info *denali, bool en)
  834. {
  835. uint32_t reg_val = 0x0;
  836. if (en)
  837. reg_val = DMA_ENABLE__FLAG;
  838. iowrite32(reg_val, denali->flash_reg + DMA_ENABLE);
  839. ioread32(denali->flash_reg + DMA_ENABLE);
  840. }
  841. /* setups the HW to perform the data DMA */
  842. static void denali_setup_dma(struct denali_nand_info *denali, int op)
  843. {
  844. uint32_t mode = 0x0;
  845. const int page_count = 1;
  846. dma_addr_t addr = denali->buf.dma_buf;
  847. mode = MODE_10 | BANK(denali->flash_bank);
  848. /* DMA is a four step process */
  849. /* 1. setup transfer type and # of pages */
  850. index_addr(denali, mode | denali->page, 0x2000 | op | page_count);
  851. /* 2. set memory high address bits 23:8 */
  852. index_addr(denali, mode | ((uint16_t)(addr >> 16) << 8), 0x2200);
  853. /* 3. set memory low address bits 23:8 */
  854. index_addr(denali, mode | ((uint16_t)addr << 8), 0x2300);
  855. /* 4. interrupt when complete, burst len = 64 bytes*/
  856. index_addr(denali, mode | 0x14000, 0x2400);
  857. }
  858. /* writes a page. user specifies type, and this function handles the
  859. * configuration details. */
  860. static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
  861. const uint8_t *buf, bool raw_xfer)
  862. {
  863. struct denali_nand_info *denali = mtd_to_denali(mtd);
  864. dma_addr_t addr = denali->buf.dma_buf;
  865. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  866. uint32_t irq_status = 0;
  867. uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
  868. INTR_STATUS__PROGRAM_FAIL;
  869. /* if it is a raw xfer, we want to disable ecc, and send
  870. * the spare area.
  871. * !raw_xfer - enable ecc
  872. * raw_xfer - transfer spare
  873. */
  874. setup_ecc_for_xfer(denali, !raw_xfer, raw_xfer);
  875. /* copy buffer into DMA buffer */
  876. memcpy(denali->buf.buf, buf, mtd->writesize);
  877. if (raw_xfer) {
  878. /* transfer the data to the spare area */
  879. memcpy(denali->buf.buf + mtd->writesize,
  880. chip->oob_poi,
  881. mtd->oobsize);
  882. }
  883. dma_sync_single_for_device(denali->dev, addr, size, DMA_TO_DEVICE);
  884. clear_interrupts(denali);
  885. denali_enable_dma(denali, true);
  886. denali_setup_dma(denali, DENALI_WRITE);
  887. /* wait for operation to complete */
  888. irq_status = wait_for_irq(denali, irq_mask);
  889. if (irq_status == 0) {
  890. dev_err(denali->dev,
  891. "timeout on write_page (type = %d)\n",
  892. raw_xfer);
  893. denali->status =
  894. (irq_status & INTR_STATUS__PROGRAM_FAIL) ?
  895. NAND_STATUS_FAIL : PASS;
  896. }
  897. denali_enable_dma(denali, false);
  898. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE);
  899. }
  900. /* NAND core entry points */
  901. /* this is the callback that the NAND core calls to write a page. Since
  902. * writing a page with ECC or without is similar, all the work is done
  903. * by write_page above.
  904. * */
  905. static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
  906. const uint8_t *buf)
  907. {
  908. /* for regular page writes, we let HW handle all the ECC
  909. * data written to the device. */
  910. write_page(mtd, chip, buf, false);
  911. }
  912. /* This is the callback that the NAND core calls to write a page without ECC.
  913. * raw access is similar to ECC page writes, so all the work is done in the
  914. * write_page() function above.
  915. */
  916. static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
  917. const uint8_t *buf)
  918. {
  919. /* for raw page writes, we want to disable ECC and simply write
  920. whatever data is in the buffer. */
  921. write_page(mtd, chip, buf, true);
  922. }
  923. static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
  924. int page)
  925. {
  926. return write_oob_data(mtd, chip->oob_poi, page);
  927. }
  928. static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
  929. int page, int sndcmd)
  930. {
  931. read_oob_data(mtd, chip->oob_poi, page);
  932. return 0; /* notify NAND core to send command to
  933. NAND device. */
  934. }
  935. static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
  936. uint8_t *buf, int page)
  937. {
  938. struct denali_nand_info *denali = mtd_to_denali(mtd);
  939. dma_addr_t addr = denali->buf.dma_buf;
  940. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  941. uint32_t irq_status = 0;
  942. uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
  943. INTR_STATUS__ECC_ERR;
  944. bool check_erased_page = false;
  945. if (page != denali->page) {
  946. dev_err(denali->dev, "IN %s: page %d is not"
  947. " equal to denali->page %d, investigate!!",
  948. __func__, page, denali->page);
  949. BUG();
  950. }
  951. setup_ecc_for_xfer(denali, true, false);
  952. denali_enable_dma(denali, true);
  953. dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
  954. clear_interrupts(denali);
  955. denali_setup_dma(denali, DENALI_READ);
  956. /* wait for operation to complete */
  957. irq_status = wait_for_irq(denali, irq_mask);
  958. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
  959. memcpy(buf, denali->buf.buf, mtd->writesize);
  960. check_erased_page = handle_ecc(denali, buf, irq_status);
  961. denali_enable_dma(denali, false);
  962. if (check_erased_page) {
  963. read_oob_data(&denali->mtd, chip->oob_poi, denali->page);
  964. /* check ECC failures that may have occurred on erased pages */
  965. if (check_erased_page) {
  966. if (!is_erased(buf, denali->mtd.writesize))
  967. denali->mtd.ecc_stats.failed++;
  968. if (!is_erased(buf, denali->mtd.oobsize))
  969. denali->mtd.ecc_stats.failed++;
  970. }
  971. }
  972. return 0;
  973. }
  974. static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
  975. uint8_t *buf, int page)
  976. {
  977. struct denali_nand_info *denali = mtd_to_denali(mtd);
  978. dma_addr_t addr = denali->buf.dma_buf;
  979. size_t size = denali->mtd.writesize + denali->mtd.oobsize;
  980. uint32_t irq_status = 0;
  981. uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP;
  982. if (page != denali->page) {
  983. dev_err(denali->dev, "IN %s: page %d is not"
  984. " equal to denali->page %d, investigate!!",
  985. __func__, page, denali->page);
  986. BUG();
  987. }
  988. setup_ecc_for_xfer(denali, false, true);
  989. denali_enable_dma(denali, true);
  990. dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
  991. clear_interrupts(denali);
  992. denali_setup_dma(denali, DENALI_READ);
  993. /* wait for operation to complete */
  994. irq_status = wait_for_irq(denali, irq_mask);
  995. dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
  996. denali_enable_dma(denali, false);
  997. memcpy(buf, denali->buf.buf, mtd->writesize);
  998. memcpy(chip->oob_poi, denali->buf.buf + mtd->writesize, mtd->oobsize);
  999. return 0;
  1000. }
  1001. static uint8_t denali_read_byte(struct mtd_info *mtd)
  1002. {
  1003. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1004. uint8_t result = 0xff;
  1005. if (denali->buf.head < denali->buf.tail)
  1006. result = denali->buf.buf[denali->buf.head++];
  1007. return result;
  1008. }
  1009. static void denali_select_chip(struct mtd_info *mtd, int chip)
  1010. {
  1011. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1012. spin_lock_irq(&denali->irq_lock);
  1013. denali->flash_bank = chip;
  1014. spin_unlock_irq(&denali->irq_lock);
  1015. }
  1016. static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip)
  1017. {
  1018. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1019. int status = denali->status;
  1020. denali->status = 0;
  1021. return status;
  1022. }
  1023. static void denali_erase(struct mtd_info *mtd, int page)
  1024. {
  1025. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1026. uint32_t cmd = 0x0, irq_status = 0;
  1027. /* clear interrupts */
  1028. clear_interrupts(denali);
  1029. /* setup page read request for access type */
  1030. cmd = MODE_10 | BANK(denali->flash_bank) | page;
  1031. index_addr(denali, (uint32_t)cmd, 0x1);
  1032. /* wait for erase to complete or failure to occur */
  1033. irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP |
  1034. INTR_STATUS__ERASE_FAIL);
  1035. denali->status = (irq_status & INTR_STATUS__ERASE_FAIL) ?
  1036. NAND_STATUS_FAIL : PASS;
  1037. }
  1038. static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
  1039. int page)
  1040. {
  1041. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1042. uint32_t addr, id;
  1043. int i;
  1044. switch (cmd) {
  1045. case NAND_CMD_PAGEPROG:
  1046. break;
  1047. case NAND_CMD_STATUS:
  1048. read_status(denali);
  1049. break;
  1050. case NAND_CMD_READID:
  1051. case NAND_CMD_PARAM:
  1052. reset_buf(denali);
  1053. /*sometimes ManufactureId read from register is not right
  1054. * e.g. some of Micron MT29F32G08QAA MLC NAND chips
  1055. * So here we send READID cmd to NAND insteand
  1056. * */
  1057. addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
  1058. index_addr(denali, (uint32_t)addr | 0, 0x90);
  1059. index_addr(denali, (uint32_t)addr | 1, 0);
  1060. for (i = 0; i < 5; i++) {
  1061. index_addr_read_data(denali,
  1062. (uint32_t)addr | 2,
  1063. &id);
  1064. write_byte_to_buf(denali, id);
  1065. }
  1066. break;
  1067. case NAND_CMD_READ0:
  1068. case NAND_CMD_SEQIN:
  1069. denali->page = page;
  1070. break;
  1071. case NAND_CMD_RESET:
  1072. reset_bank(denali);
  1073. break;
  1074. case NAND_CMD_READOOB:
  1075. /* TODO: Read OOB data */
  1076. break;
  1077. default:
  1078. printk(KERN_ERR ": unsupported command"
  1079. " received 0x%x\n", cmd);
  1080. break;
  1081. }
  1082. }
  1083. /* stubs for ECC functions not used by the NAND core */
  1084. static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data,
  1085. uint8_t *ecc_code)
  1086. {
  1087. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1088. dev_err(denali->dev,
  1089. "denali_ecc_calculate called unexpectedly\n");
  1090. BUG();
  1091. return -EIO;
  1092. }
  1093. static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data,
  1094. uint8_t *read_ecc, uint8_t *calc_ecc)
  1095. {
  1096. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1097. dev_err(denali->dev,
  1098. "denali_ecc_correct called unexpectedly\n");
  1099. BUG();
  1100. return -EIO;
  1101. }
  1102. static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
  1103. {
  1104. struct denali_nand_info *denali = mtd_to_denali(mtd);
  1105. dev_err(denali->dev,
  1106. "denali_ecc_hwctl called unexpectedly\n");
  1107. BUG();
  1108. }
  1109. /* end NAND core entry points */
  1110. /* Initialization code to bring the device up to a known good state */
  1111. static void denali_hw_init(struct denali_nand_info *denali)
  1112. {
  1113. /* tell driver how many bit controller will skip before
  1114. * writing ECC code in OOB, this register may be already
  1115. * set by firmware. So we read this value out.
  1116. * if this value is 0, just let it be.
  1117. * */
  1118. denali->bbtskipbytes = ioread32(denali->flash_reg +
  1119. SPARE_AREA_SKIP_BYTES);
  1120. denali_nand_reset(denali);
  1121. iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED);
  1122. iowrite32(CHIP_EN_DONT_CARE__FLAG,
  1123. denali->flash_reg + CHIP_ENABLE_DONT_CARE);
  1124. iowrite32(0xffff, denali->flash_reg + SPARE_AREA_MARKER);
  1125. /* Should set value for these registers when init */
  1126. iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES);
  1127. iowrite32(1, denali->flash_reg + ECC_ENABLE);
  1128. denali_nand_timing_set(denali);
  1129. denali_irq_init(denali);
  1130. }
  1131. /* Althogh controller spec said SLC ECC is forceb to be 4bit,
  1132. * but denali controller in MRST only support 15bit and 8bit ECC
  1133. * correction
  1134. * */
  1135. #define ECC_8BITS 14
  1136. static struct nand_ecclayout nand_8bit_oob = {
  1137. .eccbytes = 14,
  1138. };
  1139. #define ECC_15BITS 26
  1140. static struct nand_ecclayout nand_15bit_oob = {
  1141. .eccbytes = 26,
  1142. };
  1143. static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
  1144. static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };
  1145. static struct nand_bbt_descr bbt_main_descr = {
  1146. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1147. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1148. .offs = 8,
  1149. .len = 4,
  1150. .veroffs = 12,
  1151. .maxblocks = 4,
  1152. .pattern = bbt_pattern,
  1153. };
  1154. static struct nand_bbt_descr bbt_mirror_descr = {
  1155. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1156. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1157. .offs = 8,
  1158. .len = 4,
  1159. .veroffs = 12,
  1160. .maxblocks = 4,
  1161. .pattern = mirror_pattern,
  1162. };
  1163. /* initialize driver data structures */
  1164. void denali_drv_init(struct denali_nand_info *denali)
  1165. {
  1166. denali->idx = 0;
  1167. /* setup interrupt handler */
  1168. /* the completion object will be used to notify
  1169. * the callee that the interrupt is done */
  1170. init_completion(&denali->complete);
  1171. /* the spinlock will be used to synchronize the ISR
  1172. * with any element that might be access shared
  1173. * data (interrupt status) */
  1174. spin_lock_init(&denali->irq_lock);
  1175. /* indicate that MTD has not selected a valid bank yet */
  1176. denali->flash_bank = CHIP_SELECT_INVALID;
  1177. /* initialize our irq_status variable to indicate no interrupts */
  1178. denali->irq_status = 0;
  1179. }
  1180. /* driver entry point */
  1181. static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1182. {
  1183. int ret = -ENODEV;
  1184. resource_size_t csr_base, mem_base;
  1185. unsigned long csr_len, mem_len;
  1186. struct denali_nand_info *denali;
  1187. denali = kzalloc(sizeof(*denali), GFP_KERNEL);
  1188. if (!denali)
  1189. return -ENOMEM;
  1190. ret = pci_enable_device(dev);
  1191. if (ret) {
  1192. printk(KERN_ERR "Spectra: pci_enable_device failed.\n");
  1193. goto failed_alloc_memery;
  1194. }
  1195. if (id->driver_data == INTEL_CE4100) {
  1196. /* Due to a silicon limitation, we can only support
  1197. * ONFI timing mode 1 and below.
  1198. */
  1199. if (onfi_timing_mode < -1 || onfi_timing_mode > 1) {
  1200. printk(KERN_ERR "Intel CE4100 only supports"
  1201. " ONFI timing mode 1 or below\n");
  1202. ret = -EINVAL;
  1203. goto failed_enable_dev;
  1204. }
  1205. denali->platform = INTEL_CE4100;
  1206. mem_base = pci_resource_start(dev, 0);
  1207. mem_len = pci_resource_len(dev, 1);
  1208. csr_base = pci_resource_start(dev, 1);
  1209. csr_len = pci_resource_len(dev, 1);
  1210. } else {
  1211. denali->platform = INTEL_MRST;
  1212. csr_base = pci_resource_start(dev, 0);
  1213. csr_len = pci_resource_len(dev, 0);
  1214. mem_base = pci_resource_start(dev, 1);
  1215. mem_len = pci_resource_len(dev, 1);
  1216. if (!mem_len) {
  1217. mem_base = csr_base + csr_len;
  1218. mem_len = csr_len;
  1219. }
  1220. }
  1221. /* Is 32-bit DMA supported? */
  1222. ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
  1223. if (ret) {
  1224. printk(KERN_ERR "Spectra: no usable DMA configuration\n");
  1225. goto failed_enable_dev;
  1226. }
  1227. denali->buf.dma_buf = dma_map_single(&dev->dev, denali->buf.buf,
  1228. DENALI_BUF_SIZE,
  1229. DMA_BIDIRECTIONAL);
  1230. if (dma_mapping_error(&dev->dev, denali->buf.dma_buf)) {
  1231. dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n");
  1232. goto failed_enable_dev;
  1233. }
  1234. pci_set_master(dev);
  1235. denali->dev = &dev->dev;
  1236. denali->mtd.dev.parent = &dev->dev;
  1237. ret = pci_request_regions(dev, DENALI_NAND_NAME);
  1238. if (ret) {
  1239. printk(KERN_ERR "Spectra: Unable to request memory regions\n");
  1240. goto failed_dma_map;
  1241. }
  1242. denali->flash_reg = ioremap_nocache(csr_base, csr_len);
  1243. if (!denali->flash_reg) {
  1244. printk(KERN_ERR "Spectra: Unable to remap memory region\n");
  1245. ret = -ENOMEM;
  1246. goto failed_req_regions;
  1247. }
  1248. denali->flash_mem = ioremap_nocache(mem_base, mem_len);
  1249. if (!denali->flash_mem) {
  1250. printk(KERN_ERR "Spectra: ioremap_nocache failed!");
  1251. ret = -ENOMEM;
  1252. goto failed_remap_reg;
  1253. }
  1254. denali_hw_init(denali);
  1255. denali_drv_init(denali);
  1256. /* denali_isr register is done after all the hardware
  1257. * initilization is finished*/
  1258. if (request_irq(dev->irq, denali_isr, IRQF_SHARED,
  1259. DENALI_NAND_NAME, denali)) {
  1260. printk(KERN_ERR "Spectra: Unable to allocate IRQ\n");
  1261. ret = -ENODEV;
  1262. goto failed_remap_mem;
  1263. }
  1264. /* now that our ISR is registered, we can enable interrupts */
  1265. denali_set_intr_modes(denali, true);
  1266. pci_set_drvdata(dev, denali);
  1267. denali->mtd.name = "denali-nand";
  1268. denali->mtd.owner = THIS_MODULE;
  1269. denali->mtd.priv = &denali->nand;
  1270. /* register the driver with the NAND core subsystem */
  1271. denali->nand.select_chip = denali_select_chip;
  1272. denali->nand.cmdfunc = denali_cmdfunc;
  1273. denali->nand.read_byte = denali_read_byte;
  1274. denali->nand.waitfunc = denali_waitfunc;
  1275. /* scan for NAND devices attached to the controller
  1276. * this is the first stage in a two step process to register
  1277. * with the nand subsystem */
  1278. if (nand_scan_ident(&denali->mtd, LLD_MAX_FLASH_BANKS, NULL)) {
  1279. ret = -ENXIO;
  1280. goto failed_req_irq;
  1281. }
  1282. /* MTD supported page sizes vary by kernel. We validate our
  1283. * kernel supports the device here.
  1284. */
  1285. if (denali->mtd.writesize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) {
  1286. ret = -ENODEV;
  1287. printk(KERN_ERR "Spectra: device size not supported by this "
  1288. "version of MTD.");
  1289. goto failed_req_irq;
  1290. }
  1291. /* support for multi nand
  1292. * MTD known nothing about multi nand,
  1293. * so we should tell it the real pagesize
  1294. * and anything necessery
  1295. */
  1296. denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED);
  1297. denali->nand.chipsize <<= (denali->devnum - 1);
  1298. denali->nand.page_shift += (denali->devnum - 1);
  1299. denali->nand.pagemask = (denali->nand.chipsize >>
  1300. denali->nand.page_shift) - 1;
  1301. denali->nand.bbt_erase_shift += (denali->devnum - 1);
  1302. denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift;
  1303. denali->nand.chip_shift += (denali->devnum - 1);
  1304. denali->mtd.writesize <<= (denali->devnum - 1);
  1305. denali->mtd.oobsize <<= (denali->devnum - 1);
  1306. denali->mtd.erasesize <<= (denali->devnum - 1);
  1307. denali->mtd.size = denali->nand.numchips * denali->nand.chipsize;
  1308. denali->bbtskipbytes *= denali->devnum;
  1309. /* second stage of the NAND scan
  1310. * this stage requires information regarding ECC and
  1311. * bad block management. */
  1312. /* Bad block management */
  1313. denali->nand.bbt_td = &bbt_main_descr;
  1314. denali->nand.bbt_md = &bbt_mirror_descr;
  1315. /* skip the scan for now until we have OOB read and write support */
  1316. denali->nand.options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN;
  1317. denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
  1318. /* Denali Controller only support 15bit and 8bit ECC in MRST,
  1319. * so just let controller do 15bit ECC for MLC and 8bit ECC for
  1320. * SLC if possible.
  1321. * */
  1322. if (denali->nand.cellinfo & 0xc &&
  1323. (denali->mtd.oobsize > (denali->bbtskipbytes +
  1324. ECC_15BITS * (denali->mtd.writesize /
  1325. ECC_SECTOR_SIZE)))) {
  1326. /* if MLC OOB size is large enough, use 15bit ECC*/
  1327. denali->nand.ecc.layout = &nand_15bit_oob;
  1328. denali->nand.ecc.bytes = ECC_15BITS;
  1329. iowrite32(15, denali->flash_reg + ECC_CORRECTION);
  1330. } else if (denali->mtd.oobsize < (denali->bbtskipbytes +
  1331. ECC_8BITS * (denali->mtd.writesize /
  1332. ECC_SECTOR_SIZE))) {
  1333. printk(KERN_ERR "Your NAND chip OOB is not large enough to"
  1334. " contain 8bit ECC correction codes");
  1335. goto failed_req_irq;
  1336. } else {
  1337. denali->nand.ecc.layout = &nand_8bit_oob;
  1338. denali->nand.ecc.bytes = ECC_8BITS;
  1339. iowrite32(8, denali->flash_reg + ECC_CORRECTION);
  1340. }
  1341. denali->nand.ecc.bytes *= denali->devnum;
  1342. denali->nand.ecc.layout->eccbytes *=
  1343. denali->mtd.writesize / ECC_SECTOR_SIZE;
  1344. denali->nand.ecc.layout->oobfree[0].offset =
  1345. denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes;
  1346. denali->nand.ecc.layout->oobfree[0].length =
  1347. denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes -
  1348. denali->bbtskipbytes;
  1349. /* Let driver know the total blocks number and
  1350. * how many blocks contained by each nand chip.
  1351. * blksperchip will help driver to know how many
  1352. * blocks is taken by FW.
  1353. * */
  1354. denali->totalblks = denali->mtd.size >>
  1355. denali->nand.phys_erase_shift;
  1356. denali->blksperchip = denali->totalblks / denali->nand.numchips;
  1357. /* These functions are required by the NAND core framework, otherwise,
  1358. * the NAND core will assert. However, we don't need them, so we'll stub
  1359. * them out. */
  1360. denali->nand.ecc.calculate = denali_ecc_calculate;
  1361. denali->nand.ecc.correct = denali_ecc_correct;
  1362. denali->nand.ecc.hwctl = denali_ecc_hwctl;
  1363. /* override the default read operations */
  1364. denali->nand.ecc.size = ECC_SECTOR_SIZE * denali->devnum;
  1365. denali->nand.ecc.read_page = denali_read_page;
  1366. denali->nand.ecc.read_page_raw = denali_read_page_raw;
  1367. denali->nand.ecc.write_page = denali_write_page;
  1368. denali->nand.ecc.write_page_raw = denali_write_page_raw;
  1369. denali->nand.ecc.read_oob = denali_read_oob;
  1370. denali->nand.ecc.write_oob = denali_write_oob;
  1371. denali->nand.erase_cmd = denali_erase;
  1372. if (nand_scan_tail(&denali->mtd)) {
  1373. ret = -ENXIO;
  1374. goto failed_req_irq;
  1375. }
  1376. ret = add_mtd_device(&denali->mtd);
  1377. if (ret) {
  1378. dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n",
  1379. ret);
  1380. goto failed_req_irq;
  1381. }
  1382. return 0;
  1383. failed_req_irq:
  1384. denali_irq_cleanup(dev->irq, denali);
  1385. failed_remap_mem:
  1386. iounmap(denali->flash_mem);
  1387. failed_remap_reg:
  1388. iounmap(denali->flash_reg);
  1389. failed_req_regions:
  1390. pci_release_regions(dev);
  1391. failed_dma_map:
  1392. dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
  1393. DMA_BIDIRECTIONAL);
  1394. failed_enable_dev:
  1395. pci_disable_device(dev);
  1396. failed_alloc_memery:
  1397. kfree(denali);
  1398. return ret;
  1399. }
  1400. /* driver exit point */
  1401. static void denali_pci_remove(struct pci_dev *dev)
  1402. {
  1403. struct denali_nand_info *denali = pci_get_drvdata(dev);
  1404. nand_release(&denali->mtd);
  1405. del_mtd_device(&denali->mtd);
  1406. denali_irq_cleanup(dev->irq, denali);
  1407. iounmap(denali->flash_reg);
  1408. iounmap(denali->flash_mem);
  1409. pci_release_regions(dev);
  1410. pci_disable_device(dev);
  1411. dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
  1412. DMA_BIDIRECTIONAL);
  1413. pci_set_drvdata(dev, NULL);
  1414. kfree(denali);
  1415. }
  1416. MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  1417. static struct pci_driver denali_pci_driver = {
  1418. .name = DENALI_NAND_NAME,
  1419. .id_table = denali_pci_ids,
  1420. .probe = denali_pci_probe,
  1421. .remove = denali_pci_remove,
  1422. };
  1423. static int __devinit denali_init(void)
  1424. {
  1425. printk(KERN_INFO "Spectra MTD driver\n");
  1426. return pci_register_driver(&denali_pci_driver);
  1427. }
  1428. /* Free memory */
  1429. static void __devexit denali_exit(void)
  1430. {
  1431. pci_unregister_driver(&denali_pci_driver);
  1432. }
  1433. module_init(denali_init);
  1434. module_exit(denali_exit);