Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Atmel Corporation |
| 4 | * Bo Shen <voice.shen@atmel.com> |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/sama5d3_smc.h> |
| 12 | #include <asm/arch/at91_common.h> |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 13 | #include <asm/arch/at91_rstc.h> |
| 14 | #include <asm/arch/gpio.h> |
| 15 | #include <asm/arch/clk.h> |
Wenyou Yang | e46dd15 | 2017-04-14 08:51:47 +0800 | [diff] [blame] | 16 | #include <debug_uart.h> |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 17 | #include <spl.h> |
| 18 | #include <asm/arch/atmel_mpddrc.h> |
| 19 | #include <asm/arch/at91_wdt.h> |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Eugen Hristev | be01f77 | 2018-09-18 10:35:44 +0300 | [diff] [blame] | 23 | extern void at91_pda_detect(void); |
| 24 | |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 25 | #ifdef CONFIG_NAND_ATMEL |
| 26 | void sama5d3_xplained_nand_hw_init(void) |
| 27 | { |
| 28 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 29 | |
| 30 | at91_periph_clk_enable(ATMEL_ID_SMC); |
| 31 | |
| 32 | /* Configure SMC CS3 for NAND/SmartMedia */ |
| 33 | writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(1) | |
| 34 | AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(1), |
| 35 | &smc->cs[3].setup); |
| 36 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) | |
| 37 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(5), |
| 38 | &smc->cs[3].pulse); |
| 39 | writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8), |
| 40 | &smc->cs[3].cycle); |
| 41 | writel(AT91_SMC_TIMINGS_TCLR(3) | AT91_SMC_TIMINGS_TADL(10) | |
| 42 | AT91_SMC_TIMINGS_TAR(3) | AT91_SMC_TIMINGS_TRR(4) | |
| 43 | AT91_SMC_TIMINGS_TWB(5) | AT91_SMC_TIMINGS_RBNSEL(3)| |
| 44 | AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings); |
| 45 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 46 | AT91_SMC_MODE_EXNW_DISABLE | |
| 47 | #ifdef CONFIG_SYS_NAND_DBW_16 |
| 48 | AT91_SMC_MODE_DBW_16 | |
| 49 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
| 50 | AT91_SMC_MODE_DBW_8 | |
| 51 | #endif |
| 52 | AT91_SMC_MODE_TDF_CYCLE(3), |
| 53 | &smc->cs[3].mode); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | #ifdef CONFIG_CMD_USB |
| 58 | static void sama5d3_xplained_usb_hw_init(void) |
| 59 | { |
| 60 | at91_set_pio_output(AT91_PIO_PORTE, 3, 0); |
| 61 | at91_set_pio_output(AT91_PIO_PORTE, 4, 0); |
| 62 | } |
| 63 | #endif |
| 64 | |
| 65 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 66 | static void sama5d3_xplained_mci0_hw_init(void) |
| 67 | { |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 68 | at91_set_pio_output(AT91_PIO_PORTE, 2, 0); /* MCI0 Power */ |
| 69 | } |
| 70 | #endif |
| 71 | |
Wenyou Yang | e46dd15 | 2017-04-14 08:51:47 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 73 | void board_debug_uart_init(void) |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 74 | { |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 75 | at91_seriald_hw_init(); |
Wenyou Yang | e46dd15 | 2017-04-14 08:51:47 +0800 | [diff] [blame] | 76 | } |
| 77 | #endif |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 78 | |
Eugen Hristev | be01f77 | 2018-09-18 10:35:44 +0300 | [diff] [blame] | 79 | #ifdef CONFIG_BOARD_LATE_INIT |
| 80 | int board_late_init(void) |
| 81 | { |
| 82 | at91_pda_detect(); |
| 83 | return 0; |
| 84 | } |
| 85 | #endif |
| 86 | |
Wenyou Yang | e46dd15 | 2017-04-14 08:51:47 +0800 | [diff] [blame] | 87 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 88 | int board_early_init_f(void) |
| 89 | { |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
Wenyou Yang | e46dd15 | 2017-04-14 08:51:47 +0800 | [diff] [blame] | 92 | #endif |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 93 | |
| 94 | int board_init(void) |
| 95 | { |
| 96 | /* adress of boot parameters */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 97 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 98 | |
| 99 | #ifdef CONFIG_NAND_ATMEL |
| 100 | sama5d3_xplained_nand_hw_init(); |
| 101 | #endif |
| 102 | #ifdef CONFIG_CMD_USB |
| 103 | sama5d3_xplained_usb_hw_init(); |
| 104 | #endif |
| 105 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 106 | sama5d3_xplained_mci0_hw_init(); |
| 107 | #endif |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | int dram_init(void) |
| 112 | { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 113 | gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, |
| 114 | CFG_SYS_SDRAM_SIZE); |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 115 | |
Bo Shen | 06ce3f4 | 2014-02-09 15:52:39 +0800 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 119 | /* SPL */ |
| 120 | #ifdef CONFIG_SPL_BUILD |
| 121 | void spl_board_init(void) |
| 122 | { |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 123 | #ifdef CONFIG_SD_BOOT |
Wenyou Yang | 9ddd6fc | 2017-04-14 08:51:45 +0800 | [diff] [blame] | 124 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 125 | sama5d3_xplained_mci0_hw_init(); |
Wenyou Yang | 9ddd6fc | 2017-04-14 08:51:45 +0800 | [diff] [blame] | 126 | #endif |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 127 | #elif CONFIG_NAND_BOOT |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 128 | sama5d3_xplained_nand_hw_init(); |
| 129 | #endif |
| 130 | } |
| 131 | |
Michael Opdenacker | 6722614 | 2021-05-31 23:23:48 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_SPL_OS_BOOT |
| 133 | int spl_start_uboot(void) |
| 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | #endif |
| 138 | |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 139 | static void ddr2_conf(struct atmel_mpddrc_config *ddr2) |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 140 | { |
| 141 | ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM); |
| 142 | |
| 143 | ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | |
| 144 | ATMEL_MPDDRC_CR_NR_ROW_14 | |
| 145 | ATMEL_MPDDRC_CR_CAS_DDR_CAS3 | |
| 146 | ATMEL_MPDDRC_CR_ENRDM_ON | |
| 147 | ATMEL_MPDDRC_CR_NB_8BANKS | |
| 148 | ATMEL_MPDDRC_CR_NDQS_DISABLED | |
| 149 | ATMEL_MPDDRC_CR_DECOD_INTERLEAVED | |
| 150 | ATMEL_MPDDRC_CR_UNAL_SUPPORTED); |
| 151 | /* |
| 152 | * As the DDR2-SDRAm device requires a refresh time is 7.8125us |
| 153 | * when DDR run at 133MHz, so it needs (7.8125us * 133MHz / 10^9) clocks |
| 154 | */ |
| 155 | ddr2->rtr = 0x411; |
| 156 | |
| 157 | ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET | |
| 158 | 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET | |
| 159 | 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | |
| 160 | 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | |
| 161 | 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | |
| 162 | 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | |
| 163 | 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | |
| 164 | 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); |
| 165 | |
| 166 | ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | |
| 167 | 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET | |
| 168 | 28 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET | |
| 169 | 26 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET); |
| 170 | |
| 171 | ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET | |
| 172 | 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET | |
| 173 | 2 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET | |
| 174 | 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET | |
| 175 | 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET); |
| 176 | } |
| 177 | |
| 178 | void mem_init(void) |
| 179 | { |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 180 | struct atmel_mpddrc_config ddr2; |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 181 | |
| 182 | ddr2_conf(&ddr2); |
| 183 | |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 184 | /* Enable MPDDR clock */ |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 185 | at91_periph_clk_enable(ATMEL_ID_MPDDRC); |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 186 | at91_system_clk_enable(AT91_PMC_DDR); |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 187 | |
| 188 | /* DDRAM2 Controller initialize */ |
Erik van Luijk | 59d780a | 2015-08-13 15:43:18 +0200 | [diff] [blame] | 189 | ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2); |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void at91_pmc_init(void) |
| 193 | { |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 194 | u32 tmp; |
| 195 | |
| 196 | tmp = AT91_PMC_PLLAR_29 | |
| 197 | AT91_PMC_PLLXR_PLLCOUNT(0x3f) | |
| 198 | AT91_PMC_PLLXR_MUL(43) | |
| 199 | AT91_PMC_PLLXR_DIV(1); |
| 200 | at91_plla_init(tmp); |
| 201 | |
Wenyou Yang | 5265b1e | 2016-02-02 12:46:14 +0800 | [diff] [blame] | 202 | at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x3)); |
Bo Shen | 735ef1a | 2014-03-19 14:48:45 +0800 | [diff] [blame] | 203 | |
| 204 | tmp = AT91_PMC_MCKR_MDIV_4 | |
| 205 | AT91_PMC_MCKR_CSS_PLLA; |
| 206 | at91_mck_init(tmp); |
| 207 | } |
| 208 | #endif |