1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// phy/VSC8641.c
|
4 |
|
|
//
|
5 |
|
|
// Ethernet PHY driver
|
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, 2003, 2004, 2005, 2006, 2007,
|
12 |
|
|
// 2008, 2009 Free Software Foundation, Inc.
|
13 |
|
|
//
|
14 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
15 |
|
|
// the terms of the GNU General Public License as published by the Free
|
16 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
17 |
|
|
// version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
20 |
|
|
// ANY 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
|
25 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use
|
29 |
|
|
// macros or inline functions from this file, or you compile this file
|
30 |
|
|
// and link it with other works to produce a work based on this file,
|
31 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
32 |
|
|
// the GNU General Public License. However the source code for this file
|
33 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
34 |
|
|
// General Public License v2.
|
35 |
|
|
//
|
36 |
|
|
// This exception does not invalidate any other reasons why a work based
|
37 |
|
|
// on this file might be covered by the GNU General Public License.
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): Sachin Sushil Chaddha
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 2009-11-01
|
46 |
|
|
// Purpose:
|
47 |
|
|
// Description: Hardware driver for Ethernet PHY Vitesse VSC8641
|
48 |
|
|
//
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/system.h>
|
55 |
|
|
#include <pkgconf/devs_eth_phy.h>
|
56 |
|
|
|
57 |
|
|
#include <cyg/infra/cyg_type.h>
|
58 |
|
|
|
59 |
|
|
#include <cyg/hal/hal_arch.h>
|
60 |
|
|
#include <cyg/hal/drv_api.h>
|
61 |
|
|
#include <cyg/hal/hal_if.h>
|
62 |
|
|
#include <cyg/hal/hal_tables.h>
|
63 |
|
|
|
64 |
|
|
#include <cyg/io/eth_phy.h>
|
65 |
|
|
#include <cyg/io/eth_phy_dev.h>
|
66 |
|
|
|
67 |
|
|
#include "VSC8641.h"
|
68 |
|
|
|
69 |
|
|
static bool VSC8641_stat(eth_phy_access_t *f, int *state)
|
70 |
|
|
{
|
71 |
|
|
unsigned short phy_state;
|
72 |
|
|
int tries;
|
73 |
|
|
int auto_completed = 1;
|
74 |
|
|
int link_up = 0;
|
75 |
|
|
|
76 |
|
|
// Read negotiated state from the Quick Poll Detailed Status Register
|
77 |
|
|
if (_eth_phy_read(f, VSC8641_MII_STAT_REG, f->phy_addr, &phy_state))
|
78 |
|
|
{
|
79 |
|
|
|
80 |
|
|
if ((phy_state & VSC8641_AUTO_COMPLETED) == 0)
|
81 |
|
|
{
|
82 |
|
|
auto_completed = 0;
|
83 |
|
|
eth_phy_printf("... waiting for auto-negotiation");
|
84 |
|
|
for (tries = 0; tries < CYGINT_DEVS_ETH_PHY_AUTO_NEGOTIATION_TIME; tries++)
|
85 |
|
|
{
|
86 |
|
|
if (_eth_phy_read(f, VSC8641_MII_STAT_REG, f->phy_addr, &phy_state))
|
87 |
|
|
{
|
88 |
|
|
if ((phy_state & VSC8641_AUTO_COMPLETED) != 0)
|
89 |
|
|
{
|
90 |
|
|
auto_completed = 1;
|
91 |
|
|
break;
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
CYGACC_CALL_IF_DELAY_US(1000000); // 1 second
|
95 |
|
|
eth_phy_printf(".");
|
96 |
|
|
}
|
97 |
|
|
eth_phy_printf("\n");
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
if(phy_state & VSC8641_MII_PHY_STAT_LINK_UP)
|
101 |
|
|
link_up = 1;
|
102 |
|
|
|
103 |
|
|
if(auto_completed)
|
104 |
|
|
{
|
105 |
|
|
_eth_phy_read(f, VSC8641_MII_PHY_STAT_REG, f->phy_addr, &phy_state);
|
106 |
|
|
|
107 |
|
|
if(link_up)
|
108 |
|
|
*state |= ETH_PHY_STAT_LINK;
|
109 |
|
|
if(phy_state & VSC8641_MII_PHY_STAT_1000MB )
|
110 |
|
|
*state |= ETH_PHY_STAT_1000MB;
|
111 |
|
|
if(phy_state & VSC8641_MII_PHY_STAT_100MB)
|
112 |
|
|
*state |= ETH_PHY_STAT_100MB;
|
113 |
|
|
if(phy_state & VSC8641_MII_PHY_STAT_DUPLEX_FULL)
|
114 |
|
|
*state |= ETH_PHY_STAT_FDX;
|
115 |
|
|
return true;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
}
|
119 |
|
|
return false;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
_eth_phy_dev("Vitesse VSC8641", 0x00070431, VSC8641_stat)
|