source: rtems/c/src/lib/libbsp/powerpc/gen83xx/network/network.c @ 7a752161

4.115
Last change on this file since 7a752161 was 7a752161, checked in by Sebastian Huber <sebastian.huber@…>, on 09/26/11 at 10:08:29

2011-09-27 Sebastian Huber <sebastian.huber@…>

  • make/custom/mpc8309som.cfg, startup/linkcmds.mpc8309som: New file.
  • Makefile.am, preinstall.am: Reflect changes above.
  • configure.ac, console/console-config.c, include/bsp.h, include/hwreg_vals.h, include/irq.h, network/network.c, spi/spi_init.c, startup/cpuinit.c: Renamed various BSP options.
  • make/custom/gen83xx.inc, make/custom/hsc_cm01.cfg, make/custom/mpc8313erdb.cfg, make/custom/mpc8349eamds.cfg: Avoid special linkcmds.
  • Property mode set to 100644
File size: 7.8 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/*
22 *  $Id$
23 */
24
25#include <rtems.h>
26#include <rtems/rtems_bsdnet.h>
27#include <rtems/rtems_bsdnet_internal.h>
28#include <bsp.h>
29#include <bsp/tsec.h>
30#include <bsp/u-boot.h>
31#include <mpc83xx/mpc83xx.h>
32#include <string.h>
33#include <libcpu/spr.h>
34
35#if MPC83XX_CHIP_TYPE / 10 != 830
36
37#define TSEC_IFMODE_RGMII 0
38#define TSEC_IFMODE_GMII  1
39
40#if defined( MPC83XX_BOARD_MPC8313ERDB)
41
42#define TSEC_IFMODE TSEC_IFMODE_RGMII
43
44#elif defined( MPC83XX_BOARD_MPC8349EAMDS)
45
46#define TSEC_IFMODE TSEC_IFMODE_GMII
47
48#elif defined( MPC83XX_BOARD_HSC_CM01)
49
50#define TSEC_IFMODE TSEC_IFMODE_RGMII
51
52#else
53
54#warning No TSEC configuration available
55
56#endif
57
58/* System Version Register */
59#define SVR 286
60SPR_RO( SVR)
61
62/* Processor Version Register */
63SPR_RO( PPC_PVR)
64
65/*=========================================================================*\
66| Function:                                                                 |
67\*-------------------------------------------------------------------------*/
68int BSP_tsec_attach
69(
70/*-------------------------------------------------------------------------*\
71| Purpose:                                                                  |
72|   attach or detach the driver                                             |
73+---------------------------------------------------------------------------+
74| Input Parameters:                                                         |
75\*-------------------------------------------------------------------------*/
76 struct rtems_bsdnet_ifconfig *config, /* interface configuration          */
77 int attaching                         /* 0 = detach, else attach          */
78)
79/*-------------------------------------------------------------------------*\
80| Return Value:                                                             |
81|    1, if success                                                       |
82\*=========================================================================*/
83{
84  tsec_config tsec_cfg;
85  int    unitNumber;
86  char *unitName;
87  uint32_t svr = _read_SVR();
88  uint32_t pvr = _read_PPC_PVR();
89
90  memset(&tsec_cfg, 0, sizeof(tsec_cfg));
91  config->drv_ctrl = &tsec_cfg;
92
93  /*
94   * Parse driver name
95   */
96  if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) {
97    return 0;
98  }
99
100  tsec_cfg.reg_ptr = &mpc83xx.tsec [unitNumber - 1];
101  tsec_cfg.mdio_ptr = &mpc83xx.tsec [0];
102
103  if (attaching) {
104#if (TSEC_IFMODE==TSEC_IFMODE_GMII)
105#if !defined(MPC83XX_BOARD_HSC_CM01)
106
107      /*
108       * do not change system I/O configuration registers on HSC board
109       * because should initialize from RCW
110       */
111
112
113    if (unitNumber == 1) {
114      /*
115       * init system I/O configuration registers
116       * to ensure proper pin functions
117       */
118      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000;
119      /*
120       * init port registers (GPIO2DIR) for TSEC1
121       */
122      mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF)
123                               |                         0x0000001f);
124    }
125    if (unitNumber == 2) {
126      /*
127       * init system I/O configuration registers
128       * to ensure proper pin functions
129       */
130      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000;
131      /*
132       * init port registers (GPIO2DIR) for TSEC2
133       */
134      mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF)
135                               |                         0x00087881);
136    }
137#endif /* !defined(MPC83XX_BOARD_HSC_CM01) */
138#endif
139#if (TSEC_IFMODE==TSEC_IFMODE_RGMII)
140
141    /*
142     * Nothing special needed for TSEC1 operation
143     */
144#endif
145  }
146  /*
147   * add MAC address into config->hardware_adderss
148   * FIXME: get the real address we need
149   */
150  if (config->hardware_address == NULL) {
151#if !defined(HAS_UBOOT)
152    static char hw_addr [TSEC_COUNT][6];
153    volatile tsec_registers *reg_ptr = tsec_cfg.reg_ptr;
154
155    /* read MAC address from hardware register */
156    /* we expect it htere from the boot loader */
157    config->hardware_address = hw_addr[unitNumber-1];
158
159    hw_addr[unitNumber-1][5] = (reg_ptr->macstnaddr[0] >> 24) & 0xff;
160    hw_addr[unitNumber-1][4] = (reg_ptr->macstnaddr[0] >> 16) & 0xff;
161    hw_addr[unitNumber-1][3] = (reg_ptr->macstnaddr[0] >>  8) & 0xff;
162    hw_addr[unitNumber-1][2] = (reg_ptr->macstnaddr[0] >>  0) & 0xff;
163    hw_addr[unitNumber-1][1] = (reg_ptr->macstnaddr[1] >> 24) & 0xff;
164    hw_addr[unitNumber-1][0] = (reg_ptr->macstnaddr[1] >> 16) & 0xff;
165#endif
166
167#if defined(HAS_UBOOT)
168    switch (unitNumber) {
169      case 1:
170        config->hardware_address = bsp_uboot_board_info.bi_enetaddr;
171        break;
172
173#ifdef CONFIG_HAS_ETH1
174      case 2:
175        config->hardware_address = bsp_uboot_board_info.bi_enet1addr;
176        break;
177#endif /* CONFIG_HAS_ETH1 */
178
179#ifdef CONFIG_HAS_ETH2
180      case 3:
181        config->hardware_address = bsp_uboot_board_info.bi_enet2addr;
182        break;
183#endif /* CONFIG_HAS_ETH2 */
184
185#ifdef CONFIG_HAS_ETH3
186      case 4:
187        config->hardware_address = bsp_uboot_board_info.bi_enet3addr;
188        break;
189#endif /* CONFIG_HAS_ETH3 */
190
191      default:
192        return 0;
193    }
194
195#endif /* HAS_UBOOT */
196
197  }
198  /*
199   * set interrupt number for given interface
200   */
201  config->irno = (unsigned) (
202      unitNumber == 1
203      ? BSP_IPIC_IRQ_TSEC1_TX
204      : BSP_IPIC_IRQ_TSEC2_TX
205    );
206
207  if (svr == 0x80b00010 && pvr == 0x80850010) {
208    /*
209     * This is a special case for MPC8313ERDB with silicon revision 1.  Look in
210     * "MPC8313ECE Rev. 3, 3/2008" errata for "IPIC 1".
211     */
212    if (unitNumber == 1) {
213      tsec_cfg.irq_num_tx      = 37;
214      tsec_cfg.irq_num_rx      = 36;
215      tsec_cfg.irq_num_err     = 35;
216    } else if (unitNumber == 2) {
217      tsec_cfg.irq_num_tx      = 34;
218      tsec_cfg.irq_num_rx      = 33;
219      tsec_cfg.irq_num_err     = 32;
220    } else {
221      return 0;
222    }
223  } else {
224    rtems_irq_number irno = unitNumber == 1 ?
225      BSP_IPIC_IRQ_TSEC1_TX : BSP_IPIC_IRQ_TSEC2_TX;
226
227    /* get base interrupt number (for Tx irq, Rx=base+1,Err=base+2) */
228    tsec_cfg.irq_num_tx = irno + 0;
229    tsec_cfg.irq_num_rx = irno + 1;
230    tsec_cfg.irq_num_err = irno + 2;
231  }
232
233  /*
234   * XXX: Although most hardware builders will assign the PHY addresses
235   * like this, this should be more configurable
236   */
237#ifdef MPC83XX_BOARD_MPC8313ERDB
238  if (unitNumber == 2) {
239          tsec_cfg.phy_default = 4;
240  } else {
241          /* TODO */
242          return 0;
243  }
244#else /* MPC83XX_BOARD_MPC8313ERDB */
245  tsec_cfg.phy_default = unitNumber-1;
246#endif /* MPC83XX_BOARD_MPC8313ERDB */
247
248  tsec_cfg.unit_number = unitNumber;
249  tsec_cfg.unit_name = unitName;
250
251  /*
252   * call attach function of board independent driver
253   */
254  return tsec_driver_attach_detach(config, attaching);
255}
256
257#endif /* MPC83XX_CHIP_TYPE / 10 != 830 */
Note: See TracBrowser for help on using the repository browser.