mvme5100.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * arch/ppc/platforms/mvme5100.c
  3. *
  4. * Board setup routines for the Motorola MVME5100.
  5. *
  6. * Author: Matt Porter <mporter@mvista.com>
  7. *
  8. * 2001-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/pci.h>
  19. #include <linux/initrd.h>
  20. #include <linux/console.h>
  21. #include <linux/delay.h>
  22. #include <linux/irq.h>
  23. #include <linux/ide.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/root_dev.h>
  27. #include <asm/system.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/page.h>
  30. #include <asm/dma.h>
  31. #include <asm/io.h>
  32. #include <asm/machdep.h>
  33. #include <asm/open_pic.h>
  34. #include <asm/i8259.h>
  35. #include <asm/todc.h>
  36. #include <asm/pci-bridge.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/hawk.h>
  39. #include <platforms/pplus.h>
  40. #include <platforms/mvme5100.h>
  41. static u_char mvme5100_openpic_initsenses[16] __initdata = {
  42. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* i8259 cascade */
  43. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* TL16C550 UART 1,2 */
  44. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Enet1 front panel or P2 */
  45. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Hawk Watchdog 1,2 */
  46. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* DS1621 thermal alarm */
  47. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Universe II LINT0# */
  48. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Universe II LINT1# */
  49. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Universe II LINT2# */
  50. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Universe II LINT3# */
  51. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PMC1 INTA#, PMC2 INTB# */
  52. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PMC1 INTB#, PMC2 INTC# */
  53. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PMC1 INTC#, PMC2 INTD# */
  54. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PMC1 INTD#, PMC2 INTA# */
  55. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Enet 2 (front panel) */
  56. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Abort Switch */
  57. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* RTC Alarm */
  58. };
  59. static inline int
  60. mvme5100_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  61. {
  62. int irq;
  63. static char pci_irq_table[][4] =
  64. /*
  65. * PCI IDSEL/INTPIN->INTLINE
  66. * A B C D
  67. */
  68. {
  69. { 0, 0, 0, 0 }, /* IDSEL 11 - Winbond */
  70. { 0, 0, 0, 0 }, /* IDSEL 12 - unused */
  71. { 21, 22, 23, 24 }, /* IDSEL 13 - Universe II */
  72. { 18, 0, 0, 0 }, /* IDSEL 14 - Enet 1 */
  73. { 0, 0, 0, 0 }, /* IDSEL 15 - unused */
  74. { 25, 26, 27, 28 }, /* IDSEL 16 - PMC Slot 1 */
  75. { 28, 25, 26, 27 }, /* IDSEL 17 - PMC Slot 2 */
  76. { 0, 0, 0, 0 }, /* IDSEL 18 - unused */
  77. { 29, 0, 0, 0 }, /* IDSEL 19 - Enet 2 */
  78. { 0, 0, 0, 0 }, /* IDSEL 20 - PMCSPAN */
  79. };
  80. const long min_idsel = 11, max_idsel = 20, irqs_per_slot = 4;
  81. irq = PCI_IRQ_TABLE_LOOKUP;
  82. /* If lookup is zero, always return 0 */
  83. if (!irq)
  84. return 0;
  85. else
  86. #ifdef CONFIG_MVME5100_IPMC761_PRESENT
  87. /* If IPMC761 present, return table value */
  88. return irq;
  89. #else
  90. /* If IPMC761 not present, we don't have an i8259 so adjust */
  91. return (irq - NUM_8259_INTERRUPTS);
  92. #endif
  93. }
  94. static void
  95. mvme5100_pcibios_fixup_resources(struct pci_dev *dev)
  96. {
  97. int i;
  98. if ((dev->vendor == PCI_VENDOR_ID_MOTOROLA) &&
  99. (dev->device == PCI_DEVICE_ID_MOTOROLA_HAWK))
  100. for (i=0; i<DEVICE_COUNT_RESOURCE; i++)
  101. {
  102. dev->resource[i].start = 0;
  103. dev->resource[i].end = 0;
  104. }
  105. }
  106. static void __init
  107. mvme5100_setup_bridge(void)
  108. {
  109. struct pci_controller* hose;
  110. hose = pcibios_alloc_controller();
  111. if (!hose)
  112. return;
  113. hose->first_busno = 0;
  114. hose->last_busno = 0xff;
  115. hose->pci_mem_offset = MVME5100_PCI_MEM_OFFSET;
  116. pci_init_resource(&hose->io_resource, MVME5100_PCI_LOWER_IO,
  117. MVME5100_PCI_UPPER_IO, IORESOURCE_IO,
  118. "PCI host bridge");
  119. pci_init_resource(&hose->mem_resources[0], MVME5100_PCI_LOWER_MEM,
  120. MVME5100_PCI_UPPER_MEM, IORESOURCE_MEM,
  121. "PCI host bridge");
  122. hose->io_space.start = MVME5100_PCI_LOWER_IO;
  123. hose->io_space.end = MVME5100_PCI_UPPER_IO;
  124. hose->mem_space.start = MVME5100_PCI_LOWER_MEM;
  125. hose->mem_space.end = MVME5100_PCI_UPPER_MEM;
  126. hose->io_base_virt = (void *)MVME5100_ISA_IO_BASE;
  127. /* Use indirect method of Hawk */
  128. setup_indirect_pci(hose, MVME5100_PCI_CONFIG_ADDR,
  129. MVME5100_PCI_CONFIG_DATA);
  130. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  131. ppc_md.pcibios_fixup_resources = mvme5100_pcibios_fixup_resources;
  132. ppc_md.pci_swizzle = common_swizzle;
  133. ppc_md.pci_map_irq = mvme5100_map_irq;
  134. }
  135. static void __init
  136. mvme5100_setup_arch(void)
  137. {
  138. if ( ppc_md.progress )
  139. ppc_md.progress("mvme5100_setup_arch: enter", 0);
  140. loops_per_jiffy = 50000000 / HZ;
  141. #ifdef CONFIG_BLK_DEV_INITRD
  142. if (initrd_start)
  143. ROOT_DEV = Root_RAM0;
  144. else
  145. #endif
  146. #ifdef CONFIG_ROOT_NFS
  147. ROOT_DEV = Root_NFS;
  148. #else
  149. ROOT_DEV = Root_SDA2;
  150. #endif
  151. if ( ppc_md.progress )
  152. ppc_md.progress("mvme5100_setup_arch: find_bridges", 0);
  153. /* Setup PCI host bridge */
  154. mvme5100_setup_bridge();
  155. /* Find and map our OpenPIC */
  156. hawk_mpic_init(MVME5100_PCI_MEM_OFFSET);
  157. OpenPIC_InitSenses = mvme5100_openpic_initsenses;
  158. OpenPIC_NumInitSenses = sizeof(mvme5100_openpic_initsenses);
  159. printk("MVME5100 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
  160. if ( ppc_md.progress )
  161. ppc_md.progress("mvme5100_setup_arch: exit", 0);
  162. return;
  163. }
  164. static void __init
  165. mvme5100_init2(void)
  166. {
  167. #ifdef CONFIG_MVME5100_IPMC761_PRESENT
  168. request_region(0x00,0x20,"dma1");
  169. request_region(0x20,0x20,"pic1");
  170. request_region(0x40,0x20,"timer");
  171. request_region(0x80,0x10,"dma page reg");
  172. request_region(0xa0,0x20,"pic2");
  173. request_region(0xc0,0x20,"dma2");
  174. #endif
  175. return;
  176. }
  177. /*
  178. * Interrupt setup and service.
  179. * Have MPIC on HAWK and cascaded 8259s on Winbond cascaded to MPIC.
  180. */
  181. static void __init
  182. mvme5100_init_IRQ(void)
  183. {
  184. #ifdef CONFIG_MVME5100_IPMC761_PRESENT
  185. int i;
  186. #endif
  187. if ( ppc_md.progress )
  188. ppc_md.progress("init_irq: enter", 0);
  189. openpic_set_sources(0, 16, OpenPIC_Addr + 0x10000);
  190. #ifdef CONFIG_MVME5100_IPMC761_PRESENT
  191. openpic_init(NUM_8259_INTERRUPTS);
  192. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  193. &i8259_irq);
  194. /* Map i8259 interrupts. */
  195. for (i = 0; i < NUM_8259_INTERRUPTS; i++)
  196. irq_desc[i].handler = &i8259_pic;
  197. i8259_init(0);
  198. #else
  199. openpic_init(0);
  200. #endif
  201. if ( ppc_md.progress )
  202. ppc_md.progress("init_irq: exit", 0);
  203. return;
  204. }
  205. /*
  206. * Set BAT 3 to map 0xf0000000 to end of physical memory space.
  207. */
  208. static __inline__ void
  209. mvme5100_set_bat(void)
  210. {
  211. mb();
  212. mtspr(SPRN_DBAT1U, 0xf0001ffe);
  213. mtspr(SPRN_DBAT1L, 0xf000002a);
  214. mb();
  215. }
  216. static unsigned long __init
  217. mvme5100_find_end_of_memory(void)
  218. {
  219. return hawk_get_mem_size(MVME5100_HAWK_SMC_BASE);
  220. }
  221. static void __init
  222. mvme5100_map_io(void)
  223. {
  224. io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
  225. ioremap_base = 0xfe000000;
  226. }
  227. static void
  228. mvme5100_reset_board(void)
  229. {
  230. local_irq_disable();
  231. /* Set exception prefix high - to the firmware */
  232. _nmask_and_or_msr(0, MSR_IP);
  233. out_8((u_char *)MVME5100_BOARD_MODRST_REG, 0x01);
  234. return;
  235. }
  236. static void
  237. mvme5100_restart(char *cmd)
  238. {
  239. volatile ulong i = 10000000;
  240. mvme5100_reset_board();
  241. while (i-- > 0);
  242. panic("restart failed\n");
  243. }
  244. static void
  245. mvme5100_halt(void)
  246. {
  247. local_irq_disable();
  248. while (1);
  249. }
  250. static void
  251. mvme5100_power_off(void)
  252. {
  253. mvme5100_halt();
  254. }
  255. static int
  256. mvme5100_show_cpuinfo(struct seq_file *m)
  257. {
  258. seq_printf(m, "vendor\t\t: Motorola\n");
  259. seq_printf(m, "machine\t\t: MVME5100\n");
  260. return 0;
  261. }
  262. TODC_ALLOC();
  263. void __init
  264. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  265. unsigned long r6, unsigned long r7)
  266. {
  267. parse_bootinfo(find_bootinfo());
  268. mvme5100_set_bat();
  269. isa_io_base = MVME5100_ISA_IO_BASE;
  270. isa_mem_base = MVME5100_ISA_MEM_BASE;
  271. pci_dram_offset = MVME5100_PCI_DRAM_OFFSET;
  272. ppc_md.setup_arch = mvme5100_setup_arch;
  273. ppc_md.show_cpuinfo = mvme5100_show_cpuinfo;
  274. ppc_md.init_IRQ = mvme5100_init_IRQ;
  275. ppc_md.get_irq = openpic_get_irq;
  276. ppc_md.init = mvme5100_init2;
  277. ppc_md.restart = mvme5100_restart;
  278. ppc_md.power_off = mvme5100_power_off;
  279. ppc_md.halt = mvme5100_halt;
  280. ppc_md.find_end_of_memory = mvme5100_find_end_of_memory;
  281. ppc_md.setup_io_mappings = mvme5100_map_io;
  282. TODC_INIT(TODC_TYPE_MK48T37, MVME5100_NVRAM_AS0, MVME5100_NVRAM_AS1,
  283. MVME5100_NVRAM_DATA, 8);
  284. ppc_md.time_init = todc_time_init;
  285. ppc_md.set_rtc_time = todc_set_rtc_time;
  286. ppc_md.get_rtc_time = todc_get_rtc_time;
  287. ppc_md.calibrate_decr = todc_calibrate_decr;
  288. ppc_md.nvram_read_val = todc_m48txx_read_val;
  289. ppc_md.nvram_write_val = todc_m48txx_write_val;
  290. }