cpci690.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /*
  2. * arch/ppc/platforms/cpci690.c
  3. *
  4. * Board setup routines for the Force CPCI690 board.
  5. *
  6. * Author: Mark A. Greer <mgreer@mvista.com>
  7. *
  8. * 2003 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This programr
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/delay.h>
  15. #include <linux/pci.h>
  16. #include <linux/ide.h>
  17. #include <linux/irq.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/console.h>
  21. #include <linux/initrd.h>
  22. #include <linux/root_dev.h>
  23. #include <linux/mv643xx.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/machdep.h>
  26. #include <asm/todc.h>
  27. #include <asm/time.h>
  28. #include <asm/mv64x60.h>
  29. #include <platforms/cpci690.h>
  30. #define BOARD_VENDOR "Force"
  31. #define BOARD_MACHINE "CPCI690"
  32. /* Set IDE controllers into Native mode? */
  33. #define SET_PCI_IDE_NATIVE
  34. static struct mv64x60_handle bh;
  35. static void __iomem *cpci690_br_base;
  36. TODC_ALLOC();
  37. static int __init
  38. cpci690_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  39. {
  40. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  41. if (hose->index == 0) {
  42. static char pci_irq_table[][4] =
  43. /*
  44. * PCI IDSEL/INTPIN->INTLINE
  45. * A B C D
  46. */
  47. {
  48. { 90, 91, 88, 89 }, /* IDSEL 30/20 - Sentinel */
  49. };
  50. const long min_idsel = 20, max_idsel = 20, irqs_per_slot = 4;
  51. return PCI_IRQ_TABLE_LOOKUP;
  52. } else {
  53. static char pci_irq_table[][4] =
  54. /*
  55. * PCI IDSEL/INTPIN->INTLINE
  56. * A B C D
  57. */
  58. {
  59. { 93, 94, 95, 92 }, /* IDSEL 28/18 - PMC slot 2 */
  60. { 0, 0, 0, 0 }, /* IDSEL 29/19 - Not used */
  61. { 94, 95, 92, 93 }, /* IDSEL 30/20 - PMC slot 1 */
  62. };
  63. const long min_idsel = 18, max_idsel = 20, irqs_per_slot = 4;
  64. return PCI_IRQ_TABLE_LOOKUP;
  65. }
  66. }
  67. #define GB (1024UL * 1024UL * 1024UL)
  68. static u32
  69. cpci690_get_bus_freq(void)
  70. {
  71. if (boot_mem_size >= (1*GB)) /* bus speed based on mem size */
  72. return 100000000;
  73. else
  74. return 133333333;
  75. }
  76. static const unsigned int cpu_750xx[32] = { /* 750FX & 750GX */
  77. 0, 0, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,/* 0-15*/
  78. 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 0 /*16-31*/
  79. };
  80. static int
  81. cpci690_get_cpu_freq(void)
  82. {
  83. unsigned long pll_cfg;
  84. pll_cfg = (mfspr(SPRN_HID1) & 0xf8000000) >> 27;
  85. return cpci690_get_bus_freq() * cpu_750xx[pll_cfg]/2;
  86. }
  87. static void __init
  88. cpci690_setup_bridge(void)
  89. {
  90. struct mv64x60_setup_info si;
  91. int i;
  92. memset(&si, 0, sizeof(si));
  93. si.phys_reg_base = CONFIG_MV64X60_NEW_BASE;
  94. si.pci_0.enable_bus = 1;
  95. si.pci_0.pci_io.cpu_base = CPCI690_PCI0_IO_START_PROC_ADDR;
  96. si.pci_0.pci_io.pci_base_hi = 0;
  97. si.pci_0.pci_io.pci_base_lo = CPCI690_PCI0_IO_START_PCI_ADDR;
  98. si.pci_0.pci_io.size = CPCI690_PCI0_IO_SIZE;
  99. si.pci_0.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
  100. si.pci_0.pci_mem[0].cpu_base = CPCI690_PCI0_MEM_START_PROC_ADDR;
  101. si.pci_0.pci_mem[0].pci_base_hi = CPCI690_PCI0_MEM_START_PCI_HI_ADDR;
  102. si.pci_0.pci_mem[0].pci_base_lo = CPCI690_PCI0_MEM_START_PCI_LO_ADDR;
  103. si.pci_0.pci_mem[0].size = CPCI690_PCI0_MEM_SIZE;
  104. si.pci_0.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
  105. si.pci_0.pci_cmd_bits = 0;
  106. si.pci_0.latency_timer = 0x80;
  107. si.pci_1.enable_bus = 1;
  108. si.pci_1.pci_io.cpu_base = CPCI690_PCI1_IO_START_PROC_ADDR;
  109. si.pci_1.pci_io.pci_base_hi = 0;
  110. si.pci_1.pci_io.pci_base_lo = CPCI690_PCI1_IO_START_PCI_ADDR;
  111. si.pci_1.pci_io.size = CPCI690_PCI1_IO_SIZE;
  112. si.pci_1.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
  113. si.pci_1.pci_mem[0].cpu_base = CPCI690_PCI1_MEM_START_PROC_ADDR;
  114. si.pci_1.pci_mem[0].pci_base_hi = CPCI690_PCI1_MEM_START_PCI_HI_ADDR;
  115. si.pci_1.pci_mem[0].pci_base_lo = CPCI690_PCI1_MEM_START_PCI_LO_ADDR;
  116. si.pci_1.pci_mem[0].size = CPCI690_PCI1_MEM_SIZE;
  117. si.pci_1.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
  118. si.pci_1.pci_cmd_bits = 0;
  119. si.pci_1.latency_timer = 0x80;
  120. for (i=0; i<MV64x60_CPU2MEM_WINDOWS; i++) {
  121. si.cpu_prot_options[i] = 0;
  122. si.cpu_snoop_options[i] = GT64260_CPU_SNOOP_WB;
  123. si.pci_0.acc_cntl_options[i] =
  124. GT64260_PCI_ACC_CNTL_DREADEN |
  125. GT64260_PCI_ACC_CNTL_RDPREFETCH |
  126. GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
  127. GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
  128. GT64260_PCI_ACC_CNTL_SWAP_NONE |
  129. GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
  130. si.pci_0.snoop_options[i] = GT64260_PCI_SNOOP_WB;
  131. si.pci_1.acc_cntl_options[i] =
  132. GT64260_PCI_ACC_CNTL_DREADEN |
  133. GT64260_PCI_ACC_CNTL_RDPREFETCH |
  134. GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
  135. GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
  136. GT64260_PCI_ACC_CNTL_SWAP_NONE |
  137. GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
  138. si.pci_1.snoop_options[i] = GT64260_PCI_SNOOP_WB;
  139. }
  140. /* Lookup PCI host bridges */
  141. if (mv64x60_init(&bh, &si))
  142. printk(KERN_ERR "Bridge initialization failed.\n");
  143. pci_dram_offset = 0; /* System mem at same addr on PCI & cpu bus */
  144. ppc_md.pci_swizzle = common_swizzle;
  145. ppc_md.pci_map_irq = cpci690_map_irq;
  146. ppc_md.pci_exclude_device = mv64x60_pci_exclude_device;
  147. mv64x60_set_bus(&bh, 0, 0);
  148. bh.hose_a->first_busno = 0;
  149. bh.hose_a->last_busno = 0xff;
  150. bh.hose_a->last_busno = pciauto_bus_scan(bh.hose_a, 0);
  151. bh.hose_b->first_busno = bh.hose_a->last_busno + 1;
  152. mv64x60_set_bus(&bh, 1, bh.hose_b->first_busno);
  153. bh.hose_b->last_busno = 0xff;
  154. bh.hose_b->last_busno = pciauto_bus_scan(bh.hose_b,
  155. bh.hose_b->first_busno);
  156. }
  157. static void __init
  158. cpci690_setup_peripherals(void)
  159. {
  160. /* Set up windows to CPLD, RTC/TODC, IPMI. */
  161. mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN, CPCI690_BR_BASE,
  162. CPCI690_BR_SIZE, 0);
  163. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_0_WIN);
  164. cpci690_br_base = ioremap(CPCI690_BR_BASE, CPCI690_BR_SIZE);
  165. mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN, CPCI690_TODC_BASE,
  166. CPCI690_TODC_SIZE, 0);
  167. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN);
  168. TODC_INIT(TODC_TYPE_MK48T35, 0, 0,
  169. ioremap(CPCI690_TODC_BASE, CPCI690_TODC_SIZE), 8);
  170. mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN, CPCI690_IPMI_BASE,
  171. CPCI690_IPMI_SIZE, 0);
  172. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_2_WIN);
  173. mv64x60_set_bits(&bh, MV64x60_PCI0_ARBITER_CNTL, (1<<31));
  174. mv64x60_set_bits(&bh, MV64x60_PCI1_ARBITER_CNTL, (1<<31));
  175. mv64x60_set_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1<<9)); /* Only 1 cpu */
  176. /*
  177. * Turn off timer/counters. Not turning off watchdog timer because
  178. * can't read its reg on the 64260A so don't know if we'll be enabling
  179. * or disabling.
  180. */
  181. mv64x60_clr_bits(&bh, MV64x60_TIMR_CNTR_0_3_CNTL,
  182. ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
  183. mv64x60_clr_bits(&bh, GT64260_TIMR_CNTR_4_7_CNTL,
  184. ((1<<0) | (1<<8) | (1<<16) | (1<<24)));
  185. /*
  186. * Set MPSC Multiplex RMII
  187. * NOTE: ethernet driver modifies bit 0 and 1
  188. */
  189. mv64x60_write(&bh, GT64260_MPP_SERIAL_PORTS_MULTIPLEX, 0x00001102);
  190. #define GPP_EXTERNAL_INTERRUPTS \
  191. ((1<<24) | (1<<25) | (1<<26) | (1<<27) | \
  192. (1<<28) | (1<<29) | (1<<30) | (1<<31))
  193. /* PCI interrupts are inputs */
  194. mv64x60_clr_bits(&bh, MV64x60_GPP_IO_CNTL, GPP_EXTERNAL_INTERRUPTS);
  195. /* PCI interrupts are active low */
  196. mv64x60_set_bits(&bh, MV64x60_GPP_LEVEL_CNTL, GPP_EXTERNAL_INTERRUPTS);
  197. /* Clear any pending interrupts for these inputs and enable them. */
  198. mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~GPP_EXTERNAL_INTERRUPTS);
  199. mv64x60_set_bits(&bh, MV64x60_GPP_INTR_MASK, GPP_EXTERNAL_INTERRUPTS);
  200. /* Route MPP interrupt inputs to GPP */
  201. mv64x60_write(&bh, MV64x60_MPP_CNTL_2, 0x00000000);
  202. mv64x60_write(&bh, MV64x60_MPP_CNTL_3, 0x00000000);
  203. }
  204. static void __init
  205. cpci690_setup_arch(void)
  206. {
  207. if (ppc_md.progress)
  208. ppc_md.progress("cpci690_setup_arch: enter", 0);
  209. #ifdef CONFIG_BLK_DEV_INITRD
  210. if (initrd_start)
  211. ROOT_DEV = Root_RAM0;
  212. else
  213. #endif
  214. #ifdef CONFIG_ROOT_NFS
  215. ROOT_DEV = Root_NFS;
  216. #else
  217. ROOT_DEV = Root_SDA2;
  218. #endif
  219. if (ppc_md.progress)
  220. ppc_md.progress("cpci690_setup_arch: Enabling L2 cache", 0);
  221. /* Enable L2 and L3 caches (if 745x) */
  222. _set_L2CR(_get_L2CR() | L2CR_L2E);
  223. _set_L3CR(_get_L3CR() | L3CR_L3E);
  224. if (ppc_md.progress)
  225. ppc_md.progress("cpci690_setup_arch: Initializing bridge", 0);
  226. cpci690_setup_bridge(); /* set up PCI bridge(s) */
  227. cpci690_setup_peripherals(); /* set up chip selects/GPP/MPP etc */
  228. if (ppc_md.progress)
  229. ppc_md.progress("cpci690_setup_arch: bridge init complete", 0);
  230. printk(KERN_INFO "%s %s port (C) 2003 MontaVista Software, Inc. "
  231. "(source@mvista.com)\n", BOARD_VENDOR, BOARD_MACHINE);
  232. if (ppc_md.progress)
  233. ppc_md.progress("cpci690_setup_arch: exit", 0);
  234. }
  235. /* Platform device data fixup routines. */
  236. #if defined(CONFIG_SERIAL_MPSC)
  237. static void __init
  238. cpci690_fixup_mpsc_pdata(struct platform_device *pdev)
  239. {
  240. struct mpsc_pdata *pdata;
  241. pdata = (struct mpsc_pdata *)pdev->dev.platform_data;
  242. pdata->max_idle = 40;
  243. pdata->default_baud = CPCI690_MPSC_BAUD;
  244. pdata->brg_clk_src = CPCI690_MPSC_CLK_SRC;
  245. pdata->brg_clk_freq = cpci690_get_bus_freq();
  246. }
  247. static int __init
  248. cpci690_platform_notify(struct device *dev)
  249. {
  250. static struct {
  251. char *bus_id;
  252. void ((*rtn)(struct platform_device *pdev));
  253. } dev_map[] = {
  254. { MPSC_CTLR_NAME ".0", cpci690_fixup_mpsc_pdata },
  255. { MPSC_CTLR_NAME ".1", cpci690_fixup_mpsc_pdata },
  256. };
  257. struct platform_device *pdev;
  258. int i;
  259. if (dev && dev->bus_id)
  260. for (i=0; i<ARRAY_SIZE(dev_map); i++)
  261. if (!strncmp(dev->bus_id, dev_map[i].bus_id,
  262. BUS_ID_SIZE)) {
  263. pdev = container_of(dev,
  264. struct platform_device, dev);
  265. dev_map[i].rtn(pdev);
  266. }
  267. return 0;
  268. }
  269. #endif
  270. static void
  271. cpci690_reset_board(void)
  272. {
  273. u32 i = 10000;
  274. local_irq_disable();
  275. out_8((cpci690_br_base + CPCI690_BR_SW_RESET), 0x11);
  276. while (i != 0) i++;
  277. panic("restart failed\n");
  278. }
  279. static void
  280. cpci690_restart(char *cmd)
  281. {
  282. cpci690_reset_board();
  283. }
  284. static void
  285. cpci690_halt(void)
  286. {
  287. while (1);
  288. /* NOTREACHED */
  289. }
  290. static void
  291. cpci690_power_off(void)
  292. {
  293. cpci690_halt();
  294. /* NOTREACHED */
  295. }
  296. static int
  297. cpci690_show_cpuinfo(struct seq_file *m)
  298. {
  299. char *s;
  300. seq_printf(m, "cpu MHz\t\t: %d\n",
  301. (cpci690_get_cpu_freq() + 500000) / 1000000);
  302. seq_printf(m, "bus MHz\t\t: %d\n",
  303. (cpci690_get_bus_freq() + 500000) / 1000000);
  304. seq_printf(m, "vendor\t\t: " BOARD_VENDOR "\n");
  305. seq_printf(m, "machine\t\t: " BOARD_MACHINE "\n");
  306. seq_printf(m, "FPGA Revision\t: %d\n",
  307. in_8(cpci690_br_base + CPCI690_BR_MEM_CTLR) >> 5);
  308. switch(bh.type) {
  309. case MV64x60_TYPE_GT64260A:
  310. s = "gt64260a";
  311. break;
  312. case MV64x60_TYPE_GT64260B:
  313. s = "gt64260b";
  314. break;
  315. case MV64x60_TYPE_MV64360:
  316. s = "mv64360";
  317. break;
  318. case MV64x60_TYPE_MV64460:
  319. s = "mv64460";
  320. break;
  321. default:
  322. s = "Unknown";
  323. }
  324. seq_printf(m, "bridge type\t: %s\n", s);
  325. seq_printf(m, "bridge rev\t: 0x%x\n", bh.rev);
  326. #if defined(CONFIG_NOT_COHERENT_CACHE)
  327. seq_printf(m, "coherency\t: %s\n", "off");
  328. #else
  329. seq_printf(m, "coherency\t: %s\n", "on");
  330. #endif
  331. return 0;
  332. }
  333. static void __init
  334. cpci690_calibrate_decr(void)
  335. {
  336. ulong freq;
  337. freq = cpci690_get_bus_freq() / 4;
  338. printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
  339. freq/1000000, freq%1000000);
  340. tb_ticks_per_jiffy = freq / HZ;
  341. tb_to_us = mulhwu_scale_factor(freq, 1000000);
  342. }
  343. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC)
  344. static void __init
  345. cpci690_map_io(void)
  346. {
  347. io_block_mapping(CONFIG_MV64X60_NEW_BASE, CONFIG_MV64X60_NEW_BASE,
  348. 128 * 1024, _PAGE_IO);
  349. }
  350. #endif
  351. void __init
  352. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  353. unsigned long r6, unsigned long r7)
  354. {
  355. parse_bootinfo(find_bootinfo());
  356. #ifdef CONFIG_BLK_DEV_INITRD
  357. /* take care of initrd if we have one */
  358. if (r4) {
  359. initrd_start = r4 + KERNELBASE;
  360. initrd_end = r5 + KERNELBASE;
  361. }
  362. #endif /* CONFIG_BLK_DEV_INITRD */
  363. isa_mem_base = 0;
  364. ppc_md.setup_arch = cpci690_setup_arch;
  365. ppc_md.show_cpuinfo = cpci690_show_cpuinfo;
  366. ppc_md.init_IRQ = gt64260_init_irq;
  367. ppc_md.get_irq = gt64260_get_irq;
  368. ppc_md.restart = cpci690_restart;
  369. ppc_md.power_off = cpci690_power_off;
  370. ppc_md.halt = cpci690_halt;
  371. ppc_md.time_init = todc_time_init;
  372. ppc_md.set_rtc_time = todc_set_rtc_time;
  373. ppc_md.get_rtc_time = todc_get_rtc_time;
  374. ppc_md.nvram_read_val = todc_direct_read_val;
  375. ppc_md.nvram_write_val = todc_direct_write_val;
  376. ppc_md.calibrate_decr = cpci690_calibrate_decr;
  377. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC)
  378. ppc_md.setup_io_mappings = cpci690_map_io;
  379. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  380. ppc_md.progress = mv64x60_mpsc_progress;
  381. mv64x60_progress_init(CONFIG_MV64X60_NEW_BASE);
  382. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  383. #endif /* defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_MPSC) */
  384. #if defined(CONFIG_SERIAL_MPSC)
  385. platform_notify = cpci690_platform_notify;
  386. #endif
  387. }