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 <linux/sizes.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/clk.h>
16 #include <asm/arch/at91_matrix.h>
17 #include <asm/arch/at91sam9_smc.h>
18 #include <asm/arch/at91_pmc.h>
19 #include <asm/arch/at91_pio.h>
20 #include <asm/arch/at91sam9263.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/at91_common.h>
25 #include <atmel_lcdc.h>
26 #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
31 DECLARE_GLOBAL_DATA_PTR
;
33 #ifdef CONFIG_CMD_NAND
34 static void vl_ma2sc_nand_hw_init(void)
37 at91_smc_t
*smc
= (at91_smc_t
*) ATMEL_BASE_SMC0
;
38 at91_matrix_t
*matrix
= (at91_matrix_t
*) ATMEL_BASE_MATRIX
;
39 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
41 at91_set_pio_output(AT91_PIO_PORTA
, 13, 1); /* CAN_TX -> H */
42 at91_set_pio_output(AT91_PIO_PORTA
, 12, 1); /* CAN_STB -> H */
43 at91_set_pio_output(AT91_PIO_PORTA
, 11, 1); /* CAN_EN -> H */
46 csa
= readl(&matrix
->csa
[0]) | AT91_MATRIX_CSA_EBI_CS3A
;
47 writel(csa
, &matrix
->csa
[0]);
49 /* Configure SMC CS3 for NAND/SmartMedia */
50 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
51 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
54 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
55 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
58 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
60 writel(AT91_SMC_MODE_RM_NRD
| AT91_SMC_MODE_WM_NWE
|
62 AT91_SMC_MODE_TDF_CYCLE(2),
64 writel((1 << ATMEL_ID_PIOB
) | (1 << ATMEL_ID_PIOCDE
),
67 /* Configure RDY/BSY */
68 #ifdef CONFIG_SYS_NAND_READY_PIN
69 gpio_direction_input(CONFIG_SYS_NAND_READY_PIN
);
71 /* Enable NandFlash */
72 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN
, 1);
77 static void vl_ma2sc_macb_hw_init(void)
79 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
82 writel(1 << ATMEL_ID_EMAC
, &pmc
->pcer
);
91 vidinfo_t panel_info
= {
95 .vl_sync
= ATMEL_LCDC_INVDVAL_INVERTED
|
96 ATMEL_LCDC_INVLINE_INVERTED
|
97 ATMEL_LCDC_INVVD_INVERTED
|
98 ATMEL_LCDC_INVFRAME_INVERTED
,
99 .vl_bpix
= (ATMEL_LCDC_PIXELSIZE_8
>> 5),
101 .vl_hsync_len
= 5, /* Horiz Sync Pulse Width */
102 .vl_left_margin
= 68, /* horiz back porch */
103 .vl_right_margin
= 20, /* horiz front porch */
104 .vl_vsync_len
= 2, /* vert Sync Pulse Width */
105 .vl_upper_margin
= 18, /* vert back porch */
106 .vl_lower_margin
= 4, /* vert front porch */
107 .mmio
= ATMEL_BASE_LCDC
,
110 void lcd_enable(void)
114 void lcd_disable(void)
118 static void vl_ma2sc_lcd_hw_init(void)
120 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
122 at91_set_a_periph(AT91_PIO_PORTC
, 0, 0); /* LCDVSYNC */
123 at91_set_a_periph(AT91_PIO_PORTC
, 1, 0); /* LCDHSYNC */
124 at91_set_a_periph(AT91_PIO_PORTC
, 2, 0); /* LCDDOTCK */
125 at91_set_a_periph(AT91_PIO_PORTC
, 3, 0); /* LCDDEN */
126 at91_set_b_periph(AT91_PIO_PORTB
, 9, 0); /* LCDCC */
128 at91_set_a_periph(AT91_PIO_PORTC
, 4, 0); /* LCDD0 */
129 at91_set_a_periph(AT91_PIO_PORTC
, 5, 0); /* LCDD1 */
130 at91_set_a_periph(AT91_PIO_PORTC
, 6, 0); /* LCDD2 */
131 at91_set_a_periph(AT91_PIO_PORTC
, 7, 0); /* LCDD3 */
132 at91_set_a_periph(AT91_PIO_PORTC
, 8, 0); /* LCDD4 */
133 at91_set_a_periph(AT91_PIO_PORTC
, 9, 0); /* LCDD5 */
134 at91_set_a_periph(AT91_PIO_PORTC
, 10, 0); /* LCDD6 */
135 at91_set_a_periph(AT91_PIO_PORTC
, 11, 0); /* LCDD7 */
137 at91_set_a_periph(AT91_PIO_PORTC
, 13, 0); /* LCDD9 */
138 at91_set_a_periph(AT91_PIO_PORTC
, 14, 0); /* LCDD10 */
139 at91_set_a_periph(AT91_PIO_PORTC
, 15, 0); /* LCDD11 */
140 at91_set_a_periph(AT91_PIO_PORTC
, 16, 0); /* LCDD12 */
141 at91_set_b_periph(AT91_PIO_PORTC
, 12, 0); /* LCDD13 */
142 at91_set_a_periph(AT91_PIO_PORTC
, 18, 0); /* LCDD14 */
143 at91_set_a_periph(AT91_PIO_PORTC
, 19, 0); /* LCDD15 */
145 at91_set_a_periph(AT91_PIO_PORTC
, 20, 0); /* LCDD26 */
146 at91_set_a_periph(AT91_PIO_PORTC
, 21, 0); /* LCDD17 */
147 at91_set_a_periph(AT91_PIO_PORTC
, 22, 0); /* LCDD18 */
148 at91_set_a_periph(AT91_PIO_PORTC
, 23, 0); /* LCDD19 */
149 at91_set_a_periph(AT91_PIO_PORTC
, 24, 0); /* LCDD20 */
150 at91_set_b_periph(AT91_PIO_PORTC
, 17, 0); /* LCDD21 */
151 at91_set_a_periph(AT91_PIO_PORTC
, 26, 0); /* LCDD22 */
152 at91_set_a_periph(AT91_PIO_PORTC
, 27, 0); /* LCDD23 */
154 at91_set_pio_output(AT91_PIO_PORTE
, 0, 0); /* LCD QXH */
156 at91_set_pio_output(AT91_PIO_PORTE
, 2, 0); /* LCD SHUT */
157 at91_set_pio_output(AT91_PIO_PORTE
, 3, 1); /* LCD TopBottom */
158 at91_set_pio_output(AT91_PIO_PORTE
, 4, 0); /* LCD REV */
159 at91_set_pio_output(AT91_PIO_PORTE
, 5, 1); /* LCD RightLeft */
160 at91_set_pio_output(AT91_PIO_PORTE
, 6, 0); /* LCD Color Mode CM */
161 at91_set_pio_output(AT91_PIO_PORTE
, 7, 0); /* LCD BGR */
163 at91_set_pio_output(AT91_PIO_PORTB
, 9, 0); /* LCD CC */
165 writel(1 << ATMEL_ID_LCDC
, &pmc
->pcer
);
166 gd
->fb_base
= ATMEL_BASE_SRAM0
;
168 #endif /* Config LCD */
170 #ifdef CONFIG_BOARD_EARLY_INIT_F
171 int board_early_init_f(void)
173 struct at91_pmc
*pmc
= (struct at91_pmc
*)ATMEL_BASE_PMC
;
175 /* Enable clocks for all PIOs */
176 writel((1 << ATMEL_ID_PIOA
) | (1 << ATMEL_ID_PIOB
) |
177 (1 << ATMEL_ID_PIOCDE
),
180 at91_seriald_hw_init();
188 at91_smc_t
*smc
= (at91_smc_t
*) ATMEL_BASE_SMC0
;
189 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
193 writel(pin
, &pio
->pioa
.idr
);
194 writel(pin
, &pio
->pioa
.pudr
);
195 writel(pin
, &pio
->pioa
.per
);
196 writel(pin
, &pio
->pioa
.oer
);
197 writel(pin
, &pio
->pioa
.sodr
);
198 writel((1 << 25), &pio
->pioa
.codr
);
201 writel(pin
, &pio
->piob
.idr
);
202 writel(pin
, &pio
->piob
.pudr
);
203 writel(pin
, &pio
->piob
.per
);
204 writel(pin
, &pio
->piob
.oer
);
205 writel(pin
, &pio
->piob
.codr
);
206 writel((1 << 24), &pio
->piob
.sodr
);
208 pin
= 0x40000000; /* Pullup DRxD enbable */
209 writel(pin
, &pio
->pioc
.puer
);
211 pin
= 0x0000000F; /* HWversion als Input */
212 writel(pin
, &pio
->piod
.idr
);
213 writel(pin
, &pio
->piod
.puer
);
214 writel(pin
, &pio
->piod
.per
);
215 writel(pin
, &pio
->piod
.odr
);
216 writel(pin
, &pio
->piod
.owdr
);
218 gd
->bd
->bi_arch_number
= MACH_TYPE_VL_MA2SC
;
219 /* adress of boot parameters */
220 gd
->bd
->bi_boot_params
= CONFIG_SYS_SDRAM_BASE
+ 0x100;
222 writel(CONFIG_SYS_SMC0_MODE0_VAL
, &smc
->cs
[0].setup
);
223 writel(CONFIG_SYS_SMC0_CYCLE0_VAL
, &smc
->cs
[0].cycle
);
224 writel(CONFIG_SYS_SMC0_PULSE0_VAL
, &smc
->cs
[0].pulse
);
225 writel(CONFIG_SYS_SMC0_SETUP0_VAL
, &smc
->cs
[0].setup
);
227 #ifdef CONFIG_CMD_NAND
228 vl_ma2sc_nand_hw_init();
231 vl_ma2sc_macb_hw_init();
233 #ifdef CONFIG_USB_OHCI_NEW
237 vl_ma2sc_lcd_hw_init();
242 #ifdef CONFIG_MISC_INIT_R
243 int misc_init_r(void)
246 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
251 if (i2c_write(0x68, 0x0E, 1, buffer
, 2) != 0)
252 puts("error reseting rtc clock\n\0");
254 /* read hardware version */
256 pin
= (readl(&pio
->piod
.pdsr
) & 0x0F) + 0x44;
257 printf("Board: revision %c\n", pin
);
260 setenv("revision", (char *) buffer
);
262 pin
= 0x40000000; /* Pullup DRxD enbable */
263 writel(pin
, &pio
->pioc
.puer
);
270 gd
->ram_size
= get_ram_size((long *) CONFIG_SYS_SDRAM_BASE
,
271 CONFIG_SYS_SDRAM_SIZE
);
275 #ifdef CONFIG_RESET_PHY_R
280 * Initialize ethernet HW addr prior to starting Linux,
288 int board_eth_init(bd_t
*bis
)
292 rc
= macb_eth_initialize(0, (void *) ATMEL_BASE_EMAC
, 0x01);
297 #ifdef CONFIG_SYS_I2C_SOFT
298 void i2c_init_board(void)
302 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
303 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
307 writel(1 << ATMEL_ID_PIOB
, &pmc
->pcer
);
309 writel(pin
, &pio
->piob
.idr
); /* Disable Interupt */
310 writel(pin
, &pio
->piob
.pudr
);
311 writel(pin
, &pio
->piob
.per
);
312 writel(pin
, &pio
->piob
.oer
);
313 writel(pin
, &pio
->piob
.sodr
);
317 void watchdog_reset(void)
319 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
320 u32 pin
= 0x1; /* PA0 */
322 if ((readl(&pio
->pioa
.odsr
) & pin
) > 0)
323 writel(pin
, &pio
->pioa
.codr
);
325 writel(pin
, &pio
->pioa
.sodr
);
328 void enable_caches(void)
330 #ifndef CONFIG_SYS_DCACHE_OFF
335 /*---------------------------------------------------------------------------*/
337 int do_ledtest(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
344 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
346 at91_set_pio_output(AT91_PIO_PORTB
, 8, 0); /* LCD DIM */
349 writel(pins
, &pio
->pioa
.idr
);
350 writel(pins
, &pio
->pioa
.pudr
);
351 writel(pins
, &pio
->pioa
.per
);
352 writel(pins
, &pio
->pioa
.oer
);
353 writel(pins
, &pio
->pioa
.sodr
);
356 writel(pinz
, &pio
->piob
.idr
);
357 writel(pinz
, &pio
->piob
.pudr
);
358 writel(pinz
, &pio
->piob
.per
);
359 writel(pinz
, &pio
->piob
.oer
);
360 writel(pinz
, &pio
->piob
.sodr
);
362 for (row
= 0; row
< 5; row
++) {
363 for (col
= 0; col
< 5; col
++) {
364 writel((0x01000000 << col
), &pio
->piob
.sodr
);
365 writel((0x01000000 << row
), &pio
->pioa
.codr
);
366 printf("LED Test %d x %d\n", row
, col
);
368 writel(pinz
, &pio
->piob
.codr
);
369 writel(pins
, &pio
->pioa
.sodr
);
378 at91_set_pio_output(AT91_PIO_PORTA
, 13, 1); /* CAN_TX -> H */
380 at91_set_pio_output(AT91_PIO_PORTA
, 12, 0); /* CAN_STB -> L */
382 at91_set_pio_output(AT91_PIO_PORTA
, 11, 0); /* CAN_EN -> L */
388 int do_poweroff(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
395 int do_beep(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
406 durate
= simple_strtoul(argv
[2], NULL
, 10);
408 freq
= simple_strtoul(argv
[1], NULL
, 10);
416 durate
= durate
* freq
;
417 freq
= 500000 / freq
;
418 for (i
= 0; i
< durate
; i
++) {
419 at91_set_pio_output(AT91_PIO_PORTB
, 29, 1); /* Sound On*/
421 at91_set_pio_output(AT91_PIO_PORTB
, 29, 0); /* Sound Off*/
424 at91_set_pio_output(AT91_PIO_PORTB
, 29, 0); /* Sound Off*/
428 int do_keytest(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
435 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
436 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
438 writel((1 << ATMEL_ID_PIOA
), &pmc
->pcer
);
441 writel(pins
, &pio
->pioa
.idr
);
442 writel(pins
, &pio
->pioa
.pudr
);
443 writel(pins
, &pio
->pioa
.per
);
444 writel(pins
, &pio
->pioa
.odr
);
447 writel(pinz
, &pio
->piob
.idr
);
448 writel(pinz
, &pio
->piob
.pudr
);
449 writel(pinz
, &pio
->piob
.per
);
450 writel(pinz
, &pio
->piob
.oer
);
451 writel(pinz
, &pio
->piob
.codr
);
455 for (row
= 0; row
< 4; row
++) {
456 writel((0x00010000 << row
), &pio
->piob
.sodr
);
459 col
|= ((readl(&pio
->pioa
.pdsr
) >> 16) & 0xF) ^ 0xF ;
460 writel(pinz
, &pio
->piob
.codr
);
463 for (row
= 0; row
< 16; row
++) {
464 printf("%1.1d", col
& 1);
468 1 ^ (1 & (readl(&pio
->piob
.pdsr
) >> 20)));
469 if ((1 & (readl(&pio
->pioa
.pdsr
) >> 1)) == 0) {
473 if ((1 & (readl(&pio
->pioa
.pdsr
) >> 1)) == 0)
480 if ((1 & (readl(&pio
->pioa
.pdsr
) >> 1)) > 0) {
493 /*****************************************************************************/
496 ledtest
, 1, 0, do_ledtest
,
502 keytest
, 1, 0, do_keytest
,
503 "test keymatix and special keys, poweroff on pressing ON key",
508 poweroff
, 1, 0, do_poweroff
,
516 "freq frequence of beep\nduration duration of beep\n"
519 /*****************************************************************************/