summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/gen83xx/network/network.c
blob: 8912ec47392473e15715eca8fa349f5fc8510542 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*===============================================================*\
| Project: RTEMS support for MPC83xx                              |
+-----------------------------------------------------------------+
|                    Copyright (c) 2007                           |
|                    Embedded Brains GmbH                         |
|                    Obere Lagerstr. 30                           |
|                    D-82178 Puchheim                             |
|                    Germany                                      |
|                    rtems@embedded-brains.de                     |
+-----------------------------------------------------------------+
| The license and distribution terms for this file may be         |
| found in the file LICENSE in this distribution or at            |
|                                                                 |
| http://www.rtems.com/license/LICENSE.                           |
|                                                                 |
+-----------------------------------------------------------------+
| this file contains the board specific portion                   |
| of the network interface driver                                 |
\*===============================================================*/

#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/rtems_bsdnet_internal.h>
#include <bsp.h>
#include <bsp/tsec.h>
#include <bsp/u-boot.h>
#include <mpc83xx/mpc83xx.h>
#include <stdio.h>

#define TSEC_IFMODE_RGMII 0
#define TSEC_IFMODE_GMII  1

#if defined( MPC8313ERDB)

#define TSEC_IFMODE TSEC_IFMODE_RGMII

#elif defined( MPC8349EAMDS)

#define TSEC_IFMODE TSEC_IFMODE_GMII

#elif defined( HSC_CM01)

#define TSEC_IFMODE TSEC_IFMODE_RGMII

#else

#warning No TSEC configuration available

#endif

/*=========================================================================*\
| Function:                                                                 |
\*-------------------------------------------------------------------------*/
int BSP_tsec_attach
(
/*-------------------------------------------------------------------------*\
| Purpose:                                                                  |
|   attach or detach the driver                                             |
+---------------------------------------------------------------------------+
| Input Parameters:                                                         |
\*-------------------------------------------------------------------------*/
 struct rtems_bsdnet_ifconfig *config, /* interface configuration          */
 int attaching                         /* 0 = detach, else attach          */
)
/*-------------------------------------------------------------------------*\
| Return Value:                                                             |
|    1, if success                                                       |
\*=========================================================================*/
{
  int    unitNumber;
  char *unitName;

  /*
   * Parse driver name
   */
  if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) {
    return 0;
  }
  if (attaching) {
#if (TSEC_IFMODE==TSEC_IFMODE_GMII)
#if !defined(HSC_CM01)

      /*
       * do not change system I/O configuration registers on HSC board
       * because should initialize from RCW
       */


    if (unitNumber == 1) {
      /*
       * init system I/O configuration registers
       * to ensure proper pin functions
       */
      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000;
      /*
       * init port registers (GPIO2DIR) for TSEC1
       */
      mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF)
			       |                         0x0000001f);
    }
    if (unitNumber == 2) {
      /*
       * init system I/O configuration registers
       * to ensure proper pin functions
       */
      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000;
      /*
       * init port registers (GPIO2DIR) for TSEC2
       */
      mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF)
			       |                         0x00087881);
    }
#endif /* !defined(HSC_CM01) */
#endif
#if (TSEC_IFMODE==TSEC_IFMODE_RGMII)

    /*
     * Nothing special needed for TSEC1 operation
     */
#endif
  }
  /*
   * add MAC address into config->hardware_adderss
   * FIXME: get the real address we need
   */
  if (config->hardware_address == NULL) {
#if !defined(HAS_UBOOT)
    static char hw_addr [TSEC_COUNT][6];
    volatile tsec_registers *reg_ptr;

    /* read MAC address from hardware register */
    /* we expect it htere from the boot loader */
    reg_ptr = &mpc83xx.tsec[unitNumber - 1];
    config->hardware_address = hw_addr[unitNumber-1];

    hw_addr[unitNumber-1][5] = (reg_ptr->macstnaddr[0] >> 24) & 0xff;
    hw_addr[unitNumber-1][4] = (reg_ptr->macstnaddr[0] >> 16) & 0xff;
    hw_addr[unitNumber-1][3] = (reg_ptr->macstnaddr[0] >>  8) & 0xff;
    hw_addr[unitNumber-1][2] = (reg_ptr->macstnaddr[0] >>  0) & 0xff;
    hw_addr[unitNumber-1][1] = (reg_ptr->macstnaddr[1] >> 24) & 0xff;
    hw_addr[unitNumber-1][0] = (reg_ptr->macstnaddr[1] >> 16) & 0xff;
#endif

#if defined(HAS_UBOOT)
    switch (unitNumber) {
      case 1:
        config->hardware_address = bsp_uboot_board_info.bi_enetaddr;
        break;

#ifdef CONFIG_HAS_ETH1
      case 2:
        config->hardware_address = bsp_uboot_board_info.bi_enet1addr;
        break;
#endif /* CONFIG_HAS_ETH1 */

#ifdef CONFIG_HAS_ETH2
      case 3:
        config->hardware_address = bsp_uboot_board_info.bi_enet2addr;
        break;
#endif /* CONFIG_HAS_ETH2 */

#ifdef CONFIG_HAS_ETH3
      case 4:
        config->hardware_address = bsp_uboot_board_info.bi_enet3addr;
        break;
#endif /* CONFIG_HAS_ETH3 */

      default:
        return 0;
    }

#endif /* HAS_UBOOT */

  }
  /*
   * set interrupt number for given interface
   */
  config->irno = (unsigned) (
      unitNumber == 1
      ? BSP_IPIC_IRQ_TSEC1_TX
      : BSP_IPIC_IRQ_TSEC2_TX
    );
  /*
   * call attach function of board independent driver
   */
  return tsec_driver_attach_detach(
    config,
    unitNumber,
    unitName,
    &mpc83xx.tsec [unitNumber - 1],
    &mpc83xx.tsec [0],
    attaching
  );
}