lart.c 19 KB

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