1 /* 2 * Board functions for Siemens TAURUS (AT91SAM9G20) based boards 3 * (C) Copyright Siemens AG 4 * 5 * Based on: 6 * U-Boot file: board/atmel/at91sam9260ek/at91sam9260ek.c 7 * 8 * (C) Copyright 2007-2008 9 * Stelian Pop <stelian@popies.net> 10 * Lead Tech Design <www.leadtechdesign.com> 11 * 12 * SPDX-License-Identifier: GPL-2.0+ 13 */ 14 15 #include <common.h> 16 #include <asm/io.h> 17 #include <asm/arch/at91sam9260_matrix.h> 18 #include <asm/arch/at91sam9_smc.h> 19 #include <asm/arch/at91_common.h> 20 #include <asm/arch/at91_pmc.h> 21 #include <asm/arch/at91_rstc.h> 22 #include <asm/arch/gpio.h> 23 #include <asm/arch/at91sam9_sdramc.h> 24 #include <atmel_mci.h> 25 #include <asm/arch/at91_spi.h> 26 #include <spi.h> 27 28 #include <net.h> 29 #include <netdev.h> 30 31 DECLARE_GLOBAL_DATA_PTR; 32 33 #ifdef CONFIG_CMD_NAND 34 static void taurus_nand_hw_init(void) 35 { 36 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; 37 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; 38 unsigned long csa; 39 40 /* Assign CS3 to NAND/SmartMedia Interface */ 41 csa = readl(&matrix->ebicsa); 42 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; 43 writel(csa, &matrix->ebicsa); 44 45 /* Configure SMC CS3 for NAND/SmartMedia */ 46 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) | 47 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0), 48 &smc->cs[3].setup); 49 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) | 50 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(3), 51 &smc->cs[3].pulse); 52 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7), 53 &smc->cs[3].cycle); 54 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | 55 AT91_SMC_MODE_EXNW_DISABLE | 56 AT91_SMC_MODE_DBW_8 | 57 AT91_SMC_MODE_TDF_CYCLE(3), 58 &smc->cs[3].mode); 59 60 /* Configure RDY/BSY */ 61 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); 62 63 /* Enable NandFlash */ 64 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); 65 } 66 #endif 67 68 #ifdef CONFIG_MACB 69 static void taurus_macb_hw_init(void) 70 { 71 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; 72 73 /* Enable EMAC clock */ 74 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); 75 76 /* 77 * Disable pull-up on: 78 * RXDV (PA17) => PHY normal mode (not Test mode) 79 * ERX0 (PA14) => PHY ADDR0 80 * ERX1 (PA15) => PHY ADDR1 81 * ERX2 (PA25) => PHY ADDR2 82 * ERX3 (PA26) => PHY ADDR3 83 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 84 * 85 * PHY has internal pull-down 86 */ 87 at91_set_pio_pullup(AT91_PIO_PORTA, 14, 0); 88 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0); 89 at91_set_pio_pullup(AT91_PIO_PORTA, 17, 0); 90 at91_set_pio_pullup(AT91_PIO_PORTA, 25, 0); 91 at91_set_pio_pullup(AT91_PIO_PORTA, 26, 0); 92 at91_set_pio_pullup(AT91_PIO_PORTA, 28, 0); 93 94 at91_phy_reset(); 95 96 at91_set_gpio_input(AT91_PIN_PA25, 1); /* ERST tri-state */ 97 98 /* Re-enable pull-up */ 99 at91_set_pio_pullup(AT91_PIO_PORTA, 14, 1); 100 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1); 101 at91_set_pio_pullup(AT91_PIO_PORTA, 17, 1); 102 at91_set_pio_pullup(AT91_PIO_PORTA, 25, 1); 103 at91_set_pio_pullup(AT91_PIO_PORTA, 26, 1); 104 at91_set_pio_pullup(AT91_PIO_PORTA, 28, 1); 105 106 /* Initialize EMAC=MACB hardware */ 107 at91_macb_hw_init(); 108 } 109 #endif 110 111 #ifdef CONFIG_GENERIC_ATMEL_MCI 112 int board_mmc_init(bd_t *bd) 113 { 114 at91_mci_hw_init(); 115 116 return atmel_mci_init((void *)ATMEL_BASE_MCI); 117 } 118 #endif 119 120 int board_early_init_f(void) 121 { 122 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; 123 124 /* Enable clocks for all PIOs */ 125 writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) | 126 (1 << ATMEL_ID_PIOC), 127 &pmc->pcer); 128 129 return 0; 130 } 131 132 int spi_cs_is_valid(unsigned int bus, unsigned int cs) 133 { 134 return bus == 0 && cs == 0; 135 } 136 137 void spi_cs_activate(struct spi_slave *slave) 138 { 139 at91_set_gpio_value(TAURUS_SPI_CS_PIN, 0); 140 } 141 142 void spi_cs_deactivate(struct spi_slave *slave) 143 { 144 at91_set_gpio_value(TAURUS_SPI_CS_PIN, 1); 145 } 146 147 int board_init(void) 148 { 149 /* adress of boot parameters */ 150 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; 151 152 at91_seriald_hw_init(); 153 #ifdef CONFIG_CMD_NAND 154 taurus_nand_hw_init(); 155 #endif 156 #ifdef CONFIG_MACB 157 taurus_macb_hw_init(); 158 #endif 159 at91_spi0_hw_init(TAURUS_SPI_MASK); 160 161 return 0; 162 } 163 164 int dram_init(void) 165 { 166 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, 167 CONFIG_SYS_SDRAM_SIZE); 168 return 0; 169 } 170 171 int board_eth_init(bd_t *bis) 172 { 173 int rc = 0; 174 #ifdef CONFIG_MACB 175 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00); 176 #endif 177 return rc; 178 } 179