setup.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Momentum Computer Ocelot-G (CP7000G) - board dependent boot routines
  4. *
  5. * Copyright (C) 1996, 1997, 2001 Ralf Baechle
  6. * Copyright (C) 2000 RidgeRun, Inc.
  7. * Copyright (C) 2001 Red Hat, Inc.
  8. * Copyright (C) 2002 Momentum Computer
  9. *
  10. * Author: Matthew Dharm, Momentum Computer
  11. * mdharm@momenco.com
  12. *
  13. * Author: RidgeRun, Inc.
  14. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  15. *
  16. * Copyright 2001 MontaVista Software Inc.
  17. * Author: jsun@mvista.com or jsun@junsun.net
  18. *
  19. * This program is free software; you can redistribute it and/or modify it
  20. * under the terms of the GNU General Public License as published by the
  21. * Free Software Foundation; either version 2 of the License, or (at your
  22. * option) any later version.
  23. *
  24. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  27. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  29. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  30. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * You should have received a copy of the GNU General Public License along
  36. * with this program; if not, write to the Free Software Foundation, Inc.,
  37. * 675 Mass Ave, Cambridge, MA 02139, USA.
  38. *
  39. */
  40. #include <linux/config.h>
  41. #include <linux/init.h>
  42. #include <linux/kernel.h>
  43. #include <linux/types.h>
  44. #include <linux/mm.h>
  45. #include <linux/swap.h>
  46. #include <linux/ioport.h>
  47. #include <linux/sched.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/pci.h>
  50. #include <linux/timex.h>
  51. #include <linux/vmalloc.h>
  52. #include <asm/time.h>
  53. #include <asm/bootinfo.h>
  54. #include <asm/page.h>
  55. #include <asm/io.h>
  56. #include <asm/gt64240.h>
  57. #include <asm/irq.h>
  58. #include <asm/pci.h>
  59. #include <asm/processor.h>
  60. #include <asm/ptrace.h>
  61. #include <asm/reboot.h>
  62. #include <linux/bootmem.h>
  63. #include "ocelot_pld.h"
  64. #ifdef CONFIG_GALILLEO_GT64240_ETH
  65. extern unsigned char prom_mac_addr_base[6];
  66. #endif
  67. unsigned long marvell_base;
  68. /* These functions are used for rebooting or halting the machine*/
  69. extern void momenco_ocelot_restart(char *command);
  70. extern void momenco_ocelot_halt(void);
  71. extern void momenco_ocelot_power_off(void);
  72. extern void gt64240_time_init(void);
  73. extern void momenco_ocelot_irq_setup(void);
  74. static char reset_reason;
  75. static unsigned long ENTRYLO(unsigned long paddr)
  76. {
  77. return ((paddr & PAGE_MASK) |
  78. (_PAGE_PRESENT | __READABLE | __WRITEABLE | _PAGE_GLOBAL |
  79. _CACHE_UNCACHED)) >> 6;
  80. }
  81. /* setup code for a handoff from a version 2 PMON 2000 PROM */
  82. void PMON_v2_setup(void)
  83. {
  84. /* A wired TLB entry for the GT64240 and the serial port. The
  85. GT64240 is going to be hit on every IRQ anyway - there's
  86. absolutely no point in letting it be a random TLB entry, as
  87. it'll just cause needless churning of the TLB. And we use
  88. the other half for the serial port, which is just a PITA
  89. otherwise :)
  90. Device Physical Virtual
  91. GT64240 Internal Regs 0xf4000000 0xe0000000
  92. UARTs (CS2) 0xfd000000 0xe0001000
  93. */
  94. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000),
  95. 0xf4000000, PM_64K);
  96. add_wired_entry(ENTRYLO(0xfd000000), ENTRYLO(0xfd001000),
  97. 0xfd000000, PM_4K);
  98. /* Also a temporary entry to let us talk to the Ocelot PLD and NVRAM
  99. in the CS[012] region. We can't use ioremap() yet. The NVRAM
  100. is a ST M48T37Y, which includes NVRAM, RTC, and Watchdog functions.
  101. Ocelot PLD (CS0) 0xfc000000 0xe0020000
  102. NVRAM (CS1) 0xfc800000 0xe0030000
  103. */
  104. add_temporary_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfc010000),
  105. 0xfc000000, PM_64K);
  106. add_temporary_entry(ENTRYLO(0xfc800000), ENTRYLO(0xfc810000),
  107. 0xfc800000, PM_64K);
  108. marvell_base = 0xf4000000;
  109. }
  110. extern int rm7k_tcache_enabled;
  111. /*
  112. * This runs in KSEG1. See the verbiage in rm7k.c::probe_scache()
  113. */
  114. #define Page_Invalidate_T 0x16
  115. static void __init setup_l3cache(unsigned long size)
  116. {
  117. int register i;
  118. printk("Enabling L3 cache...");
  119. /* Enable the L3 cache in the GT64120A's CPU Configuration register */
  120. MV_WRITE(0, MV_READ(0) | (1<<14));
  121. /* Enable the L3 cache in the CPU */
  122. set_c0_config(1<<12 /* CONF_TE */);
  123. /* Clear the cache */
  124. write_c0_taglo(0);
  125. write_c0_taghi(0);
  126. for (i=0; i < size; i+= 4096) {
  127. __asm__ __volatile__ (
  128. ".set noreorder\n\t"
  129. ".set mips3\n\t"
  130. "cache %1, (%0)\n\t"
  131. ".set mips0\n\t"
  132. ".set reorder"
  133. :
  134. : "r" (KSEG0ADDR(i)),
  135. "i" (Page_Invalidate_T));
  136. }
  137. /* Let the RM7000 MM code know that the tertiary cache is enabled */
  138. rm7k_tcache_enabled = 1;
  139. printk("Done\n");
  140. }
  141. static int __init momenco_ocelot_g_setup(void)
  142. {
  143. void (*l3func)(unsigned long) = (void *) KSEG1ADDR(setup_l3cache);
  144. unsigned int tmpword;
  145. board_time_init = gt64240_time_init;
  146. _machine_restart = momenco_ocelot_restart;
  147. _machine_halt = momenco_ocelot_halt;
  148. _machine_power_off = momenco_ocelot_power_off;
  149. /*
  150. * initrd_start = (ulong)ocelot_initrd_start;
  151. * initrd_end = (ulong)ocelot_initrd_start + (ulong)ocelot_initrd_size;
  152. * initrd_below_start_ok = 1;
  153. */
  154. /* do handoff reconfiguration */
  155. PMON_v2_setup();
  156. #ifdef CONFIG_GALILLEO_GT64240_ETH
  157. /* get the mac addr */
  158. memcpy(prom_mac_addr_base, (void*)0xfc807cf2, 6);
  159. #endif
  160. /* Turn off the Bit-Error LED */
  161. OCELOT_PLD_WRITE(0x80, INTCLR);
  162. tmpword = OCELOT_PLD_READ(BOARDREV);
  163. if (tmpword < 26)
  164. printk("Momenco Ocelot-G: Board Assembly Rev. %c\n", 'A'+tmpword);
  165. else
  166. printk("Momenco Ocelot-G: Board Assembly Revision #0x%x\n", tmpword);
  167. tmpword = OCELOT_PLD_READ(PLD1_ID);
  168. printk("PLD 1 ID: %d.%d\n", tmpword>>4, tmpword&15);
  169. tmpword = OCELOT_PLD_READ(PLD2_ID);
  170. printk("PLD 2 ID: %d.%d\n", tmpword>>4, tmpword&15);
  171. tmpword = OCELOT_PLD_READ(RESET_STATUS);
  172. printk("Reset reason: 0x%x\n", tmpword);
  173. reset_reason = tmpword;
  174. OCELOT_PLD_WRITE(0xff, RESET_STATUS);
  175. tmpword = OCELOT_PLD_READ(BOARD_STATUS);
  176. printk("Board Status register: 0x%02x\n", tmpword);
  177. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  178. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  179. printk(" - Tulip PHY %s connected\n", (tmpword&0x10)?"is":"not");
  180. printk(" - L3 Cache size: %d MiB\n", (1<<((tmpword&12) >> 2))&~1);
  181. printk(" - SDRAM size: %d MiB\n", 1<<(6+(tmpword&3)));
  182. if (tmpword&12)
  183. l3func((1<<(((tmpword&12) >> 2)+20)));
  184. switch(tmpword &3) {
  185. case 3:
  186. /* 512MiB -- two banks of 256MiB */
  187. add_memory_region( 0x0<<20, 0x100<<20, BOOT_MEM_RAM);
  188. /*
  189. add_memory_region(0x100<<20, 0x100<<20, BOOT_MEM_RAM);
  190. */
  191. break;
  192. case 2:
  193. /* 256MiB -- two banks of 128MiB */
  194. add_memory_region( 0x0<<20, 0x80<<20, BOOT_MEM_RAM);
  195. add_memory_region(0x80<<20, 0x80<<20, BOOT_MEM_RAM);
  196. break;
  197. case 1:
  198. /* 128MiB -- 64MiB per bank */
  199. add_memory_region( 0x0<<20, 0x40<<20, BOOT_MEM_RAM);
  200. add_memory_region(0x40<<20, 0x40<<20, BOOT_MEM_RAM);
  201. break;
  202. case 0:
  203. /* 64MiB */
  204. add_memory_region( 0x0<<20, 0x40<<20, BOOT_MEM_RAM);
  205. break;
  206. }
  207. /* FIXME: Fix up the DiskOnChip mapping */
  208. MV_WRITE(0x468, 0xfef73);
  209. return 0;
  210. }
  211. early_initcall(momenco_ocelot_g_setup);
  212. /* This needs to be one of the first initcalls, because no I/O port access
  213. can work before this */
  214. static int io_base_ioremap(void)
  215. {
  216. /* we're mapping PCI accesses from 0xc0000000 to 0xf0000000 */
  217. unsigned long io_remap_range;
  218. io_remap_range = (unsigned long) ioremap(0xc0000000, 0x30000000);
  219. if (!io_remap_range)
  220. panic("Could not ioremap I/O port range");
  221. set_io_port_base(io_remap_range - 0xc0000000);
  222. return 0;
  223. }
  224. module_init(io_base_ioremap);