ca9x4_ct_vxp.c 5.2 KB

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