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