mvme5100.c 8.3 KB

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