gemini_setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. * Adapted from 'alpha' version by Gary Thomas
  4. * Modified by Cort Dougan (cort@cs.nmt.edu)
  5. * Synergy Microsystems board support by Dan Cox (dan@synergymicro.com)
  6. *
  7. */
  8. #include <linux/config.h>
  9. #include <linux/stddef.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/errno.h>
  13. #include <linux/reboot.h>
  14. #include <linux/pci.h>
  15. #include <linux/time.h>
  16. #include <linux/kdev_t.h>
  17. #include <linux/types.h>
  18. #include <linux/major.h>
  19. #include <linux/initrd.h>
  20. #include <linux/console.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/root_dev.h>
  23. #include <linux/bcd.h>
  24. #include <asm/system.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/page.h>
  27. #include <asm/dma.h>
  28. #include <asm/io.h>
  29. #include <asm/m48t35.h>
  30. #include <platforms/gemini.h>
  31. #include <asm/time.h>
  32. #include <asm/open_pic.h>
  33. #include <asm/bootinfo.h>
  34. #include <asm/machdep.h>
  35. void gemini_find_bridges(void);
  36. static int gemini_get_clock_speed(void);
  37. extern void gemini_pcibios_fixup(void);
  38. static char *gemini_board_families[] = {
  39. "VGM", "VSS", "KGM", "VGR", "VCM", "VCS", "KCM", "VCR"
  40. };
  41. static int gemini_board_count = sizeof(gemini_board_families) /
  42. sizeof(gemini_board_families[0]);
  43. static unsigned int cpu_7xx[16] = {
  44. 0, 15, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
  45. };
  46. static unsigned int cpu_6xx[16] = {
  47. 0, 0, 14, 0, 0, 13, 5, 9, 6, 11, 8, 10, 0, 12, 7, 0
  48. };
  49. /*
  50. * prom_init is the Gemini version of prom.c:prom_init. We only need
  51. * the BSS clearing code, so I copied that out of prom.c. This is a
  52. * lot simpler than hacking prom.c so it will build with Gemini. -VAL
  53. */
  54. #define PTRRELOC(x) ((typeof(x))((unsigned long)(x) + offset))
  55. unsigned long
  56. prom_init(void)
  57. {
  58. unsigned long offset = reloc_offset();
  59. unsigned long phys;
  60. extern char __bss_start, _end;
  61. /* First zero the BSS -- use memset, some arches don't have
  62. * caches on yet */
  63. memset_io(PTRRELOC(&__bss_start),0 , &_end - &__bss_start);
  64. /* Default */
  65. phys = offset + KERNELBASE;
  66. gemini_prom_init();
  67. return phys;
  68. }
  69. int
  70. gemini_show_cpuinfo(struct seq_file *m)
  71. {
  72. unsigned char reg, rev;
  73. char *family;
  74. unsigned int type;
  75. reg = readb(GEMINI_FEAT);
  76. family = gemini_board_families[((reg>>4) & 0xf)];
  77. if (((reg>>4) & 0xf) > gemini_board_count)
  78. printk(KERN_ERR "cpuinfo(): unable to determine board family\n");
  79. reg = readb(GEMINI_BREV);
  80. type = (reg>>4) & 0xf;
  81. rev = reg & 0xf;
  82. reg = readb(GEMINI_BECO);
  83. seq_printf(m, "machine\t\t: Gemini %s%d, rev %c, eco %d\n",
  84. family, type, (rev + 'A'), (reg & 0xf));
  85. seq_printf(m, "board\t\t: Gemini %s", family);
  86. if (type > 9)
  87. seq_printf(m, "%c", (type - 10) + 'A');
  88. else
  89. seq_printf(m, "%d", type);
  90. seq_printf(m, ", rev %c, eco %d\n", (rev + 'A'), (reg & 0xf));
  91. seq_printf(m, "clock\t\t: %dMhz\n", gemini_get_clock_speed());
  92. return 0;
  93. }
  94. static u_char gemini_openpic_initsenses[] = {
  95. 1,
  96. 1,
  97. 1,
  98. 1,
  99. 0,
  100. 0,
  101. 1, /* remainder are level-triggered */
  102. };
  103. #define GEMINI_MPIC_ADDR (0xfcfc0000)
  104. #define GEMINI_MPIC_PCI_CFG (0x80005800)
  105. void __init gemini_openpic_init(void)
  106. {
  107. OpenPIC_Addr = (volatile struct OpenPIC *)
  108. grackle_read(GEMINI_MPIC_PCI_CFG + 0x10);
  109. OpenPIC_InitSenses = gemini_openpic_initsenses;
  110. OpenPIC_NumInitSenses = sizeof( gemini_openpic_initsenses );
  111. ioremap( GEMINI_MPIC_ADDR, OPENPIC_SIZE);
  112. }
  113. extern unsigned long loops_per_jiffy;
  114. extern int root_mountflags;
  115. extern char cmd_line[];
  116. void
  117. gemini_heartbeat(void)
  118. {
  119. static unsigned long led = GEMINI_LEDBASE+(4*8);
  120. static char direction = 8;
  121. /* We only want to do this on 1 CPU */
  122. if (smp_processor_id())
  123. return;
  124. *(char *)led = 0;
  125. if ( (led + direction) > (GEMINI_LEDBASE+(7*8)) ||
  126. (led + direction) < (GEMINI_LEDBASE+(4*8)) )
  127. direction *= -1;
  128. led += direction;
  129. *(char *)led = 0xff;
  130. ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
  131. }
  132. void __init gemini_setup_arch(void)
  133. {
  134. extern char cmd_line[];
  135. loops_per_jiffy = 50000000/HZ;
  136. #ifdef CONFIG_BLK_DEV_INITRD
  137. /* bootable off CDROM */
  138. if (initrd_start)
  139. ROOT_DEV = Root_SR0;
  140. else
  141. #endif
  142. ROOT_DEV = Root_SDA1;
  143. /* nothing but serial consoles... */
  144. sprintf(cmd_line, "%s console=ttyS0", cmd_line);
  145. printk("Boot arguments: %s\n", cmd_line);
  146. ppc_md.heartbeat = gemini_heartbeat;
  147. ppc_md.heartbeat_reset = HZ/8;
  148. ppc_md.heartbeat_count = 1;
  149. /* Lookup PCI hosts */
  150. gemini_find_bridges();
  151. /* take special pains to map the MPIC, since it isn't mapped yet */
  152. gemini_openpic_init();
  153. /* start the L2 */
  154. gemini_init_l2();
  155. }
  156. int
  157. gemini_get_clock_speed(void)
  158. {
  159. unsigned long hid1, pvr;
  160. int clock;
  161. pvr = mfspr(SPRN_PVR);
  162. hid1 = (mfspr(SPRN_HID1) >> 28) & 0xf;
  163. if (PVR_VER(pvr) == 8 ||
  164. PVR_VER(pvr) == 12)
  165. hid1 = cpu_7xx[hid1];
  166. else
  167. hid1 = cpu_6xx[hid1];
  168. switch((readb(GEMINI_BSTAT) & 0xc) >> 2) {
  169. case 0:
  170. default:
  171. clock = (hid1*100)/3;
  172. break;
  173. case 1:
  174. clock = (hid1*125)/3;
  175. break;
  176. case 2:
  177. clock = (hid1*50);
  178. break;
  179. }
  180. return clock;
  181. }
  182. void __init gemini_init_l2(void)
  183. {
  184. unsigned char reg, brev, fam, creg;
  185. unsigned long cache;
  186. unsigned long pvr;
  187. reg = readb(GEMINI_L2CFG);
  188. brev = readb(GEMINI_BREV);
  189. fam = readb(GEMINI_FEAT);
  190. pvr = mfspr(SPRN_PVR);
  191. switch(PVR_VER(pvr)) {
  192. case 8:
  193. if (reg & 0xc0)
  194. cache = (((reg >> 6) & 0x3) << 28);
  195. else
  196. cache = 0x3 << 28;
  197. #ifdef CONFIG_SMP
  198. /* Pre-3.0 processor revs had snooping errata. Leave
  199. their L2's disabled with SMP. -- Dan */
  200. if (PVR_CFG(pvr) < 3) {
  201. printk("Pre-3.0 750; L2 left disabled!\n");
  202. return;
  203. }
  204. #endif /* CONFIG_SMP */
  205. /* Special case: VGM5-B's came before L2 ratios were set on
  206. the board. Processor speed shouldn't be too high, so
  207. set L2 ratio to 1:1.5. */
  208. if ((brev == 0x51) && ((fam & 0xa0) >> 4) == 0)
  209. reg |= 1;
  210. /* determine best cache ratio based upon what the board
  211. tells us (which sometimes _may_ not be true) and
  212. the processor speed. */
  213. else {
  214. if (gemini_get_clock_speed() > 250)
  215. reg = 2;
  216. }
  217. break;
  218. case 12:
  219. {
  220. static unsigned long l2_size_val = 0;
  221. if (!l2_size_val)
  222. l2_size_val = _get_L2CR();
  223. cache = l2_size_val;
  224. break;
  225. }
  226. case 4:
  227. case 9:
  228. creg = readb(GEMINI_CPUSTAT);
  229. if (((creg & 0xc) >> 2) != 1)
  230. printk("Dual-604 boards don't support the use of L2\n");
  231. else
  232. writeb(1, GEMINI_L2CFG);
  233. return;
  234. default:
  235. printk("Unknown processor; L2 left disabled\n");
  236. return;
  237. }
  238. cache |= ((1<<reg) << 25);
  239. cache |= (L2CR_L2RAM_MASK|L2CR_L2CTL|L2CR_L2DO);
  240. _set_L2CR(0);
  241. _set_L2CR(cache | L2CR_L2E);
  242. }
  243. void
  244. gemini_restart(char *cmd)
  245. {
  246. local_irq_disable();
  247. /* make a clean restart, not via the MPIC */
  248. _gemini_reboot();
  249. for(;;);
  250. }
  251. void
  252. gemini_power_off(void)
  253. {
  254. for(;;);
  255. }
  256. void
  257. gemini_halt(void)
  258. {
  259. gemini_restart(NULL);
  260. }
  261. void __init gemini_init_IRQ(void)
  262. {
  263. /* gemini has no 8259 */
  264. openpic_init(1, 0, 0, -1);
  265. }
  266. #define gemini_rtc_read(x) (readb(GEMINI_RTC+(x)))
  267. #define gemini_rtc_write(val,x) (writeb((val),(GEMINI_RTC+(x))))
  268. /* ensure that the RTC is up and running */
  269. long __init gemini_time_init(void)
  270. {
  271. unsigned char reg;
  272. reg = gemini_rtc_read(M48T35_RTC_CONTROL);
  273. if ( reg & M48T35_RTC_STOPPED ) {
  274. printk(KERN_INFO "M48T35 real-time-clock was stopped. Now starting...\n");
  275. gemini_rtc_write((reg & ~(M48T35_RTC_STOPPED)), M48T35_RTC_CONTROL);
  276. gemini_rtc_write((reg | M48T35_RTC_SET), M48T35_RTC_CONTROL);
  277. }
  278. return 0;
  279. }
  280. #undef DEBUG_RTC
  281. unsigned long
  282. gemini_get_rtc_time(void)
  283. {
  284. unsigned int year, mon, day, hour, min, sec;
  285. unsigned char reg;
  286. reg = gemini_rtc_read(M48T35_RTC_CONTROL);
  287. gemini_rtc_write((reg|M48T35_RTC_READ), M48T35_RTC_CONTROL);
  288. #ifdef DEBUG_RTC
  289. printk("get rtc: reg = %x\n", reg);
  290. #endif
  291. do {
  292. sec = gemini_rtc_read(M48T35_RTC_SECONDS);
  293. min = gemini_rtc_read(M48T35_RTC_MINUTES);
  294. hour = gemini_rtc_read(M48T35_RTC_HOURS);
  295. day = gemini_rtc_read(M48T35_RTC_DOM);
  296. mon = gemini_rtc_read(M48T35_RTC_MONTH);
  297. year = gemini_rtc_read(M48T35_RTC_YEAR);
  298. } while( sec != gemini_rtc_read(M48T35_RTC_SECONDS));
  299. #ifdef DEBUG_RTC
  300. printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
  301. sec, min, hour, day, mon, year);
  302. #endif
  303. gemini_rtc_write(reg, M48T35_RTC_CONTROL);
  304. BCD_TO_BIN(sec);
  305. BCD_TO_BIN(min);
  306. BCD_TO_BIN(hour);
  307. BCD_TO_BIN(day);
  308. BCD_TO_BIN(mon);
  309. BCD_TO_BIN(year);
  310. if ((year += 1900) < 1970)
  311. year += 100;
  312. #ifdef DEBUG_RTC
  313. printk("get rtc: sec=%x, min=%x, hour=%x, day=%x, mon=%x, year=%x\n",
  314. sec, min, hour, day, mon, year);
  315. #endif
  316. return mktime( year, mon, day, hour, min, sec );
  317. }
  318. int
  319. gemini_set_rtc_time( unsigned long now )
  320. {
  321. unsigned char reg;
  322. struct rtc_time tm;
  323. to_tm( now, &tm );
  324. reg = gemini_rtc_read(M48T35_RTC_CONTROL);
  325. #ifdef DEBUG_RTC
  326. printk("set rtc: reg = %x\n", reg);
  327. #endif
  328. gemini_rtc_write((reg|M48T35_RTC_SET), M48T35_RTC_CONTROL);
  329. #ifdef DEBUG_RTC
  330. printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
  331. tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
  332. #endif
  333. tm.tm_year -= 1900;
  334. BIN_TO_BCD(tm.tm_sec);
  335. BIN_TO_BCD(tm.tm_min);
  336. BIN_TO_BCD(tm.tm_hour);
  337. BIN_TO_BCD(tm.tm_mon);
  338. BIN_TO_BCD(tm.tm_mday);
  339. BIN_TO_BCD(tm.tm_year);
  340. #ifdef DEBUG_RTC
  341. printk("set rtc: tm vals - sec=%x, min=%x, hour=%x, mon=%x, mday=%x, year=%x\n",
  342. tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mon, tm.tm_mday, tm.tm_year);
  343. #endif
  344. gemini_rtc_write(tm.tm_sec, M48T35_RTC_SECONDS);
  345. gemini_rtc_write(tm.tm_min, M48T35_RTC_MINUTES);
  346. gemini_rtc_write(tm.tm_hour, M48T35_RTC_HOURS);
  347. gemini_rtc_write(tm.tm_mday, M48T35_RTC_DOM);
  348. gemini_rtc_write(tm.tm_mon, M48T35_RTC_MONTH);
  349. gemini_rtc_write(tm.tm_year, M48T35_RTC_YEAR);
  350. /* done writing */
  351. gemini_rtc_write(reg, M48T35_RTC_CONTROL);
  352. return 0;
  353. }
  354. /* use the RTC to determine the decrementer count */
  355. void __init gemini_calibrate_decr(void)
  356. {
  357. int freq, divisor;
  358. unsigned char reg;
  359. /* determine processor bus speed */
  360. reg = readb(GEMINI_BSTAT);
  361. switch(((reg & 0x0c)>>2)&0x3) {
  362. case 0:
  363. default:
  364. freq = 66667;
  365. break;
  366. case 1:
  367. freq = 83000;
  368. break;
  369. case 2:
  370. freq = 100000;
  371. break;
  372. }
  373. freq *= 1000;
  374. divisor = 4;
  375. tb_ticks_per_jiffy = freq / HZ / divisor;
  376. tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
  377. }
  378. unsigned long __init gemini_find_end_of_memory(void)
  379. {
  380. unsigned long total;
  381. unsigned char reg;
  382. reg = readb(GEMINI_MEMCFG);
  383. total = ((1<<((reg & 0x7) - 1)) *
  384. (8<<((reg >> 3) & 0x7)));
  385. total *= (1024*1024);
  386. return total;
  387. }
  388. static void __init
  389. gemini_map_io(void)
  390. {
  391. io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
  392. io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
  393. }
  394. #ifdef CONFIG_SMP
  395. static int
  396. smp_gemini_probe(void)
  397. {
  398. int i, nr;
  399. nr = (readb(GEMINI_CPUSTAT) & GEMINI_CPU_COUNT_MASK) >> 2;
  400. if (nr == 0)
  401. nr = 4;
  402. if (nr > 1) {
  403. openpic_request_IPIs();
  404. for (i = 1; i < nr; ++i)
  405. smp_hw_index[i] = i;
  406. }
  407. return nr;
  408. }
  409. static void
  410. smp_gemini_kick_cpu(int nr)
  411. {
  412. openpic_reset_processor_phys(1 << nr);
  413. openpic_reset_processor_phys(0);
  414. }
  415. static void
  416. smp_gemini_setup_cpu(int cpu_nr)
  417. {
  418. if (OpenPIC_Addr)
  419. do_openpic_setup_cpu();
  420. if (cpu_nr > 0)
  421. gemini_init_l2();
  422. }
  423. static struct smp_ops_t gemini_smp_ops = {
  424. smp_openpic_message_pass,
  425. smp_gemini_probe,
  426. smp_gemini_kick_cpu,
  427. smp_gemini_setup_cpu,
  428. .give_timebase = smp_generic_give_timebase,
  429. .take_timebase = smp_generic_take_timebase,
  430. };
  431. #endif /* CONFIG_SMP */
  432. void __init platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  433. unsigned long r6, unsigned long r7)
  434. {
  435. int i;
  436. /* Restore BATs for now */
  437. mtspr(SPRN_DBAT3U, 0xf0001fff);
  438. mtspr(SPRN_DBAT3L, 0xf000002a);
  439. parse_bootinfo(find_bootinfo());
  440. for(i = 0; i < GEMINI_LEDS; i++)
  441. gemini_led_off(i);
  442. ISA_DMA_THRESHOLD = 0;
  443. DMA_MODE_READ = 0;
  444. DMA_MODE_WRITE = 0;
  445. #ifdef CONFIG_BLK_DEV_INITRD
  446. if ( r4 )
  447. {
  448. initrd_start = r4 + KERNELBASE;
  449. initrd_end = r5 + KERNELBASE;
  450. }
  451. #endif
  452. ppc_md.setup_arch = gemini_setup_arch;
  453. ppc_md.show_cpuinfo = gemini_show_cpuinfo;
  454. ppc_md.init_IRQ = gemini_init_IRQ;
  455. ppc_md.get_irq = openpic_get_irq;
  456. ppc_md.init = NULL;
  457. ppc_md.restart = gemini_restart;
  458. ppc_md.power_off = gemini_power_off;
  459. ppc_md.halt = gemini_halt;
  460. ppc_md.time_init = gemini_time_init;
  461. ppc_md.set_rtc_time = gemini_set_rtc_time;
  462. ppc_md.get_rtc_time = gemini_get_rtc_time;
  463. ppc_md.calibrate_decr = gemini_calibrate_decr;
  464. ppc_md.find_end_of_memory = gemini_find_end_of_memory;
  465. ppc_md.setup_io_mappings = gemini_map_io;
  466. ppc_md.pcibios_fixup_bus = gemini_pcibios_fixup;
  467. #ifdef CONFIG_SMP
  468. smp_ops = &gemini_smp_ops;
  469. #endif /* CONFIG_SMP */
  470. }