mpc52xx_setup.c 6.8 KB

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