spl_atmel.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. tmp = readl(&pmc->mor);
  46. tmp &= ~AT91_PMC_MOR_MOSCRCEN;
  47. tmp &= ~AT91_PMC_MOR_KEY(0xff);
  48. tmp |= AT91_PMC_MOR_KEY(0x37);
  49. writel(tmp, &pmc->mor);
  50. }
  51. void s_init(void)
  52. {
  53. switch_to_main_crystal_osc();
  54. /* disable watchdog */
  55. at91_disable_wdt();
  56. /* PMC configuration */
  57. at91_pmc_init();
  58. at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
  59. timer_init();
  60. board_early_init_f();
  61. preloader_console_init();
  62. mem_init();
  63. }