blob: 98193bfdc6aa89596ea67651c46ff3695f59c702 [file] [log] [blame]
Stelian Pop78379932008-03-26 18:52:33 +01001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop78379932008-03-26 18:52:33 +01004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop78379932008-03-26 18:52:33 +01007 */
8
9#include <common.h>
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000010#include <asm/io.h>
Stelian Pop78379932008-03-26 18:52:33 +010011#include <asm/arch/at91sam9260_matrix.h>
Stelian Popd57846e2008-05-08 22:52:10 +020012#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD6b0b3db2009-03-21 21:07:59 +010013#include <asm/arch/at91_common.h>
Wenyou Yang78f89762016-02-03 10:16:50 +080014#include <asm/arch/clk.h>
Stelian Pop78379932008-03-26 18:52:33 +010015#include <asm/arch/gpio.h>
Wu, Josh1a500d62013-03-28 20:28:41 +000016#include <atmel_mci.h>
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000017
Stelian Pop78379932008-03-26 18:52:33 +010018#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000019# include <net.h>
Stelian Pop78379932008-03-26 18:52:33 +010020#endif
Ben Warren057d2022008-08-12 22:11:53 -070021#include <netdev.h>
Stelian Pop78379932008-03-26 18:52:33 +010022
23DECLARE_GLOBAL_DATA_PTR;
24
25/* ------------------------------------------------------------------------- */
26/*
27 * Miscelaneous platform dependent initialisations
28 */
29
Stelian Pop78379932008-03-26 18:52:33 +010030#ifdef CONFIG_CMD_NAND
31static void at91sam9260ek_nand_hw_init(void)
32{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000033 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
34 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop78379932008-03-26 18:52:33 +010035 unsigned long csa;
36
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000037 /* Assign CS3 to NAND/SmartMedia Interface */
38 csa = readl(&matrix->ebicsa);
39 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
40 writel(csa, &matrix->ebicsa);
Stelian Pop78379932008-03-26 18:52:33 +010041
42 /* Configure SMC CS3 for NAND/SmartMedia */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000043 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-VILLARD03836942008-10-16 15:01:15 +020053#ifdef CONFIG_SYS_NAND_DBW_16
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000054 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055#else /* CONFIG_SYS_NAND_DBW_8 */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000056 AT91_SMC_MODE_DBW_8 |
Stelian Popa35a4f82008-05-08 20:52:18 +020057#endif
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000058 AT91_SMC_MODE_TDF_CYCLE(2),
59 &smc->cs[3].mode);
Stelian Pop78379932008-03-26 18:52:33 +010060
61 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010062 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop78379932008-03-26 18:52:33 +010063
64 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010065 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000066
Stelian Pop78379932008-03-26 18:52:33 +010067}
68#endif
69
Stelian Pop78379932008-03-26 18:52:33 +010070#ifdef CONFIG_MACB
71static void at91sam9260ek_macb_hw_init(void)
72{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000073 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
Sedji Gaouaou419a5812009-06-24 08:32:09 +020074
Wenyou Yang78f89762016-02-03 10:16:50 +080075 at91_periph_clk_enable(ATMEL_ID_EMAC0);
Stelian Pop78379932008-03-26 18:52:33 +010076
77 /*
78 * Disable pull-up on:
79 * RXDV (PA17) => PHY normal mode (not Test mode)
Wolfgang Denka1be4762008-05-20 16:00:29 +020080 * ERX0 (PA14) => PHY ADDR0
Stelian Pop78379932008-03-26 18:52:33 +010081 * 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 Meyer0bda5f22011-06-06 00:13:10 +000089 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 Pop78379932008-03-26 18:52:33 +010095
Heiko Schocher8a84ae12013-11-18 08:07:23 +010096 at91_phy_reset();
Stelian Pop78379932008-03-26 18:52:33 +010097
98 /* Re-enable pull-up */
99 writel(pin_to_mask(AT91_PIN_PA14) |
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000100 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 Pop78379932008-03-26 18:52:33 +0100106
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000107 /* Initialize EMAC=MACB hardware */
Jean-Christophe PLAGNIOL-VILLARDfafa9232009-03-21 21:08:00 +0100108 at91_macb_hw_init();
Stelian Pop78379932008-03-26 18:52:33 +0100109}
110#endif
111
Wu, Josh1a500d62013-03-28 20:28:41 +0000112#ifdef CONFIG_GENERIC_ATMEL_MCI
113int 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 Meyer0bda5f22011-06-06 00:13:10 +0000121int board_early_init_f(void)
Stelian Pop78379932008-03-26 18:52:33 +0100122{
Wenyou Yang78f89762016-02-03 10:16:50 +0800123 at91_periph_clk_enable(ATMEL_ID_PIOA);
124 at91_periph_clk_enable(ATMEL_ID_PIOB);
125 at91_periph_clk_enable(ATMEL_ID_PIOC);
Stelian Pop78379932008-03-26 18:52:33 +0100126
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000127 return 0;
128}
129
130int board_init(void)
131{
Stelian Pop78379932008-03-26 18:52:33 +0100132 /* adress of boot parameters */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000133 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop78379932008-03-26 18:52:33 +0100134
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000135 at91_seriald_hw_init();
Stelian Pop78379932008-03-26 18:52:33 +0100136#ifdef CONFIG_CMD_NAND
137 at91sam9260ek_nand_hw_init();
138#endif
139#ifdef CONFIG_HAS_DATAFLASH
Albin Tonnerreacad29e2009-09-01 11:26:20 +0200140 at91_spi0_hw_init((1 << 0) | (1 << 1));
Stelian Pop78379932008-03-26 18:52:33 +0100141#endif
142#ifdef CONFIG_MACB
143 at91sam9260ek_macb_hw_init();
144#endif
145
146 return 0;
147}
148
149int dram_init(void)
150{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000151 gd->ram_size = get_ram_size(
152 (void *)CONFIG_SYS_SDRAM_BASE,
153 CONFIG_SYS_SDRAM_SIZE);
Stelian Pop78379932008-03-26 18:52:33 +0100154 return 0;
155}
156
157#ifdef CONFIG_RESET_PHY_R
158void reset_phy(void)
159{
Stelian Pop78379932008-03-26 18:52:33 +0100160}
161#endif
Ben Warren057d2022008-08-12 22:11:53 -0700162
163int board_eth_init(bd_t *bis)
164{
165 int rc = 0;
166#ifdef CONFIG_MACB
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000167 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
Ben Warren057d2022008-08-12 22:11:53 -0700168#endif
169 return rc;
170}