ca9x4_ct_vxp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. int cpu_mmc_init(bd_t *bis)
  80. {
  81. int rc = 0;
  82. #ifdef CONFIG_ARM_PL180_MMCI
  83. rc = arm_pl180_mmci_init();
  84. #endif
  85. return rc;
  86. }
  87. static void flash__init(void)
  88. {
  89. /* Setup the sytem control register to allow writing to flash */
  90. writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
  91. &sysctrl_base->scflashctrl);
  92. }
  93. int dram_init(void)
  94. {
  95. gd->ram_size =
  96. get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
  97. return 0;
  98. }
  99. void dram_init_banksize(void)
  100. {
  101. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  102. gd->bd->bi_dram[0].size =
  103. get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  104. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  105. gd->bd->bi_dram[1].size =
  106. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  107. }
  108. int timer_init(void)
  109. {
  110. return 0;
  111. }
  112. /*
  113. * Start timer:
  114. * Setup a 32 bit timer, running at 1KHz
  115. * Versatile Express Motherboard provides 1 MHz timer
  116. */
  117. static void vexpress_timer_init(void)
  118. {
  119. /*
  120. * Set clock frequency in system controller:
  121. * VEXPRESS_REFCLK is 32KHz
  122. * VEXPRESS_TIMCLK is 1MHz
  123. */
  124. writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
  125. SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
  126. readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
  127. /*
  128. * Set Timer0 to be:
  129. * Enabled, free running, no interrupt, 32-bit, wrapping
  130. */
  131. writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
  132. writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
  133. writel(SYSTIMER_EN | SYSTIMER_32BIT | \
  134. readl(&systimer_base->timer0control), \
  135. &systimer_base->timer0control);
  136. reset_timer_masked();
  137. }
  138. /* Use the ARM Watchdog System to cause reset */
  139. void reset_cpu(ulong addr)
  140. {
  141. writeb(WDT_EN, &wdt_base->wdogcontrol);
  142. writel(WDT_RESET_LOAD, &wdt_base->wdogload);
  143. while (1)
  144. ;
  145. }
  146. /*
  147. * Delay x useconds AND perserve advance timstamp value
  148. * assumes timer is ticking at 1 msec
  149. */
  150. void __udelay(ulong usec)
  151. {
  152. ulong tmo, tmp;
  153. tmo = usec / 1000;
  154. tmp = get_timer(0); /* get current timestamp */
  155. /*
  156. * If setting this forward will roll time stamp then
  157. * reset "advancing" timestamp to 0 and set lastdec value
  158. * otherwise set the advancing stamp to the wake up time
  159. */
  160. if ((tmo + tmp + 1) < tmp)
  161. reset_timer_masked();
  162. else
  163. tmo += tmp;
  164. while (get_timer_masked() < tmo)
  165. ; /* loop till wakeup event */
  166. }
  167. ulong get_timer(ulong base)
  168. {
  169. return get_timer_masked() - base;
  170. }
  171. void reset_timer_masked(void)
  172. {
  173. lastdec = readl(&systimer_base->timer0value) / 1000;
  174. timestamp = 0;
  175. }
  176. void reset_timer(void)
  177. {
  178. reset_timer_masked();
  179. }
  180. ulong get_timer_masked(void)
  181. {
  182. ulong now = readl(&systimer_base->timer0value) / 1000;
  183. if (lastdec >= now) { /* normal mode (non roll) */
  184. timestamp += lastdec - now;
  185. } else { /* count down timer overflowed */
  186. /*
  187. * nts = ts + ld - now
  188. * ts = old stamp, ld = time before passing through - 1
  189. * now = amount of time after passing though - 1
  190. * nts = new "advancing time stamp"
  191. */
  192. timestamp += lastdec + SYSTIMER_RELOAD - now;
  193. }
  194. lastdec = now;
  195. return timestamp;
  196. }
  197. void lowlevel_init(void)
  198. {
  199. }
  200. ulong get_board_rev(void){
  201. return readl((u32 *)SYS_ID);
  202. }