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> |
Wenyou Yang | 70341e2 | 2016-02-03 10:16:50 +0800 | [diff] [blame^] | 14 | #include <asm/arch/clk.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_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA; |
Sedji Gaouaou | 0aafde1 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 74 | |
Wenyou Yang | 70341e2 | 2016-02-03 10:16:50 +0800 | [diff] [blame^] | 75 | at91_periph_clk_enable(ATMEL_ID_EMAC0); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Disable pull-up on: |
| 79 | * RXDV (PA17) => PHY normal mode (not Test mode) |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 80 | * ERX0 (PA14) => PHY ADDR0 |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 81 | * ERX1 (PA15) => PHY ADDR1 |
| 82 | * ERX2 (PA25) => PHY ADDR2 |
| 83 | * ERX3 (PA26) => PHY ADDR3 |
| 84 | * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 |
| 85 | * |
| 86 | * PHY has internal pull-down |
| 87 | */ |
| 88 | writel(pin_to_mask(AT91_PIN_PA14) | |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 89 | pin_to_mask(AT91_PIN_PA15) | |
| 90 | pin_to_mask(AT91_PIN_PA17) | |
| 91 | pin_to_mask(AT91_PIN_PA25) | |
| 92 | pin_to_mask(AT91_PIN_PA26) | |
| 93 | pin_to_mask(AT91_PIN_PA28), |
| 94 | &pioa->pudr); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 95 | |
Heiko Schocher | 4535a24 | 2013-11-18 08:07:23 +0100 | [diff] [blame] | 96 | at91_phy_reset(); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 97 | |
| 98 | /* Re-enable pull-up */ |
| 99 | writel(pin_to_mask(AT91_PIN_PA14) | |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 100 | pin_to_mask(AT91_PIN_PA15) | |
| 101 | pin_to_mask(AT91_PIN_PA17) | |
| 102 | pin_to_mask(AT91_PIN_PA25) | |
| 103 | pin_to_mask(AT91_PIN_PA26) | |
| 104 | pin_to_mask(AT91_PIN_PA28), |
| 105 | &pioa->puer); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 106 | |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 107 | /* Initialize EMAC=MACB hardware */ |
Jean-Christophe PLAGNIOL-VILLARD | e2c0476 | 2009-03-21 21:08:00 +0100 | [diff] [blame] | 108 | at91_macb_hw_init(); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 109 | } |
| 110 | #endif |
| 111 | |
Wu, Josh | a73267a | 2013-03-28 20:28:41 +0000 | [diff] [blame] | 112 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 113 | int board_mmc_init(bd_t *bd) |
| 114 | { |
| 115 | at91_mci_hw_init(); |
| 116 | |
| 117 | return atmel_mci_init((void *)ATMEL_BASE_MCI); |
| 118 | } |
| 119 | #endif |
| 120 | |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 121 | int board_early_init_f(void) |
| 122 | { |
Wenyou Yang | 70341e2 | 2016-02-03 10:16:50 +0800 | [diff] [blame^] | 123 | at91_periph_clk_enable(ATMEL_ID_PIOA); |
| 124 | at91_periph_clk_enable(ATMEL_ID_PIOB); |
| 125 | at91_periph_clk_enable(ATMEL_ID_PIOC); |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 130 | int board_init(void) |
| 131 | { |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 132 | /* adress of boot parameters */ |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 133 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 134 | |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 135 | at91_seriald_hw_init(); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_CMD_NAND |
| 137 | at91sam9260ek_nand_hw_init(); |
| 138 | #endif |
| 139 | #ifdef CONFIG_HAS_DATAFLASH |
Albin Tonnerre | 50b5fff | 2009-09-01 11:26:20 +0200 | [diff] [blame] | 140 | at91_spi0_hw_init((1 << 0) | (1 << 1)); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 141 | #endif |
| 142 | #ifdef CONFIG_MACB |
| 143 | at91sam9260ek_macb_hw_init(); |
| 144 | #endif |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | int dram_init(void) |
| 150 | { |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 151 | gd->ram_size = get_ram_size( |
| 152 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 153 | CONFIG_SYS_SDRAM_SIZE); |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | #ifdef CONFIG_RESET_PHY_R |
| 158 | void reset_phy(void) |
| 159 | { |
Stelian Pop | 0176d43 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 160 | } |
| 161 | #endif |
Ben Warren | 3ae071e | 2008-08-12 22:11:53 -0700 | [diff] [blame] | 162 | |
| 163 | int board_eth_init(bd_t *bis) |
| 164 | { |
| 165 | int rc = 0; |
| 166 | #ifdef CONFIG_MACB |
Reinhard Meyer | 8c6407f | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 167 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00); |
Ben Warren | 3ae071e | 2008-08-12 22:11:53 -0700 | [diff] [blame] | 168 | #endif |
| 169 | return rc; |
| 170 | } |