cpci690.c 12 KB

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