ipaq-flash.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * Flash memory access on iPAQ Handhelds (either SA1100 or PXA250 based)
  3. *
  4. * (C) 2000 Nicolas Pitre <nico@cam.org>
  5. * (C) 2002 Hewlett-Packard Company <jamey.hicks@hp.com>
  6. * (C) 2003 Christian Pellegrin <chri@ascensit.com>, <chri@infis.univ.ts.it>: concatenation of multiple flashes
  7. *
  8. * $Id: ipaq-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $
  9. */
  10. #include <linux/config.h>
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <asm/page.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/system.h>
  20. #include <asm/errno.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/map.h>
  23. #include <linux/mtd/partitions.h>
  24. #ifdef CONFIG_MTD_CONCAT
  25. #include <linux/mtd/concat.h>
  26. #endif
  27. #include <asm/hardware.h>
  28. #include <asm/arch-sa1100/h3600.h>
  29. #include <asm/io.h>
  30. #ifndef CONFIG_IPAQ_HANDHELD
  31. #error This is for iPAQ Handhelds only
  32. #endif
  33. #ifdef CONFIG_SA1100_JORNADA56X
  34. static void jornada56x_set_vpp(struct map_info *map, int vpp)
  35. {
  36. if (vpp)
  37. GPSR = GPIO_GPIO26;
  38. else
  39. GPCR = GPIO_GPIO26;
  40. GPDR |= GPIO_GPIO26;
  41. }
  42. #endif
  43. #ifdef CONFIG_SA1100_JORNADA720
  44. static void jornada720_set_vpp(struct map_info *map, int vpp)
  45. {
  46. if (vpp)
  47. PPSR |= 0x80;
  48. else
  49. PPSR &= ~0x80;
  50. PPDR |= 0x80;
  51. }
  52. #endif
  53. #define MAX_IPAQ_CS 2 /* Number of CS we are going to test */
  54. #define IPAQ_MAP_INIT(X) \
  55. { \
  56. name: "IPAQ flash " X, \
  57. }
  58. static struct map_info ipaq_map[MAX_IPAQ_CS] = {
  59. IPAQ_MAP_INIT("bank 1"),
  60. IPAQ_MAP_INIT("bank 2")
  61. };
  62. static struct mtd_info *my_sub_mtd[MAX_IPAQ_CS] = {
  63. NULL,
  64. NULL
  65. };
  66. /*
  67. * Here are partition information for all known IPAQ-based devices.
  68. * See include/linux/mtd/partitions.h for definition of the mtd_partition
  69. * structure.
  70. *
  71. * The *_max_flash_size is the maximum possible mapped flash size which
  72. * is not necessarily the actual flash size. It must be no more than
  73. * the value specified in the "struct map_desc *_io_desc" mapping
  74. * definition for the corresponding machine.
  75. *
  76. * Please keep these in alphabetical order, and formatted as per existing
  77. * entries. Thanks.
  78. */
  79. #ifdef CONFIG_IPAQ_HANDHELD
  80. static unsigned long h3xxx_max_flash_size = 0x04000000;
  81. static struct mtd_partition h3xxx_partitions[] = {
  82. {
  83. name: "H3XXX boot firmware",
  84. #ifndef CONFIG_LAB
  85. size: 0x00040000,
  86. #else
  87. size: 0x00080000,
  88. #endif
  89. offset: 0,
  90. #ifndef CONFIG_LAB
  91. mask_flags: MTD_WRITEABLE, /* force read-only */
  92. #endif
  93. },
  94. {
  95. name: "H3XXX root jffs2",
  96. #ifndef CONFIG_LAB
  97. size: 0x2000000 - 2*0x40000, /* Warning, this is fixed later */
  98. offset: 0x00040000,
  99. #else
  100. size: 0x2000000 - 0x40000 - 0x80000, /* Warning, this is fixed later */
  101. offset: 0x00080000,
  102. #endif
  103. },
  104. {
  105. name: "asset",
  106. size: 0x40000,
  107. offset: 0x2000000 - 0x40000, /* Warning, this is fixed later */
  108. mask_flags: MTD_WRITEABLE, /* force read-only */
  109. }
  110. };
  111. #ifndef CONFIG_MTD_CONCAT
  112. static struct mtd_partition h3xxx_partitions_bank2[] = {
  113. /* this is used only on 2 CS machines when concat is not present */
  114. {
  115. name: "second H3XXX root jffs2",
  116. size: 0x1000000 - 0x40000, /* Warning, this is fixed later */
  117. offset: 0x00000000,
  118. },
  119. {
  120. name: "second asset",
  121. size: 0x40000,
  122. offset: 0x1000000 - 0x40000, /* Warning, this is fixed later */
  123. mask_flags: MTD_WRITEABLE, /* force read-only */
  124. }
  125. };
  126. #endif
  127. static DEFINE_SPINLOCK(ipaq_vpp_lock);
  128. static void h3xxx_set_vpp(struct map_info *map, int vpp)
  129. {
  130. static int nest = 0;
  131. spin_lock(&ipaq_vpp_lock);
  132. if (vpp)
  133. nest++;
  134. else
  135. nest--;
  136. if (nest)
  137. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 1);
  138. else
  139. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 0);
  140. spin_unlock(&ipaq_vpp_lock);
  141. }
  142. #endif
  143. #if defined(CONFIG_SA1100_JORNADA56X) || defined(CONFIG_SA1100_JORNADA720)
  144. static unsigned long jornada_max_flash_size = 0x02000000;
  145. static struct mtd_partition jornada_partitions[] = {
  146. {
  147. name: "Jornada boot firmware",
  148. size: 0x00040000,
  149. offset: 0,
  150. mask_flags: MTD_WRITEABLE, /* force read-only */
  151. }, {
  152. name: "Jornada root jffs2",
  153. size: MTDPART_SIZ_FULL,
  154. offset: 0x00040000,
  155. }
  156. };
  157. #endif
  158. static struct mtd_partition *parsed_parts;
  159. static struct mtd_info *mymtd;
  160. static unsigned long cs_phys[] = {
  161. #ifdef CONFIG_ARCH_SA1100
  162. SA1100_CS0_PHYS,
  163. SA1100_CS1_PHYS,
  164. SA1100_CS2_PHYS,
  165. SA1100_CS3_PHYS,
  166. SA1100_CS4_PHYS,
  167. SA1100_CS5_PHYS,
  168. #else
  169. PXA_CS0_PHYS,
  170. PXA_CS1_PHYS,
  171. PXA_CS2_PHYS,
  172. PXA_CS3_PHYS,
  173. PXA_CS4_PHYS,
  174. PXA_CS5_PHYS,
  175. #endif
  176. };
  177. static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
  178. static int __init h1900_special_case(void);
  179. int __init ipaq_mtd_init(void)
  180. {
  181. struct mtd_partition *parts = NULL;
  182. int nb_parts = 0;
  183. int parsed_nr_parts = 0;
  184. const char *part_type;
  185. int i; /* used when we have >1 flash chips */
  186. unsigned long tot_flashsize = 0; /* used when we have >1 flash chips */
  187. /* Default flash bankwidth */
  188. // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
  189. if (machine_is_h1900())
  190. {
  191. /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */
  192. return h1900_special_case();
  193. }
  194. if (machine_is_h3100() || machine_is_h1900())
  195. for(i=0; i<MAX_IPAQ_CS; i++)
  196. ipaq_map[i].bankwidth = 2;
  197. else
  198. for(i=0; i<MAX_IPAQ_CS; i++)
  199. ipaq_map[i].bankwidth = 4;
  200. /*
  201. * Static partition definition selection
  202. */
  203. part_type = "static";
  204. simple_map_init(&ipaq_map[0]);
  205. simple_map_init(&ipaq_map[1]);
  206. #ifdef CONFIG_IPAQ_HANDHELD
  207. if (machine_is_ipaq()) {
  208. parts = h3xxx_partitions;
  209. nb_parts = ARRAY_SIZE(h3xxx_partitions);
  210. for(i=0; i<MAX_IPAQ_CS; i++) {
  211. ipaq_map[i].size = h3xxx_max_flash_size;
  212. ipaq_map[i].set_vpp = h3xxx_set_vpp;
  213. ipaq_map[i].phys = cs_phys[i];
  214. ipaq_map[i].virt = ioremap(cs_phys[i], 0x04000000);
  215. if (machine_is_h3100 () || machine_is_h1900())
  216. ipaq_map[i].bankwidth = 2;
  217. }
  218. if (machine_is_h3600()) {
  219. /* No asset partition here */
  220. h3xxx_partitions[1].size += 0x40000;
  221. nb_parts--;
  222. }
  223. }
  224. #endif
  225. #ifdef CONFIG_ARCH_H5400
  226. if (machine_is_h5400()) {
  227. ipaq_map[0].size = 0x02000000;
  228. ipaq_map[1].size = 0x02000000;
  229. ipaq_map[1].phys = 0x02000000;
  230. ipaq_map[1].virt = ipaq_map[0].virt + 0x02000000;
  231. }
  232. #endif
  233. #ifdef CONFIG_ARCH_H1900
  234. if (machine_is_h1900()) {
  235. ipaq_map[0].size = 0x00400000;
  236. ipaq_map[1].size = 0x02000000;
  237. ipaq_map[1].phys = 0x00080000;
  238. ipaq_map[1].virt = ipaq_map[0].virt + 0x00080000;
  239. }
  240. #endif
  241. #ifdef CONFIG_SA1100_JORNADA56X
  242. if (machine_is_jornada56x()) {
  243. parts = jornada_partitions;
  244. nb_parts = ARRAY_SIZE(jornada_partitions);
  245. ipaq_map[0].size = jornada_max_flash_size;
  246. ipaq_map[0].set_vpp = jornada56x_set_vpp;
  247. ipaq_map[0].virt = (__u32)ioremap(0x0, 0x04000000);
  248. }
  249. #endif
  250. #ifdef CONFIG_SA1100_JORNADA720
  251. if (machine_is_jornada720()) {
  252. parts = jornada_partitions;
  253. nb_parts = ARRAY_SIZE(jornada_partitions);
  254. ipaq_map[0].size = jornada_max_flash_size;
  255. ipaq_map[0].set_vpp = jornada720_set_vpp;
  256. }
  257. #endif
  258. if (machine_is_ipaq()) { /* for iPAQs only */
  259. for(i=0; i<MAX_IPAQ_CS; i++) {
  260. printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with CFI.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
  261. my_sub_mtd[i] = do_map_probe("cfi_probe", &ipaq_map[i]);
  262. if (!my_sub_mtd[i]) {
  263. printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt);
  264. my_sub_mtd[i] = do_map_probe("jedec_probe", &ipaq_map[i]);
  265. }
  266. if (!my_sub_mtd[i]) {
  267. printk(KERN_NOTICE "iPAQ flash: failed to find flash.\n");
  268. if (i)
  269. break;
  270. else
  271. return -ENXIO;
  272. } else
  273. printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size);
  274. /* do we really need this debugging? --joshua 20030703 */
  275. // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]);
  276. my_sub_mtd[i]->owner = THIS_MODULE;
  277. tot_flashsize += my_sub_mtd[i]->size;
  278. }
  279. #ifdef CONFIG_MTD_CONCAT
  280. /* fix the asset location */
  281. # ifdef CONFIG_LAB
  282. h3xxx_partitions[1].size = tot_flashsize - 0x40000 - 0x80000 /* extra big boot block */;
  283. # else
  284. h3xxx_partitions[1].size = tot_flashsize - 2 * 0x40000;
  285. # endif
  286. h3xxx_partitions[2].offset = tot_flashsize - 0x40000;
  287. /* and concat the devices */
  288. mymtd = mtd_concat_create(&my_sub_mtd[0], i,
  289. "ipaq");
  290. if (!mymtd) {
  291. printk("Cannot create iPAQ concat device\n");
  292. return -ENXIO;
  293. }
  294. #else
  295. mymtd = my_sub_mtd[0];
  296. /*
  297. *In the very near future, command line partition parsing
  298. * will use the device name as 'mtd-id' instead of a value
  299. * passed to the parse_cmdline_partitions() routine. Since
  300. * the bootldr says 'ipaq', make sure it continues to work.
  301. */
  302. mymtd->name = "ipaq";
  303. if ((machine_is_h3600())) {
  304. # ifdef CONFIG_LAB
  305. h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x80000;
  306. # else
  307. h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000;
  308. # endif
  309. nb_parts = 2;
  310. } else {
  311. # ifdef CONFIG_LAB
  312. h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000 - 0x80000; /* extra big boot block */
  313. # else
  314. h3xxx_partitions[1].size = my_sub_mtd[0]->size - 2*0x40000;
  315. # endif
  316. h3xxx_partitions[2].offset = my_sub_mtd[0]->size - 0x40000;
  317. }
  318. if (my_sub_mtd[1]) {
  319. # ifdef CONFIG_LAB
  320. h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x80000;
  321. # else
  322. h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x40000;
  323. # endif
  324. h3xxx_partitions_bank2[1].offset = my_sub_mtd[1]->size - 0x40000;
  325. }
  326. #endif
  327. }
  328. else {
  329. /*
  330. * Now let's probe for the actual flash. Do it here since
  331. * specific machine settings might have been set above.
  332. */
  333. printk(KERN_NOTICE "IPAQ flash: probing %d-bit flash bus, window=%lx\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
  334. mymtd = do_map_probe("cfi_probe", &ipaq_map[0]);
  335. if (!mymtd)
  336. return -ENXIO;
  337. mymtd->owner = THIS_MODULE;
  338. }
  339. /*
  340. * Dynamic partition selection stuff (might override the static ones)
  341. */
  342. i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0);
  343. if (i > 0) {
  344. nb_parts = parsed_nr_parts = i;
  345. parts = parsed_parts;
  346. part_type = "dynamic";
  347. }
  348. if (!parts) {
  349. printk(KERN_NOTICE "IPAQ flash: no partition info available, registering whole flash at once\n");
  350. add_mtd_device(mymtd);
  351. #ifndef CONFIG_MTD_CONCAT
  352. if (my_sub_mtd[1])
  353. add_mtd_device(my_sub_mtd[1]);
  354. #endif
  355. } else {
  356. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  357. add_mtd_partitions(mymtd, parts, nb_parts);
  358. #ifndef CONFIG_MTD_CONCAT
  359. if (my_sub_mtd[1])
  360. add_mtd_partitions(my_sub_mtd[1], h3xxx_partitions_bank2, ARRAY_SIZE(h3xxx_partitions_bank2));
  361. #endif
  362. }
  363. return 0;
  364. }
  365. static void __exit ipaq_mtd_cleanup(void)
  366. {
  367. int i;
  368. if (mymtd) {
  369. del_mtd_partitions(mymtd);
  370. #ifndef CONFIG_MTD_CONCAT
  371. if (my_sub_mtd[1])
  372. del_mtd_partitions(my_sub_mtd[1]);
  373. #endif
  374. map_destroy(mymtd);
  375. #ifdef CONFIG_MTD_CONCAT
  376. for(i=0; i<MAX_IPAQ_CS; i++)
  377. #else
  378. for(i=1; i<MAX_IPAQ_CS; i++)
  379. #endif
  380. {
  381. if (my_sub_mtd[i])
  382. map_destroy(my_sub_mtd[i]);
  383. }
  384. kfree(parsed_parts);
  385. }
  386. }
  387. static int __init h1900_special_case(void)
  388. {
  389. /* The iPAQ h1900 is a special case - it has weird ROM. */
  390. simple_map_init(&ipaq_map[0]);
  391. ipaq_map[0].size = 0x80000;
  392. ipaq_map[0].set_vpp = h3xxx_set_vpp;
  393. ipaq_map[0].phys = 0x0;
  394. ipaq_map[0].virt = ioremap(0x0, 0x04000000);
  395. ipaq_map[0].bankwidth = 2;
  396. printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
  397. mymtd = do_map_probe("jedec_probe", &ipaq_map[0]);
  398. if (!mymtd)
  399. return -ENODEV;
  400. add_mtd_device(mymtd);
  401. printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n");
  402. return 0;
  403. }
  404. module_init(ipaq_mtd_init);
  405. module_exit(ipaq_mtd_cleanup);
  406. MODULE_AUTHOR("Jamey Hicks");
  407. MODULE_DESCRIPTION("IPAQ CFI map driver");
  408. MODULE_LICENSE("MIT");