Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | c9e798d | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
| 6 | * (C) Copyright 2010 |
| 7 | * Reinhard Meyer, EMK Elektronik, reinhard.meyer@emk-elektronik.de |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <net.h> |
| 30 | #include <netdev.h> |
| 31 | #include <mmc.h> |
Andreas Bießmann | 77c3d84 | 2012-03-13 05:01:51 +0000 | [diff] [blame] | 32 | #include <atmel_mci.h> |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 33 | #include <i2c.h> |
| 34 | #include <spi.h> |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 35 | #include <asm/io.h> |
| 36 | #include <asm/arch/hardware.h> |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 37 | #include <asm/arch/at91sam9260_matrix.h> |
| 38 | #include <asm/arch/at91sam9_smc.h> |
| 39 | #include <asm/arch/at91_common.h> |
| 40 | #include <asm/arch/at91_pmc.h> |
| 41 | #include <asm/arch/at91_rstc.h> |
| 42 | #include <asm/arch/at91_shdwn.h> |
| 43 | #include <asm/arch/gpio.h> |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 44 | |
| 45 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | |
| 47 | #ifdef CONFIG_CMD_NAND |
| 48 | static void nand_hw_init(void) |
| 49 | { |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 50 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 51 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 52 | unsigned long csa; |
| 53 | |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +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); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 58 | |
| 59 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +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); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 73 | |
| 74 | /* Configure RDY/BSY */ |
| 75 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
| 76 | |
| 77 | /* Enable NandFlash */ |
| 78 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | #ifdef CONFIG_MACB |
| 83 | static void macb_hw_init(void) |
| 84 | { |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 85 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 86 | |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 87 | /* Enable EMAC clock */ |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 88 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 89 | |
| 90 | /* Initialize EMAC=MACB hardware */ |
| 91 | at91_macb_hw_init(); |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 96 | /* this is a weak define that we are overriding */ |
| 97 | int board_mmc_init(bd_t *bd) |
| 98 | { |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 99 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 100 | |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 101 | /* Enable MCI clock */ |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 102 | writel(1 << ATMEL_ID_MCI, &pmc->pcer); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 103 | |
| 104 | /* Initialize MCI hardware */ |
| 105 | at91_mci_hw_init(); |
| 106 | |
| 107 | /* This calls the atmel_mmc_init in gen_atmel_mci.c */ |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 108 | return atmel_mci_init((void *)ATMEL_BASE_MCI); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* this is a weak define that we are overriding */ |
Thierry Reding | 314284b | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 112 | int board_mmc_getcd(struct mmc *mmc) |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 113 | { |
Thierry Reding | 314284b | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 114 | return !at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | #endif |
| 118 | |
| 119 | int board_early_init_f(void) |
| 120 | { |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 121 | struct at91_shdwn *shdwn = (struct at91_shdwn *)ATMEL_BASE_SHDWN; |
| 122 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * make sure the board can be powered on by |
| 126 | * any transition on WKUP |
| 127 | */ |
| 128 | writel(AT91_SHDW_MR_WKMODE0H2L | AT91_SHDW_MR_WKMODE0L2H, |
| 129 | &shdwn->mr); |
| 130 | |
| 131 | /* Enable clocks for all PIOs */ |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 132 | writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) | |
| 133 | (1 << ATMEL_ID_PIOC), |
| 134 | &pmc->pcer); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 135 | |
| 136 | /* set SCL0 and SDA0 to open drain */ |
| 137 | at91_set_pio_output(I2C0_PORT, SCL0_PIN, 1); |
| 138 | at91_set_pio_multi_drive(I2C0_PORT, SCL0_PIN, 1); |
| 139 | at91_set_pio_pullup(I2C0_PORT, SCL0_PIN, 1); |
| 140 | at91_set_pio_output(I2C0_PORT, SDA0_PIN, 1); |
| 141 | at91_set_pio_multi_drive(I2C0_PORT, SDA0_PIN, 1); |
| 142 | at91_set_pio_pullup(I2C0_PORT, SDA0_PIN, 1); |
| 143 | |
| 144 | /* set SCL1 and SDA1 to open drain */ |
| 145 | at91_set_pio_output(I2C1_PORT, SCL1_PIN, 1); |
| 146 | at91_set_pio_multi_drive(I2C1_PORT, SCL1_PIN, 1); |
| 147 | at91_set_pio_pullup(I2C1_PORT, SCL1_PIN, 1); |
| 148 | at91_set_pio_output(I2C1_PORT, SDA1_PIN, 1); |
| 149 | at91_set_pio_multi_drive(I2C1_PORT, SDA1_PIN, 1); |
| 150 | at91_set_pio_pullup(I2C1_PORT, SDA1_PIN, 1); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int board_init(void) |
| 155 | { |
| 156 | /* arch number of TOP9000 Board */ |
| 157 | gd->bd->bi_arch_number = MACH_TYPE_TOP9000; |
| 158 | /* adress of boot parameters */ |
| 159 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 160 | |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 161 | at91_seriald_hw_init(); |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 162 | #ifdef CONFIG_CMD_NAND |
| 163 | nand_hw_init(); |
| 164 | #endif |
| 165 | #ifdef CONFIG_MACB |
| 166 | macb_hw_init(); |
| 167 | #endif |
| 168 | #ifdef CONFIG_ATMEL_SPI0 |
| 169 | /* (n+4) denotes to use nSPISEL(0) in GPIO mode! */ |
| 170 | at91_spi0_hw_init(1 << (FRAM_CS_NUM + 4)); |
| 171 | #endif |
| 172 | #ifdef CONFIG_ATMEL_SPI1 |
| 173 | at91_spi1_hw_init(1 << (ENC_CS_NUM + 4)); |
| 174 | #endif |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | #ifdef CONFIG_MISC_INIT_R |
| 179 | int misc_init_r(void) |
| 180 | { |
| 181 | /* read 'factory' part of EEPROM */ |
| 182 | read_factory_r(); |
| 183 | return 0; |
| 184 | } |
| 185 | #endif |
| 186 | |
| 187 | int dram_init(void) |
| 188 | { |
| 189 | gd->ram_size = get_ram_size( |
| 190 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 191 | CONFIG_SYS_SDRAM_SIZE); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | #ifdef CONFIG_RESET_PHY_R |
| 196 | void reset_phy(void) |
| 197 | { |
| 198 | /* |
| 199 | * Initialize ethernet HW addresses prior to starting Linux, |
| 200 | * needed for nfsroot. |
| 201 | * TODO: We need to investigate if that is really necessary. |
| 202 | */ |
| 203 | eth_init(gd->bd); |
| 204 | } |
| 205 | #endif |
| 206 | |
| 207 | int board_eth_init(bd_t *bis) |
| 208 | { |
| 209 | int rc = 0; |
| 210 | int num = 0; |
| 211 | #ifdef CONFIG_MACB |
| 212 | rc = macb_eth_initialize(0, |
Reinhard Meyer | 9b372b2 | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 213 | (void *)ATMEL_BASE_EMAC0, |
Reinhard Meyer | d55c5c3 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 214 | CONFIG_SYS_PHY_ID); |
| 215 | if (!rc) |
| 216 | num++; |
| 217 | #endif |
| 218 | #ifdef CONFIG_ENC28J60 |
| 219 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM, |
| 220 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 221 | if (!rc) |
| 222 | num++; |
| 223 | # ifdef CONFIG_ENC28J60_2 |
| 224 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+1, |
| 225 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 226 | if (!rc) |
| 227 | num++; |
| 228 | # ifdef CONFIG_ENC28J60_3 |
| 229 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+2, |
| 230 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 231 | if (!rc) |
| 232 | num++; |
| 233 | # endif |
| 234 | # endif |
| 235 | #endif |
| 236 | return num; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * I2C access functions |
| 241 | * |
| 242 | * Note: |
| 243 | * We need to access Bus 0 before relocation to access the |
| 244 | * environment settings. |
| 245 | * However i2c_get_bus_num() cannot be called before |
| 246 | * relocation. |
| 247 | */ |
| 248 | #ifdef CONFIG_SOFT_I2C |
| 249 | void iic_init(void) |
| 250 | { |
| 251 | /* ports are now initialized in board_early_init_f() */ |
| 252 | } |
| 253 | |
| 254 | int iic_read(void) |
| 255 | { |
| 256 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 257 | case 0: |
| 258 | return at91_get_pio_value(I2C0_PORT, SDA0_PIN); |
| 259 | case 1: |
| 260 | return at91_get_pio_value(I2C1_PORT, SDA1_PIN); |
| 261 | } |
| 262 | return 1; |
| 263 | } |
| 264 | |
| 265 | void iic_sda(int bit) |
| 266 | { |
| 267 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 268 | case 0: |
| 269 | at91_set_pio_value(I2C0_PORT, SDA0_PIN, bit); |
| 270 | break; |
| 271 | case 1: |
| 272 | at91_set_pio_value(I2C1_PORT, SDA1_PIN, bit); |
| 273 | break; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void iic_scl(int bit) |
| 278 | { |
| 279 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 280 | case 0: |
| 281 | at91_set_pio_value(I2C0_PORT, SCL0_PIN, bit); |
| 282 | break; |
| 283 | case 1: |
| 284 | at91_set_pio_value(I2C1_PORT, SCL1_PIN, bit); |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | #endif |