cpci690.c 13 KB

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