vexpress_common.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <malloc.h>
  37. #include <errno.h>
  38. #include <netdev.h>
  39. #include <asm/io.h>
  40. #include <asm/arch/systimer.h>
  41. #include <asm/arch/sysctrl.h>
  42. #include <asm/arch/wdt.h>
  43. #include "../drivers/mmc/arm_pl180_mmci.h"
  44. static ulong timestamp;
  45. static ulong lastdec;
  46. static struct systimer *systimer_base = (struct systimer *)V2M_TIMER01;
  47. static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
  48. static void flash__init(void);
  49. static void vexpress_timer_init(void);
  50. DECLARE_GLOBAL_DATA_PTR;
  51. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  52. void show_boot_progress(int progress)
  53. {
  54. printf("Boot reached stage %d\n", progress);
  55. }
  56. #endif
  57. static inline void delay(ulong loops)
  58. {
  59. __asm__ volatile ("1:\n"
  60. "subs %0, %1, #1\n"
  61. "bne 1b" : "=r" (loops) : "0" (loops));
  62. }
  63. int board_init(void)
  64. {
  65. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  66. gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
  67. gd->flags = 0;
  68. icache_enable();
  69. flash__init();
  70. vexpress_timer_init();
  71. return 0;
  72. }
  73. int board_eth_init(bd_t *bis)
  74. {
  75. int rc = 0;
  76. #ifdef CONFIG_SMC911X
  77. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  78. #endif
  79. return rc;
  80. }
  81. int cpu_mmc_init(bd_t *bis)
  82. {
  83. int rc = 0;
  84. (void) bis;
  85. #ifdef CONFIG_ARM_PL180_MMCI
  86. struct pl180_mmc_host *host;
  87. host = malloc(sizeof(struct pl180_mmc_host));
  88. if (!host)
  89. return -ENOMEM;
  90. memset(host, 0, sizeof(*host));
  91. strcpy(host->name, "MMC");
  92. host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
  93. host->pwr_init = INIT_PWR;
  94. host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
  95. host->voltages = VOLTAGE_WINDOW_MMC;
  96. host->caps = 0;
  97. host->clock_in = ARM_MCLK;
  98. host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
  99. host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
  100. rc = arm_pl180_mmci_init(host);
  101. #endif
  102. return rc;
  103. }
  104. static void flash__init(void)
  105. {
  106. /* Setup the sytem control register to allow writing to flash */
  107. writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
  108. &sysctrl_base->scflashctrl);
  109. }
  110. int dram_init(void)
  111. {
  112. gd->ram_size =
  113. get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
  114. return 0;
  115. }
  116. void dram_init_banksize(void)
  117. {
  118. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  119. gd->bd->bi_dram[0].size =
  120. get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  121. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  122. gd->bd->bi_dram[1].size =
  123. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  124. }
  125. int timer_init(void)
  126. {
  127. return 0;
  128. }
  129. /*
  130. * Start timer:
  131. * Setup a 32 bit timer, running at 1KHz
  132. * Versatile Express Motherboard provides 1 MHz timer
  133. */
  134. static void vexpress_timer_init(void)
  135. {
  136. /*
  137. * Set clock frequency in system controller:
  138. * VEXPRESS_REFCLK is 32KHz
  139. * VEXPRESS_TIMCLK is 1MHz
  140. */
  141. writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
  142. SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
  143. readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
  144. /*
  145. * Set Timer0 to be:
  146. * Enabled, free running, no interrupt, 32-bit, wrapping
  147. */
  148. writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
  149. writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
  150. writel(SYSTIMER_EN | SYSTIMER_32BIT |
  151. readl(&systimer_base->timer0control),
  152. &systimer_base->timer0control);
  153. reset_timer_masked();
  154. }
  155. int v2m_cfg_write(u32 devfn, u32 data)
  156. {
  157. /* Configuration interface broken? */
  158. u32 val;
  159. devfn |= SYS_CFG_START | SYS_CFG_WRITE;
  160. val = readl(V2M_SYS_CFGSTAT);
  161. writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
  162. writel(data, V2M_SYS_CFGDATA);
  163. writel(devfn, V2M_SYS_CFGCTRL);
  164. do {
  165. val = readl(V2M_SYS_CFGSTAT);
  166. } while (val == 0);
  167. return !!(val & SYS_CFG_ERR);
  168. }
  169. /* Use the ARM Watchdog System to cause reset */
  170. void reset_cpu(ulong addr)
  171. {
  172. if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
  173. printf("Unable to reboot\n");
  174. }
  175. /*
  176. * Delay x useconds AND perserve advance timstamp value
  177. * assumes timer is ticking at 1 msec
  178. */
  179. void __udelay(ulong usec)
  180. {
  181. ulong tmo, tmp;
  182. tmo = usec / 1000;
  183. tmp = get_timer(0); /* get current timestamp */
  184. /*
  185. * If setting this forward will roll time stamp then
  186. * reset "advancing" timestamp to 0 and set lastdec value
  187. * otherwise set the advancing stamp to the wake up time
  188. */
  189. if ((tmo + tmp + 1) < tmp)
  190. reset_timer_masked();
  191. else
  192. tmo += tmp;
  193. while (get_timer_masked() < tmo)
  194. ; /* loop till wakeup event */
  195. }
  196. ulong get_timer(ulong base)
  197. {
  198. return get_timer_masked() - base;
  199. }
  200. void reset_timer_masked(void)
  201. {
  202. lastdec = readl(&systimer_base->timer0value) / 1000;
  203. timestamp = 0;
  204. }
  205. ulong get_timer_masked(void)
  206. {
  207. ulong now = readl(&systimer_base->timer0value) / 1000;
  208. if (lastdec >= now) { /* normal mode (non roll) */
  209. timestamp += lastdec - now;
  210. } else { /* count down timer overflowed */
  211. /*
  212. * nts = ts + ld - now
  213. * ts = old stamp, ld = time before passing through - 1
  214. * now = amount of time after passing though - 1
  215. * nts = new "advancing time stamp"
  216. */
  217. timestamp += lastdec + SYSTIMER_RELOAD - now;
  218. }
  219. lastdec = now;
  220. return timestamp;
  221. }
  222. void lowlevel_init(void)
  223. {
  224. }
  225. ulong get_board_rev(void){
  226. return readl((u32 *)SYS_ID);
  227. }
  228. unsigned long long get_ticks(void)
  229. {
  230. return get_timer(0);
  231. }
  232. ulong get_tbclk(void)
  233. {
  234. return (ulong)CONFIG_SYS_HZ;
  235. }