1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Board file for the VInCo platform
3*4882a593Smuzhiyun * Based on the the SAMA5-EK board file
4*4882a593Smuzhiyun * Configuration settings for the VInCo platform.
5*4882a593Smuzhiyun * Copyright (C) 2014 Atmel
6*4882a593Smuzhiyun * Bo Shen <voice.shen@atmel.com>
7*4882a593Smuzhiyun * Copyright (C) 2015 Free Electrons
8*4882a593Smuzhiyun * Gregory CLEMENT <gregory.clement@free-electrons.com>
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <common.h>
14*4882a593Smuzhiyun #include <asm/io.h>
15*4882a593Smuzhiyun #include <asm/arch/at91_common.h>
16*4882a593Smuzhiyun #include <asm/arch/at91_pmc.h>
17*4882a593Smuzhiyun #include <asm/arch/at91_rstc.h>
18*4882a593Smuzhiyun #include <asm/arch/atmel_mpddrc.h>
19*4882a593Smuzhiyun #include <asm/arch/atmel_usba_udc.h>
20*4882a593Smuzhiyun #include <asm/arch/gpio.h>
21*4882a593Smuzhiyun #include <asm/arch/clk.h>
22*4882a593Smuzhiyun #include <asm/arch/sama5d3_smc.h>
23*4882a593Smuzhiyun #include <asm/arch/sama5d4.h>
24*4882a593Smuzhiyun #include <atmel_hlcdc.h>
25*4882a593Smuzhiyun #include <atmel_mci.h>
26*4882a593Smuzhiyun #include <lcd.h>
27*4882a593Smuzhiyun #include <mmc.h>
28*4882a593Smuzhiyun #include <net.h>
29*4882a593Smuzhiyun #include <netdev.h>
30*4882a593Smuzhiyun #include <nand.h>
31*4882a593Smuzhiyun #include <spi.h>
32*4882a593Smuzhiyun #include <version.h>
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #ifdef CONFIG_ATMEL_SPI
spi_cs_is_valid(unsigned int bus,unsigned int cs)37*4882a593Smuzhiyun int spi_cs_is_valid(unsigned int bus, unsigned int cs)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun return bus == 0 && cs == 0;
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun
spi_cs_activate(struct spi_slave * slave)42*4882a593Smuzhiyun void spi_cs_activate(struct spi_slave *slave)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun
spi_cs_deactivate(struct spi_slave * slave)47*4882a593Smuzhiyun void spi_cs_deactivate(struct spi_slave *slave)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
vinco_spi0_hw_init(void)52*4882a593Smuzhiyun static void vinco_spi0_hw_init(void)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
55*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
56*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /* Enable clock */
61*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_SPI0);
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun #endif /* CONFIG_ATMEL_SPI */
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun #ifdef CONFIG_CMD_USB
vinco_usb_hw_init(void)67*4882a593Smuzhiyun static void vinco_usb_hw_init(void)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
70*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
71*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun #endif
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_ATMEL_MCI
vinco_mci0_hw_init(void)77*4882a593Smuzhiyun void vinco_mci0_hw_init(void)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI0 CDA */
80*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI0 DA0 */
81*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI0 DA1 */
82*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI0 DA2 */
83*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI0 DA3 */
84*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI0 DA4 */
85*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI0 DA5 */
86*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI0 DA6 */
87*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI0 DA7 */
88*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI0 CLK */
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun * As the mci io internal pull down is too strong, so if the io needs
92*4882a593Smuzhiyun * external pull up, the pull up resistor will be very small, if so
93*4882a593Smuzhiyun * the power consumption will increase, so disable the interanl pull
94*4882a593Smuzhiyun * down to save the power.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
97*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
98*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
99*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
100*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
101*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
102*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
103*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
104*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
105*4882a593Smuzhiyun at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /* Enable clock */
108*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_MCI0);
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
board_mmc_init(bd_t * bis)111*4882a593Smuzhiyun int board_mmc_init(bd_t *bis)
112*4882a593Smuzhiyun {
113*4882a593Smuzhiyun /* Enable power for MCI0 interface */
114*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTE, 7, 1);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun return atmel_mci_init((void *)ATMEL_BASE_MCI0);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun #endif /* CONFIG_GENERIC_ATMEL_MCI */
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun #ifdef CONFIG_MACB
vinco_macb0_hw_init(void)121*4882a593Smuzhiyun void vinco_macb0_hw_init(void)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
124*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
125*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
126*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
127*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
128*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
129*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
130*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
131*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
132*4882a593Smuzhiyun at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun /* Enable clock */
135*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_GMAC0);
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /* Enable Phy*/
138*4882a593Smuzhiyun at91_set_pio_output(AT91_PIO_PORTE, 8, 1);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun #endif
141*4882a593Smuzhiyun
vinco_serial3_hw_init(void)142*4882a593Smuzhiyun static void vinco_serial3_hw_init(void)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
145*4882a593Smuzhiyun at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* Enable clock */
148*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_USART3);
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
board_early_init_f(void)151*4882a593Smuzhiyun int board_early_init_f(void)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_PIOA);
154*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_PIOB);
155*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_PIOC);
156*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_PIOD);
157*4882a593Smuzhiyun at91_periph_clk_enable(ATMEL_ID_PIOE);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun vinco_serial3_hw_init();
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun return 0;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
board_init(void)164*4882a593Smuzhiyun int board_init(void)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun /* adress of boot parameters */
167*4882a593Smuzhiyun gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun #ifdef CONFIG_ATMEL_SPI
170*4882a593Smuzhiyun vinco_spi0_hw_init();
171*4882a593Smuzhiyun #endif
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_ATMEL_MCI
174*4882a593Smuzhiyun vinco_mci0_hw_init();
175*4882a593Smuzhiyun #endif
176*4882a593Smuzhiyun #ifdef CONFIG_MACB
177*4882a593Smuzhiyun vinco_macb0_hw_init();
178*4882a593Smuzhiyun #endif
179*4882a593Smuzhiyun #ifdef CONFIG_CMD_USB
180*4882a593Smuzhiyun vinco_usb_hw_init();
181*4882a593Smuzhiyun #endif
182*4882a593Smuzhiyun #ifdef CONFIG_USB_GADGET_ATMEL_USBA
183*4882a593Smuzhiyun at91_udp_hw_init();
184*4882a593Smuzhiyun #endif
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun return 0;
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun
dram_init(void)189*4882a593Smuzhiyun int dram_init(void)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
192*4882a593Smuzhiyun CONFIG_SYS_SDRAM_SIZE);
193*4882a593Smuzhiyun return 0;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun
board_eth_init(bd_t * bis)196*4882a593Smuzhiyun int board_eth_init(bd_t *bis)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun int rc = 0;
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun #ifdef CONFIG_MACB
201*4882a593Smuzhiyun rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
202*4882a593Smuzhiyun #endif
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun #ifdef CONFIG_USB_GADGET_ATMEL_USBA
205*4882a593Smuzhiyun usba_udc_probe(&pdata);
206*4882a593Smuzhiyun #ifdef CONFIG_USB_ETH_RNDIS
207*4882a593Smuzhiyun usb_eth_initialize(bis);
208*4882a593Smuzhiyun #endif
209*4882a593Smuzhiyun #endif
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun return rc;
212*4882a593Smuzhiyun }
213