ipaq-flash.c 11 KB

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