Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Marek Vasut <marex@denx.de> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/at91_common.h> |
| 10 | #include <asm/arch/at91_pmc.h> |
| 11 | #include <asm/arch/at91_rstc.h> |
| 12 | #include <asm/arch/atmel_mpddrc.h> |
| 13 | #include <asm/arch/atmel_usba_udc.h> |
| 14 | #include <asm/arch/gpio.h> |
| 15 | #include <asm/arch/clk.h> |
| 16 | #include <asm/arch/sama5d3_smc.h> |
| 17 | #include <asm/arch/sama5d4.h> |
| 18 | #include <atmel_hlcdc.h> |
| 19 | #include <atmel_mci.h> |
| 20 | #include <lcd.h> |
| 21 | #include <mmc.h> |
| 22 | #include <net.h> |
| 23 | #include <netdev.h> |
| 24 | #include <spi.h> |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 25 | #include <spi_flash.h> |
Marek Vasut | 8997de2 | 2017-05-02 20:27:47 +0200 | [diff] [blame] | 26 | #include <spl.h> |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 27 | #include <version.h> |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 31 | static u8 boot_mode_sf; |
| 32 | |
Jagan Teki | 4dc04eb | 2018-03-14 18:46:40 +0530 | [diff] [blame] | 33 | /* FIXME gpio code here need to handle through DM_GPIO */ |
| 34 | #ifndef CONFIG_DM_SPI |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 35 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 36 | { |
| 37 | return bus == 0 && cs == 0; |
| 38 | } |
| 39 | |
| 40 | void spi_cs_activate(struct spi_slave *slave) |
| 41 | { |
| 42 | at91_set_pio_output(AT91_PIO_PORTC, 3, 0); |
| 43 | } |
| 44 | |
| 45 | void spi_cs_deactivate(struct spi_slave *slave) |
| 46 | { |
| 47 | at91_set_pio_output(AT91_PIO_PORTC, 3, 1); |
| 48 | } |
| 49 | |
| 50 | static void ma5d4evk_spi0_hw_init(void) |
| 51 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 52 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */ |
| 53 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */ |
| 54 | at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 55 | |
| 56 | at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */ |
| 57 | |
| 58 | /* Enable clock */ |
| 59 | at91_periph_clk_enable(ATMEL_ID_SPI0); |
| 60 | } |
Jagan Teki | 4dc04eb | 2018-03-14 18:46:40 +0530 | [diff] [blame] | 61 | #endif /* CONFIG_DM_SPI */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 62 | |
| 63 | #ifdef CONFIG_CMD_USB |
| 64 | static void ma5d4evk_usb_hw_init(void) |
| 65 | { |
| 66 | at91_set_pio_output(AT91_PIO_PORTE, 11, 0); |
| 67 | at91_set_pio_output(AT91_PIO_PORTE, 14, 0); |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #ifdef CONFIG_LCD |
| 72 | vidinfo_t panel_info = { |
| 73 | .vl_col = 800, |
| 74 | .vl_row = 480, |
| 75 | .vl_clk = 33500000, |
| 76 | .vl_bpix = LCD_BPP, |
| 77 | .vl_tft = 1, |
| 78 | .vl_hsync_len = 10, |
| 79 | .vl_left_margin = 89, |
| 80 | .vl_right_margin = 164, |
| 81 | .vl_vsync_len = 10, |
| 82 | .vl_upper_margin = 23, |
| 83 | .vl_lower_margin = 10, |
| 84 | .mmio = ATMEL_BASE_LCDC, |
| 85 | }; |
| 86 | |
| 87 | /* No power up/down pin for the LCD pannel */ |
| 88 | void lcd_enable(void) { /* Empty! */ } |
| 89 | void lcd_disable(void) { /* Empty! */ } |
| 90 | |
| 91 | unsigned int has_lcdc(void) |
| 92 | { |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | static void ma5d4evk_lcd_hw_init(void) |
| 97 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 98 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 24, 1); /* LCDPWM */ |
| 99 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */ |
| 100 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */ |
| 101 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */ |
| 102 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */ |
| 103 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 29, 1); /* LCDDEN */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 104 | |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 105 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 0, 0); /* LCDD0 */ |
| 106 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 1, 0); /* LCDD1 */ |
| 107 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */ |
| 108 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */ |
| 109 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */ |
| 110 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */ |
| 111 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */ |
| 112 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 113 | |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 114 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 8, 0); /* LCDD9 */ |
| 115 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 0); /* LCDD8 */ |
| 116 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */ |
| 117 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */ |
| 118 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */ |
| 119 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */ |
| 120 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */ |
| 121 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 122 | |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 123 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 0); /* LCDD16 */ |
| 124 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 0); /* LCDD17 */ |
| 125 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */ |
| 126 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */ |
| 127 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */ |
| 128 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */ |
| 129 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */ |
| 130 | at91_pio3_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 131 | |
| 132 | /* Enable clock */ |
| 133 | at91_periph_clk_enable(ATMEL_ID_LCDC); |
| 134 | } |
| 135 | |
| 136 | #endif /* CONFIG_LCD */ |
| 137 | |
| 138 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 139 | /* On-SoM eMMC */ |
| 140 | void ma5d4evk_mci0_hw_init(void) |
| 141 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 142 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI1 CDA */ |
| 143 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI1 DA0 */ |
| 144 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI1 DA1 */ |
| 145 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI1 DA2 */ |
| 146 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI1 DA3 */ |
| 147 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI1 DA4 */ |
| 148 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI1 DA5 */ |
| 149 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI1 DA6 */ |
| 150 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI1 DA7 */ |
| 151 | at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI1 CLK */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * As the mci io internal pull down is too strong, so if the io needs |
| 155 | * external pull up, the pull up resistor will be very small, if so |
| 156 | * the power consumption will increase, so disable the internal pull |
| 157 | * down to save the power. |
| 158 | */ |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 159 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0); |
| 160 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0); |
| 161 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0); |
| 162 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0); |
| 163 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0); |
| 164 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0); |
| 165 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0); |
| 166 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0); |
| 167 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0); |
| 168 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 169 | |
| 170 | /* Enable clock */ |
| 171 | at91_periph_clk_enable(ATMEL_ID_MCI0); |
| 172 | } |
| 173 | |
| 174 | /* On-board MicroSD slot */ |
| 175 | void ma5d4evk_mci1_hw_init(void) |
| 176 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 177 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 19, 1); /* MCI1 CDA */ |
| 178 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 20, 1); /* MCI1 DA0 */ |
| 179 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 21, 1); /* MCI1 DA1 */ |
| 180 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 22, 1); /* MCI1 DA2 */ |
| 181 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 23, 1); /* MCI1 DA3 */ |
| 182 | at91_pio3_set_c_periph(AT91_PIO_PORTE, 18, 0); /* MCI1 CLK */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * As the mci io internal pull down is too strong, so if the io needs |
| 186 | * external pull up, the pull up resistor will be very small, if so |
| 187 | * the power consumption will increase, so disable the internal pull |
| 188 | * down to save the power. |
| 189 | */ |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 190 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 18, 0); |
| 191 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 19, 0); |
| 192 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 20, 0); |
| 193 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 21, 0); |
| 194 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 22, 0); |
| 195 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 23, 0); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 196 | |
| 197 | /* Deal with WP pin on the microSD slot. */ |
| 198 | at91_set_pio_output(AT91_PIO_PORTE, 16, 0); |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 199 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 16, 1); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 200 | |
| 201 | /* Enable clock */ |
| 202 | at91_periph_clk_enable(ATMEL_ID_MCI1); |
| 203 | } |
| 204 | |
| 205 | int board_mmc_init(bd_t *bis) |
| 206 | { |
| 207 | int ret; |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 208 | void *mci0 = (void *)ATMEL_BASE_MCI0; |
| 209 | void *mci1 = (void *)ATMEL_BASE_MCI1; |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 210 | |
| 211 | /* De-assert reset on On-SoM eMMC */ |
| 212 | at91_set_pio_output(AT91_PIO_PORTE, 15, 1); |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 213 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 15, 0); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 214 | |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 215 | ret = atmel_mci_init(boot_mode_sf ? mci0 : mci1); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 216 | if (ret) /* eMMC init failed, skip it. */ |
| 217 | at91_set_pio_output(AT91_PIO_PORTE, 15, 0); |
| 218 | |
| 219 | /* Enable the power supply to On-board MicroSD */ |
| 220 | at91_set_pio_output(AT91_PIO_PORTE, 17, 0); |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 221 | ret = atmel_mci_init(boot_mode_sf ? mci1 : mci0); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 222 | if (ret) /* uSD init failed, power it down. */ |
| 223 | at91_set_pio_output(AT91_PIO_PORTE, 17, 1); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | #endif /* CONFIG_GENERIC_ATMEL_MCI */ |
| 228 | |
| 229 | #ifdef CONFIG_MACB |
| 230 | void ma5d4evk_macb0_hw_init(void) |
| 231 | { |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 232 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */ |
| 233 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */ |
| 234 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */ |
| 235 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */ |
| 236 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */ |
| 237 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */ |
| 238 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */ |
| 239 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */ |
| 240 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */ |
| 241 | at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 242 | |
| 243 | /* Enable clock */ |
| 244 | at91_periph_clk_enable(ATMEL_ID_GMAC0); |
| 245 | } |
| 246 | #endif |
| 247 | |
| 248 | static void ma5d4evk_serial_hw_init(void) |
| 249 | { |
| 250 | /* USART0 */ |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 251 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1); /* TXD */ |
| 252 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 0); /* RXD */ |
| 253 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 0); /* RTS */ |
| 254 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 0); /* CTS */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 255 | at91_periph_clk_enable(ATMEL_ID_USART0); |
| 256 | |
| 257 | /* USART1 */ |
Wenyou Yang | 2dc63f7 | 2017-03-23 12:44:36 +0800 | [diff] [blame] | 258 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 17, 1); /* TXD */ |
| 259 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 16, 0); /* RXD */ |
| 260 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 15, 0); /* RTS */ |
| 261 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 14, 0); /* CTS */ |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 262 | at91_periph_clk_enable(ATMEL_ID_USART1); |
| 263 | } |
| 264 | |
| 265 | int board_early_init_f(void) |
| 266 | { |
| 267 | at91_periph_clk_enable(ATMEL_ID_PIOA); |
| 268 | at91_periph_clk_enable(ATMEL_ID_PIOB); |
| 269 | at91_periph_clk_enable(ATMEL_ID_PIOC); |
| 270 | at91_periph_clk_enable(ATMEL_ID_PIOD); |
| 271 | at91_periph_clk_enable(ATMEL_ID_PIOE); |
| 272 | |
| 273 | /* Configure LEDs as OFF */ |
| 274 | at91_set_pio_output(AT91_PIO_PORTD, 28, 0); |
| 275 | at91_set_pio_output(AT91_PIO_PORTD, 29, 0); |
| 276 | at91_set_pio_output(AT91_PIO_PORTD, 30, 0); |
| 277 | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 278 | ma5d4evk_serial_hw_init(); |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 283 | static void board_identify(void) |
| 284 | { |
| 285 | struct spi_flash *sf; |
| 286 | sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, |
| 287 | CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE); |
| 288 | boot_mode_sf = (sf != NULL); |
| 289 | } |
| 290 | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 291 | int board_init(void) |
| 292 | { |
| 293 | /* adress of boot parameters */ |
| 294 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 295 | |
Jagan Teki | 4dc04eb | 2018-03-14 18:46:40 +0530 | [diff] [blame] | 296 | #ifndef CONFIG_DM_SPI |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 297 | ma5d4evk_spi0_hw_init(); |
| 298 | #endif |
| 299 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 300 | ma5d4evk_mci0_hw_init(); |
| 301 | ma5d4evk_mci1_hw_init(); |
| 302 | #endif |
| 303 | #ifdef CONFIG_MACB |
| 304 | ma5d4evk_macb0_hw_init(); |
| 305 | #endif |
| 306 | #ifdef CONFIG_LCD |
| 307 | ma5d4evk_lcd_hw_init(); |
| 308 | #endif |
| 309 | #ifdef CONFIG_CMD_USB |
| 310 | ma5d4evk_usb_hw_init(); |
| 311 | #endif |
| 312 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA |
| 313 | at91_udp_hw_init(); |
| 314 | #endif |
| 315 | |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 316 | board_identify(); |
| 317 | |
Marek Vasut | 52a557d6 | 2017-05-02 20:27:42 +0200 | [diff] [blame] | 318 | /* Reset CAN controllers */ |
| 319 | at91_set_pio_output(AT91_PIO_PORTB, 21, 0); |
| 320 | udelay(100); |
| 321 | at91_set_pio_output(AT91_PIO_PORTB, 21, 1); |
| 322 | at91_pio3_set_pio_pulldown(AT91_PIO_PORTB, 21, 0); |
| 323 | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 327 | int board_late_init(void) |
| 328 | { |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 329 | env_set("bootmode", boot_mode_sf ? "sf" : "emmc"); |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 333 | int dram_init(void) |
| 334 | { |
| 335 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 336 | CONFIG_SYS_SDRAM_SIZE); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | int board_eth_init(bd_t *bis) |
| 341 | { |
| 342 | int rc = 0; |
| 343 | |
| 344 | #ifdef CONFIG_MACB |
| 345 | rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00); |
| 346 | #endif |
| 347 | |
| 348 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA |
| 349 | usba_udc_probe(&pdata); |
| 350 | #ifdef CONFIG_USB_ETH_RNDIS |
| 351 | usb_eth_initialize(bis); |
| 352 | #endif |
| 353 | #endif |
| 354 | |
| 355 | return rc; |
| 356 | } |
| 357 | |
| 358 | /* SPL */ |
| 359 | #ifdef CONFIG_SPL_BUILD |
| 360 | void spl_board_init(void) |
| 361 | { |
Jagan Teki | 5a6eab8 | 2018-03-14 18:46:41 +0530 | [diff] [blame^] | 362 | #ifndef CONFIG_DM_SPI |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 363 | ma5d4evk_spi0_hw_init(); |
Marek Vasut | 24257db | 2017-05-02 20:27:44 +0200 | [diff] [blame] | 364 | #endif |
| 365 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 366 | ma5d4evk_mci0_hw_init(); |
| 367 | ma5d4evk_mci1_hw_init(); |
| 368 | #endif |
Marek Vasut | e3f4072 | 2017-05-02 20:27:50 +0200 | [diff] [blame] | 369 | board_identify(); |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 370 | } |
| 371 | |
Marek Vasut | 8997de2 | 2017-05-02 20:27:47 +0200 | [diff] [blame] | 372 | void board_boot_order(u32 *spl_boot_list) |
| 373 | { |
| 374 | spl_boot_list[0] = spl_boot_device(); |
| 375 | |
| 376 | switch (spl_boot_list[0]) { |
| 377 | case BOOT_DEVICE_MMC1: |
| 378 | case BOOT_DEVICE_MMC2: |
| 379 | spl_boot_list[0] = BOOT_DEVICE_MMC1; |
| 380 | break; |
| 381 | case BOOT_DEVICE_SPI: |
| 382 | break; |
| 383 | case BOOT_DEVICE_USB: |
| 384 | spl_boot_list[0] = BOOT_DEVICE_MMC2; |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 389 | static void ddr2_conf(struct atmel_mpddrc_config *ddr2) |
| 390 | { |
| 391 | ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM); |
| 392 | |
| 393 | ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | |
| 394 | ATMEL_MPDDRC_CR_NR_ROW_13 | |
| 395 | ATMEL_MPDDRC_CR_CAS_DDR_CAS3 | |
| 396 | ATMEL_MPDDRC_CR_NB_8BANKS | |
| 397 | ATMEL_MPDDRC_CR_NDQS_DISABLED | |
Marek Vasut | c21c28b | 2016-02-11 14:13:38 +0100 | [diff] [blame] | 398 | ATMEL_MPDDRC_CR_UNAL_SUPPORTED); |
| 399 | |
| 400 | ddr2->rtr = 0x2b0; |
| 401 | |
| 402 | ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET | |
| 403 | 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET | |
| 404 | 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | |
| 405 | 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | |
| 406 | 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | |
| 407 | 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | |
| 408 | 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | |
| 409 | 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); |
| 410 | |
| 411 | ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | |
| 412 | 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET | |
| 413 | 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET | |
| 414 | 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET); |
| 415 | |
| 416 | ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET | |
| 417 | 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET | |
| 418 | 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET | |
| 419 | 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET | |
| 420 | 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET); |
| 421 | } |
| 422 | |
| 423 | void mem_init(void) |
| 424 | { |
| 425 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 426 | struct atmel_mpddrc_config ddr2; |
| 427 | |
| 428 | ddr2_conf(&ddr2); |
| 429 | |
| 430 | /* enable MPDDR clock */ |
| 431 | at91_periph_clk_enable(ATMEL_ID_MPDDRC); |
| 432 | writel(AT91_PMC_DDR, &pmc->scer); |
| 433 | |
| 434 | /* DDRAM2 Controller initialize */ |
| 435 | ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2); |
| 436 | } |
| 437 | |
| 438 | void at91_pmc_init(void) |
| 439 | { |
| 440 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 441 | u32 tmp; |
| 442 | |
| 443 | tmp = AT91_PMC_PLLAR_29 | |
| 444 | AT91_PMC_PLLXR_PLLCOUNT(0x3f) | |
| 445 | AT91_PMC_PLLXR_MUL(87) | |
| 446 | AT91_PMC_PLLXR_DIV(1); |
| 447 | at91_plla_init(tmp); |
| 448 | |
| 449 | writel(0x0 << 8, &pmc->pllicpr); |
| 450 | |
| 451 | tmp = AT91_PMC_MCKR_H32MXDIV | |
| 452 | AT91_PMC_MCKR_PLLADIV_2 | |
| 453 | AT91_PMC_MCKR_MDIV_3 | |
| 454 | AT91_PMC_MCKR_CSS_PLLA; |
| 455 | at91_mck_init(tmp); |
| 456 | } |
| 457 | #endif |