Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
| 3 | * Stelian Pop <stelian.pop@leadtechdesign.com> |
| 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * (C) Copyright 2008 Sergey Lapin <slapin@ossfans.org> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/arch/at91sam9260.h> |
| 28 | #include <asm/arch/at91sam9260_matrix.h> |
| 29 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 1332a2a | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 30 | #include <asm/arch/at91_common.h> |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 31 | #include <asm/arch/at91_pmc.h> |
| 32 | #include <asm/arch/at91_rstc.h> |
| 33 | #include <asm/arch/gpio.h> |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 34 | #include <asm/io.h> |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 35 | #include <asm/arch/hardware.h> |
| 36 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB) |
| 37 | #include <netdev.h> |
| 38 | #include <net.h> |
| 39 | #endif |
| 40 | |
| 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
| 43 | /* ------------------------------------------------------------------------- */ |
| 44 | /* |
| 45 | * Miscelaneous platform dependent initialisations |
| 46 | */ |
| 47 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 48 | static void afeb9260_nand_hw_init(void) |
| 49 | { |
| 50 | unsigned long csa; |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 51 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 52 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 53 | |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 54 | /* Assign CS3 to NAND/SmartMedia Interface */ |
| 55 | csa = readl(&matrix->ebicsa); |
| 56 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 57 | writel(csa, &matrix->ebicsa); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 58 | |
| 59 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 60 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 61 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 62 | &smc->cs[3].setup); |
| 63 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 64 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 65 | &smc->cs[3].pulse); |
| 66 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 67 | &smc->cs[3].cycle); |
| 68 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 69 | AT91_SMC_MODE_EXNW_DISABLE | |
| 70 | AT91_SMC_MODE_DBW_8 | |
| 71 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 72 | &smc->cs[3].mode); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 73 | |
| 74 | /* Configure RDY/BSY */ |
Jean-Christophe PLAGNIOL-VILLARD | 74c076d | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 75 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 76 | |
| 77 | /* Enable NandFlash */ |
Jean-Christophe PLAGNIOL-VILLARD | 74c076d | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 78 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 81 | #ifdef CONFIG_MACB |
| 82 | static void afeb9260_macb_hw_init(void) |
| 83 | { |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 84 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 85 | struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA; |
| 86 | struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC; |
| 87 | unsigned long erstl; |
Sedji Gaouaou | 0aafde1 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 88 | |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 89 | |
| 90 | /* Enable EMAC clock */ |
| 91 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
| 92 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Disable pull-up on: |
| 96 | * RXDV (PA17) => PHY normal mode (not Test mode) |
| 97 | * ERX0 (PA14) => PHY ADDR0 |
| 98 | * ERX1 (PA15) => PHY ADDR1 |
| 99 | * ERX2 (PA25) => PHY ADDR2 |
| 100 | * ERX3 (PA26) => PHY ADDR3 |
| 101 | * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 |
| 102 | * |
| 103 | * PHY has internal pull-down |
| 104 | */ |
| 105 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 106 | pin_to_mask(AT91_PIN_PA15) | |
| 107 | pin_to_mask(AT91_PIN_PA17) | |
| 108 | pin_to_mask(AT91_PIN_PA25) | |
| 109 | pin_to_mask(AT91_PIN_PA26) | |
| 110 | pin_to_mask(AT91_PIN_PA28), |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 111 | &pioa->pudr); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 112 | |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 113 | erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK; |
Sedji Gaouaou | 0aafde1 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 114 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 115 | /* Need to reset PHY -> 500ms reset */ |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 116 | writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) | |
| 117 | AT91_RSTC_MR_URSTEN, &rstc->mr); |
| 118 | writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 119 | |
| 120 | /* Wait for end hardware reset */ |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 121 | while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) |
| 122 | ; |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 123 | /* Restore NRST value */ |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 124 | writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, |
| 125 | &rstc->mr); |
| 126 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 127 | |
| 128 | /* Re-enable pull-up */ |
| 129 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 130 | pin_to_mask(AT91_PIN_PA15) | |
| 131 | pin_to_mask(AT91_PIN_PA17) | |
| 132 | pin_to_mask(AT91_PIN_PA25) | |
| 133 | pin_to_mask(AT91_PIN_PA26) | |
| 134 | pin_to_mask(AT91_PIN_PA28), |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 135 | &pioa->puer); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 136 | |
Jean-Christophe PLAGNIOL-VILLARD | e2c0476 | 2009-03-21 21:08:00 +0100 | [diff] [blame] | 137 | at91_macb_hw_init(); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 138 | } |
| 139 | #endif |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 140 | int board_early_init_f(void) |
| 141 | { |
| 142 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 143 | /* Enable clocks for all PIOs */ |
| 144 | writel((1 << ATMEL_ID_PIOA) | |
| 145 | (1 << ATMEL_ID_PIOB) | |
| 146 | (1 << ATMEL_ID_PIOC), |
| 147 | &pmc->pcer); |
| 148 | return 0; |
| 149 | } |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 150 | int board_init(void) |
| 151 | { |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 152 | /* arch number of AT91SAM9260EK-Board */ |
| 153 | gd->bd->bi_arch_number = MACH_TYPE_AFEB9260; |
| 154 | /* adress of boot parameters */ |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 155 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 156 | |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 157 | at91_seriald_hw_init(); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_CMD_NAND |
| 159 | afeb9260_nand_hw_init(); |
| 160 | #endif |
Albin Tonnerre | 50b5fff | 2009-09-01 11:26:20 +0200 | [diff] [blame] | 161 | at91_spi0_hw_init((1 << 0) | (1 << 1)); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 162 | #ifdef CONFIG_MACB |
| 163 | afeb9260_macb_hw_init(); |
| 164 | #endif |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | int dram_init(void) |
| 170 | { |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 171 | gd->ram_size = get_ram_size( |
| 172 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 173 | CONFIG_SYS_SDRAM_SIZE); |
| 174 | |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | #ifdef CONFIG_RESET_PHY_R |
| 179 | void reset_phy(void) |
| 180 | { |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 181 | } |
| 182 | #endif |
| 183 | |
| 184 | int board_eth_init(bd_t *bis) |
| 185 | { |
| 186 | int rc = 0; |
| 187 | #ifdef CONFIG_MACB |
Sergey Lapin | 282e27c | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 188 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x01); |
Sergey Lapin | 1079432 | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 189 | #endif |
| 190 | return rc; |
| 191 | } |