prpmc800.c 13 KB

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