1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries
4 *
5 * Author: Durai Manickam KR <durai.manickamkr@microchip.com>
6 */
7
8#include <common.h>
9#include <debug_uart.h>
10#include <fdtdec.h>
11#include <init.h>
12#include <led.h>
13#include <asm/arch/at91_common.h>
14#include <asm/arch/at91_rstc.h>
15#include <asm/arch/at91_sfr.h>
16#include <asm/arch/at91sam9_smc.h>
17#include <asm/arch/clk.h>
18#include <asm/arch/gpio.h>
19#include <asm/global_data.h>
20#include <asm/io.h>
21#include <asm/mach-types.h>
22#include <dm/ofnode.h>
23
24extern void at91_pda_detect(void);
25
26DECLARE_GLOBAL_DATA_PTR;
27
28void at91_prepare_cpu_var(void);
29
30static void board_leds_init(void)
31{
32#if CONFIG_IS_ENABLED(LED)
33	const char *led_name;
34	struct udevice *dev;
35	int ret;
36
37	led_name = ofnode_conf_read_str("u-boot,boot-led");
38	if (!led_name)
39		return;
40
41	ret = led_get_by_label(led_name, &dev);
42	if (ret)
43		return;
44
45	led_set_state(dev, LEDST_ON);
46#else
47	at91_set_pio_output(AT91_PIO_PORTD, 17, 0);	/* LED RED */
48	at91_set_pio_output(AT91_PIO_PORTD, 19, 0);	/* LED GREEN */
49	at91_set_pio_output(AT91_PIO_PORTD, 21, 1);	/* LED BLUE */
50#endif
51}
52
53int board_late_init(void)
54{
55	at91_prepare_cpu_var();
56
57	at91_pda_detect();
58
59	return 0;
60}
61
62#ifdef CONFIG_DEBUG_UART_BOARD_INIT
63void board_debug_uart_init(void)
64{
65	at91_seriald_hw_init();
66}
67#endif
68
69int board_early_init_f(void)
70{
71	return 0;
72}
73
74#define MAC24AA_MAC_OFFSET     0xfa
75
76#ifdef CONFIG_MISC_INIT_R
77int misc_init_r(void)
78{
79#ifdef CONFIG_I2C_EEPROM
80	at91_set_ethaddr(MAC24AA_MAC_OFFSET);
81#endif
82	return 0;
83}
84#endif
85
86int board_init(void)
87{
88	/* address of boot parameters */
89	gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
90
91	board_leds_init();
92
93	return 0;
94}
95
96int dram_init_banksize(void)
97{
98	return fdtdec_setup_memory_banksize();
99}
100
101int dram_init(void)
102{
103	return fdtdec_setup_mem_size_base();
104}
105