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 #ifdef CONFIG_SYS_NO_FLASH
34 # define USE_MAC_IN_FLASH 0
36 # define USE_MAC_IN_FLASH 1
38 bool valid_mac
= false;
40 if (USE_MAC_IN_FLASH
) {
41 /* we cram the MAC in the last flash sector */
42 uchar
*board_mac_addr
= (uchar
*)0x203F0096;
43 if (is_valid_ether_addr(board_mac_addr
)) {
44 memcpy(mac_addr
, board_mac_addr
, 6);
50 puts("Warning: Generating 'random' MAC address\n");
51 bfin_gen_rand_mac(mac_addr
);
54 eth_setenv_enetaddr("ethaddr", mac_addr
);
57 /* Only the first run of boards had a KSZ switch */
58 #if defined(CONFIG_BFIN_SPI) && __SILICON_REVISION__ == 0
59 # define KSZ_POSSIBLE 1
61 # define KSZ_POSSIBLE 0
64 #define KSZ_MAX_HZ 5000000
66 #define KSZ_WRITE 0x02
69 #define KSZ_REG_CHID 0x00 /* Register 0: Chip ID0 */
70 #define KSZ_REG_STPID 0x01 /* Register 1: Chip ID1 / Start Switch */
71 #define KSZ_REG_GC9 0x0b /* Register 11: Global Control 9 */
72 #define KSZ_REG_P3C0 0x30 /* Register 48: Port 3 Control 0 */
74 static int ksz8893m_transfer(struct spi_slave
*slave
, uchar dir
, uchar reg
,
75 uchar data
, uchar result
[3])
77 unsigned char dout
[3] = { dir
, reg
, data
, };
78 return spi_xfer(slave
, sizeof(dout
) * 8, dout
, result
, SPI_XFER_BEGIN
| SPI_XFER_END
);
81 static int ksz8893m_reg_set(struct spi_slave
*slave
, uchar reg
, uchar data
)
84 return ksz8893m_transfer(slave
, KSZ_WRITE
, reg
, data
, din
);
87 static int ksz8893m_reg_read(struct spi_slave
*slave
, uchar reg
)
91 ret
= ksz8893m_transfer(slave
, KSZ_READ
, reg
, 0, din
);
92 return ret
? ret
: din
[2];
95 static int ksz8893m_reg_clear(struct spi_slave
*slave
, uchar reg
, uchar mask
)
97 return ksz8893m_reg_set(slave
, reg
, ksz8893m_reg_read(slave
, reg
) & mask
);
100 static int ksz8893m_reset(struct spi_slave
*slave
)
104 /* Disable STPID mode */
105 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_GC9
, 0x01);
107 /* Disable VLAN tag insert on Port3 */
108 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_P3C0
, 0x04);
111 ret
|= ksz8893m_reg_set(slave
, KSZ_REG_STPID
, 0x01);
116 static bool board_ksz_init(void)
118 static bool switch_is_alive
= false;
120 if (!switch_is_alive
) {
121 struct spi_slave
*slave
= spi_setup_slave(0, 1, KSZ_MAX_HZ
, SPI_MODE_3
);
123 if (!spi_claim_bus(slave
)) {
124 bool phy_is_ksz
= (ksz8893m_reg_read(slave
, KSZ_REG_CHID
) == 0x88);
125 int ret
= phy_is_ksz
? ksz8893m_reset(slave
) : 0;
126 switch_is_alive
= (ret
== 0);
127 spi_release_bus(slave
);
129 spi_free_slave(slave
);
133 return switch_is_alive
;
136 int board_eth_init(bd_t
*bis
)
139 if (!board_ksz_init())
142 return bfin_EMAC_initialize(bis
);
146 int misc_init_r(void)
148 #ifdef CONFIG_BFIN_MAC
150 if (!eth_getenv_enetaddr("ethaddr", enetaddr
))
151 board_init_enetaddr(enetaddr
);
154 #ifndef CONFIG_SYS_NO_FLASH
155 /* we use the last sector for the MAC address / POST LDR */
156 extern flash_info_t flash_info
[];
157 flash_protect(FLAG_PROTECT_SET
, 0x203F0000, 0x203FFFFF, &flash_info
[0]);
163 int board_early_init_f(void)
165 /* connect async banks by default */
166 const unsigned short pins
[] = {
169 return peripheral_request_list(pins
, "async");
172 #ifdef CONFIG_BFIN_SDH
173 int board_mmc_init(bd_t
*bis
)
175 return bfin_mmc_init(bis
);