prpmc800.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*
  2. * arch/ppc/platforms/prpmc800.c
  3. *
  4. * Author: Dale Farnsworth <dale.farnsworth@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/harrier_defs.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/time.h>
  37. #include <asm/pci-bridge.h>
  38. #include <asm/open_pic.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/harrier.h>
  41. #include "prpmc800.h"
  42. #define HARRIER_REVI_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_REVI_OFF)
  43. #define HARRIER_UCTL_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_UCTL_OFF)
  44. #define HARRIER_MISC_CSR_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_MISC_CSR_OFF)
  45. #define HARRIER_IFEVP_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEVP_OFF)
  46. #define HARRIER_IFEDE_REG (PRPMC800_HARRIER_MPIC_BASE+HARRIER_MPIC_IFEDE_OFF)
  47. #define HARRIER_FEEN_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEEN_OFF)
  48. #define HARRIER_FEMA_REG (PRPMC800_HARRIER_XCSR_BASE+HARRIER_FEMA_OFF)
  49. #define HARRIER_VENI_REG (PRPMC800_HARRIER_XCSR_BASE + HARRIER_VENI_OFF)
  50. #define HARRIER_MISC_CSR (PRPMC800_HARRIER_XCSR_BASE + \
  51. HARRIER_MISC_CSR_OFF)
  52. #define MONARCH (monarch != 0)
  53. #define NON_MONARCH (monarch == 0)
  54. extern int mpic_init(void);
  55. extern unsigned long loops_per_jiffy;
  56. extern void gen550_progress(char *, unsigned short);
  57. static int monarch = 0;
  58. static int found_self = 0;
  59. static int self = 0;
  60. static u_char prpmc800_openpic_initsenses[] __initdata =
  61. {
  62. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT0 */
  63. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  64. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_DEBUGINT */
  65. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HARRIER_WDT */
  66. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  67. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  68. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT1 */
  69. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT2 */
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HOSTINT3 */
  71. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTA */
  72. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTB */
  73. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTC */
  74. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_PMC_INTD */
  75. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  76. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  77. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_UNUSED */
  78. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* PRPMC800_INT_HARRIER_INT (UARTS, ABORT, DMA) */
  79. };
  80. /*
  81. * Motorola PrPMC750/PrPMC800 in PrPMCBASE or PrPMC-Carrier
  82. * Combined irq tables. Only Base has IDSEL 14, only Carrier has 21 and 22.
  83. */
  84. static inline int
  85. prpmc_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  86. {
  87. static char pci_irq_table[][4] =
  88. /*
  89. * PCI IDSEL/INTPIN->INTLINE
  90. * A B C D
  91. */
  92. {
  93. {12, 0, 0, 0}, /* IDSEL 14 - Ethernet, base */
  94. {0, 0, 0, 0}, /* IDSEL 15 - unused */
  95. {10, 11, 12, 9}, /* IDSEL 16 - PMC A1, PMC1 */
  96. {10, 11, 12, 9}, /* IDSEL 17 - PrPMC-A-B, PMC2-B */
  97. {11, 12, 9, 10}, /* IDSEL 18 - PMC A1-B, PMC1-B */
  98. {0, 0, 0, 0}, /* IDSEL 19 - unused */
  99. {9, 10, 11, 12}, /* IDSEL 20 - P2P Bridge */
  100. {11, 12, 9, 10}, /* IDSEL 21 - PMC A2, carrier */
  101. {12, 9, 10, 11}, /* IDSEL 22 - PMC A2-B, carrier */
  102. };
  103. const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
  104. return PCI_IRQ_TABLE_LOOKUP;
  105. };
  106. static int
  107. prpmc_read_config_dword(struct pci_controller *hose, u8 bus, u8 devfn,
  108. int offset, u32 * val)
  109. {
  110. /* paranoia */
  111. if ((hose == NULL) ||
  112. (hose->cfg_addr == NULL) || (hose->cfg_data == NULL))
  113. return PCIBIOS_DEVICE_NOT_FOUND;
  114. out_be32(hose->cfg_addr, ((offset & 0xfc) << 24) | (devfn << 16)
  115. | ((bus - hose->bus_offset) << 8) | 0x80);
  116. *val = in_le32((u32 *) (hose->cfg_data + (offset & 3)));
  117. return PCIBIOS_SUCCESSFUL;
  118. }
  119. #define HARRIER_PCI_VEND_DEV_ID (PCI_VENDOR_ID_MOTOROLA | \
  120. (PCI_DEVICE_ID_MOTOROLA_HARRIER << 16))
  121. static int prpmc_self(u8 bus, u8 devfn)
  122. {
  123. /*
  124. * Harriers always view themselves as being on bus 0. If we're not
  125. * looking at bus 0, we're not going to find ourselves.
  126. */
  127. if (bus != 0)
  128. return PCIBIOS_DEVICE_NOT_FOUND;
  129. else {
  130. int result;
  131. int val;
  132. struct pci_controller *hose;
  133. hose = pci_bus_to_hose(bus);
  134. /* See if target device is a Harrier */
  135. result = prpmc_read_config_dword(hose, bus, devfn,
  136. PCI_VENDOR_ID, &val);
  137. if ((result != PCIBIOS_SUCCESSFUL) ||
  138. (val != HARRIER_PCI_VEND_DEV_ID))
  139. return PCIBIOS_DEVICE_NOT_FOUND;
  140. /*
  141. * LBA bit is set if target Harrier == initiating Harrier
  142. * (i.e. if we are reading our own PCI header).
  143. */
  144. result = prpmc_read_config_dword(hose, bus, devfn,
  145. HARRIER_LBA_OFF, &val);
  146. if ((result != PCIBIOS_SUCCESSFUL) ||
  147. ((val & HARRIER_LBA_MSK) != HARRIER_LBA_MSK))
  148. return PCIBIOS_DEVICE_NOT_FOUND;
  149. /* It's us, save our location for later */
  150. self = devfn;
  151. found_self = 1;
  152. return PCIBIOS_SUCCESSFUL;
  153. }
  154. }
  155. static int prpmc_exclude_device(u8 bus, u8 devfn)
  156. {
  157. /*
  158. * Monarch is allowed to access all PCI devices. Non-monarch is
  159. * only allowed to access its own Harrier.
  160. */
  161. if (MONARCH)
  162. return PCIBIOS_SUCCESSFUL;
  163. if (found_self)
  164. if ((bus == 0) && (devfn == self))
  165. return PCIBIOS_SUCCESSFUL;
  166. else
  167. return PCIBIOS_DEVICE_NOT_FOUND;
  168. else
  169. return prpmc_self(bus, devfn);
  170. }
  171. void __init prpmc800_find_bridges(void)
  172. {
  173. struct pci_controller *hose;
  174. int host_bridge;
  175. hose = pcibios_alloc_controller();
  176. if (!hose)
  177. return;
  178. hose->first_busno = 0;
  179. hose->last_busno = 0xff;
  180. ppc_md.pci_exclude_device = prpmc_exclude_device;
  181. ppc_md.pcibios_fixup = NULL;
  182. ppc_md.pcibios_fixup_bus = NULL;
  183. ppc_md.pci_swizzle = common_swizzle;
  184. ppc_md.pci_map_irq = prpmc_map_irq;
  185. setup_indirect_pci(hose,
  186. PRPMC800_PCI_CONFIG_ADDR, PRPMC800_PCI_CONFIG_DATA);
  187. /* Get host bridge vendor/dev id */
  188. host_bridge = in_be32((uint *) (HARRIER_VENI_REG));
  189. if (host_bridge != HARRIER_VEND_DEV_ID) {
  190. printk(KERN_CRIT "Host bridge 0x%x not supported\n",
  191. host_bridge);
  192. return;
  193. }
  194. monarch = in_be32((uint *) HARRIER_MISC_CSR) & HARRIER_SYSCON;
  195. printk(KERN_INFO "Running as %s.\n",
  196. MONARCH ? "Monarch" : "Non-Monarch");
  197. hose->io_space.start = PRPMC800_PCI_IO_START;
  198. hose->io_space.end = PRPMC800_PCI_IO_END;
  199. hose->io_base_virt = (void *)PRPMC800_ISA_IO_BASE;
  200. hose->pci_mem_offset = PRPMC800_PCI_PHY_MEM_OFFSET;
  201. pci_init_resource(&hose->io_resource,
  202. PRPMC800_PCI_IO_START, PRPMC800_PCI_IO_END,
  203. IORESOURCE_IO, "PCI host bridge");
  204. if (MONARCH) {
  205. hose->mem_space.start = PRPMC800_PCI_MEM_START;
  206. hose->mem_space.end = PRPMC800_PCI_MEM_END;
  207. pci_init_resource(&hose->mem_resources[0],
  208. PRPMC800_PCI_MEM_START,
  209. PRPMC800_PCI_MEM_END,
  210. IORESOURCE_MEM, "PCI host bridge");
  211. if (harrier_init(hose,
  212. PRPMC800_HARRIER_XCSR_BASE,
  213. PRPMC800_PROC_PCI_MEM_START,
  214. PRPMC800_PROC_PCI_MEM_END,
  215. PRPMC800_PROC_PCI_IO_START,
  216. PRPMC800_PROC_PCI_IO_END,
  217. PRPMC800_HARRIER_MPIC_BASE) != 0)
  218. printk(KERN_CRIT "Could not initialize HARRIER "
  219. "bridge\n");
  220. harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE);
  221. harrier_wait_eready(PRPMC800_HARRIER_XCSR_BASE);
  222. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  223. } else {
  224. pci_init_resource(&hose->mem_resources[0],
  225. PRPMC800_NM_PCI_MEM_START,
  226. PRPMC800_NM_PCI_MEM_END,
  227. IORESOURCE_MEM, "PCI host bridge");
  228. hose->mem_space.start = PRPMC800_NM_PCI_MEM_START;
  229. hose->mem_space.end = PRPMC800_NM_PCI_MEM_END;
  230. if (harrier_init(hose,
  231. PRPMC800_HARRIER_XCSR_BASE,
  232. PRPMC800_NM_PROC_PCI_MEM_START,
  233. PRPMC800_NM_PROC_PCI_MEM_END,
  234. PRPMC800_PROC_PCI_IO_START,
  235. PRPMC800_PROC_PCI_IO_END,
  236. PRPMC800_HARRIER_MPIC_BASE) != 0)
  237. printk(KERN_CRIT "Could not initialize HARRIER "
  238. "bridge\n");
  239. harrier_setup_nonmonarch(PRPMC800_HARRIER_XCSR_BASE,
  240. HARRIER_ITSZ_1MB);
  241. harrier_release_eready(PRPMC800_HARRIER_XCSR_BASE);
  242. }
  243. }
  244. static int prpmc800_show_cpuinfo(struct seq_file *m)
  245. {
  246. seq_printf(m, "machine\t\t: PrPMC800\n");
  247. return 0;
  248. }
  249. static void __init prpmc800_setup_arch(void)
  250. {
  251. /* init to some ~sane value until calibrate_delay() runs */
  252. loops_per_jiffy = 50000000 / HZ;
  253. /* Lookup PCI host bridges */
  254. prpmc800_find_bridges();
  255. #ifdef CONFIG_BLK_DEV_INITRD
  256. if (initrd_start)
  257. ROOT_DEV = Root_RAM0;
  258. else
  259. #endif
  260. #ifdef CONFIG_ROOT_NFS
  261. ROOT_DEV = Root_NFS;
  262. #else
  263. ROOT_DEV = Root_SDA2;
  264. #endif
  265. printk(KERN_INFO "Port by MontaVista Software, Inc. "
  266. "(source@mvista.com)\n");
  267. }
  268. /*
  269. * Compute the PrPMC800's tbl frequency using the baud clock as a reference.
  270. */
  271. static void __init prpmc800_calibrate_decr(void)
  272. {
  273. unsigned long tbl_start, tbl_end;
  274. unsigned long current_state, old_state, tb_ticks_per_second;
  275. unsigned int count;
  276. unsigned int harrier_revision;
  277. harrier_revision = readb(HARRIER_REVI_REG);
  278. if (harrier_revision < 2) {
  279. /* XTAL64 was broken in harrier revision 1 */
  280. printk(KERN_INFO "time_init: Harrier revision %d, assuming "
  281. "100 Mhz bus\n", harrier_revision);
  282. tb_ticks_per_second = 100000000 / 4;
  283. tb_ticks_per_jiffy = tb_ticks_per_second / HZ;
  284. tb_to_us = mulhwu_scale_factor(tb_ticks_per_second, 1000000);
  285. return;
  286. }
  287. /*
  288. * The XTAL64 bit oscillates at the 1/64 the base baud clock
  289. * Set count to XTAL64 cycles per second. Since we'll count
  290. * half-cycles, we'll reach the count in half a second.
  291. */
  292. count = PRPMC800_BASE_BAUD / 64;
  293. /* Find the first edge of the baud clock */
  294. old_state = readb(HARRIER_UCTL_REG) & HARRIER_XTAL64_MASK;
  295. do {
  296. current_state = readb(HARRIER_UCTL_REG) & HARRIER_XTAL64_MASK;
  297. } while (old_state == current_state);
  298. old_state = current_state;
  299. /* Get the starting time base value */
  300. tbl_start = get_tbl();
  301. /*
  302. * Loop until we have found a number of edges (half-cycles)
  303. * equal to the count (half a second)
  304. */
  305. do {
  306. do {
  307. current_state = readb(HARRIER_UCTL_REG) &
  308. HARRIER_XTAL64_MASK;
  309. } while (old_state == current_state);
  310. old_state = current_state;
  311. } while (--count);
  312. /* Get the ending time base value */
  313. tbl_end = get_tbl();
  314. /* We only counted for half a second, so double to get ticks/second */
  315. tb_ticks_per_second = (tbl_end - tbl_start) * 2;
  316. tb_ticks_per_jiffy = tb_ticks_per_second / HZ;
  317. tb_to_us = mulhwu_scale_factor(tb_ticks_per_second, 1000000);
  318. }
  319. static void prpmc800_restart(char *cmd)
  320. {
  321. ulong temp;
  322. local_irq_disable();
  323. temp = in_be32((uint *) HARRIER_MISC_CSR_REG);
  324. temp |= HARRIER_RSTOUT;
  325. out_be32((uint *) HARRIER_MISC_CSR_REG, temp);
  326. while (1) ;
  327. }
  328. static void prpmc800_halt(void)
  329. {
  330. local_irq_disable();
  331. while (1) ;
  332. }
  333. static void prpmc800_power_off(void)
  334. {
  335. prpmc800_halt();
  336. }
  337. static void __init prpmc800_init_IRQ(void)
  338. {
  339. OpenPIC_InitSenses = prpmc800_openpic_initsenses;
  340. OpenPIC_NumInitSenses = sizeof(prpmc800_openpic_initsenses);
  341. /* Setup external interrupt sources. */
  342. openpic_set_sources(0, 16, OpenPIC_Addr + 0x10000);
  343. /* Setup internal UART interrupt source. */
  344. openpic_set_sources(16, 1, OpenPIC_Addr + 0x10200);
  345. /* Do the MPIC initialization based on the above settings. */
  346. openpic_init(0);
  347. /* enable functional exceptions for uarts and abort */
  348. out_8((u8 *) HARRIER_FEEN_REG, (HARRIER_FE_UA0 | HARRIER_FE_UA1));
  349. out_8((u8 *) HARRIER_FEMA_REG, ~(HARRIER_FE_UA0 | HARRIER_FE_UA1));
  350. }
  351. /*
  352. * Set BAT 3 to map 0xf0000000 to end of physical memory space.
  353. */
  354. static __inline__ void prpmc800_set_bat(void)
  355. {
  356. mb();
  357. mtspr(SPRN_DBAT1U, 0xf0001ffe);
  358. mtspr(SPRN_DBAT1L, 0xf000002a);
  359. mb();
  360. }
  361. /*
  362. * We need to read the Harrier memory controller
  363. * to properly determine this value
  364. */
  365. static unsigned long __init prpmc800_find_end_of_memory(void)
  366. {
  367. /* Read the memory size from the Harrier XCSR */
  368. return harrier_get_mem_size(PRPMC800_HARRIER_XCSR_BASE);
  369. }
  370. static void __init prpmc800_map_io(void)
  371. {
  372. io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
  373. io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
  374. }
  375. void __init
  376. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  377. unsigned long r6, unsigned long r7)
  378. {
  379. parse_bootinfo(find_bootinfo());
  380. prpmc800_set_bat();
  381. isa_io_base = PRPMC800_ISA_IO_BASE;
  382. isa_mem_base = PRPMC800_ISA_MEM_BASE;
  383. pci_dram_offset = PRPMC800_PCI_DRAM_OFFSET;
  384. ppc_md.setup_arch = prpmc800_setup_arch;
  385. ppc_md.show_cpuinfo = prpmc800_show_cpuinfo;
  386. ppc_md.init_IRQ = prpmc800_init_IRQ;
  387. ppc_md.get_irq = openpic_get_irq;
  388. ppc_md.find_end_of_memory = prpmc800_find_end_of_memory;
  389. ppc_md.setup_io_mappings = prpmc800_map_io;
  390. ppc_md.restart = prpmc800_restart;
  391. ppc_md.power_off = prpmc800_power_off;
  392. ppc_md.halt = prpmc800_halt;
  393. /* PrPMC800 has no timekeeper part */
  394. ppc_md.time_init = NULL;
  395. ppc_md.get_rtc_time = NULL;
  396. ppc_md.set_rtc_time = NULL;
  397. ppc_md.calibrate_decr = prpmc800_calibrate_decr;
  398. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  399. ppc_md.progress = gen550_progress;
  400. #else /* !CONFIG_SERIAL_TEXT_DEBUG */
  401. ppc_md.progress = NULL;
  402. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  403. }