setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * setup.c
  3. *
  4. * BRIEF MODULE DESCRIPTION
  5. * Momentum Computer Ocelot (CP7000) - board dependent boot routines
  6. *
  7. * Copyright (C) 1996, 1997, 2001, 06 Ralf Baechle (ralf@linux-mips.org)
  8. * Copyright (C) 2000 RidgeRun, Inc.
  9. * Copyright (C) 2001 Red Hat, Inc.
  10. * Copyright (C) 2002 Momentum Computer
  11. *
  12. * Author: RidgeRun, Inc.
  13. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  14. *
  15. * Copyright 2001 MontaVista Software Inc.
  16. * Author: jsun@mvista.com or jsun@junsun.net
  17. *
  18. * This program is free software; you can redistribute it and/or modify it
  19. * under the terms of the GNU General Public License as published by the
  20. * Free Software Foundation; either version 2 of the License, or (at your
  21. * option) any later version.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  26. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  28. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  29. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  32. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program; if not, write to the Free Software Foundation, Inc.,
  36. * 675 Mass Ave, Cambridge, MA 02139, USA.
  37. *
  38. */
  39. #include <linux/init.h>
  40. #include <linux/kernel.h>
  41. #include <linux/types.h>
  42. #include <linux/mm.h>
  43. #include <linux/swap.h>
  44. #include <linux/ioport.h>
  45. #include <linux/sched.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/pci.h>
  48. #include <linux/timex.h>
  49. #include <linux/vmalloc.h>
  50. #include <linux/pm.h>
  51. #include <asm/time.h>
  52. #include <asm/bootinfo.h>
  53. #include <asm/page.h>
  54. #include <asm/io.h>
  55. #include <asm/irq.h>
  56. #include <asm/pci.h>
  57. #include <asm/processor.h>
  58. #include <asm/reboot.h>
  59. #include <asm/traps.h>
  60. #include <linux/bootmem.h>
  61. #include <linux/initrd.h>
  62. #include <asm/gt64120.h>
  63. #include "ocelot_pld.h"
  64. unsigned long gt64120_base = KSEG1ADDR(GT_DEF_BASE);
  65. /* These functions are used for rebooting or halting the machine*/
  66. extern void momenco_ocelot_restart(char *command);
  67. extern void momenco_ocelot_halt(void);
  68. extern void momenco_ocelot_power_off(void);
  69. extern void gt64120_time_init(void);
  70. extern void momenco_ocelot_irq_setup(void);
  71. static char reset_reason;
  72. #define ENTRYLO(x) ((pte_val(pfn_pte((x) >> PAGE_SHIFT, PAGE_KERNEL_UNCACHED)) >> 6)|1)
  73. static void __init setup_l3cache(unsigned long size);
  74. /* setup code for a handoff from a version 1 PMON 2000 PROM */
  75. void PMON_v1_setup()
  76. {
  77. /* A wired TLB entry for the GT64120A and the serial port. The
  78. GT64120A is going to be hit on every IRQ anyway - there's
  79. absolutely no point in letting it be a random TLB entry, as
  80. it'll just cause needless churning of the TLB. And we use
  81. the other half for the serial port, which is just a PITA
  82. otherwise :)
  83. Device Physical Virtual
  84. GT64120 Internal Regs 0x24000000 0xe0000000
  85. UARTs (CS2) 0x2d000000 0xe0001000
  86. */
  87. add_wired_entry(ENTRYLO(0x24000000), ENTRYLO(0x2D000000), 0xe0000000, PM_4K);
  88. /* Also a temporary entry to let us talk to the Ocelot PLD and NVRAM
  89. in the CS[012] region. We can't use ioremap() yet. The NVRAM
  90. is a ST M48T37Y, which includes NVRAM, RTC, and Watchdog functions.
  91. Ocelot PLD (CS0) 0x2c000000 0xe0020000
  92. NVRAM 0x2c800000 0xe0030000
  93. */
  94. add_temporary_entry(ENTRYLO(0x2C000000), ENTRYLO(0x2d000000), 0xe0020000, PM_64K);
  95. /* Relocate the CS3/BootCS region */
  96. GT_WRITE(GT_CS3BOOTLD_OFS, 0x2f000000 >> 21);
  97. /* Relocate CS[012] */
  98. GT_WRITE(GT_CS20LD_OFS, 0x2c000000 >> 21);
  99. /* Relocate the GT64120A itself... */
  100. GT_WRITE(GT_ISD_OFS, 0x24000000 >> 21);
  101. mb();
  102. gt64120_base = 0xe0000000;
  103. /* ...and the PCI0 view of it. */
  104. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000020);
  105. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x24000000);
  106. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000024);
  107. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x24000001);
  108. }
  109. /* setup code for a handoff from a version 2 PMON 2000 PROM */
  110. void PMON_v2_setup()
  111. {
  112. /* A wired TLB entry for the GT64120A and the serial port. The
  113. GT64120A is going to be hit on every IRQ anyway - there's
  114. absolutely no point in letting it be a random TLB entry, as
  115. it'll just cause needless churning of the TLB. And we use
  116. the other half for the serial port, which is just a PITA
  117. otherwise :)
  118. Device Physical Virtual
  119. GT64120 Internal Regs 0xf4000000 0xe0000000
  120. UARTs (CS2) 0xfd000000 0xe0001000
  121. */
  122. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xfD000000), 0xe0000000, PM_4K);
  123. /* Also a temporary entry to let us talk to the Ocelot PLD and NVRAM
  124. in the CS[012] region. We can't use ioremap() yet. The NVRAM
  125. is a ST M48T37Y, which includes NVRAM, RTC, and Watchdog functions.
  126. Ocelot PLD (CS0) 0xfc000000 0xe0020000
  127. NVRAM 0xfc800000 0xe0030000
  128. */
  129. add_temporary_entry(ENTRYLO(0xfC000000), ENTRYLO(0xfd000000), 0xe0020000, PM_64K);
  130. gt64120_base = 0xe0000000;
  131. }
  132. void __init plat_mem_setup(void)
  133. {
  134. void (*l3func)(unsigned long)=KSEG1ADDR(&setup_l3cache);
  135. unsigned int tmpword;
  136. board_time_init = gt64120_time_init;
  137. _machine_restart = momenco_ocelot_restart;
  138. _machine_halt = momenco_ocelot_halt;
  139. pm_power_off = momenco_ocelot_power_off;
  140. /*
  141. * initrd_start = (unsigned long)ocelot_initrd_start;
  142. * initrd_end = (unsigned long)ocelot_initrd_start + (ulong)ocelot_initrd_size;
  143. * initrd_below_start_ok = 1;
  144. */
  145. /* do handoff reconfiguration */
  146. if (gt64120_base == KSEG1ADDR(GT_DEF_BASE))
  147. PMON_v1_setup();
  148. else
  149. PMON_v2_setup();
  150. /* Turn off the Bit-Error LED */
  151. OCELOT_PLD_WRITE(0x80, INTCLR);
  152. /* Relocate all the PCI1 stuff, not that we use it */
  153. GT_WRITE(GT_PCI1IOLD_OFS, 0x30000000 >> 21);
  154. GT_WRITE(GT_PCI1M0LD_OFS, 0x32000000 >> 21);
  155. GT_WRITE(GT_PCI1M1LD_OFS, 0x34000000 >> 21);
  156. /* Relocate PCI0 I/O and Mem0 */
  157. GT_WRITE(GT_PCI0IOLD_OFS, 0x20000000 >> 21);
  158. GT_WRITE(GT_PCI0M0LD_OFS, 0x22000000 >> 21);
  159. /* Relocate PCI0 Mem1 */
  160. GT_WRITE(GT_PCI0M1LD_OFS, 0x36000000 >> 21);
  161. /* For the initial programming, we assume 512MB configuration */
  162. /* Relocate the CPU's view of the RAM... */
  163. GT_WRITE(GT_SCS10LD_OFS, 0);
  164. GT_WRITE(GT_SCS10HD_OFS, 0x0fe00000 >> 21);
  165. GT_WRITE(GT_SCS32LD_OFS, 0x10000000 >> 21);
  166. GT_WRITE(GT_SCS32HD_OFS, 0x0fe00000 >> 21);
  167. GT_WRITE(GT_SCS1LD_OFS, 0xff);
  168. GT_WRITE(GT_SCS1HD_OFS, 0x00);
  169. GT_WRITE(GT_SCS0LD_OFS, 0);
  170. GT_WRITE(GT_SCS0HD_OFS, 0xff);
  171. GT_WRITE(GT_SCS3LD_OFS, 0xff);
  172. GT_WRITE(GT_SCS3HD_OFS, 0x00);
  173. GT_WRITE(GT_SCS2LD_OFS, 0);
  174. GT_WRITE(GT_SCS2HD_OFS, 0xff);
  175. /* ...and the PCI0 view of it. */
  176. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000010);
  177. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x00000000);
  178. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000014);
  179. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x10000000);
  180. GT_WRITE(GT_PCI0_BS_SCS10_OFS, 0x0ffff000);
  181. GT_WRITE(GT_PCI0_BS_SCS32_OFS, 0x0ffff000);
  182. tmpword = OCELOT_PLD_READ(BOARDREV);
  183. if (tmpword < 26)
  184. printk("Momenco Ocelot: Board Assembly Rev. %c\n", 'A'+tmpword);
  185. else
  186. printk("Momenco Ocelot: Board Assembly Revision #0x%x\n", tmpword);
  187. tmpword = OCELOT_PLD_READ(PLD1_ID);
  188. printk("PLD 1 ID: %d.%d\n", tmpword>>4, tmpword&15);
  189. tmpword = OCELOT_PLD_READ(PLD2_ID);
  190. printk("PLD 2 ID: %d.%d\n", tmpword>>4, tmpword&15);
  191. tmpword = OCELOT_PLD_READ(RESET_STATUS);
  192. printk("Reset reason: 0x%x\n", tmpword);
  193. reset_reason = tmpword;
  194. OCELOT_PLD_WRITE(0xff, RESET_STATUS);
  195. tmpword = OCELOT_PLD_READ(BOARD_STATUS);
  196. printk("Board Status register: 0x%02x\n", tmpword);
  197. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  198. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  199. printk(" - Tulip PHY %s connected\n", (tmpword&0x10)?"is":"not");
  200. printk(" - L3 Cache size: %d MiB\n", (1<<((tmpword&12) >> 2))&~1);
  201. printk(" - SDRAM size: %d MiB\n", 1<<(6+(tmpword&3)));
  202. if (tmpword&12)
  203. l3func((1<<(((tmpword&12) >> 2)+20)));
  204. switch(tmpword &3) {
  205. case 3:
  206. /* 512MiB */
  207. /* Decoders are allready set -- just add the
  208. * appropriate region */
  209. add_memory_region( 0x40<<20, 0xC0<<20, BOOT_MEM_RAM);
  210. add_memory_region(0x100<<20, 0x100<<20, BOOT_MEM_RAM);
  211. break;
  212. case 2:
  213. /* 256MiB -- two banks of 128MiB */
  214. GT_WRITE(GT_SCS10HD_OFS, 0x07e00000 >> 21);
  215. GT_WRITE(GT_SCS32LD_OFS, 0x08000000 >> 21);
  216. GT_WRITE(GT_SCS32HD_OFS, 0x0fe00000 >> 21);
  217. GT_WRITE(GT_SCS0HD_OFS, 0x7f);
  218. GT_WRITE(GT_SCS2LD_OFS, 0x80);
  219. GT_WRITE(GT_SCS2HD_OFS, 0xff);
  220. /* reconfigure the PCI0 interface view of memory */
  221. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000014);
  222. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x08000000);
  223. GT_WRITE(GT_PCI0_BS_SCS10_OFS, 0x0ffff000);
  224. GT_WRITE(GT_PCI0_BS_SCS32_OFS, 0x0ffff000);
  225. add_memory_region(0x40<<20, 0x40<<20, BOOT_MEM_RAM);
  226. add_memory_region(0x80<<20, 0x80<<20, BOOT_MEM_RAM);
  227. break;
  228. case 1:
  229. /* 128MiB -- 64MiB per bank */
  230. GT_WRITE(GT_SCS10HD_OFS, 0x03e00000 >> 21);
  231. GT_WRITE(GT_SCS32LD_OFS, 0x04000000 >> 21);
  232. GT_WRITE(GT_SCS32HD_OFS, 0x07e00000 >> 21);
  233. GT_WRITE(GT_SCS0HD_OFS, 0x3f);
  234. GT_WRITE(GT_SCS2LD_OFS, 0x40);
  235. GT_WRITE(GT_SCS2HD_OFS, 0x7f);
  236. /* reconfigure the PCI0 interface view of memory */
  237. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000014);
  238. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x04000000);
  239. GT_WRITE(GT_PCI0_BS_SCS10_OFS, 0x03fff000);
  240. GT_WRITE(GT_PCI0_BS_SCS32_OFS, 0x03fff000);
  241. /* add the appropriate region */
  242. add_memory_region(0x40<<20, 0x40<<20, BOOT_MEM_RAM);
  243. break;
  244. case 0:
  245. /* 64MiB */
  246. GT_WRITE(GT_SCS10HD_OFS, 0x01e00000 >> 21);
  247. GT_WRITE(GT_SCS32LD_OFS, 0x02000000 >> 21);
  248. GT_WRITE(GT_SCS32HD_OFS, 0x03e00000 >> 21);
  249. GT_WRITE(GT_SCS0HD_OFS, 0x1f);
  250. GT_WRITE(GT_SCS2LD_OFS, 0x20);
  251. GT_WRITE(GT_SCS2HD_OFS, 0x3f);
  252. /* reconfigure the PCI0 interface view of memory */
  253. GT_WRITE(GT_PCI0_CFGADDR_OFS, 0x80000014);
  254. GT_WRITE(GT_PCI0_CFGDATA_OFS, 0x04000000);
  255. GT_WRITE(GT_PCI0_BS_SCS10_OFS, 0x01fff000);
  256. GT_WRITE(GT_PCI0_BS_SCS32_OFS, 0x01fff000);
  257. break;
  258. }
  259. /* Fix up the DiskOnChip mapping */
  260. GT_WRITE(GT_DEV_B3_OFS, 0xfef73);
  261. }
  262. extern int rm7k_tcache_enabled;
  263. /*
  264. * This runs in KSEG1. See the verbiage in rm7k.c::probe_scache()
  265. */
  266. #define Page_Invalidate_T 0x16
  267. static void __init setup_l3cache(unsigned long size)
  268. {
  269. int register i;
  270. unsigned long tmp;
  271. printk("Enabling L3 cache...");
  272. /* Enable the L3 cache in the GT64120A's CPU Configuration register */
  273. tmp = GT_READ(GT_CPU_OFS);
  274. GT_WRITE(GT_CPU_OFS, tmp | (1<<14));
  275. /* Enable the L3 cache in the CPU */
  276. set_c0_config(1<<12 /* CONF_TE */);
  277. /* Clear the cache */
  278. write_c0_taglo(0);
  279. write_c0_taghi(0);
  280. for (i=0; i < size; i+= 4096) {
  281. __asm__ __volatile__ (
  282. ".set noreorder\n\t"
  283. ".set mips3\n\t"
  284. "cache %1, (%0)\n\t"
  285. ".set mips0\n\t"
  286. ".set reorder"
  287. :
  288. : "r" (KSEG0ADDR(i)),
  289. "i" (Page_Invalidate_T));
  290. }
  291. /* Let the RM7000 MM code know that the tertiary cache is enabled */
  292. rm7k_tcache_enabled = 1;
  293. printk("Done\n");
  294. }
  295. /* This needs to be one of the first initcalls, because no I/O port access
  296. can work before this */
  297. static int io_base_ioremap(void)
  298. {
  299. void *io_remap_range = ioremap(GT_PCI_IO_BASE, GT_PCI_IO_SIZE);
  300. if (!io_remap_range) {
  301. panic("Could not ioremap I/O port range");
  302. }
  303. set_io_port_base(io_remap_range - GT_PCI_IO_BASE);
  304. return 0;
  305. }
  306. module_init(io_base_ioremap);