cpci690.c 12 KB

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