annotate packages/devs/eth/phy/current/src/DM9161A.c @ 2367:6f59b6d486cd

* cdl/phy_eth_drivers.cdl: * src/DM9161A.c: Add support for Davicom 9161A.
author asl
date Wed, 28 Feb 2007 23:08:33 +0000
parents
children 74dbf4c3f2e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2367
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
1 //==========================================================================
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
2 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
3 // dev/DM9161A.c
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
4 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
5 // Ethernet transceiver (PHY) support
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
6 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
7 //==========================================================================
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
9 // -------------------------------------------
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
11 // Copyright (C) 2003 Gary Thomas
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
12 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later version.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
16 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
20 // for more details.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
21 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
22 // You should have received a copy of the GNU General Public License along
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
25 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
26 // As a special exception, if other files instantiate templates or use macros
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
27 // or inline functions from this file, or you compile this file and link it
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
28 // with other works to produce a work based on this file, this file does not
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
29 // by itself cause the resulting work to be covered by the GNU General Public
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
30 // License. However the source code for this file must still be made available
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
31 // in accordance with section (3) of the GNU General Public License.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
32 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
33 // This exception does not invalidate any other reasons why a work based on
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
34 // this file might be covered by the GNU General Public License.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
35 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
37 // at http://sources.redhat.com/ecos/ecos-license/
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
38 // -------------------------------------------
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
40 //==========================================================================
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
42 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
43 // Author(s): John Eigelaar
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
44 // Contributors: Gary Thomas
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
45 // Date: 2006-12-07
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
46 // Purpose:
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
47 // Description: Support for Davicom DM9161A PHY
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
48 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
49 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
50 //####DESCRIPTIONEND####
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
51 //
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
52 //==========================================================================
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
53
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
54 #include <pkgconf/system.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
55 #include <pkgconf/devs_eth_phy.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
56
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
57 #include <cyg/infra/cyg_type.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
58
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
59 #include <cyg/hal/hal_arch.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
60 #include <cyg/hal/drv_api.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
61 #include <cyg/hal/hal_if.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
62 #include <cyg/hal/hal_tables.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
63
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
64 #include <cyg/io/eth_phy.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
65 #include <cyg/io/eth_phy_dev.h>
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
66
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
67 #define DM9161A_BMSR 0x01
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
68 #define DM9161A_BMSR_ANEG_COMP (1<<5)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
69 #define DM9161A_BMSR_LINK (1<<2)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
70
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
71 #define DM9161A_BMCR 0x00
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
72
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
73 #define DM9161A_DSCSR 17
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
74 #define DM9161A_DSCSR_100FDX (1<<15)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
75 #define DM9161A_DSCSR_100HDX (1<<14)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
76 #define DM9161A_DSCSR_10FDX (1<<13)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
77 #define DM9161A_DSCSR_10HDX (1<<12)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
78
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
79 static bool dm9161a_stat(eth_phy_access_t *f, int *state)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
80 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
81 unsigned short phy_state;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
82 int tries;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
83
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
84 *state = 0;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
85 // Read negotiated state
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
86
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
87 if (_eth_phy_read(f, DM9161A_BMSR, f->phy_addr, &phy_state))
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
88 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
89 if ((phy_state & DM9161A_BMSR_ANEG_COMP) == 0)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
90 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
91 eth_phy_printf("... waiting for auto-negotiation");
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
92 for (tries = 0; tries < CYGINT_DEVS_ETH_PHY_AUTO_NEGOTIATION_TIME;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
93 tries++)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
94 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
95 if (_eth_phy_read(f, DM9161A_BMSR, f->phy_addr, &phy_state))
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
96 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
97 if ((phy_state & DM9161A_BMSR_ANEG_COMP) != 0)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
98 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
99 break;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
100 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
101 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
102 CYGACC_CALL_IF_DELAY_US(1000000); // 1 second
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
103 eth_phy_printf(".");
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
104 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
105 eth_phy_printf("\n");
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
106 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
107 if ((phy_state & DM9161A_BMSR_ANEG_COMP) != 0)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
108 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
109 *state = 0;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
110 if (!_eth_phy_read(f, DM9161A_DSCSR, f->phy_addr, &phy_state))
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
111 return false;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
112
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
113 if (phy_state & 0xF000)
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
114 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
115 *state |= ETH_PHY_STAT_LINK;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
116 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
117 if ((phy_state & DM9161A_DSCSR_100FDX) ||
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
118 (phy_state & DM9161A_DSCSR_100HDX))
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
119 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
120 *state |= ETH_PHY_STAT_100MB;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
121 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
122 if ((phy_state & DM9161A_DSCSR_100FDX) ||
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
123 (phy_state & DM9161A_DSCSR_10FDX))
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
124 {
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
125 *state |= ETH_PHY_STAT_FDX;
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
126 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
127
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
128 return (true);
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
129 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
130 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
131 return (false);
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
132 }
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
133
6f59b6d486cd * cdl/phy_eth_drivers.cdl:
asl
parents:
diff changeset
134 _eth_phy_dev("Davicom DM9161A", 0x0181B8A0, dm9161a_stat)