2 * (C) Copyright 2009-2012
3 * Jens Scharsig <esw@bus-elekronik.de>
4 * BuS Elektronik GmbH & Co. KG
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/sizes.h>
13 #include <asm/arch/hardware.h>
14 #include <asm/arch/clk.h>
15 #include <asm/arch/at91_matrix.h>
16 #include <asm/arch/at91sam9_smc.h>
17 #include <asm/arch/at91_pmc.h>
18 #include <asm/arch/at91_pio.h>
19 #include <asm/arch/at91sam9263.h>
20 #include <asm/arch/gpio.h>
21 #include <asm/arch/at91_common.h>
24 #include <atmel_lcdc.h>
25 #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
30 DECLARE_GLOBAL_DATA_PTR;
32 #ifdef CONFIG_CMD_NAND
33 static void vl_ma2sc_nand_hw_init(void)
36 at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC0;
37 at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
38 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
40 at91_set_pio_output(AT91_PIO_PORTA, 13, 1); /* CAN_TX -> H */
41 at91_set_pio_output(AT91_PIO_PORTA, 12, 1); /* CAN_STB -> H */
42 at91_set_pio_output(AT91_PIO_PORTA, 11, 1); /* CAN_EN -> H */
45 csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
46 writel(csa, &matrix->csa[0]);
48 /* Configure SMC CS3 for NAND/SmartMedia */
49 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
50 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
53 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
54 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
57 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
59 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
61 AT91_SMC_MODE_TDF_CYCLE(2),
63 writel((1 << ATMEL_ID_PIOB) | (1 << ATMEL_ID_PIOCDE),
66 /* Configure RDY/BSY */
67 #ifdef CONFIG_SYS_NAND_READY_PIN
68 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
70 /* Enable NandFlash */
71 at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
76 static void vl_ma2sc_macb_hw_init(void)
78 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
81 writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
90 vidinfo_t panel_info = {
94 .vl_sync = ATMEL_LCDC_INVDVAL_INVERTED |
95 ATMEL_LCDC_INVLINE_INVERTED |
96 ATMEL_LCDC_INVVD_INVERTED |
97 ATMEL_LCDC_INVFRAME_INVERTED,
98 .vl_bpix = (ATMEL_LCDC_PIXELSIZE_8 >> 5),
100 .vl_hsync_len = 5, /* Horiz Sync Pulse Width */
101 .vl_left_margin = 68, /* horiz back porch */
102 .vl_right_margin = 20, /* horiz front porch */
103 .vl_vsync_len = 2, /* vert Sync Pulse Width */
104 .vl_upper_margin = 18, /* vert back porch */
105 .vl_lower_margin = 4, /* vert front porch */
106 .mmio = ATMEL_BASE_LCDC,
109 void lcd_enable(void)
113 void lcd_disable(void)
117 static void vl_ma2sc_lcd_hw_init(void)
119 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
121 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDVSYNC */
122 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
123 at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
124 at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
125 at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
127 at91_set_a_periph(AT91_PIO_PORTC, 4, 0); /* LCDD0 */
128 at91_set_a_periph(AT91_PIO_PORTC, 5, 0); /* LCDD1 */
129 at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
130 at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
131 at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
132 at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
133 at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
134 at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
136 at91_set_a_periph(AT91_PIO_PORTC, 13, 0); /* LCDD9 */
137 at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
138 at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
139 at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
140 at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
141 at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
142 at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
144 at91_set_a_periph(AT91_PIO_PORTC, 20, 0); /* LCDD26 */
145 at91_set_a_periph(AT91_PIO_PORTC, 21, 0); /* LCDD17 */
146 at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
147 at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
148 at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
149 at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
150 at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
151 at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
153 at91_set_pio_output(AT91_PIO_PORTE, 0, 0); /* LCD QXH */
155 at91_set_pio_output(AT91_PIO_PORTE, 2, 0); /* LCD SHUT */
156 at91_set_pio_output(AT91_PIO_PORTE, 3, 1); /* LCD TopBottom */
157 at91_set_pio_output(AT91_PIO_PORTE, 4, 0); /* LCD REV */
158 at91_set_pio_output(AT91_PIO_PORTE, 5, 1); /* LCD RightLeft */
159 at91_set_pio_output(AT91_PIO_PORTE, 6, 0); /* LCD Color Mode CM */
160 at91_set_pio_output(AT91_PIO_PORTE, 7, 0); /* LCD BGR */
162 at91_set_pio_output(AT91_PIO_PORTB, 9, 0); /* LCD CC */
164 writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
165 gd->fb_base = ATMEL_BASE_SRAM0;
167 #endif /* Config LCD */
169 #ifdef CONFIG_BOARD_EARLY_INIT_F
170 int board_early_init_f(void)
172 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
174 /* Enable clocks for all PIOs */
175 writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
176 (1 << ATMEL_ID_PIOCDE),
179 at91_seriald_hw_init();
187 at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC0;
188 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
192 writel(pin, &pio->pioa.idr);
193 writel(pin, &pio->pioa.pudr);
194 writel(pin, &pio->pioa.per);
195 writel(pin, &pio->pioa.oer);
196 writel(pin, &pio->pioa.sodr);
197 writel((1 << 25), &pio->pioa.codr);
200 writel(pin, &pio->piob.idr);
201 writel(pin, &pio->piob.pudr);
202 writel(pin, &pio->piob.per);
203 writel(pin, &pio->piob.oer);
204 writel(pin, &pio->piob.codr);
205 writel((1 << 24), &pio->piob.sodr);
207 pin = 0x40000000; /* Pullup DRxD enbable */
208 writel(pin, &pio->pioc.puer);
210 pin = 0x0000000F; /* HWversion als Input */
211 writel(pin, &pio->piod.idr);
212 writel(pin, &pio->piod.puer);
213 writel(pin, &pio->piod.per);
214 writel(pin, &pio->piod.odr);
215 writel(pin, &pio->piod.owdr);
217 gd->bd->bi_arch_number = MACH_TYPE_VL_MA2SC;
218 /* adress of boot parameters */
219 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
221 writel(CONFIG_SYS_SMC0_MODE0_VAL, &smc->cs[0].setup);
222 writel(CONFIG_SYS_SMC0_CYCLE0_VAL, &smc->cs[0].cycle);
223 writel(CONFIG_SYS_SMC0_PULSE0_VAL, &smc->cs[0].pulse);
224 writel(CONFIG_SYS_SMC0_SETUP0_VAL, &smc->cs[0].setup);
226 #ifdef CONFIG_CMD_NAND
227 vl_ma2sc_nand_hw_init();
230 vl_ma2sc_macb_hw_init();
232 #ifdef CONFIG_USB_OHCI_NEW
236 vl_ma2sc_lcd_hw_init();
241 #ifdef CONFIG_MISC_INIT_R
242 int misc_init_r(void)
245 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
250 if (i2c_write(0x68, 0x0E, 1, buffer, 2) != 0)
251 puts("error reseting rtc clock\n\0");
253 /* read hardware version */
255 pin = (readl(&pio->piod.pdsr) & 0x0F) + 0x44;
256 printf("Board: revision %c\n", pin);
259 setenv("revision", (char *) buffer);
261 pin = 0x40000000; /* Pullup DRxD enbable */
262 writel(pin, &pio->pioc.puer);
269 gd->ram_size = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE,
270 CONFIG_SYS_SDRAM_SIZE);
274 #ifdef CONFIG_RESET_PHY_R
279 * Initialize ethernet HW addr prior to starting Linux,
287 int board_eth_init(bd_t *bis)
291 rc = macb_eth_initialize(0, (void *) ATMEL_BASE_EMAC, 0x01);
296 #ifdef CONFIG_SYS_I2C_SOFT
297 void i2c_init_board(void)
301 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
302 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
306 writel(1 << ATMEL_ID_PIOB, &pmc->pcer);
308 writel(pin, &pio->piob.idr); /* Disable Interupt */
309 writel(pin, &pio->piob.pudr);
310 writel(pin, &pio->piob.per);
311 writel(pin, &pio->piob.oer);
312 writel(pin, &pio->piob.sodr);
316 void watchdog_reset(void)
318 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
319 u32 pin = 0x1; /* PA0 */
321 if ((readl(&pio->pioa.odsr) & pin) > 0)
322 writel(pin, &pio->pioa.codr);
324 writel(pin, &pio->pioa.sodr);
327 void enable_caches(void)
329 #ifndef CONFIG_SYS_DCACHE_OFF
334 /*---------------------------------------------------------------------------*/
336 int do_ledtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
343 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
345 at91_set_pio_output(AT91_PIO_PORTB, 8, 0); /* LCD DIM */
348 writel(pins, &pio->pioa.idr);
349 writel(pins, &pio->pioa.pudr);
350 writel(pins, &pio->pioa.per);
351 writel(pins, &pio->pioa.oer);
352 writel(pins, &pio->pioa.sodr);
355 writel(pinz, &pio->piob.idr);
356 writel(pinz, &pio->piob.pudr);
357 writel(pinz, &pio->piob.per);
358 writel(pinz, &pio->piob.oer);
359 writel(pinz, &pio->piob.sodr);
361 for (row = 0; row < 5; row++) {
362 for (col = 0; col < 5; col++) {
363 writel((0x01000000 << col), &pio->piob.sodr);
364 writel((0x01000000 << row), &pio->pioa.codr);
365 printf("LED Test %d x %d\n", row, col);
367 writel(pinz, &pio->piob.codr);
368 writel(pins, &pio->pioa.sodr);
377 at91_set_pio_output(AT91_PIO_PORTA, 13, 1); /* CAN_TX -> H */
379 at91_set_pio_output(AT91_PIO_PORTA, 12, 0); /* CAN_STB -> L */
381 at91_set_pio_output(AT91_PIO_PORTA, 11, 0); /* CAN_EN -> L */
387 int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
394 int do_beep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
405 durate = simple_strtoul(argv[2], NULL, 10);
407 freq = simple_strtoul(argv[1], NULL, 10);
415 durate = durate * freq;
416 freq = 500000 / freq;
417 for (i = 0; i < durate; i++) {
418 at91_set_pio_output(AT91_PIO_PORTB, 29, 1); /* Sound On*/
420 at91_set_pio_output(AT91_PIO_PORTB, 29, 0); /* Sound Off*/
423 at91_set_pio_output(AT91_PIO_PORTB, 29, 0); /* Sound Off*/
427 int do_keytest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
434 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
435 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
437 writel((1 << ATMEL_ID_PIOA), &pmc->pcer);
440 writel(pins, &pio->pioa.idr);
441 writel(pins, &pio->pioa.pudr);
442 writel(pins, &pio->pioa.per);
443 writel(pins, &pio->pioa.odr);
446 writel(pinz, &pio->piob.idr);
447 writel(pinz, &pio->piob.pudr);
448 writel(pinz, &pio->piob.per);
449 writel(pinz, &pio->piob.oer);
450 writel(pinz, &pio->piob.codr);
454 for (row = 0; row < 4; row++) {
455 writel((0x00010000 << row), &pio->piob.sodr);
458 col |= ((readl(&pio->pioa.pdsr) >> 16) & 0xF) ^ 0xF ;
459 writel(pinz, &pio->piob.codr);
462 for (row = 0; row < 16; row++) {
463 printf("%1.1d", col & 1);
467 1 ^ (1 & (readl(&pio->piob.pdsr) >> 20)));
468 if ((1 & (readl(&pio->pioa.pdsr) >> 1)) == 0) {
472 if ((1 & (readl(&pio->pioa.pdsr) >> 1)) == 0)
479 if ((1 & (readl(&pio->pioa.pdsr) >> 1)) > 0) {
492 /*****************************************************************************/
495 ledtest, 1, 0, do_ledtest,
501 keytest, 1, 0, do_keytest,
502 "test keymatix and special keys, poweroff on pressing ON key",
507 poweroff, 1, 0, do_poweroff,
515 "freq frequence of beep\nduration duration of beep\n"
518 /*****************************************************************************/