Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Reinhard Meyer | 82a0979 | 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> |
| 32 | #include <i2c.h> |
| 33 | #include <spi.h> |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 34 | #include <asm/io.h> |
| 35 | #include <asm/arch/hardware.h> |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 36 | #include <asm/arch/at91sam9260_matrix.h> |
| 37 | #include <asm/arch/at91sam9_smc.h> |
| 38 | #include <asm/arch/at91_common.h> |
| 39 | #include <asm/arch/at91_pmc.h> |
| 40 | #include <asm/arch/at91_rstc.h> |
| 41 | #include <asm/arch/at91_shdwn.h> |
| 42 | #include <asm/arch/gpio.h> |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 43 | |
| 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
| 46 | #ifdef CONFIG_CMD_NAND |
| 47 | static void nand_hw_init(void) |
| 48 | { |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 49 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 50 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 51 | unsigned long csa; |
| 52 | |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 53 | /* Assign CS3 to NAND/SmartMedia Interface */ |
| 54 | csa = readl(&matrix->ebicsa); |
| 55 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 56 | writel(csa, &matrix->ebicsa); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 57 | |
| 58 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +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); |
| 67 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 68 | AT91_SMC_MODE_EXNW_DISABLE | |
| 69 | AT91_SMC_MODE_DBW_8 | |
| 70 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 71 | &smc->cs[3].mode); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 72 | |
| 73 | /* Configure RDY/BSY */ |
| 74 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
| 75 | |
| 76 | /* Enable NandFlash */ |
| 77 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | #ifdef CONFIG_MACB |
| 82 | static void macb_hw_init(void) |
| 83 | { |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 84 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 85 | |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 86 | /* Enable EMAC clock */ |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 87 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 88 | |
| 89 | /* Initialize EMAC=MACB hardware */ |
| 90 | at91_macb_hw_init(); |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 95 | /* this is a weak define that we are overriding */ |
| 96 | int board_mmc_init(bd_t *bd) |
| 97 | { |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 98 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 99 | |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 100 | /* Enable MCI clock */ |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 101 | writel(1 << ATMEL_ID_MCI, &pmc->pcer); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 102 | |
| 103 | /* Initialize MCI hardware */ |
| 104 | at91_mci_hw_init(); |
| 105 | |
| 106 | /* This calls the atmel_mmc_init in gen_atmel_mci.c */ |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 107 | return atmel_mci_init((void *)ATMEL_BASE_MCI); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* this is a weak define that we are overriding */ |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame^] | 111 | int board_mmc_getcd(struct mmc *mmc) |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 112 | { |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame^] | 113 | return !at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #endif |
| 117 | |
| 118 | int board_early_init_f(void) |
| 119 | { |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 120 | struct at91_shdwn *shdwn = (struct at91_shdwn *)ATMEL_BASE_SHDWN; |
| 121 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * make sure the board can be powered on by |
| 125 | * any transition on WKUP |
| 126 | */ |
| 127 | writel(AT91_SHDW_MR_WKMODE0H2L | AT91_SHDW_MR_WKMODE0L2H, |
| 128 | &shdwn->mr); |
| 129 | |
| 130 | /* Enable clocks for all PIOs */ |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 131 | writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) | |
| 132 | (1 << ATMEL_ID_PIOC), |
| 133 | &pmc->pcer); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 134 | |
| 135 | /* set SCL0 and SDA0 to open drain */ |
| 136 | at91_set_pio_output(I2C0_PORT, SCL0_PIN, 1); |
| 137 | at91_set_pio_multi_drive(I2C0_PORT, SCL0_PIN, 1); |
| 138 | at91_set_pio_pullup(I2C0_PORT, SCL0_PIN, 1); |
| 139 | at91_set_pio_output(I2C0_PORT, SDA0_PIN, 1); |
| 140 | at91_set_pio_multi_drive(I2C0_PORT, SDA0_PIN, 1); |
| 141 | at91_set_pio_pullup(I2C0_PORT, SDA0_PIN, 1); |
| 142 | |
| 143 | /* set SCL1 and SDA1 to open drain */ |
| 144 | at91_set_pio_output(I2C1_PORT, SCL1_PIN, 1); |
| 145 | at91_set_pio_multi_drive(I2C1_PORT, SCL1_PIN, 1); |
| 146 | at91_set_pio_pullup(I2C1_PORT, SCL1_PIN, 1); |
| 147 | at91_set_pio_output(I2C1_PORT, SDA1_PIN, 1); |
| 148 | at91_set_pio_multi_drive(I2C1_PORT, SDA1_PIN, 1); |
| 149 | at91_set_pio_pullup(I2C1_PORT, SDA1_PIN, 1); |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | int board_init(void) |
| 154 | { |
| 155 | /* arch number of TOP9000 Board */ |
| 156 | gd->bd->bi_arch_number = MACH_TYPE_TOP9000; |
| 157 | /* adress of boot parameters */ |
| 158 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 159 | |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 160 | at91_seriald_hw_init(); |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 161 | #ifdef CONFIG_CMD_NAND |
| 162 | nand_hw_init(); |
| 163 | #endif |
| 164 | #ifdef CONFIG_MACB |
| 165 | macb_hw_init(); |
| 166 | #endif |
| 167 | #ifdef CONFIG_ATMEL_SPI0 |
| 168 | /* (n+4) denotes to use nSPISEL(0) in GPIO mode! */ |
| 169 | at91_spi0_hw_init(1 << (FRAM_CS_NUM + 4)); |
| 170 | #endif |
| 171 | #ifdef CONFIG_ATMEL_SPI1 |
| 172 | at91_spi1_hw_init(1 << (ENC_CS_NUM + 4)); |
| 173 | #endif |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | #ifdef CONFIG_MISC_INIT_R |
| 178 | int misc_init_r(void) |
| 179 | { |
| 180 | /* read 'factory' part of EEPROM */ |
| 181 | read_factory_r(); |
| 182 | return 0; |
| 183 | } |
| 184 | #endif |
| 185 | |
| 186 | int dram_init(void) |
| 187 | { |
| 188 | gd->ram_size = get_ram_size( |
| 189 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 190 | CONFIG_SYS_SDRAM_SIZE); |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | #ifdef CONFIG_RESET_PHY_R |
| 195 | void reset_phy(void) |
| 196 | { |
| 197 | /* |
| 198 | * Initialize ethernet HW addresses prior to starting Linux, |
| 199 | * needed for nfsroot. |
| 200 | * TODO: We need to investigate if that is really necessary. |
| 201 | */ |
| 202 | eth_init(gd->bd); |
| 203 | } |
| 204 | #endif |
| 205 | |
| 206 | int board_eth_init(bd_t *bis) |
| 207 | { |
| 208 | int rc = 0; |
| 209 | int num = 0; |
| 210 | #ifdef CONFIG_MACB |
| 211 | rc = macb_eth_initialize(0, |
Reinhard Meyer | e89794b | 2011-06-06 00:16:42 +0000 | [diff] [blame] | 212 | (void *)ATMEL_BASE_EMAC0, |
Reinhard Meyer | 82a0979 | 2010-10-30 23:09:58 +0000 | [diff] [blame] | 213 | CONFIG_SYS_PHY_ID); |
| 214 | if (!rc) |
| 215 | num++; |
| 216 | #endif |
| 217 | #ifdef CONFIG_ENC28J60 |
| 218 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM, |
| 219 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 220 | if (!rc) |
| 221 | num++; |
| 222 | # ifdef CONFIG_ENC28J60_2 |
| 223 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+1, |
| 224 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 225 | if (!rc) |
| 226 | num++; |
| 227 | # ifdef CONFIG_ENC28J60_3 |
| 228 | rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+2, |
| 229 | ENC_SPI_CLOCK, SPI_MODE_0); |
| 230 | if (!rc) |
| 231 | num++; |
| 232 | # endif |
| 233 | # endif |
| 234 | #endif |
| 235 | return num; |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * I2C access functions |
| 240 | * |
| 241 | * Note: |
| 242 | * We need to access Bus 0 before relocation to access the |
| 243 | * environment settings. |
| 244 | * However i2c_get_bus_num() cannot be called before |
| 245 | * relocation. |
| 246 | */ |
| 247 | #ifdef CONFIG_SOFT_I2C |
| 248 | void iic_init(void) |
| 249 | { |
| 250 | /* ports are now initialized in board_early_init_f() */ |
| 251 | } |
| 252 | |
| 253 | int iic_read(void) |
| 254 | { |
| 255 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 256 | case 0: |
| 257 | return at91_get_pio_value(I2C0_PORT, SDA0_PIN); |
| 258 | case 1: |
| 259 | return at91_get_pio_value(I2C1_PORT, SDA1_PIN); |
| 260 | } |
| 261 | return 1; |
| 262 | } |
| 263 | |
| 264 | void iic_sda(int bit) |
| 265 | { |
| 266 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 267 | case 0: |
| 268 | at91_set_pio_value(I2C0_PORT, SDA0_PIN, bit); |
| 269 | break; |
| 270 | case 1: |
| 271 | at91_set_pio_value(I2C1_PORT, SDA1_PIN, bit); |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | void iic_scl(int bit) |
| 277 | { |
| 278 | switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) { |
| 279 | case 0: |
| 280 | at91_set_pio_value(I2C0_PORT, SCL0_PIN, bit); |
| 281 | break; |
| 282 | case 1: |
| 283 | at91_set_pio_value(I2C1_PORT, SCL1_PIN, bit); |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | #endif |