prpmc800.c 13 KB

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