prpmc750.c 9.9 KB

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