cpci690.c 12 KB

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