lart.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 PART_BLOB_START 0x00000000
  69. #define PART_BLOB_LEN (NUM_BLOB_BLOCKS * FLASH_BLOCKSIZE_PARAM)
  70. /* kernel */
  71. #define NUM_KERNEL_BLOCKS 7
  72. #define PART_KERNEL_START (PART_BLOB_START + PART_BLOB_LEN)
  73. #define PART_KERNEL_LEN (NUM_KERNEL_BLOCKS * FLASH_BLOCKSIZE_MAIN)
  74. /* initial ramdisk */
  75. #define NUM_INITRD_BLOCKS 24
  76. #define PART_INITRD_START (PART_KERNEL_START + PART_KERNEL_LEN)
  77. #define PART_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. return (-EIO);
  368. addr += mtd->eraseregions[i].erasesize;
  369. len -= mtd->eraseregions[i].erasesize;
  370. if (addr == mtd->eraseregions[i].offset + (mtd->eraseregions[i].erasesize * mtd->eraseregions[i].numblocks)) i++;
  371. }
  372. return (0);
  373. }
  374. static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf)
  375. {
  376. #ifdef LART_DEBUG
  377. printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
  378. #endif
  379. /* we always read len bytes */
  380. *retlen = len;
  381. /* first, we read bytes until we reach a dword boundary */
  382. if (from & (BUSWIDTH - 1))
  383. {
  384. int gap = BUSWIDTH - (from & (BUSWIDTH - 1));
  385. while (len && gap--) *buf++ = read8 (from++), len--;
  386. }
  387. /* now we read dwords until we reach a non-dword boundary */
  388. while (len >= BUSWIDTH)
  389. {
  390. *((__u32 *) buf) = read32 (from);
  391. buf += BUSWIDTH;
  392. from += BUSWIDTH;
  393. len -= BUSWIDTH;
  394. }
  395. /* top up the last unaligned bytes */
  396. if (len & (BUSWIDTH - 1))
  397. while (len--) *buf++ = read8 (from++);
  398. return (0);
  399. }
  400. /*
  401. * Write one dword ``x'' to flash memory at offset ``offset''. ``offset''
  402. * must be 32 bits, i.e. it must be on a dword boundary.
  403. *
  404. * Returns 1 if successful, 0 otherwise.
  405. */
  406. static inline int write_dword (__u32 offset,__u32 x)
  407. {
  408. __u32 status;
  409. #ifdef LART_DEBUG
  410. printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x);
  411. #endif
  412. /* setup writing */
  413. write32 (DATA_TO_FLASH (PGM_SETUP),offset);
  414. /* write the data */
  415. write32 (x,offset);
  416. /* wait for the write to finish */
  417. do
  418. {
  419. write32 (DATA_TO_FLASH (STATUS_READ),offset);
  420. status = FLASH_TO_DATA (read32 (offset));
  421. }
  422. while ((~status & STATUS_BUSY) != 0);
  423. /* put the flash back into command mode */
  424. write32 (DATA_TO_FLASH (READ_ARRAY),offset);
  425. /* was the write successful? */
  426. if ((status & STATUS_PGM_ERR) || read32 (offset) != x)
  427. {
  428. printk (KERN_WARNING "%s: write error at address 0x%.8x.\n",module_name,offset);
  429. return (0);
  430. }
  431. return (1);
  432. }
  433. static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen,const u_char *buf)
  434. {
  435. __u8 tmp[4];
  436. int i,n;
  437. #ifdef LART_DEBUG
  438. printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
  439. #endif
  440. /* sanity checks */
  441. if (!len) return (0);
  442. /* first, we write a 0xFF.... padded byte until we reach a dword boundary */
  443. if (to & (BUSWIDTH - 1))
  444. {
  445. __u32 aligned = to & ~(BUSWIDTH - 1);
  446. int gap = to - aligned;
  447. i = n = 0;
  448. while (gap--) tmp[i++] = 0xFF;
  449. while (len && i < BUSWIDTH) tmp[i++] = buf[n++], len--;
  450. while (i < BUSWIDTH) tmp[i++] = 0xFF;
  451. if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO);
  452. to += n;
  453. buf += n;
  454. *retlen += n;
  455. }
  456. /* now we write dwords until we reach a non-dword boundary */
  457. while (len >= BUSWIDTH)
  458. {
  459. if (!write_dword (to,*((__u32 *) buf))) return (-EIO);
  460. to += BUSWIDTH;
  461. buf += BUSWIDTH;
  462. *retlen += BUSWIDTH;
  463. len -= BUSWIDTH;
  464. }
  465. /* top up the last unaligned bytes, padded with 0xFF.... */
  466. if (len & (BUSWIDTH - 1))
  467. {
  468. i = n = 0;
  469. while (len--) tmp[i++] = buf[n++];
  470. while (i < BUSWIDTH) tmp[i++] = 0xFF;
  471. if (!write_dword (to,*((__u32 *) tmp))) return (-EIO);
  472. *retlen += n;
  473. }
  474. return (0);
  475. }
  476. /***************************************************************************************************/
  477. static struct mtd_info mtd;
  478. static struct mtd_erase_region_info erase_regions[] = {
  479. /* parameter blocks */
  480. {
  481. .offset = 0x00000000,
  482. .erasesize = FLASH_BLOCKSIZE_PARAM,
  483. .numblocks = FLASH_NUMBLOCKS_16m_PARAM,
  484. },
  485. /* main blocks */
  486. {
  487. .offset = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM,
  488. .erasesize = FLASH_BLOCKSIZE_MAIN,
  489. .numblocks = FLASH_NUMBLOCKS_16m_MAIN,
  490. }
  491. };
  492. static const struct mtd_partition lart_partitions[] = {
  493. /* blob */
  494. {
  495. .name = "blob",
  496. .offset = PART_BLOB_START,
  497. .size = PART_BLOB_LEN,
  498. },
  499. /* kernel */
  500. {
  501. .name = "kernel",
  502. .offset = PART_KERNEL_START, /* MTDPART_OFS_APPEND */
  503. .size = PART_KERNEL_LEN,
  504. },
  505. /* initial ramdisk / file system */
  506. {
  507. .name = "file system",
  508. .offset = PART_INITRD_START, /* MTDPART_OFS_APPEND */
  509. .size = PART_INITRD_LEN, /* MTDPART_SIZ_FULL */
  510. }
  511. };
  512. #define NUM_PARTITIONS ARRAY_SIZE(lart_partitions)
  513. static int __init lart_flash_init (void)
  514. {
  515. int result;
  516. memset (&mtd,0,sizeof (mtd));
  517. printk ("MTD driver for LART. Written by Abraham vd Merwe <abraham@2d3d.co.za>\n");
  518. printk ("%s: Probing for 28F160x3 flash on LART...\n",module_name);
  519. if (!flash_probe ())
  520. {
  521. printk (KERN_WARNING "%s: Found no LART compatible flash device\n",module_name);
  522. return (-ENXIO);
  523. }
  524. printk ("%s: This looks like a LART board to me.\n",module_name);
  525. mtd.name = module_name;
  526. mtd.type = MTD_NORFLASH;
  527. mtd.writesize = 1;
  528. mtd.writebufsize = 4;
  529. mtd.flags = MTD_CAP_NORFLASH;
  530. mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
  531. mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
  532. mtd.numeraseregions = ARRAY_SIZE(erase_regions);
  533. mtd.eraseregions = erase_regions;
  534. mtd._erase = flash_erase;
  535. mtd._read = flash_read;
  536. mtd._write = flash_write;
  537. mtd.owner = THIS_MODULE;
  538. #ifdef LART_DEBUG
  539. printk (KERN_DEBUG
  540. "mtd.name = %s\n"
  541. "mtd.size = 0x%.8x (%uM)\n"
  542. "mtd.erasesize = 0x%.8x (%uK)\n"
  543. "mtd.numeraseregions = %d\n",
  544. mtd.name,
  545. mtd.size,mtd.size / (1024*1024),
  546. mtd.erasesize,mtd.erasesize / 1024,
  547. mtd.numeraseregions);
  548. if (mtd.numeraseregions)
  549. for (result = 0; result < mtd.numeraseregions; result++)
  550. printk (KERN_DEBUG
  551. "\n\n"
  552. "mtd.eraseregions[%d].offset = 0x%.8x\n"
  553. "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n"
  554. "mtd.eraseregions[%d].numblocks = %d\n",
  555. result,mtd.eraseregions[result].offset,
  556. result,mtd.eraseregions[result].erasesize,mtd.eraseregions[result].erasesize / 1024,
  557. result,mtd.eraseregions[result].numblocks);
  558. printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));
  559. for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
  560. printk (KERN_DEBUG
  561. "\n\n"
  562. "lart_partitions[%d].name = %s\n"
  563. "lart_partitions[%d].offset = 0x%.8x\n"
  564. "lart_partitions[%d].size = 0x%.8x (%uK)\n",
  565. result,lart_partitions[result].name,
  566. result,lart_partitions[result].offset,
  567. result,lart_partitions[result].size,lart_partitions[result].size / 1024);
  568. #endif
  569. result = mtd_device_register(&mtd, lart_partitions,
  570. ARRAY_SIZE(lart_partitions));
  571. return (result);
  572. }
  573. static void __exit lart_flash_exit (void)
  574. {
  575. mtd_device_unregister(&mtd);
  576. }
  577. module_init (lart_flash_init);
  578. module_exit (lart_flash_exit);
  579. MODULE_LICENSE("GPL");
  580. MODULE_AUTHOR("Abraham vd Merwe <abraham@2d3d.co.za>");
  581. MODULE_DESCRIPTION("MTD driver for Intel 28F160F3 on LART board");