[f610e83f] | 1 | /*===============================================================*\ |
---|
| 2 | | Project: RTEMS support for MPC83xx | |
---|
| 3 | +-----------------------------------------------------------------+ |
---|
| 4 | | Copyright (c) 2007 | |
---|
| 5 | | Embedded Brains GmbH | |
---|
| 6 | | Obere Lagerstr. 30 | |
---|
| 7 | | D-82178 Puchheim | |
---|
| 8 | | Germany | |
---|
| 9 | | rtems@embedded-brains.de | |
---|
| 10 | +-----------------------------------------------------------------+ |
---|
| 11 | | The license and distribution terms for this file may be | |
---|
| 12 | | found in the file LICENSE in this distribution or at | |
---|
| 13 | | | |
---|
[c499856] | 14 | | http://www.rtems.org/license/LICENSE. | |
---|
[f610e83f] | 15 | | | |
---|
| 16 | +-----------------------------------------------------------------+ |
---|
| 17 | | this file contains the board specific portion | |
---|
| 18 | | of the network interface driver | |
---|
| 19 | \*===============================================================*/ |
---|
| 20 | |
---|
[d8d6a08] | 21 | #define __INSIDE_RTEMS_BSD_TCPIP_STACK__ |
---|
[e570c313] | 22 | |
---|
[f610e83f] | 23 | #include <rtems.h> |
---|
| 24 | #include <rtems/rtems_bsdnet.h> |
---|
[3df08660] | 25 | #include <rtems/rtems_bsdnet_internal.h> |
---|
[f610e83f] | 26 | #include <bsp.h> |
---|
[ce0922e] | 27 | #include <bsp/tsec.h> |
---|
| 28 | #include <bsp/u-boot.h> |
---|
[f610e83f] | 29 | #include <mpc83xx/mpc83xx.h> |
---|
[0e1d590c] | 30 | #include <string.h> |
---|
| 31 | #include <libcpu/spr.h> |
---|
[f610e83f] | 32 | |
---|
[7a752161] | 33 | #if MPC83XX_CHIP_TYPE / 10 != 830 |
---|
| 34 | |
---|
[f610e83f] | 35 | #define TSEC_IFMODE_RGMII 0 |
---|
| 36 | #define TSEC_IFMODE_GMII 1 |
---|
[42bf1b9] | 37 | |
---|
[7a752161] | 38 | #if defined( MPC83XX_BOARD_MPC8313ERDB) |
---|
[574fb67] | 39 | |
---|
[214cbd9] | 40 | #define TSEC_IFMODE TSEC_IFMODE_RGMII |
---|
[42bf1b9] | 41 | |
---|
[7a752161] | 42 | #elif defined( MPC83XX_BOARD_MPC8349EAMDS) |
---|
[574fb67] | 43 | |
---|
[677cf05f] | 44 | #define TSEC_IFMODE TSEC_IFMODE_GMII |
---|
[574fb67] | 45 | |
---|
[7a752161] | 46 | #elif defined( MPC83XX_BOARD_HSC_CM01) |
---|
[574fb67] | 47 | |
---|
[f610e83f] | 48 | #define TSEC_IFMODE TSEC_IFMODE_RGMII |
---|
[574fb67] | 49 | |
---|
| 50 | #else |
---|
| 51 | |
---|
| 52 | #warning No TSEC configuration available |
---|
| 53 | |
---|
[42bf1b9] | 54 | #endif |
---|
[f610e83f] | 55 | |
---|
[0e1d590c] | 56 | /* System Version Register */ |
---|
| 57 | #define SVR 286 |
---|
| 58 | SPR_RO( SVR) |
---|
| 59 | |
---|
| 60 | /* Processor Version Register */ |
---|
[01750d5] | 61 | SPR_RO( PPC_PVR) |
---|
[0e1d590c] | 62 | |
---|
[f610e83f] | 63 | /*=========================================================================*\ |
---|
| 64 | | Function: | |
---|
| 65 | \*-------------------------------------------------------------------------*/ |
---|
| 66 | int BSP_tsec_attach |
---|
| 67 | ( |
---|
| 68 | /*-------------------------------------------------------------------------*\ |
---|
| 69 | | Purpose: | |
---|
| 70 | | attach or detach the driver | |
---|
| 71 | +---------------------------------------------------------------------------+ |
---|
| 72 | | Input Parameters: | |
---|
| 73 | \*-------------------------------------------------------------------------*/ |
---|
| 74 | struct rtems_bsdnet_ifconfig *config, /* interface configuration */ |
---|
| 75 | int attaching /* 0 = detach, else attach */ |
---|
| 76 | ) |
---|
| 77 | /*-------------------------------------------------------------------------*\ |
---|
| 78 | | Return Value: | |
---|
| 79 | | 1, if success | |
---|
| 80 | \*=========================================================================*/ |
---|
| 81 | { |
---|
[0e1d590c] | 82 | tsec_config tsec_cfg; |
---|
[f610e83f] | 83 | int unitNumber; |
---|
[ce0922e] | 84 | char *unitName; |
---|
[0e1d590c] | 85 | uint32_t svr = _read_SVR(); |
---|
[01750d5] | 86 | uint32_t pvr = _read_PPC_PVR(); |
---|
[0e1d590c] | 87 | |
---|
| 88 | memset(&tsec_cfg, 0, sizeof(tsec_cfg)); |
---|
| 89 | config->drv_ctrl = &tsec_cfg; |
---|
[f610e83f] | 90 | |
---|
| 91 | /* |
---|
| 92 | * Parse driver name |
---|
| 93 | */ |
---|
[ce0922e] | 94 | if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) { |
---|
[f610e83f] | 95 | return 0; |
---|
| 96 | } |
---|
[0e1d590c] | 97 | |
---|
| 98 | tsec_cfg.reg_ptr = &mpc83xx.tsec [unitNumber - 1]; |
---|
| 99 | tsec_cfg.mdio_ptr = &mpc83xx.tsec [0]; |
---|
| 100 | |
---|
[f610e83f] | 101 | if (attaching) { |
---|
[42bf1b9] | 102 | #if (TSEC_IFMODE==TSEC_IFMODE_GMII) |
---|
[7a752161] | 103 | #if !defined(MPC83XX_BOARD_HSC_CM01) |
---|
[4b23c94] | 104 | |
---|
| 105 | /* |
---|
| 106 | * do not change system I/O configuration registers on HSC board |
---|
| 107 | * because should initialize from RCW |
---|
| 108 | */ |
---|
| 109 | |
---|
| 110 | |
---|
[f610e83f] | 111 | if (unitNumber == 1) { |
---|
| 112 | /* |
---|
[ac7af4a] | 113 | * init system I/O configuration registers |
---|
| 114 | * to ensure proper pin functions |
---|
[f610e83f] | 115 | */ |
---|
[59be902] | 116 | mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000; |
---|
[f610e83f] | 117 | /* |
---|
| 118 | * init port registers (GPIO2DIR) for TSEC1 |
---|
| 119 | */ |
---|
| 120 | mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF) |
---|
| 121 | | 0x0000001f); |
---|
| 122 | } |
---|
[42bf1b9] | 123 | if (unitNumber == 2) { |
---|
[59be902] | 124 | /* |
---|
[ac7af4a] | 125 | * init system I/O configuration registers |
---|
| 126 | * to ensure proper pin functions |
---|
[59be902] | 127 | */ |
---|
| 128 | mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000; |
---|
[42bf1b9] | 129 | /* |
---|
| 130 | * init port registers (GPIO2DIR) for TSEC2 |
---|
| 131 | */ |
---|
| 132 | mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF) |
---|
| 133 | | 0x00087881); |
---|
| 134 | } |
---|
[7a752161] | 135 | #endif /* !defined(MPC83XX_BOARD_HSC_CM01) */ |
---|
[42bf1b9] | 136 | #endif |
---|
| 137 | #if (TSEC_IFMODE==TSEC_IFMODE_RGMII) |
---|
| 138 | |
---|
[f610e83f] | 139 | /* |
---|
[42bf1b9] | 140 | * Nothing special needed for TSEC1 operation |
---|
[f610e83f] | 141 | */ |
---|
[ac7af4a] | 142 | #endif |
---|
[f610e83f] | 143 | } |
---|
| 144 | /* |
---|
| 145 | * add MAC address into config->hardware_adderss |
---|
| 146 | * FIXME: get the real address we need |
---|
| 147 | */ |
---|
| 148 | if (config->hardware_address == NULL) { |
---|
[d11ea4eb] | 149 | #if !defined(HAS_UBOOT) |
---|
[45c8fb6] | 150 | static char hw_addr [TSEC_COUNT][6]; |
---|
[760ef104] | 151 | volatile tsec_registers *reg_ptr = tsec_cfg.reg_ptr; |
---|
[d11ea4eb] | 152 | |
---|
| 153 | /* read MAC address from hardware register */ |
---|
| 154 | /* we expect it htere from the boot loader */ |
---|
| 155 | config->hardware_address = hw_addr[unitNumber-1]; |
---|
[ac7af4a] | 156 | |
---|
[d11ea4eb] | 157 | hw_addr[unitNumber-1][5] = (reg_ptr->macstnaddr[0] >> 24) & 0xff; |
---|
| 158 | hw_addr[unitNumber-1][4] = (reg_ptr->macstnaddr[0] >> 16) & 0xff; |
---|
| 159 | hw_addr[unitNumber-1][3] = (reg_ptr->macstnaddr[0] >> 8) & 0xff; |
---|
| 160 | hw_addr[unitNumber-1][2] = (reg_ptr->macstnaddr[0] >> 0) & 0xff; |
---|
| 161 | hw_addr[unitNumber-1][1] = (reg_ptr->macstnaddr[1] >> 24) & 0xff; |
---|
| 162 | hw_addr[unitNumber-1][0] = (reg_ptr->macstnaddr[1] >> 16) & 0xff; |
---|
| 163 | #endif |
---|
[574fb67] | 164 | |
---|
[d11ea4eb] | 165 | #if defined(HAS_UBOOT) |
---|
[574fb67] | 166 | switch (unitNumber) { |
---|
| 167 | case 1: |
---|
[ac4b164] | 168 | config->hardware_address = bsp_uboot_board_info.bi_enetaddr; |
---|
[574fb67] | 169 | break; |
---|
| 170 | |
---|
| 171 | #ifdef CONFIG_HAS_ETH1 |
---|
| 172 | case 2: |
---|
[ac4b164] | 173 | config->hardware_address = bsp_uboot_board_info.bi_enet1addr; |
---|
[574fb67] | 174 | break; |
---|
| 175 | #endif /* CONFIG_HAS_ETH1 */ |
---|
| 176 | |
---|
| 177 | #ifdef CONFIG_HAS_ETH2 |
---|
| 178 | case 3: |
---|
[ac4b164] | 179 | config->hardware_address = bsp_uboot_board_info.bi_enet2addr; |
---|
[574fb67] | 180 | break; |
---|
| 181 | #endif /* CONFIG_HAS_ETH2 */ |
---|
| 182 | |
---|
| 183 | #ifdef CONFIG_HAS_ETH3 |
---|
| 184 | case 4: |
---|
[ac4b164] | 185 | config->hardware_address = bsp_uboot_board_info.bi_enet3addr; |
---|
[574fb67] | 186 | break; |
---|
| 187 | #endif /* CONFIG_HAS_ETH3 */ |
---|
| 188 | |
---|
| 189 | default: |
---|
| 190 | return 0; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | #endif /* HAS_UBOOT */ |
---|
| 194 | |
---|
[f610e83f] | 195 | } |
---|
| 196 | /* |
---|
| 197 | * set interrupt number for given interface |
---|
| 198 | */ |
---|
[699c2be] | 199 | config->irno = (unsigned) ( |
---|
| 200 | unitNumber == 1 |
---|
| 201 | ? BSP_IPIC_IRQ_TSEC1_TX |
---|
| 202 | : BSP_IPIC_IRQ_TSEC2_TX |
---|
| 203 | ); |
---|
[0e1d590c] | 204 | |
---|
| 205 | if (svr == 0x80b00010 && pvr == 0x80850010) { |
---|
| 206 | /* |
---|
| 207 | * This is a special case for MPC8313ERDB with silicon revision 1. Look in |
---|
| 208 | * "MPC8313ECE Rev. 3, 3/2008" errata for "IPIC 1". |
---|
| 209 | */ |
---|
| 210 | if (unitNumber == 1) { |
---|
| 211 | tsec_cfg.irq_num_tx = 37; |
---|
| 212 | tsec_cfg.irq_num_rx = 36; |
---|
| 213 | tsec_cfg.irq_num_err = 35; |
---|
| 214 | } else if (unitNumber == 2) { |
---|
| 215 | tsec_cfg.irq_num_tx = 34; |
---|
| 216 | tsec_cfg.irq_num_rx = 33; |
---|
| 217 | tsec_cfg.irq_num_err = 32; |
---|
| 218 | } else { |
---|
| 219 | return 0; |
---|
| 220 | } |
---|
| 221 | } else { |
---|
| 222 | rtems_irq_number irno = unitNumber == 1 ? |
---|
| 223 | BSP_IPIC_IRQ_TSEC1_TX : BSP_IPIC_IRQ_TSEC2_TX; |
---|
| 224 | |
---|
| 225 | /* get base interrupt number (for Tx irq, Rx=base+1,Err=base+2) */ |
---|
| 226 | tsec_cfg.irq_num_tx = irno + 0; |
---|
| 227 | tsec_cfg.irq_num_rx = irno + 1; |
---|
| 228 | tsec_cfg.irq_num_err = irno + 2; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | /* |
---|
| 232 | * XXX: Although most hardware builders will assign the PHY addresses |
---|
| 233 | * like this, this should be more configurable |
---|
| 234 | */ |
---|
[7a752161] | 235 | #ifdef MPC83XX_BOARD_MPC8313ERDB |
---|
[0e1d590c] | 236 | if (unitNumber == 2) { |
---|
| 237 | tsec_cfg.phy_default = 4; |
---|
| 238 | } else { |
---|
| 239 | /* TODO */ |
---|
| 240 | return 0; |
---|
| 241 | } |
---|
[7a752161] | 242 | #else /* MPC83XX_BOARD_MPC8313ERDB */ |
---|
[0e1d590c] | 243 | tsec_cfg.phy_default = unitNumber-1; |
---|
[7a752161] | 244 | #endif /* MPC83XX_BOARD_MPC8313ERDB */ |
---|
[0e1d590c] | 245 | |
---|
| 246 | tsec_cfg.unit_number = unitNumber; |
---|
| 247 | tsec_cfg.unit_name = unitName; |
---|
| 248 | |
---|
[f610e83f] | 249 | /* |
---|
| 250 | * call attach function of board independent driver |
---|
| 251 | */ |
---|
[0e1d590c] | 252 | return tsec_driver_attach_detach(config, attaching); |
---|
[f610e83f] | 253 | } |
---|
[7a752161] | 254 | |
---|
| 255 | #endif /* MPC83XX_CHIP_TYPE / 10 != 830 */ |
---|