ca9x4_ct_vxp.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #include <asm/io.h>
  38. #include <asm/arch/systimer.h>
  39. #include <asm/arch/sysctrl.h>
  40. #include <asm/arch/wdt.h>
  41. static ulong timestamp;
  42. static ulong lastdec;
  43. static struct wdt *wdt_base = (struct wdt *)WDT_BASE;
  44. static struct systimer *systimer_base = (struct systimer *)SYSTIMER_BASE;
  45. static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
  46. static void flash__init(void);
  47. static void vexpress_timer_init(void);
  48. DECLARE_GLOBAL_DATA_PTR;
  49. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  50. void show_boot_progress(int progress)
  51. {
  52. printf("Boot reached stage %d\n", progress);
  53. }
  54. #endif
  55. static inline void delay(ulong loops)
  56. {
  57. __asm__ volatile ("1:\n"
  58. "subs %0, %1, #1\n"
  59. "bne 1b" : "=r" (loops) : "0" (loops));
  60. }
  61. int board_init(void)
  62. {
  63. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  64. gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
  65. gd->flags = 0;
  66. icache_enable();
  67. flash__init();
  68. vexpress_timer_init();
  69. return 0;
  70. }
  71. int board_eth_init(bd_t *bis)
  72. {
  73. int rc = 0;
  74. #ifdef CONFIG_SMC911X
  75. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  76. #endif
  77. return rc;
  78. }
  79. static void flash__init(void)
  80. {
  81. /* Setup the sytem control register to allow writing to flash */
  82. writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
  83. &sysctrl_base->scflashctrl);
  84. }
  85. int dram_init(void)
  86. {
  87. gd->ram_size =
  88. get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
  89. return 0;
  90. }
  91. void dram_init_banksize(void)
  92. {
  93. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  94. gd->bd->bi_dram[0].size =
  95. get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  96. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  97. gd->bd->bi_dram[1].size =
  98. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  99. }
  100. int timer_init(void)
  101. {
  102. return 0;
  103. }
  104. /*
  105. * Start timer:
  106. * Setup a 32 bit timer, running at 1KHz
  107. * Versatile Express Motherboard provides 1 MHz timer
  108. */
  109. static void vexpress_timer_init(void)
  110. {
  111. /*
  112. * Set clock frequency in system controller:
  113. * VEXPRESS_REFCLK is 32KHz
  114. * VEXPRESS_TIMCLK is 1MHz
  115. */
  116. writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
  117. SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
  118. readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
  119. /*
  120. * Set Timer0 to be:
  121. * Enabled, free running, no interrupt, 32-bit, wrapping
  122. */
  123. writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
  124. writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
  125. writel(SYSTIMER_EN | SYSTIMER_32BIT | \
  126. readl(&systimer_base->timer0control), \
  127. &systimer_base->timer0control);
  128. reset_timer_masked();
  129. }
  130. /* Use the ARM Watchdog System to cause reset */
  131. void reset_cpu(ulong addr)
  132. {
  133. writeb(WDT_EN, &wdt_base->wdogcontrol);
  134. writel(WDT_RESET_LOAD, &wdt_base->wdogload);
  135. while (1)
  136. ;
  137. }
  138. /*
  139. * Delay x useconds AND perserve advance timstamp value
  140. * assumes timer is ticking at 1 msec
  141. */
  142. void __udelay(ulong usec)
  143. {
  144. ulong tmo, tmp;
  145. tmo = usec / 1000;
  146. tmp = get_timer(0); /* get current timestamp */
  147. /*
  148. * If setting this forward will roll time stamp then
  149. * reset "advancing" timestamp to 0 and set lastdec value
  150. * otherwise set the advancing stamp to the wake up time
  151. */
  152. if ((tmo + tmp + 1) < tmp)
  153. reset_timer_masked();
  154. else
  155. tmo += tmp;
  156. while (get_timer_masked() < tmo)
  157. ; /* loop till wakeup event */
  158. }
  159. ulong get_timer(ulong base)
  160. {
  161. return get_timer_masked() - base;
  162. }
  163. void reset_timer_masked(void)
  164. {
  165. lastdec = readl(&systimer_base->timer0value) / 1000;
  166. timestamp = 0;
  167. }
  168. void reset_timer(void)
  169. {
  170. reset_timer_masked();
  171. }
  172. ulong get_timer_masked(void)
  173. {
  174. ulong now = readl(&systimer_base->timer0value) / 1000;
  175. if (lastdec >= now) { /* normal mode (non roll) */
  176. timestamp += lastdec - now;
  177. } else { /* count down timer overflowed */
  178. /*
  179. * nts = ts + ld - now
  180. * ts = old stamp, ld = time before passing through - 1
  181. * now = amount of time after passing though - 1
  182. * nts = new "advancing time stamp"
  183. */
  184. timestamp += lastdec + SYSTIMER_RELOAD - now;
  185. }
  186. lastdec = now;
  187. return timestamp;
  188. }
  189. void lowlevel_init(void)
  190. {
  191. }
  192. ulong get_board_rev(void){
  193. return readl((u32 *)SYS_ID);
  194. }