]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
ce4054bf WY |
2 | /* |
3 | * Copyright (C) 2017 Microchip Corporation | |
4 | * Wenyou.Yang <[email protected]> | |
ce4054bf WY |
5 | */ |
6 | ||
ce4054bf | 7 | #include <debug_uart.h> |
73c1589f | 8 | #include <fdtdec.h> |
5255932f | 9 | #include <init.h> |
401d1c4f | 10 | #include <asm/global_data.h> |
ce4054bf WY |
11 | #include <asm/io.h> |
12 | #include <asm/arch/at91_common.h> | |
13 | #include <asm/arch/atmel_pio4.h> | |
14 | #include <asm/arch/atmel_mpddrc.h> | |
15 | #include <asm/arch/atmel_sdhci.h> | |
16 | #include <asm/arch/clk.h> | |
17 | #include <asm/arch/gpio.h> | |
18 | #include <asm/arch/sama5d2.h> | |
19 | ||
67f551af EH |
20 | extern void at91_pda_detect(void); |
21 | ||
ce4054bf WY |
22 | DECLARE_GLOBAL_DATA_PTR; |
23 | ||
d05fc47b MS |
24 | static void rgb_leds_init(void) |
25 | { | |
26 | atmel_pio4_set_pio_output(AT91_PIO_PORTA, 10, 0); /* LED RED */ | |
27 | atmel_pio4_set_pio_output(AT91_PIO_PORTB, 1, 0); /* LED GREEN */ | |
28 | atmel_pio4_set_pio_output(AT91_PIO_PORTA, 31, 1); /* LED BLUE */ | |
29 | } | |
30 | ||
ef5a7438 | 31 | #ifdef CONFIG_CMD_USB |
ce4054bf WY |
32 | static void board_usb_hw_init(void) |
33 | { | |
528a42a7 | 34 | atmel_pio4_set_pio_output(AT91_PIO_PORTA, 27, 1); |
ce4054bf | 35 | } |
ef5a7438 | 36 | #endif |
ce4054bf WY |
37 | |
38 | #ifdef CONFIG_BOARD_LATE_INIT | |
39 | int board_late_init(void) | |
40 | { | |
b86986c7 | 41 | #ifdef CONFIG_VIDEO |
ce4054bf WY |
42 | at91_video_show_board_info(); |
43 | #endif | |
67f551af | 44 | at91_pda_detect(); |
ce4054bf WY |
45 | return 0; |
46 | } | |
47 | #endif | |
48 | ||
49 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT | |
50 | static void board_uart1_hw_init(void) | |
51 | { | |
8ee54672 | 52 | atmel_pio4_set_a_periph(AT91_PIO_PORTD, 2, ATMEL_PIO_PUEN_MASK); /* URXD1 */ |
ce4054bf WY |
53 | atmel_pio4_set_a_periph(AT91_PIO_PORTD, 3, 0); /* UTXD1 */ |
54 | ||
55 | at91_periph_clk_enable(ATMEL_ID_UART1); | |
56 | } | |
57 | ||
58 | void board_debug_uart_init(void) | |
59 | { | |
60 | board_uart1_hw_init(); | |
61 | } | |
62 | #endif | |
63 | ||
64 | #ifdef CONFIG_BOARD_EARLY_INIT_F | |
65 | int board_early_init_f(void) | |
66 | { | |
ce4054bf WY |
67 | return 0; |
68 | } | |
69 | #endif | |
70 | ||
71 | int board_init(void) | |
72 | { | |
73 | /* address of boot parameters */ | |
73c1589f | 74 | gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100; |
ce4054bf | 75 | |
d05fc47b MS |
76 | rgb_leds_init(); |
77 | ||
ce4054bf WY |
78 | #ifdef CONFIG_CMD_USB |
79 | board_usb_hw_init(); | |
80 | #endif | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
73c1589f CL |
85 | int dram_init_banksize(void) |
86 | { | |
87 | return fdtdec_setup_memory_banksize(); | |
88 | } | |
89 | ||
ce4054bf WY |
90 | int dram_init(void) |
91 | { | |
73c1589f | 92 | return fdtdec_setup_mem_size_base(); |
ce4054bf WY |
93 | } |
94 | ||
95 | #define MAC24AA_MAC_OFFSET 0xfa | |
96 | ||
97 | #ifdef CONFIG_MISC_INIT_R | |
98 | int misc_init_r(void) | |
99 | { | |
100 | #ifdef CONFIG_I2C_EEPROM | |
101 | at91_set_ethaddr(MAC24AA_MAC_OFFSET); | |
102 | #endif | |
103 | return 0; | |
104 | } | |
105 | #endif | |
106 | ||
107 | /* SPL */ | |
dac3ce97 | 108 | #ifdef CONFIG_XPL_BUILD |
ce4054bf WY |
109 | void spl_board_init(void) |
110 | { | |
111 | } | |
112 | ||
113 | static void ddrc_conf(struct atmel_mpddrc_config *ddrc) | |
114 | { | |
115 | ddrc->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM); | |
116 | ||
117 | ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 | | |
118 | ATMEL_MPDDRC_CR_NR_ROW_13 | | |
119 | ATMEL_MPDDRC_CR_CAS_DDR_CAS3 | | |
120 | ATMEL_MPDDRC_CR_DIC_DS | | |
121 | ATMEL_MPDDRC_CR_ZQ_LONG | | |
122 | ATMEL_MPDDRC_CR_NB_8BANKS | | |
123 | ATMEL_MPDDRC_CR_DECOD_INTERLEAVED | | |
124 | ATMEL_MPDDRC_CR_UNAL_SUPPORTED); | |
125 | ||
126 | ddrc->rtr = 0x511; | |
127 | ||
128 | ddrc->tpr0 = ((7 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET) | | |
129 | (3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET) | | |
130 | (3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET) | | |
131 | (9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET) | | |
132 | (3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET) | | |
133 | (4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET) | | |
134 | (4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET) | | |
135 | (2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET)); | |
136 | ||
137 | ddrc->tpr1 = ((22 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET) | | |
138 | (23 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET) | | |
139 | (200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET) | | |
140 | (3 << ATMEL_MPDDRC_TPR1_TXP_OFFSET)); | |
141 | ||
142 | ddrc->tpr2 = ((2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET) | | |
143 | (8 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET) | | |
144 | (4 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET) | | |
145 | (4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET) | | |
146 | (8 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET)); | |
147 | } | |
148 | ||
effe97d4 | 149 | void at91_mem_init(void) |
ce4054bf WY |
150 | { |
151 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; | |
152 | struct atmel_mpddr *mpddrc = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC; | |
153 | struct atmel_mpddrc_config ddrc_config; | |
154 | u32 reg; | |
155 | ||
156 | ddrc_conf(&ddrc_config); | |
157 | ||
158 | at91_periph_clk_enable(ATMEL_ID_MPDDRC); | |
159 | writel(AT91_PMC_DDR, &pmc->scer); | |
160 | ||
161 | reg = readl(&mpddrc->io_calibr); | |
162 | reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV; | |
163 | reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55; | |
164 | reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO; | |
165 | reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(101); | |
166 | writel(reg, &mpddrc->io_calibr); | |
167 | ||
168 | writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE, | |
169 | &mpddrc->rd_data_path); | |
170 | ||
171 | ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config); | |
172 | ||
173 | writel(0x3, &mpddrc->cal_mr4); | |
174 | writel(64, &mpddrc->tim_cal); | |
175 | } | |
176 | ||
177 | void at91_pmc_init(void) | |
178 | { | |
179 | u32 tmp; | |
180 | ||
181 | /* | |
182 | * while coming from the ROM code, we run on PLLA @ 492 MHz / 164 MHz | |
183 | * so we need to slow down and configure MCKR accordingly. | |
184 | * This is why we have a special flavor of the switching function. | |
185 | */ | |
186 | tmp = AT91_PMC_MCKR_PLLADIV_2 | | |
187 | AT91_PMC_MCKR_MDIV_3 | | |
188 | AT91_PMC_MCKR_CSS_MAIN; | |
189 | at91_mck_init_down(tmp); | |
190 | ||
191 | tmp = AT91_PMC_PLLAR_29 | | |
192 | AT91_PMC_PLLXR_PLLCOUNT(0x3f) | | |
193 | AT91_PMC_PLLXR_MUL(40) | | |
194 | AT91_PMC_PLLXR_DIV(1); | |
195 | at91_plla_init(tmp); | |
196 | ||
197 | tmp = AT91_PMC_MCKR_H32MXDIV | | |
198 | AT91_PMC_MCKR_PLLADIV_2 | | |
199 | AT91_PMC_MCKR_MDIV_3 | | |
200 | AT91_PMC_MCKR_CSS_PLLA; | |
201 | at91_mck_init(tmp); | |
202 | } | |
203 | #endif |