setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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/reboot.h>
  65. #include <asm/tlbflush.h>
  66. #include "jaguar_atx_fpga.h"
  67. extern unsigned long mv64340_sram_base;
  68. unsigned long cpu_clock;
  69. /* These functions are used for rebooting or halting the machine*/
  70. extern void momenco_jaguar_restart(char *command);
  71. extern void momenco_jaguar_halt(void);
  72. extern void momenco_jaguar_power_off(void);
  73. void momenco_time_init(void);
  74. static char reset_reason;
  75. static inline 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. void __init bus_error_init(void) { /* nothing */ }
  82. /*
  83. * Load a few TLB entries for the MV64340 and perhiperals. The MV64340 is going
  84. * to be hit on every IRQ anyway - there's absolutely no point in letting it be
  85. * a random TLB entry, as it'll just cause needless churning of the TLB. And we
  86. * use the other half for the serial port, which is just a PITA otherwise :)
  87. *
  88. * Device Physical Virtual
  89. * MV64340 Internal Regs 0xf4000000 0xf4000000
  90. * Ocelot-C[S] PLD (CS0) 0xfc000000 0xfc000000
  91. * NVRAM (CS1) 0xfc800000 0xfc800000
  92. * UARTs (CS2) 0xfd000000 0xfd000000
  93. * Internal SRAM 0xfe000000 0xfe000000
  94. * M-Systems DOC (CS3) 0xff000000 0xff000000
  95. */
  96. static __init void wire_stupidity_into_tlb(void)
  97. {
  98. #ifdef CONFIG_32BIT
  99. write_c0_wired(0);
  100. local_flush_tlb_all();
  101. /* marvell and extra space */
  102. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000),
  103. 0xf4000000UL, PM_64K);
  104. /* fpga, rtc, and uart */
  105. add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000),
  106. 0xfc000000UL, PM_16M);
  107. // /* m-sys and internal SRAM */
  108. // add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000),
  109. // 0xfe000000UL, PM_16M);
  110. marvell_base = 0xf4000000;
  111. //mv64340_sram_base = 0xfe000000; /* Currently unused */
  112. #endif
  113. }
  114. unsigned long marvell_base = 0xf4000000L;
  115. unsigned long ja_fpga_base = JAGUAR_ATX_CS0_ADDR;
  116. unsigned long uart_base = 0xfd000000L;
  117. static unsigned char *rtc_base = (unsigned char*) 0xfc800000L;
  118. EXPORT_SYMBOL(marvell_base);
  119. static __init int per_cpu_mappings(void)
  120. {
  121. marvell_base = (unsigned long) ioremap(0xf4000000, 0x10000);
  122. ja_fpga_base = (unsigned long) ioremap(JAGUAR_ATX_CS0_ADDR, 0x1000);
  123. uart_base = (unsigned long) ioremap(0xfd000000UL, 0x1000);
  124. rtc_base = ioremap(0xfc000000UL, 0x8000);
  125. // ioremap(0xfe000000, 32 << 20);
  126. write_c0_wired(0);
  127. local_flush_tlb_all();
  128. ja_setup_console();
  129. return 0;
  130. }
  131. arch_initcall(per_cpu_mappings);
  132. unsigned long m48t37y_get_time(void)
  133. {
  134. unsigned int year, month, day, hour, min, sec;
  135. unsigned long flags;
  136. spin_lock_irqsave(&rtc_lock, flags);
  137. /* stop the update */
  138. rtc_base[0x7ff8] = 0x40;
  139. year = BCD2BIN(rtc_base[0x7fff]);
  140. year += BCD2BIN(rtc_base[0x7ff1]) * 100;
  141. month = BCD2BIN(rtc_base[0x7ffe]);
  142. day = BCD2BIN(rtc_base[0x7ffd]);
  143. hour = BCD2BIN(rtc_base[0x7ffb]);
  144. min = BCD2BIN(rtc_base[0x7ffa]);
  145. sec = BCD2BIN(rtc_base[0x7ff9]);
  146. /* start the update */
  147. rtc_base[0x7ff8] = 0x00;
  148. spin_unlock_irqrestore(&rtc_lock, flags);
  149. return mktime(year, month, day, hour, min, sec);
  150. }
  151. int m48t37y_set_time(unsigned long sec)
  152. {
  153. struct rtc_time tm;
  154. unsigned long flags;
  155. /* convert to a more useful format -- note months count from 0 */
  156. to_tm(sec, &tm);
  157. tm.tm_mon += 1;
  158. spin_lock_irqsave(&rtc_lock, flags);
  159. /* enable writing */
  160. rtc_base[0x7ff8] = 0x80;
  161. /* year */
  162. rtc_base[0x7fff] = BIN2BCD(tm.tm_year % 100);
  163. rtc_base[0x7ff1] = BIN2BCD(tm.tm_year / 100);
  164. /* month */
  165. rtc_base[0x7ffe] = BIN2BCD(tm.tm_mon);
  166. /* day */
  167. rtc_base[0x7ffd] = BIN2BCD(tm.tm_mday);
  168. /* hour/min/sec */
  169. rtc_base[0x7ffb] = BIN2BCD(tm.tm_hour);
  170. rtc_base[0x7ffa] = BIN2BCD(tm.tm_min);
  171. rtc_base[0x7ff9] = BIN2BCD(tm.tm_sec);
  172. /* day of week -- not really used, but let's keep it up-to-date */
  173. rtc_base[0x7ffc] = BIN2BCD(tm.tm_wday + 1);
  174. /* disable writing */
  175. rtc_base[0x7ff8] = 0x00;
  176. spin_unlock_irqrestore(&rtc_lock, flags);
  177. return 0;
  178. }
  179. void __init plat_timer_setup(struct irqaction *irq)
  180. {
  181. setup_irq(8, irq);
  182. }
  183. /*
  184. * Ugly but the least of all evils. TLB initialization did flush the TLB so
  185. * We need to setup mappings again before we can touch the RTC.
  186. */
  187. void momenco_time_init(void)
  188. {
  189. wire_stupidity_into_tlb();
  190. mips_hpt_frequency = cpu_clock / 2;
  191. rtc_mips_get_time = m48t37y_get_time;
  192. rtc_mips_set_time = m48t37y_set_time;
  193. }
  194. static struct resource mv_pci_io_mem0_resource = {
  195. .name = "MV64340 PCI0 IO MEM",
  196. .flags = IORESOURCE_IO
  197. };
  198. static struct resource mv_pci_mem0_resource = {
  199. .name = "MV64340 PCI0 MEM",
  200. .flags = IORESOURCE_MEM
  201. };
  202. static struct mv_pci_controller mv_bus0_controller = {
  203. .pcic = {
  204. .pci_ops = &mv_pci_ops,
  205. .mem_resource = &mv_pci_mem0_resource,
  206. .io_resource = &mv_pci_io_mem0_resource,
  207. },
  208. .config_addr = MV64340_PCI_0_CONFIG_ADDR,
  209. .config_vreg = MV64340_PCI_0_CONFIG_DATA_VIRTUAL_REG,
  210. };
  211. static uint32_t mv_io_base, mv_io_size;
  212. static void ja_pci0_init(void)
  213. {
  214. uint32_t mem0_base, mem0_size;
  215. uint32_t io_base, io_size;
  216. io_base = MV_READ(MV64340_PCI_0_IO_BASE_ADDR) << 16;
  217. io_size = (MV_READ(MV64340_PCI_0_IO_SIZE) + 1) << 16;
  218. mem0_base = MV_READ(MV64340_PCI_0_MEMORY0_BASE_ADDR) << 16;
  219. mem0_size = (MV_READ(MV64340_PCI_0_MEMORY0_SIZE) + 1) << 16;
  220. mv_pci_io_mem0_resource.start = 0;
  221. mv_pci_io_mem0_resource.end = io_size - 1;
  222. mv_pci_mem0_resource.start = mem0_base;
  223. mv_pci_mem0_resource.end = mem0_base + mem0_size - 1;
  224. mv_bus0_controller.pcic.mem_offset = mem0_base;
  225. mv_bus0_controller.pcic.io_offset = 0;
  226. ioport_resource.end = io_size - 1;
  227. register_pci_controller(&mv_bus0_controller.pcic);
  228. mv_io_base = io_base;
  229. mv_io_size = io_size;
  230. }
  231. static struct resource mv_pci_io_mem1_resource = {
  232. .name = "MV64340 PCI1 IO MEM",
  233. .flags = IORESOURCE_IO
  234. };
  235. static struct resource mv_pci_mem1_resource = {
  236. .name = "MV64340 PCI1 MEM",
  237. .flags = IORESOURCE_MEM
  238. };
  239. static struct mv_pci_controller mv_bus1_controller = {
  240. .pcic = {
  241. .pci_ops = &mv_pci_ops,
  242. .mem_resource = &mv_pci_mem1_resource,
  243. .io_resource = &mv_pci_io_mem1_resource,
  244. },
  245. .config_addr = MV64340_PCI_1_CONFIG_ADDR,
  246. .config_vreg = MV64340_PCI_1_CONFIG_DATA_VIRTUAL_REG,
  247. };
  248. static __init void ja_pci1_init(void)
  249. {
  250. uint32_t mem0_base, mem0_size;
  251. uint32_t io_base, io_size;
  252. io_base = MV_READ(MV64340_PCI_1_IO_BASE_ADDR) << 16;
  253. io_size = (MV_READ(MV64340_PCI_1_IO_SIZE) + 1) << 16;
  254. mem0_base = MV_READ(MV64340_PCI_1_MEMORY0_BASE_ADDR) << 16;
  255. mem0_size = (MV_READ(MV64340_PCI_1_MEMORY0_SIZE) + 1) << 16;
  256. /*
  257. * Here we assume the I/O window of second bus to be contiguous with
  258. * the first. A gap is no problem but would waste address space for
  259. * remapping the port space.
  260. */
  261. mv_pci_io_mem1_resource.start = mv_io_size;
  262. mv_pci_io_mem1_resource.end = mv_io_size + io_size - 1;
  263. mv_pci_mem1_resource.start = mem0_base;
  264. mv_pci_mem1_resource.end = mem0_base + mem0_size - 1;
  265. mv_bus1_controller.pcic.mem_offset = mem0_base;
  266. mv_bus1_controller.pcic.io_offset = 0;
  267. ioport_resource.end = io_base + io_size -mv_io_base - 1;
  268. register_pci_controller(&mv_bus1_controller.pcic);
  269. mv_io_size = io_base + io_size - mv_io_base;
  270. }
  271. static __init int __init ja_pci_init(void)
  272. {
  273. unsigned long io_v_base;
  274. uint32_t enable;
  275. enable = ~MV_READ(MV64340_BASE_ADDR_ENABLE);
  276. /*
  277. * We require at least one enabled I/O or PCI memory window or we
  278. * will ignore this PCI bus. We ignore PCI windows 1, 2 and 3.
  279. */
  280. if (enable & (0x01 << 9) || enable & (0x01 << 10))
  281. ja_pci0_init();
  282. if (enable & (0x01 << 14) || enable & (0x01 << 15))
  283. ja_pci1_init();
  284. if (mv_io_size) {
  285. io_v_base = (unsigned long) ioremap(mv_io_base, mv_io_size);
  286. if (!io_v_base)
  287. panic("Could not ioremap I/O port range");
  288. set_io_port_base(io_v_base);
  289. }
  290. return 0;
  291. }
  292. arch_initcall(ja_pci_init);
  293. void __init plat_mem_setup(void)
  294. {
  295. unsigned int tmpword;
  296. board_time_init = momenco_time_init;
  297. _machine_restart = momenco_jaguar_restart;
  298. _machine_halt = momenco_jaguar_halt;
  299. pm_power_off = momenco_jaguar_power_off;
  300. /*
  301. * initrd_start = (unsigned long)jaguar_initrd_start;
  302. * initrd_end = (unsigned long)jaguar_initrd_start + (ulong)jaguar_initrd_size;
  303. * initrd_below_start_ok = 1;
  304. */
  305. wire_stupidity_into_tlb();
  306. /*
  307. * shut down ethernet ports, just to be sure our memory doesn't get
  308. * corrupted by random ethernet traffic.
  309. */
  310. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
  311. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
  312. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(2), 0xff << 8);
  313. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
  314. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
  315. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(2), 0xff << 8);
  316. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
  317. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
  318. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(2)) & 0xff);
  319. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
  320. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
  321. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(2)) & 0xff);
  322. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0),
  323. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
  324. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1),
  325. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
  326. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(2),
  327. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(2)) & ~1);
  328. /* Turn off the Bit-Error LED */
  329. JAGUAR_FPGA_WRITE(0x80, CLR);
  330. tmpword = JAGUAR_FPGA_READ(BOARDREV);
  331. if (tmpword < 26)
  332. printk("Momentum Jaguar-ATX: Board Assembly Rev. %c\n",
  333. 'A'+tmpword);
  334. else
  335. printk("Momentum Jaguar-ATX: Board Assembly Revision #0x%x\n",
  336. tmpword);
  337. tmpword = JAGUAR_FPGA_READ(FPGA_REV);
  338. printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
  339. tmpword = JAGUAR_FPGA_READ(RESET_STATUS);
  340. printk("Reset reason: 0x%x\n", tmpword);
  341. switch (tmpword) {
  342. case 0x1:
  343. printk(" - Power-up reset\n");
  344. break;
  345. case 0x2:
  346. printk(" - Push-button reset\n");
  347. break;
  348. case 0x8:
  349. printk(" - Watchdog reset\n");
  350. break;
  351. case 0x10:
  352. printk(" - JTAG reset\n");
  353. break;
  354. default:
  355. printk(" - Unknown reset cause\n");
  356. }
  357. reset_reason = tmpword;
  358. JAGUAR_FPGA_WRITE(0xff, RESET_STATUS);
  359. tmpword = JAGUAR_FPGA_READ(BOARD_STATUS);
  360. printk("Board Status register: 0x%02x\n", tmpword);
  361. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  362. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  363. /* 256MiB of RM9000x2 DDR */
  364. // add_memory_region(0x0, 0x100<<20, BOOT_MEM_RAM);
  365. /* 128MiB of MV-64340 DDR */
  366. // add_memory_region(0x100<<20, 0x80<<20, BOOT_MEM_RAM);
  367. /* XXX Memory configuration should be picked up from PMON2k */
  368. #ifdef CONFIG_JAGUAR_DMALOW
  369. printk("Jaguar ATX DMA-low mode set\n");
  370. add_memory_region(0x00000000, 0x08000000, BOOT_MEM_RAM);
  371. add_memory_region(0x08000000, 0x10000000, BOOT_MEM_RAM);
  372. #else
  373. /* 128MiB of MV-64340 DDR RAM */
  374. printk("Jaguar ATX DMA-low mode is not set\n");
  375. add_memory_region(0x100<<20, 0x80<<20, BOOT_MEM_RAM);
  376. #endif
  377. #ifdef GEMDEBUG_TRACEBUFFER
  378. {
  379. unsigned int tbControl;
  380. tbControl =
  381. 0 << 26 | /* post trigger delay 0 */
  382. 0x2 << 16 | /* sequential trace mode */
  383. // 0x0 << 16 | /* non-sequential trace mode */
  384. // 0xf << 4 | /* watchpoints disabled */
  385. 2 << 2 | /* armed */
  386. 2 ; /* interrupt disabled */
  387. printk ("setting tbControl = %08lx\n", tbControl);
  388. write_32bit_cp0_set1_register($22, tbControl);
  389. __asm__ __volatile__(".set noreorder\n\t" \
  390. "nop; nop; nop; nop; nop; nop;\n\t" \
  391. "nop; nop; nop; nop; nop; nop;\n\t" \
  392. ".set reorder\n\t");
  393. }
  394. #endif
  395. }