spl_at91.c 2.7 KB

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