m8xx_setup.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. * Modified for MBX using prep/chrp/pmac functions by Dan (dmalek@jlc.net)
  6. * Further modified for generic 8xx by Dan.
  7. */
  8. /*
  9. * bootup setup stuff..
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/stddef.h>
  16. #include <linux/unistd.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/slab.h>
  19. #include <linux/user.h>
  20. #include <linux/a.out.h>
  21. #include <linux/tty.h>
  22. #include <linux/major.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/reboot.h>
  25. #include <linux/init.h>
  26. #include <linux/initrd.h>
  27. #include <linux/ioport.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/time.h>
  32. #include <linux/rtc.h>
  33. #include <linux/fsl_devices.h>
  34. #include <asm/mmu.h>
  35. #include <asm/reg.h>
  36. #include <asm/residual.h>
  37. #include <asm/io.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/mpc8xx.h>
  40. #include <asm/8xx_immap.h>
  41. #include <asm/machdep.h>
  42. #include <asm/bootinfo.h>
  43. #include <asm/time.h>
  44. #include <asm/prom.h>
  45. #include <asm/fs_pd.h>
  46. #include <mm/mmu_decl.h>
  47. #include "sysdev/mpc8xx_pic.h"
  48. #ifdef CONFIG_PCMCIA_M8XX
  49. struct mpc8xx_pcmcia_ops m8xx_pcmcia_ops;
  50. #endif
  51. void m8xx_calibrate_decr(void);
  52. extern void m8xx_wdt_handler_install(bd_t *bp);
  53. extern int cpm_pic_init(void);
  54. extern int cpm_get_irq(void);
  55. /* A place holder for time base interrupts, if they are ever enabled. */
  56. irqreturn_t timebase_interrupt(int irq, void * dev)
  57. {
  58. printk ("timebase_interrupt()\n");
  59. return IRQ_HANDLED;
  60. }
  61. static struct irqaction tbint_irqaction = {
  62. .handler = timebase_interrupt,
  63. .mask = CPU_MASK_NONE,
  64. .name = "tbint",
  65. };
  66. /* per-board overridable init_internal_rtc() function. */
  67. void __init __attribute__ ((weak))
  68. init_internal_rtc(void)
  69. {
  70. sit8xx_t *sys_tmr = (sit8xx_t *) immr_map(im_sit);
  71. /* Disable the RTC one second and alarm interrupts. */
  72. clrbits16(&sys_tmr->sit_rtcsc, (RTCSC_SIE | RTCSC_ALE));
  73. /* Enable the RTC */
  74. setbits16(&sys_tmr->sit_rtcsc, (RTCSC_RTF | RTCSC_RTE));
  75. immr_unmap(sys_tmr);
  76. }
  77. static int __init get_freq(char *name, unsigned long *val)
  78. {
  79. struct device_node *cpu;
  80. const unsigned int *fp;
  81. int found = 0;
  82. /* The cpu node should have timebase and clock frequency properties */
  83. cpu = of_find_node_by_type(NULL, "cpu");
  84. if (cpu) {
  85. fp = of_get_property(cpu, name, NULL);
  86. if (fp) {
  87. found = 1;
  88. *val = *fp;
  89. }
  90. of_node_put(cpu);
  91. }
  92. return found;
  93. }
  94. /* The decrementer counts at the system (internal) clock frequency divided by
  95. * sixteen, or external oscillator divided by four. We force the processor
  96. * to use system clock divided by sixteen.
  97. */
  98. void __init mpc8xx_calibrate_decr(void)
  99. {
  100. struct device_node *cpu;
  101. cark8xx_t *clk_r1;
  102. car8xx_t *clk_r2;
  103. sitk8xx_t *sys_tmr1;
  104. sit8xx_t *sys_tmr2;
  105. int irq, virq;
  106. clk_r1 = (cark8xx_t *) immr_map(im_clkrstk);
  107. /* Unlock the SCCR. */
  108. out_be32(&clk_r1->cark_sccrk, ~KAPWR_KEY);
  109. out_be32(&clk_r1->cark_sccrk, KAPWR_KEY);
  110. immr_unmap(clk_r1);
  111. /* Force all 8xx processors to use divide by 16 processor clock. */
  112. clk_r2 = (car8xx_t *) immr_map(im_clkrst);
  113. setbits32(&clk_r2->car_sccr, 0x02000000);
  114. immr_unmap(clk_r2);
  115. /* Processor frequency is MHz.
  116. */
  117. ppc_tb_freq = 50000000;
  118. if (!get_freq("bus-frequency", &ppc_tb_freq)) {
  119. printk(KERN_ERR "WARNING: Estimating decrementer frequency "
  120. "(not found)\n");
  121. }
  122. ppc_tb_freq /= 16;
  123. ppc_proc_freq = 50000000;
  124. if (!get_freq("clock-frequency", &ppc_proc_freq))
  125. printk(KERN_ERR "WARNING: Estimating processor frequency"
  126. "(not found)\n");
  127. printk("Decrementer Frequency = 0x%lx\n", ppc_tb_freq);
  128. /* Perform some more timer/timebase initialization. This used
  129. * to be done elsewhere, but other changes caused it to get
  130. * called more than once....that is a bad thing.
  131. *
  132. * First, unlock all of the registers we are going to modify.
  133. * To protect them from corruption during power down, registers
  134. * that are maintained by keep alive power are "locked". To
  135. * modify these registers we have to write the key value to
  136. * the key location associated with the register.
  137. * Some boards power up with these unlocked, while others
  138. * are locked. Writing anything (including the unlock code?)
  139. * to the unlocked registers will lock them again. So, here
  140. * we guarantee the registers are locked, then we unlock them
  141. * for our use.
  142. */
  143. sys_tmr1 = (sitk8xx_t *) immr_map(im_sitk);
  144. out_be32(&sys_tmr1->sitk_tbscrk, ~KAPWR_KEY);
  145. out_be32(&sys_tmr1->sitk_rtcsck, ~KAPWR_KEY);
  146. out_be32(&sys_tmr1->sitk_tbk, ~KAPWR_KEY);
  147. out_be32(&sys_tmr1->sitk_tbscrk, KAPWR_KEY);
  148. out_be32(&sys_tmr1->sitk_rtcsck, KAPWR_KEY);
  149. out_be32(&sys_tmr1->sitk_tbk, KAPWR_KEY);
  150. immr_unmap(sys_tmr1);
  151. init_internal_rtc();
  152. /* Enabling the decrementer also enables the timebase interrupts
  153. * (or from the other point of view, to get decrementer interrupts
  154. * we have to enable the timebase). The decrementer interrupt
  155. * is wired into the vector table, nothing to do here for that.
  156. */
  157. cpu = of_find_node_by_type(NULL, "cpu");
  158. virq= irq_of_parse_and_map(cpu, 0);
  159. irq = irq_map[virq].hwirq;
  160. sys_tmr2 = (sit8xx_t *) immr_map(im_sit);
  161. out_be16(&sys_tmr2->sit_tbscr, ((1 << (7 - (irq/2))) << 8) |
  162. (TBSCR_TBF | TBSCR_TBE));
  163. immr_unmap(sys_tmr2);
  164. if (setup_irq(virq, &tbint_irqaction))
  165. panic("Could not allocate timer IRQ!");
  166. #ifdef CONFIG_8xx_WDT
  167. /* Install watchdog timer handler early because it might be
  168. * already enabled by the bootloader
  169. */
  170. m8xx_wdt_handler_install(binfo);
  171. #endif
  172. }
  173. /* The RTC on the MPC8xx is an internal register.
  174. * We want to protect this during power down, so we need to unlock,
  175. * modify, and re-lock.
  176. */
  177. int mpc8xx_set_rtc_time(struct rtc_time *tm)
  178. {
  179. sitk8xx_t *sys_tmr1;
  180. sit8xx_t *sys_tmr2;
  181. int time;
  182. sys_tmr1 = (sitk8xx_t *) immr_map(im_sitk);
  183. sys_tmr2 = (sit8xx_t *) immr_map(im_sit);
  184. time = mktime(tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
  185. tm->tm_hour, tm->tm_min, tm->tm_sec);
  186. out_be32(&sys_tmr1->sitk_rtck, KAPWR_KEY);
  187. out_be32(&sys_tmr2->sit_rtc, time);
  188. out_be32(&sys_tmr1->sitk_rtck, ~KAPWR_KEY);
  189. immr_unmap(sys_tmr2);
  190. immr_unmap(sys_tmr1);
  191. return 0;
  192. }
  193. void mpc8xx_get_rtc_time(struct rtc_time *tm)
  194. {
  195. unsigned long data;
  196. sit8xx_t *sys_tmr = (sit8xx_t *) immr_map(im_sit);
  197. /* Get time from the RTC. */
  198. data = in_be32(&sys_tmr->sit_rtc);
  199. to_tm(data, tm);
  200. tm->tm_year -= 1900;
  201. tm->tm_mon -= 1;
  202. immr_unmap(sys_tmr);
  203. return;
  204. }
  205. void mpc8xx_restart(char *cmd)
  206. {
  207. __volatile__ unsigned char dummy;
  208. car8xx_t * clk_r = (car8xx_t *) immr_map(im_clkrst);
  209. local_irq_disable();
  210. setbits32(&clk_r->car_plprcr, 0x00000080);
  211. /* Clear the ME bit in MSR to cause checkstop on machine check
  212. */
  213. mtmsr(mfmsr() & ~0x1000);
  214. dummy = in_8(&clk_r->res[0]);
  215. printk("Restart failed\n");
  216. while(1);
  217. }
  218. void mpc8xx_show_cpuinfo(struct seq_file *m)
  219. {
  220. struct device_node *root;
  221. uint memsize = total_memory;
  222. const char *model = "";
  223. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  224. root = of_find_node_by_path("/");
  225. if (root)
  226. model = of_get_property(root, "model", NULL);
  227. seq_printf(m, "Machine\t\t: %s\n", model);
  228. of_node_put(root);
  229. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  230. }
  231. static void cpm_cascade(unsigned int irq, struct irq_desc *desc)
  232. {
  233. int cascade_irq;
  234. if ((cascade_irq = cpm_get_irq()) >= 0) {
  235. struct irq_desc *cdesc = irq_desc + cascade_irq;
  236. generic_handle_irq(cascade_irq);
  237. cdesc->chip->eoi(cascade_irq);
  238. }
  239. desc->chip->eoi(irq);
  240. }
  241. /* Initialize the internal interrupt controller. The number of
  242. * interrupts supported can vary with the processor type, and the
  243. * 82xx family can have up to 64.
  244. * External interrupts can be either edge or level triggered, and
  245. * need to be initialized by the appropriate driver.
  246. */
  247. void __init m8xx_pic_init(void)
  248. {
  249. int irq;
  250. if (mpc8xx_pic_init()) {
  251. printk(KERN_ERR "Failed interrupt 8xx controller initialization\n");
  252. return;
  253. }
  254. irq = cpm_pic_init();
  255. if (irq != NO_IRQ)
  256. set_irq_chained_handler(irq, cpm_cascade);
  257. }