1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2023 Microchip Technology Inc. and its subsidiaries
4 *
5 * Author: Mihai Sain <mihai.sain@microchip.com>
6 *
7 */
8
9#include <common.h>
10#include <debug_uart.h>
11#include <init.h>
12#include <asm/global_data.h>
13#include <asm/io.h>
14#include <asm/arch/at91_common.h>
15#include <asm/arch/atmel_pio4.h>
16#include <asm/arch/atmel_sdhci.h>
17#include <asm/arch/clk.h>
18#include <asm/arch/gpio.h>
19#include <asm/arch/sama5d2.h>
20
21extern void at91_pda_detect(void);
22
23DECLARE_GLOBAL_DATA_PTR;
24
25static void rgb_leds_init(void)
26{
27	atmel_pio4_set_pio_output(AT91_PIO_PORTA, 7, 0);	/* LED RED */
28	atmel_pio4_set_pio_output(AT91_PIO_PORTA, 8, 0);	/* LED GREEN */
29	atmel_pio4_set_pio_output(AT91_PIO_PORTA, 9, 1);	/* LED BLUE */
30}
31
32static void board_usb_hw_init(void)
33{
34	atmel_pio4_set_pio_output(AT91_PIO_PORTA, 6, 1);
35}
36
37int board_late_init(void)
38{
39	at91_video_show_board_info();
40
41	at91_pda_detect();
42
43	return 0;
44}
45
46static void board_uart0_hw_init(void)
47{
48	atmel_pio4_set_c_periph(AT91_PIO_PORTB, 26, ATMEL_PIO_PUEN_MASK);	/* URXD0 */
49	atmel_pio4_set_c_periph(AT91_PIO_PORTB, 27, 0);				/* UTXD0 */
50
51	at91_periph_clk_enable(ATMEL_ID_UART0);
52}
53
54void board_debug_uart_init(void)
55{
56	board_uart0_hw_init();
57}
58
59int board_early_init_f(void)
60{
61	debug_uart_init();
62
63	return 0;
64}
65
66int board_init(void)
67{
68	/* address of boot parameters */
69	gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
70
71	rgb_leds_init();
72
73	board_usb_hw_init();
74
75	return 0;
76}
77
78int dram_init_banksize(void)
79{
80	return fdtdec_setup_memory_banksize();
81}
82
83int dram_init(void)
84{
85	return fdtdec_setup_mem_size_base();
86}
87