[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 | | | |
---|
| 14 | | http://www.rtems.com/license/LICENSE. | |
---|
| 15 | | | |
---|
| 16 | +-----------------------------------------------------------------+ |
---|
| 17 | | this file contains the board specific portion | |
---|
| 18 | | of the network interface driver | |
---|
| 19 | \*===============================================================*/ |
---|
| 20 | |
---|
| 21 | #include <rtems.h> |
---|
| 22 | #include <rtems/rtems_bsdnet.h> |
---|
[3df08660] | 23 | #include <rtems/rtems_bsdnet_internal.h> |
---|
[f610e83f] | 24 | #include <bsp.h> |
---|
| 25 | #include <mpc83xx/tsec.h> |
---|
| 26 | #include <mpc83xx/mpc83xx.h> |
---|
| 27 | #include <stdio.h> |
---|
| 28 | |
---|
| 29 | #define TSEC_IFMODE_RGMII 0 |
---|
| 30 | #define TSEC_IFMODE_GMII 1 |
---|
[42bf1b9] | 31 | |
---|
[574fb67] | 32 | #if defined( MPC8313ERDB) |
---|
| 33 | |
---|
[214cbd9] | 34 | #define TSEC_IFMODE TSEC_IFMODE_RGMII |
---|
[42bf1b9] | 35 | |
---|
[574fb67] | 36 | #elif defined( MPC8349EAMDS) |
---|
| 37 | |
---|
[677cf05f] | 38 | #define TSEC_IFMODE TSEC_IFMODE_GMII |
---|
[574fb67] | 39 | |
---|
| 40 | #elif defined( HSC_CM01) |
---|
| 41 | |
---|
[f610e83f] | 42 | #define TSEC_IFMODE TSEC_IFMODE_RGMII |
---|
[574fb67] | 43 | |
---|
| 44 | #else |
---|
| 45 | |
---|
| 46 | #warning No TSEC configuration available |
---|
| 47 | |
---|
[42bf1b9] | 48 | #endif |
---|
[f610e83f] | 49 | |
---|
| 50 | /*=========================================================================*\ |
---|
| 51 | | Function: | |
---|
| 52 | \*-------------------------------------------------------------------------*/ |
---|
| 53 | int BSP_tsec_attach |
---|
| 54 | ( |
---|
| 55 | /*-------------------------------------------------------------------------*\ |
---|
| 56 | | Purpose: | |
---|
| 57 | | attach or detach the driver | |
---|
| 58 | +---------------------------------------------------------------------------+ |
---|
| 59 | | Input Parameters: | |
---|
| 60 | \*-------------------------------------------------------------------------*/ |
---|
| 61 | struct rtems_bsdnet_ifconfig *config, /* interface configuration */ |
---|
| 62 | int attaching /* 0 = detach, else attach */ |
---|
| 63 | ) |
---|
| 64 | /*-------------------------------------------------------------------------*\ |
---|
| 65 | | Return Value: | |
---|
| 66 | | 1, if success | |
---|
| 67 | \*=========================================================================*/ |
---|
| 68 | { |
---|
| 69 | int unitNumber; |
---|
| 70 | char *unitName; |
---|
| 71 | |
---|
| 72 | /* |
---|
| 73 | * Parse driver name |
---|
| 74 | */ |
---|
| 75 | if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) { |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
| 78 | if (attaching) { |
---|
[42bf1b9] | 79 | #if (TSEC_IFMODE==TSEC_IFMODE_GMII) |
---|
[4b23c94] | 80 | #if !defined(HSC_CM01) |
---|
| 81 | |
---|
| 82 | /* |
---|
| 83 | * do not change system I/O configuration registers on HSC board |
---|
| 84 | * because should initialize from RCW |
---|
| 85 | */ |
---|
| 86 | |
---|
| 87 | |
---|
[f610e83f] | 88 | if (unitNumber == 1) { |
---|
| 89 | /* |
---|
| 90 | * init system I/O configuration registers |
---|
[59be902] | 91 | * to ensure proper pin functions |
---|
[f610e83f] | 92 | */ |
---|
[59be902] | 93 | mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000; |
---|
[f610e83f] | 94 | /* |
---|
| 95 | * init port registers (GPIO2DIR) for TSEC1 |
---|
| 96 | */ |
---|
| 97 | mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF) |
---|
| 98 | | 0x0000001f); |
---|
| 99 | } |
---|
[42bf1b9] | 100 | if (unitNumber == 2) { |
---|
[59be902] | 101 | /* |
---|
| 102 | * init system I/O configuration registers |
---|
| 103 | * to ensure proper pin functions |
---|
| 104 | */ |
---|
| 105 | mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000; |
---|
[42bf1b9] | 106 | /* |
---|
| 107 | * init port registers (GPIO2DIR) for TSEC2 |
---|
| 108 | */ |
---|
| 109 | mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF) |
---|
| 110 | | 0x00087881); |
---|
| 111 | } |
---|
[4b23c94] | 112 | #endif /* !defined(HSC_CM01) */ |
---|
[42bf1b9] | 113 | #endif |
---|
| 114 | #if (TSEC_IFMODE==TSEC_IFMODE_RGMII) |
---|
| 115 | |
---|
[f610e83f] | 116 | /* |
---|
[42bf1b9] | 117 | * Nothing special needed for TSEC1 operation |
---|
[f610e83f] | 118 | */ |
---|
[42bf1b9] | 119 | #endif |
---|
[f610e83f] | 120 | } |
---|
| 121 | /* |
---|
| 122 | * add MAC address into config->hardware_adderss |
---|
| 123 | * FIXME: get the real address we need |
---|
| 124 | */ |
---|
| 125 | if (config->hardware_address == NULL) { |
---|
[574fb67] | 126 | |
---|
| 127 | #ifdef HAS_UBOOT |
---|
| 128 | |
---|
| 129 | switch (unitNumber) { |
---|
| 130 | case 1: |
---|
| 131 | config->hardware_address = mpc83xx_uboot_board_info.bi_enetaddr; |
---|
| 132 | break; |
---|
| 133 | |
---|
| 134 | #ifdef CONFIG_HAS_ETH1 |
---|
| 135 | case 2: |
---|
| 136 | config->hardware_address = mpc83xx_uboot_board_info.bi_enet1addr; |
---|
| 137 | break; |
---|
| 138 | #endif /* CONFIG_HAS_ETH1 */ |
---|
| 139 | |
---|
| 140 | #ifdef CONFIG_HAS_ETH2 |
---|
| 141 | case 3: |
---|
| 142 | config->hardware_address = mpc83xx_uboot_board_info.bi_enet2addr; |
---|
| 143 | break; |
---|
| 144 | #endif /* CONFIG_HAS_ETH2 */ |
---|
| 145 | |
---|
| 146 | #ifdef CONFIG_HAS_ETH3 |
---|
| 147 | case 4: |
---|
| 148 | config->hardware_address = mpc83xx_uboot_board_info.bi_enet3addr; |
---|
| 149 | break; |
---|
| 150 | #endif /* CONFIG_HAS_ETH3 */ |
---|
| 151 | |
---|
| 152 | default: |
---|
| 153 | return 0; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | #else /* HAS_UBOOT */ |
---|
| 157 | |
---|
| 158 | char hw_addr [6] = { 0x00, 0x04, 0x9f, 0x00, 0x2f, 0xcb}; |
---|
| 159 | |
---|
[f610e83f] | 160 | config->hardware_address = hw_addr; |
---|
[574fb67] | 161 | |
---|
| 162 | #endif /* HAS_UBOOT */ |
---|
| 163 | |
---|
[f610e83f] | 164 | } |
---|
| 165 | /* |
---|
| 166 | * set interrupt number for given interface |
---|
| 167 | */ |
---|
[699c2be] | 168 | config->irno = (unsigned) ( |
---|
| 169 | unitNumber == 1 |
---|
| 170 | ? BSP_IPIC_IRQ_TSEC1_TX |
---|
| 171 | : BSP_IPIC_IRQ_TSEC2_TX |
---|
| 172 | ); |
---|
[f610e83f] | 173 | /* |
---|
| 174 | * call attach function of board independent driver |
---|
| 175 | */ |
---|
| 176 | if (0 == rtems_mpc83xx_tsec_driver_attach_detach(config,attaching)) { |
---|
| 177 | return 0; |
---|
| 178 | } |
---|
| 179 | return 1; |
---|
| 180 | } |
---|