xref: /rk3399_rockchip-uboot/board/l+g/vinco/vinco.c (revision b7b24a7a3cd74bb165d28a2959ed9143e3648fbf)
1522e4fbbSGregory CLEMENT /*
2522e4fbbSGregory CLEMENT  * Board file for the VInCo platform
3522e4fbbSGregory CLEMENT  * Based on the the SAMA5-EK board file
4522e4fbbSGregory CLEMENT  * Configuration settings for the VInCo platform.
5522e4fbbSGregory CLEMENT  * Copyright (C) 2014 Atmel
6522e4fbbSGregory CLEMENT  *		      Bo Shen <voice.shen@atmel.com>
7522e4fbbSGregory CLEMENT  * Copyright (C) 2015 Free Electrons
8522e4fbbSGregory CLEMENT  *		      Gregory CLEMENT <gregory.clement@free-electrons.com>
9522e4fbbSGregory CLEMENT  *
10522e4fbbSGregory CLEMENT  * SPDX-License-Identifier:	GPL-2.0+
11522e4fbbSGregory CLEMENT  */
12522e4fbbSGregory CLEMENT 
13522e4fbbSGregory CLEMENT #include <common.h>
14522e4fbbSGregory CLEMENT #include <asm/io.h>
15522e4fbbSGregory CLEMENT #include <asm/arch/at91_common.h>
16522e4fbbSGregory CLEMENT #include <asm/arch/at91_pmc.h>
17522e4fbbSGregory CLEMENT #include <asm/arch/at91_rstc.h>
18522e4fbbSGregory CLEMENT #include <asm/arch/atmel_mpddrc.h>
19522e4fbbSGregory CLEMENT #include <asm/arch/atmel_usba_udc.h>
20522e4fbbSGregory CLEMENT #include <asm/arch/gpio.h>
21522e4fbbSGregory CLEMENT #include <asm/arch/clk.h>
22522e4fbbSGregory CLEMENT #include <asm/arch/sama5d3_smc.h>
23522e4fbbSGregory CLEMENT #include <asm/arch/sama5d4.h>
24522e4fbbSGregory CLEMENT #include <atmel_hlcdc.h>
25522e4fbbSGregory CLEMENT #include <atmel_mci.h>
26522e4fbbSGregory CLEMENT #include <lcd.h>
27522e4fbbSGregory CLEMENT #include <mmc.h>
28522e4fbbSGregory CLEMENT #include <net.h>
29522e4fbbSGregory CLEMENT #include <netdev.h>
30522e4fbbSGregory CLEMENT #include <nand.h>
31522e4fbbSGregory CLEMENT #include <spi.h>
32522e4fbbSGregory CLEMENT #include <version.h>
33522e4fbbSGregory CLEMENT 
34522e4fbbSGregory CLEMENT DECLARE_GLOBAL_DATA_PTR;
35522e4fbbSGregory CLEMENT 
36522e4fbbSGregory CLEMENT #ifdef CONFIG_ATMEL_SPI
spi_cs_is_valid(unsigned int bus,unsigned int cs)37522e4fbbSGregory CLEMENT int spi_cs_is_valid(unsigned int bus, unsigned int cs)
38522e4fbbSGregory CLEMENT {
39522e4fbbSGregory CLEMENT 	return bus == 0 && cs == 0;
40522e4fbbSGregory CLEMENT }
41522e4fbbSGregory CLEMENT 
spi_cs_activate(struct spi_slave * slave)42522e4fbbSGregory CLEMENT void spi_cs_activate(struct spi_slave *slave)
43522e4fbbSGregory CLEMENT {
44522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
45522e4fbbSGregory CLEMENT }
46522e4fbbSGregory CLEMENT 
spi_cs_deactivate(struct spi_slave * slave)47522e4fbbSGregory CLEMENT void spi_cs_deactivate(struct spi_slave *slave)
48522e4fbbSGregory CLEMENT {
49522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
50522e4fbbSGregory CLEMENT }
51522e4fbbSGregory CLEMENT 
vinco_spi0_hw_init(void)52522e4fbbSGregory CLEMENT static void vinco_spi0_hw_init(void)
53522e4fbbSGregory CLEMENT {
54*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0);	/* SPI0_MISO */
55*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0);	/* SPI0_MOSI */
56*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0);	/* SPI0_SPCK */
57522e4fbbSGregory CLEMENT 
58522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTC, 3, 1);	/* SPI0_CS0 */
59522e4fbbSGregory CLEMENT 
60522e4fbbSGregory CLEMENT 	/* Enable clock */
61522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_SPI0);
62522e4fbbSGregory CLEMENT }
63522e4fbbSGregory CLEMENT #endif /* CONFIG_ATMEL_SPI */
64522e4fbbSGregory CLEMENT 
65522e4fbbSGregory CLEMENT 
66522e4fbbSGregory CLEMENT #ifdef CONFIG_CMD_USB
vinco_usb_hw_init(void)67522e4fbbSGregory CLEMENT static void vinco_usb_hw_init(void)
68522e4fbbSGregory CLEMENT {
69522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
70522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
71522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
72522e4fbbSGregory CLEMENT }
73522e4fbbSGregory CLEMENT #endif
74522e4fbbSGregory CLEMENT 
75522e4fbbSGregory CLEMENT 
76522e4fbbSGregory CLEMENT #ifdef CONFIG_GENERIC_ATMEL_MCI
vinco_mci0_hw_init(void)77522e4fbbSGregory CLEMENT void vinco_mci0_hw_init(void)
78522e4fbbSGregory CLEMENT {
79*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1);	/* MCI0 CDA */
80*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1);	/* MCI0 DA0 */
81*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1);	/* MCI0 DA1 */
82*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1);	/* MCI0 DA2 */
83*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1);	/* MCI0 DA3 */
84*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1);	/* MCI0 DA4 */
85*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1);	/* MCI0 DA5 */
86*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1);	/* MCI0 DA6 */
87*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1);	/* MCI0 DA7 */
88*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0);	/* MCI0 CLK */
89522e4fbbSGregory CLEMENT 
90522e4fbbSGregory CLEMENT 	/*
91522e4fbbSGregory CLEMENT 	 * As the mci io internal pull down is too strong, so if the io needs
92522e4fbbSGregory CLEMENT 	 * external pull up, the pull up resistor will be very small, if so
93522e4fbbSGregory CLEMENT 	 * the power consumption will increase, so disable the interanl pull
94522e4fbbSGregory CLEMENT 	 * down to save the power.
95522e4fbbSGregory CLEMENT 	 */
96*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
97*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
98*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
99*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
100*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
101*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
102*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
103*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
104*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
105*2dc63f73SWenyou Yang 	at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
106522e4fbbSGregory CLEMENT 
107522e4fbbSGregory CLEMENT 	/* Enable clock */
108522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_MCI0);
109522e4fbbSGregory CLEMENT }
110522e4fbbSGregory CLEMENT 
board_mmc_init(bd_t * bis)111522e4fbbSGregory CLEMENT int board_mmc_init(bd_t *bis)
112522e4fbbSGregory CLEMENT {
113522e4fbbSGregory CLEMENT 	/* Enable power for MCI0 interface */
114522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTE, 7, 1);
115522e4fbbSGregory CLEMENT 
116522e4fbbSGregory CLEMENT 	return atmel_mci_init((void *)ATMEL_BASE_MCI0);
117522e4fbbSGregory CLEMENT }
118522e4fbbSGregory CLEMENT #endif /* CONFIG_GENERIC_ATMEL_MCI */
119522e4fbbSGregory CLEMENT 
120522e4fbbSGregory CLEMENT #ifdef CONFIG_MACB
vinco_macb0_hw_init(void)121522e4fbbSGregory CLEMENT void vinco_macb0_hw_init(void)
122522e4fbbSGregory CLEMENT {
123*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0);	/* ETXCK_EREFCK */
124*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0);	/* ERXDV */
125*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0);	/* ERX0 */
126*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0);	/* ERX1 */
127*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0);	/* ERXER */
128*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0);	/* ETXEN */
129*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0);	/* ETX0 */
130*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0);	/* ETX1 */
131*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0);	/* EMDIO */
132*2dc63f73SWenyou Yang 	at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0);	/* EMDC */
133522e4fbbSGregory CLEMENT 
134522e4fbbSGregory CLEMENT 	/* Enable clock */
135522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_GMAC0);
136522e4fbbSGregory CLEMENT 
137522e4fbbSGregory CLEMENT 	/* Enable Phy*/
138522e4fbbSGregory CLEMENT 	at91_set_pio_output(AT91_PIO_PORTE, 8, 1);
139522e4fbbSGregory CLEMENT }
140522e4fbbSGregory CLEMENT #endif
141522e4fbbSGregory CLEMENT 
vinco_serial3_hw_init(void)142522e4fbbSGregory CLEMENT static void vinco_serial3_hw_init(void)
143522e4fbbSGregory CLEMENT {
144*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1);	/* TXD3 */
145*2dc63f73SWenyou Yang 	at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0);	/* RXD3 */
146522e4fbbSGregory CLEMENT 
147522e4fbbSGregory CLEMENT 	/* Enable clock */
148522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_USART3);
149522e4fbbSGregory CLEMENT }
150522e4fbbSGregory CLEMENT 
board_early_init_f(void)151522e4fbbSGregory CLEMENT int board_early_init_f(void)
152522e4fbbSGregory CLEMENT {
153522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_PIOA);
154522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_PIOB);
155522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_PIOC);
156522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_PIOD);
157522e4fbbSGregory CLEMENT 	at91_periph_clk_enable(ATMEL_ID_PIOE);
158522e4fbbSGregory CLEMENT 
159522e4fbbSGregory CLEMENT 	vinco_serial3_hw_init();
160522e4fbbSGregory CLEMENT 
161522e4fbbSGregory CLEMENT 	return 0;
162522e4fbbSGregory CLEMENT }
163522e4fbbSGregory CLEMENT 
board_init(void)164522e4fbbSGregory CLEMENT int board_init(void)
165522e4fbbSGregory CLEMENT {
166522e4fbbSGregory CLEMENT 	/* adress of boot parameters */
167522e4fbbSGregory CLEMENT 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
168522e4fbbSGregory CLEMENT 
169522e4fbbSGregory CLEMENT #ifdef CONFIG_ATMEL_SPI
170522e4fbbSGregory CLEMENT 	vinco_spi0_hw_init();
171522e4fbbSGregory CLEMENT #endif
172522e4fbbSGregory CLEMENT 
173522e4fbbSGregory CLEMENT #ifdef CONFIG_GENERIC_ATMEL_MCI
174522e4fbbSGregory CLEMENT 	vinco_mci0_hw_init();
175522e4fbbSGregory CLEMENT #endif
176522e4fbbSGregory CLEMENT #ifdef CONFIG_MACB
177522e4fbbSGregory CLEMENT 	vinco_macb0_hw_init();
178522e4fbbSGregory CLEMENT #endif
179522e4fbbSGregory CLEMENT #ifdef CONFIG_CMD_USB
180522e4fbbSGregory CLEMENT 	vinco_usb_hw_init();
181522e4fbbSGregory CLEMENT #endif
182522e4fbbSGregory CLEMENT #ifdef CONFIG_USB_GADGET_ATMEL_USBA
183522e4fbbSGregory CLEMENT 	at91_udp_hw_init();
184522e4fbbSGregory CLEMENT #endif
185522e4fbbSGregory CLEMENT 
186522e4fbbSGregory CLEMENT 	return 0;
187522e4fbbSGregory CLEMENT }
188522e4fbbSGregory CLEMENT 
dram_init(void)189522e4fbbSGregory CLEMENT int dram_init(void)
190522e4fbbSGregory CLEMENT {
191522e4fbbSGregory CLEMENT 	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
192522e4fbbSGregory CLEMENT 				    CONFIG_SYS_SDRAM_SIZE);
193522e4fbbSGregory CLEMENT 	return 0;
194522e4fbbSGregory CLEMENT }
195522e4fbbSGregory CLEMENT 
board_eth_init(bd_t * bis)196522e4fbbSGregory CLEMENT int board_eth_init(bd_t *bis)
197522e4fbbSGregory CLEMENT {
198522e4fbbSGregory CLEMENT 	int rc = 0;
199522e4fbbSGregory CLEMENT 
200522e4fbbSGregory CLEMENT #ifdef CONFIG_MACB
201522e4fbbSGregory CLEMENT 	rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
202522e4fbbSGregory CLEMENT #endif
203522e4fbbSGregory CLEMENT 
204522e4fbbSGregory CLEMENT #ifdef CONFIG_USB_GADGET_ATMEL_USBA
205522e4fbbSGregory CLEMENT 	usba_udc_probe(&pdata);
206522e4fbbSGregory CLEMENT #ifdef CONFIG_USB_ETH_RNDIS
207522e4fbbSGregory CLEMENT 	usb_eth_initialize(bis);
208522e4fbbSGregory CLEMENT #endif
209522e4fbbSGregory CLEMENT #endif
210522e4fbbSGregory CLEMENT 
211522e4fbbSGregory CLEMENT 	return rc;
212522e4fbbSGregory CLEMENT }
213