lart.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART.
  3. *
  4. * Author: Abraham vd Merwe <abraham@2d3d.co.za>
  5. *
  6. * Copyright (c) 2001, 2d3D, Inc.
  7. *
  8. * This code is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * References:
  13. *
  14. * [1] 3 Volt Fast Boot Block Flash Memory" Intel Datasheet
  15. * - Order Number: 290644-005
  16. * - January 2000
  17. *
  18. * [2] MTD internal API documentation
  19. * - http://www.linux-mtd.infradead.org/
  20. *
  21. * Limitations:
  22. *
  23. * Even though this driver is written for 3 Volt Fast Boot
  24. * Block Flash Memory, it is rather specific to LART. With
  25. * Minor modifications, notably the without data/address line
  26. * mangling and different bus settings, etc. it should be
  27. * trivial to adapt to other platforms.
  28. *
  29. * If somebody would sponsor me a different board, I'll
  30. * adapt the driver (:
  31. */
  32. /* debugging */
  33. //#define LART_DEBUG
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/types.h>
  37. #include <linux/init.h>
  38. #include <linux/errno.h>
  39. #include <linux/string.h>
  40. #include <linux/mtd/mtd.h>
  41. #include <linux/mtd/partitions.h>
  42. #ifndef CONFIG_SA1100_LART
  43. #error This is for LART architecture only
  44. #endif
  45. static char module_name[] = "lart";
  46. /*
  47. * These values is specific to 28Fxxxx3 flash memory.
  48. * See section 2.3.1 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet
  49. */
  50. #define FLASH_BLOCKSIZE_PARAM (4096 * BUSWIDTH)
  51. #define FLASH_NUMBLOCKS_16m_PARAM 8
  52. #define FLASH_NUMBLOCKS_8m_PARAM 8
  53. /*
  54. * These values is specific to 28Fxxxx3 flash memory.
  55. * See section 2.3.2 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet
  56. */
  57. #define FLASH_BLOCKSIZE_MAIN (32768 * BUSWIDTH)
  58. #define FLASH_NUMBLOCKS_16m_MAIN 31
  59. #define FLASH_NUMBLOCKS_8m_MAIN 15
  60. /*
  61. * These values are specific to LART
  62. */
  63. /* general */
  64. #define BUSWIDTH 4 /* don't change this - a lot of the code _will_ break if you change this */
  65. #define FLASH_OFFSET 0xe8000000 /* see linux/arch/arm/mach-sa1100/lart.c */
  66. /* blob */
  67. #define NUM_BLOB_BLOCKS FLASH_NUMBLOCKS_16m_PARAM
  68. #define BLOB_START 0x00000000
  69. #define BLOB_LEN (NUM_BLOB_BLOCKS * FLASH_BLOCKSIZE_PARAM)
  70. /* kernel */
  71. #define NUM_KERNEL_BLOCKS 7
  72. #define KERNEL_START (BLOB_START + BLOB_LEN)
  73. #define KERNEL_LEN (NUM_KERNEL_BLOCKS * FLASH_BLOCKSIZE_MAIN)
  74. /* initial ramdisk */
  75. #define NUM_INITRD_BLOCKS 24
  76. #define INITRD_START (KERNEL_START + KERNEL_LEN)
  77. #define INITRD_LEN (NUM_INITRD_BLOCKS * FLASH_BLOCKSIZE_MAIN)
  78. /*
  79. * See section 4.0 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet
  80. */
  81. #define READ_ARRAY 0x00FF00FF /* Read Array/Reset */
  82. #define READ_ID_CODES 0x00900090 /* Read Identifier Codes */
  83. #define ERASE_SETUP 0x00200020 /* Block Erase */
  84. #define ERASE_CONFIRM 0x00D000D0 /* Block Erase and Program Resume */
  85. #define PGM_SETUP 0x00400040 /* Program */
  86. #define STATUS_READ 0x00700070 /* Read Status Register */
  87. #define STATUS_CLEAR 0x00500050 /* Clear Status Register */
  88. #define STATUS_BUSY 0x00800080 /* Write State Machine Status (WSMS) */
  89. #define STATUS_ERASE_ERR 0x00200020 /* Erase Status (ES) */
  90. #define STATUS_PGM_ERR 0x00100010 /* Program Status (PS) */
  91. /*
  92. * See section 4.2 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet
  93. */
  94. #define FLASH_MANUFACTURER 0x00890089
  95. #define FLASH_DEVICE_8mbit_TOP 0x88f188f1
  96. #define FLASH_DEVICE_8mbit_BOTTOM 0x88f288f2
  97. #define FLASH_DEVICE_16mbit_TOP 0x88f388f3
  98. #define FLASH_DEVICE_16mbit_BOTTOM 0x88f488f4
  99. /***************************************************************************************************/
  100. /*
  101. * The data line mapping on LART is as follows:
  102. *
  103. * U2 CPU | U3 CPU
  104. * -------------------
  105. * 0 20 | 0 12
  106. * 1 22 | 1 14
  107. * 2 19 | 2 11
  108. * 3 17 | 3 9
  109. * 4 24 | 4 0
  110. * 5 26 | 5 2
  111. * 6 31 | 6 7
  112. * 7 29 | 7 5
  113. * 8 21 | 8 13
  114. * 9 23 | 9 15
  115. * 10 18 | 10 10
  116. * 11 16 | 11 8
  117. * 12 25 | 12 1
  118. * 13 27 | 13 3
  119. * 14 30 | 14 6
  120. * 15 28 | 15 4
  121. */
  122. /* Mangle data (x) */
  123. #define DATA_TO_FLASH(x) \
  124. ( \
  125. (((x) & 0x08009000) >> 11) + \
  126. (((x) & 0x00002000) >> 10) + \
  127. (((x) & 0x04004000) >> 8) + \
  128. (((x) & 0x00000010) >> 4) + \
  129. (((x) & 0x91000820) >> 3) + \
  130. (((x) & 0x22080080) >> 2) + \
  131. ((x) & 0x40000400) + \
  132. (((x) & 0x00040040) << 1) + \
  133. (((x) & 0x00110000) << 4) + \
  134. (((x) & 0x00220100) << 5) + \
  135. (((x) & 0x00800208) << 6) + \
  136. (((x) & 0x00400004) << 9) + \
  137. (((x) & 0x00000001) << 12) + \
  138. (((x) & 0x00000002) << 13) \
  139. )
  140. /* Unmangle data (x) */
  141. #define FLASH_TO_DATA(x) \
  142. ( \
  143. (((x) & 0x00010012) << 11) + \
  144. (((x) & 0x00000008) << 10) + \
  145. (((x) & 0x00040040) << 8) + \
  146. (((x) & 0x00000001) << 4) + \
  147. (((x) & 0x12200104) << 3) + \
  148. (((x) & 0x08820020) << 2) + \
  149. ((x) & 0x40000400) + \
  150. (((x) & 0x00080080) >> 1) + \
  151. (((x) & 0x01100000) >> 4) + \
  152. (((x) & 0x04402000) >> 5) + \
  153. (((x) & 0x20008200) >> 6) + \
  154. (((x) & 0x80000800) >> 9) + \
  155. (((x) & 0x00001000) >> 12) + \
  156. (((x) & 0x00004000) >> 13) \
  157. )
  158. /*
  159. * The address line mapping on LART is as follows:
  160. *
  161. * U3 CPU | U2 CPU
  162. * -------------------
  163. * 0 2 | 0 2
  164. * 1 3 | 1 3
  165. * 2 9 | 2 9
  166. * 3 13 | 3 8
  167. * 4 8 | 4 7
  168. * 5 12 | 5 6
  169. * 6 11 | 6 5
  170. * 7 10 | 7 4
  171. * 8 4 | 8 10
  172. * 9 5 | 9 11
  173. * 10 6 | 10 12
  174. * 11 7 | 11 13
  175. *
  176. * BOOT BLOCK BOUNDARY
  177. *
  178. * 12 15 | 12 15
  179. * 13 14 | 13 14
  180. * 14 16 | 14 16
  181. *
  182. * MAIN BLOCK BOUNDARY
  183. *
  184. * 15 17 | 15 18
  185. * 16 18 | 16 17
  186. * 17 20 | 17 20
  187. * 18 19 | 18 19
  188. * 19 21 | 19 21
  189. *
  190. * As we can see from above, the addresses aren't mangled across
  191. * block boundaries, so we don't need to worry about address
  192. * translations except for sending/reading commands during
  193. * initialization
  194. */
  195. /* Mangle address (x) on chip U2 */
  196. #define ADDR_TO_FLASH_U2(x) \
  197. ( \
  198. (((x) & 0x00000f00) >> 4) + \
  199. (((x) & 0x00042000) << 1) + \
  200. (((x) & 0x0009c003) << 2) + \
  201. (((x) & 0x00021080) << 3) + \
  202. (((x) & 0x00000010) << 4) + \
  203. (((x) & 0x00000040) << 5) + \
  204. (((x) & 0x00000024) << 7) + \
  205. (((x) & 0x00000008) << 10) \
  206. )
  207. /* Unmangle address (x) on chip U2 */
  208. #define FLASH_U2_TO_ADDR(x) \
  209. ( \
  210. (((x) << 4) & 0x00000f00) + \
  211. (((x) >> 1) & 0x00042000) + \
  212. (((x) >> 2) & 0x0009c003) + \
  213. (((x) >> 3) & 0x00021080) + \
  214. (((x) >> 4) & 0x00000010) + \
  215. (((x) >> 5) & 0x00000040) + \
  216. (((x) >> 7) & 0x00000024) + \
  217. (((x) >> 10) & 0x00000008) \
  218. )
  219. /* Mangle address (x) on chip U3 */
  220. #define ADDR_TO_FLASH_U3(x) \
  221. ( \
  222. (((x) & 0x00000080) >> 3) + \
  223. (((x) & 0x00000040) >> 1) + \
  224. (((x) & 0x00052020) << 1) + \
  225. (((x) & 0x00084f03) << 2) + \
  226. (((x) & 0x00029010) << 3) + \
  227. (((x) & 0x00000008) << 5) + \
  228. (((x) & 0x00000004) << 7) \
  229. )
  230. /* Unmangle address (x) on chip U3 */
  231. #define FLASH_U3_TO_ADDR(x) \
  232. ( \
  233. (((x) << 3) & 0x00000080) + \
  234. (((x) << 1) & 0x00000040) + \
  235. (((x) >> 1) & 0x00052020) + \
  236. (((x) >> 2) & 0x00084f03) + \
  237. (((x) >> 3) & 0x00029010) + \
  238. (((x) >> 5) & 0x00000008) + \
  239. (((x) >> 7) & 0x00000004) \
  240. )
  241. /***************************************************************************************************/
  242. static __u8 read8 (__u32 offset)
  243. {
  244. volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset);
  245. #ifdef LART_DEBUG
  246. printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data);
  247. #endif
  248. return (*data);
  249. }
  250. static __u32 read32 (__u32 offset)
  251. {
  252. volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
  253. #ifdef LART_DEBUG
  254. printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data);
  255. #endif
  256. return (*data);
  257. }
  258. static void write32 (__u32 x,__u32 offset)
  259. {
  260. volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
  261. *data = x;
  262. #ifdef LART_DEBUG
  263. printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data);
  264. #endif
  265. }
  266. /***************************************************************************************************/
  267. /*
  268. * Probe for 16mbit flash memory on a LART board without doing
  269. * too much damage. Since we need to write 1 dword to memory,
  270. * we're f**cked if this happens to be DRAM since we can't
  271. * restore the memory (otherwise we might exit Read Array mode).
  272. *
  273. * Returns 1 if we found 16mbit flash memory on LART, 0 otherwise.
  274. */
  275. static int flash_probe (void)
  276. {
  277. __u32 manufacturer,devtype;
  278. /* setup "Read Identifier Codes" mode */
  279. write32 (DATA_TO_FLASH (READ_ID_CODES),0x00000000);
  280. /* probe U2. U2/U3 returns the same data since the first 3
  281. * address lines is mangled in the same way */
  282. manufacturer = FLASH_TO_DATA (read32 (ADDR_TO_FLASH_U2 (0x00000000)));
  283. devtype = FLASH_TO_DATA (read32 (ADDR_TO_FLASH_U2 (0x00000001)));
  284. /* put the flash back into command mode */
  285. write32 (DATA_TO_FLASH (READ_ARRAY),0x00000000);
  286. return (manufacturer == FLASH_MANUFACTURER && (devtype == FLASH_DEVICE_16mbit_TOP || devtype == FLASH_DEVICE_16mbit_BOTTOM));
  287. }
  288. /*
  289. * Erase one block of flash memory at offset ``offset'' which is any
  290. * address within the block which should be erased.
  291. *
  292. * Returns 1 if successful, 0 otherwise.
  293. */
  294. static inline int erase_block (__u32 offset)
  295. {
  296. __u32 status;
  297. #ifdef LART_DEBUG
  298. printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset);
  299. #endif
  300. /* erase and confirm */
  301. write32 (DATA_TO_FLASH (ERASE_SETUP),offset);
  302. write32 (DATA_TO_FLASH (ERASE_CONFIRM),offset);
  303. /* wait for block erase to finish */
  304. do
  305. {
  306. write32 (DATA_TO_FLASH (STATUS_READ),offset);
  307. status = FLASH_TO_DATA (read32 (offset));
  308. }
  309. while ((~status & STATUS_BUSY) != 0);
  310. /* put the flash back into command mode */
  311. write32 (DATA_TO_FLASH (READ_ARRAY),offset);
  312. /* was the erase successful? */
  313. if ((status & STATUS_ERASE_ERR))
  314. {
  315. printk (KERN_WARNING "%s: erase error at address 0x%.8x.\n",module_name,offset);
  316. return (0);
  317. }
  318. return (1);
  319. }
  320. static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
  321. {
  322. __u32 addr,len;
  323. int i,first;
  324. #ifdef LART_DEBUG
  325. printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len);
  326. #endif
  327. /*
  328. * check that both start and end of the requested erase are
  329. * aligned with the erasesize at the appropriate addresses.
  330. *
  331. * skip all erase regions which are ended before the start of
  332. * the requested erase. Actually, to save on the calculations,
  333. * we skip to the first erase region which starts after the
  334. * start of the requested erase, and then go back one.
  335. */
  336. for (i = 0; i < mtd->numeraseregions && instr->addr >= mtd->eraseregions[i].offset; i++) ;
  337. i--;
  338. /*
  339. * ok, now i is pointing at the erase region in which this
  340. * erase request starts. Check the start of the requested
  341. * erase range is aligned with the erase size which is in
  342. * effect here.
  343. */
  344. if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1)))
  345. return -EINVAL;
  346. /* Remember the erase region we start on */
  347. first = i;
  348. /*
  349. * next, check that the end of the requested erase is aligned
  350. * with the erase region at that address.
  351. *
  352. * as before, drop back one to point at the region in which
  353. * the address actually falls
  354. */
  355. for (; i < mtd->numeraseregions && instr->addr + instr->len >= mtd->eraseregions[i].offset; i++) ;
  356. i--;
  357. /* is the end aligned on a block boundary? */
  358. if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1)))
  359. return -EINVAL;
  360. addr = instr->addr;
  361. len = instr->len;
  362. i = first;
  363. /* now erase those blocks */
  364. while (len)
  365. {
  366. if (!erase_block (addr))
  367. {
  368. instr->state = MTD_ERASE_FAILED;
  369. return (-EIO);
  370. }
  371. addr += mtd->eraseregions[i].erasesize;
  372. len -= mtd->eraseregions[i].erasesize;
  373. if (addr == mtd->eraseregions[i].offset + (mtd->eraseregions[i].erasesize * mtd->eraseregions[i].numblocks)) i++;
  374. }
  375. instr->state = MTD_ERASE_DONE;
  376. mtd_erase_callback(instr);
  377. return (0);
  378. }
  379. static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf)
  380. {
  381. #ifdef LART_DEBUG
  382. printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
  383. #endif
  384. /* we always read len bytes */
  385. *retlen = len;
  386. /* first, we read bytes until we reach a dword boundary */
  387. if (from & (BUSWIDTH - 1))
  388. {
  389. int gap = BUSWIDTH - (from & (BUSWIDTH - 1));
  390. while (len && gap--) *buf++ = read8 (from++), len--;
  391. }
  392. /* now we read dwords until we reach a non-dword boundary */
  393. while (len >= BUSWIDTH)
  394. {
  395. *((__u32 *) buf) = read32 (from);
  396. buf += BUSWIDTH;
  397. from += BUSWIDTH;
  398. len -= BUSWIDTH;
  399. }
  400. /* top up the last unaligned bytes */
  401. if (len & (BUSWIDTH - 1))
  402. while (len--) *buf++ = read8 (from++);
  403. return (0);
  404. }
  405. /*
  406. * Write one dword ``x'' to flash memory at offset ``offset''. ``offset''
  407. * must be 32 bits, i.e. it must be on a dword boundary.
  408. *
  409. * Returns 1 if successful, 0 otherwise.
  410. */
  411. static inline int write_dword (__u32 offset,__u32 x)
  412. {
  413. __u32 status;
  414. #ifdef LART_DEBUG
  415. printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x);
  416. #endif
  417. /* setup writing */
  418. write32 (DATA_TO_FLASH (PGM_SETUP),offset);
  419. /* write the data */
  420. write32 (x,offset);
  421. /* wait for the write to finish */
  422. do
  423. {
  424. write32 (DATA_TO_FLASH (STATUS_READ),offset);
  425. status = FLASH_TO_DATA (read32 (offset));
  426. }
  427. while ((~status & STATUS_BUSY) != 0);
  428. /* put the flash back into command mode */
  429. write32 (DATA_TO_FLASH (READ_ARRAY),offset);
  430. /* was the write successful? */
  431. if ((status & STATUS_PGM_ERR) || read32 (offset) != x)
  432. {
  433. printk (KERN_WARNING "%s: write error at address 0x%.8x.\n",module_name,offset);
  434. return (0);
  435. }
  436. return (1);
  437. }
  438. static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen,const u_char *buf)
  439. {
  440. __u8 tmp[4];
  441. int i,n;
  442. #ifdef LART_DEBUG
  443. printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
  444. #endif
  445. /* sanity checks */
  446. if (!len) return (0);
  447. /* first, we write a 0xFF.... padded byte until we reach a dword boundary */
  448. if (to & (BUSWIDTH - 1))
  449. {
  450. __u32 aligned = to & ~(BUSWIDTH - 1);
  451. int gap = to - aligned;
  452. i = n = 0;
  453. while (gap--) tmp[i++] = 0xFF;
  454. while (len && i < BUSWIDTH) tmp[i++] = buf[n++], len--;
  455. while (i < BUSWIDTH) tmp[i++] = 0xFF;
  456. if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO);
  457. to += n;
  458. buf += n;
  459. *retlen += n;
  460. }
  461. /* now we write dwords until we reach a non-dword boundary */
  462. while (len >= BUSWIDTH)
  463. {
  464. if (!write_dword (to,*((__u32 *) buf))) return (-EIO);
  465. to += BUSWIDTH;
  466. buf += BUSWIDTH;
  467. *retlen += BUSWIDTH;
  468. len -= BUSWIDTH;
  469. }
  470. /* top up the last unaligned bytes, padded with 0xFF.... */
  471. if (len & (BUSWIDTH - 1))
  472. {
  473. i = n = 0;
  474. while (len--) tmp[i++] = buf[n++];
  475. while (i < BUSWIDTH) tmp[i++] = 0xFF;
  476. if (!write_dword (to,*((__u32 *) tmp))) return (-EIO);
  477. *retlen += n;
  478. }
  479. return (0);
  480. }
  481. /***************************************************************************************************/
  482. static struct mtd_info mtd;
  483. static struct mtd_erase_region_info erase_regions[] = {
  484. /* parameter blocks */
  485. {
  486. .offset = 0x00000000,
  487. .erasesize = FLASH_BLOCKSIZE_PARAM,
  488. .numblocks = FLASH_NUMBLOCKS_16m_PARAM,
  489. },
  490. /* main blocks */
  491. {
  492. .offset = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM,
  493. .erasesize = FLASH_BLOCKSIZE_MAIN,
  494. .numblocks = FLASH_NUMBLOCKS_16m_MAIN,
  495. }
  496. };
  497. static struct mtd_partition lart_partitions[] = {
  498. /* blob */
  499. {
  500. .name = "blob",
  501. .offset = BLOB_START,
  502. .size = BLOB_LEN,
  503. },
  504. /* kernel */
  505. {
  506. .name = "kernel",
  507. .offset = KERNEL_START, /* MTDPART_OFS_APPEND */
  508. .size = KERNEL_LEN,
  509. },
  510. /* initial ramdisk / file system */
  511. {
  512. .name = "file system",
  513. .offset = INITRD_START, /* MTDPART_OFS_APPEND */
  514. .size = INITRD_LEN, /* MTDPART_SIZ_FULL */
  515. }
  516. };
  517. #define NUM_PARTITIONS ARRAY_SIZE(lart_partitions)
  518. static int __init lart_flash_init (void)
  519. {
  520. int result;
  521. memset (&mtd,0,sizeof (mtd));
  522. printk ("MTD driver for LART. Written by Abraham vd Merwe <abraham@2d3d.co.za>\n");
  523. printk ("%s: Probing for 28F160x3 flash on LART...\n",module_name);
  524. if (!flash_probe ())
  525. {
  526. printk (KERN_WARNING "%s: Found no LART compatible flash device\n",module_name);
  527. return (-ENXIO);
  528. }
  529. printk ("%s: This looks like a LART board to me.\n",module_name);
  530. mtd.name = module_name;
  531. mtd.type = MTD_NORFLASH;
  532. mtd.writesize = 1;
  533. mtd.writebufsize = 4;
  534. mtd.flags = MTD_CAP_NORFLASH;
  535. mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
  536. mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
  537. mtd.numeraseregions = ARRAY_SIZE(erase_regions);
  538. mtd.eraseregions = erase_regions;
  539. mtd._erase = flash_erase;
  540. mtd._read = flash_read;
  541. mtd._write = flash_write;
  542. mtd.owner = THIS_MODULE;
  543. #ifdef LART_DEBUG
  544. printk (KERN_DEBUG
  545. "mtd.name = %s\n"
  546. "mtd.size = 0x%.8x (%uM)\n"
  547. "mtd.erasesize = 0x%.8x (%uK)\n"
  548. "mtd.numeraseregions = %d\n",
  549. mtd.name,
  550. mtd.size,mtd.size / (1024*1024),
  551. mtd.erasesize,mtd.erasesize / 1024,
  552. mtd.numeraseregions);
  553. if (mtd.numeraseregions)
  554. for (result = 0; result < mtd.numeraseregions; result++)
  555. printk (KERN_DEBUG
  556. "\n\n"
  557. "mtd.eraseregions[%d].offset = 0x%.8x\n"
  558. "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n"
  559. "mtd.eraseregions[%d].numblocks = %d\n",
  560. result,mtd.eraseregions[result].offset,
  561. result,mtd.eraseregions[result].erasesize,mtd.eraseregions[result].erasesize / 1024,
  562. result,mtd.eraseregions[result].numblocks);
  563. printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));
  564. for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
  565. printk (KERN_DEBUG
  566. "\n\n"
  567. "lart_partitions[%d].name = %s\n"
  568. "lart_partitions[%d].offset = 0x%.8x\n"
  569. "lart_partitions[%d].size = 0x%.8x (%uK)\n",
  570. result,lart_partitions[result].name,
  571. result,lart_partitions[result].offset,
  572. result,lart_partitions[result].size,lart_partitions[result].size / 1024);
  573. #endif
  574. result = mtd_device_register(&mtd, lart_partitions,
  575. ARRAY_SIZE(lart_partitions));
  576. return (result);
  577. }
  578. static void __exit lart_flash_exit (void)
  579. {
  580. mtd_device_unregister(&mtd);
  581. }
  582. module_init (lart_flash_init);
  583. module_exit (lart_flash_exit);
  584. MODULE_LICENSE("GPL");
  585. MODULE_AUTHOR("Abraham vd Merwe <abraham@2d3d.co.za>");
  586. MODULE_DESCRIPTION("MTD driver for Intel 28F160F3 on LART board");