blob: 39e7ff633b30780a9289ebc33f15e01a4dba3bd9 [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
Tom Rinidec7ea02024-05-20 13:35:03 -060012#include <config.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>
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010027#include <mmc.h>
28#include <net.h>
29#include <netdev.h>
30#include <nand.h>
31#include <spi.h>
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010032
33DECLARE_GLOBAL_DATA_PTR;
34
Jagan Tekic022b3c2018-03-14 18:46:37 +053035/* FIXME gpio code here need to handle through DM_GPIO */
Lukasz Majewski76f442982020-06-04 23:11:53 +080036#if !CONFIG_IS_ENABLED(DM_SPI)
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010037int spi_cs_is_valid(unsigned int bus, unsigned int cs)
38{
39 return bus == 0 && cs == 0;
40}
41
42void spi_cs_activate(struct spi_slave *slave)
43{
44 at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
45}
46
47void spi_cs_deactivate(struct spi_slave *slave)
48{
49 at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
50}
51
52static void vinco_spi0_hw_init(void)
53{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080054 at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
55 at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
56 at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010057
58 at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
59
60 /* Enable clock */
61 at91_periph_clk_enable(ATMEL_ID_SPI0);
62}
63#endif /* CONFIG_ATMEL_SPI */
64
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010065#ifdef CONFIG_CMD_USB
66static void vinco_usb_hw_init(void)
67{
68 at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
69 at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
70 at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
71}
72#endif
73
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010074#ifdef CONFIG_GENERIC_ATMEL_MCI
75void vinco_mci0_hw_init(void)
76{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080077 at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI0 CDA */
78 at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI0 DA0 */
79 at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI0 DA1 */
80 at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI0 DA2 */
81 at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI0 DA3 */
82 at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI0 DA4 */
83 at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI0 DA5 */
84 at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI0 DA6 */
85 at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI0 DA7 */
86 at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI0 CLK */
Gregory CLEMENT02b49b52015-12-16 17:01:44 +010087
88 /*
89 * As the mci io internal pull down is too strong, so if the io needs
90 * external pull up, the pull up resistor will be very small, if so
91 * the power consumption will increase, so disable the interanl pull
92 * down to save the power.
93 */
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080094 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
95 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
96 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
97 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
98 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
99 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
100 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
101 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
102 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
103 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100104
105 /* Enable clock */
106 at91_periph_clk_enable(ATMEL_ID_MCI0);
107}
108
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900109int board_mmc_init(struct bd_info *bis)
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100110{
111 /* Enable power for MCI0 interface */
112 at91_set_pio_output(AT91_PIO_PORTE, 7, 1);
113
114 return atmel_mci_init((void *)ATMEL_BASE_MCI0);
115}
116#endif /* CONFIG_GENERIC_ATMEL_MCI */
117
118#ifdef CONFIG_MACB
119void vinco_macb0_hw_init(void)
120{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800121 at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
122 at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
123 at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
124 at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
125 at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
126 at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
127 at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
128 at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
129 at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
130 at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100131
132 /* Enable clock */
133 at91_periph_clk_enable(ATMEL_ID_GMAC0);
134
135 /* Enable Phy*/
136 at91_set_pio_output(AT91_PIO_PORTE, 8, 1);
137}
138#endif
139
140static void vinco_serial3_hw_init(void)
141{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800142 at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
143 at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100144
145 /* Enable clock */
146 at91_periph_clk_enable(ATMEL_ID_USART3);
147}
148
149int board_early_init_f(void)
150{
151 at91_periph_clk_enable(ATMEL_ID_PIOA);
152 at91_periph_clk_enable(ATMEL_ID_PIOB);
153 at91_periph_clk_enable(ATMEL_ID_PIOC);
154 at91_periph_clk_enable(ATMEL_ID_PIOD);
155 at91_periph_clk_enable(ATMEL_ID_PIOE);
156
157 vinco_serial3_hw_init();
158
159 return 0;
160}
161
162int board_init(void)
163{
164 /* adress of boot parameters */
Tom Rinibb4dd962022-11-16 13:10:37 -0500165 gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100166
Lukasz Majewski76f442982020-06-04 23:11:53 +0800167#if !CONFIG_IS_ENABLED(DM_SPI)
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100168 vinco_spi0_hw_init();
169#endif
170
171#ifdef CONFIG_GENERIC_ATMEL_MCI
172 vinco_mci0_hw_init();
173#endif
174#ifdef CONFIG_MACB
175 vinco_macb0_hw_init();
176#endif
177#ifdef CONFIG_CMD_USB
178 vinco_usb_hw_init();
179#endif
180#ifdef CONFIG_USB_GADGET_ATMEL_USBA
181 at91_udp_hw_init();
182#endif
183
184 return 0;
185}
186
187int dram_init(void)
188{
Tom Rinibb4dd962022-11-16 13:10:37 -0500189 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE,
190 CFG_SYS_SDRAM_SIZE);
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100191 return 0;
192}
193
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900194int board_eth_init(struct bd_info *bis)
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100195{
196 int rc = 0;
197
198#ifdef CONFIG_MACB
199 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
200#endif
201
202#ifdef CONFIG_USB_GADGET_ATMEL_USBA
203 usba_udc_probe(&pdata);
Gregory CLEMENT02b49b52015-12-16 17:01:44 +0100204#endif
205
206 return rc;
207}