Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Atmel Corporation |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/at91sam9x5_matrix.h> |
| 11 | #include <asm/arch/at91sam9_smc.h> |
| 12 | #include <asm/arch/at91_common.h> |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 13 | #include <asm/arch/at91_rstc.h> |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 14 | #include <asm/arch/clk.h> |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 15 | #include <asm/arch/gpio.h> |
Wenyou Yang | a9606f0 | 2017-04-18 14:51:56 +0800 | [diff] [blame] | 16 | #include <debug_uart.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 17 | #include <asm/mach-types.h> |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | /* ------------------------------------------------------------------------- */ |
| 22 | /* |
| 23 | * Miscelaneous platform dependent initialisations |
| 24 | */ |
Eugen Hristev | 3232f9b | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 25 | |
| 26 | void at91_prepare_cpu_var(void); |
| 27 | |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 28 | #ifdef CONFIG_CMD_NAND |
| 29 | static void at91sam9x5ek_nand_hw_init(void) |
| 30 | { |
| 31 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 32 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 33 | unsigned long csa; |
| 34 | |
| 35 | /* Enable CS3 */ |
| 36 | csa = readl(&matrix->ebicsa); |
| 37 | csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA; |
Bo Shen | 68df918 | 2012-08-15 18:44:27 +0000 | [diff] [blame] | 38 | /* NAND flash on D16 */ |
| 39 | csa |= AT91_MATRIX_NFD0_ON_D16; |
Wu, Josh | ccae57a | 2012-09-05 22:14:28 +0000 | [diff] [blame] | 40 | |
| 41 | /* Configure IO drive */ |
| 42 | csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL; |
| 43 | |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 44 | writel(csa, &matrix->ebicsa); |
| 45 | |
| 46 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Wu, Josh | e333036 | 2012-08-23 00:05:37 +0000 | [diff] [blame] | 47 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 48 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 49 | &smc->cs[3].setup); |
Wu, Josh | e333036 | 2012-08-23 00:05:37 +0000 | [diff] [blame] | 50 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) | |
| 51 | AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6), |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 52 | &smc->cs[3].pulse); |
Wu, Josh | e333036 | 2012-08-23 00:05:37 +0000 | [diff] [blame] | 53 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(6), |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 54 | &smc->cs[3].cycle); |
| 55 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 56 | AT91_SMC_MODE_EXNW_DISABLE | |
| 57 | #ifdef CONFIG_SYS_NAND_DBW_16 |
| 58 | AT91_SMC_MODE_DBW_16 | |
| 59 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
| 60 | AT91_SMC_MODE_DBW_8 | |
| 61 | #endif |
Wu, Josh | e333036 | 2012-08-23 00:05:37 +0000 | [diff] [blame] | 62 | AT91_SMC_MODE_TDF_CYCLE(1), |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 63 | &smc->cs[3].mode); |
| 64 | |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 65 | at91_periph_clk_enable(ATMEL_ID_PIOCD); |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 66 | |
| 67 | /* Configure RDY/BSY */ |
Tom Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 68 | at91_set_gpio_input(CFG_SYS_NAND_READY_PIN, 1); |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 69 | /* Enable NandFlash */ |
Tom Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 70 | at91_set_gpio_output(CFG_SYS_NAND_ENABLE_PIN, 1); |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 71 | |
Wenyou Yang | 4a92a3e | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 72 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */ |
| 73 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */ |
| 74 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* NAND ALE */ |
| 75 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* NAND CLE */ |
| 76 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1); |
| 77 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1); |
| 78 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1); |
| 79 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1); |
| 80 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1); |
| 81 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1); |
| 82 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1); |
| 83 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1); |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 84 | } |
| 85 | #endif |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 86 | |
Wenyou Yang | aa02353 | 2017-09-18 15:26:01 +0800 | [diff] [blame] | 87 | #ifdef CONFIG_BOARD_LATE_INIT |
| 88 | int board_late_init(void) |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 89 | { |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 90 | #ifdef CONFIG_VIDEO |
Wenyou Yang | aa02353 | 2017-09-18 15:26:01 +0800 | [diff] [blame] | 91 | at91_video_show_board_info(); |
| 92 | #endif |
Eugen Hristev | 3232f9b | 2018-10-08 09:54:27 +0300 | [diff] [blame] | 93 | at91_prepare_cpu_var(); |
Wenyou Yang | aa02353 | 2017-09-18 15:26:01 +0800 | [diff] [blame] | 94 | return 0; |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 95 | } |
Wenyou Yang | aa02353 | 2017-09-18 15:26:01 +0800 | [diff] [blame] | 96 | #endif |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 97 | |
Wenyou Yang | a9606f0 | 2017-04-18 14:51:56 +0800 | [diff] [blame] | 98 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 99 | void board_debug_uart_init(void) |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 100 | { |
| 101 | at91_seriald_hw_init(); |
Wenyou Yang | a9606f0 | 2017-04-18 14:51:56 +0800 | [diff] [blame] | 102 | } |
| 103 | #endif |
| 104 | |
| 105 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 106 | int board_early_init_f(void) |
| 107 | { |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 108 | return 0; |
| 109 | } |
Wenyou Yang | a9606f0 | 2017-04-18 14:51:56 +0800 | [diff] [blame] | 110 | #endif |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 111 | |
| 112 | int board_init(void) |
| 113 | { |
Tom Rini | 4815734 | 2017-01-25 20:42:35 -0500 | [diff] [blame] | 114 | /* arch number of AT91SAM9X5EK-Board */ |
| 115 | gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9X5EK; |
| 116 | |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 117 | /* adress of boot parameters */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 118 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 119 | |
| 120 | #ifdef CONFIG_CMD_NAND |
| 121 | at91sam9x5ek_nand_hw_init(); |
| 122 | #endif |
| 123 | |
Tom Rini | ceed5d2 | 2017-05-12 22:33:27 -0400 | [diff] [blame] | 124 | #if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD) |
Richard Genoud | b762a9c | 2012-11-29 23:18:32 +0000 | [diff] [blame] | 125 | at91_uhp_hw_init(); |
| 126 | #endif |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | int dram_init(void) |
| 131 | { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 132 | gd->ram_size = get_ram_size((void *) CFG_SYS_SDRAM_BASE, |
| 133 | CFG_SYS_SDRAM_SIZE); |
Bo Shen | 42aafb3 | 2012-07-05 17:21:46 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 136 | |
| 137 | #if defined(CONFIG_SPL_BUILD) |
| 138 | #include <spl.h> |
| 139 | #include <nand.h> |
| 140 | |
| 141 | void at91_spl_board_init(void) |
| 142 | { |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 143 | #ifdef CONFIG_SD_BOOT |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 144 | at91_mci_hw_init(); |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 145 | #elif CONFIG_NAND_BOOT |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 146 | at91sam9x5ek_nand_hw_init(); |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 147 | #endif |
| 148 | } |
| 149 | |
| 150 | #include <asm/arch/atmel_mpddrc.h> |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 151 | static void ddr2_conf(struct atmel_mpddrc_config *ddr2) |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 152 | { |
| 153 | ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM); |
| 154 | |
| 155 | ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | |
| 156 | ATMEL_MPDDRC_CR_NR_ROW_13 | |
| 157 | ATMEL_MPDDRC_CR_CAS_DDR_CAS3 | |
| 158 | ATMEL_MPDDRC_CR_NB_8BANKS | |
| 159 | ATMEL_MPDDRC_CR_DECOD_INTERLEAVED); |
| 160 | |
| 161 | ddr2->rtr = 0x411; |
| 162 | |
| 163 | ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET | |
| 164 | 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET | |
| 165 | 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | |
| 166 | 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | |
| 167 | 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | |
| 168 | 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | |
| 169 | 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | |
| 170 | 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); |
| 171 | |
| 172 | ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | |
| 173 | 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET | |
| 174 | 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET | |
| 175 | 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET); |
| 176 | |
| 177 | ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET | |
| 178 | 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET | |
| 179 | 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET | |
| 180 | 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET | |
| 181 | 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET); |
| 182 | } |
| 183 | |
| 184 | void mem_init(void) |
| 185 | { |
| 186 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 187 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 188 | struct atmel_mpddrc_config ddr2; |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 189 | unsigned long csa; |
| 190 | |
| 191 | ddr2_conf(&ddr2); |
| 192 | |
| 193 | /* enable DDR2 clock */ |
Erik van Luijk | ebaa800 | 2015-08-13 15:43:20 +0200 | [diff] [blame] | 194 | writel(AT91_PMC_DDR, &pmc->scer); |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 195 | |
| 196 | /* Chip select 1 is for DDR2/SDRAM */ |
| 197 | csa = readl(&matrix->ebicsa); |
| 198 | csa |= AT91_MATRIX_EBI_CS1A_SDRAMC; |
| 199 | csa &= ~AT91_MATRIX_EBI_DBPU_OFF; |
| 200 | csa |= AT91_MATRIX_EBI_DBPD_OFF; |
| 201 | csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL; |
| 202 | writel(csa, &matrix->ebicsa); |
| 203 | |
| 204 | /* DDRAM2 Controller initialize */ |
Erik van Luijk | 59d780a | 2015-08-13 15:43:18 +0200 | [diff] [blame] | 205 | ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2); |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 206 | } |
| 207 | #endif |