mvme5100.c 8.4 KB

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