bab7xx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  3. * Andreas Heppel <aheppel@sysgo.de>
  4. * (C) Copyright 2001 ELTEC Elektronik AG
  5. * Frank Gottschling <fgottschling@eltec.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <mpc106.h>
  28. #include <mk48t59.h>
  29. #include <74xx_7xx.h>
  30. #include <ns87308.h>
  31. #include <video_fb.h>
  32. /*---------------------------------------------------------------------------*/
  33. /*
  34. * Get Bus clock frequency
  35. */
  36. ulong bab7xx_get_bus_freq (void)
  37. {
  38. /*
  39. * The GPIO Port 1 on BAB7xx reflects the bus speed.
  40. */
  41. volatile struct GPIO *gpio = (struct GPIO *)(CFG_ISA_IO + CFG_NS87308_GPIO_BASE);
  42. unsigned char data = gpio->dta1;
  43. if (data & 0x02)
  44. return 66666666;
  45. return 83333333;
  46. }
  47. /*---------------------------------------------------------------------------*/
  48. /*
  49. * Measure CPU clock speed (core clock GCLK1) (Approx. GCLK frequency in Hz)
  50. */
  51. ulong bab7xx_get_gclk_freq (void)
  52. {
  53. static const int pllratio_to_factor[] = {
  54. 00, 75, 70, 00, 20, 65, 100, 45, 30, 55, 40, 50, 80, 60, 35, 00,
  55. };
  56. return pllratio_to_factor[get_hid1 () >> 28] * (bab7xx_get_bus_freq() / 10);
  57. }
  58. /*----------------------------------------------------------------------------*/
  59. int checkcpu (void)
  60. {
  61. uint pvr = get_pvr();
  62. printf ("MPC7xx V%d.%d",(pvr >> 8) & 0xFF, pvr & 0xFF);
  63. printf (" at %ld / %ld MHz\n", bab7xx_get_gclk_freq()/1000000,
  64. bab7xx_get_bus_freq()/1000000);
  65. return (0);
  66. }
  67. /* ------------------------------------------------------------------------- */
  68. int checkboard (void)
  69. {
  70. #ifdef CFG_ADDRESS_MAP_A
  71. puts ("Board: ELTEC BAB7xx PReP\n");
  72. #else
  73. puts ("Board: ELTEC BAB7xx CHRP\n");
  74. #endif
  75. return (0);
  76. }
  77. /* ------------------------------------------------------------------------- */
  78. int checkflash (void)
  79. {
  80. /* TODO: XXX XXX XXX */
  81. printf ("2 MB ## Test not implemented yet ##\n");
  82. return (0);
  83. }
  84. /* ------------------------------------------------------------------------- */
  85. static unsigned int mpc106_read_cfg_dword (unsigned int reg)
  86. {
  87. unsigned int reg_addr = MPC106_REG | (reg & 0xFFFFFFFC);
  88. out32r(MPC106_REG_ADDR, reg_addr);
  89. return (in32r(MPC106_REG_DATA | (reg & 0x3)));
  90. }
  91. /* ------------------------------------------------------------------------- */
  92. long int dram_size (int board_type)
  93. {
  94. /* No actual initialisation to do - done when setting up
  95. * PICRs MCCRs ME/SARs etc in ram_init.S.
  96. */
  97. register unsigned long i, msar1, mear1, memSize;
  98. #if defined(CFG_MEMTEST)
  99. register unsigned long reg;
  100. printf("Testing DRAM\n");
  101. /* write each mem addr with it's address */
  102. for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg+=4)
  103. *reg = reg;
  104. for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg+=4)
  105. {
  106. if (*reg != reg)
  107. return -1;
  108. }
  109. #endif
  110. /*
  111. * Since MPC106 memory controller chip has already been set to
  112. * control all memory, just read and interpret its memory boundery register.
  113. */
  114. memSize = 0;
  115. msar1 = mpc106_read_cfg_dword(MPC106_MSAR1);
  116. mear1 = mpc106_read_cfg_dword(MPC106_MEAR1);
  117. i = mpc106_read_cfg_dword(MPC106_MBER) & 0xf;
  118. do
  119. {
  120. if (i & 0x01) /* is bank enabled ? */
  121. memSize += (mear1 & 0xff) - (msar1 & 0xff) + 1;
  122. msar1 >>= 8;
  123. mear1 >>= 8;
  124. i >>= 1;
  125. } while (i);
  126. return (memSize * 0x100000);
  127. }
  128. /* ------------------------------------------------------------------------- */
  129. long int initdram(int board_type)
  130. {
  131. return dram_size(board_type);
  132. }
  133. /* ------------------------------------------------------------------------- */
  134. void after_reloc (ulong dest_addr)
  135. {
  136. DECLARE_GLOBAL_DATA_PTR;
  137. /*
  138. * Jump to the main U-Boot board init code
  139. */
  140. board_init_r(gd, dest_addr);
  141. }
  142. /* ------------------------------------------------------------------------- */
  143. /*
  144. * do_reset is done here because in this case it is board specific, since the
  145. * 7xx CPUs can only be reset by external HW (the RTC in this case).
  146. */
  147. void
  148. do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  149. {
  150. #if defined(CONFIG_RTC_MK48T59)
  151. /* trigger watchdog immediately */
  152. rtc_set_watchdog(1, RTC_WD_RB_16TH);
  153. #else
  154. #error "You must define the macro CONFIG_RTC_MK48T59."
  155. #endif
  156. }
  157. /* ------------------------------------------------------------------------- */
  158. #if defined(CONFIG_WATCHDOG)
  159. /*
  160. * Since the 7xx CPUs don't have an internal watchdog, this function is
  161. * board specific. We use the RTC here.
  162. */
  163. void watchdog_reset(void)
  164. {
  165. #if defined(CONFIG_RTC_MK48T59)
  166. /* we use a 32 sec watchdog timer */
  167. rtc_set_watchdog(8, RTC_WD_RB_4);
  168. #else
  169. #error "You must define the macro CONFIG_RTC_MK48T59."
  170. #endif
  171. }
  172. #endif /* CONFIG_WATCHDOG */
  173. /* ------------------------------------------------------------------------- */
  174. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  175. extern GraphicDevice smi;
  176. void video_get_info_str (int line_number, char *info)
  177. {
  178. /* init video info strings for graphic console */
  179. switch (line_number)
  180. {
  181. case 1:
  182. sprintf (info," MPC7xx V%d.%d at %ld / %ld MHz",
  183. (get_pvr() >> 8) & 0xFF,
  184. get_pvr() & 0xFF,
  185. bab7xx_get_gclk_freq()/1000000,
  186. bab7xx_get_bus_freq()/1000000);
  187. return;
  188. case 2:
  189. sprintf (info, " ELTEC BAB7xx with %ld MB DRAM and %ld MB FLASH",
  190. dram_size(0)/0x100000,
  191. flash_init()/0x100000);
  192. return;
  193. case 3:
  194. sprintf (info, " %s", smi.modeIdent);
  195. return;
  196. }
  197. /* no more info lines */
  198. *info = 0;
  199. return;
  200. }
  201. #endif
  202. /*---------------------------------------------------------------------------*/