excite_setup.c 8.9 KB

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