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