excite_setup.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Copyright (C) 2004, 2005 by Basler Vision Technologies AG
  3. * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
  4. * Based on the PMC-Sierra Yosemite board support by Ralf Baechle and
  5. * Manish Lachwani.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/string.h>
  25. #include <linux/tty.h>
  26. #include <linux/serial_core.h>
  27. #include <linux/serial.h>
  28. #include <linux/serial_8250.h>
  29. #include <linux/ioport.h>
  30. #include <linux/spinlock.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/mipsregs.h>
  33. #include <asm/pgtable-32.h>
  34. #include <asm/io.h>
  35. #include <asm/time.h>
  36. #include <asm/rm9k-ocd.h>
  37. #include <excite.h>
  38. #define TITAN_UART_CLK 25000000
  39. #if 1
  40. /* normal serial port assignment */
  41. #define REGBASE_SER0 0x0208
  42. #define REGBASE_SER1 0x0238
  43. #define MASK_SER0 0x1
  44. #define MASK_SER1 0x2
  45. #else
  46. /* serial ports swapped */
  47. #define REGBASE_SER0 0x0238
  48. #define REGBASE_SER1 0x0208
  49. #define MASK_SER0 0x2
  50. #define MASK_SER1 0x1
  51. #endif
  52. unsigned long memsize;
  53. char modetty[30];
  54. unsigned int titan_irq = TITAN_IRQ;
  55. static void __iomem * ctl_regs;
  56. u32 unit_id;
  57. volatile void __iomem * const ocd_base = (void *) (EXCITE_ADDR_OCD);
  58. volatile void __iomem * const titan_base = (void *) (EXCITE_ADDR_TITAN);
  59. /* Protect access to shared GPI registers */
  60. DEFINE_SPINLOCK(titan_lock);
  61. int titan_irqflags;
  62. void __init plat_time_init(void)
  63. {
  64. const u32 modebit5 = ocd_readl(0x00e4);
  65. unsigned int
  66. mult = ((modebit5 >> 11) & 0x1f) + 2,
  67. div = ((modebit5 >> 16) & 0x1f) + 2;
  68. if (div == 33) div = 1;
  69. mips_hpt_frequency = EXCITE_CPU_EXT_CLOCK * mult / div / 2;
  70. }
  71. void __init plat_timer_setup(struct irqaction *irq)
  72. {
  73. /* The eXcite platform uses the alternate timer interrupt */
  74. set_c0_intcontrol(0x80);
  75. setup_irq(TIMER_IRQ, irq);
  76. }
  77. static int __init excite_init_console(void)
  78. {
  79. #if defined(CONFIG_SERIAL_8250)
  80. static __initdata char serr[] =
  81. KERN_ERR "Serial port #%u setup failed\n";
  82. struct uart_port up;
  83. /* Take the DUART out of reset */
  84. titan_writel(0x00ff1cff, CPRR);
  85. #if defined(CONFIG_KGDB) || (CONFIG_SERIAL_8250_NR_UARTS > 1)
  86. /* Enable both ports */
  87. titan_writel(MASK_SER0 | MASK_SER1, UACFG);
  88. #else
  89. /* Enable port #0 only */
  90. titan_writel(MASK_SER0, UACFG);
  91. #endif /* defined(CONFIG_KGDB) */
  92. /*
  93. * Set up serial port #0. Do not use autodetection; the result is
  94. * not what we want.
  95. */
  96. memset(&up, 0, sizeof(up));
  97. up.membase = (char *) titan_addr(REGBASE_SER0);
  98. up.irq = TITAN_IRQ;
  99. up.uartclk = TITAN_UART_CLK;
  100. up.regshift = 0;
  101. up.iotype = UPIO_RM9000;
  102. up.type = PORT_RM9000;
  103. up.flags = UPF_SHARE_IRQ;
  104. up.line = 0;
  105. if (early_serial_setup(&up))
  106. printk(serr, up.line);
  107. #if CONFIG_SERIAL_8250_NR_UARTS > 1
  108. /* And now for port #1. */
  109. up.membase = (char *) titan_addr(REGBASE_SER1);
  110. up.line = 1;
  111. if (early_serial_setup(&up))
  112. printk(serr, up.line);
  113. #endif /* CONFIG_SERIAL_8250_NR_UARTS > 1 */
  114. #else
  115. /* Leave the DUART in reset */
  116. titan_writel(0x00ff3cff, CPRR);
  117. #endif /* defined(CONFIG_SERIAL_8250) */
  118. return 0;
  119. }
  120. static int __init excite_platform_init(void)
  121. {
  122. unsigned int i;
  123. unsigned char buf[3];
  124. u8 reg;
  125. void __iomem * dpr;
  126. /* BIU buffer allocations */
  127. ocd_writel(8, CPURSLMT); /* CPU */
  128. titan_writel(4, CPGRWL); /* GPI / Ethernet */
  129. /* Map control registers located in FPGA */
  130. ctl_regs = ioremap_nocache(EXCITE_PHYS_FPGA + EXCITE_FPGA_SYSCTL, 16);
  131. if (!ctl_regs)
  132. panic("eXcite: failed to map platform control registers\n");
  133. memcpy_fromio(buf, ctl_regs + 2, ARRAY_SIZE(buf));
  134. unit_id = buf[0] | (buf[1] << 8) | (buf[2] << 16);
  135. /* Clear the reboot flag */
  136. dpr = ioremap_nocache(EXCITE_PHYS_FPGA + EXCITE_FPGA_DPR, 1);
  137. reg = __raw_readb(dpr);
  138. __raw_writeb(reg & 0x7f, dpr);
  139. iounmap(dpr);
  140. /* Interrupt controller setup */
  141. for (i = INTP0Status0; i < INTP0Status0 + 0x80; i += 0x10) {
  142. ocd_writel(0x00000000, i + 0x04);
  143. ocd_writel(0xffffffff, i + 0x0c);
  144. }
  145. ocd_writel(0x2, NMICONFIG);
  146. ocd_writel(0x1 << (TITAN_MSGINT % 0x20),
  147. INTP0Mask0 + (0x10 * (TITAN_MSGINT / 0x20)));
  148. ocd_writel((0x1 << (FPGA0_MSGINT % 0x20))
  149. | ocd_readl(INTP0Mask0 + (0x10 * (FPGA0_MSGINT / 0x20))),
  150. INTP0Mask0 + (0x10 * (FPGA0_MSGINT / 0x20)));
  151. ocd_writel((0x1 << (FPGA1_MSGINT % 0x20))
  152. | ocd_readl(INTP0Mask0 + (0x10 * (FPGA1_MSGINT / 0x20))),
  153. INTP0Mask0 + (0x10 * (FPGA1_MSGINT / 0x20)));
  154. ocd_writel((0x1 << (PHY_MSGINT % 0x20))
  155. | ocd_readl(INTP0Mask0 + (0x10 * (PHY_MSGINT / 0x20))),
  156. INTP0Mask0 + (0x10 * (PHY_MSGINT / 0x20)));
  157. #if USB_IRQ < 10
  158. ocd_writel((0x1 << (USB_MSGINT % 0x20))
  159. | ocd_readl(INTP0Mask0 + (0x10 * (USB_MSGINT / 0x20))),
  160. INTP0Mask0 + (0x10 * (USB_MSGINT / 0x20)));
  161. #endif
  162. /* Enable the packet FIFO, XDMA and XDMA arbiter */
  163. titan_writel(0x00ff18ff, CPRR);
  164. /*
  165. * Set up the PADMUX. Power down all ethernet slices,
  166. * they will be powered up and configured at device startup.
  167. */
  168. titan_writel(0x00878206, CPTC1R);
  169. titan_writel(0x00001100, CPTC0R); /* latch PADMUX, enable WCIMODE */
  170. /* Reset and enable the FIFO block */
  171. titan_writel(0x00000001, SDRXFCIE);
  172. titan_writel(0x00000001, SDTXFCIE);
  173. titan_writel(0x00000100, SDRXFCIE);
  174. titan_writel(0x00000000, SDTXFCIE);
  175. /*
  176. * Initialize the common interrupt shared by all components of
  177. * the GPI/Ethernet subsystem.
  178. */
  179. titan_writel((EXCITE_PHYS_OCD >> 12), CPCFG0);
  180. titan_writel(TITAN_MSGINT, CPCFG1);
  181. /*
  182. * XDMA configuration.
  183. * In order for the XDMA to be sharable among multiple drivers,
  184. * the setup must be done here in the platform. The reason is that
  185. * this setup can only be done while the XDMA is in reset. If this
  186. * were done in a driver, it would interrupt all other drivers
  187. * using the XDMA.
  188. */
  189. titan_writel(0x80021dff, GXCFG); /* XDMA reset */
  190. titan_writel(0x00000000, CPXCISRA);
  191. titan_writel(0x00000000, CPXCISRB); /* clear pending interrupts */
  192. #if defined(CONFIG_HIGHMEM)
  193. # error change for HIGHMEM support!
  194. #else
  195. titan_writel(0x00000000, GXDMADRPFX); /* buffer address prefix */
  196. #endif
  197. titan_writel(0, GXDMA_DESCADR);
  198. for (i = 0x5040; i <= 0x5300; i += 0x0040)
  199. titan_writel(0x80080000, i); /* reset channel */
  200. titan_writel((0x1 << 29) /* no sparse tx descr. */
  201. | (0x1 << 28) /* no sparse rx descr. */
  202. | (0x1 << 23) | (0x1 << 24) /* descriptor coherency */
  203. | (0x1 << 21) | (0x1 << 22) /* data coherency */
  204. | (0x1 << 17)
  205. | 0x1dff,
  206. GXCFG);
  207. #if defined(CONFIG_SMP)
  208. # error No SMP support
  209. #else
  210. /* All interrupts go to core #0 only. */
  211. titan_writel(0x1f007fff, CPDST0A);
  212. titan_writel(0x00000000, CPDST0B);
  213. titan_writel(0x0000ff3f, CPDST1A);
  214. titan_writel(0x00000000, CPDST1B);
  215. titan_writel(0x00ffffff, CPXDSTA);
  216. titan_writel(0x00000000, CPXDSTB);
  217. #endif
  218. /* Enable DUART interrupts, disable everything else. */
  219. titan_writel(0x04000000, CPGIG0ER);
  220. titan_writel(0x000000c0, CPGIG1ER);
  221. excite_procfs_init();
  222. return 0;
  223. }
  224. void __init plat_mem_setup(void)
  225. {
  226. volatile u32 * const boot_ocd_base = (u32 *) 0xbf7fc000;
  227. /* Announce RAM to system */
  228. add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
  229. /* Set up the peripheral address map */
  230. *(boot_ocd_base + (LKB9 / sizeof(u32))) = 0;
  231. *(boot_ocd_base + (LKB10 / sizeof(u32))) = 0;
  232. *(boot_ocd_base + (LKB11 / sizeof(u32))) = 0;
  233. *(boot_ocd_base + (LKB12 / sizeof(u32))) = 0;
  234. wmb();
  235. *(boot_ocd_base + (LKB0 / sizeof(u32))) = EXCITE_PHYS_OCD >> 4;
  236. wmb();
  237. ocd_writel((EXCITE_PHYS_TITAN >> 4) | 0x1UL, LKB5);
  238. ocd_writel(((EXCITE_SIZE_TITAN >> 4) & 0x7fffff00) - 0x100, LKM5);
  239. ocd_writel((EXCITE_PHYS_SCRAM >> 4) | 0x1UL, LKB13);
  240. ocd_writel(((EXCITE_SIZE_SCRAM >> 4) & 0xffffff00) - 0x100, LKM13);
  241. /* Local bus slot #0 */
  242. ocd_writel(0x00040510, LDP0);
  243. ocd_writel((EXCITE_PHYS_BOOTROM >> 4) | 0x1UL, LKB9);
  244. ocd_writel(((EXCITE_SIZE_BOOTROM >> 4) & 0x03ffff00) - 0x100, LKM9);
  245. /* Local bus slot #2 */
  246. ocd_writel(0x00000330, LDP2);
  247. ocd_writel((EXCITE_PHYS_FPGA >> 4) | 0x1, LKB11);
  248. ocd_writel(((EXCITE_SIZE_FPGA >> 4) - 0x100) & 0x03ffff00, LKM11);
  249. /* Local bus slot #3 */
  250. ocd_writel(0x00123413, LDP3);
  251. ocd_writel((EXCITE_PHYS_NAND >> 4) | 0x1, LKB12);
  252. ocd_writel(((EXCITE_SIZE_NAND >> 4) - 0x100) & 0x03ffff00, LKM12);
  253. }
  254. console_initcall(excite_init_console);
  255. arch_initcall(excite_platform_init);
  256. EXPORT_SYMBOL(titan_lock);
  257. EXPORT_SYMBOL(titan_irqflags);
  258. EXPORT_SYMBOL(titan_irq);
  259. EXPORT_SYMBOL(ocd_base);
  260. EXPORT_SYMBOL(titan_base);