Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +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> |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * (C) Copyright 2008 Sergey Lapin <slapin@ossfans.org> |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/arch/at91sam9260.h> |
| 12 | #include <asm/arch/at91sam9260_matrix.h> |
| 13 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6b0b3db | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 14 | #include <asm/arch/at91_common.h> |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 15 | #include <asm/arch/at91_pmc.h> |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 16 | #include <asm/arch/gpio.h> |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 18 | #include <asm/arch/hardware.h> |
| 19 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB) |
| 20 | #include <netdev.h> |
| 21 | #include <net.h> |
| 22 | #endif |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | /* ------------------------------------------------------------------------- */ |
| 27 | /* |
| 28 | * Miscelaneous platform dependent initialisations |
| 29 | */ |
| 30 | |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 31 | static void afeb9260_nand_hw_init(void) |
| 32 | { |
| 33 | unsigned long csa; |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +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; |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 36 | |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +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); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 41 | |
| 42 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +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 | |
| 53 | AT91_SMC_MODE_DBW_8 | |
| 54 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 55 | &smc->cs[3].mode); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 56 | |
| 57 | /* Configure RDY/BSY */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 58 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 59 | |
| 60 | /* Enable NandFlash */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 61 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_MACB |
| 65 | static void afeb9260_macb_hw_init(void) |
| 66 | { |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 67 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 68 | struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA; |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | /* Enable EMAC clock */ |
| 72 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
Sedji Gaouaou | 419a581 | 2009-06-24 08:32:09 +0200 | [diff] [blame] | 73 | |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Disable pull-up on: |
| 77 | * RXDV (PA17) => PHY normal mode (not Test mode) |
| 78 | * ERX0 (PA14) => PHY ADDR0 |
| 79 | * ERX1 (PA15) => PHY ADDR1 |
| 80 | * ERX2 (PA25) => PHY ADDR2 |
| 81 | * ERX3 (PA26) => PHY ADDR3 |
| 82 | * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 |
| 83 | * |
| 84 | * PHY has internal pull-down |
| 85 | */ |
| 86 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 87 | pin_to_mask(AT91_PIN_PA15) | |
| 88 | pin_to_mask(AT91_PIN_PA17) | |
| 89 | pin_to_mask(AT91_PIN_PA25) | |
| 90 | pin_to_mask(AT91_PIN_PA26) | |
| 91 | pin_to_mask(AT91_PIN_PA28), |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 92 | &pioa->pudr); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 93 | |
Heiko Schocher | 8a84ae1 | 2013-11-18 08:07:23 +0100 | [diff] [blame^] | 94 | at91_phy_reset(); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 95 | |
| 96 | /* Re-enable pull-up */ |
| 97 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 98 | pin_to_mask(AT91_PIN_PA15) | |
| 99 | pin_to_mask(AT91_PIN_PA17) | |
| 100 | pin_to_mask(AT91_PIN_PA25) | |
| 101 | pin_to_mask(AT91_PIN_PA26) | |
| 102 | pin_to_mask(AT91_PIN_PA28), |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 103 | &pioa->puer); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 104 | |
Jean-Christophe PLAGNIOL-VILLARD | fafa923 | 2009-03-21 21:08:00 +0100 | [diff] [blame] | 105 | at91_macb_hw_init(); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 106 | } |
| 107 | #endif |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 108 | int board_early_init_f(void) |
| 109 | { |
| 110 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 111 | /* Enable clocks for all PIOs */ |
| 112 | writel((1 << ATMEL_ID_PIOA) | |
| 113 | (1 << ATMEL_ID_PIOB) | |
| 114 | (1 << ATMEL_ID_PIOC), |
| 115 | &pmc->pcer); |
| 116 | return 0; |
| 117 | } |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 118 | int board_init(void) |
| 119 | { |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 120 | /* arch number of AT91SAM9260EK-Board */ |
| 121 | gd->bd->bi_arch_number = MACH_TYPE_AFEB9260; |
| 122 | /* adress of boot parameters */ |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 123 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 124 | |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 125 | at91_seriald_hw_init(); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 126 | #ifdef CONFIG_CMD_NAND |
| 127 | afeb9260_nand_hw_init(); |
| 128 | #endif |
Albin Tonnerre | acad29e | 2009-09-01 11:26:20 +0200 | [diff] [blame] | 129 | at91_spi0_hw_init((1 << 0) | (1 << 1)); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 130 | #ifdef CONFIG_MACB |
| 131 | afeb9260_macb_hw_init(); |
| 132 | #endif |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int dram_init(void) |
| 138 | { |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 139 | gd->ram_size = get_ram_size( |
| 140 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 141 | CONFIG_SYS_SDRAM_SIZE); |
| 142 | |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | #ifdef CONFIG_RESET_PHY_R |
| 147 | void reset_phy(void) |
| 148 | { |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 149 | } |
| 150 | #endif |
| 151 | |
| 152 | int board_eth_init(bd_t *bis) |
| 153 | { |
| 154 | int rc = 0; |
| 155 | #ifdef CONFIG_MACB |
Sergey Lapin | 8f6ed2a | 2011-06-09 05:45:31 +0000 | [diff] [blame] | 156 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x01); |
Sergey Lapin | 77e524c | 2008-10-31 12:28:43 +0100 | [diff] [blame] | 157 | #endif |
| 158 | return rc; |
| 159 | } |