gemini_setup.c 13 KB

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