bab7xx.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include <netdev.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. /*---------------------------------------------------------------------------*/
  35. /*
  36. * Get Bus clock frequency
  37. */
  38. ulong bab7xx_get_bus_freq (void)
  39. {
  40. /*
  41. * The GPIO Port 1 on BAB7xx reflects the bus speed.
  42. */
  43. volatile struct GPIO *gpio =
  44. (struct GPIO *) (CONFIG_SYS_ISA_IO + CONFIG_SYS_NS87308_GPIO_BASE);
  45. unsigned char data = gpio->dta1;
  46. if (data & 0x02)
  47. return 66666666;
  48. return 83333333;
  49. }
  50. /*---------------------------------------------------------------------------*/
  51. /*
  52. * Measure CPU clock speed (core clock GCLK1) (Approx. GCLK frequency in Hz)
  53. */
  54. ulong bab7xx_get_gclk_freq (void)
  55. {
  56. static const int pllratio_to_factor[] = {
  57. 00, 75, 70, 00, 20, 65, 100, 45, 30, 55, 40, 50, 80, 60, 35,
  58. 00,
  59. };
  60. return pllratio_to_factor[get_hid1 () >> 28] *
  61. (bab7xx_get_bus_freq () / 10);
  62. }
  63. /*----------------------------------------------------------------------------*/
  64. int checkcpu (void)
  65. {
  66. uint pvr = get_pvr ();
  67. printf ("MPC7xx V%d.%d", (pvr >> 8) & 0xFF, pvr & 0xFF);
  68. printf (" at %ld / %ld MHz\n", bab7xx_get_gclk_freq () / 1000000,
  69. bab7xx_get_bus_freq () / 1000000);
  70. return (0);
  71. }
  72. /* ------------------------------------------------------------------------- */
  73. int checkboard (void)
  74. {
  75. #ifdef CONFIG_SYS_ADDRESS_MAP_A
  76. puts ("Board: ELTEC BAB7xx PReP\n");
  77. #else
  78. puts ("Board: ELTEC BAB7xx CHRP\n");
  79. #endif
  80. return (0);
  81. }
  82. /* ------------------------------------------------------------------------- */
  83. int checkflash (void)
  84. {
  85. /* TODO: XXX XXX XXX */
  86. printf ("2 MB ## Test not implemented yet ##\n");
  87. return (0);
  88. }
  89. /* ------------------------------------------------------------------------- */
  90. static unsigned int mpc106_read_cfg_dword (unsigned int reg)
  91. {
  92. unsigned int reg_addr = MPC106_REG | (reg & 0xFFFFFFFC);
  93. out32r (MPC106_REG_ADDR, reg_addr);
  94. return (in32r (MPC106_REG_DATA | (reg & 0x3)));
  95. }
  96. /* ------------------------------------------------------------------------- */
  97. long int dram_size (int board_type)
  98. {
  99. /* No actual initialisation to do - done when setting up
  100. * PICRs MCCRs ME/SARs etc in ram_init.S.
  101. */
  102. register unsigned long i, msar1, mear1, memSize;
  103. #if defined(CONFIG_SYS_MEMTEST)
  104. register unsigned long reg;
  105. printf ("Testing DRAM\n");
  106. /* write each mem addr with it's address */
  107. for (reg = CONFIG_SYS_MEMTEST_START; reg < CONFIG_SYS_MEMTEST_END; reg += 4)
  108. *reg = reg;
  109. for (reg = CONFIG_SYS_MEMTEST_START; reg < CONFIG_SYS_MEMTEST_END; reg += 4) {
  110. if (*reg != reg)
  111. return -1;
  112. }
  113. #endif
  114. /*
  115. * Since MPC106 memory controller chip has already been set to
  116. * control all memory, just read and interpret its memory boundery register.
  117. */
  118. memSize = 0;
  119. msar1 = mpc106_read_cfg_dword (MPC106_MSAR1);
  120. mear1 = mpc106_read_cfg_dword (MPC106_MEAR1);
  121. i = mpc106_read_cfg_dword (MPC106_MBER) & 0xf;
  122. do {
  123. if (i & 0x01) /* is bank enabled ? */
  124. memSize += (mear1 & 0xff) - (msar1 & 0xff) + 1;
  125. msar1 >>= 8;
  126. mear1 >>= 8;
  127. i >>= 1;
  128. } while (i);
  129. return (memSize * 0x100000);
  130. }
  131. /* ------------------------------------------------------------------------- */
  132. phys_size_t initdram (int board_type)
  133. {
  134. return dram_size (board_type);
  135. }
  136. /* ------------------------------------------------------------------------- */
  137. void after_reloc (ulong dest_addr)
  138. {
  139. /*
  140. * Jump to the main U-Boot board init code
  141. */
  142. board_init_r ((gd_t *) gd, dest_addr);
  143. }
  144. /* ------------------------------------------------------------------------- */
  145. /*
  146. * do_reset is done here because in this case it is board specific, since the
  147. * 7xx CPUs can only be reset by external HW (the RTC in this case).
  148. */
  149. void do_reset (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  150. {
  151. #if defined(CONFIG_RTC_MK48T59)
  152. /* trigger watchdog immediately */
  153. rtc_set_watchdog (1, RTC_WD_RB_16TH);
  154. #else
  155. #error "You must define the macro CONFIG_RTC_MK48T59."
  156. #endif
  157. }
  158. /* ------------------------------------------------------------------------- */
  159. #if defined(CONFIG_WATCHDOG)
  160. /*
  161. * Since the 7xx CPUs don't have an internal watchdog, this function is
  162. * board specific. We use the RTC here.
  163. */
  164. void watchdog_reset (void)
  165. {
  166. #if defined(CONFIG_RTC_MK48T59)
  167. /* we use a 32 sec watchdog timer */
  168. rtc_set_watchdog (8, RTC_WD_RB_4);
  169. #else
  170. #error "You must define the macro CONFIG_RTC_MK48T59."
  171. #endif
  172. }
  173. #endif /* CONFIG_WATCHDOG */
  174. /* ------------------------------------------------------------------------- */
  175. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  176. extern GraphicDevice smi;
  177. void video_get_info_str (int line_number, char *info)
  178. {
  179. /* init video info strings for graphic console */
  180. switch (line_number) {
  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,
  190. " ELTEC BAB7xx with %ld MB DRAM and %ld MB FLASH",
  191. dram_size (0) / 0x100000, 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. /*---------------------------------------------------------------------------*/
  203. int board_eth_init(bd_t *bis)
  204. {
  205. return pci_eth_init(bis);
  206. }