nettel.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /****************************************************************************/
  2. /*
  3. * nettel.c -- mappings for NETtel/SecureEdge/SnapGear (x86) boards.
  4. *
  5. * (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com)
  6. * (C) Copyright 2001-2002, SnapGear (www.snapgear.com)
  7. *
  8. * $Id: nettel.c,v 1.12 2005/11/29 14:30:00 gleixner Exp $
  9. */
  10. /****************************************************************************/
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/map.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/mtd/cfi.h>
  19. #include <linux/reboot.h>
  20. #include <linux/err.h>
  21. #include <linux/kdev_t.h>
  22. #include <linux/root_dev.h>
  23. #include <asm/io.h>
  24. /****************************************************************************/
  25. #define INTEL_BUSWIDTH 1
  26. #define AMD_WINDOW_MAXSIZE 0x00200000
  27. #define AMD_BUSWIDTH 1
  28. /*
  29. * PAR masks and shifts, assuming 64K pages.
  30. */
  31. #define SC520_PAR_ADDR_MASK 0x00003fff
  32. #define SC520_PAR_ADDR_SHIFT 16
  33. #define SC520_PAR_TO_ADDR(par) \
  34. (((par)&SC520_PAR_ADDR_MASK) << SC520_PAR_ADDR_SHIFT)
  35. #define SC520_PAR_SIZE_MASK 0x01ffc000
  36. #define SC520_PAR_SIZE_SHIFT 2
  37. #define SC520_PAR_TO_SIZE(par) \
  38. ((((par)&SC520_PAR_SIZE_MASK) << SC520_PAR_SIZE_SHIFT) + (64*1024))
  39. #define SC520_PAR(cs, addr, size) \
  40. ((cs) | \
  41. ((((size)-(64*1024)) >> SC520_PAR_SIZE_SHIFT) & SC520_PAR_SIZE_MASK) | \
  42. (((addr) >> SC520_PAR_ADDR_SHIFT) & SC520_PAR_ADDR_MASK))
  43. #define SC520_PAR_BOOTCS 0x8a000000
  44. #define SC520_PAR_ROMCS1 0xaa000000
  45. #define SC520_PAR_ROMCS2 0xca000000 /* Cache disabled, 64K page */
  46. static void *nettel_mmcrp = NULL;
  47. #ifdef CONFIG_MTD_CFI_INTELEXT
  48. static struct mtd_info *intel_mtd;
  49. #endif
  50. static struct mtd_info *amd_mtd;
  51. /****************************************************************************/
  52. /****************************************************************************/
  53. #ifdef CONFIG_MTD_CFI_INTELEXT
  54. static struct map_info nettel_intel_map = {
  55. .name = "SnapGear Intel",
  56. .size = 0,
  57. .bankwidth = INTEL_BUSWIDTH,
  58. };
  59. static struct mtd_partition nettel_intel_partitions[] = {
  60. {
  61. .name = "SnapGear kernel",
  62. .offset = 0,
  63. .size = 0x000e0000
  64. },
  65. {
  66. .name = "SnapGear filesystem",
  67. .offset = 0x00100000,
  68. },
  69. {
  70. .name = "SnapGear config",
  71. .offset = 0x000e0000,
  72. .size = 0x00020000
  73. },
  74. {
  75. .name = "SnapGear Intel",
  76. .offset = 0
  77. },
  78. {
  79. .name = "SnapGear BIOS Config",
  80. .offset = 0x007e0000,
  81. .size = 0x00020000
  82. },
  83. {
  84. .name = "SnapGear BIOS",
  85. .offset = 0x007e0000,
  86. .size = 0x00020000
  87. },
  88. };
  89. #endif
  90. static struct map_info nettel_amd_map = {
  91. .name = "SnapGear AMD",
  92. .size = AMD_WINDOW_MAXSIZE,
  93. .bankwidth = AMD_BUSWIDTH,
  94. };
  95. static struct mtd_partition nettel_amd_partitions[] = {
  96. {
  97. .name = "SnapGear BIOS config",
  98. .offset = 0x000e0000,
  99. .size = 0x00010000
  100. },
  101. {
  102. .name = "SnapGear BIOS",
  103. .offset = 0x000f0000,
  104. .size = 0x00010000
  105. },
  106. {
  107. .name = "SnapGear AMD",
  108. .offset = 0
  109. },
  110. {
  111. .name = "SnapGear high BIOS",
  112. .offset = 0x001f0000,
  113. .size = 0x00010000
  114. }
  115. };
  116. #define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)
  117. /****************************************************************************/
  118. #ifdef CONFIG_MTD_CFI_INTELEXT
  119. /*
  120. * Set the Intel flash back to read mode since some old boot
  121. * loaders don't.
  122. */
  123. static int nettel_reboot_notifier(struct notifier_block *nb, unsigned long val, void *v)
  124. {
  125. struct cfi_private *cfi = nettel_intel_map.fldrv_priv;
  126. unsigned long b;
  127. /* Make sure all FLASH chips are put back into read mode */
  128. for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) {
  129. cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi,
  130. cfi->device_type, NULL);
  131. }
  132. return(NOTIFY_OK);
  133. }
  134. static struct notifier_block nettel_notifier_block = {
  135. nettel_reboot_notifier, NULL, 0
  136. };
  137. #endif
  138. /****************************************************************************/
  139. static int __init nettel_init(void)
  140. {
  141. volatile unsigned long *amdpar;
  142. unsigned long amdaddr, maxsize;
  143. int num_amd_partitions=0;
  144. #ifdef CONFIG_MTD_CFI_INTELEXT
  145. volatile unsigned long *intel0par, *intel1par;
  146. unsigned long orig_bootcspar, orig_romcs1par;
  147. unsigned long intel0addr, intel0size;
  148. unsigned long intel1addr, intel1size;
  149. int intelboot, intel0cs, intel1cs;
  150. int num_intel_partitions;
  151. #endif
  152. int rc = 0;
  153. nettel_mmcrp = (void *) ioremap_nocache(0xfffef000, 4096);
  154. if (nettel_mmcrp == NULL) {
  155. printk("SNAPGEAR: failed to disable MMCR cache??\n");
  156. return(-EIO);
  157. }
  158. /* Set CPU clock to be 33.000MHz */
  159. *((unsigned char *) (nettel_mmcrp + 0xc64)) = 0x01;
  160. amdpar = (volatile unsigned long *) (nettel_mmcrp + 0xc4);
  161. #ifdef CONFIG_MTD_CFI_INTELEXT
  162. intelboot = 0;
  163. intel0cs = SC520_PAR_ROMCS1;
  164. intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc0);
  165. intel1cs = SC520_PAR_ROMCS2;
  166. intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xbc);
  167. /*
  168. * Save the CS settings then ensure ROMCS1 and ROMCS2 are off,
  169. * otherwise they might clash with where we try to map BOOTCS.
  170. */
  171. orig_bootcspar = *amdpar;
  172. orig_romcs1par = *intel0par;
  173. *intel0par = 0;
  174. *intel1par = 0;
  175. #endif
  176. /*
  177. * The first thing to do is determine if we have a separate
  178. * boot FLASH device. Typically this is a small (1 to 2MB)
  179. * AMD FLASH part. It seems that device size is about the
  180. * only way to tell if this is the case...
  181. */
  182. amdaddr = 0x20000000;
  183. maxsize = AMD_WINDOW_MAXSIZE;
  184. *amdpar = SC520_PAR(SC520_PAR_BOOTCS, amdaddr, maxsize);
  185. __asm__ ("wbinvd");
  186. nettel_amd_map.phys = amdaddr;
  187. nettel_amd_map.virt = ioremap_nocache(amdaddr, maxsize);
  188. if (!nettel_amd_map.virt) {
  189. printk("SNAPGEAR: failed to ioremap() BOOTCS\n");
  190. iounmap(nettel_mmcrp);
  191. return(-EIO);
  192. }
  193. simple_map_init(&nettel_amd_map);
  194. if ((amd_mtd = do_map_probe("jedec_probe", &nettel_amd_map))) {
  195. printk(KERN_NOTICE "SNAPGEAR: AMD flash device size = %dK\n",
  196. amd_mtd->size>>10);
  197. amd_mtd->owner = THIS_MODULE;
  198. /* The high BIOS partition is only present for 2MB units */
  199. num_amd_partitions = NUM_AMD_PARTITIONS;
  200. if (amd_mtd->size < AMD_WINDOW_MAXSIZE)
  201. num_amd_partitions--;
  202. /* Don't add the partition until after the primary INTEL's */
  203. #ifdef CONFIG_MTD_CFI_INTELEXT
  204. /*
  205. * Map the Intel flash into memory after the AMD
  206. * It has to start on a multiple of maxsize.
  207. */
  208. maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
  209. if (maxsize < (32 * 1024 * 1024))
  210. maxsize = (32 * 1024 * 1024);
  211. intel0addr = amdaddr + maxsize;
  212. #endif
  213. } else {
  214. #ifdef CONFIG_MTD_CFI_INTELEXT
  215. /* INTEL boot FLASH */
  216. intelboot++;
  217. if (!orig_romcs1par) {
  218. intel0cs = SC520_PAR_BOOTCS;
  219. intel0par = (volatile unsigned long *)
  220. (nettel_mmcrp + 0xc4);
  221. intel1cs = SC520_PAR_ROMCS1;
  222. intel1par = (volatile unsigned long *)
  223. (nettel_mmcrp + 0xc0);
  224. intel0addr = SC520_PAR_TO_ADDR(orig_bootcspar);
  225. maxsize = SC520_PAR_TO_SIZE(orig_bootcspar);
  226. } else {
  227. /* Kernel base is on ROMCS1, not BOOTCS */
  228. intel0cs = SC520_PAR_ROMCS1;
  229. intel0par = (volatile unsigned long *)
  230. (nettel_mmcrp + 0xc0);
  231. intel1cs = SC520_PAR_BOOTCS;
  232. intel1par = (volatile unsigned long *)
  233. (nettel_mmcrp + 0xc4);
  234. intel0addr = SC520_PAR_TO_ADDR(orig_romcs1par);
  235. maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
  236. }
  237. /* Destroy useless AMD MTD mapping */
  238. amd_mtd = NULL;
  239. iounmap(nettel_amd_map.virt);
  240. nettel_amd_map.virt = NULL;
  241. #else
  242. /* Only AMD flash supported */
  243. rc = -ENXIO;
  244. goto out_unmap2;
  245. #endif
  246. }
  247. #ifdef CONFIG_MTD_CFI_INTELEXT
  248. /*
  249. * We have determined the INTEL FLASH configuration, so lets
  250. * go ahead and probe for them now.
  251. */
  252. /* Set PAR to the maximum size */
  253. if (maxsize < (32 * 1024 * 1024))
  254. maxsize = (32 * 1024 * 1024);
  255. *intel0par = SC520_PAR(intel0cs, intel0addr, maxsize);
  256. /* Turn other PAR off so the first probe doesn't find it */
  257. *intel1par = 0;
  258. /* Probe for the size of the first Intel flash */
  259. nettel_intel_map.size = maxsize;
  260. nettel_intel_map.phys = intel0addr;
  261. nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize);
  262. if (!nettel_intel_map.virt) {
  263. printk("SNAPGEAR: failed to ioremap() ROMCS1\n");
  264. rc = -EIO;
  265. goto out_unmap2;
  266. }
  267. simple_map_init(&nettel_intel_map);
  268. intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
  269. if (!intel_mtd) {
  270. rc = -ENXIO;
  271. goto out_unmap1;
  272. }
  273. /* Set PAR to the detected size */
  274. intel0size = intel_mtd->size;
  275. *intel0par = SC520_PAR(intel0cs, intel0addr, intel0size);
  276. /*
  277. * Map second Intel FLASH right after first. Set its size to the
  278. * same maxsize used for the first Intel FLASH.
  279. */
  280. intel1addr = intel0addr + intel0size;
  281. *intel1par = SC520_PAR(intel1cs, intel1addr, maxsize);
  282. __asm__ ("wbinvd");
  283. maxsize += intel0size;
  284. /* Delete the old map and probe again to do both chips */
  285. map_destroy(intel_mtd);
  286. intel_mtd = NULL;
  287. iounmap(nettel_intel_map.virt);
  288. nettel_intel_map.size = maxsize;
  289. nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize);
  290. if (!nettel_intel_map.virt) {
  291. printk("SNAPGEAR: failed to ioremap() ROMCS1/2\n");
  292. rc = -EIO;
  293. goto out_unmap2;
  294. }
  295. intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
  296. if (! intel_mtd) {
  297. rc = -ENXIO;
  298. goto out_unmap1;
  299. }
  300. intel1size = intel_mtd->size - intel0size;
  301. if (intel1size > 0) {
  302. *intel1par = SC520_PAR(intel1cs, intel1addr, intel1size);
  303. __asm__ ("wbinvd");
  304. } else {
  305. *intel1par = 0;
  306. }
  307. printk(KERN_NOTICE "SNAPGEAR: Intel flash device size = %dK\n",
  308. (intel_mtd->size >> 10));
  309. intel_mtd->owner = THIS_MODULE;
  310. num_intel_partitions = sizeof(nettel_intel_partitions) /
  311. sizeof(nettel_intel_partitions[0]);
  312. if (intelboot) {
  313. /*
  314. * Adjust offset and size of last boot partition.
  315. * Must allow for BIOS region at end of FLASH.
  316. */
  317. nettel_intel_partitions[1].size = (intel0size + intel1size) -
  318. (1024*1024 + intel_mtd->erasesize);
  319. nettel_intel_partitions[3].size = intel0size + intel1size;
  320. nettel_intel_partitions[4].offset =
  321. (intel0size + intel1size) - intel_mtd->erasesize;
  322. nettel_intel_partitions[4].size = intel_mtd->erasesize;
  323. nettel_intel_partitions[5].offset =
  324. nettel_intel_partitions[4].offset;
  325. nettel_intel_partitions[5].size =
  326. nettel_intel_partitions[4].size;
  327. } else {
  328. /* No BIOS regions when AMD boot */
  329. num_intel_partitions -= 2;
  330. }
  331. rc = add_mtd_partitions(intel_mtd, nettel_intel_partitions,
  332. num_intel_partitions);
  333. #endif
  334. if (amd_mtd) {
  335. rc = add_mtd_partitions(amd_mtd, nettel_amd_partitions,
  336. num_amd_partitions);
  337. }
  338. #ifdef CONFIG_MTD_CFI_INTELEXT
  339. register_reboot_notifier(&nettel_notifier_block);
  340. #endif
  341. return(rc);
  342. #ifdef CONFIG_MTD_CFI_INTELEXT
  343. out_unmap1:
  344. iounmap(nettel_intel_map.virt);
  345. #endif
  346. out_unmap2:
  347. iounmap(nettel_mmcrp);
  348. iounmap(nettel_amd_map.virt);
  349. return(rc);
  350. }
  351. /****************************************************************************/
  352. static void __exit nettel_cleanup(void)
  353. {
  354. #ifdef CONFIG_MTD_CFI_INTELEXT
  355. unregister_reboot_notifier(&nettel_notifier_block);
  356. #endif
  357. if (amd_mtd) {
  358. del_mtd_partitions(amd_mtd);
  359. map_destroy(amd_mtd);
  360. }
  361. if (nettel_mmcrp) {
  362. iounmap(nettel_mmcrp);
  363. nettel_mmcrp = NULL;
  364. }
  365. if (nettel_amd_map.virt) {
  366. iounmap(nettel_amd_map.virt);
  367. nettel_amd_map.virt = NULL;
  368. }
  369. #ifdef CONFIG_MTD_CFI_INTELEXT
  370. if (intel_mtd) {
  371. del_mtd_partitions(intel_mtd);
  372. map_destroy(intel_mtd);
  373. }
  374. if (nettel_intel_map.virt) {
  375. iounmap(nettel_intel_map.virt);
  376. nettel_intel_map.virt = NULL;
  377. }
  378. #endif
  379. }
  380. /****************************************************************************/
  381. module_init(nettel_init);
  382. module_exit(nettel_cleanup);
  383. MODULE_LICENSE("GPL");
  384. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  385. MODULE_DESCRIPTION("SnapGear/SecureEdge FLASH support");
  386. /****************************************************************************/