1 /* 2 * Copyright (C) 2015 Atmel Corporation 3 * Wenyou.Yang <wenyou.yang@atmel.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <atmel_hlcdc.h> 10 #include <lcd.h> 11 #include <mmc.h> 12 #include <net.h> 13 #include <netdev.h> 14 #include <spi.h> 15 #include <version.h> 16 #include <asm/io.h> 17 #include <asm/arch/at91_common.h> 18 #include <asm/arch/at91_pmc.h> 19 #include <asm/arch/atmel_pio4.h> 20 #include <asm/arch/atmel_mpddrc.h> 21 #include <asm/arch/atmel_usba_udc.h> 22 #include <asm/arch/atmel_sdhci.h> 23 #include <asm/arch/clk.h> 24 #include <asm/arch/gpio.h> 25 #include <asm/arch/sama5d2.h> 26 27 DECLARE_GLOBAL_DATA_PTR; 28 29 int spi_cs_is_valid(unsigned int bus, unsigned int cs) 30 { 31 return bus == 0 && cs == 0; 32 } 33 34 void spi_cs_activate(struct spi_slave *slave) 35 { 36 atmel_pio4_set_pio_output(AT91_PIO_PORTA, 17, 0); 37 } 38 39 void spi_cs_deactivate(struct spi_slave *slave) 40 { 41 atmel_pio4_set_pio_output(AT91_PIO_PORTA, 17, 1); 42 } 43 44 static void board_spi0_hw_init(void) 45 { 46 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 14, 0); 47 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 15, 0); 48 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 16, 0); 49 50 atmel_pio4_set_pio_output(AT91_PIO_PORTA, 17, 1); 51 52 at91_periph_clk_enable(ATMEL_ID_SPI0); 53 } 54 55 static void board_usb_hw_init(void) 56 { 57 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 10, 1); 58 } 59 60 #ifdef CONFIG_LCD 61 vidinfo_t panel_info = { 62 .vl_col = 480, 63 .vl_row = 272, 64 .vl_clk = 9000000, 65 .vl_bpix = LCD_BPP, 66 .vl_tft = 1, 67 .vl_hsync_len = 41, 68 .vl_left_margin = 2, 69 .vl_right_margin = 2, 70 .vl_vsync_len = 11, 71 .vl_upper_margin = 2, 72 .vl_lower_margin = 2, 73 .mmio = ATMEL_BASE_LCDC, 74 }; 75 76 /* No power up/down pin for the LCD pannel */ 77 void lcd_enable(void) { /* Empty! */ } 78 void lcd_disable(void) { /* Empty! */ } 79 80 unsigned int has_lcdc(void) 81 { 82 return 1; 83 } 84 85 static void board_lcd_hw_init(void) 86 { 87 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 28, 0); /* LCDPWM */ 88 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 29, 0); /* LCDDISP */ 89 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 30, 0); /* LCDVSYNC */ 90 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 31, 0); /* LCDHSYNC */ 91 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 0, 0); /* LCDPCK */ 92 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 1, 0); /* LCDDEN */ 93 94 /* LCDDAT0 */ 95 /* LCDDAT1 */ 96 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDDAT2 */ 97 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDDAT3 */ 98 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 12, 0); /* LCDDAT4 */ 99 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 13, 0); /* LCDDAT5 */ 100 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDDAT6 */ 101 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDDAT7 */ 102 103 /* LCDDAT8 */ 104 /* LCDDAT9 */ 105 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDDAT10 */ 106 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 17, 0); /* LCDDAT11 */ 107 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDDAT12 */ 108 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDDAT13 */ 109 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 20, 0); /* LCDDAT14 */ 110 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 21, 0); /* LCDDAT15 */ 111 112 /* LCDD16 */ 113 /* LCDD17 */ 114 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDDAT18 */ 115 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDDAT19 */ 116 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDDAT20 */ 117 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 25, 0); /* LCDDAT21 */ 118 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDDAT22 */ 119 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDDAT23 */ 120 121 at91_periph_clk_enable(ATMEL_ID_LCDC); 122 } 123 124 #ifdef CONFIG_LCD_INFO 125 void lcd_show_board_info(void) 126 { 127 ulong dram_size; 128 int i; 129 char temp[32]; 130 131 lcd_printf("%s\n", U_BOOT_VERSION); 132 lcd_printf("2015 ATMEL Corp\n"); 133 lcd_printf("%s CPU at %s MHz\n", get_cpu_name(), 134 strmhz(temp, get_cpu_clk_rate())); 135 136 dram_size = 0; 137 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) 138 dram_size += gd->bd->bi_dram[i].size; 139 140 lcd_printf("%ld MB SDRAM\n", dram_size >> 20); 141 } 142 #endif /* CONFIG_LCD_INFO */ 143 #endif /* CONFIG_LCD */ 144 145 static void board_gmac_hw_init(void) 146 { 147 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 14, 0); /* GTXCK */ 148 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 15, 0); /* GTXEN */ 149 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 16, 0); /* GRXDV */ 150 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 17, 0); /* GRXER */ 151 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 18, 0); /* GRX0 */ 152 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 19, 0); /* GRX1 */ 153 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 20, 0); /* GTX0 */ 154 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 21, 0); /* GTX1 */ 155 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 22, 0); /* GMDC */ 156 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 23, 0); /* GMDIO */ 157 158 at91_periph_clk_enable(ATMEL_ID_GMAC); 159 } 160 161 static void board_sdhci0_hw_init(void) 162 { 163 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 0, 0); /* SDMMC0_CK */ 164 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 1, 0); /* SDMMC0_CMD */ 165 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 2, 0); /* SDMMC0_DAT0 */ 166 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 3, 0); /* SDMMC0_DAT1 */ 167 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 4, 0); /* SDMMC0_DAT2 */ 168 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 5, 0); /* SDMMC0_DAT3 */ 169 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 6, 0); /* SDMMC0_DAT4 */ 170 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 7, 0); /* SDMMC0_DAT5 */ 171 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 8, 0); /* SDMMC0_DAT6 */ 172 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 9, 0); /* SDMMC0_DAT7 */ 173 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 10, 0); /* SDMMC0_RSTN */ 174 atmel_pio4_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SDMMC0_VDDSEL */ 175 176 at91_periph_clk_enable(ATMEL_ID_SDMMC0); 177 at91_enable_periph_generated_clk(ATMEL_ID_SDMMC0, 178 GCK_CSS_PLLA_CLK, 1); 179 } 180 181 static void board_sdhci1_hw_init(void) 182 { 183 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 18, 0); /* SDMMC1_DAT0 */ 184 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 19, 0); /* SDMMC1_DAT1 */ 185 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 20, 0); /* SDMMC1_DAT2 */ 186 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 21, 0); /* SDMMC1_DAT3 */ 187 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 22, 0); /* SDMMC1_CK */ 188 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 27, 0); /* SDMMC1_RSTN */ 189 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 28, 0); /* SDMMC1_CMD */ 190 atmel_pio4_set_e_periph(AT91_PIO_PORTA, 30, 0); /* SDMMC1_CD */ 191 192 at91_periph_clk_enable(ATMEL_ID_SDMMC1); 193 at91_enable_periph_generated_clk(ATMEL_ID_SDMMC1, 194 GCK_CSS_PLLA_CLK, 1); 195 } 196 197 int board_mmc_init(bd_t *bis) 198 { 199 #ifdef CONFIG_ATMEL_SDHCI0 200 atmel_sdhci_init((void *)ATMEL_BASE_SDMMC0, ATMEL_ID_SDMMC0); 201 #endif 202 #ifdef CONFIG_ATMEL_SDHCI1 203 atmel_sdhci_init((void *)ATMEL_BASE_SDMMC1, ATMEL_ID_SDMMC1); 204 #endif 205 206 return 0; 207 } 208 209 static void board_uart1_hw_init(void) 210 { 211 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 2, 1); /* URXD1 */ 212 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 3, 0); /* UTXD1 */ 213 214 at91_periph_clk_enable(ATMEL_ID_UART1); 215 } 216 217 int board_early_init_f(void) 218 { 219 at91_periph_clk_enable(ATMEL_ID_PIOA); 220 at91_periph_clk_enable(ATMEL_ID_PIOB); 221 at91_periph_clk_enable(ATMEL_ID_PIOC); 222 at91_periph_clk_enable(ATMEL_ID_PIOD); 223 224 board_uart1_hw_init(); 225 226 return 0; 227 } 228 229 int board_init(void) 230 { 231 /* address of boot parameters */ 232 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; 233 234 #ifdef CONFIG_ATMEL_SPI 235 board_spi0_hw_init(); 236 #endif 237 #ifdef CONFIG_ATMEL_SDHCI 238 #ifdef CONFIG_ATMEL_SDHCI0 239 board_sdhci0_hw_init(); 240 #endif 241 #ifdef CONFIG_ATMEL_SDHCI1 242 board_sdhci1_hw_init(); 243 #endif 244 #endif 245 #ifdef CONFIG_MACB 246 board_gmac_hw_init(); 247 #endif 248 #ifdef CONFIG_LCD 249 board_lcd_hw_init(); 250 #endif 251 #ifdef CONFIG_CMD_USB 252 board_usb_hw_init(); 253 #endif 254 #ifdef CONFIG_USB_GADGET_ATMEL_USBA 255 at91_udp_hw_init(); 256 #endif 257 258 return 0; 259 } 260 261 int dram_init(void) 262 { 263 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, 264 CONFIG_SYS_SDRAM_SIZE); 265 return 0; 266 } 267 268 int board_eth_init(bd_t *bis) 269 { 270 int rc = 0; 271 272 #ifdef CONFIG_MACB 273 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC, 0x00); 274 #endif 275 276 #ifdef CONFIG_USB_GADGET_ATMEL_USBA 277 usba_udc_probe(&pdata); 278 #ifdef CONFIG_USB_ETH_RNDIS 279 usb_eth_initialize(bis); 280 #endif 281 #endif 282 283 return rc; 284 } 285 286 /* SPL */ 287 #ifdef CONFIG_SPL_BUILD 288 void spl_board_init(void) 289 { 290 #ifdef CONFIG_SYS_USE_SERIALFLASH 291 board_spi0_hw_init(); 292 #endif 293 #ifdef CONFIG_ATMEL_SDHCI 294 #ifdef CONFIG_ATMEL_SDHCI0 295 board_sdhci0_hw_init(); 296 #endif 297 #ifdef CONFIG_ATMEL_SDHCI1 298 board_sdhci1_hw_init(); 299 #endif 300 #endif 301 } 302 303 static void ddrc_conf(struct atmel_mpddrc_config *ddrc) 304 { 305 ddrc->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR3_SDRAM); 306 307 ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | 308 ATMEL_MPDDRC_CR_NR_ROW_14 | 309 ATMEL_MPDDRC_CR_CAS_DDR_CAS5 | 310 ATMEL_MPDDRC_CR_DIC_DS | 311 ATMEL_MPDDRC_CR_DIS_DLL | 312 ATMEL_MPDDRC_CR_NB_8BANKS | 313 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED | 314 ATMEL_MPDDRC_CR_UNAL_SUPPORTED); 315 316 ddrc->rtr = 0x511; 317 318 ddrc->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET | 319 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET | 320 4 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | 321 9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | 322 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | 323 4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | 324 4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | 325 4 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); 326 327 ddrc->tpr1 = (27 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET | 328 29 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET | 329 0 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET | 330 3 << ATMEL_MPDDRC_TPR1_TXP_OFFSET); 331 332 ddrc->tpr2 = (0 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET | 333 0 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET | 334 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET | 335 4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET | 336 7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET); 337 } 338 339 void mem_init(void) 340 { 341 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; 342 struct atmel_mpddr *mpddrc = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC; 343 struct atmel_mpddrc_config ddrc_config; 344 u32 reg; 345 346 ddrc_conf(&ddrc_config); 347 348 at91_periph_clk_enable(ATMEL_ID_MPDDRC); 349 writel(AT91_PMC_DDR, &pmc->scer); 350 351 reg = readl(&mpddrc->io_calibr); 352 reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV; 353 reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55; 354 reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO; 355 reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(100); 356 writel(reg, &mpddrc->io_calibr); 357 358 writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_TWO_CYCLE, 359 &mpddrc->rd_data_path); 360 361 ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config); 362 363 writel(0x3, &mpddrc->cal_mr4); 364 writel(64, &mpddrc->tim_cal); 365 } 366 367 void at91_pmc_init(void) 368 { 369 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; 370 u32 tmp; 371 372 tmp = AT91_PMC_PLLAR_29 | 373 AT91_PMC_PLLXR_PLLCOUNT(0x3f) | 374 AT91_PMC_PLLXR_MUL(82) | 375 AT91_PMC_PLLXR_DIV(1); 376 at91_plla_init(tmp); 377 378 writel(0x0 << 8, &pmc->pllicpr); 379 380 tmp = AT91_PMC_MCKR_H32MXDIV | 381 AT91_PMC_MCKR_PLLADIV_2 | 382 AT91_PMC_MCKR_MDIV_3 | 383 AT91_PMC_MCKR_CSS_PLLA; 384 at91_mck_init(tmp); 385 } 386 #endif 387