]>
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>
16 #include <asm/portmux.h>
17 #include <asm/mach-common/bits/otp.h>
20 DECLARE_GLOBAL_DATA_PTR
;
24 printf("Board: ADI BF518F EZ-Board board\n");
25 printf(" Support: http://blackfin.uclinux.org/\n");
29 #if defined(CONFIG_BFIN_MAC)
30 static void board_init_enetaddr(uchar
*mac_addr
)
32 #ifdef CONFIG_MTD_NOR_FLASH
33 /* we cram the MAC in the last flash sector */
34 uchar
*board_mac_addr
= (uchar
*)0x203F0096;
35 if (is_valid_ethaddr(board_mac_addr
)) {
36 memcpy(mac_addr
, board_mac_addr
, 6);
37 eth_setenv_enetaddr("ethaddr", mac_addr
);
42 /* Only the first run of boards had a KSZ switch */
43 #if defined(CONFIG_BFIN_SPI) && __SILICON_REVISION__ == 0
44 # define KSZ_POSSIBLE 1
46 # define KSZ_POSSIBLE 0
49 #define KSZ_MAX_HZ 5000000
51 #define KSZ_WRITE 0x02
54 #define KSZ_REG_CHID 0x00 /* Register 0: Chip ID0 */
55 #define KSZ_REG_STPID 0x01 /* Register 1: Chip ID1 / Start Switch */
56 #define KSZ_REG_GC9 0x0b /* Register 11: Global Control 9 */
57 #define KSZ_REG_P3C0 0x30 /* Register 48: Port 3 Control 0 */
59 static int ksz8893m_transfer(struct spi_slave
*slave
, uchar dir
, uchar reg
,
60 uchar data
, uchar result
[3])
62 unsigned char dout
[3] = { dir
, reg
, data
, };
63 return spi_xfer(slave
, sizeof(dout
) * 8, dout
, result
, SPI_XFER_BEGIN
| SPI_XFER_END
);
66 static int ksz8893m_reg_set(struct spi_slave
*slave
, uchar reg
, uchar data
)
69 return ksz8893m_transfer(slave
, KSZ_WRITE
, reg
, data
, din
);
72 static int ksz8893m_reg_read(struct spi_slave
*slave
, uchar reg
)
76 ret
= ksz8893m_transfer(slave
, KSZ_READ
, reg
, 0, din
);
77 return ret
? ret
: din
[2];
80 static int ksz8893m_reg_clear(struct spi_slave
*slave
, uchar reg
, uchar mask
)
82 return ksz8893m_reg_set(slave
, reg
, ksz8893m_reg_read(slave
, reg
) & mask
);
85 static int ksz8893m_reset(struct spi_slave
*slave
)
89 /* Disable STPID mode */
90 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_GC9
, 0x01);
92 /* Disable VLAN tag insert on Port3 */
93 ret
|= ksz8893m_reg_clear(slave
, KSZ_REG_P3C0
, 0x04);
96 ret
|= ksz8893m_reg_set(slave
, KSZ_REG_STPID
, 0x01);
101 static bool board_ksz_init(void)
103 static bool switch_is_alive
= false;
105 if (!switch_is_alive
) {
106 struct spi_slave
*slave
= spi_setup_slave(0, 1, KSZ_MAX_HZ
, SPI_MODE_3
);
108 if (!spi_claim_bus(slave
)) {
109 bool phy_is_ksz
= (ksz8893m_reg_read(slave
, KSZ_REG_CHID
) == 0x88);
110 int ret
= phy_is_ksz
? ksz8893m_reset(slave
) : 0;
111 switch_is_alive
= (ret
== 0);
112 spi_release_bus(slave
);
114 spi_free_slave(slave
);
118 return switch_is_alive
;
121 int board_eth_init(bd_t
*bis
)
124 if (!board_ksz_init())
127 return bfin_EMAC_initialize(bis
);
131 int misc_init_r(void)
133 #ifdef CONFIG_BFIN_MAC
135 if (!eth_getenv_enetaddr("ethaddr", enetaddr
))
136 board_init_enetaddr(enetaddr
);
139 #ifdef CONFIG_MTD_NOR_FLASH
140 /* we use the last sector for the MAC address / POST LDR */
141 extern flash_info_t flash_info
[];
142 flash_protect(FLAG_PROTECT_SET
, 0x203F0000, 0x203FFFFF, &flash_info
[0]);
148 int board_early_init_f(void)
150 /* connect async banks by default */
151 const unsigned short pins
[] = {
154 return peripheral_request_list(pins
, "async");
157 #ifdef CONFIG_BFIN_SDH
158 int board_mmc_init(bd_t
*bis
)
160 return bfin_mmc_init(bis
);