]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/bf518f-ezbrd/bf518f-ezbrd.c
2 * U-boot - main board file
4 * Copyright (c) 2008-2009 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
15 #include <asm/blackfin.h>
17 #include <asm/portmux.h>
18 #include <asm/mach-common/bits/otp.h>
21 DECLARE_GLOBAL_DATA_PTR
;
25 printf("Board: ADI BF518F EZ-Board board\n");
26 printf(" Support: http://blackfin.uclinux.org/\n");
30 #if defined(CONFIG_BFIN_MAC)
31 static void board_init_enetaddr(uchar
*mac_addr
)
33 bool valid_mac
= false;
36 /* the MAC is stored in OTP memory page 0xDF */
40 ret
= bfrom_OtpRead(0xDF, OTP_LOWER_HALF
, &otp_mac
);
41 if (!(ret
& OTP_MASTER_ERROR
)) {
42 uchar
*otp_mac_p
= (uchar
*)&otp_mac
;
44 for (ret
= 0; ret
< 6; ++ret
)
45 mac_addr
[ret
] = otp_mac_p
[5 - ret
];
47 if (is_valid_ether_addr(mac_addr
))
53 puts("Warning: Generating 'random' MAC address\n");
54 bfin_gen_rand_mac(mac_addr
);
57 eth_setenv_enetaddr("ethaddr", mac_addr
);
60 /* Only the first run of boards had a KSZ switch */
61 #if defined(CONFIG_BFIN_SPI) && __SILICON_REVISION__ == 0
62 # define KSZ_POSSIBLE 1
64 # define KSZ_POSSIBLE 0
67 #define KSZ_MAX_HZ 5000000
69 #define KSZ_WRITE 0x02
72 #define KSZ_REG_CHID 0x00 /* Register 0: Chip ID0 */
73 #define KSZ_REG_STPID 0x01 /* Register 1: Chip ID1 / Start Switch */
74 #define KSZ_REG_GC9 0x0b /* Register 11: Global Control 9 */
75 #define KSZ_REG_P3C0 0x30 /* Register 48: Port 3 Control 0 */
77 static int ksz8893m_transfer(struct spi_slave
*slave
, uchar dir
, uchar reg
,
78 uchar data
, uchar result
[3])
80 unsigned char dout
[3] = { dir
, reg
, data
, };
81 return spi_xfer(slave
, sizeof(dout
) * 8, dout
, result
, SPI_XFER_BEGIN
| SPI_XFER_END
);
84 static int ksz8893m_reg_set(struct spi_slave
*slave
, uchar reg
, uchar data
)
87 return ksz8893m_transfer(slave
, KSZ_WRITE
, reg
, data
, din
);
90 static int ksz8893m_reg_read(struct spi_slave
*slave
, uchar reg
)
94 ret
= ksz8893m_transfer(slave
, KSZ_READ
, reg
, 0, din
);
95 return ret
? ret
: din
[2];
98 static int ksz8893m_reg_clear(struct spi_slave
*slave
, uchar reg
, uchar mask
)
100 return ksz8893m_reg_set(slave
, reg
, ksz8893m_reg_read(slave
, reg
) & mask
);
103 static int ksz8893m_reset(struct spi_slave
*slave
)
107 /* Disable STPID mode */
108 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_GC9
, 0x01);
110 /* Disable VLAN tag insert on Port3 */
111 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_P3C0
, 0x04);
114 ret
|= ksz8893m_reg_set(slave
, KSZ_REG_STPID
, 0x01);
119 static bool board_ksz_init(void)
121 static bool switch_is_alive
= false;
123 if (!switch_is_alive
) {
124 struct spi_slave
*slave
= spi_setup_slave(0, 1, KSZ_MAX_HZ
, SPI_MODE_3
);
126 if (!spi_claim_bus(slave
)) {
127 bool phy_is_ksz
= (ksz8893m_reg_read(slave
, KSZ_REG_CHID
) == 0x88);
128 int ret
= phy_is_ksz
? ksz8893m_reset(slave
) : 0;
129 switch_is_alive
= (ret
== 0);
130 spi_release_bus(slave
);
132 spi_free_slave(slave
);
136 return switch_is_alive
;
139 int board_eth_init(bd_t
*bis
)
142 if (!board_ksz_init())
145 return bfin_EMAC_initialize(bis
);
149 int misc_init_r(void)
151 #ifdef CONFIG_BFIN_MAC
153 if (!eth_getenv_enetaddr("ethaddr", enetaddr
))
154 board_init_enetaddr(enetaddr
);
160 int board_early_init_f(void)
162 /* connect async banks by default */
163 const unsigned short pins
[] = {
166 return peripheral_request_list(pins
, "async");
169 #ifdef CONFIG_BFIN_SDH
170 int board_mmc_init(bd_t
*bis
)
172 return bfin_mmc_init(bis
);