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