xref: /OK3568_Linux_fs/u-boot/board/egnite/ethernut5/ethernut5.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2011
3*4882a593Smuzhiyun  * egnite GmbH <info@egnite.de>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * (C) Copyright 2010
6*4882a593Smuzhiyun  * Ole Reinhardt <ole.reinhardt@thermotemp.de>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun  * Ethernut 5 general board support
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * Ethernut is an open source hardware and software project for
15*4882a593Smuzhiyun  * embedded Ethernet devices. Hardware layouts and CAD files are
16*4882a593Smuzhiyun  * freely available under BSD-like license.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * Ethernut 5 is the first member of the Ethernut board family
19*4882a593Smuzhiyun  * with U-Boot and Linux support. This implementation is based
20*4882a593Smuzhiyun  * on the original work done by Ole Reinhardt, but heavily modified
21*4882a593Smuzhiyun  * to support additional features and the latest board revision 5.0F.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Main board components are by default:
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Atmel AT91SAM9XE512 CPU with 512 kBytes NOR Flash
26*4882a593Smuzhiyun  * 2 x 64 MBytes Micron MT48LC32M16A2P SDRAM
27*4882a593Smuzhiyun  * 512 MBytes Micron MT29F4G08ABADA NAND Flash
28*4882a593Smuzhiyun  * 4 MBytes Atmel AT45DB321D DataFlash
29*4882a593Smuzhiyun  * SMSC LAN8710 Ethernet PHY
30*4882a593Smuzhiyun  * Atmel ATmega168 MCU used for power management
31*4882a593Smuzhiyun  * Linear Technology LTC4411 PoE controller
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * U-Boot relevant board interfaces are:
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * 100 Mbit Ethernet with IEEE 802.3af PoE
36*4882a593Smuzhiyun  * RS-232 serial port
37*4882a593Smuzhiyun  * USB host and device
38*4882a593Smuzhiyun  * MMC/SD-Card slot
39*4882a593Smuzhiyun  * Expansion port with I2C, SPI and more...
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * Typically the U-Boot image is loaded from serial DataFlash into
42*4882a593Smuzhiyun  * SDRAM by the samboot boot loader, which is located in internal
43*4882a593Smuzhiyun  * NOR Flash and provides all essential initializations like CPU
44*4882a593Smuzhiyun  * and peripheral clocks and, of course, the SDRAM configuration.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  * For testing purposes it is also possibly to directly transfer
47*4882a593Smuzhiyun  * the image into SDRAM via JTAG. A tested configuration exists
48*4882a593Smuzhiyun  * for the Turtelizer 2 hardware dongle and the OpenOCD software.
49*4882a593Smuzhiyun  * In this case the latter will do the basic hardware configuration
50*4882a593Smuzhiyun  * via its reset-init script.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * For additional information visit the project home page at
53*4882a593Smuzhiyun  * http://www.ethernut.de/
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #include <common.h>
57*4882a593Smuzhiyun #include <net.h>
58*4882a593Smuzhiyun #include <netdev.h>
59*4882a593Smuzhiyun #include <miiphy.h>
60*4882a593Smuzhiyun #include <i2c.h>
61*4882a593Smuzhiyun #include <mmc.h>
62*4882a593Smuzhiyun #include <atmel_mci.h>
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #include <asm/arch/at91sam9260.h>
65*4882a593Smuzhiyun #include <asm/arch/at91sam9260_matrix.h>
66*4882a593Smuzhiyun #include <asm/arch/at91sam9_smc.h>
67*4882a593Smuzhiyun #include <asm/arch/at91_common.h>
68*4882a593Smuzhiyun #include <asm/arch/clk.h>
69*4882a593Smuzhiyun #include <asm/arch/gpio.h>
70*4882a593Smuzhiyun #include <asm/io.h>
71*4882a593Smuzhiyun #include <asm/gpio.h>
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #include "ethernut5_pwrman.h"
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /*
78*4882a593Smuzhiyun  * This is called last during early initialization. Most of the basic
79*4882a593Smuzhiyun  * hardware interfaces are up and running.
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  * The SDRAM hardware has been configured by the first stage boot loader.
82*4882a593Smuzhiyun  * We only need to announce its size, using u-boot's memory check.
83*4882a593Smuzhiyun  */
dram_init(void)84*4882a593Smuzhiyun int dram_init(void)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun 	gd->ram_size = get_ram_size(
87*4882a593Smuzhiyun 			(void *)CONFIG_SYS_SDRAM_BASE,
88*4882a593Smuzhiyun 			CONFIG_SYS_SDRAM_SIZE);
89*4882a593Smuzhiyun 	return 0;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #ifdef CONFIG_CMD_NAND
ethernut5_nand_hw_init(void)93*4882a593Smuzhiyun static void ethernut5_nand_hw_init(void)
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun 	struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
96*4882a593Smuzhiyun 	struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
97*4882a593Smuzhiyun 	unsigned long csa;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	/* Assign CS3 to NAND/SmartMedia Interface */
100*4882a593Smuzhiyun 	csa = readl(&matrix->ebicsa);
101*4882a593Smuzhiyun 	csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
102*4882a593Smuzhiyun 	writel(csa, &matrix->ebicsa);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	/* Configure SMC CS3 for NAND/SmartMedia */
105*4882a593Smuzhiyun 	writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
106*4882a593Smuzhiyun 		AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
107*4882a593Smuzhiyun 		&smc->cs[3].setup);
108*4882a593Smuzhiyun 	writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
109*4882a593Smuzhiyun 		AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
110*4882a593Smuzhiyun 		&smc->cs[3].pulse);
111*4882a593Smuzhiyun 	writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
112*4882a593Smuzhiyun 		&smc->cs[3].cycle);
113*4882a593Smuzhiyun 	writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
114*4882a593Smuzhiyun 		AT91_SMC_MODE_EXNW_DISABLE |
115*4882a593Smuzhiyun 		AT91_SMC_MODE_DBW_8 |
116*4882a593Smuzhiyun 		AT91_SMC_MODE_TDF_CYCLE(2),
117*4882a593Smuzhiyun 		&smc->cs[3].mode);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #ifdef CONFIG_SYS_NAND_READY_PIN
120*4882a593Smuzhiyun 	/* Ready pin is optional. */
121*4882a593Smuzhiyun 	at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
122*4882a593Smuzhiyun #endif
123*4882a593Smuzhiyun 	gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun #endif
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /*
128*4882a593Smuzhiyun  * This is called first during late initialization.
129*4882a593Smuzhiyun  */
board_init(void)130*4882a593Smuzhiyun int board_init(void)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun 	at91_periph_clk_enable(ATMEL_ID_PIOA);
133*4882a593Smuzhiyun 	at91_periph_clk_enable(ATMEL_ID_PIOB);
134*4882a593Smuzhiyun 	at91_periph_clk_enable(ATMEL_ID_PIOC);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	/* Set adress of boot parameters. */
137*4882a593Smuzhiyun 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
138*4882a593Smuzhiyun 	/* Initialize UARTs and power management. */
139*4882a593Smuzhiyun 	ethernut5_power_init();
140*4882a593Smuzhiyun #ifdef CONFIG_CMD_NAND
141*4882a593Smuzhiyun 	ethernut5_nand_hw_init();
142*4882a593Smuzhiyun #endif
143*4882a593Smuzhiyun 	return 0;
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #ifdef CONFIG_MACB
147*4882a593Smuzhiyun /*
148*4882a593Smuzhiyun  * This is optionally called last during late initialization.
149*4882a593Smuzhiyun  */
board_eth_init(bd_t * bis)150*4882a593Smuzhiyun int board_eth_init(bd_t *bis)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	const char *devname;
153*4882a593Smuzhiyun 	unsigned short mode;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	at91_periph_clk_enable(ATMEL_ID_EMAC0);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	/* Need to reset PHY via power management. */
158*4882a593Smuzhiyun 	ethernut5_phy_reset();
159*4882a593Smuzhiyun 	/* Set peripheral pins. */
160*4882a593Smuzhiyun 	at91_macb_hw_init();
161*4882a593Smuzhiyun 	/* Basic EMAC initialization. */
162*4882a593Smuzhiyun 	if (macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, CONFIG_PHY_ID))
163*4882a593Smuzhiyun 		return -1;
164*4882a593Smuzhiyun 	/*
165*4882a593Smuzhiyun 	 * Early board revisions have a pull-down at the PHY's MODE0
166*4882a593Smuzhiyun 	 * strap pin, which forces the PHY into power down. Here we
167*4882a593Smuzhiyun 	 * switch to all-capable mode.
168*4882a593Smuzhiyun 	 */
169*4882a593Smuzhiyun 	devname = miiphy_get_current_dev();
170*4882a593Smuzhiyun 	if (miiphy_read(devname, 0, 18, &mode) == 0) {
171*4882a593Smuzhiyun 		/* Set mode[2:0] to 0b111. */
172*4882a593Smuzhiyun 		mode |= 0x00E0;
173*4882a593Smuzhiyun 		miiphy_write(devname, 0, 18, mode);
174*4882a593Smuzhiyun 		/* Soft reset overrides strap pins. */
175*4882a593Smuzhiyun 		miiphy_write(devname, 0, MII_BMCR, BMCR_RESET);
176*4882a593Smuzhiyun 	}
177*4882a593Smuzhiyun 	/* Sync environment with network devices, needed for nfsroot. */
178*4882a593Smuzhiyun 	return eth_init();
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun #endif
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_ATMEL_MCI
board_mmc_init(bd_t * bd)183*4882a593Smuzhiyun int board_mmc_init(bd_t *bd)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun 	at91_periph_clk_enable(ATMEL_ID_MCI);
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	/* Initialize MCI hardware. */
188*4882a593Smuzhiyun 	at91_mci_hw_init();
189*4882a593Smuzhiyun 	/* Register the device. */
190*4882a593Smuzhiyun 	return atmel_mci_init((void *)ATMEL_BASE_MCI);
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun 
board_mmc_getcd(struct mmc * mmc)193*4882a593Smuzhiyun int board_mmc_getcd(struct mmc *mmc)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun 	return !at91_get_pio_value(CONFIG_SYS_MMC_CD_PIN);
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun #endif
198