prpmc750.c 9.8 KB

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