Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 1 | /* |
| 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> |
Cliff Cai | e463892 | 2009-11-20 08:24:43 +0000 | [diff] [blame] | 18 | #include <asm/sdh.h> |
Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | int checkboard(void) |
| 23 | { |
| 24 | printf("Board: ADI BF518F EZ-Board board\n"); |
| 25 | printf(" Support: http://blackfin.uclinux.org/\n"); |
| 26 | return 0; |
| 27 | } |
| 28 | |
Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 29 | #if defined(CONFIG_BFIN_MAC) |
| 30 | static void board_init_enetaddr(uchar *mac_addr) |
| 31 | { |
| 32 | bool valid_mac = false; |
| 33 | |
| 34 | #if 0 |
| 35 | /* the MAC is stored in OTP memory page 0xDF */ |
| 36 | uint32_t ret; |
| 37 | uint64_t otp_mac; |
| 38 | |
| 39 | ret = bfrom_OtpRead(0xDF, OTP_LOWER_HALF, &otp_mac); |
| 40 | if (!(ret & OTP_MASTER_ERROR)) { |
| 41 | uchar *otp_mac_p = (uchar *)&otp_mac; |
| 42 | |
| 43 | for (ret = 0; ret < 6; ++ret) |
| 44 | mac_addr[ret] = otp_mac_p[5 - ret]; |
| 45 | |
| 46 | if (is_valid_ether_addr(mac_addr)) |
| 47 | valid_mac = true; |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | if (!valid_mac) { |
| 52 | puts("Warning: Generating 'random' MAC address\n"); |
| 53 | bfin_gen_rand_mac(mac_addr); |
| 54 | } |
| 55 | |
| 56 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 57 | } |
| 58 | |
Graf Yang | a211d4b | 2009-05-05 02:26:27 -0400 | [diff] [blame] | 59 | #define KSZ_MAX_HZ 5000000 |
| 60 | |
| 61 | #define KSZ_WRITE 0x02 |
| 62 | #define KSZ_READ 0x03 |
| 63 | |
| 64 | #define KSZ_REG_STPID 0x01 /* Register 1: Chip ID1 / Start Switch */ |
| 65 | #define KSZ_REG_GC9 0x0b /* Register 11: Global Control 9 */ |
| 66 | #define KSZ_REG_P3C0 0x30 /* Register 48: Port 3 Control 0 */ |
| 67 | |
| 68 | static int ksz8893m_transfer(struct spi_slave *slave, uchar dir, uchar reg, |
Wolfgang Denk | cc474d8 | 2009-05-15 22:32:57 +0200 | [diff] [blame] | 69 | uchar data, uchar result[3]) |
Graf Yang | a211d4b | 2009-05-05 02:26:27 -0400 | [diff] [blame] | 70 | { |
| 71 | unsigned char dout[3] = { dir, reg, data, }; |
| 72 | return spi_xfer(slave, sizeof(dout) * 8, dout, result, SPI_XFER_BEGIN | SPI_XFER_END); |
| 73 | } |
| 74 | |
| 75 | static int ksz8893m_reg_set(struct spi_slave *slave, uchar reg, uchar data) |
| 76 | { |
| 77 | unsigned char din[3]; |
| 78 | return ksz8893m_transfer(slave, KSZ_WRITE, reg, data, din); |
| 79 | } |
| 80 | |
| 81 | static int ksz8893m_reg_clear(struct spi_slave *slave, uchar reg, uchar mask) |
| 82 | { |
| 83 | int ret = 0; |
| 84 | unsigned char din[3]; |
| 85 | |
| 86 | ret |= ksz8893m_transfer(slave, KSZ_READ, reg, 0, din); |
| 87 | ret |= ksz8893m_reg_set(slave, reg, din[2] & mask); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | static int ksz8893m_reset(struct spi_slave *slave) |
| 93 | { |
| 94 | int ret = 0; |
| 95 | |
| 96 | /* Disable STPID mode */ |
| 97 | ret |= ksz8893m_reg_clear(slave, KSZ_REG_GC9, 0x01); |
| 98 | |
| 99 | /* Disable VLAN tag insert on Port3 */ |
| 100 | ret |= ksz8893m_reg_clear(slave, KSZ_REG_P3C0, 0x04); |
| 101 | |
| 102 | /* Start switch */ |
| 103 | ret |= ksz8893m_reg_set(slave, KSZ_REG_STPID, 0x01); |
| 104 | |
| 105 | return ret; |
| 106 | } |
| 107 | |
Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 108 | int board_eth_init(bd_t *bis) |
| 109 | { |
| 110 | static bool switch_is_alive = false; |
| 111 | int ret; |
| 112 | |
| 113 | if (!switch_is_alive) { |
Graf Yang | a211d4b | 2009-05-05 02:26:27 -0400 | [diff] [blame] | 114 | struct spi_slave *slave = spi_setup_slave(0, 1, KSZ_MAX_HZ, SPI_MODE_3); |
Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 115 | if (slave) { |
| 116 | if (!spi_claim_bus(slave)) { |
Graf Yang | a211d4b | 2009-05-05 02:26:27 -0400 | [diff] [blame] | 117 | ret = ksz8893m_reset(slave); |
Mike Frysinger | 4752c19 | 2008-10-12 21:32:52 -0400 | [diff] [blame] | 118 | if (!ret) |
| 119 | switch_is_alive = true; |
| 120 | spi_release_bus(slave); |
| 121 | } |
| 122 | spi_free_slave(slave); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (switch_is_alive) |
| 127 | return bfin_EMAC_initialize(bis); |
| 128 | else |
| 129 | return -1; |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | int misc_init_r(void) |
| 134 | { |
| 135 | #ifdef CONFIG_BFIN_MAC |
| 136 | uchar enetaddr[6]; |
| 137 | if (!eth_getenv_enetaddr("ethaddr", enetaddr)) |
| 138 | board_init_enetaddr(enetaddr); |
| 139 | #endif |
| 140 | |
| 141 | return 0; |
| 142 | } |
Graf Yang | 55e4b49 | 2009-05-24 02:34:34 -0400 | [diff] [blame] | 143 | |
| 144 | int board_early_init_f(void) |
| 145 | { |
| 146 | #if !defined(CONFIG_SYS_NO_FLASH) |
| 147 | /* setup BF518-EZBRD GPIO pin PG11 to AMS2. */ |
| 148 | bfin_write_PORTG_MUX((bfin_read_PORTG_MUX() & ~PORT_x_MUX_6_MASK) | PORT_x_MUX_6_FUNC_2); |
| 149 | bfin_write_PORTG_FER(bfin_read_PORTG_FER() | PG11); |
| 150 | |
| 151 | # if !defined(CONFIG_BFIN_SPI) |
| 152 | /* setup BF518-EZBRD GPIO pin PG15 to AMS3. */ |
| 153 | bfin_write_PORTG_MUX((bfin_read_PORTG_MUX() & ~PORT_x_MUX_7_MASK) | PORT_x_MUX_7_FUNC_3); |
| 154 | bfin_write_PORTG_FER(bfin_read_PORTG_FER() | PG15); |
| 155 | # endif |
| 156 | #endif |
| 157 | return 0; |
| 158 | } |
Cliff Cai | e463892 | 2009-11-20 08:24:43 +0000 | [diff] [blame] | 159 | |
| 160 | #ifdef CONFIG_BFIN_SDH |
| 161 | int board_mmc_init(bd_t *bis) |
| 162 | { |
| 163 | return bfin_mmc_init(bis); |
| 164 | } |
| 165 | #endif |