Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [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> |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
| 6 | * Copyright (C) 2009 |
| 7 | * Albin Tonnerre, Free-Electrons <albin.tonnerre@free-electrons.com> |
| 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 14 | #include <asm/arch/at91sam9260_matrix.h> |
| 15 | #include <asm/arch/at91sam9_smc.h> |
| 16 | #include <asm/arch/at91_common.h> |
| 17 | #include <asm/arch/at91_pmc.h> |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 18 | #include <asm/arch/gpio.h> |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 19 | |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 20 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB) |
| 21 | #include <net.h> |
| 22 | #endif |
| 23 | #include <netdev.h> |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | /* ------------------------------------------------------------------------- */ |
| 28 | /* |
| 29 | * Miscelaneous platform dependent initialisations |
| 30 | */ |
| 31 | |
| 32 | #ifdef CONFIG_CMD_NAND |
| 33 | static void sbc35_a9g20_nand_hw_init(void) |
| 34 | { |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 35 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 36 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 37 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 38 | unsigned long csa; |
| 39 | |
| 40 | /* Enable CS3 */ |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 41 | csa = readl(&matrix->ebicsa); |
| 42 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 43 | writel(csa, &matrix->ebicsa); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 44 | |
| 45 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 46 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 47 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 48 | &smc->cs[3].setup); |
| 49 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 50 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 51 | &smc->cs[3].pulse); |
| 52 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 53 | &smc->cs[3].cycle); |
| 54 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 55 | AT91_SMC_MODE_EXNW_DISABLE | |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 57 | AT91_SMC_MODE_DBW_16 | |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 58 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 59 | AT91_SMC_MODE_DBW_8 | |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 60 | #endif |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 61 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 62 | &smc->cs[3].mode); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 63 | |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 64 | writel(1 << ATMEL_ID_PIOC, &pmc->pcer); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 65 | |
| 66 | /* Configure RDY/BSY */ |
| 67 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
| 68 | |
| 69 | /* Enable NandFlash */ |
| 70 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | #ifdef CONFIG_MACB |
| 75 | static void sbc35_a9g20_macb_hw_init(void) |
| 76 | { |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 77 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 78 | struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA; |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 79 | |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 80 | /* Enable EMAC clock */ |
| 81 | writel(1 << ATMEL_ID_EMAC0, &pmc->pcer); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Disable pull-up on: |
| 85 | * RXDV (PA17) => PHY normal mode (not Test mode) |
| 86 | * ERX0 (PA14) => PHY ADDR0 |
| 87 | * ERX1 (PA15) => PHY ADDR1 |
| 88 | * ERX2 (PA25) => PHY ADDR2 |
| 89 | * ERX3 (PA26) => PHY ADDR3 |
| 90 | * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0 |
| 91 | * |
| 92 | * PHY has internal pull-down |
| 93 | */ |
| 94 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 95 | pin_to_mask(AT91_PIN_PA15) | |
| 96 | pin_to_mask(AT91_PIN_PA17) | |
| 97 | pin_to_mask(AT91_PIN_PA25) | |
| 98 | pin_to_mask(AT91_PIN_PA26) | |
| 99 | pin_to_mask(AT91_PIN_PA28), |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 100 | &pioa->pudr); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 101 | |
Heiko Schocher | 8a84ae1 | 2013-11-18 08:07:23 +0100 | [diff] [blame^] | 102 | at91_phy_reset(); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 103 | |
| 104 | /* Re-enable pull-up */ |
| 105 | writel(pin_to_mask(AT91_PIN_PA14) | |
| 106 | pin_to_mask(AT91_PIN_PA15) | |
| 107 | pin_to_mask(AT91_PIN_PA17) | |
| 108 | pin_to_mask(AT91_PIN_PA25) | |
| 109 | pin_to_mask(AT91_PIN_PA26) | |
| 110 | pin_to_mask(AT91_PIN_PA28), |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 111 | &pioa->puer); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 112 | |
| 113 | at91_macb_hw_init(); |
| 114 | } |
| 115 | #endif |
| 116 | |
| 117 | int board_init(void) |
| 118 | { |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 119 | /* adress of boot parameters */ |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 120 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 121 | |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 122 | at91_seriald_hw_init(); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 123 | sbc35_a9g20_nand_hw_init(); |
| 124 | #ifdef CONFIG_ATMEL_SPI |
| 125 | at91_spi0_hw_init(1 << 4 | 1 << 5); |
| 126 | #endif |
| 127 | #ifdef CONFIG_MACB |
| 128 | sbc35_a9g20_macb_hw_init(); |
| 129 | #endif |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int dram_init(void) |
| 135 | { |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 136 | gd->ram_size = get_ram_size( |
| 137 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 138 | CONFIG_SYS_SDRAM_SIZE); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | #ifdef CONFIG_RESET_PHY_R |
| 143 | void reset_phy(void) |
| 144 | { |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 145 | } |
| 146 | #endif |
| 147 | |
| 148 | int board_eth_init(bd_t *bis) |
| 149 | { |
| 150 | int rc = 0; |
| 151 | #ifdef CONFIG_MACB |
Thomas Petazzoni | 740fcb6 | 2011-08-04 02:22:20 +0000 | [diff] [blame] | 152 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00); |
Albin Tonnerre | 4f572d8 | 2009-08-24 18:03:26 +0200 | [diff] [blame] | 153 | #endif |
| 154 | return rc; |
| 155 | } |