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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [arm/] [ks32c5000/] [current/] [src/] [lxt970.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      lxt970.c
4
//
5
//      Driver for LXT970 PHY
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas, jskov
44
//               Grant Edwards <grante@visi.com>
45
// Date:         2001-07-31
46
// Purpose:      
47
// Description:  
48
//
49
//####DESCRIPTIONEND####
50
//
51
//========================================================================*/
52
 
53
#include "std.h"
54
#include "phy.h"
55
 
56
// address of the LX970 phy
57
#ifdef CYGPKG_DEVS_ETH_ARM_KS32C5000_PHYADDR
58
#define LX970_ADDR  CYGPKG_DEVS_ETH_ARM_KS32C5000_PHYADDR
59
#else
60
#define LX970_ADDR  1
61
#endif
62
 
63
// LX970 register offsets
64
#define LX970_CNTL_REG          0x00
65
#define LX970_STATUS_REG        0x01
66
#define LX970_ID_REG1           0x02
67
#define LX970_ID_REG2           0x03
68
#define LX970_ANA_REG           0x04
69
#define LX970_ANLPAR_REG        0x05
70
#define LX970_ANE_REG           0x06
71
#define LX970_MIRROR_REG        0x10
72
#define LX970_INTEN_REG         0x11
73
#define LX970_INTSTAT_REG       0x12
74
#define LX970_CONFIG_REG        0x13
75
#define LX970_CHIPSTAT_REG      0x14
76
 
77
// LX970 Control register bit defines
78
#define LX970_CNTL_RESET        0x8000
79
#define LX970_CNTL_LOOPBACK     0x4000
80
#define LX970_CNTL_SPEED        0x2000  // 1=100Meg, 0=10Meg
81
#define LX970_CNTL_AN           0x1000  // 1=Enable auto negotiation, 0=disable it
82
#define LX970_CNTL_PWRDN        0x0800  // 1=Enable power down
83
#define LX970_CNTL_ISOLATE      0x0400  // 1=Isolate from MII
84
#define LX970_CNTL_RSTRT_AN     0x0200  // 1=Restart Auto Negotioation process
85
#define LX970_CNTL_FULL_DUP     0x0100  // 1=Enable full duplex mode, 0=half dup
86
#define LX970_CNTL_TST_COLL     0x0080  // 1=Enable collision test
87
 
88
#define Bit(n) (1<<(n))
89
 
90
#define LX970_ANA_PAUSE_ENA    Bit(10)
91
#define LX970_ANA_100T4        Bit(9)
92
#define LX970_ANA_100TX_FULL   Bit(8)
93
#define LX970_ANA_100TX        Bit(7)
94
#define LX970_ANA_10T_FULL     Bit(6)
95
#define LX970_ANA_10T          Bit(5)
96
#define LX970_ANA_SEL_802_3    Bit(0)
97
 
98
#define LX970_CHIPSTAT_LINKUP    Bit(13)
99
#define LX970_CHIPSTAT_FULLDUP   Bit(12)
100
#define LX970_CHIPSTAT_100M      Bit(11)
101
#define LX970_CHIPSTAT_ANEG_DONE Bit(9)
102
#define LX970_CHIPSTAT_PAGE_RX   Bit(8)
103
#define LX970_CHIPSTAT_LOWVOLT   Bit(2)
104
 
105
// phy functions for Level1 PHY LXT970
106
 
107
void PhyReset(void)
108
{
109
    // first software reset the LX970      
110
    MiiStationWrite(LX970_CNTL_REG, LX970_ADDR, LX970_CNTL_RESET);
111
    MiiStationWrite(LX970_CNTL_REG, LX970_ADDR, 0);
112
 
113
    // set low level drive for MII lines, enable interrupt output
114
    MiiStationWrite(17, LX970_ADDR, BIT3+BIT1);
115
 
116
    // default values for 100M encryption are wrong, so fix them
117
    // and configure LEDC to be activity indicator
118
     MiiStationWrite(19, LX970_ADDR, BIT7);
119
 
120
    // initialize auto-negotiation capabilities
121
    MiiStationWrite(LX970_ANA_REG,LX970_ADDR,
122
                    LX970_ANA_PAUSE_ENA+
123
                    LX970_ANA_100T4+
124
                    LX970_ANA_100TX_FULL+
125
                    LX970_ANA_100TX+
126
                    LX970_ANA_10T_FULL+
127
                    LX970_ANA_10T+
128
                    LX970_ANA_SEL_802_3);
129
#if 1
130
    // Now start an auto negotiation
131
    MiiStationWrite(LX970_CNTL_REG, LX970_ADDR,
132
                    LX970_CNTL_AN+
133
                    LX970_CNTL_RSTRT_AN);
134
#else
135
    // force to 10M full duplex
136
    MiiStationWrite(LX970_CNTL_REG, LX970_ADDR,
137
                    LX970_CNTL_FULL_DUP);
138
#endif
139
}
140
 
141
unsigned PhyStatus(void)
142
{
143
  unsigned lxt970Status = MiiStationRead(LX970_CHIPSTAT_REG,LX970_ADDR);
144
  unsigned r = 0;
145
  if (lxt970Status & LX970_CHIPSTAT_LINKUP)
146
    r |= PhyStatus_LinkUp;
147
  if (lxt970Status & LX970_CHIPSTAT_FULLDUP)
148
    r |= PhyStatus_FullDuplex;
149
  if (lxt970Status & LX970_CHIPSTAT_100M)
150
    r |=  PhyStatus_100Mb;
151
  return r;
152
}
153
 
154
void PhyInterruptAck(void)
155
{
156
  MiiStationRead(1,LX970_ADDR);
157
  MiiStationRead(18,LX970_ADDR);
158
}
159
 
160
// EOF lxt970.c

powered by: WebSVN 2.1.0

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