setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Momentum Computer Jaguar-ATX board dependent boot routines
  4. *
  5. * Copyright (C) 1996, 1997, 2001, 04, 06 Ralf Baechle (ralf@linux-mips.org)
  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. * Louis Hamilton, Red Hat, Inc.
  14. * hamilton@redhat.com [MIPS64 modifications]
  15. *
  16. * Author: RidgeRun, Inc.
  17. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  18. *
  19. * Copyright 2001 MontaVista Software Inc.
  20. * Author: jsun@mvista.com or jsun@junsun.net
  21. *
  22. * This program is free software; you can redistribute it and/or modify it
  23. * under the terms of the GNU General Public License as published by the
  24. * Free Software Foundation; either version 2 of the License, or (at your
  25. * option) any later version.
  26. *
  27. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  28. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  29. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  30. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  32. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  33. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  34. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  36. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * You should have received a copy of the GNU General Public License along
  39. * with this program; if not, write to the Free Software Foundation, Inc.,
  40. * 675 Mass Ave, Cambridge, MA 02139, USA.
  41. */
  42. #include <linux/bcd.h>
  43. #include <linux/init.h>
  44. #include <linux/kernel.h>
  45. #include <linux/types.h>
  46. #include <linux/mm.h>
  47. #include <linux/bootmem.h>
  48. #include <linux/module.h>
  49. #include <linux/pci.h>
  50. #include <linux/swap.h>
  51. #include <linux/ioport.h>
  52. #include <linux/pm.h>
  53. #include <linux/sched.h>
  54. #include <linux/interrupt.h>
  55. #include <linux/timex.h>
  56. #include <linux/vmalloc.h>
  57. #include <linux/mv643xx.h>
  58. #include <asm/time.h>
  59. #include <asm/bootinfo.h>
  60. #include <asm/page.h>
  61. #include <asm/io.h>
  62. #include <asm/irq.h>
  63. #include <asm/processor.h>
  64. #include <asm/ptrace.h>
  65. #include <asm/reboot.h>
  66. #include <asm/tlbflush.h>
  67. #include "jaguar_atx_fpga.h"
  68. extern unsigned long mv64340_sram_base;
  69. unsigned long cpu_clock;
  70. /* These functions are used for rebooting or halting the machine*/
  71. extern void momenco_jaguar_restart(char *command);
  72. extern void momenco_jaguar_halt(void);
  73. extern void momenco_jaguar_power_off(void);
  74. void momenco_time_init(void);
  75. static char reset_reason;
  76. static inline unsigned long ENTRYLO(unsigned long paddr)
  77. {
  78. return ((paddr & PAGE_MASK) |
  79. (_PAGE_PRESENT | __READABLE | __WRITEABLE | _PAGE_GLOBAL |
  80. _CACHE_UNCACHED)) >> 6;
  81. }
  82. void __init bus_error_init(void) { /* nothing */ }
  83. /*
  84. * Load a few TLB entries for the MV64340 and perhiperals. The MV64340 is going
  85. * to be hit on every IRQ anyway - there's absolutely no point in letting it be
  86. * a random TLB entry, as it'll just cause needless churning of the TLB. And we
  87. * use the other half for the serial port, which is just a PITA otherwise :)
  88. *
  89. * Device Physical Virtual
  90. * MV64340 Internal Regs 0xf4000000 0xf4000000
  91. * Ocelot-C[S] PLD (CS0) 0xfc000000 0xfc000000
  92. * NVRAM (CS1) 0xfc800000 0xfc800000
  93. * UARTs (CS2) 0xfd000000 0xfd000000
  94. * Internal SRAM 0xfe000000 0xfe000000
  95. * M-Systems DOC (CS3) 0xff000000 0xff000000
  96. */
  97. static __init void wire_stupidity_into_tlb(void)
  98. {
  99. #ifdef CONFIG_32BIT
  100. write_c0_wired(0);
  101. local_flush_tlb_all();
  102. /* marvell and extra space */
  103. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000),
  104. 0xf4000000UL, PM_64K);
  105. /* fpga, rtc, and uart */
  106. add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000),
  107. 0xfc000000UL, PM_16M);
  108. // /* m-sys and internal SRAM */
  109. // add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000),
  110. // 0xfe000000UL, PM_16M);
  111. marvell_base = 0xf4000000;
  112. //mv64340_sram_base = 0xfe000000; /* Currently unused */
  113. #endif
  114. }
  115. unsigned long marvell_base = 0xf4000000L;
  116. unsigned long ja_fpga_base = JAGUAR_ATX_CS0_ADDR;
  117. unsigned long uart_base = 0xfd000000L;
  118. static unsigned char *rtc_base = (unsigned char*) 0xfc800000L;
  119. EXPORT_SYMBOL(marvell_base);
  120. static __init int per_cpu_mappings(void)
  121. {
  122. marvell_base = (unsigned long) ioremap(0xf4000000, 0x10000);
  123. ja_fpga_base = (unsigned long) ioremap(JAGUAR_ATX_CS0_ADDR, 0x1000);
  124. uart_base = (unsigned long) ioremap(0xfd000000UL, 0x1000);
  125. rtc_base = ioremap(0xfc000000UL, 0x8000);
  126. // ioremap(0xfe000000, 32 << 20);
  127. write_c0_wired(0);
  128. local_flush_tlb_all();
  129. ja_setup_console();
  130. return 0;
  131. }
  132. arch_initcall(per_cpu_mappings);
  133. unsigned long m48t37y_get_time(void)
  134. {
  135. unsigned int year, month, day, hour, min, sec;
  136. unsigned long flags;
  137. spin_lock_irqsave(&rtc_lock, flags);
  138. /* stop the update */
  139. rtc_base[0x7ff8] = 0x40;
  140. year = BCD2BIN(rtc_base[0x7fff]);
  141. year += BCD2BIN(rtc_base[0x7ff1]) * 100;
  142. month = BCD2BIN(rtc_base[0x7ffe]);
  143. day = BCD2BIN(rtc_base[0x7ffd]);
  144. hour = BCD2BIN(rtc_base[0x7ffb]);
  145. min = BCD2BIN(rtc_base[0x7ffa]);
  146. sec = BCD2BIN(rtc_base[0x7ff9]);
  147. /* start the update */
  148. rtc_base[0x7ff8] = 0x00;
  149. spin_unlock_irqrestore(&rtc_lock, flags);
  150. return mktime(year, month, day, hour, min, sec);
  151. }
  152. int m48t37y_set_time(unsigned long sec)
  153. {
  154. struct rtc_time tm;
  155. unsigned long flags;
  156. /* convert to a more useful format -- note months count from 0 */
  157. to_tm(sec, &tm);
  158. tm.tm_mon += 1;
  159. spin_lock_irqsave(&rtc_lock, flags);
  160. /* enable writing */
  161. rtc_base[0x7ff8] = 0x80;
  162. /* year */
  163. rtc_base[0x7fff] = BIN2BCD(tm.tm_year % 100);
  164. rtc_base[0x7ff1] = BIN2BCD(tm.tm_year / 100);
  165. /* month */
  166. rtc_base[0x7ffe] = BIN2BCD(tm.tm_mon);
  167. /* day */
  168. rtc_base[0x7ffd] = BIN2BCD(tm.tm_mday);
  169. /* hour/min/sec */
  170. rtc_base[0x7ffb] = BIN2BCD(tm.tm_hour);
  171. rtc_base[0x7ffa] = BIN2BCD(tm.tm_min);
  172. rtc_base[0x7ff9] = BIN2BCD(tm.tm_sec);
  173. /* day of week -- not really used, but let's keep it up-to-date */
  174. rtc_base[0x7ffc] = BIN2BCD(tm.tm_wday + 1);
  175. /* disable writing */
  176. rtc_base[0x7ff8] = 0x00;
  177. spin_unlock_irqrestore(&rtc_lock, flags);
  178. return 0;
  179. }
  180. void __init plat_timer_setup(struct irqaction *irq)
  181. {
  182. setup_irq(8, irq);
  183. }
  184. /*
  185. * Ugly but the least of all evils. TLB initialization did flush the TLB so
  186. * We need to setup mappings again before we can touch the RTC.
  187. */
  188. void momenco_time_init(void)
  189. {
  190. wire_stupidity_into_tlb();
  191. mips_hpt_frequency = cpu_clock / 2;
  192. rtc_mips_get_time = m48t37y_get_time;
  193. rtc_mips_set_time = m48t37y_set_time;
  194. }
  195. static struct resource mv_pci_io_mem0_resource = {
  196. .name = "MV64340 PCI0 IO MEM",
  197. .flags = IORESOURCE_IO
  198. };
  199. static struct resource mv_pci_mem0_resource = {
  200. .name = "MV64340 PCI0 MEM",
  201. .flags = IORESOURCE_MEM
  202. };
  203. static struct mv_pci_controller mv_bus0_controller = {
  204. .pcic = {
  205. .pci_ops = &mv_pci_ops,
  206. .mem_resource = &mv_pci_mem0_resource,
  207. .io_resource = &mv_pci_io_mem0_resource,
  208. },
  209. .config_addr = MV64340_PCI_0_CONFIG_ADDR,
  210. .config_vreg = MV64340_PCI_0_CONFIG_DATA_VIRTUAL_REG,
  211. };
  212. static uint32_t mv_io_base, mv_io_size;
  213. static void ja_pci0_init(void)
  214. {
  215. uint32_t mem0_base, mem0_size;
  216. uint32_t io_base, io_size;
  217. io_base = MV_READ(MV64340_PCI_0_IO_BASE_ADDR) << 16;
  218. io_size = (MV_READ(MV64340_PCI_0_IO_SIZE) + 1) << 16;
  219. mem0_base = MV_READ(MV64340_PCI_0_MEMORY0_BASE_ADDR) << 16;
  220. mem0_size = (MV_READ(MV64340_PCI_0_MEMORY0_SIZE) + 1) << 16;
  221. mv_pci_io_mem0_resource.start = 0;
  222. mv_pci_io_mem0_resource.end = io_size - 1;
  223. mv_pci_mem0_resource.start = mem0_base;
  224. mv_pci_mem0_resource.end = mem0_base + mem0_size - 1;
  225. mv_bus0_controller.pcic.mem_offset = mem0_base;
  226. mv_bus0_controller.pcic.io_offset = 0;
  227. ioport_resource.end = io_size - 1;
  228. register_pci_controller(&mv_bus0_controller.pcic);
  229. mv_io_base = io_base;
  230. mv_io_size = io_size;
  231. }
  232. static struct resource mv_pci_io_mem1_resource = {
  233. .name = "MV64340 PCI1 IO MEM",
  234. .flags = IORESOURCE_IO
  235. };
  236. static struct resource mv_pci_mem1_resource = {
  237. .name = "MV64340 PCI1 MEM",
  238. .flags = IORESOURCE_MEM
  239. };
  240. static struct mv_pci_controller mv_bus1_controller = {
  241. .pcic = {
  242. .pci_ops = &mv_pci_ops,
  243. .mem_resource = &mv_pci_mem1_resource,
  244. .io_resource = &mv_pci_io_mem1_resource,
  245. },
  246. .config_addr = MV64340_PCI_1_CONFIG_ADDR,
  247. .config_vreg = MV64340_PCI_1_CONFIG_DATA_VIRTUAL_REG,
  248. };
  249. static __init void ja_pci1_init(void)
  250. {
  251. uint32_t mem0_base, mem0_size;
  252. uint32_t io_base, io_size;
  253. io_base = MV_READ(MV64340_PCI_1_IO_BASE_ADDR) << 16;
  254. io_size = (MV_READ(MV64340_PCI_1_IO_SIZE) + 1) << 16;
  255. mem0_base = MV_READ(MV64340_PCI_1_MEMORY0_BASE_ADDR) << 16;
  256. mem0_size = (MV_READ(MV64340_PCI_1_MEMORY0_SIZE) + 1) << 16;
  257. /*
  258. * Here we assume the I/O window of second bus to be contiguous with
  259. * the first. A gap is no problem but would waste address space for
  260. * remapping the port space.
  261. */
  262. mv_pci_io_mem1_resource.start = mv_io_size;
  263. mv_pci_io_mem1_resource.end = mv_io_size + io_size - 1;
  264. mv_pci_mem1_resource.start = mem0_base;
  265. mv_pci_mem1_resource.end = mem0_base + mem0_size - 1;
  266. mv_bus1_controller.pcic.mem_offset = mem0_base;
  267. mv_bus1_controller.pcic.io_offset = 0;
  268. ioport_resource.end = io_base + io_size -mv_io_base - 1;
  269. register_pci_controller(&mv_bus1_controller.pcic);
  270. mv_io_size = io_base + io_size - mv_io_base;
  271. }
  272. static __init int __init ja_pci_init(void)
  273. {
  274. unsigned long io_v_base;
  275. uint32_t enable;
  276. enable = ~MV_READ(MV64340_BASE_ADDR_ENABLE);
  277. /*
  278. * We require at least one enabled I/O or PCI memory window or we
  279. * will ignore this PCI bus. We ignore PCI windows 1, 2 and 3.
  280. */
  281. if (enable & (0x01 << 9) || enable & (0x01 << 10))
  282. ja_pci0_init();
  283. if (enable & (0x01 << 14) || enable & (0x01 << 15))
  284. ja_pci1_init();
  285. if (mv_io_size) {
  286. io_v_base = (unsigned long) ioremap(mv_io_base, mv_io_size);
  287. if (!io_v_base)
  288. panic("Could not ioremap I/O port range");
  289. set_io_port_base(io_v_base);
  290. }
  291. return 0;
  292. }
  293. arch_initcall(ja_pci_init);
  294. void __init plat_mem_setup(void)
  295. {
  296. unsigned int tmpword;
  297. board_time_init = momenco_time_init;
  298. _machine_restart = momenco_jaguar_restart;
  299. _machine_halt = momenco_jaguar_halt;
  300. pm_power_off = momenco_jaguar_power_off;
  301. /*
  302. * initrd_start = (unsigned long)jaguar_initrd_start;
  303. * initrd_end = (unsigned long)jaguar_initrd_start + (ulong)jaguar_initrd_size;
  304. * initrd_below_start_ok = 1;
  305. */
  306. wire_stupidity_into_tlb();
  307. /*
  308. * shut down ethernet ports, just to be sure our memory doesn't get
  309. * corrupted by random ethernet traffic.
  310. */
  311. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
  312. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
  313. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(2), 0xff << 8);
  314. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
  315. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
  316. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(2), 0xff << 8);
  317. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
  318. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
  319. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(2)) & 0xff);
  320. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
  321. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
  322. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(2)) & 0xff);
  323. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0),
  324. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
  325. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1),
  326. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
  327. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(2),
  328. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(2)) & ~1);
  329. /* Turn off the Bit-Error LED */
  330. JAGUAR_FPGA_WRITE(0x80, CLR);
  331. tmpword = JAGUAR_FPGA_READ(BOARDREV);
  332. if (tmpword < 26)
  333. printk("Momentum Jaguar-ATX: Board Assembly Rev. %c\n",
  334. 'A'+tmpword);
  335. else
  336. printk("Momentum Jaguar-ATX: Board Assembly Revision #0x%x\n",
  337. tmpword);
  338. tmpword = JAGUAR_FPGA_READ(FPGA_REV);
  339. printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
  340. tmpword = JAGUAR_FPGA_READ(RESET_STATUS);
  341. printk("Reset reason: 0x%x\n", tmpword);
  342. switch (tmpword) {
  343. case 0x1:
  344. printk(" - Power-up reset\n");
  345. break;
  346. case 0x2:
  347. printk(" - Push-button reset\n");
  348. break;
  349. case 0x8:
  350. printk(" - Watchdog reset\n");
  351. break;
  352. case 0x10:
  353. printk(" - JTAG reset\n");
  354. break;
  355. default:
  356. printk(" - Unknown reset cause\n");
  357. }
  358. reset_reason = tmpword;
  359. JAGUAR_FPGA_WRITE(0xff, RESET_STATUS);
  360. tmpword = JAGUAR_FPGA_READ(BOARD_STATUS);
  361. printk("Board Status register: 0x%02x\n", tmpword);
  362. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  363. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  364. /* 256MiB of RM9000x2 DDR */
  365. // add_memory_region(0x0, 0x100<<20, BOOT_MEM_RAM);
  366. /* 128MiB of MV-64340 DDR */
  367. // add_memory_region(0x100<<20, 0x80<<20, BOOT_MEM_RAM);
  368. /* XXX Memory configuration should be picked up from PMON2k */
  369. #ifdef CONFIG_JAGUAR_DMALOW
  370. printk("Jaguar ATX DMA-low mode set\n");
  371. add_memory_region(0x00000000, 0x08000000, BOOT_MEM_RAM);
  372. add_memory_region(0x08000000, 0x10000000, BOOT_MEM_RAM);
  373. #else
  374. /* 128MiB of MV-64340 DDR RAM */
  375. printk("Jaguar ATX DMA-low mode is not set\n");
  376. add_memory_region(0x100<<20, 0x80<<20, BOOT_MEM_RAM);
  377. #endif
  378. #ifdef GEMDEBUG_TRACEBUFFER
  379. {
  380. unsigned int tbControl;
  381. tbControl =
  382. 0 << 26 | /* post trigger delay 0 */
  383. 0x2 << 16 | /* sequential trace mode */
  384. // 0x0 << 16 | /* non-sequential trace mode */
  385. // 0xf << 4 | /* watchpoints disabled */
  386. 2 << 2 | /* armed */
  387. 2 ; /* interrupt disabled */
  388. printk ("setting tbControl = %08lx\n", tbControl);
  389. write_32bit_cp0_set1_register($22, tbControl);
  390. __asm__ __volatile__(".set noreorder\n\t" \
  391. "nop; nop; nop; nop; nop; nop;\n\t" \
  392. "nop; nop; nop; nop; nop; nop;\n\t" \
  393. ".set reorder\n\t");
  394. }
  395. #endif
  396. }