blob: 2c7961ab7c290e11392649d21ca405485d34e218 [file] [log] [blame]
Mike Frysinger4752c192008-10-12 21:32:52 -04001/*
2 * U-boot - main board file
3 *
4 * Copyright (c) 2008-2009 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <common.h>
10#include <config.h>
11#include <command.h>
12#include <net.h>
13#include <netdev.h>
14#include <spi.h>
15#include <asm/blackfin.h>
16#include <asm/net.h>
17#include <asm/mach-common/bits/otp.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21int checkboard(void)
22{
23 printf("Board: ADI BF518F EZ-Board board\n");
24 printf(" Support: http://blackfin.uclinux.org/\n");
25 return 0;
26}
27
28phys_size_t initdram(int board_type)
29{
30 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
31 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
32 return gd->bd->bi_memsize;
33}
34
35#if defined(CONFIG_BFIN_MAC)
36static void board_init_enetaddr(uchar *mac_addr)
37{
38 bool valid_mac = false;
39
40#if 0
41 /* the MAC is stored in OTP memory page 0xDF */
42 uint32_t ret;
43 uint64_t otp_mac;
44
45 ret = bfrom_OtpRead(0xDF, OTP_LOWER_HALF, &otp_mac);
46 if (!(ret & OTP_MASTER_ERROR)) {
47 uchar *otp_mac_p = (uchar *)&otp_mac;
48
49 for (ret = 0; ret < 6; ++ret)
50 mac_addr[ret] = otp_mac_p[5 - ret];
51
52 if (is_valid_ether_addr(mac_addr))
53 valid_mac = true;
54 }
55#endif
56
57 if (!valid_mac) {
58 puts("Warning: Generating 'random' MAC address\n");
59 bfin_gen_rand_mac(mac_addr);
60 }
61
62 eth_setenv_enetaddr("ethaddr", mac_addr);
63}
64
65int board_eth_init(bd_t *bis)
66{
67 static bool switch_is_alive = false;
68 int ret;
69
70 if (!switch_is_alive) {
71 struct spi_slave *slave = spi_setup_slave(0, 1, 5000000, SPI_MODE_3);
72 if (slave) {
73 if (!spi_claim_bus(slave)) {
74 unsigned char dout[3] = { 2, 1, 1, };
75 unsigned char din[3];
76 ret = spi_xfer(slave, sizeof(dout) * 8, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
77 if (!ret)
78 switch_is_alive = true;
79 spi_release_bus(slave);
80 }
81 spi_free_slave(slave);
82 }
83 }
84
85 if (switch_is_alive)
86 return bfin_EMAC_initialize(bis);
87 else
88 return -1;
89}
90#endif
91
92int misc_init_r(void)
93{
94#ifdef CONFIG_BFIN_MAC
95 uchar enetaddr[6];
96 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
97 board_init_enetaddr(enetaddr);
98#endif
99
100 return 0;
101}