Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [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> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 11 | #include <asm/arch/at91sam9260_matrix.h> |
Stelian Pop | d57846e | 2008-05-08 22:52:10 +0200 | [diff] [blame] | 12 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6b0b3db | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 13 | #include <asm/arch/at91_common.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 14 | #include <asm/arch/at91_pmc.h> |
| 15 | #include <asm/arch/at91_rstc.h> |
| 16 | #include <asm/arch/gpio.h> |
Wu, Josh | 1a500d6 | 2013-03-28 20:28:41 +0000 | [diff] [blame] | 17 | #include <atmel_mci.h> |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 18 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 19 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB) |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 20 | # include <net.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 21 | #endif |
Ben Warren | 057d202 | 2008-08-12 22:11:53 -0700 | [diff] [blame] | 22 | #include <netdev.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | /* ------------------------------------------------------------------------- */ |
| 27 | /* |
| 28 | * Miscelaneous platform dependent initialisations |
| 29 | */ |
| 30 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 31 | #ifdef CONFIG_CMD_NAND |
| 32 | static void at91sam9260ek_nand_hw_init(void) |
| 33 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 34 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 35 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 36 | unsigned long csa; |
| 37 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 38 | /* Assign CS3 to NAND/SmartMedia Interface */ |
| 39 | csa = readl(&matrix->ebicsa); |
| 40 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 41 | writel(csa, &matrix->ebicsa); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 42 | |
| 43 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 44 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 45 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 46 | &smc->cs[3].setup); |
| 47 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 48 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 49 | &smc->cs[3].pulse); |
| 50 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 51 | &smc->cs[3].cycle); |
| 52 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 53 | AT91_SMC_MODE_EXNW_DISABLE | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 55 | AT91_SMC_MODE_DBW_16 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 57 | AT91_SMC_MODE_DBW_8 | |
Stelian Pop | a35a4f8 | 2008-05-08 20:52:18 +0200 | [diff] [blame] | 58 | #endif |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 59 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 60 | &smc->cs[3].mode); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 61 | |
| 62 | /* Configure RDY/BSY */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 63 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 64 | |
| 65 | /* Enable NandFlash */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 66 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 67 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 68 | } |
| 69 | #endif |
| 70 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 71 | #ifdef CONFIG_MACB |
| 72 | static void at91sam9260ek_macb_hw_init(void) |
| 73 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 74 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 75 | struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA; |
| 76 | struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC; |
| 77 | unsigned long erstl; |
Sedji Gaouaou | 419a581 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 78 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 79 | /* Enable EMAC clock */ |
| 80 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Disable pull-up on: |
| 84 | * RXDV (PA17) => PHY normal mode (not Test mode) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 85 | * ERX0 (PA14) => PHY ADDR0 |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 86 | * ERX1 (PA15) => PHY ADDR1 |
| 87 | * ERX2 (PA25) => PHY ADDR2 |
| 88 | * ERX3 (PA26) => PHY ADDR3 |
| 89 | * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 |
| 90 | * |
| 91 | * PHY has internal pull-down |
| 92 | */ |
| 93 | writel(pin_to_mask(AT91_PIN_PA14) | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 94 | pin_to_mask(AT91_PIN_PA15) | |
| 95 | pin_to_mask(AT91_PIN_PA17) | |
| 96 | pin_to_mask(AT91_PIN_PA25) | |
| 97 | pin_to_mask(AT91_PIN_PA26) | |
| 98 | pin_to_mask(AT91_PIN_PA28), |
| 99 | &pioa->pudr); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 100 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 101 | erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK; |
Sedji Gaouaou | 419a581 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 102 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 103 | /* Need to reset PHY -> 500ms reset */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 104 | writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) | |
| 105 | AT91_RSTC_MR_URSTEN, &rstc->mr); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 106 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 107 | writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 108 | |
| 109 | /* Wait for end hardware reset */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 110 | while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) |
| 111 | ; |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 112 | |
| 113 | /* Restore NRST value */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 114 | writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, |
| 115 | &rstc->mr); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 116 | |
| 117 | /* Re-enable pull-up */ |
| 118 | writel(pin_to_mask(AT91_PIN_PA14) | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 119 | pin_to_mask(AT91_PIN_PA15) | |
| 120 | pin_to_mask(AT91_PIN_PA17) | |
| 121 | pin_to_mask(AT91_PIN_PA25) | |
| 122 | pin_to_mask(AT91_PIN_PA26) | |
| 123 | pin_to_mask(AT91_PIN_PA28), |
| 124 | &pioa->puer); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 125 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 126 | /* Initialize EMAC=MACB hardware */ |
Jean-Christophe PLAGNIOL-VILLARD | fafa923 | 2009-03-21 21:08:00 +0100 | [diff] [blame] | 127 | at91_macb_hw_init(); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 128 | } |
| 129 | #endif |
| 130 | |
Wu, Josh | 1a500d6 | 2013-03-28 20:28:41 +0000 | [diff] [blame] | 131 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 132 | int board_mmc_init(bd_t *bd) |
| 133 | { |
| 134 | at91_mci_hw_init(); |
| 135 | |
| 136 | return atmel_mci_init((void *)ATMEL_BASE_MCI); |
| 137 | } |
| 138 | #endif |
| 139 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 140 | int board_early_init_f(void) |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 141 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 142 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 143 | |
| 144 | /* Enable clocks for all PIOs */ |
| 145 | writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) | |
| 146 | (1 << ATMEL_ID_PIOC), |
| 147 | &pmc->pcer); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 148 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int board_init(void) |
| 153 | { |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 154 | /* adress of boot parameters */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 155 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 156 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 157 | at91_seriald_hw_init(); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_CMD_NAND |
| 159 | at91sam9260ek_nand_hw_init(); |
| 160 | #endif |
| 161 | #ifdef CONFIG_HAS_DATAFLASH |
Albin Tonnerre | acad29e | 2009-09-01 11:26:20 +0200 | [diff] [blame] | 162 | at91_spi0_hw_init((1 << 0) | (1 << 1)); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 163 | #endif |
| 164 | #ifdef CONFIG_MACB |
| 165 | at91sam9260ek_macb_hw_init(); |
| 166 | #endif |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int dram_init(void) |
| 172 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 173 | gd->ram_size = get_ram_size( |
| 174 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 175 | CONFIG_SYS_SDRAM_SIZE); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | #ifdef CONFIG_RESET_PHY_R |
| 180 | void reset_phy(void) |
| 181 | { |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 182 | } |
| 183 | #endif |
Ben Warren | 057d202 | 2008-08-12 22:11:53 -0700 | [diff] [blame] | 184 | |
| 185 | int board_eth_init(bd_t *bis) |
| 186 | { |
| 187 | int rc = 0; |
| 188 | #ifdef CONFIG_MACB |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 189 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00); |
Ben Warren | 057d202 | 2008-08-12 22:11:53 -0700 | [diff] [blame] | 190 | #endif |
| 191 | return rc; |
| 192 | } |