vexpress_common.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  5. * Marius Groeger <mgroeger@sysgo.de>
  6. *
  7. * (C) Copyright 2002
  8. * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
  9. *
  10. * (C) Copyright 2003
  11. * Texas Instruments, <www.ti.com>
  12. * Kshitij Gupta <Kshitij@ti.com>
  13. *
  14. * (C) Copyright 2004
  15. * ARM Ltd.
  16. * Philippe Robin, <philippe.robin@arm.com>
  17. */
  18. #include <common.h>
  19. #include <malloc.h>
  20. #include <errno.h>
  21. #include <netdev.h>
  22. #include <asm/io.h>
  23. #include <asm/mach-types.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. struct mmc *mmc;
  70. host = malloc(sizeof(struct pl180_mmc_host));
  71. if (!host)
  72. return -ENOMEM;
  73. memset(host, 0, sizeof(*host));
  74. strcpy(host->name, "MMC");
  75. host->base = (struct sdi_registers *)CONFIG_ARM_PL180_MMCI_BASE;
  76. host->pwr_init = INIT_PWR;
  77. host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V1 | SDI_CLKCR_CLKEN;
  78. host->voltages = VOLTAGE_WINDOW_MMC;
  79. host->caps = 0;
  80. host->clock_in = ARM_MCLK;
  81. host->clock_min = ARM_MCLK / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1));
  82. host->clock_max = CONFIG_ARM_PL180_MMCI_CLOCK_FREQ;
  83. rc = arm_pl180_mmci_init(host, &mmc);
  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. int 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. return 0;
  108. }
  109. /*
  110. * Start timer:
  111. * Setup a 32 bit timer, running at 1KHz
  112. * Versatile Express Motherboard provides 1 MHz timer
  113. */
  114. static void vexpress_timer_init(void)
  115. {
  116. /*
  117. * Set clock frequency in system controller:
  118. * VEXPRESS_REFCLK is 32KHz
  119. * VEXPRESS_TIMCLK is 1MHz
  120. */
  121. writel(SP810_TIMER0_ENSEL | SP810_TIMER1_ENSEL |
  122. SP810_TIMER2_ENSEL | SP810_TIMER3_ENSEL |
  123. readl(&sysctrl_base->scctrl), &sysctrl_base->scctrl);
  124. /*
  125. * Set Timer0 to be:
  126. * Enabled, free running, no interrupt, 32-bit, wrapping
  127. */
  128. writel(SYSTIMER_RELOAD, &systimer_base->timer0load);
  129. writel(SYSTIMER_RELOAD, &systimer_base->timer0value);
  130. writel(SYSTIMER_EN | SYSTIMER_32BIT |
  131. readl(&systimer_base->timer0control),
  132. &systimer_base->timer0control);
  133. }
  134. int v2m_cfg_write(u32 devfn, u32 data)
  135. {
  136. /* Configuration interface broken? */
  137. u32 val;
  138. devfn |= SYS_CFG_START | SYS_CFG_WRITE;
  139. val = readl(V2M_SYS_CFGSTAT);
  140. writel(val & ~SYS_CFG_COMPLETE, V2M_SYS_CFGSTAT);
  141. writel(data, V2M_SYS_CFGDATA);
  142. writel(devfn, V2M_SYS_CFGCTRL);
  143. do {
  144. val = readl(V2M_SYS_CFGSTAT);
  145. } while (val == 0);
  146. return !!(val & SYS_CFG_ERR);
  147. }
  148. /* Use the ARM Watchdog System to cause reset */
  149. void reset_cpu(ulong addr)
  150. {
  151. if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
  152. printf("Unable to reboot\n");
  153. }
  154. void lowlevel_init(void)
  155. {
  156. }
  157. ulong get_board_rev(void){
  158. return readl((u32 *)SYS_ID);
  159. }
  160. #ifdef CONFIG_ARMV7_NONSEC
  161. /* Setting the address at which secondary cores start from.
  162. * Versatile Express uses one address for all cores, so ignore corenr
  163. */
  164. void smp_set_core_boot_addr(unsigned long addr, int corenr)
  165. {
  166. /* The SYSFLAGS register on VExpress needs to be cleared first
  167. * by writing to the next address, since any writes to the address
  168. * at offset 0 will only be ORed in
  169. */
  170. writel(~0, CONFIG_SYSFLAGS_ADDR + 4);
  171. writel(addr, CONFIG_SYSFLAGS_ADDR);
  172. }
  173. #endif