integratorap.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
  8. *
  9. * (C) Copyright 2003
  10. * Texas Instruments, <www.ti.com>
  11. * Kshitij Gupta <Kshitij@ti.com>
  12. *
  13. * (C) Copyright 2004
  14. * ARM Ltd.
  15. * Philippe Robin, <philippe.robin@arm.com>
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <common.h>
  36. #include <netdev.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. void flash__init (void);
  39. void ether__init (void);
  40. void peripheral_power_enable (void);
  41. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  42. void show_boot_progress(int progress)
  43. {
  44. printf("Boot reached stage %d\n", progress);
  45. }
  46. #endif
  47. #define COMP_MODE_ENABLE ((unsigned int)0x0000EAEF)
  48. static inline void delay (unsigned long loops)
  49. {
  50. __asm__ volatile ("1:\n"
  51. "subs %0, %1, #1\n"
  52. "bne 1b":"=r" (loops):"0" (loops));
  53. }
  54. /*
  55. * Miscellaneous platform dependent initialisations
  56. */
  57. int board_init (void)
  58. {
  59. /* arch number of Integrator Board */
  60. gd->bd->bi_arch_number = MACH_TYPE_INTEGRATOR;
  61. /* adress of boot parameters */
  62. gd->bd->bi_boot_params = 0x00000100;
  63. gd->flags = 0;
  64. #ifdef CONFIG_CM_REMAP
  65. extern void cm_remap(void);
  66. cm_remap(); /* remaps writeable memory to 0x00000000 */
  67. #endif
  68. icache_enable ();
  69. flash__init ();
  70. return 0;
  71. }
  72. int misc_init_r (void)
  73. {
  74. #ifdef CONFIG_PCI
  75. pci_init();
  76. #endif
  77. setenv("verify", "n");
  78. return (0);
  79. }
  80. /******************************
  81. Routine:
  82. Description:
  83. ******************************/
  84. void flash__init (void)
  85. {
  86. }
  87. /*************************************************************
  88. Routine:ether__init
  89. Description: take the Ethernet controller out of reset and wait
  90. for the EEPROM load to complete.
  91. *************************************************************/
  92. void ether__init (void)
  93. {
  94. }
  95. /******************************
  96. Routine:
  97. Description:
  98. ******************************/
  99. int dram_init (void)
  100. {
  101. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  102. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  103. #ifdef CONFIG_CM_SPD_DETECT
  104. {
  105. extern void dram_query(void);
  106. unsigned long cm_reg_sdram;
  107. unsigned long sdram_shift;
  108. dram_query(); /* Assembler accesses to CM registers */
  109. /* Queries the SPD values */
  110. /* Obtain the SDRAM size from the CM SDRAM register */
  111. cm_reg_sdram = *(volatile ulong *)(CM_BASE + OS_SDRAM);
  112. /* Register SDRAM size
  113. *
  114. * 0xXXXXXXbbb000bb 16 MB
  115. * 0xXXXXXXbbb001bb 32 MB
  116. * 0xXXXXXXbbb010bb 64 MB
  117. * 0xXXXXXXbbb011bb 128 MB
  118. * 0xXXXXXXbbb100bb 256 MB
  119. *
  120. */
  121. sdram_shift = ((cm_reg_sdram & 0x0000001C)/4)%4;
  122. gd->bd->bi_dram[0].size = 0x01000000 << sdram_shift;
  123. }
  124. #endif /* CM_SPD_DETECT */
  125. return 0;
  126. }
  127. /* The Integrator/AP timer1 is clocked at 24MHz
  128. * can be divided by 16 or 256
  129. * and is a 16-bit counter
  130. */
  131. /* U-Boot expects a 32 bit timer running at CONFIG_SYS_HZ*/
  132. static ulong timestamp; /* U-Boot ticks since startup */
  133. static ulong total_count = 0; /* Total timer count */
  134. static ulong lastdec; /* Timer reading at last call */
  135. static ulong div_clock = 256; /* Divisor applied to the timer clock */
  136. static ulong div_timer = 1; /* Divisor to convert timer reading
  137. * change to U-Boot ticks
  138. */
  139. /* CONFIG_SYS_HZ = CONFIG_SYS_HZ_CLOCK/(div_clock * div_timer) */
  140. #define TIMER_LOAD_VAL 0x0000FFFFL
  141. #define READ_TIMER ((*(volatile ulong *)(CONFIG_SYS_TIMERBASE+4)) & 0x0000FFFFL)
  142. /* all function return values in U-Boot ticks i.e. (1/CONFIG_SYS_HZ) sec
  143. * - unless otherwise stated
  144. */
  145. /* starts a counter
  146. * - the Integrator/AP timer issues an interrupt
  147. * each time it reaches zero
  148. */
  149. int timer_init (void)
  150. {
  151. /* Load timer with initial value */
  152. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 0) = TIMER_LOAD_VAL;
  153. /* Set timer to be
  154. * enabled 1
  155. * free-running 0
  156. * XX 00
  157. * divider 256 10
  158. * XX 00
  159. */
  160. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = 0x00000088;
  161. total_count = 0;
  162. /* init the timestamp and lastdec value */
  163. reset_timer_masked();
  164. div_timer = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
  165. div_timer /= div_clock;
  166. return (0);
  167. }
  168. /*
  169. * timer without interrupts
  170. */
  171. void reset_timer (void)
  172. {
  173. reset_timer_masked ();
  174. }
  175. ulong get_timer (ulong base_ticks)
  176. {
  177. return get_timer_masked () - base_ticks;
  178. }
  179. void set_timer (ulong ticks)
  180. {
  181. timestamp = ticks;
  182. total_count = ticks * div_timer;
  183. reset_timer_masked();
  184. }
  185. /* delay x useconds */
  186. void udelay (unsigned long usec)
  187. {
  188. ulong tmo, tmp;
  189. /* Convert to U-Boot ticks */
  190. tmo = usec * CONFIG_SYS_HZ;
  191. tmo /= (1000000L);
  192. tmp = get_timer_masked(); /* get current timestamp */
  193. tmo += tmp; /* wake up timestamp */
  194. while (get_timer_masked () < tmo) { /* loop till event */
  195. /*NOP*/;
  196. }
  197. }
  198. void reset_timer_masked (void)
  199. {
  200. /* reset time */
  201. lastdec = READ_TIMER; /* capture current decrementer value */
  202. timestamp = 0; /* start "advancing" time stamp from 0 */
  203. }
  204. /* converts the timer reading to U-Boot ticks */
  205. /* the timestamp is the number of ticks since reset */
  206. /* This routine does not detect wraps unless called regularly
  207. ASSUMES a call at least every 16 seconds to detect every reload */
  208. ulong get_timer_masked (void)
  209. {
  210. ulong now = READ_TIMER; /* current count */
  211. if (now > lastdec) {
  212. /* Must have wrapped */
  213. total_count += lastdec + TIMER_LOAD_VAL + 1 - now;
  214. } else {
  215. total_count += lastdec - now;
  216. }
  217. lastdec = now;
  218. timestamp = total_count/div_timer;
  219. return timestamp;
  220. }
  221. /* waits specified delay value and resets timestamp */
  222. void udelay_masked (unsigned long usec)
  223. {
  224. udelay(usec);
  225. }
  226. /*
  227. * This function is derived from PowerPC code (read timebase as long long).
  228. * On ARM it just returns the timer value.
  229. */
  230. unsigned long long get_ticks(void)
  231. {
  232. return get_timer(0);
  233. }
  234. /*
  235. * Return the timebase clock frequency
  236. * i.e. how often the timer decrements
  237. */
  238. ulong get_tbclk (void)
  239. {
  240. return CONFIG_SYS_HZ_CLOCK/div_clock;
  241. }
  242. int board_eth_init(bd_t *bis)
  243. {
  244. return pci_eth_init(bis);
  245. }