gemini_setup.c 13 KB

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