PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src-rt-6.x/linux/linux-2.6/arch/powerpc/platforms/8xx/m8xx_setup.c

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