prpmc800.c 14 KB

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