Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 Atmel Corporation |
| 4 | * Josh Wu <josh.wu@atmel.com> |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 10 | #include <vsprintf.h> |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/at91sam9x5_matrix.h> |
| 13 | #include <asm/arch/at91sam9_smc.h> |
| 14 | #include <asm/arch/at91_common.h> |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 15 | #include <asm/arch/at91_rstc.h> |
| 16 | #include <asm/arch/at91_pio.h> |
| 17 | #include <asm/arch/clk.h> |
Wenyou Yang | e3c9930 | 2017-04-18 14:54:53 +0800 | [diff] [blame] | 18 | #include <debug_uart.h> |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 19 | #include <lcd.h> |
| 20 | #include <atmel_hlcdc.h> |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 21 | #include <netdev.h> |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 22 | |
| 23 | #ifdef CONFIG_LCD_INFO |
| 24 | #include <nand.h> |
| 25 | #include <version.h> |
| 26 | #endif |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | /* ------------------------------------------------------------------------- */ |
| 31 | /* |
| 32 | * Miscelaneous platform dependent initialisations |
| 33 | */ |
| 34 | #ifdef CONFIG_NAND_ATMEL |
| 35 | static void at91sam9n12ek_nand_hw_init(void) |
| 36 | { |
| 37 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 38 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
| 39 | unsigned long csa; |
| 40 | |
| 41 | /* Assign CS3 to NAND/SmartMedia Interface */ |
| 42 | csa = readl(&matrix->ebicsa); |
| 43 | csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA; |
| 44 | /* Configure databus */ |
| 45 | csa &= ~AT91_MATRIX_NFD0_ON_D16; /* nandflash connect to D0~D15 */ |
| 46 | /* Configure IO drive */ |
Bo Shen | 3c8217e | 2013-07-17 17:14:17 +0800 | [diff] [blame] | 47 | csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL; |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 48 | |
| 49 | writel(csa, &matrix->ebicsa); |
| 50 | |
| 51 | /* Configure SMC CS3 for NAND/SmartMedia */ |
| 52 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 53 | AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0), |
| 54 | &smc->cs[3].setup); |
| 55 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) | |
| 56 | AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6), |
| 57 | &smc->cs[3].pulse); |
| 58 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(7), |
| 59 | &smc->cs[3].cycle); |
| 60 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 61 | AT91_SMC_MODE_EXNW_DISABLE | |
| 62 | #ifdef CONFIG_SYS_NAND_DBW_16 |
| 63 | AT91_SMC_MODE_DBW_16 | |
| 64 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
| 65 | AT91_SMC_MODE_DBW_8 | |
| 66 | #endif |
| 67 | AT91_SMC_MODE_TDF_CYCLE(1), |
| 68 | &smc->cs[3].mode); |
| 69 | |
| 70 | /* Configure RDY/BSY pin */ |
| 71 | at91_set_pio_input(AT91_PIO_PORTD, 5, 1); |
| 72 | |
| 73 | /* Configure ENABLE pin for NandFlash */ |
| 74 | at91_set_pio_output(AT91_PIO_PORTD, 4, 1); |
| 75 | |
Wenyou Yang | 4a92a3e | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 76 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */ |
| 77 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */ |
| 78 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* ALE */ |
| 79 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* CLE */ |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 80 | } |
| 81 | #endif |
| 82 | |
| 83 | #ifdef CONFIG_LCD |
| 84 | vidinfo_t panel_info = { |
| 85 | .vl_col = 480, |
| 86 | .vl_row = 272, |
| 87 | .vl_clk = 9000000, |
| 88 | .vl_bpix = LCD_BPP, |
| 89 | .vl_sync = 0, |
| 90 | .vl_tft = 1, |
| 91 | .vl_hsync_len = 5, |
| 92 | .vl_left_margin = 8, |
| 93 | .vl_right_margin = 43, |
| 94 | .vl_vsync_len = 10, |
| 95 | .vl_upper_margin = 4, |
| 96 | .vl_lower_margin = 12, |
| 97 | .mmio = ATMEL_BASE_LCDC, |
| 98 | }; |
| 99 | |
| 100 | void lcd_enable(void) |
| 101 | { |
| 102 | at91_set_pio_output(AT91_PIO_PORTC, 25, 0); /* power up */ |
| 103 | } |
| 104 | |
| 105 | void lcd_disable(void) |
| 106 | { |
| 107 | at91_set_pio_output(AT91_PIO_PORTC, 25, 1); /* power down */ |
| 108 | } |
| 109 | |
| 110 | #ifdef CONFIG_LCD_INFO |
| 111 | void lcd_show_board_info(void) |
| 112 | { |
| 113 | ulong dram_size, nand_size; |
| 114 | int i; |
| 115 | char temp[32]; |
| 116 | |
| 117 | lcd_printf("%s\n", U_BOOT_VERSION); |
| 118 | lcd_printf("ATMEL Corp\n"); |
| 119 | lcd_printf("at91@atmel.com\n"); |
| 120 | lcd_printf("%s CPU at %s MHz\n", |
| 121 | ATMEL_CPU_NAME, |
| 122 | strmhz(temp, get_cpu_clk_rate())); |
| 123 | |
| 124 | dram_size = 0; |
| 125 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
| 126 | dram_size += gd->bd->bi_dram[i].size; |
| 127 | nand_size = 0; |
| 128 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) |
Grygorii Strashko | 1e096a2 | 2017-06-26 19:13:03 -0500 | [diff] [blame] | 129 | nand_size += get_nand_dev_by_index(i)->size; |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 130 | lcd_printf(" %ld MB SDRAM, %ld MB NAND\n", |
| 131 | dram_size >> 20, |
| 132 | nand_size >> 20); |
| 133 | } |
| 134 | #endif /* CONFIG_LCD_INFO */ |
| 135 | #endif /* CONFIG_LCD */ |
| 136 | |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 137 | #ifdef CONFIG_KS8851_MLL |
| 138 | void at91sam9n12ek_ks8851_hw_init(void) |
| 139 | { |
| 140 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 141 | |
| 142 | writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) | |
| 143 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 144 | &smc->cs[2].setup); |
| 145 | writel(AT91_SMC_PULSE_NWE(7) | AT91_SMC_PULSE_NCS_WR(7) | |
| 146 | AT91_SMC_PULSE_NRD(7) | AT91_SMC_PULSE_NCS_RD(7), |
| 147 | &smc->cs[2].pulse); |
| 148 | writel(AT91_SMC_CYCLE_NWE(9) | AT91_SMC_CYCLE_NRD(9), |
| 149 | &smc->cs[2].cycle); |
| 150 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 151 | AT91_SMC_MODE_EXNW_DISABLE | |
| 152 | AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 | |
| 153 | AT91_SMC_MODE_TDF_CYCLE(1), |
| 154 | &smc->cs[2].mode); |
| 155 | |
| 156 | /* Configure NCS2 PIN */ |
Wenyou Yang | 4a92a3e | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 157 | at91_pio3_set_b_periph(AT91_PIO_PORTD, 19, 0); |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 158 | } |
| 159 | #endif |
| 160 | |
Bo Shen | 8ed8783 | 2013-10-21 16:13:59 +0800 | [diff] [blame] | 161 | #ifdef CONFIG_USB_ATMEL |
| 162 | void at91sam9n12ek_usb_hw_init(void) |
| 163 | { |
| 164 | at91_set_pio_output(AT91_PIO_PORTB, 7, 0); |
| 165 | } |
| 166 | #endif |
| 167 | |
Wenyou Yang | e3c9930 | 2017-04-18 14:54:53 +0800 | [diff] [blame] | 168 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 169 | void board_debug_uart_init(void) |
| 170 | { |
| 171 | at91_seriald_hw_init(); |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 176 | int board_early_init_f(void) |
| 177 | { |
Wenyou Yang | e3c9930 | 2017-04-18 14:54:53 +0800 | [diff] [blame] | 178 | #ifdef CONFIG_DEBUG_UART |
| 179 | debug_uart_init(); |
| 180 | #endif |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 181 | return 0; |
| 182 | } |
Wenyou Yang | e3c9930 | 2017-04-18 14:54:53 +0800 | [diff] [blame] | 183 | #endif |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 184 | |
| 185 | int board_init(void) |
| 186 | { |
| 187 | /* adress of boot parameters */ |
| 188 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 189 | |
| 190 | #ifdef CONFIG_NAND_ATMEL |
| 191 | at91sam9n12ek_nand_hw_init(); |
| 192 | #endif |
| 193 | |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 194 | #ifdef CONFIG_LCD |
| 195 | at91_lcd_hw_init(); |
| 196 | #endif |
| 197 | |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 198 | #ifdef CONFIG_KS8851_MLL |
| 199 | at91sam9n12ek_ks8851_hw_init(); |
| 200 | #endif |
| 201 | |
Bo Shen | 8ed8783 | 2013-10-21 16:13:59 +0800 | [diff] [blame] | 202 | #ifdef CONFIG_USB_ATMEL |
| 203 | at91sam9n12ek_usb_hw_init(); |
| 204 | #endif |
| 205 | |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 209 | #ifdef CONFIG_KS8851_MLL |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 210 | int board_eth_init(struct bd_info *bis) |
Bo Shen | d2c2612 | 2013-04-24 10:46:18 +0800 | [diff] [blame] | 211 | { |
| 212 | return ks8851_mll_initialize(0, CONFIG_KS8851_MLL_BASEADDR); |
| 213 | } |
| 214 | #endif |
| 215 | |
Wu, Josh | 3f338c1 | 2013-04-16 23:42:44 +0000 | [diff] [blame] | 216 | int dram_init(void) |
| 217 | { |
| 218 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 219 | CONFIG_SYS_SDRAM_SIZE); |
| 220 | return 0; |
| 221 | } |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 222 | |
| 223 | #if defined(CONFIG_SPL_BUILD) |
| 224 | #include <spl.h> |
| 225 | #include <nand.h> |
| 226 | |
| 227 | void at91_spl_board_init(void) |
| 228 | { |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 229 | #ifdef CONFIG_SD_BOOT |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 230 | at91_mci_hw_init(); |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 231 | #elif CONFIG_NAND_BOOT |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 232 | at91sam9n12ek_nand_hw_init(); |
Wenyou Yang | e035ea7 | 2017-09-14 11:07:44 +0800 | [diff] [blame] | 233 | #elif CONFIG_SPI_BOOT |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 234 | at91_spi0_hw_init(1 << 4); |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | #include <asm/arch/atmel_mpddrc.h> |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 239 | static void ddr2_conf(struct atmel_mpddrc_config *ddr2) |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 240 | { |
| 241 | ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM); |
| 242 | |
| 243 | ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | |
| 244 | ATMEL_MPDDRC_CR_NR_ROW_13 | |
| 245 | ATMEL_MPDDRC_CR_CAS_DDR_CAS3 | |
| 246 | ATMEL_MPDDRC_CR_NB_8BANKS | |
| 247 | ATMEL_MPDDRC_CR_DECOD_INTERLEAVED); |
| 248 | |
| 249 | ddr2->rtr = 0x411; |
| 250 | |
| 251 | ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET | |
| 252 | 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET | |
| 253 | 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | |
| 254 | 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | |
| 255 | 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | |
| 256 | 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | |
| 257 | 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | |
| 258 | 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); |
| 259 | |
| 260 | ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | |
| 261 | 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET | |
| 262 | 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET | |
| 263 | 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET); |
| 264 | |
| 265 | ddr2->tpr2 = (2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET | |
| 266 | 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET | |
| 267 | 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET | |
| 268 | 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET); |
| 269 | } |
| 270 | |
| 271 | void mem_init(void) |
| 272 | { |
| 273 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 274 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Wenyou Yang | aa0a58d | 2016-02-01 18:12:15 +0800 | [diff] [blame] | 275 | struct atmel_mpddrc_config ddr2; |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 276 | unsigned long csa; |
| 277 | |
| 278 | ddr2_conf(&ddr2); |
| 279 | |
| 280 | /* enable DDR2 clock */ |
Erik van Luijk | ebaa800 | 2015-08-13 15:43:20 +0200 | [diff] [blame] | 281 | writel(AT91_PMC_DDR, &pmc->scer); |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 282 | |
| 283 | /* Chip select 1 is for DDR2/SDRAM */ |
| 284 | csa = readl(&matrix->ebicsa); |
| 285 | csa |= AT91_MATRIX_EBI_CS1A_SDRAMC; |
| 286 | csa &= ~AT91_MATRIX_EBI_DBPU_OFF; |
| 287 | csa |= AT91_MATRIX_EBI_DBPD_OFF; |
| 288 | csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL; |
| 289 | writel(csa, &matrix->ebicsa); |
| 290 | |
| 291 | /* DDRAM2 Controller initialize */ |
Erik van Luijk | 59d780a | 2015-08-13 15:43:18 +0200 | [diff] [blame] | 292 | ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2); |
Bo Shen | 9c70939 | 2015-03-27 14:23:36 +0800 | [diff] [blame] | 293 | } |
| 294 | #endif |