spl_atmel.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2013 Atmel Corporation
  3. * Bo Shen <voice.shen@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/at91_pit.h>
  11. #include <asm/arch/at91_pmc.h>
  12. #include <asm/arch/at91_rstc.h>
  13. #include <asm/arch/at91_wdt.h>
  14. #include <asm/arch/clk.h>
  15. #include <spl.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static void switch_to_main_crystal_osc(void)
  18. {
  19. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  20. u32 tmp;
  21. tmp = readl(&pmc->mor);
  22. tmp &= ~AT91_PMC_MOR_OSCOUNT(0xff);
  23. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  24. tmp |= AT91_PMC_MOR_MOSCEN;
  25. tmp |= AT91_PMC_MOR_OSCOUNT(8);
  26. tmp |= AT91_PMC_MOR_KEY(0x37);
  27. writel(tmp, &pmc->mor);
  28. while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCS))
  29. ;
  30. tmp = readl(&pmc->mor);
  31. tmp &= ~AT91_PMC_MOR_OSCBYPASS;
  32. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  33. tmp |= AT91_PMC_MOR_KEY(0x37);
  34. writel(tmp, &pmc->mor);
  35. tmp = readl(&pmc->mor);
  36. tmp |= AT91_PMC_MOR_MOSCSEL;
  37. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  38. tmp |= AT91_PMC_MOR_KEY(0x37);
  39. writel(tmp, &pmc->mor);
  40. while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCSELS))
  41. ;
  42. /* Wait until MAINRDY field is set to make sure main clock is stable */
  43. while (!(readl(&pmc->mcfr) & AT91_PMC_MAINRDY))
  44. ;
  45. #ifndef CONFIG_SAMA5D4
  46. tmp = readl(&pmc->mor);
  47. tmp &= ~AT91_PMC_MOR_MOSCRCEN;
  48. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  49. tmp |= AT91_PMC_MOR_KEY(0x37);
  50. writel(tmp, &pmc->mor);
  51. #endif
  52. }
  53. __weak void matrix_init(void)
  54. {
  55. /* This only be used for sama5d4 soc now */
  56. }
  57. __weak void redirect_int_from_saic_to_aic(void)
  58. {
  59. /* This only be used for sama5d4 soc now */
  60. }
  61. /* empty stub to satisfy current lowlevel_init, can be removed any time */
  62. void s_init(void)
  63. {
  64. }
  65. void board_init_f(ulong dummy)
  66. {
  67. switch_to_main_crystal_osc();
  68. /* disable watchdog */
  69. at91_disable_wdt();
  70. /* PMC configuration */
  71. at91_pmc_init();
  72. at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
  73. matrix_init();
  74. redirect_int_from_saic_to_aic();
  75. timer_init();
  76. board_early_init_f();
  77. preloader_console_init();
  78. mem_init();
  79. /* Clear the BSS. */
  80. memset(__bss_start, 0, __bss_end - __bss_start);
  81. board_init_r(NULL, 0);
  82. }