spl_atmel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013 Atmel Corporation
  4. * Bo Shen <voice.shen@atmel.com>
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/at91_common.h>
  9. #include <asm/arch/at91_pit.h>
  10. #include <asm/arch/at91_pmc.h>
  11. #include <asm/arch/at91_rstc.h>
  12. #include <asm/arch/at91_wdt.h>
  13. #include <asm/arch/clk.h>
  14. #include <spl.h>
  15. static void switch_to_main_crystal_osc(void)
  16. {
  17. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  18. u32 tmp;
  19. tmp = readl(&pmc->mor);
  20. tmp &= ~AT91_PMC_MOR_OSCOUNT(0xff);
  21. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  22. tmp |= AT91_PMC_MOR_MOSCEN;
  23. tmp |= AT91_PMC_MOR_OSCOUNT(8);
  24. tmp |= AT91_PMC_MOR_KEY(0x37);
  25. writel(tmp, &pmc->mor);
  26. while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCS))
  27. ;
  28. #if defined(CONFIG_SAMA5D2)
  29. /* Enable a measurement of the external oscillator */
  30. tmp = readl(&pmc->mcfr);
  31. tmp |= AT91_PMC_MCFR_CCSS_XTAL_OSC;
  32. tmp |= AT91_PMC_MCFR_RCMEAS;
  33. writel(tmp, &pmc->mcfr);
  34. while (!(readl(&pmc->mcfr) & AT91_PMC_MCFR_MAINRDY))
  35. ;
  36. if (!(readl(&pmc->mcfr) & AT91_PMC_MCFR_MAINF_MASK))
  37. hang();
  38. #endif
  39. tmp = readl(&pmc->mor);
  40. tmp &= ~AT91_PMC_MOR_OSCBYPASS;
  41. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  42. tmp |= AT91_PMC_MOR_KEY(0x37);
  43. writel(tmp, &pmc->mor);
  44. tmp = readl(&pmc->mor);
  45. tmp |= AT91_PMC_MOR_MOSCSEL;
  46. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  47. tmp |= AT91_PMC_MOR_KEY(0x37);
  48. writel(tmp, &pmc->mor);
  49. while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCSELS))
  50. ;
  51. #if !defined(CONFIG_SAMA5D2)
  52. /* Wait until MAINRDY field is set to make sure main clock is stable */
  53. while (!(readl(&pmc->mcfr) & AT91_PMC_MAINRDY))
  54. ;
  55. #endif
  56. #if !defined(CONFIG_SAMA5D4) && !defined(CONFIG_SAMA5D2)
  57. tmp = readl(&pmc->mor);
  58. tmp &= ~AT91_PMC_MOR_MOSCRCEN;
  59. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  60. tmp |= AT91_PMC_MOR_KEY(0x37);
  61. writel(tmp, &pmc->mor);
  62. #endif
  63. }
  64. __weak void matrix_init(void)
  65. {
  66. /* This only be used for sama5d4 soc now */
  67. }
  68. __weak void redirect_int_from_saic_to_aic(void)
  69. {
  70. /* This only be used for sama5d4 soc now */
  71. }
  72. /* empty stub to satisfy current lowlevel_init, can be removed any time */
  73. void s_init(void)
  74. {
  75. }
  76. void board_init_f(ulong dummy)
  77. {
  78. int ret;
  79. switch_to_main_crystal_osc();
  80. #ifdef CONFIG_SAMA5D2
  81. configure_2nd_sram_as_l2_cache();
  82. #endif
  83. #if !defined(CONFIG_WDT_AT91)
  84. /* disable watchdog */
  85. at91_disable_wdt();
  86. #endif
  87. /* PMC configuration */
  88. at91_pmc_init();
  89. at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
  90. matrix_init();
  91. redirect_int_from_saic_to_aic();
  92. timer_init();
  93. board_early_init_f();
  94. mem_init();
  95. ret = spl_init();
  96. if (ret) {
  97. debug("spl_init() failed: %d\n", ret);
  98. hang();
  99. }
  100. preloader_console_init();
  101. }