Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [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_pmc.h> |
| 12 | #include <asm/arch/at91_wdt.h> |
| 13 | #include <asm/arch/clk.h> |
| 14 | #include <spl.h> |
| 15 | |
| 16 | static void at91_disable_wdt(void) |
| 17 | { |
| 18 | struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT; |
| 19 | |
| 20 | writel(AT91_WDT_MR_WDDIS, &wdt->mr); |
| 21 | } |
| 22 | |
| 23 | void at91_plla_init(u32 pllar) |
| 24 | { |
| 25 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 26 | |
| 27 | writel(pllar, &pmc->pllar); |
| 28 | while (!(readl(&pmc->sr) & (AT91_PMC_LOCKA | AT91_PMC_MCKRDY))) |
| 29 | ; |
| 30 | } |
| 31 | |
| 32 | void at91_mck_init(u32 mckr) |
| 33 | { |
| 34 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 35 | u32 tmp; |
| 36 | |
| 37 | tmp = readl(&pmc->mckr); |
| 38 | tmp &= ~(AT91_PMC_MCKR_PRES_MASK | |
| 39 | AT91_PMC_MCKR_MDIV_MASK | |
| 40 | AT91_PMC_MCKR_PLLADIV_2); |
| 41 | tmp |= mckr & (AT91_PMC_MCKR_PRES_MASK | |
| 42 | AT91_PMC_MCKR_MDIV_MASK | |
| 43 | AT91_PMC_MCKR_PLLADIV_2); |
| 44 | writel(tmp, &pmc->mckr); |
| 45 | |
| 46 | while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY)) |
| 47 | ; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | u32 spl_boot_device(void) |
| 52 | { |
| 53 | #ifdef CONFIG_SYS_USE_MMC |
| 54 | return BOOT_DEVICE_MMC1; |
Bo Shen | 27019e4 | 2014-03-03 14:47:17 +0800 | [diff] [blame^] | 55 | #elif CONFIG_SYS_USE_NANDFLASH |
| 56 | return BOOT_DEVICE_NAND; |
Bo Shen | 8a45b0b | 2014-03-03 14:47:15 +0800 | [diff] [blame] | 57 | #elif CONFIG_SYS_USE_SERIALFLASH |
| 58 | return BOOT_DEVICE_SPI; |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 59 | #endif |
| 60 | return BOOT_DEVICE_NONE; |
| 61 | } |
| 62 | |
| 63 | u32 spl_boot_mode(void) |
| 64 | { |
| 65 | switch (spl_boot_device()) { |
| 66 | #ifdef CONFIG_SYS_USE_MMC |
| 67 | case BOOT_DEVICE_MMC1: |
| 68 | return MMCSD_MODE_FAT; |
| 69 | break; |
| 70 | #endif |
| 71 | case BOOT_DEVICE_NONE: |
| 72 | default: |
| 73 | hang(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void s_init(void) |
| 78 | { |
| 79 | /* disable watchdog */ |
| 80 | at91_disable_wdt(); |
| 81 | |
| 82 | /* PMC configuration */ |
| 83 | at91_pmc_init(); |
| 84 | |
| 85 | at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK); |
| 86 | |
| 87 | timer_init(); |
| 88 | |
| 89 | board_early_init_f(); |
| 90 | |
| 91 | preloader_console_init(); |
| 92 | |
| 93 | mem_init(); |
| 94 | } |