1 |
27 |
unneback |
#ifndef CYGONCE_DEVS_ETH_PHYTER_PHYTER_INL
|
2 |
|
|
#define CYGONCE_DEVS_ETH_PHYTER_PHYTER_INL
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// phyther.inl
|
6 |
|
|
//
|
7 |
|
|
// Generic Phyter definitions and helpers
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//==========================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): jskov
|
46 |
|
|
// Contributors: jskov
|
47 |
|
|
// Date: 2002-02-19
|
48 |
|
|
// Purpose: phy/MII definitions
|
49 |
|
|
// Description:
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//
|
53 |
|
|
//==========================================================================
|
54 |
|
|
|
55 |
|
|
// Caller must define _MII_WRITE and _MII_READ macros
|
56 |
|
|
#ifndef _MII_WRITE
|
57 |
|
|
# error "_MII_WRITE(_priv_, _id_, _reg_, _val_) and _MII_READ(_priv_, _id_, _reg_) must be defined"
|
58 |
|
|
#endif
|
59 |
|
|
|
60 |
|
|
// Caller can define _MII_HAS_EXTENDED to add support for extended registers
|
61 |
|
|
|
62 |
|
|
//-----------------------------------------------------------------------------
|
63 |
|
|
// Helpers
|
64 |
|
|
|
65 |
|
|
// Renegotiate link
|
66 |
|
|
// This function will delay for up to 2 seconds waiting for a renegotiation
|
67 |
|
|
// of the link.
|
68 |
|
|
#define _MII_RENEGOTIATE(_priv_, _id_) \
|
69 |
|
|
CYG_MACRO_START \
|
70 |
|
|
_MII_WRITE(_priv_, _id_, CYGARC_REG_MII_BMCR, CYGARC_REG_MII_BMCR_RENEGOTIATE); \
|
71 |
|
|
_MII_RENEGOTIATION_WAIT(_priv_, _id_); \
|
72 |
|
|
CYG_MACRO_END
|
73 |
|
|
|
74 |
|
|
// Wait for renegotiation to complete
|
75 |
|
|
// This function will delay for up to 2 seconds waiting for a renegotiation
|
76 |
|
|
// of the link.
|
77 |
|
|
#define _MII_RENEGOTIATION_WAIT(_priv_, _id_) \
|
78 |
|
|
CYG_MACRO_START \
|
79 |
|
|
int _i; \
|
80 |
|
|
cyg_uint16 _r; \
|
81 |
|
|
for (_i = 0; _i < 2000; _i++) { \
|
82 |
|
|
HAL_DELAY_US(1000); \
|
83 |
|
|
_r = _MII_READ(_priv_, _id_, CYGARC_REG_MII_BMSR); \
|
84 |
|
|
if (_r & CYGARC_REG_MII_BMSR_AN_COMPLETE) break; \
|
85 |
|
|
} \
|
86 |
|
|
CYG_MACRO_END
|
87 |
|
|
|
88 |
|
|
// Link state query
|
89 |
|
|
#define _MII_LINK_STATE(_priv_, _id_) \
|
90 |
|
|
({ int _i; \
|
91 |
|
|
if (_MII_READ(_priv_, _id_, CYGARC_REG_MII_BMSR) & CYGARC_REG_MII_BMSR_LINK) \
|
92 |
|
|
(_i) = 1; \
|
93 |
|
|
else \
|
94 |
|
|
(_i) = 0; \
|
95 |
|
|
_i; })
|
96 |
|
|
|
97 |
|
|
// Clear 100MB capability advertisement bits
|
98 |
|
|
// Caller has to start a new renegoatiation
|
99 |
|
|
#define _MII_SPEED_FORCE_10MB(_priv_, _id_) \
|
100 |
|
|
CYG_MACRO_START \
|
101 |
|
|
cyg_uint16 _d; \
|
102 |
|
|
_d = _MII_READ(_priv_, _id_, CYGARC_REG_MII_ANAR); \
|
103 |
|
|
_d &= ~(CYGARC_REG_MII_ANAR_T4|CYGARC_REG_MII_ANAR_TX_FD|CYGARC_REG_MII_ANAR_TX); \
|
104 |
|
|
_MII_WRITE(_priv_, _id_, CYGARC_REG_MII_ANAR, _d); \
|
105 |
|
|
CYG_MACRO_END
|
106 |
|
|
|
107 |
|
|
#ifdef _MII_HAS_EXTENDED
|
108 |
|
|
|
109 |
|
|
// Speed state query
|
110 |
|
|
// 0 = 10Mb, 1 = 100Mb
|
111 |
|
|
#define _MII_SPEED_STATE(_priv_, _id_) \
|
112 |
|
|
({ int _i; \
|
113 |
|
|
if (_MII_READ(_priv_, _id_, CYGARC_REG_MII_PHYSTS) & CYGARC_REG_MII_PHYSTS_SPEED) \
|
114 |
|
|
(_i) = 0; \
|
115 |
|
|
else \
|
116 |
|
|
(_i) = 1; \
|
117 |
|
|
_i; })
|
118 |
|
|
|
119 |
|
|
// Duplex state query
|
120 |
|
|
// 0 = simplex, 1 = duplex
|
121 |
|
|
#define _MII_DUPLEX_STATE(_priv_, _id_) \
|
122 |
|
|
({ int _i; \
|
123 |
|
|
if (_MII_READ(_priv_, _id_, CYGARC_REG_MII_PHYSTS) & CYGARC_REG_MII_PHYSTS_DUPLEX) \
|
124 |
|
|
(_i) = 1; \
|
125 |
|
|
else \
|
126 |
|
|
(_i) = 0; \
|
127 |
|
|
_i; })
|
128 |
|
|
|
129 |
|
|
#endif // _MII_HAS_EXTENDED
|
130 |
|
|
|
131 |
|
|
// Dump registers
|
132 |
|
|
// Useful for debugging
|
133 |
|
|
#define _MII_DUMP_REGS(_priv_, _id_) \
|
134 |
|
|
CYG_MACRO_START \
|
135 |
|
|
int _i; \
|
136 |
|
|
diag_printf("PHY registers:\n"); \
|
137 |
|
|
for(_i = 0; _i <= CYGARC_REG_MII_LAST; _i++) \
|
138 |
|
|
diag_printf(" %02d %04x\n", _i, _MII_READ(_priv_, _id_, _i)); \
|
139 |
|
|
CYG_MACRO_END
|
140 |
|
|
|
141 |
|
|
//-----------------------------------------------------------------------------
|
142 |
|
|
// Phyter Registers
|
143 |
|
|
|
144 |
|
|
// Generic
|
145 |
|
|
#define CYGARC_REG_MII_BMCR 0x00
|
146 |
|
|
#define CYGARC_REG_MII_BMSR 0x01
|
147 |
|
|
#define CYGARC_REG_MII_PHYIDR1 0x02
|
148 |
|
|
#define CYGARC_REG_MII_PHYIDR2 0x03
|
149 |
|
|
#define CYGARC_REG_MII_ANAR 0x04
|
150 |
|
|
#define CYGARC_REG_MII_ANLPAR 0x05
|
151 |
|
|
#define CYGARC_REG_MII_ANER 0x06
|
152 |
|
|
#define CYGARC_REG_MII_ANNPTR 0x07
|
153 |
|
|
|
154 |
|
|
#define CYGARC_REG_MII_BMCR_RESET 0x8000
|
155 |
|
|
#define CYGARC_REG_MII_BMCR_LOOPBACK 0x4000
|
156 |
|
|
#define CYGARC_REG_MII_BMCR_RENEGOTIATE 0x3300
|
157 |
|
|
|
158 |
|
|
#define CYGARC_REG_MII_BMSR_AN_COMPLETE 0x0020
|
159 |
|
|
#define CYGARC_REG_MII_BMSR_LINK 0x0004
|
160 |
|
|
|
161 |
|
|
#define CYGARC_REG_MII_ANAR_T4 0x0200
|
162 |
|
|
#define CYGARC_REG_MII_ANAR_TX_FD 0x0100
|
163 |
|
|
#define CYGARC_REG_MII_ANAR_TX 0x0080
|
164 |
|
|
#define CYGARC_REG_MII_ANAR_10_FD 0x0040
|
165 |
|
|
#define CYGARC_REG_MII_ANAR_10 0x0020
|
166 |
|
|
|
167 |
|
|
// Extended registers
|
168 |
|
|
#ifndef _MII_HAS_EXTENDED
|
169 |
|
|
# define CYGARC_REG_MII_LAST 0x0f
|
170 |
|
|
#else
|
171 |
|
|
# define CYGARC_REG_MII_PHYSTS 0x10
|
172 |
|
|
# define CYGARC_REG_MII_FCSCR 0x14
|
173 |
|
|
# define CYGARC_REG_MII_RECR 0x15
|
174 |
|
|
# define CYGARC_REG_MII_PCSR 0x16
|
175 |
|
|
# define CYGARC_REG_MII_PHYCTRL 0x19
|
176 |
|
|
# define CYGARC_REG_MII_10BTSCR 0x1a
|
177 |
|
|
# define CYGARC_REG_MII_CDCTRL 0x1b
|
178 |
|
|
# define CYGARC_REG_MII_LAST 0x1f
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
# define CYGARC_REG_MII_PHYSTS_SPEED 0x00000002
|
182 |
|
|
# define CYGARC_REG_MII_PHYSTS_DUPLEX 0x00000004
|
183 |
|
|
|
184 |
|
|
#endif
|
185 |
|
|
|
186 |
|
|
#endif // CYGONCE_DEVS_ETH_PHYTER_PHYTER_INL
|