prpmc750.c 9.8 KB

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