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