prpmc750.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * arch/ppc/platforms/prpmc750_setup.c
  3. *
  4. * Board setup routines for Motorola PrPMC750
  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/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/irq.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/ide.h>
  29. #include <linux/root_dev.h>
  30. #include <linux/slab.h>
  31. #include <asm/byteorder.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/irq.h>
  38. #include <asm/machdep.h>
  39. #include <asm/pci-bridge.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/time.h>
  42. #include <asm/open_pic.h>
  43. #include <asm/bootinfo.h>
  44. #include <asm/hawk.h>
  45. #include "prpmc750.h"
  46. extern unsigned long loops_per_jiffy;
  47. extern void gen550_progress(char *, unsigned short);
  48. static u_char prpmc750_openpic_initsenses[] __initdata =
  49. {
  50. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT0 */
  51. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UART */
  52. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_DEBUGINT */
  53. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HAWK_WDT */
  54. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
  55. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_ABORT */
  56. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT1 */
  57. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT2 */
  58. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_HOSTINT3 */
  59. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTA */
  60. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTB */
  61. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTC */
  62. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_PMC_INTD */
  63. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
  64. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
  65. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC750_INT_UNUSED */
  66. };
  67. /*
  68. * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
  69. * Combined irq tables. Only Base has IDSEL 14, only Carrier has 21 and 22.
  70. */
  71. static inline int
  72. prpmc_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  73. {
  74. static char pci_irq_table[][4] =
  75. /*
  76. * PCI IDSEL/INTPIN->INTLINE
  77. * A B C D
  78. */
  79. {
  80. {12, 0, 0, 0}, /* IDSEL 14 - Ethernet, base */
  81. {0, 0, 0, 0}, /* IDSEL 15 - unused */
  82. {10, 11, 12, 9}, /* IDSEL 16 - PMC A1, PMC1 */
  83. {10, 11, 12, 9}, /* IDSEL 17 - PrPMC-A-B, PMC2-B */
  84. {11, 12, 9, 10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
  85. {0, 0, 0, 0}, /* IDSEL 19 - unused */
  86. {9, 10, 11, 12}, /* IDSEL 20 - P2P Bridge */
  87. {11, 12, 9, 10}, /* IDSEL 21 - PMC A2, carrier */
  88. {12, 9, 10, 11}, /* IDSEL 22 - PMC A2-B, carrier */
  89. };
  90. const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
  91. return PCI_IRQ_TABLE_LOOKUP;
  92. };
  93. static void __init prpmc750_pcibios_fixup(void)
  94. {
  95. struct pci_dev *dev;
  96. unsigned short wtmp;
  97. /*
  98. * Kludge to clean up after PPC6BUG which doesn't
  99. * configure the CL5446 VGA card. Also the
  100. * resource subsystem doesn't fixup the
  101. * PCI mem resources on the CL5446.
  102. */
  103. if ((dev = pci_get_device(PCI_VENDOR_ID_CIRRUS,
  104. PCI_DEVICE_ID_CIRRUS_5446, 0))) {
  105. dev->resource[0].start += PRPMC750_PCI_PHY_MEM_OFFSET;
  106. dev->resource[0].end += PRPMC750_PCI_PHY_MEM_OFFSET;
  107. pci_read_config_word(dev, PCI_COMMAND, &wtmp);
  108. pci_write_config_word(dev, PCI_COMMAND, wtmp | 3);
  109. /* Enable Color mode in MISC reg */
  110. outb(0x03, 0x3c2);
  111. /* Select DRAM config reg */
  112. outb(0x0f, 0x3c4);
  113. /* Set proper DRAM config */
  114. outb(0xdf, 0x3c5);
  115. pci_dev_put(dev);
  116. }
  117. }
  118. void __init prpmc750_find_bridges(void)
  119. {
  120. struct pci_controller *hose;
  121. hose = pcibios_alloc_controller();
  122. if (!hose)
  123. return;
  124. hose->first_busno = 0;
  125. hose->last_busno = 0xff;
  126. hose->io_base_virt = (void *)PRPMC750_ISA_IO_BASE;
  127. hose->pci_mem_offset = PRPMC750_PCI_PHY_MEM_OFFSET;
  128. pci_init_resource(&hose->io_resource,
  129. PRPMC750_PCI_IO_START,
  130. PRPMC750_PCI_IO_END,
  131. IORESOURCE_IO, "PCI host bridge");
  132. pci_init_resource(&hose->mem_resources[0],
  133. PRPMC750_PROC_PCI_MEM_START,
  134. PRPMC750_PROC_PCI_MEM_END,
  135. IORESOURCE_MEM, "PCI host bridge");
  136. hose->io_space.start = PRPMC750_PCI_IO_START;
  137. hose->io_space.end = PRPMC750_PCI_IO_END;
  138. hose->mem_space.start = PRPMC750_PCI_MEM_START;
  139. hose->mem_space.end = PRPMC750_PCI_MEM_END - HAWK_MPIC_SIZE;
  140. if (hawk_init(hose, PRPMC750_HAWK_PPC_REG_BASE,
  141. PRPMC750_PROC_PCI_MEM_START,
  142. PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE,
  143. PRPMC750_PROC_PCI_IO_START, PRPMC750_PROC_PCI_IO_END,
  144. PRPMC750_PROC_PCI_MEM_END - HAWK_MPIC_SIZE + 1)
  145. != 0) {
  146. printk(KERN_CRIT "Could not initialize host bridge\n");
  147. }
  148. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  149. ppc_md.pcibios_fixup = prpmc750_pcibios_fixup;
  150. ppc_md.pci_swizzle = common_swizzle;
  151. ppc_md.pci_map_irq = prpmc_map_irq;
  152. }
  153. static int prpmc750_show_cpuinfo(struct seq_file *m)
  154. {
  155. seq_printf(m, "machine\t\t: PrPMC750\n");
  156. return 0;
  157. }
  158. static void __init prpmc750_setup_arch(void)
  159. {
  160. /* init to some ~sane value until calibrate_delay() runs */
  161. loops_per_jiffy = 50000000 / HZ;
  162. /* Lookup PCI host bridges */
  163. prpmc750_find_bridges();
  164. #ifdef CONFIG_BLK_DEV_INITRD
  165. if (initrd_start)
  166. ROOT_DEV = Root_RAM0;
  167. else
  168. #endif
  169. #ifdef CONFIG_ROOT_NFS
  170. ROOT_DEV = Root_NFS;
  171. #else
  172. ROOT_DEV = Root_SDA2;
  173. #endif
  174. OpenPIC_InitSenses = prpmc750_openpic_initsenses;
  175. OpenPIC_NumInitSenses = sizeof(prpmc750_openpic_initsenses);
  176. printk(KERN_INFO "Port by MontaVista Software, Inc. "
  177. "(source@mvista.com)\n");
  178. }
  179. /*
  180. * Compute the PrPMC750's bus speed using the baud clock as a
  181. * reference.
  182. */
  183. static unsigned long __init prpmc750_get_bus_speed(void)
  184. {
  185. unsigned long tbl_start, tbl_end;
  186. unsigned long current_state, old_state, bus_speed;
  187. unsigned char lcr, dll, dlm;
  188. int baud_divisor, count;
  189. /* Read the UART's baud clock divisor */
  190. lcr = readb(PRPMC750_SERIAL_0_LCR);
  191. writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
  192. dll = readb(PRPMC750_SERIAL_0_DLL);
  193. dlm = readb(PRPMC750_SERIAL_0_DLM);
  194. writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
  195. baud_divisor = (dlm << 8) | dll;
  196. /*
  197. * Use the baud clock divisor and base baud clock
  198. * to determine the baud rate and use that as
  199. * the number of baud clock edges we use for
  200. * the time base sample. Make it half the baud
  201. * rate.
  202. */
  203. count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
  204. /* Find the first edge of the baud clock */
  205. old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
  206. do {
  207. current_state = readb(PRPMC750_STATUS_REG) &
  208. PRPMC750_BAUDOUT_MASK;
  209. } while (old_state == current_state);
  210. old_state = current_state;
  211. /* Get the starting time base value */
  212. tbl_start = get_tbl();
  213. /*
  214. * Loop until we have found a number of edges equal
  215. * to half the count (half the baud rate)
  216. */
  217. do {
  218. do {
  219. current_state = readb(PRPMC750_STATUS_REG) &
  220. PRPMC750_BAUDOUT_MASK;
  221. } while (old_state == current_state);
  222. old_state = current_state;
  223. } while (--count);
  224. /* Get the ending time base value */
  225. tbl_end = get_tbl();
  226. /* Compute bus speed */
  227. bus_speed = (tbl_end - tbl_start) * 128;
  228. return bus_speed;
  229. }
  230. static void __init prpmc750_calibrate_decr(void)
  231. {
  232. unsigned long freq;
  233. int divisor = 4;
  234. freq = prpmc750_get_bus_speed();
  235. tb_ticks_per_jiffy = freq / (HZ * divisor);
  236. tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
  237. }
  238. static void prpmc750_restart(char *cmd)
  239. {
  240. local_irq_disable();
  241. writeb(PRPMC750_MODRST_MASK, PRPMC750_MODRST_REG);
  242. while (1) ;
  243. }
  244. static void prpmc750_halt(void)
  245. {
  246. local_irq_disable();
  247. while (1) ;
  248. }
  249. static void prpmc750_power_off(void)
  250. {
  251. prpmc750_halt();
  252. }
  253. static void __init prpmc750_init_IRQ(void)
  254. {
  255. openpic_init(0);
  256. }
  257. /*
  258. * Set BAT 3 to map 0xf0000000 to end of physical memory space.
  259. */
  260. static __inline__ void prpmc750_set_bat(void)
  261. {
  262. mb();
  263. mtspr(SPRN_DBAT1U, 0xf0001ffe);
  264. mtspr(SPRN_DBAT1L, 0xf000002a);
  265. mb();
  266. }
  267. /*
  268. * We need to read the Falcon/Hawk memory controller
  269. * to properly determine this value
  270. */
  271. static unsigned long __init prpmc750_find_end_of_memory(void)
  272. {
  273. /* Read the memory size from the Hawk SMC */
  274. return hawk_get_mem_size(PRPMC750_HAWK_SMC_BASE);
  275. }
  276. static void __init prpmc750_map_io(void)
  277. {
  278. io_block_mapping(PRPMC750_ISA_IO_BASE, PRPMC750_ISA_IO_BASE,
  279. 0x10000000, _PAGE_IO);
  280. #if 0
  281. io_block_mapping(0xf0000000, 0xc0000000, 0x08000000, _PAGE_IO);
  282. #endif
  283. io_block_mapping(0xf8000000, 0xf8000000, 0x08000000, _PAGE_IO);
  284. }
  285. void __init
  286. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  287. unsigned long r6, unsigned long r7)
  288. {
  289. parse_bootinfo(find_bootinfo());
  290. /* Cover the Hawk registers with a BAT */
  291. prpmc750_set_bat();
  292. isa_io_base = PRPMC750_ISA_IO_BASE;
  293. isa_mem_base = PRPMC750_ISA_MEM_BASE;
  294. pci_dram_offset = PRPMC750_PCI_DRAM_OFFSET;
  295. ppc_md.setup_arch = prpmc750_setup_arch;
  296. ppc_md.show_cpuinfo = prpmc750_show_cpuinfo;
  297. ppc_md.init_IRQ = prpmc750_init_IRQ;
  298. ppc_md.get_irq = openpic_get_irq;
  299. ppc_md.find_end_of_memory = prpmc750_find_end_of_memory;
  300. ppc_md.setup_io_mappings = prpmc750_map_io;
  301. ppc_md.restart = prpmc750_restart;
  302. ppc_md.power_off = prpmc750_power_off;
  303. ppc_md.halt = prpmc750_halt;
  304. /* PrPMC750 has no timekeeper part */
  305. ppc_md.time_init = NULL;
  306. ppc_md.get_rtc_time = NULL;
  307. ppc_md.set_rtc_time = NULL;
  308. ppc_md.calibrate_decr = prpmc750_calibrate_decr;
  309. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  310. ppc_md.progress = gen550_progress;
  311. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  312. }