mpc52xx_setup.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * arch/ppc/syslib/mpc52xx_setup.c
  3. *
  4. * Common code for the boards based on Freescale MPC52xx embedded CPU.
  5. *
  6. *
  7. * Maintainer : Sylvain Munaut <tnt@246tNt.com>
  8. *
  9. * Support for other bootloaders than UBoot by Dale Farnsworth
  10. * <dfarnsworth@mvista.com>
  11. *
  12. * Copyright (C) 2004 Sylvain Munaut <tnt@246tNt.com>
  13. * Copyright (C) 2003 Montavista Software, Inc
  14. *
  15. * This file is licensed under the terms of the GNU General Public License
  16. * version 2. This program is licensed "as is" without any warranty of any
  17. * kind, whether express or implied.
  18. */
  19. #include <linux/config.h>
  20. #include <asm/io.h>
  21. #include <asm/time.h>
  22. #include <asm/mpc52xx.h>
  23. #include <asm/mpc52xx_psc.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/ppcboot.h>
  26. extern bd_t __res;
  27. static int core_mult[] = { /* CPU Frequency multiplier, taken */
  28. 0, 0, 0, 10, 20, 20, 25, 45, /* from the datasheet used to compute */
  29. 30, 55, 40, 50, 0, 60, 35, 0, /* CPU frequency from XLB freq and */
  30. 30, 25, 65, 10, 70, 20, 75, 45, /* external jumper config */
  31. 0, 55, 40, 50, 80, 60, 35, 0
  32. };
  33. void
  34. mpc52xx_restart(char *cmd)
  35. {
  36. struct mpc52xx_gpt __iomem *gpt0 = MPC52xx_VA(MPC52xx_GPTx_OFFSET(0));
  37. local_irq_disable();
  38. /* Turn on the watchdog and wait for it to expire. It effectively
  39. does a reset */
  40. out_be32(&gpt0->count, 0x000000ff);
  41. out_be32(&gpt0->mode, 0x00009004);
  42. while (1);
  43. }
  44. void
  45. mpc52xx_halt(void)
  46. {
  47. local_irq_disable();
  48. while (1);
  49. }
  50. void
  51. mpc52xx_power_off(void)
  52. {
  53. /* By default we don't have any way of shut down.
  54. If a specific board wants to, it can set the power down
  55. code to any hardware implementation dependent code */
  56. mpc52xx_halt();
  57. }
  58. void __init
  59. mpc52xx_set_bat(void)
  60. {
  61. /* Set BAT 2 to map the 0xf0000000 area */
  62. /* This mapping is used during mpc52xx_progress,
  63. * mpc52xx_find_end_of_memory, and UARTs/GPIO access for debug
  64. */
  65. mb();
  66. mtspr(SPRN_DBAT2U, 0xf0001ffe);
  67. mtspr(SPRN_DBAT2L, 0xf000002a);
  68. mb();
  69. }
  70. void __init
  71. mpc52xx_map_io(void)
  72. {
  73. /* Here we map the MBAR and the whole upper zone. MBAR is only
  74. 64k but we can't map only 64k with BATs. Map the whole
  75. 0xf0000000 range is ok and helps eventual lpb devices placed there */
  76. io_block_mapping(
  77. MPC52xx_MBAR_VIRT, MPC52xx_MBAR, 0x10000000, _PAGE_IO);
  78. }
  79. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  80. #ifndef MPC52xx_PF_CONSOLE_PORT
  81. #error "mpc52xx PSC for console not selected"
  82. #endif
  83. static void
  84. mpc52xx_psc_putc(struct mpc52xx_psc __iomem *psc, unsigned char c)
  85. {
  86. while (!(in_be16(&psc->mpc52xx_psc_status) &
  87. MPC52xx_PSC_SR_TXRDY));
  88. out_8(&psc->mpc52xx_psc_buffer_8, c);
  89. }
  90. void
  91. mpc52xx_progress(char *s, unsigned short hex)
  92. {
  93. char c;
  94. struct mpc52xx_psc __iomem *psc;
  95. psc = MPC52xx_VA(MPC52xx_PSCx_OFFSET(MPC52xx_PF_CONSOLE_PORT));
  96. while ((c = *s++) != 0) {
  97. if (c == '\n')
  98. mpc52xx_psc_putc(psc, '\r');
  99. mpc52xx_psc_putc(psc, c);
  100. }
  101. mpc52xx_psc_putc(psc, '\r');
  102. mpc52xx_psc_putc(psc, '\n');
  103. }
  104. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  105. unsigned long __init
  106. mpc52xx_find_end_of_memory(void)
  107. {
  108. u32 ramsize = __res.bi_memsize;
  109. /*
  110. * if bootloader passed a memsize, just use it
  111. * else get size from sdram config registers
  112. */
  113. if (ramsize == 0) {
  114. struct mpc52xx_mmap_ctl __iomem *mmap_ctl;
  115. u32 sdram_config_0, sdram_config_1;
  116. /* Temp BAT2 mapping active when this is called ! */
  117. mmap_ctl = MPC52xx_VA(MPC52xx_MMAP_CTL_OFFSET);
  118. sdram_config_0 = in_be32(&mmap_ctl->sdram0);
  119. sdram_config_1 = in_be32(&mmap_ctl->sdram1);
  120. if ((sdram_config_0 & 0x1f) >= 0x13)
  121. ramsize = 1 << ((sdram_config_0 & 0xf) + 17);
  122. if (((sdram_config_1 & 0x1f) >= 0x13) &&
  123. ((sdram_config_1 & 0xfff00000) == ramsize))
  124. ramsize += 1 << ((sdram_config_1 & 0xf) + 17);
  125. }
  126. return ramsize;
  127. }
  128. void __init
  129. mpc52xx_calibrate_decr(void)
  130. {
  131. int current_time, previous_time;
  132. int tbl_start, tbl_end;
  133. unsigned int xlbfreq, cpufreq, ipbfreq, pcifreq, divisor;
  134. xlbfreq = __res.bi_busfreq;
  135. /* if bootloader didn't pass bus frequencies, calculate them */
  136. if (xlbfreq == 0) {
  137. /* Get RTC & Clock manager modules */
  138. struct mpc52xx_rtc __iomem *rtc;
  139. struct mpc52xx_cdm __iomem *cdm;
  140. rtc = ioremap(MPC52xx_PA(MPC52xx_RTC_OFFSET), MPC52xx_RTC_SIZE);
  141. cdm = ioremap(MPC52xx_PA(MPC52xx_CDM_OFFSET), MPC52xx_CDM_SIZE);
  142. if ((rtc==NULL) || (cdm==NULL))
  143. panic("Can't ioremap RTC/CDM while computing bus freq");
  144. /* Count bus clock during 1/64 sec */
  145. out_be32(&rtc->dividers, 0x8f1f0000); /* Set RTC 64x faster */
  146. previous_time = in_be32(&rtc->time);
  147. while ((current_time = in_be32(&rtc->time)) == previous_time) ;
  148. tbl_start = get_tbl();
  149. previous_time = current_time;
  150. while ((current_time = in_be32(&rtc->time)) == previous_time) ;
  151. tbl_end = get_tbl();
  152. out_be32(&rtc->dividers, 0xffff0000); /* Restore RTC */
  153. /* Compute all frequency from that & CDM settings */
  154. xlbfreq = (tbl_end - tbl_start) << 8;
  155. cpufreq = (xlbfreq * core_mult[in_be32(&cdm->rstcfg)&0x1f])/10;
  156. ipbfreq = (in_8(&cdm->ipb_clk_sel) & 1) ?
  157. xlbfreq / 2 : xlbfreq;
  158. switch (in_8(&cdm->pci_clk_sel) & 3) {
  159. case 0:
  160. pcifreq = ipbfreq;
  161. break;
  162. case 1:
  163. pcifreq = ipbfreq / 2;
  164. break;
  165. default:
  166. pcifreq = xlbfreq / 4;
  167. break;
  168. }
  169. __res.bi_busfreq = xlbfreq;
  170. __res.bi_intfreq = cpufreq;
  171. __res.bi_ipbfreq = ipbfreq;
  172. __res.bi_pcifreq = pcifreq;
  173. /* Release mapping */
  174. iounmap(rtc);
  175. iounmap(cdm);
  176. }
  177. divisor = 4;
  178. tb_ticks_per_jiffy = xlbfreq / HZ / divisor;
  179. tb_to_us = mulhwu_scale_factor(xlbfreq / divisor, 1000000);
  180. }
  181. int mpc52xx_match_psc_function(int psc_idx, const char *func)
  182. {
  183. struct mpc52xx_psc_func *cf = mpc52xx_psc_functions;
  184. while ((cf->id != -1) && (cf->func != NULL)) {
  185. if ((cf->id == psc_idx) && !strcmp(cf->func,func))
  186. return 1;
  187. cf++;
  188. }
  189. return 0;
  190. }