1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55#include <common.h>
56#include <init.h>
57#include <net.h>
58#include <netdev.h>
59#include <miiphy.h>
60#include <i2c.h>
61#include <mmc.h>
62#include <atmel_mci.h>
63#include <asm/global_data.h>
64
65#include <asm/arch/at91sam9260.h>
66#include <asm/arch/at91sam9260_matrix.h>
67#include <asm/arch/at91sam9_smc.h>
68#include <asm/arch/at91_common.h>
69#include <asm/arch/clk.h>
70#include <asm/arch/gpio.h>
71#include <asm/io.h>
72#include <asm/gpio.h>
73
74#include "ethernut5_pwrman.h"
75
76DECLARE_GLOBAL_DATA_PTR;
77
78
79
80
81
82
83
84
85int dram_init(void)
86{
87 gd->ram_size = get_ram_size(
88 (void *)CONFIG_SYS_SDRAM_BASE,
89 CONFIG_SYS_SDRAM_SIZE);
90 return 0;
91}
92
93#ifdef CONFIG_CMD_NAND
94static void ethernut5_nand_hw_init(void)
95{
96 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
97 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
98 unsigned long csa;
99
100
101 csa = readl(&matrix->ebicsa);
102 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
103 writel(csa, &matrix->ebicsa);
104
105
106 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
107 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
108 &smc->cs[3].setup);
109 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
110 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
111 &smc->cs[3].pulse);
112 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
113 &smc->cs[3].cycle);
114 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
115 AT91_SMC_MODE_EXNW_DISABLE |
116 AT91_SMC_MODE_DBW_8 |
117 AT91_SMC_MODE_TDF_CYCLE(2),
118 &smc->cs[3].mode);
119
120#ifdef CONFIG_SYS_NAND_READY_PIN
121
122 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
123#endif
124 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
125}
126#endif
127
128
129
130
131int board_init(void)
132{
133 at91_periph_clk_enable(ATMEL_ID_PIOA);
134 at91_periph_clk_enable(ATMEL_ID_PIOB);
135 at91_periph_clk_enable(ATMEL_ID_PIOC);
136
137
138 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
139
140 ethernut5_power_init();
141#ifdef CONFIG_CMD_NAND
142 ethernut5_nand_hw_init();
143#endif
144 return 0;
145}
146
147#ifdef CONFIG_MACB
148
149
150
151int board_eth_init(struct bd_info *bis)
152{
153 const char *devname;
154 unsigned short mode;
155
156 at91_periph_clk_enable(ATMEL_ID_EMAC0);
157
158
159 ethernut5_phy_reset();
160
161 at91_macb_hw_init();
162
163 if (macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, CONFIG_PHY_ID))
164 return -1;
165
166
167
168
169
170 devname = miiphy_get_current_dev();
171 if (miiphy_read(devname, 0, 18, &mode) == 0) {
172
173 mode |= 0x00E0;
174 miiphy_write(devname, 0, 18, mode);
175
176 miiphy_write(devname, 0, MII_BMCR, BMCR_RESET);
177 }
178
179 return eth_init();
180}
181#endif
182
183#ifdef CONFIG_GENERIC_ATMEL_MCI
184int board_mmc_init(struct bd_info *bd)
185{
186 at91_periph_clk_enable(ATMEL_ID_MCI);
187
188
189 at91_mci_hw_init();
190
191 return atmel_mci_init((void *)ATMEL_BASE_MCI);
192}
193
194int board_mmc_getcd(struct mmc *mmc)
195{
196 return !at91_get_pio_value(CONFIG_SYS_MMC_CD_PIN);
197}
198#endif
199