blob: 7ccadf214a108729890d5a9d6707bb10440db586 [file] [log] [blame]
Wenyou Yang75238f22015-10-30 09:55:52 +08001/*
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>
Wenyou Yang75238f22015-10-30 09:55:52 +080018#include <asm/arch/atmel_pio4.h>
Wenyou Yang37dadbc2016-02-01 18:18:21 +080019#include <asm/arch/atmel_mpddrc.h>
Wenyou Yang75238f22015-10-30 09:55:52 +080020#include <asm/arch/atmel_usba_udc.h>
21#include <asm/arch/atmel_sdhci.h>
22#include <asm/arch/clk.h>
23#include <asm/arch/gpio.h>
24#include <asm/arch/sama5d2.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
Wenyou Yang75238f22015-10-30 09:55:52 +080028static void board_usb_hw_init(void)
29{
30 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 10, 1);
31}
32
33#ifdef CONFIG_LCD
34vidinfo_t panel_info = {
35 .vl_col = 480,
36 .vl_row = 272,
37 .vl_clk = 9000000,
38 .vl_bpix = LCD_BPP,
39 .vl_tft = 1,
40 .vl_hsync_len = 41,
41 .vl_left_margin = 2,
42 .vl_right_margin = 2,
43 .vl_vsync_len = 11,
44 .vl_upper_margin = 2,
45 .vl_lower_margin = 2,
46 .mmio = ATMEL_BASE_LCDC,
47};
48
49/* No power up/down pin for the LCD pannel */
50void lcd_enable(void) { /* Empty! */ }
51void lcd_disable(void) { /* Empty! */ }
52
53unsigned int has_lcdc(void)
54{
55 return 1;
56}
57
58static void board_lcd_hw_init(void)
59{
60 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 28, 0); /* LCDPWM */
61 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 29, 0); /* LCDDISP */
62 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 30, 0); /* LCDVSYNC */
63 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 31, 0); /* LCDHSYNC */
64 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 0, 0); /* LCDPCK */
65 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 1, 0); /* LCDDEN */
66
67 /* LCDDAT0 */
68 /* LCDDAT1 */
69 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDDAT2 */
70 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDDAT3 */
71 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 12, 0); /* LCDDAT4 */
72 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 13, 0); /* LCDDAT5 */
73 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDDAT6 */
74 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDDAT7 */
75
76 /* LCDDAT8 */
77 /* LCDDAT9 */
78 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDDAT10 */
79 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 17, 0); /* LCDDAT11 */
80 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDDAT12 */
81 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDDAT13 */
82 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 20, 0); /* LCDDAT14 */
83 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 21, 0); /* LCDDAT15 */
84
85 /* LCDD16 */
86 /* LCDD17 */
87 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDDAT18 */
88 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDDAT19 */
89 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDDAT20 */
90 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 25, 0); /* LCDDAT21 */
91 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDDAT22 */
92 atmel_pio4_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDDAT23 */
93
94 at91_periph_clk_enable(ATMEL_ID_LCDC);
95}
96
97#ifdef CONFIG_LCD_INFO
98void lcd_show_board_info(void)
99{
100 ulong dram_size;
101 int i;
102 char temp[32];
103
104 lcd_printf("%s\n", U_BOOT_VERSION);
105 lcd_printf("2015 ATMEL Corp\n");
106 lcd_printf("%s CPU at %s MHz\n", get_cpu_name(),
107 strmhz(temp, get_cpu_clk_rate()));
108
109 dram_size = 0;
110 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
111 dram_size += gd->bd->bi_dram[i].size;
112
113 lcd_printf("%ld MB SDRAM\n", dram_size >> 20);
114}
115#endif /* CONFIG_LCD_INFO */
116#endif /* CONFIG_LCD */
117
118static void board_gmac_hw_init(void)
119{
120 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 14, 0); /* GTXCK */
121 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 15, 0); /* GTXEN */
122 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 16, 0); /* GRXDV */
123 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 17, 0); /* GRXER */
124 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 18, 0); /* GRX0 */
125 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 19, 0); /* GRX1 */
126 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 20, 0); /* GTX0 */
127 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 21, 0); /* GTX1 */
128 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 22, 0); /* GMDC */
129 atmel_pio4_set_f_periph(AT91_PIO_PORTB, 23, 0); /* GMDIO */
130
131 at91_periph_clk_enable(ATMEL_ID_GMAC);
132}
133
Wenyou Yang75238f22015-10-30 09:55:52 +0800134static void board_uart1_hw_init(void)
135{
136 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 2, 1); /* URXD1 */
137 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 3, 0); /* UTXD1 */
138
139 at91_periph_clk_enable(ATMEL_ID_UART1);
140}
141
142int board_early_init_f(void)
143{
Wenyou Yang75238f22015-10-30 09:55:52 +0800144 board_uart1_hw_init();
145
146 return 0;
147}
148
149int board_init(void)
150{
151 /* address of boot parameters */
152 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
153
Wenyou Yang75238f22015-10-30 09:55:52 +0800154#ifdef CONFIG_MACB
155 board_gmac_hw_init();
156#endif
157#ifdef CONFIG_LCD
158 board_lcd_hw_init();
159#endif
160#ifdef CONFIG_CMD_USB
161 board_usb_hw_init();
162#endif
163#ifdef CONFIG_USB_GADGET_ATMEL_USBA
164 at91_udp_hw_init();
165#endif
166
167 return 0;
168}
169
170int dram_init(void)
171{
172 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
173 CONFIG_SYS_SDRAM_SIZE);
174 return 0;
175}
176
177int board_eth_init(bd_t *bis)
178{
179 int rc = 0;
180
181#ifdef CONFIG_MACB
182 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC, 0x00);
183#endif
184
185#ifdef CONFIG_USB_GADGET_ATMEL_USBA
186 usba_udc_probe(&pdata);
187#ifdef CONFIG_USB_ETH_RNDIS
188 usb_eth_initialize(bis);
189#endif
190#endif
191
192 return rc;
193}
Wenyou Yang37dadbc2016-02-01 18:18:21 +0800194
195/* SPL */
196#ifdef CONFIG_SPL_BUILD
197void spl_board_init(void)
198{
Wenyou Yang37dadbc2016-02-01 18:18:21 +0800199}
200
201static void ddrc_conf(struct atmel_mpddrc_config *ddrc)
202{
203 ddrc->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR3_SDRAM);
204
205 ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
206 ATMEL_MPDDRC_CR_NR_ROW_14 |
207 ATMEL_MPDDRC_CR_CAS_DDR_CAS5 |
208 ATMEL_MPDDRC_CR_DIC_DS |
209 ATMEL_MPDDRC_CR_DIS_DLL |
210 ATMEL_MPDDRC_CR_NB_8BANKS |
211 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
212 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
213
214 ddrc->rtr = 0x511;
215
216 ddrc->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
217 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
218 4 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
219 9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
220 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
221 4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
222 4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
223 4 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
224
225 ddrc->tpr1 = (27 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET |
226 29 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
227 0 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
228 3 << ATMEL_MPDDRC_TPR1_TXP_OFFSET);
229
230 ddrc->tpr2 = (0 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET |
231 0 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
232 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
233 4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
234 7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET);
235}
236
237void mem_init(void)
238{
239 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
240 struct atmel_mpddr *mpddrc = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC;
241 struct atmel_mpddrc_config ddrc_config;
242 u32 reg;
243
244 ddrc_conf(&ddrc_config);
245
246 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
247 writel(AT91_PMC_DDR, &pmc->scer);
248
249 reg = readl(&mpddrc->io_calibr);
250 reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV;
251 reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55;
252 reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO;
253 reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(100);
254 writel(reg, &mpddrc->io_calibr);
255
256 writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_TWO_CYCLE,
257 &mpddrc->rd_data_path);
258
259 ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config);
260
261 writel(0x3, &mpddrc->cal_mr4);
262 writel(64, &mpddrc->tim_cal);
263}
264
265void at91_pmc_init(void)
266{
267 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
268 u32 tmp;
269
270 tmp = AT91_PMC_PLLAR_29 |
271 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
272 AT91_PMC_PLLXR_MUL(82) |
273 AT91_PMC_PLLXR_DIV(1);
274 at91_plla_init(tmp);
275
276 writel(0x0 << 8, &pmc->pllicpr);
277
278 tmp = AT91_PMC_MCKR_H32MXDIV |
279 AT91_PMC_MCKR_PLLADIV_2 |
280 AT91_PMC_MCKR_MDIV_3 |
281 AT91_PMC_MCKR_CSS_PLLA;
282 at91_mck_init(tmp);
283}
284#endif