source: rtems/c/src/lib/libbsp/powerpc/gen83xx/network/network.c @ 73b019a0

4.9
Last change on this file since 73b019a0 was eb32e3a, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 11/18/08 at 11:36:28

include/bsp.h, include/hwreg_vals.h, network/network.c:

correct some init values for HSC_CM01 boards
change strategy to determine MAC address

  • Property mode set to 100644
File size: 6.1 KB
Line 
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>
23#include <rtems/rtems_bsdnet_internal.h>
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
31
32#if defined( MPC8313ERDB)
33
34#define TSEC_IFMODE TSEC_IFMODE_RGMII
35
36#elif defined( MPC8349EAMDS)
37
38#define TSEC_IFMODE TSEC_IFMODE_GMII
39
40#elif defined( HSC_CM01)
41
42#define TSEC_IFMODE TSEC_IFMODE_RGMII
43
44#else
45
46#warning No TSEC configuration available
47
48#endif
49
50/*=========================================================================*\
51| Function:                                                                 |
52\*-------------------------------------------------------------------------*/
53int 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) {
79#if (TSEC_IFMODE==TSEC_IFMODE_GMII)
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
88    if (unitNumber == 1) {
89      /*
90       * init system I/O configuration registers
91       * to ensure proper pin functions
92       */
93      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000;
94      /*
95       * init port registers (GPIO2DIR) for TSEC1
96       */
97      mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF)
98                               |                         0x0000001f);
99    }
100    if (unitNumber == 2) {
101      /*
102       * init system I/O configuration registers
103       * to ensure proper pin functions
104       */
105      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000;
106      /*
107       * init port registers (GPIO2DIR) for TSEC2
108       */
109      mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF)
110                               |                         0x00087881);
111    }
112#endif /* !defined(HSC_CM01) */
113#endif
114#if (TSEC_IFMODE==TSEC_IFMODE_RGMII)
115
116    /*
117     * Nothing special needed for TSEC1 operation
118     */
119#endif   
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) {
126#if !defined(HAS_UBOOT)
127    static char hw_addr [M83xx_TSEC_NIFACES][6];
128    m83xxTSEC_Registers_t  *reg_ptr;
129
130    /* read MAC address from hardware register */
131    /* we expect it htere from the boot loader */
132    reg_ptr = &mpc83xx.tsec[unitNumber - 1];
133    config->hardware_address = hw_addr[unitNumber-1];
134   
135    hw_addr[unitNumber-1][5] = (reg_ptr->macstnaddr[0] >> 24) & 0xff;
136    hw_addr[unitNumber-1][4] = (reg_ptr->macstnaddr[0] >> 16) & 0xff;
137    hw_addr[unitNumber-1][3] = (reg_ptr->macstnaddr[0] >>  8) & 0xff;
138    hw_addr[unitNumber-1][2] = (reg_ptr->macstnaddr[0] >>  0) & 0xff;
139    hw_addr[unitNumber-1][1] = (reg_ptr->macstnaddr[1] >> 24) & 0xff;
140    hw_addr[unitNumber-1][0] = (reg_ptr->macstnaddr[1] >> 16) & 0xff;
141#endif
142
143#if defined(HAS_UBOOT)
144    switch (unitNumber) {
145      case 1:
146        config->hardware_address = mpc83xx_uboot_board_info.bi_enetaddr;
147        break;
148
149#ifdef CONFIG_HAS_ETH1
150      case 2:
151        config->hardware_address = mpc83xx_uboot_board_info.bi_enet1addr;
152        break;
153#endif /* CONFIG_HAS_ETH1 */
154
155#ifdef CONFIG_HAS_ETH2
156      case 3:
157        config->hardware_address = mpc83xx_uboot_board_info.bi_enet2addr;
158        break;
159#endif /* CONFIG_HAS_ETH2 */
160
161#ifdef CONFIG_HAS_ETH3
162      case 4:
163        config->hardware_address = mpc83xx_uboot_board_info.bi_enet3addr;
164        break;
165#endif /* CONFIG_HAS_ETH3 */
166
167      default:
168        return 0;
169    }
170
171#endif /* HAS_UBOOT */
172
173  }
174  /*
175   * set interrupt number for given interface
176   */
177  config->irno = (unsigned) (
178      unitNumber == 1
179      ? BSP_IPIC_IRQ_TSEC1_TX
180      : BSP_IPIC_IRQ_TSEC2_TX
181    );
182  /*
183   * call attach function of board independent driver
184   */
185  if (0 == rtems_mpc83xx_tsec_driver_attach_detach(config,attaching)) {
186    return 0;
187  }
188  return 1;
189}
Note: See TracBrowser for help on using the repository browser.