prpmc750.c 9.8 KB

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