bab7xx.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. DECLARE_GLOBAL_DATA_PTR;
  33. /*---------------------------------------------------------------------------*/
  34. /*
  35. * Get Bus clock frequency
  36. */
  37. ulong bab7xx_get_bus_freq (void)
  38. {
  39. /*
  40. * The GPIO Port 1 on BAB7xx reflects the bus speed.
  41. */
  42. volatile struct GPIO *gpio =
  43. (struct GPIO *) (CFG_ISA_IO + CFG_NS87308_GPIO_BASE);
  44. unsigned char data = gpio->dta1;
  45. if (data & 0x02)
  46. return 66666666;
  47. return 83333333;
  48. }
  49. /*---------------------------------------------------------------------------*/
  50. /*
  51. * Measure CPU clock speed (core clock GCLK1) (Approx. GCLK frequency in Hz)
  52. */
  53. ulong bab7xx_get_gclk_freq (void)
  54. {
  55. static const int pllratio_to_factor[] = {
  56. 00, 75, 70, 00, 20, 65, 100, 45, 30, 55, 40, 50, 80, 60, 35,
  57. 00,
  58. };
  59. return pllratio_to_factor[get_hid1 () >> 28] *
  60. (bab7xx_get_bus_freq () / 10);
  61. }
  62. /*----------------------------------------------------------------------------*/
  63. int checkcpu (void)
  64. {
  65. uint pvr = get_pvr ();
  66. printf ("MPC7xx V%d.%d", (pvr >> 8) & 0xFF, pvr & 0xFF);
  67. printf (" at %ld / %ld MHz\n", bab7xx_get_gclk_freq () / 1000000,
  68. bab7xx_get_bus_freq () / 1000000);
  69. return (0);
  70. }
  71. /* ------------------------------------------------------------------------- */
  72. int checkboard (void)
  73. {
  74. #ifdef CFG_ADDRESS_MAP_A
  75. puts ("Board: ELTEC BAB7xx PReP\n");
  76. #else
  77. puts ("Board: ELTEC BAB7xx CHRP\n");
  78. #endif
  79. return (0);
  80. }
  81. /* ------------------------------------------------------------------------- */
  82. int checkflash (void)
  83. {
  84. /* TODO: XXX XXX XXX */
  85. printf ("2 MB ## Test not implemented yet ##\n");
  86. return (0);
  87. }
  88. /* ------------------------------------------------------------------------- */
  89. static unsigned int mpc106_read_cfg_dword (unsigned int reg)
  90. {
  91. unsigned int reg_addr = MPC106_REG | (reg & 0xFFFFFFFC);
  92. out32r (MPC106_REG_ADDR, reg_addr);
  93. return (in32r (MPC106_REG_DATA | (reg & 0x3)));
  94. }
  95. /* ------------------------------------------------------------------------- */
  96. long int dram_size (int board_type)
  97. {
  98. /* No actual initialisation to do - done when setting up
  99. * PICRs MCCRs ME/SARs etc in ram_init.S.
  100. */
  101. register unsigned long i, msar1, mear1, memSize;
  102. #if defined(CFG_MEMTEST)
  103. register unsigned long reg;
  104. printf ("Testing DRAM\n");
  105. /* write each mem addr with it's address */
  106. for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg += 4)
  107. *reg = reg;
  108. for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg += 4) {
  109. if (*reg != reg)
  110. return -1;
  111. }
  112. #endif
  113. /*
  114. * Since MPC106 memory controller chip has already been set to
  115. * control all memory, just read and interpret its memory boundery register.
  116. */
  117. memSize = 0;
  118. msar1 = mpc106_read_cfg_dword (MPC106_MSAR1);
  119. mear1 = mpc106_read_cfg_dword (MPC106_MEAR1);
  120. i = mpc106_read_cfg_dword (MPC106_MBER) & 0xf;
  121. do {
  122. if (i & 0x01) /* is bank enabled ? */
  123. memSize += (mear1 & 0xff) - (msar1 & 0xff) + 1;
  124. msar1 >>= 8;
  125. mear1 >>= 8;
  126. i >>= 1;
  127. } while (i);
  128. return (memSize * 0x100000);
  129. }
  130. /* ------------------------------------------------------------------------- */
  131. long int initdram (int board_type)
  132. {
  133. return dram_size (board_type);
  134. }
  135. /* ------------------------------------------------------------------------- */
  136. void after_reloc (ulong dest_addr)
  137. {
  138. /*
  139. * Jump to the main U-Boot board init code
  140. */
  141. board_init_r ((gd_t *) gd, dest_addr);
  142. }
  143. /* ------------------------------------------------------------------------- */
  144. /*
  145. * do_reset is done here because in this case it is board specific, since the
  146. * 7xx CPUs can only be reset by external HW (the RTC in this case).
  147. */
  148. void 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. case 1:
  181. sprintf (info, " MPC7xx V%d.%d at %ld / %ld MHz",
  182. (get_pvr () >> 8) & 0xFF,
  183. get_pvr () & 0xFF,
  184. bab7xx_get_gclk_freq () / 1000000,
  185. bab7xx_get_bus_freq () / 1000000);
  186. return;
  187. case 2:
  188. sprintf (info,
  189. " ELTEC BAB7xx with %ld MB DRAM and %ld MB FLASH",
  190. dram_size (0) / 0x100000, flash_init () / 0x100000);
  191. return;
  192. case 3:
  193. sprintf (info, " %s", smi.modeIdent);
  194. return;
  195. }
  196. /* no more info lines */
  197. *info = 0;
  198. return;
  199. }
  200. #endif
  201. /*---------------------------------------------------------------------------*/