blob: f53d359404ef2763d1d51a1a7da8e987a3399268 [file] [log] [blame]
Durai Manickam KR2e7bc612022-04-04 11:23:18 +05301// 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>
Alexander Dahl23f626d2023-08-23 15:58:55 +020012#include <led.h>
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053013#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>
Alexander Dahl23f626d2023-08-23 15:58:55 +020022#include <dm/ofnode.h>
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053023
Durai Manickam KR98676a92022-07-07 16:40:55 +053024extern void at91_pda_detect(void);
25
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053026DECLARE_GLOBAL_DATA_PTR;
27
28void at91_prepare_cpu_var(void);
29
Mihai Sain647089c2022-12-23 08:39:36 +020030static void board_leds_init(void)
31{
Alexander Dahl23f626d2023-08-23 15:58:55 +020032#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
Mihai Sain647089c2022-12-23 08:39:36 +020047 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 */
Alexander Dahl23f626d2023-08-23 15:58:55 +020050#endif
Mihai Sain647089c2022-12-23 08:39:36 +020051}
52
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053053int board_late_init(void)
54{
55 at91_prepare_cpu_var();
56
Durai Manickam KR98676a92022-07-07 16:40:55 +053057 at91_pda_detect();
58
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053059 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{
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053071 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;
Mihai Sain647089c2022-12-23 08:39:36 +020090
91 board_leds_init();
92
Durai Manickam KR2e7bc612022-04-04 11:23:18 +053093 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}