spruce.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * Board and PCI setup routines for IBM Spruce
  3. *
  4. * Author: MontaVista Software <source@mvista.com>
  5. *
  6. * 2000-2004 (c) MontaVista, Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/reboot.h>
  16. #include <linux/pci.h>
  17. #include <linux/kdev_t.h>
  18. #include <linux/types.h>
  19. #include <linux/major.h>
  20. #include <linux/initrd.h>
  21. #include <linux/console.h>
  22. #include <linux/delay.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/ide.h>
  25. #include <linux/root_dev.h>
  26. #include <linux/serial.h>
  27. #include <linux/tty.h>
  28. #include <linux/serial_core.h>
  29. #include <asm/system.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/page.h>
  32. #include <asm/dma.h>
  33. #include <asm/io.h>
  34. #include <asm/machdep.h>
  35. #include <asm/time.h>
  36. #include <asm/todc.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/kgdb.h>
  39. #include <syslib/cpc700.h>
  40. #include "spruce.h"
  41. static inline int
  42. spruce_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  43. {
  44. static char pci_irq_table[][4] =
  45. /*
  46. * PCI IDSEL/INTPIN->INTLINE
  47. * A B C D
  48. */
  49. {
  50. {23, 24, 25, 26}, /* IDSEL 1 - PCI slot 3 */
  51. {24, 25, 26, 23}, /* IDSEL 2 - PCI slot 2 */
  52. {25, 26, 23, 24}, /* IDSEL 3 - PCI slot 1 */
  53. {26, 23, 24, 25}, /* IDSEL 4 - PCI slot 0 */
  54. };
  55. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  56. return PCI_IRQ_TABLE_LOOKUP;
  57. }
  58. static void __init
  59. spruce_setup_hose(void)
  60. {
  61. struct pci_controller *hose;
  62. /* Setup hose */
  63. hose = pcibios_alloc_controller();
  64. if (!hose)
  65. return;
  66. hose->first_busno = 0;
  67. hose->last_busno = 0xff;
  68. pci_init_resource(&hose->io_resource,
  69. SPRUCE_PCI_LOWER_IO,
  70. SPRUCE_PCI_UPPER_IO,
  71. IORESOURCE_IO,
  72. "PCI host bridge");
  73. pci_init_resource(&hose->mem_resources[0],
  74. SPRUCE_PCI_LOWER_MEM,
  75. SPRUCE_PCI_UPPER_MEM,
  76. IORESOURCE_MEM,
  77. "PCI host bridge");
  78. hose->io_space.start = SPRUCE_PCI_LOWER_IO;
  79. hose->io_space.end = SPRUCE_PCI_UPPER_IO;
  80. hose->mem_space.start = SPRUCE_PCI_LOWER_MEM;
  81. hose->mem_space.end = SPRUCE_PCI_UPPER_MEM;
  82. hose->io_base_virt = (void *)SPRUCE_ISA_IO_BASE;
  83. setup_indirect_pci(hose,
  84. SPRUCE_PCI_CONFIG_ADDR,
  85. SPRUCE_PCI_CONFIG_DATA);
  86. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  87. ppc_md.pci_swizzle = common_swizzle;
  88. ppc_md.pci_map_irq = spruce_map_irq;
  89. }
  90. /*
  91. * CPC700 PIC interrupt programming table
  92. *
  93. * First entry is the sensitivity (level/edge), second is the polarity.
  94. */
  95. unsigned int cpc700_irq_assigns[32][2] = {
  96. { 1, 1 }, /* IRQ 0: ECC Correctable Error - rising edge */
  97. { 1, 1 }, /* IRQ 1: PCI Write Mem Range - rising edge */
  98. { 0, 1 }, /* IRQ 2: PCI Write Command Reg - active high */
  99. { 0, 1 }, /* IRQ 3: UART 0 - active high */
  100. { 0, 1 }, /* IRQ 4: UART 1 - active high */
  101. { 0, 1 }, /* IRQ 5: ICC 0 - active high */
  102. { 0, 1 }, /* IRQ 6: ICC 1 - active high */
  103. { 0, 1 }, /* IRQ 7: GPT Compare 0 - active high */
  104. { 0, 1 }, /* IRQ 8: GPT Compare 1 - active high */
  105. { 0, 1 }, /* IRQ 9: GPT Compare 2 - active high */
  106. { 0, 1 }, /* IRQ 10: GPT Compare 3 - active high */
  107. { 0, 1 }, /* IRQ 11: GPT Compare 4 - active high */
  108. { 0, 1 }, /* IRQ 12: GPT Capture 0 - active high */
  109. { 0, 1 }, /* IRQ 13: GPT Capture 1 - active high */
  110. { 0, 1 }, /* IRQ 14: GPT Capture 2 - active high */
  111. { 0, 1 }, /* IRQ 15: GPT Capture 3 - active high */
  112. { 0, 1 }, /* IRQ 16: GPT Capture 4 - active high */
  113. { 0, 0 }, /* IRQ 17: Reserved */
  114. { 0, 0 }, /* IRQ 18: Reserved */
  115. { 0, 0 }, /* IRQ 19: Reserved */
  116. { 0, 1 }, /* IRQ 20: FPGA EXT_IRQ0 - active high */
  117. { 1, 1 }, /* IRQ 21: Mouse - rising edge */
  118. { 1, 1 }, /* IRQ 22: Keyboard - rising edge */
  119. { 0, 0 }, /* IRQ 23: PCI Slot 3 - active low */
  120. { 0, 0 }, /* IRQ 24: PCI Slot 2 - active low */
  121. { 0, 0 }, /* IRQ 25: PCI Slot 1 - active low */
  122. { 0, 0 }, /* IRQ 26: PCI Slot 0 - active low */
  123. };
  124. static void __init
  125. spruce_calibrate_decr(void)
  126. {
  127. int freq, divisor = 4;
  128. /* determine processor bus speed */
  129. freq = SPRUCE_BUS_SPEED;
  130. tb_ticks_per_jiffy = freq / HZ / divisor;
  131. tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
  132. }
  133. static int
  134. spruce_show_cpuinfo(struct seq_file *m)
  135. {
  136. seq_printf(m, "vendor\t\t: IBM\n");
  137. seq_printf(m, "machine\t\t: Spruce\n");
  138. return 0;
  139. }
  140. static void __init
  141. spruce_early_serial_map(void)
  142. {
  143. u32 uart_clk;
  144. struct uart_port serial_req;
  145. if (SPRUCE_UARTCLK_IS_33M(readb(SPRUCE_FPGA_REG_A)))
  146. uart_clk = SPRUCE_BAUD_33M * 16;
  147. else
  148. uart_clk = SPRUCE_BAUD_30M * 16;
  149. /* Setup serial port access */
  150. memset(&serial_req, 0, sizeof(serial_req));
  151. serial_req.uartclk = uart_clk;
  152. serial_req.irq = UART0_INT;
  153. serial_req.flags = UPF_BOOT_AUTOCONF;
  154. serial_req.iotype = UPIO_MEM;
  155. serial_req.membase = (u_char *)UART0_IO_BASE;
  156. serial_req.regshift = 0;
  157. #if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
  158. gen550_init(0, &serial_req);
  159. #endif
  160. #ifdef CONFIG_SERIAL_8250
  161. if (early_serial_setup(&serial_req) != 0)
  162. printk("Early serial init of port 0 failed\n");
  163. #endif
  164. /* Assume early_serial_setup() doesn't modify serial_req */
  165. serial_req.line = 1;
  166. serial_req.irq = UART1_INT;
  167. serial_req.membase = (u_char *)UART1_IO_BASE;
  168. #if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
  169. gen550_init(1, &serial_req);
  170. #endif
  171. #ifdef CONFIG_SERIAL_8250
  172. if (early_serial_setup(&serial_req) != 0)
  173. printk("Early serial init of port 1 failed\n");
  174. #endif
  175. }
  176. TODC_ALLOC();
  177. static void __init
  178. spruce_setup_arch(void)
  179. {
  180. /* Setup TODC access */
  181. TODC_INIT(TODC_TYPE_DS1643, 0, 0, SPRUCE_RTC_BASE_ADDR, 8);
  182. /* init to some ~sane value until calibrate_delay() runs */
  183. loops_per_jiffy = 50000000 / HZ;
  184. /* Setup PCI host bridge */
  185. spruce_setup_hose();
  186. #ifdef CONFIG_BLK_DEV_INITRD
  187. if (initrd_start)
  188. ROOT_DEV = Root_RAM0;
  189. else
  190. #endif
  191. #ifdef CONFIG_ROOT_NFS
  192. ROOT_DEV = Root_NFS;
  193. #else
  194. ROOT_DEV = Root_SDA1;
  195. #endif
  196. /* Identify the system */
  197. printk(KERN_INFO "System Identification: IBM Spruce\n");
  198. printk(KERN_INFO "Port by MontaVista Software, Inc. (source@mvista.com)\n");
  199. }
  200. static void
  201. spruce_restart(char *cmd)
  202. {
  203. local_irq_disable();
  204. /* SRR0 has system reset vector, SRR1 has default MSR value */
  205. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  206. __asm__ __volatile__
  207. ("\n\
  208. lis 3,0xfff0 \n\
  209. ori 3,3,0x0100 \n\
  210. mtspr 26,3 \n\
  211. li 3,0 \n\
  212. mtspr 27,3 \n\
  213. rfi \n\
  214. ");
  215. for(;;);
  216. }
  217. static void
  218. spruce_power_off(void)
  219. {
  220. for(;;);
  221. }
  222. static void
  223. spruce_halt(void)
  224. {
  225. spruce_restart(NULL);
  226. }
  227. static void __init
  228. spruce_map_io(void)
  229. {
  230. io_block_mapping(SPRUCE_PCI_IO_BASE, SPRUCE_PCI_PHY_IO_BASE,
  231. 0x08000000, _PAGE_IO);
  232. }
  233. /*
  234. * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
  235. */
  236. static __inline__ void
  237. spruce_set_bat(void)
  238. {
  239. mb();
  240. mtspr(SPRN_DBAT1U, 0xf8000ffe);
  241. mtspr(SPRN_DBAT1L, 0xf800002a);
  242. mb();
  243. }
  244. void __init
  245. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  246. unsigned long r6, unsigned long r7)
  247. {
  248. parse_bootinfo(find_bootinfo());
  249. /* Map in board regs, etc. */
  250. spruce_set_bat();
  251. isa_io_base = SPRUCE_ISA_IO_BASE;
  252. pci_dram_offset = SPRUCE_PCI_SYS_MEM_BASE;
  253. ppc_md.setup_arch = spruce_setup_arch;
  254. ppc_md.show_cpuinfo = spruce_show_cpuinfo;
  255. ppc_md.init_IRQ = cpc700_init_IRQ;
  256. ppc_md.get_irq = cpc700_get_irq;
  257. ppc_md.setup_io_mappings = spruce_map_io;
  258. ppc_md.restart = spruce_restart;
  259. ppc_md.power_off = spruce_power_off;
  260. ppc_md.halt = spruce_halt;
  261. ppc_md.time_init = todc_time_init;
  262. ppc_md.set_rtc_time = todc_set_rtc_time;
  263. ppc_md.get_rtc_time = todc_get_rtc_time;
  264. ppc_md.calibrate_decr = spruce_calibrate_decr;
  265. ppc_md.nvram_read_val = todc_direct_read_val;
  266. ppc_md.nvram_write_val = todc_direct_write_val;
  267. spruce_early_serial_map();
  268. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  269. ppc_md.progress = gen550_progress;
  270. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  271. #ifdef CONFIG_KGDB
  272. ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
  273. #endif
  274. }