blob: 5d6cb24966d6618f2ea85449d56963cd1f09fa2e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Erik van Luijk29365df2015-08-17 12:47:34 +02002/*
3 * Board functions for mini-box PICOSAM9G45 (AT91SAM9G45) based board
4 * (C) Copyright 2015 Inter Act B.V.
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>
Erik van Luijk29365df2015-08-17 12:47:34 +020011 */
12
13#include <common.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070014#include <init.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070015#include <vsprintf.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Erik van Luijk29365df2015-08-17 12:47:34 +020017#include <asm/io.h>
18#include <asm/arch/clk.h>
19#include <asm/arch/at91sam9g45_matrix.h>
20#include <asm/arch/at91sam9_smc.h>
21#include <asm/arch/at91_common.h>
Erik van Luijk29365df2015-08-17 12:47:34 +020022#include <asm/arch/gpio.h>
23#include <asm/arch/clk.h>
24#include <lcd.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090025#include <linux/mtd/rawnand.h>
Erik van Luijk29365df2015-08-17 12:47:34 +020026#include <atmel_lcdc.h>
27#include <atmel_mci.h>
28#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
29#include <net.h>
30#endif
31#include <netdev.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060032#include <asm/mach-types.h>
Erik van Luijk29365df2015-08-17 12:47:34 +020033
34DECLARE_GLOBAL_DATA_PTR;
35
36/* ------------------------------------------------------------------------- */
37/*
38 * Miscelaneous platform dependent initialisations
39 */
40
41#if defined(CONFIG_SPL_BUILD)
42#include <spl.h>
43
44void at91_spl_board_init(void)
45{
46#ifdef CONFIG_SYS_USE_MMC
47 at91_mci_hw_init();
48#endif
49}
50
51#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +080052static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Erik van Luijk29365df2015-08-17 12:47:34 +020053{
54 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
55
56 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
57 ATMEL_MPDDRC_CR_NR_ROW_14 |
58 ATMEL_MPDDRC_CR_DQMS_SHARED |
59 ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
60
61 ddr2->rtr = 0x24b;
62
63 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
64 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
65 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
66 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
67 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
68 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
69 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
70 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
71
72 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
73 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
74 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
75 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
76
77 ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
78 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
79 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
80 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
81}
82
83void mem_init(void)
84{
Erik van Luijk29365df2015-08-17 12:47:34 +020085 struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Wenyou Yangaa0a58d2016-02-01 18:12:15 +080086 struct atmel_mpddrc_config ddr2;
Erik van Luijk29365df2015-08-17 12:47:34 +020087 unsigned long csa;
88
89 ddr2_conf(&ddr2);
90
Wenyou Yang78f89762016-02-03 10:16:50 +080091 at91_system_clk_enable(AT91_PMC_DDR);
Erik van Luijk29365df2015-08-17 12:47:34 +020092
93 /* Chip select 1 is for DDR2/SDRAM */
94 csa = readl(&mat->ebicsa);
95 csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
96 csa &= ~AT91_MATRIX_EBI_VDDIOMSEL_3_3V;
97 writel(csa, &mat->ebicsa);
98
99 /* DDRAM2 Controller initialize */
100 ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
101 ddr2_init(ATMEL_BASE_DDRSDRC1, ATMEL_BASE_CS1, &ddr2);
102}
103#endif
104
105#ifdef CONFIG_CMD_USB
106static void picosam9g45_usb_hw_init(void)
107{
Wenyou Yang78f89762016-02-03 10:16:50 +0800108 at91_periph_clk_enable(ATMEL_ID_PIODE);
Erik van Luijk29365df2015-08-17 12:47:34 +0200109
110 at91_set_gpio_output(AT91_PIN_PD1, 0);
111 at91_set_gpio_output(AT91_PIN_PD3, 0);
112}
113#endif
114
115#ifdef CONFIG_MACB
116static void picosam9g45_macb_hw_init(void)
117{
Erik van Luijk29365df2015-08-17 12:47:34 +0200118 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
119
Wenyou Yang78f89762016-02-03 10:16:50 +0800120 at91_periph_clk_enable(ATMEL_ID_EMAC);
Erik van Luijk29365df2015-08-17 12:47:34 +0200121
122 /*
123 * Disable pull-up on:
124 * RXDV (PA15) => PHY normal mode (not Test mode)
125 * ERX0 (PA12) => PHY ADDR0
126 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
127 *
128 * PHY has internal pull-down
129 */
130 writel(pin_to_mask(AT91_PIN_PA15) |
131 pin_to_mask(AT91_PIN_PA12) |
132 pin_to_mask(AT91_PIN_PA13),
133 &pioa->pudr);
134
135 at91_phy_reset();
136
137 /* Re-enable pull-up */
138 writel(pin_to_mask(AT91_PIN_PA15) |
139 pin_to_mask(AT91_PIN_PA12) |
140 pin_to_mask(AT91_PIN_PA13),
141 &pioa->puer);
142
143 /* And the pins. */
144 at91_macb_hw_init();
145}
146#endif
147
148#ifdef CONFIG_LCD
149
150vidinfo_t panel_info = {
151 .vl_col = 480,
152 .vl_row = 272,
153 .vl_clk = 9000000,
154 .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
155 ATMEL_LCDC_INVFRAME_NORMAL,
156 .vl_bpix = 3,
157 .vl_tft = 1,
158 .vl_hsync_len = 45,
159 .vl_left_margin = 1,
160 .vl_right_margin = 1,
161 .vl_vsync_len = 1,
162 .vl_upper_margin = 40,
163 .vl_lower_margin = 1,
164 .mmio = ATMEL_BASE_LCDC,
165};
166
167
168void lcd_enable(void)
169{
170 at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
171}
172
173void lcd_disable(void)
174{
175 at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
176}
177
178static void picosam9g45_lcd_hw_init(void)
179{
Erik van Luijk29365df2015-08-17 12:47:34 +0200180 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
181 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
182 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
183 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
184 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
185
186 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
187 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
188 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
189 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
190 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
191 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
192 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
193 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
194 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
195 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
196 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
197 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
198 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
199 at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
200 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
201 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
202 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
203 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
204 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
205 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
206 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
207 at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
208 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
209 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
210
Wenyou Yang78f89762016-02-03 10:16:50 +0800211 at91_periph_clk_enable(ATMEL_ID_LCDC);
Erik van Luijk29365df2015-08-17 12:47:34 +0200212
213 gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
214}
215
216#ifdef CONFIG_LCD_INFO
217#include <nand.h>
218#include <version.h>
219
220void lcd_show_board_info(void)
221{
222 ulong dram_size;
223 int i;
224 char temp[32];
225
226 lcd_printf("%s\n", U_BOOT_VERSION);
227 lcd_printf("(C) 2015 Inter Act B.V.\n");
228 lcd_printf("support@interact.nl\n");
229 lcd_printf("%s CPU at %s MHz\n",
230 ATMEL_CPU_NAME,
231 strmhz(temp, get_cpu_clk_rate()));
232
233 dram_size = 0;
234 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
235 dram_size += gd->bd->bi_dram[i].size;
236 lcd_printf(" %ld MB SDRAM\n", dram_size >> 20);
237}
238#endif /* CONFIG_LCD_INFO */
239#endif
240
241#ifdef CONFIG_GENERIC_ATMEL_MCI
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900242int board_mmc_init(struct bd_info *bis)
Erik van Luijk29365df2015-08-17 12:47:34 +0200243{
244 at91_mci_hw_init();
245
246 return atmel_mci_init((void *)ATMEL_BASE_MCI0);
247}
248#endif
249
250int board_early_init_f(void)
251{
252 at91_seriald_hw_init();
253 return 0;
254}
255
256int board_init(void)
257{
Tom Rini48157342017-01-25 20:42:35 -0500258 gd->bd->bi_arch_number = MACH_TYPE_PICOSAM9G45;
259
Erik van Luijk29365df2015-08-17 12:47:34 +0200260 /* adress of boot parameters */
261 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
262
263#ifdef CONFIG_CMD_USB
264 picosam9g45_usb_hw_init();
265#endif
Erik van Luijk29365df2015-08-17 12:47:34 +0200266#ifdef CONFIG_ATMEL_SPI
267 at91_spi0_hw_init(1 << 4);
268#endif
269#ifdef CONFIG_MACB
270 picosam9g45_macb_hw_init();
271#endif
272#ifdef CONFIG_LCD
273 picosam9g45_lcd_hw_init();
274#endif
275 return 0;
276}
277
278int dram_init(void)
279{
280 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE)
281 + get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
282
283 return 0;
284}
285
Simon Glass2f949c32017-03-31 08:40:32 -0600286int dram_init_banksize(void)
Erik van Luijk29365df2015-08-17 12:47:34 +0200287{
288 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
289 gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1,
290 PHYS_SDRAM_1_SIZE);
291 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
292 gd->bd->bi_dram[1].size = get_ram_size((long *)PHYS_SDRAM_2,
293 PHYS_SDRAM_2_SIZE);
Simon Glass2f949c32017-03-31 08:40:32 -0600294
295 return 0;
Erik van Luijk29365df2015-08-17 12:47:34 +0200296}
297
298#ifdef CONFIG_RESET_PHY_R
299void reset_phy(void)
300{
301}
302#endif
303
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900304int board_eth_init(struct bd_info *bis)
Erik van Luijk29365df2015-08-17 12:47:34 +0200305{
306 int rc = 0;
307#ifdef CONFIG_MACB
308 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
309#endif
310 return rc;
311}
312
313/* SPI chip select control */
314#ifdef CONFIG_ATMEL_SPI
315#include <spi.h>
316
317int spi_cs_is_valid(unsigned int bus, unsigned int cs)
318{
319 return bus == 0 && cs < 2;
320}
321
322void spi_cs_activate(struct spi_slave *slave)
323{
324 switch (slave->cs) {
325 case 1:
326 at91_set_gpio_output(AT91_PIN_PB18, 0);
327 break;
328 case 0:
329 default:
330 at91_set_gpio_output(AT91_PIN_PB3, 0);
331 break;
332 }
333}
334
335void spi_cs_deactivate(struct spi_slave *slave)
336{
337 switch (slave->cs) {
338 case 1:
339 at91_set_gpio_output(AT91_PIN_PB18, 1);
340 break;
341 case 0:
342 default:
343 at91_set_gpio_output(AT91_PIN_PB3, 1);
344 break;
345 }
346}
347#endif /* CONFIG_ATMEL_SPI */