Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007-2008 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 4 | * Stelian Pop <stelian@popies.net> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 5 | * Lead Tech Design <www.leadtechdesign.com> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Tom Rini | 5f201cd | 2024-04-30 20:41:08 -0600 | [diff] [blame] | 8 | #include <config.h> |
Wenyou.Yang@microchip.com | b59fe68 | 2017-07-21 13:28:40 +0800 | [diff] [blame] | 9 | #include <debug_uart.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 11 | #include <vsprintf.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 14 | #include <asm/arch/at91sam9261.h> |
| 15 | #include <asm/arch/at91sam9261_matrix.h> |
| 16 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6b0b3db | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 17 | #include <asm/arch/at91_common.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 18 | #include <asm/arch/at91_rstc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 19 | #include <asm/arch/clk.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 20 | #include <asm/arch/gpio.h> |
Stelian Pop | 905ed22 | 2008-05-08 14:52:30 +0200 | [diff] [blame] | 21 | #include <atmel_lcdc.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 22 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000) |
| 23 | #include <net.h> |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 24 | #include <netdev.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 25 | #endif |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | /* ------------------------------------------------------------------------- */ |
| 31 | /* |
| 32 | * Miscelaneous platform dependent initialisations |
| 33 | */ |
| 34 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 35 | #ifdef CONFIG_CMD_NAND |
| 36 | static void at91sam9261ek_nand_hw_init(void) |
| 37 | { |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 38 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 39 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 40 | unsigned long csa; |
| 41 | |
| 42 | /* Enable CS3 */ |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 43 | csa = readl(&matrix->ebicsa); |
| 44 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 45 | |
| 46 | writel(csa, &matrix->ebicsa); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 47 | |
| 48 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 49 | #ifdef CONFIG_AT91SAM9G10EK |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 50 | writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) | |
| 51 | AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0), |
| 52 | &smc->cs[3].setup); |
| 53 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) | |
| 54 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7), |
| 55 | &smc->cs[3].pulse); |
| 56 | writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7), |
| 57 | &smc->cs[3].cycle); |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 58 | #else |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 59 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 60 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 61 | &smc->cs[3].setup); |
| 62 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 63 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 64 | &smc->cs[3].pulse); |
| 65 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 66 | &smc->cs[3].cycle); |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 67 | #endif |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 68 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 69 | AT91_SMC_MODE_EXNW_DISABLE | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 71 | AT91_SMC_MODE_DBW_16 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 73 | AT91_SMC_MODE_DBW_8 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 74 | #endif |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 75 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 76 | &smc->cs[3].mode); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 77 | |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 78 | at91_periph_clk_enable(ATMEL_ID_PIOC); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 79 | |
| 80 | /* Configure RDY/BSY */ |
Tom Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 81 | at91_set_gpio_input(CFG_SYS_NAND_READY_PIN, 1); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 82 | |
| 83 | /* Enable NandFlash */ |
Tom Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 84 | at91_set_gpio_output(CFG_SYS_NAND_ENABLE_PIN, 1); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 85 | |
| 86 | at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */ |
| 87 | at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */ |
| 88 | } |
| 89 | #endif |
| 90 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 91 | #ifdef CONFIG_DRIVER_DM9000 |
| 92 | static void at91sam9261ek_dm9000_hw_init(void) |
| 93 | { |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 94 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 95 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 96 | /* Configure SMC CS2 for DM9000 */ |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_AT91SAM9G10EK |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 98 | writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) | |
| 99 | AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0), |
| 100 | &smc->cs[2].setup); |
| 101 | writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) | |
| 102 | AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8), |
| 103 | &smc->cs[2].pulse); |
| 104 | writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20), |
| 105 | &smc->cs[2].cycle); |
| 106 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 107 | AT91_SMC_MODE_EXNW_DISABLE | |
| 108 | AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 | |
| 109 | AT91_SMC_MODE_TDF_CYCLE(1), |
| 110 | &smc->cs[2].mode); |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 111 | #else |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 112 | writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) | |
| 113 | AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0), |
| 114 | &smc->cs[2].setup); |
| 115 | writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) | |
| 116 | AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8), |
| 117 | &smc->cs[2].pulse); |
| 118 | writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16), |
| 119 | &smc->cs[2].cycle); |
| 120 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 121 | AT91_SMC_MODE_EXNW_DISABLE | |
| 122 | AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 | |
| 123 | AT91_SMC_MODE_TDF_CYCLE(1), |
| 124 | &smc->cs[2].mode); |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 125 | #endif |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 126 | |
| 127 | /* Configure Reset signal as output */ |
| 128 | at91_set_gpio_output(AT91_PIN_PC10, 0); |
| 129 | |
| 130 | /* Configure Interrupt pin as input, no pull-up */ |
| 131 | at91_set_gpio_input(AT91_PIN_PC11, 0); |
| 132 | } |
| 133 | #endif |
| 134 | |
Wenyou.Yang@microchip.com | b59fe68 | 2017-07-21 13:28:40 +0800 | [diff] [blame] | 135 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 136 | void board_debug_uart_init(void) |
| 137 | { |
| 138 | at91_seriald_hw_init(); |
| 139 | } |
| 140 | #endif |
| 141 | |
| 142 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 143 | int board_early_init_f(void) |
| 144 | { |
Wenyou.Yang@microchip.com | b59fe68 | 2017-07-21 13:28:40 +0800 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | #endif |
| 148 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 149 | int board_init(void) |
| 150 | { |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_AT91SAM9G10EK |
| 152 | /* arch number of AT91SAM9G10EK-Board */ |
| 153 | gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G10EK; |
| 154 | #else |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 155 | /* arch number of AT91SAM9261EK-Board */ |
| 156 | gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK; |
Sedji Gaouaou | 97a031b | 2009-06-25 17:04:15 +0200 | [diff] [blame] | 157 | #endif |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 158 | /* adress of boot parameters */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 159 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 160 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_CMD_NAND |
| 162 | at91sam9261ek_nand_hw_init(); |
| 163 | #endif |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 164 | #ifdef CONFIG_DRIVER_DM9000 |
| 165 | at91sam9261ek_dm9000_hw_init(); |
| 166 | #endif |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 170 | #ifdef CONFIG_DRIVER_DM9000 |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 171 | int board_eth_init(struct bd_info *bis) |
Wolfgang Denk | e5032c8 | 2009-12-07 21:06:40 +0100 | [diff] [blame] | 172 | { |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 173 | return dm9000_initialize(bis); |
Wolfgang Denk | e5032c8 | 2009-12-07 21:06:40 +0100 | [diff] [blame] | 174 | } |
| 175 | #endif |
| 176 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 177 | int dram_init(void) |
| 178 | { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 179 | gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, |
| 180 | CFG_SYS_SDRAM_SIZE); |
Xu, Hong | 0a61494 | 2011-07-31 22:49:00 +0000 | [diff] [blame] | 181 | |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | #ifdef CONFIG_RESET_PHY_R |
| 186 | void reset_phy(void) |
| 187 | { |
| 188 | #ifdef CONFIG_DRIVER_DM9000 |
| 189 | /* |
| 190 | * Initialize ethernet HW addr prior to starting Linux, |
| 191 | * needed for nfsroot |
| 192 | */ |
Joe Hershberger | 3dbe17e | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 193 | eth_init(); |
Stelian Pop | 61e69d7 | 2008-05-08 20:52:22 +0200 | [diff] [blame] | 194 | #endif |
| 195 | } |
| 196 | #endif |