spl_at91.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014 DENX Software Engineering
  4. * Heiko Schocher <hs@denx.de>
  5. *
  6. * Based on:
  7. * Copyright (C) 2013 Atmel Corporation
  8. * Bo Shen <voice.shen@atmel.com>
  9. */
  10. #include <common.h>
  11. #include <hang.h>
  12. #include <init.h>
  13. #include <log.h>
  14. #include <asm/global_data.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/at91_common.h>
  17. #include <asm/arch/at91sam9_matrix.h>
  18. #include <asm/arch/at91_pit.h>
  19. #include <asm/arch/at91_rstc.h>
  20. #include <asm/arch/at91_wdt.h>
  21. #include <asm/arch/clk.h>
  22. #include <spl.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. static void enable_ext_reset(void)
  25. {
  26. struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
  27. writel(AT91_RSTC_KEY | AT91_RSTC_MR_URSTEN, &rstc->mr);
  28. }
  29. void lowlevel_clock_init(void)
  30. {
  31. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  32. if (!(readl(&pmc->sr) & AT91_PMC_MOSCS)) {
  33. /* Enable Main Oscillator */
  34. writel(AT91_PMC_MOSCS | (0x40 << 8), &pmc->mor);
  35. /* Wait until Main Oscillator is stable */
  36. while (!(readl(&pmc->sr) & AT91_PMC_MOSCS))
  37. ;
  38. }
  39. /* After stabilization, switch to Main Oscillator */
  40. if ((readl(&pmc->mckr) & AT91_PMC_CSS) == AT91_PMC_CSS_SLOW) {
  41. unsigned long tmp;
  42. tmp = readl(&pmc->mckr);
  43. tmp &= ~AT91_PMC_CSS;
  44. tmp |= AT91_PMC_CSS_MAIN;
  45. writel(tmp, &pmc->mckr);
  46. while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY))
  47. ;
  48. tmp &= ~AT91_PMC_PRES;
  49. tmp |= AT91_PMC_PRES_1;
  50. writel(tmp, &pmc->mckr);
  51. while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY))
  52. ;
  53. }
  54. return;
  55. }
  56. void __weak matrix_init(void)
  57. {
  58. }
  59. void __weak at91_spl_board_init(void)
  60. {
  61. }
  62. void __weak spl_board_init(void)
  63. {
  64. }
  65. void board_init_f(ulong dummy)
  66. {
  67. #if CONFIG_IS_ENABLED(OF_CONTROL)
  68. int ret;
  69. ret = spl_early_init();
  70. if (ret) {
  71. debug("spl_early_init() failed: %d\n", ret);
  72. hang();
  73. }
  74. #endif
  75. lowlevel_clock_init();
  76. #if !defined(CONFIG_WDT_AT91)
  77. at91_disable_wdt();
  78. #endif
  79. /*
  80. * At this stage the main oscillator is supposed to be enabled
  81. * PCK = MCK = MOSC
  82. */
  83. at91_pllicpr_init(0x00);
  84. /* Configure PLLA = MOSC * (PLL_MULA + 1) / PLL_DIVA */
  85. at91_plla_init(CONFIG_SYS_AT91_PLLA);
  86. /* PCK = PLLA = 2 * MCK */
  87. at91_mck_init(CONFIG_SYS_MCKR);
  88. /* Switch MCK on PLLA output */
  89. at91_mck_init(CONFIG_SYS_MCKR_CSS);
  90. #if defined(CONFIG_SYS_AT91_PLLB)
  91. /* Configure PLLB */
  92. at91_pllb_init(CONFIG_SYS_AT91_PLLB);
  93. #endif
  94. /* Enable External Reset */
  95. enable_ext_reset();
  96. /* Initialize matrix */
  97. matrix_init();
  98. gd->arch.mck_rate_hz = CONFIG_SYS_MASTER_CLOCK;
  99. /*
  100. * init timer long enough for using in spl.
  101. */
  102. timer_init();
  103. /* enable clocks for all PIOs */
  104. #if defined(CONFIG_AT91SAM9X5) || defined(CONFIG_AT91SAM9N12)
  105. at91_periph_clk_enable(ATMEL_ID_PIOAB);
  106. at91_periph_clk_enable(ATMEL_ID_PIOCD);
  107. #else
  108. at91_periph_clk_enable(ATMEL_ID_PIOA);
  109. at91_periph_clk_enable(ATMEL_ID_PIOB);
  110. at91_periph_clk_enable(ATMEL_ID_PIOC);
  111. #endif
  112. #if defined(CONFIG_SPL_SERIAL_SUPPORT)
  113. /* init console */
  114. at91_seriald_hw_init();
  115. preloader_console_init();
  116. #endif
  117. mem_init();
  118. at91_spl_board_init();
  119. }