blob: 28a974d9789a78b91e631e0f0264a7fca8aa5ee4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher3757e972013-12-02 07:47:23 +01002/*
3 * Board functions for Siemens CORVUS (AT91SAM9G45) based board
4 * (C) Copyright 2013 Siemens AG
5 *
6 * Based on:
7 * U-Boot file: board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
8 * (C) Copyright 2007-2008
9 * Stelian Pop <stelian@popies.net>
10 * Lead Tech Design <www.leadtechdesign.com>
Heiko Schocher3757e972013-12-02 07:47:23 +010011 */
12
Heiko Schocher3757e972013-12-02 07:47:23 +010013#include <common.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020014#include <dm.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070015#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060016#include <log.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010017#include <asm/io.h>
18#include <asm/arch/at91sam9g45_matrix.h>
19#include <asm/arch/at91sam9_smc.h>
20#include <asm/arch/at91_common.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010021#include <asm/arch/at91_rstc.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020022#include <asm/arch/atmel_serial.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010023#include <asm/arch/gpio.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020024#include <asm/gpio.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010025#include <asm/arch/clk.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010026#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
27#include <net.h>
28#endif
Heiko Schocher914aff12016-05-25 07:23:45 +020029#ifndef CONFIG_DM_ETH
Heiko Schocher3757e972013-12-02 07:47:23 +010030#include <netdev.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020031#endif
Heiko Schocher3757e972013-12-02 07:47:23 +010032#include <spi.h>
33
Heiko Schocher08c5df22015-08-21 11:28:20 +020034#ifdef CONFIG_USB_GADGET_ATMEL_USBA
35#include <asm/arch/atmel_usba_udc.h>
36#endif
37
Heiko Schocher3757e972013-12-02 07:47:23 +010038DECLARE_GLOBAL_DATA_PTR;
39
Heiko Schocher914aff12016-05-25 07:23:45 +020040static void corvus_request_gpio(void)
41{
42 gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand ena");
43 gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand rdy");
44 gpio_request(AT91_PIN_PD7, "d0");
45 gpio_request(AT91_PIN_PD8, "d1");
46 gpio_request(AT91_PIN_PA12, "d2");
47 gpio_request(AT91_PIN_PA13, "d3");
48 gpio_request(AT91_PIN_PA15, "d4");
49 gpio_request(AT91_PIN_PB7, "recovery button");
50 gpio_request(AT91_PIN_PD1, "USB0");
51 gpio_request(AT91_PIN_PD3, "USB1");
52 gpio_request(AT91_PIN_PB18, "SPICS1");
53 gpio_request(AT91_PIN_PB3, "SPICS0");
54 gpio_request(CONFIG_RED_LED, "red led");
55 gpio_request(CONFIG_GREEN_LED, "green led");
56}
57
Heiko Schocher3757e972013-12-02 07:47:23 +010058static void corvus_nand_hw_init(void)
59{
60 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
61 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Heiko Schocher3757e972013-12-02 07:47:23 +010062 unsigned long csa;
63
64 /* Enable CS3 */
65 csa = readl(&matrix->ebicsa);
66 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
67 writel(csa, &matrix->ebicsa);
68
69 /* Configure SMC CS3 for NAND/SmartMedia */
Heiko Schocher22ab1322014-11-18 11:53:53 +010070 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
71 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
Heiko Schocher3757e972013-12-02 07:47:23 +010072 &smc->cs[3].setup);
Heiko Schocher22ab1322014-11-18 11:53:53 +010073 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
74 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
Heiko Schocher3757e972013-12-02 07:47:23 +010075 &smc->cs[3].pulse);
Heiko Schocher22ab1322014-11-18 11:53:53 +010076 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
Heiko Schocher3757e972013-12-02 07:47:23 +010077 &smc->cs[3].cycle);
78 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
79 AT91_SMC_MODE_EXNW_DISABLE |
80#ifdef CONFIG_SYS_NAND_DBW_16
81 AT91_SMC_MODE_DBW_16 |
82#else /* CONFIG_SYS_NAND_DBW_8 */
83 AT91_SMC_MODE_DBW_8 |
84#endif
85 AT91_SMC_MODE_TDF_CYCLE(3),
86 &smc->cs[3].mode);
87
Heiko Schocher25d74a32014-10-31 08:31:06 +010088 at91_periph_clk_enable(ATMEL_ID_PIOC);
Heiko Schocher22ab1322014-11-18 11:53:53 +010089 at91_periph_clk_enable(ATMEL_ID_PIOA);
Heiko Schocher3757e972013-12-02 07:47:23 +010090
91 /* Enable NandFlash */
92 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Heiko Schocher22ab1322014-11-18 11:53:53 +010093 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Heiko Schocher3757e972013-12-02 07:47:23 +010094}
Heiko Schocher25d74a32014-10-31 08:31:06 +010095
96#if defined(CONFIG_SPL_BUILD)
97#include <spl.h>
98#include <nand.h>
99
Heiko Schocher8189a082015-08-21 11:28:19 +0200100void spl_board_init(void)
Heiko Schocher25d74a32014-10-31 08:31:06 +0100101{
Heiko Schocher914aff12016-05-25 07:23:45 +0200102 corvus_request_gpio();
Heiko Schocher25d74a32014-10-31 08:31:06 +0100103 /*
104 * For on the sam9m10g45ek board, the chip wm9711 stay in the test
105 * mode, so it need do some action to exit mode.
106 */
107 at91_set_gpio_output(AT91_PIN_PD7, 0);
108 at91_set_gpio_output(AT91_PIN_PD8, 0);
109 at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
110 at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
111 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
112 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
113 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
114
115 corvus_nand_hw_init();
116
117 /* Configure recovery button PINs */
118 at91_set_gpio_input(AT91_PIN_PB7, 1);
119
120 /* check if button is pressed */
121 if (at91_get_gpio_value(AT91_PIN_PB7) == 0) {
122 u32 boot_device;
123
124 debug("Recovery button pressed\n");
125 boot_device = spl_boot_device();
126 switch (boot_device) {
127#ifdef CONFIG_SPL_NAND_SUPPORT
128 case BOOT_DEVICE_NAND:
129 nand_init();
130 spl_nand_erase_one(0, 0);
131 break;
Heiko Schocher3757e972013-12-02 07:47:23 +0100132#endif
Heiko Schocher25d74a32014-10-31 08:31:06 +0100133 }
134 }
135}
Heiko Schocher3757e972013-12-02 07:47:23 +0100136
Heiko Schocher25d74a32014-10-31 08:31:06 +0100137#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800138static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Heiko Schocher25d74a32014-10-31 08:31:06 +0100139{
140 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
141
142 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
143 ATMEL_MPDDRC_CR_NR_ROW_14 |
144 ATMEL_MPDDRC_CR_DIC_DS |
145 ATMEL_MPDDRC_CR_DQMS_SHARED |
146 ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
147 ddr2->rtr = 0x24b;
148
149 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
150 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
151 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
152 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 75 ns */
153 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
154 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
155 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
156 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
157
158 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
159 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
160 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
161 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
162
163 ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
164 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
165 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
166 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
167}
168
169void mem_init(void)
Heiko Schocher3757e972013-12-02 07:47:23 +0100170{
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800171 struct atmel_mpddrc_config ddr2;
Heiko Schocher3757e972013-12-02 07:47:23 +0100172
Heiko Schocher25d74a32014-10-31 08:31:06 +0100173 ddr2_conf(&ddr2);
174
Wenyou Yang78f89762016-02-03 10:16:50 +0800175 at91_system_clk_enable(AT91_PMC_DDR);
Heiko Schocher25d74a32014-10-31 08:31:06 +0100176
Heiko Schocher25d74a32014-10-31 08:31:06 +0100177 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200178 ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
Heiko Schocher25d74a32014-10-31 08:31:06 +0100179}
180#endif
181
182#ifdef CONFIG_CMD_USB
183static void taurus_usb_hw_init(void)
184{
185 at91_periph_clk_enable(ATMEL_ID_PIODE);
Heiko Schocher3757e972013-12-02 07:47:23 +0100186
187 at91_set_gpio_output(AT91_PIN_PD1, 0);
188 at91_set_gpio_output(AT91_PIN_PD3, 0);
189}
190#endif
191
192#ifdef CONFIG_MACB
193static void corvus_macb_hw_init(void)
194{
Heiko Schocher3757e972013-12-02 07:47:23 +0100195 /* Enable clock */
Heiko Schocher25d74a32014-10-31 08:31:06 +0100196 at91_periph_clk_enable(ATMEL_ID_EMAC);
Heiko Schocher3757e972013-12-02 07:47:23 +0100197
198 /*
199 * Disable pull-up on:
200 * RXDV (PA15) => PHY normal mode (not Test mode)
201 * ERX0 (PA12) => PHY ADDR0
202 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
203 *
204 * PHY has internal pull-down
205 */
206 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
207 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
208 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
209
210 at91_phy_reset();
211
212 /* Re-enable pull-up */
213 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
214 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
215 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
216
217 /* And the pins. */
218 at91_macb_hw_init();
219}
220#endif
221
222int board_early_init_f(void)
223{
224 at91_seriald_hw_init();
Heiko Schocher914aff12016-05-25 07:23:45 +0200225 corvus_request_gpio();
Heiko Schocher3757e972013-12-02 07:47:23 +0100226 return 0;
227}
228
Heiko Schocher08c5df22015-08-21 11:28:20 +0200229#ifdef CONFIG_USB_GADGET_ATMEL_USBA
230/* from ./arch/arm/mach-at91/armv7/sama5d3_devices.c */
231void at91_udp_hw_init(void)
232{
Heiko Schocher08c5df22015-08-21 11:28:20 +0200233 /* Enable UPLL clock */
Wenyou Yang0c252292016-02-02 11:11:54 +0800234 at91_upll_clk_enable();
Wenyou Yang78f89762016-02-03 10:16:50 +0800235
Heiko Schocher08c5df22015-08-21 11:28:20 +0200236 /* Enable UDPHS clock */
237 at91_periph_clk_enable(ATMEL_ID_UDPHS);
238}
239#endif
240
Heiko Schocher3757e972013-12-02 07:47:23 +0100241int board_init(void)
242{
243 /* address of boot parameters */
244 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
245
Heiko Schocher914aff12016-05-25 07:23:45 +0200246 /* we have to request the gpios again after relocation */
247 corvus_request_gpio();
Heiko Schocher3757e972013-12-02 07:47:23 +0100248#ifdef CONFIG_CMD_NAND
249 corvus_nand_hw_init();
250#endif
251#ifdef CONFIG_ATMEL_SPI
252 at91_spi0_hw_init(1 << 4);
253#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100254#ifdef CONFIG_MACB
255 corvus_macb_hw_init();
256#endif
257#ifdef CONFIG_CMD_USB
258 taurus_usb_hw_init();
259#endif
Heiko Schocher08c5df22015-08-21 11:28:20 +0200260#ifdef CONFIG_USB_GADGET_ATMEL_USBA
261 at91_udp_hw_init();
262 usba_udc_probe(&pdata);
263#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100264 return 0;
265}
266
267int dram_init(void)
268{
269 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
270 CONFIG_SYS_SDRAM_SIZE);
271 return 0;
272}
273
Heiko Schocher914aff12016-05-25 07:23:45 +0200274#ifndef CONFIG_DM_ETH
Heiko Schocher3757e972013-12-02 07:47:23 +0100275int board_eth_init(bd_t *bis)
276{
277 int rc = 0;
278#ifdef CONFIG_MACB
279 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
280#endif
281 return rc;
282}
Heiko Schocher914aff12016-05-25 07:23:45 +0200283#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100284
285/* SPI chip select control */
286int spi_cs_is_valid(unsigned int bus, unsigned int cs)
287{
288 return bus == 0 && cs < 2;
289}
290
291void spi_cs_activate(struct spi_slave *slave)
292{
293 switch (slave->cs) {
294 case 1:
295 at91_set_gpio_output(AT91_PIN_PB18, 0);
296 break;
297 case 0:
298 default:
299 at91_set_gpio_output(AT91_PIN_PB3, 0);
300 break;
301 }
302}
303
304void spi_cs_deactivate(struct spi_slave *slave)
305{
306 switch (slave->cs) {
307 case 1:
308 at91_set_gpio_output(AT91_PIN_PB18, 1);
309 break;
310 case 0:
311 default:
312 at91_set_gpio_output(AT91_PIN_PB3, 1);
313 break;
314 }
315}
Heiko Schocher914aff12016-05-25 07:23:45 +0200316
317static struct atmel_serial_platdata at91sam9260_serial_plat = {
318 .base_addr = ATMEL_BASE_DBGU,
319};
320
321U_BOOT_DEVICE(at91sam9260_serial) = {
322 .name = "serial_atmel",
323 .platdata = &at91sam9260_serial_plat,
324};