spruce.c 8.2 KB

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