blob: a6e1737be0227f19bf614e94a6a431f9d5d2bce7 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010018#include <asm/io.h>
19#include <asm/arch/at91sam9g45_matrix.h>
20#include <asm/arch/at91sam9_smc.h>
21#include <asm/arch/at91_common.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010022#include <asm/arch/at91_rstc.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020023#include <asm/arch/atmel_serial.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010024#include <asm/arch/gpio.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020025#include <asm/gpio.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010026#include <asm/arch/clk.h>
Heiko Schocher3757e972013-12-02 07:47:23 +010027#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
28#include <net.h>
29#endif
Heiko Schocher914aff12016-05-25 07:23:45 +020030#ifndef CONFIG_DM_ETH
Heiko Schocher3757e972013-12-02 07:47:23 +010031#include <netdev.h>
Heiko Schocher914aff12016-05-25 07:23:45 +020032#endif
Heiko Schocher3757e972013-12-02 07:47:23 +010033#include <spi.h>
34
Heiko Schocher08c5df22015-08-21 11:28:20 +020035#ifdef CONFIG_USB_GADGET_ATMEL_USBA
36#include <asm/arch/atmel_usba_udc.h>
37#endif
38
Heiko Schocher3757e972013-12-02 07:47:23 +010039DECLARE_GLOBAL_DATA_PTR;
40
Heiko Schocher914aff12016-05-25 07:23:45 +020041static void corvus_request_gpio(void)
42{
43 gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand ena");
44 gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand rdy");
45 gpio_request(AT91_PIN_PD7, "d0");
46 gpio_request(AT91_PIN_PD8, "d1");
47 gpio_request(AT91_PIN_PA12, "d2");
48 gpio_request(AT91_PIN_PA13, "d3");
49 gpio_request(AT91_PIN_PA15, "d4");
50 gpio_request(AT91_PIN_PB7, "recovery button");
51 gpio_request(AT91_PIN_PD1, "USB0");
52 gpio_request(AT91_PIN_PD3, "USB1");
53 gpio_request(AT91_PIN_PB18, "SPICS1");
54 gpio_request(AT91_PIN_PB3, "SPICS0");
55 gpio_request(CONFIG_RED_LED, "red led");
56 gpio_request(CONFIG_GREEN_LED, "green led");
57}
58
Heiko Schocher3757e972013-12-02 07:47:23 +010059static void corvus_nand_hw_init(void)
60{
61 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
62 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Heiko Schocher3757e972013-12-02 07:47:23 +010063 unsigned long csa;
64
65 /* Enable CS3 */
66 csa = readl(&matrix->ebicsa);
67 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
68 writel(csa, &matrix->ebicsa);
69
70 /* Configure SMC CS3 for NAND/SmartMedia */
Heiko Schocher22ab1322014-11-18 11:53:53 +010071 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
72 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
Heiko Schocher3757e972013-12-02 07:47:23 +010073 &smc->cs[3].setup);
Heiko Schocher22ab1322014-11-18 11:53:53 +010074 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
75 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
Heiko Schocher3757e972013-12-02 07:47:23 +010076 &smc->cs[3].pulse);
Heiko Schocher22ab1322014-11-18 11:53:53 +010077 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
Heiko Schocher3757e972013-12-02 07:47:23 +010078 &smc->cs[3].cycle);
79 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
80 AT91_SMC_MODE_EXNW_DISABLE |
81#ifdef CONFIG_SYS_NAND_DBW_16
82 AT91_SMC_MODE_DBW_16 |
83#else /* CONFIG_SYS_NAND_DBW_8 */
84 AT91_SMC_MODE_DBW_8 |
85#endif
86 AT91_SMC_MODE_TDF_CYCLE(3),
87 &smc->cs[3].mode);
88
Heiko Schocher25d74a32014-10-31 08:31:06 +010089 at91_periph_clk_enable(ATMEL_ID_PIOC);
Heiko Schocher22ab1322014-11-18 11:53:53 +010090 at91_periph_clk_enable(ATMEL_ID_PIOA);
Heiko Schocher3757e972013-12-02 07:47:23 +010091
92 /* Enable NandFlash */
93 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Heiko Schocher22ab1322014-11-18 11:53:53 +010094 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Heiko Schocher3757e972013-12-02 07:47:23 +010095}
Heiko Schocher25d74a32014-10-31 08:31:06 +010096
97#if defined(CONFIG_SPL_BUILD)
98#include <spl.h>
99#include <nand.h>
100
Heiko Schocher8189a082015-08-21 11:28:19 +0200101void spl_board_init(void)
Heiko Schocher25d74a32014-10-31 08:31:06 +0100102{
Heiko Schocher914aff12016-05-25 07:23:45 +0200103 corvus_request_gpio();
Heiko Schocher25d74a32014-10-31 08:31:06 +0100104 /*
105 * For on the sam9m10g45ek board, the chip wm9711 stay in the test
106 * mode, so it need do some action to exit mode.
107 */
108 at91_set_gpio_output(AT91_PIN_PD7, 0);
109 at91_set_gpio_output(AT91_PIN_PD8, 0);
110 at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
111 at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
112 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
113 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
114 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
115
116 corvus_nand_hw_init();
117
118 /* Configure recovery button PINs */
119 at91_set_gpio_input(AT91_PIN_PB7, 1);
120
121 /* check if button is pressed */
122 if (at91_get_gpio_value(AT91_PIN_PB7) == 0) {
123 u32 boot_device;
124
125 debug("Recovery button pressed\n");
126 boot_device = spl_boot_device();
127 switch (boot_device) {
128#ifdef CONFIG_SPL_NAND_SUPPORT
129 case BOOT_DEVICE_NAND:
130 nand_init();
131 spl_nand_erase_one(0, 0);
132 break;
Heiko Schocher3757e972013-12-02 07:47:23 +0100133#endif
Heiko Schocher25d74a32014-10-31 08:31:06 +0100134 }
135 }
136}
Heiko Schocher3757e972013-12-02 07:47:23 +0100137
Heiko Schocher25d74a32014-10-31 08:31:06 +0100138#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800139static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Heiko Schocher25d74a32014-10-31 08:31:06 +0100140{
141 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
142
143 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
144 ATMEL_MPDDRC_CR_NR_ROW_14 |
145 ATMEL_MPDDRC_CR_DIC_DS |
146 ATMEL_MPDDRC_CR_DQMS_SHARED |
147 ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
148 ddr2->rtr = 0x24b;
149
150 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
151 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
152 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
153 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 75 ns */
154 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
155 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
156 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
157 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
158
159 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
160 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
161 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
162 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
163
164 ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
165 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
166 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
167 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
168}
169
170void mem_init(void)
Heiko Schocher3757e972013-12-02 07:47:23 +0100171{
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800172 struct atmel_mpddrc_config ddr2;
Heiko Schocher3757e972013-12-02 07:47:23 +0100173
Heiko Schocher25d74a32014-10-31 08:31:06 +0100174 ddr2_conf(&ddr2);
175
Wenyou Yang78f89762016-02-03 10:16:50 +0800176 at91_system_clk_enable(AT91_PMC_DDR);
Heiko Schocher25d74a32014-10-31 08:31:06 +0100177
Heiko Schocher25d74a32014-10-31 08:31:06 +0100178 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200179 ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
Heiko Schocher25d74a32014-10-31 08:31:06 +0100180}
181#endif
182
183#ifdef CONFIG_CMD_USB
184static void taurus_usb_hw_init(void)
185{
186 at91_periph_clk_enable(ATMEL_ID_PIODE);
Heiko Schocher3757e972013-12-02 07:47:23 +0100187
188 at91_set_gpio_output(AT91_PIN_PD1, 0);
189 at91_set_gpio_output(AT91_PIN_PD3, 0);
190}
191#endif
192
193#ifdef CONFIG_MACB
194static void corvus_macb_hw_init(void)
195{
Heiko Schocher3757e972013-12-02 07:47:23 +0100196 /* Enable clock */
Heiko Schocher25d74a32014-10-31 08:31:06 +0100197 at91_periph_clk_enable(ATMEL_ID_EMAC);
Heiko Schocher3757e972013-12-02 07:47:23 +0100198
199 /*
200 * Disable pull-up on:
201 * RXDV (PA15) => PHY normal mode (not Test mode)
202 * ERX0 (PA12) => PHY ADDR0
203 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
204 *
205 * PHY has internal pull-down
206 */
207 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
208 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
209 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
210
211 at91_phy_reset();
212
213 /* Re-enable pull-up */
214 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
215 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
216 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
217
218 /* And the pins. */
219 at91_macb_hw_init();
220}
221#endif
222
223int board_early_init_f(void)
224{
225 at91_seriald_hw_init();
Heiko Schocher914aff12016-05-25 07:23:45 +0200226 corvus_request_gpio();
Heiko Schocher3757e972013-12-02 07:47:23 +0100227 return 0;
228}
229
Heiko Schocher08c5df22015-08-21 11:28:20 +0200230#ifdef CONFIG_USB_GADGET_ATMEL_USBA
231/* from ./arch/arm/mach-at91/armv7/sama5d3_devices.c */
232void at91_udp_hw_init(void)
233{
Heiko Schocher08c5df22015-08-21 11:28:20 +0200234 /* Enable UPLL clock */
Wenyou Yang0c252292016-02-02 11:11:54 +0800235 at91_upll_clk_enable();
Wenyou Yang78f89762016-02-03 10:16:50 +0800236
Heiko Schocher08c5df22015-08-21 11:28:20 +0200237 /* Enable UDPHS clock */
238 at91_periph_clk_enable(ATMEL_ID_UDPHS);
239}
240#endif
241
Heiko Schocher3757e972013-12-02 07:47:23 +0100242int board_init(void)
243{
244 /* address of boot parameters */
245 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
246
Heiko Schocher914aff12016-05-25 07:23:45 +0200247 /* we have to request the gpios again after relocation */
248 corvus_request_gpio();
Heiko Schocher3757e972013-12-02 07:47:23 +0100249#ifdef CONFIG_CMD_NAND
250 corvus_nand_hw_init();
251#endif
252#ifdef CONFIG_ATMEL_SPI
253 at91_spi0_hw_init(1 << 4);
254#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100255#ifdef CONFIG_MACB
256 corvus_macb_hw_init();
257#endif
258#ifdef CONFIG_CMD_USB
259 taurus_usb_hw_init();
260#endif
Heiko Schocher08c5df22015-08-21 11:28:20 +0200261#ifdef CONFIG_USB_GADGET_ATMEL_USBA
262 at91_udp_hw_init();
263 usba_udc_probe(&pdata);
264#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100265 return 0;
266}
267
268int dram_init(void)
269{
270 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
271 CONFIG_SYS_SDRAM_SIZE);
272 return 0;
273}
274
Heiko Schocher914aff12016-05-25 07:23:45 +0200275#ifndef CONFIG_DM_ETH
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900276int board_eth_init(struct bd_info *bis)
Heiko Schocher3757e972013-12-02 07:47:23 +0100277{
278 int rc = 0;
279#ifdef CONFIG_MACB
280 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
281#endif
282 return rc;
283}
Heiko Schocher914aff12016-05-25 07:23:45 +0200284#endif
Heiko Schocher3757e972013-12-02 07:47:23 +0100285
286/* SPI chip select control */
287int spi_cs_is_valid(unsigned int bus, unsigned int cs)
288{
289 return bus == 0 && cs < 2;
290}
291
292void spi_cs_activate(struct spi_slave *slave)
293{
294 switch (slave->cs) {
295 case 1:
296 at91_set_gpio_output(AT91_PIN_PB18, 0);
297 break;
298 case 0:
299 default:
300 at91_set_gpio_output(AT91_PIN_PB3, 0);
301 break;
302 }
303}
304
305void spi_cs_deactivate(struct spi_slave *slave)
306{
307 switch (slave->cs) {
308 case 1:
309 at91_set_gpio_output(AT91_PIN_PB18, 1);
310 break;
311 case 0:
312 default:
313 at91_set_gpio_output(AT91_PIN_PB3, 1);
314 break;
315 }
316}
Heiko Schocher914aff12016-05-25 07:23:45 +0200317
Simon Glassb75b15b2020-12-03 16:55:23 -0700318static struct atmel_serial_plat at91sam9260_serial_plat = {
Heiko Schocher914aff12016-05-25 07:23:45 +0200319 .base_addr = ATMEL_BASE_DBGU,
320};
321
Simon Glass1d8364a2020-12-28 20:34:54 -0700322U_BOOT_DRVINFO(at91sam9260_serial) = {
Heiko Schocher914aff12016-05-25 07:23:45 +0200323 .name = "serial_atmel",
Simon Glass71fa5b42020-12-03 16:55:18 -0700324 .plat = &at91sam9260_serial_plat,
Heiko Schocher914aff12016-05-25 07:23:45 +0200325};