OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [powerpc/] [quicc2/] [current/] [src/] [EnetPHY.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
2
// -------------------------------------------                              
3
// This file is part of eCos, the Embedded Configurable Operating System.   
4
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5
//
6
// eCos is free software; you can redistribute it and/or modify it under    
7
// the terms of the GNU General Public License as published by the Free     
8
// Software Foundation; either version 2 or (at your option) any later      
9
// version.                                                                 
10
//
11
// eCos is distributed in the hope that it will be useful, but WITHOUT      
12
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
13
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
14
// for more details.                                                        
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
18
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
19
//
20
// As a special exception, if other files instantiate templates or use      
21
// macros or inline functions from this file, or you compile this file      
22
// and link it with other works to produce a work based on this file,       
23
// this file does not by itself cause the resulting work to be covered by   
24
// the GNU General Public License. However the source code for this file    
25
// must still be made available in accordance with section (3) of the GNU   
26
// General Public License v2.                                               
27
//
28
// This exception does not invalidate any other reasons why a work based    
29
// on this file might be covered by the GNU General Public License.         
30
// -------------------------------------------                              
31
// ####ECOSGPLCOPYRIGHTEND####                                              
32
/*-------------------------------------------------------------------
33
*
34
* FILE: enetPHY.c
35
*
36
* DESCRIPTION:   GPIO Management Pins driver for the LXT970a
37
*
38
*
39
* Modified for the mpc8260 VADS board
40
*--------------------------------------------------------------------*/
41
#include "types.h"
42
#include <cyg/hal/hal_intr.h> /* HAL_DELAY_US */
43
#include "EnetPHY.h"
44
 
45
/* Internal functions */
46
void    MdioSend(UINT32, UINT16);
47
UINT16  MdioReceive(UINT16);
48
UINT16  MdioFrame(MDIORW, UINT16, UINT16, UINT32);
49
 
50
VUINT32 * pPortDir;
51
VUINT32 * pPortData;
52
 
53
/*-------------------------------------------------------------------
54
*
55
* FUNCTION NAME:
56
*
57
* DESCRIPTION:
58
*
59
* EXTERNAL EFFECT: Turns on the LXT970 transciever
60
*
61
* PARAMETERS:
62
*
63
* RETURNS: None
64
*
65
* ASSUMPTIONS:
66
*
67
*-------------------------------------------------------------------*/
68
void
69
EnableResetPHY(volatile t_BCSR *pBCSR)
70
{
71
#ifdef CYGPKG_HAL_POWERPC_TS6
72
#define ETH_RST_MASK 0x20
73
  /* The FPGA control register on the TS6 board uses the same memory
74
   * location as the BCSR register on the VADS board.
75
   */
76
  volatile cyg_uint32 *fpga_ctrl = (cyg_uint32 *) pBCSR;
77
  volatile cyg_uint32 *fpga_vers;
78
  cyg_uint32 value;
79
  fpga_vers = fpga_ctrl + 1;
80
  value = *fpga_vers;
81
  if(value >= 6){ /* version 06 of the FPGA added PHY reset control */
82
    value = *fpga_ctrl;
83
    /* Set the PHY reset bit */
84
    value |= ETH_RST_MASK;
85
    *fpga_vers = value;
86
 
87
    /* Give the PHY time to reset */
88
    HAL_DELAY_US(10000);
89
 
90
    /* Clear the reset bit */
91
    *fpga_vers = value & ~ETH_RST_MASK;
92
  }
93
#else
94
  // active low FETHIEN on BSCR1, assert reset low
95
  pBCSR->bcsr1 &= ~(FETHIEN_ | FETHRST_);
96
  // de-assert reset
97
  pBCSR->bcsr1 |= FETHRST_;
98
#endif
99
}
100
 
101
 
102
/*-------------------------------------------------------------------
103
*
104
* FUNCTION NAME:
105
*
106
* DESCRIPTION: Writes parameters to the control registers of LXT970
107
*
108
* EXTERNAL EFFECT:
109
*
110
* PARAMETERS:
111
*
112
* RETURNS: None
113
*
114
* ASSUMPTIONS:
115
*
116
*-------------------------------------------------------------------*/
117
UINT16
118
InitEthernetPHY(VUINT32* pdir, VUINT32* pdat, UINT16 link)
119
{
120
 
121
  VUINT16 FrameValue;
122
 
123
  /* 8101 Ethernet Management Pin Assignments */
124
  pPortDir = pdir;
125
  pPortData = pdat;
126
 
127
  (*pPortDir) |= MDC_PIN_MASK;   /* MD_Clock will always be output only */
128
 
129
  /* Test MDC & MDIO Pin Connection to PHY */
130
  MdioFrame(WRITE, 0, MIRROR_REG, MD_TEST_FRAME); //send test frame
131
  MdioFrame(WRITE, 0, MIRROR_REG, MD_TEST_FRAME); //send test frame
132
  FrameValue = MdioFrame(READ, 0, MIRROR_REG, 0); //read test frame
133
 
134
  if (FrameValue != MD_TEST_FRAME)
135
    return LINKERROR;   //test data integrity
136
 
137
  /* General Configuration */
138
  MdioFrame(WRITE, 0, CONFIG_REG, 0x0000);
139
 
140
  if(link == HUNDRED_HD)
141
      MdioFrame(WRITE, 0, AUTONEG_AD_REG, 0x0081); //100 Mbps Half, 802.3
142
  else
143
      MdioFrame(WRITE, 0, AUTONEG_AD_REG, 0x0021); //10  Mbps Half, 802.3
144
 
145
  // 100 Mbps full duplex not supported
146
  // MdioFrame(WRITE, 0, AUTONEG_AD_REG, 0x0101); //100 Mbps Full, 802.3
147
 
148
  MdioFrame(WRITE, 0, CONTROL_REG, 0x1300);
149
 
150
  return 0;
151
}
152
 
153
/*-------------------------------------------------------------------
154
*
155
* FUNCTION NAME:
156
*
157
* DESCRIPTION:
158
*
159
* EXTERNAL EFFECT:
160
*
161
* PARAMETERS:
162
*
163
* RETURNS: None
164
*
165
* ASSUMPTIONS:
166
*
167
*-------------------------------------------------------------------*/
168
UINT16
169
EthernetPHYInterruptHandler()
170
{
171
  // Reading registers 1 and 18 in sequence 
172
  // clears the transceiver interrupt
173
 
174
  MdioFrame(READ, 0, STATUS_REG, 0);
175
  MdioFrame(READ, 0, INT_STAT_REG, 0);
176
 
177
  return LinkTestPHY();
178
} /* end EthernetPHYInterruptHandler */
179
 
180
/*-------------------------------------------------------------------
181
*
182
* FUNCTION NAME:
183
*
184
* DESCRIPTION:
185
*
186
* EXTERNAL EFFECT:
187
*
188
* PARAMETERS:
189
*
190
* RETURNS: None
191
*
192
* ASSUMPTIONS:
193
*
194
*-------------------------------------------------------------------*/
195
UINT16
196
LinkTestPHY()
197
{
198
  UINT32 j;
199
  UINT16 FrameValue = 0;
200
 
201
  for (j = 0; j < 50; j++) {
202
 
203
    HAL_DELAY_US(100000);
204
 
205
    FrameValue = MdioFrame(READ,0,CHIP_STAT_REG,0);
206
 
207
    if ( (FrameValue & 0x0200) != 0 )
208
      break;
209
  }
210
 
211
  FrameValue &= 0x3800;
212
 
213
  switch (FrameValue) {
214
 
215
    case 0x3800: return HUNDRED_FD;
216
    case 0x2800: return HUNDRED_HD;
217
    case 0x3000: return TEN_FD;
218
    case 0x2000: return TEN_HD;
219
    default:     return NOTLINKED;
220
  }
221
 
222
}
223
 
224
/*-------------------------------------------------------------------
225
*
226
* FUNCTION NAME:
227
*
228
* DESCRIPTION:
229
*
230
* EXTERNAL EFFECT:
231
*
232
* PARAMETERS:
233
*
234
* RETURNS: None
235
*
236
* ASSUMPTIONS:
237
*
238
*-------------------------------------------------------------------*/
239
void EnablePHYinterrupt(UINT8 enable)
240
{
241
  MdioFrame(WRITE, 0, INT_EN_REG, enable?0x2:0x0);
242
}
243
 
244
/*----------------------------------------------------------------------
245
*
246
* FUNCTION NAME:
247
*
248
* DESCRIPTION: generic READ/WRITE function of LXT970
249
*              through the MDC/MDIO interface.
250
*
251
* EXTERNAL EFFECT:
252
*
253
* PARAMETERS:
254
*
255
* RETURNS: None
256
*
257
* ASSUMPTIONS:
258
*
259
*---------------------------------------------------------------------*/
260
UINT16
261
MdioFrame(MDIORW R_W, UINT16 PhyAddr, UINT16 RegAddr, UINT32 PutData) {
262
 
263
  UINT16 GetData;
264
 
265
  *pPortDir |= MDIO_PIN_MASK;   //set to output mode
266
 
267
  MdioSend(0xFFFFFFFF,32);      //PreAmble
268
  MdioSend(0x1,2);              //Start Frame Delimiter
269
  if (R_W==READ)
270
    MdioSend(0x2,2);            //Read OpCode
271
  else
272
    MdioSend(0x1,2);            //Write OpCode
273
 
274
  MdioSend(PhyAddr,5);         //Send PHY transciever Address
275
  MdioSend(RegAddr,5);         //Send Register Address
276
 
277
  if (R_W==READ) {
278
    *pPortDir &= ~MDIO_PIN_MASK;  //set to input mode
279
    GetData = MdioReceive(17);    //Drive TurnAround and Data
280
    MdioReceive(2);
281
  }
282
  else {
283
    MdioSend(0x2,2);              //Drive TurnAround
284
    MdioSend(PutData, 16);        //Send Data
285
    GetData = 0;
286
    *pPortDir &= ~MDIO_PIN_MASK;  //set to input mode
287
  }
288
 
289
  return GetData;
290
 
291
}
292
/*----------------------------------------------------------------------
293
*
294
* FUNCTION NAME:
295
*
296
* DESCRIPTION:  Shift out  bits of data
297
*
298
* EXTERNAL EFFECT:
299
*
300
* PARAMETERS:
301
*
302
* RETURNS: None
303
*
304
* ASSUMPTIONS:
305
*
306
*----------------------------------------------------------------------*/
307
void
308
MdioSend(UINT32 txF, UINT16 size) {
309
 
310
  UINT32 dmask;
311
  INT_NATIVE i, j;
312
 
313
  dmask = 1 << (size-1);            // msbit out first
314
 
315
  for (i = 0; i < size; i++) {      // for "size" bits
316
 
317
    if ( txF & dmask )              //output data bit high
318
      *pPortData |=  MDIO_PIN_MASK;
319
    else                            //output data bit low > 400ns
320
      *pPortData &= ~MDIO_PIN_MASK;
321
                                        // >10ns       
322
    *pPortData |= MDC_PIN_MASK;         // clock rise
323
 
324
    txF = (UINT32)(txF << 1);           // >160ns
325
 
326
    for (j=0; j<MDC_HOLD_TIME; j++);
327
 
328
    *pPortData &= ~MDC_PIN_MASK;        // clock fall 
329
 
330
    for (j=0; j<MDC_HOLD_TIME; j++);
331
 
332
  }
333
 
334
  return;
335
}
336
 
337
 
338
/*---------------------------------------------------------------------
339
*
340
* FUNCTION NAME:
341
*
342
* DESCRIPTION:  Shifts in bits of data
343
*
344
* EXTERNAL EFFECT:
345
*
346
* PARAMETERS:
347
*
348
* RETURNS:
349
*
350
* ASSUMPTIONS:
351
*
352
*---------------------------------------------------------------------*/
353
UINT16
354
MdioReceive(UINT16 size) {
355
 
356
  UINT16 i,j, rxF = 0;
357
 
358
  for (i = 0; i < size; i++) {    // 16 bits
359
 
360
    *pPortData |= MDC_PIN_MASK;            // clock rise
361
 
362
    if ( *pPortData & MDIO_PIN_MASK )             // if read in a high bit
363
      rxF = ( (UINT16)(rxF << 1) | 1 );           // shift in a one
364
    else                                          // if read in a low bit
365
      rxF = ( (UINT16)(rxF << 1) & ~(UINT16)1 );  // shift in a zero
366
 
367
 
368
    for (j=0; j<MDC_HOLD_TIME; j++);
369
 
370
    *pPortData &= ~MDC_PIN_MASK;          // clock fall         
371
 
372
    for (j=0; j<MDC_HOLD_TIME; j++);
373
 
374
  }
375
 
376
  return rxF;
377
}
378
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.