Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 2 | /* |
| 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 CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 15 | #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> |
| 33 | #include <version.h> |
| 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Jagan Teki | c60bfe9 | 2018-03-14 18:46:37 +0530 | [diff] [blame] | 37 | /* FIXME gpio code here need to handle through DM_GPIO */ |
Lukasz Majewski | 56c4046 | 2020-06-04 23:11:53 +0800 | [diff] [blame] | 38 | #if !CONFIG_IS_ENABLED(DM_SPI) |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 39 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 40 | { |
| 41 | return bus == 0 && cs == 0; |
| 42 | } |
| 43 | |
| 44 | void spi_cs_activate(struct spi_slave *slave) |
| 45 | { |
| 46 | at91_set_pio_output(AT91_PIO_PORTC, 3, 0); |
| 47 | } |
| 48 | |
| 49 | void spi_cs_deactivate(struct spi_slave *slave) |
| 50 | { |
| 51 | at91_set_pio_output(AT91_PIO_PORTC, 3, 1); |
| 52 | } |
| 53 | |
| 54 | static void vinco_spi0_hw_init(void) |
| 55 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 56 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */ |
| 57 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */ |
| 58 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */ |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 59 | |
| 60 | at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */ |
| 61 | |
| 62 | /* Enable clock */ |
| 63 | at91_periph_clk_enable(ATMEL_ID_SPI0); |
| 64 | } |
| 65 | #endif /* CONFIG_ATMEL_SPI */ |
| 66 | |
| 67 | |
| 68 | #ifdef CONFIG_CMD_USB |
| 69 | static void vinco_usb_hw_init(void) |
| 70 | { |
| 71 | at91_set_pio_output(AT91_PIO_PORTE, 11, 0); |
| 72 | at91_set_pio_output(AT91_PIO_PORTE, 12, 0); |
| 73 | at91_set_pio_output(AT91_PIO_PORTE, 10, 0); |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | |
| 78 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 79 | void vinco_mci0_hw_init(void) |
| 80 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 81 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI0 CDA */ |
| 82 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI0 DA0 */ |
| 83 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI0 DA1 */ |
| 84 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI0 DA2 */ |
| 85 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI0 DA3 */ |
| 86 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI0 DA4 */ |
| 87 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI0 DA5 */ |
| 88 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI0 DA6 */ |
| 89 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI0 DA7 */ |
| 90 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI0 CLK */ |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * As the mci io internal pull down is too strong, so if the io needs |
| 94 | * external pull up, the pull up resistor will be very small, if so |
| 95 | * the power consumption will increase, so disable the interanl pull |
| 96 | * down to save the power. |
| 97 | */ |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 98 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0); |
| 99 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0); |
| 100 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0); |
| 101 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0); |
| 102 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0); |
| 103 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0); |
| 104 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0); |
| 105 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0); |
| 106 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0); |
| 107 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0); |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 108 | |
| 109 | /* Enable clock */ |
| 110 | at91_periph_clk_enable(ATMEL_ID_MCI0); |
| 111 | } |
| 112 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 113 | int board_mmc_init(struct bd_info *bis) |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 114 | { |
| 115 | /* Enable power for MCI0 interface */ |
| 116 | at91_set_pio_output(AT91_PIO_PORTE, 7, 1); |
| 117 | |
| 118 | return atmel_mci_init((void *)ATMEL_BASE_MCI0); |
| 119 | } |
| 120 | #endif /* CONFIG_GENERIC_ATMEL_MCI */ |
| 121 | |
| 122 | #ifdef CONFIG_MACB |
| 123 | void vinco_macb0_hw_init(void) |
| 124 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 125 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */ |
| 126 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */ |
| 127 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */ |
| 128 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */ |
| 129 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */ |
| 130 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */ |
| 131 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */ |
| 132 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */ |
| 133 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */ |
| 134 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */ |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 135 | |
| 136 | /* Enable clock */ |
| 137 | at91_periph_clk_enable(ATMEL_ID_GMAC0); |
| 138 | |
| 139 | /* Enable Phy*/ |
| 140 | at91_set_pio_output(AT91_PIO_PORTE, 8, 1); |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | static void vinco_serial3_hw_init(void) |
| 145 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 146 | at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */ |
| 147 | at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */ |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 148 | |
| 149 | /* Enable clock */ |
| 150 | at91_periph_clk_enable(ATMEL_ID_USART3); |
| 151 | } |
| 152 | |
| 153 | int board_early_init_f(void) |
| 154 | { |
| 155 | at91_periph_clk_enable(ATMEL_ID_PIOA); |
| 156 | at91_periph_clk_enable(ATMEL_ID_PIOB); |
| 157 | at91_periph_clk_enable(ATMEL_ID_PIOC); |
| 158 | at91_periph_clk_enable(ATMEL_ID_PIOD); |
| 159 | at91_periph_clk_enable(ATMEL_ID_PIOE); |
| 160 | |
| 161 | vinco_serial3_hw_init(); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | int board_init(void) |
| 167 | { |
| 168 | /* adress of boot parameters */ |
| 169 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 170 | |
Lukasz Majewski | 56c4046 | 2020-06-04 23:11:53 +0800 | [diff] [blame] | 171 | #if !CONFIG_IS_ENABLED(DM_SPI) |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 172 | vinco_spi0_hw_init(); |
| 173 | #endif |
| 174 | |
| 175 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 176 | vinco_mci0_hw_init(); |
| 177 | #endif |
| 178 | #ifdef CONFIG_MACB |
| 179 | vinco_macb0_hw_init(); |
| 180 | #endif |
| 181 | #ifdef CONFIG_CMD_USB |
| 182 | vinco_usb_hw_init(); |
| 183 | #endif |
| 184 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA |
| 185 | at91_udp_hw_init(); |
| 186 | #endif |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | int dram_init(void) |
| 192 | { |
| 193 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 194 | CONFIG_SYS_SDRAM_SIZE); |
| 195 | return 0; |
| 196 | } |
| 197 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 198 | int board_eth_init(struct bd_info *bis) |
Gregory CLEMENT | 522e4fb | 2015-12-16 17:01:44 +0100 | [diff] [blame] | 199 | { |
| 200 | int rc = 0; |
| 201 | |
| 202 | #ifdef CONFIG_MACB |
| 203 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00); |
| 204 | #endif |
| 205 | |
| 206 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA |
| 207 | usba_udc_probe(&pdata); |
| 208 | #ifdef CONFIG_USB_ETH_RNDIS |
| 209 | usb_eth_initialize(bis); |
| 210 | #endif |
| 211 | #endif |
| 212 | |
| 213 | return rc; |
| 214 | } |