prpmc800.c 14 KB

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