vexpress_common.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. * SPDX-License-Identifier: GPL-2.0+
  18. */
  19. #include <common.h>
  20. #include <malloc.h>
  21. #include <errno.h>
  22. #include <netdev.h>
  23. #include <asm/io.h>
  24. #include <asm/arch/systimer.h>
  25. #include <asm/arch/sysctrl.h>
  26. #include <asm/arch/wdt.h>
  27. #include "../drivers/mmc/arm_pl180_mmci.h"
  28. static struct systimer *systimer_base = (struct systimer *)V2M_TIMER01;
  29. static struct sysctrl *sysctrl_base = (struct sysctrl *)SCTL_BASE;
  30. static void flash__init(void);
  31. static void vexpress_timer_init(void);
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  34. void show_boot_progress(int progress)
  35. {
  36. printf("Boot reached stage %d\n", progress);
  37. }
  38. #endif
  39. static inline void delay(ulong loops)
  40. {
  41. __asm__ volatile ("1:\n"
  42. "subs %0, %1, #1\n"
  43. "bne 1b" : "=r" (loops) : "0" (loops));
  44. }
  45. int board_init(void)
  46. {
  47. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  48. gd->bd->bi_arch_number = MACH_TYPE_VEXPRESS;
  49. gd->flags = 0;
  50. icache_enable();
  51. flash__init();
  52. vexpress_timer_init();
  53. return 0;
  54. }
  55. int board_eth_init(bd_t *bis)
  56. {
  57. int rc = 0;
  58. #ifdef CONFIG_SMC911X
  59. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  60. #endif
  61. return rc;
  62. }
  63. int cpu_mmc_init(bd_t *bis)
  64. {
  65. int rc = 0;
  66. (void) bis;
  67. #ifdef CONFIG_ARM_PL180_MMCI
  68. struct pl180_mmc_host *host;
  69. host = malloc(sizeof(struct pl180_mmc_host));
  70. if (!host)
  71. return -ENOMEM;
  72. memset(host, 0, sizeof(*host));
  73. strcpy(host->name, "MMC");
  74. host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
  75. host->pwr_init = INIT_PWR;
  76. host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
  77. host->voltages = VOLTAGE_WINDOW_MMC;
  78. host->caps = 0;
  79. host->clock_in = ARM_MCLK;
  80. host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
  81. host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
  82. rc = arm_pl180_mmci_init(host);
  83. #endif
  84. return rc;
  85. }
  86. static void flash__init(void)
  87. {
  88. /* Setup the sytem control register to allow writing to flash */
  89. writel(readl(&sysctrl_base->scflashctrl) | VEXPRESS_FLASHPROG_FLVPPEN,
  90. &sysctrl_base->scflashctrl);
  91. }
  92. int dram_init(void)
  93. {
  94. gd->ram_size =
  95. get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, PHYS_SDRAM_1_SIZE);
  96. return 0;
  97. }
  98. void dram_init_banksize(void)
  99. {
  100. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  101. gd->bd->bi_dram[0].size =
  102. get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  103. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  104. gd->bd->bi_dram[1].size =
  105. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  106. }
  107. /*
  108. * Start timer:
  109. * Setup a 32 bit timer, running at 1KHz
  110. * Versatile Express Motherboard provides 1 MHz timer
  111. */
  112. static void vexpress_timer_init(void)
  113. {
  114. /*
  115. * Set clock frequency in system controller:
  116. * VEXPRESS_REFCLK is 32KHz
  117. * VEXPRESS_TIMCLK is 1MHz
  118. */
  119. writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
  120. SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
  121. readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
  122. /*
  123. * Set Timer0 to be:
  124. * Enabled, free running, no interrupt, 32-bit, wrapping
  125. */
  126. writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
  127. writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
  128. writel(SYSTIMER_EN | SYSTIMER_32BIT |
  129. readl(&systimer_base->timer0control),
  130. &systimer_base->timer0control);
  131. }
  132. int v2m_cfg_write(u32 devfn, u32 data)
  133. {
  134. /* Configuration interface broken? */
  135. u32 val;
  136. devfn |= SYS_CFG_START | SYS_CFG_WRITE;
  137. val = readl(V2M_SYS_CFGSTAT);
  138. writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
  139. writel(data, V2M_SYS_CFGDATA);
  140. writel(devfn, V2M_SYS_CFGCTRL);
  141. do {
  142. val = readl(V2M_SYS_CFGSTAT);
  143. } while (val == 0);
  144. return !!(val & SYS_CFG_ERR);
  145. }
  146. /* Use the ARM Watchdog System to cause reset */
  147. void reset_cpu(ulong addr)
  148. {
  149. if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
  150. printf("Unable to reboot\n");
  151. }
  152. void lowlevel_init(void)
  153. {
  154. }
  155. ulong get_board_rev(void){
  156. return readl((u32 *)SYS_ID);
  157. }
  158. #ifdef CONFIG_ARMV7_NONSEC
  159. /* Setting the address at which secondary cores start from.
  160. * Versatile Express uses one address for all cores, so ignore corenr
  161. */
  162. void smp_set_core_boot_addr(unsigned long addr, int corenr)
  163. {
  164. /* The SYSFLAGS register on VExpress needs to be cleared first
  165. * by writing to the next address, since any writes to the address
  166. * at offset 0 will only be ORed in
  167. */
  168. writel(~0, CONFIG_SYSFLAGS_ADDR + 4);
  169. writel(addr, CONFIG_SYSFLAGS_ADDR);
  170. }
  171. #endif