gemini_setup.c 13 KB

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