mvme5100.c 8.3 KB

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