]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/devs/eth/arm/netarm/v2_0/src/MII.c
6701f64649db0bcf16e45c5fcc51e06c7d82e7b9
[karo-tx-redboot.git] / packages / devs / eth / arm / netarm / v2_0 / src / MII.c
1 //==========================================================================
2 //
3 //      MII.c
4 //
5 //      NetSilion NET+ARM PHY chip configuration
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2005 eCosCentric LTD
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 version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //==========================================================================
36 //#####DESCRIPTIONBEGIN####
37 //
38 // Author(s):           Harald Brandl (harald.brandl@fh-joanneum.at)
39 // Contributors:        Harald Brandl
40 // Date:                01.08.2004
41 // Purpose:             PHY chip configuration
42 // Description:
43 //
44 //####DESCRIPTIONEND####
45 //
46 //==========================================================================
47
48 #include <stdio.h>
49 #include <pkgconf/devs_eth_arm_netarm.h>
50 #include <cyg/hal/hal_diag.h>
51 #include <cyg/hal/hal_io.h>
52 #include "eth_regs.h"
53
54 #define PHYS(_i_) (0x800 | _i_)
55
56 #define SysReg (unsigned int*)0xffb00004        // System Status Register
57
58 /*  Function: void mii_poll_busy (void)
59  *
60  *  Description:
61  *     This routine is responsible for waiting for the current PHY
62  *     operation to complete.
63  *
64  *  Parameters:
65  *     none
66  */
67
68 void mii_poll_busy(void)
69 {
70   /* check to see if PHY is busy with read or write */
71   while (MIIIR & 1)
72     HAL_DELAY_US(1);
73 }
74
75 /*  Function: void mii_reset (void)
76  *
77  *  Description:
78  *
79  *       This routine resets the PHY.
80  *
81  *  Return Values:
82  *      none
83  */
84
85 void mii_reset(void)
86 {
87   MIIAR = PHYS(0);      // select command register
88   MIIWDR = 0x8000;      // reset
89   mii_poll_busy();
90 }
91
92 /*  Function: cyg_bool mii_negotiate (void)
93  *
94  *  Description:
95  *     This routine is responsible for causing the external Ethernet PHY
96  *     to begin the negotatiation process.
97  *
98  *  Parameters:
99  *     none
100  *
101  *  Return Value:
102  *     0: SUCCESS
103  *     1: ERROR
104  */
105
106 cyg_bool mii_negotiate(void)
107 {
108   int timeout = 100000;
109   
110   MIIAR = PHYS(4);
111   
112   mii_poll_busy();
113   
114   MIIAR = PHYS(0);
115   MIIWDR |= 0x1200;
116   
117   mii_poll_busy();
118   
119   while(timeout)
120     {
121       MIIAR = PHYS(1);
122       MIICR = 1;
123       
124       mii_poll_busy();
125       
126       if(0x24 == (MIIRDR & 0x24))
127         return 0;
128       else
129         timeout--;
130     }
131   
132   return 1;
133 }
134
135
136 /*  Function: void mii_set_speed (cyg_bool speed, cyg_bool duplex)
137  *
138  *  Description:
139  *
140  *       This routine will set the speed and duplex of the external PHY.
141  *
142  *  Parameters:
143  *      Speed
144  *        0: 10Mbit
145  *        1: 100Mbit
146  *      Duplex
147  *        0: Half
148  *        1: Full
149  *
150  *  Return Values:
151  *      none
152  */
153
154 void mii_set_speed(cyg_bool speed, cyg_bool duplex)
155 {
156   unsigned long int timeout = 1000000;
157   
158   MIIAR = PHYS(0);      // select command register
159   MIIWDR = (speed << 13) | (duplex << 8);       // set speed and duplex
160   mii_poll_busy();
161   
162   
163   while(timeout)
164     {
165       MIIAR = PHYS(1);  // select status register
166       MIICR = 1;
167       mii_poll_busy();
168       if((MIIRDR) & 0x4)
169         break;
170       timeout--;
171     }
172 }
173
174 /*  Function: cyg_bool mii_check_speed
175  *
176  *  Description:
177  *
178  *       This routine will check the operating speed of the ethernet
179  *       interface.
180  *
181  *  Parameters:
182  *      none
183  *
184  *  Return Values:
185  *      0: 10Mbit Speed
186  *      1: 100Mbit Speed
187  */
188
189 cyg_bool mii_check_speed(void)
190 {
191   MIIAR = PHYS(17);
192   MIICR = 1;
193   mii_poll_busy();
194   return (MIIRDR >> 14) & 1;
195 }
196
197 /*  Function: void mii_check_duplex
198  *
199  *  Description:
200  *
201  *       This routine will check the operating duplex of the ethernet
202  *       interface.
203  *
204  *  Parameters:
205  *      none
206  *
207  *  Return Values:
208  *      0: Half Duplex
209  *      1: Full Duplex
210  */
211
212 cyg_bool mii_check_duplex(void)
213 {
214   MIIAR = PHYS(17);
215   MIICR = 1;
216   mii_poll_busy();
217   return (MIIRDR >> 9) & 1;
218 }