Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Atmel Corporation |
| 3 | * Bo Shen <voice.shen@atmel.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/at91_common.h> |
| 11 | #include <asm/arch/at91_pit.h> |
| 12 | #include <asm/arch/at91_pmc.h> |
| 13 | #include <asm/arch/at91_rstc.h> |
| 14 | #include <asm/arch/at91_wdt.h> |
| 15 | #include <asm/arch/clk.h> |
| 16 | #include <spl.h> |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | static void switch_to_main_crystal_osc(void) |
| 21 | { |
| 22 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 23 | u32 tmp; |
| 24 | |
| 25 | tmp = readl(&pmc->mor); |
| 26 | tmp &= ~AT91_PMC_MOR_OSCOUNT(0xff); |
| 27 | tmp &= ~AT91_PMC_MOR_KEY(0xff); |
| 28 | tmp |= AT91_PMC_MOR_MOSCEN; |
| 29 | tmp |= AT91_PMC_MOR_OSCOUNT(8); |
| 30 | tmp |= AT91_PMC_MOR_KEY(0x37); |
| 31 | writel(tmp, &pmc->mor); |
| 32 | while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCS)) |
| 33 | ; |
| 34 | |
| 35 | tmp = readl(&pmc->mor); |
| 36 | tmp &= ~AT91_PMC_MOR_OSCBYPASS; |
| 37 | tmp &= ~AT91_PMC_MOR_KEY(0xff); |
| 38 | tmp |= AT91_PMC_MOR_KEY(0x37); |
| 39 | writel(tmp, &pmc->mor); |
| 40 | |
| 41 | tmp = readl(&pmc->mor); |
| 42 | tmp |= AT91_PMC_MOR_MOSCSEL; |
| 43 | tmp &= ~AT91_PMC_MOR_KEY(0xff); |
| 44 | tmp |= AT91_PMC_MOR_KEY(0x37); |
| 45 | writel(tmp, &pmc->mor); |
| 46 | |
| 47 | while (!(readl(&pmc->sr) & AT91_PMC_IXR_MOSCSELS)) |
| 48 | ; |
| 49 | |
| 50 | /* Wait until MAINRDY field is set to make sure main clock is stable */ |
| 51 | while (!(readl(&pmc->mcfr) & AT91_PMC_MAINRDY)) |
| 52 | ; |
| 53 | |
Bo Shen | 0246b7c | 2014-12-15 13:24:32 +0800 | [diff] [blame] | 54 | #ifndef CONFIG_SAMA5D4 |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 55 | tmp = readl(&pmc->mor); |
| 56 | tmp &= ~AT91_PMC_MOR_MOSCRCEN; |
| 57 | tmp &= ~AT91_PMC_MOR_KEY(0xff); |
| 58 | tmp |= AT91_PMC_MOR_KEY(0x37); |
| 59 | writel(tmp, &pmc->mor); |
Bo Shen | 0246b7c | 2014-12-15 13:24:32 +0800 | [diff] [blame] | 60 | #endif |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Bo Shen | 433be90 | 2014-12-15 13:24:30 +0800 | [diff] [blame] | 63 | __weak void matrix_init(void) |
| 64 | { |
| 65 | /* This only be used for sama5d4 soc now */ |
| 66 | } |
| 67 | |
Bo Shen | 4514b5f | 2014-12-15 13:24:31 +0800 | [diff] [blame] | 68 | __weak void redirect_int_from_saic_to_aic(void) |
| 69 | { |
| 70 | /* This only be used for sama5d4 soc now */ |
| 71 | } |
| 72 | |
Tom Rini | e755d54 | 2015-02-10 19:07:22 -0500 | [diff] [blame] | 73 | /* empty stub to satisfy current lowlevel_init, can be removed any time */ |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 74 | void s_init(void) |
| 75 | { |
Tom Rini | e755d54 | 2015-02-10 19:07:22 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void board_init_f(ulong dummy) |
| 79 | { |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 80 | switch_to_main_crystal_osc(); |
| 81 | |
Samuel Mescoff | f7cf291 | 2016-02-16 09:45:06 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_SAMA5D2 |
| 83 | configure_2nd_sram_as_l2_cache(); |
| 84 | #endif |
| 85 | |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 86 | /* disable watchdog */ |
| 87 | at91_disable_wdt(); |
| 88 | |
| 89 | /* PMC configuration */ |
| 90 | at91_pmc_init(); |
| 91 | |
| 92 | at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK); |
| 93 | |
Bo Shen | 433be90 | 2014-12-15 13:24:30 +0800 | [diff] [blame] | 94 | matrix_init(); |
| 95 | |
Bo Shen | 4514b5f | 2014-12-15 13:24:31 +0800 | [diff] [blame] | 96 | redirect_int_from_saic_to_aic(); |
| 97 | |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 98 | timer_init(); |
| 99 | |
| 100 | board_early_init_f(); |
| 101 | |
| 102 | preloader_console_init(); |
| 103 | |
| 104 | mem_init(); |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 105 | } |