ca9x4_ct_vxp.c 5.1 KB

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