1 /* $NetBSD: dp83905.c,v 1.3 2005/12/11 12:21:26 christos Exp $ */
4 * Copyright (c) 2001 Ben Harris
5 * Copyright (c) 1998 Mike Pumford
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/param.h>
38 __KERNEL_RCSID(0, "$NetBSD: dp83905.c,v 1.3 2005/12/11 12:21:26 christos Exp $");
40 #include <sys/device.h>
42 #include <sys/socket.h>
43 #include <sys/systm.h>
46 #include <net/if_ether.h>
47 #include <net/if_media.h>
51 #include <dev/ic/dp8390reg.h>
52 #include <dev/ic/dp8390var.h>
54 #include <dev/ic/dp83905reg.h>
55 #include <dev/ic/dp83905var.h>
58 dp83905_mediachange(struct dp8390_softc
*sc
)
61 /* Media already set up. Reset the interface to make it stick. */
67 dp83905_mediastatus(struct dp8390_softc
*sc
, struct ifmediareq
*ifmr
)
69 bus_space_tag_t nict
= sc
->sc_regt
;
70 bus_space_handle_t nich
= sc
->sc_regh
;
73 bus_space_write_1(nict
, nich
, ED_P0_CR
,
74 ED_CR_RD2
| ED_CR_PAGE_0
| ED_CR_STA
);
75 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
76 /* Random op so next RBCR1 write doesn't go to MCRB. */
77 bus_space_write_1(nict
, nich
, ED_P0_CR
,
78 ED_CR_RD2
| ED_CR_PAGE_0
| ED_CR_STA
);
79 switch (mcrb
& DP83905_MCRB_PHY_MASK
) {
80 case DP83905_MCRB_PHY_10_T
:
81 case DP83905_MCRB_PHY_TPI_NONSPEC
: /* XXX */
82 ifmr
->ifm_active
= IFM_ETHER
| IFM_10_T
;
83 ifmr
->ifm_status
= IFM_AVALID
;
84 if (mcrb
& DP83905_MCRB_GDLNK
)
85 ifmr
->ifm_status
|= IFM_ACTIVE
;
87 case DP83905_MCRB_PHY_10_2
:
88 ifmr
->ifm_active
= IFM_ETHER
| IFM_10_2
;
90 case DP83905_MCRB_PHY_AUI
:
91 ifmr
->ifm_active
= IFM_ETHER
| IFM_10_5
;
96 void dp83905_init_card(struct dp8390_softc
*sc
)
98 struct ifmedia
*ifm
= &sc
->sc_media
;
99 bus_space_tag_t nict
= sc
->sc_regt
;
100 bus_space_handle_t nich
= sc
->sc_regh
;
103 /* Set basic media type. */
104 switch (IFM_SUBTYPE(ifm
->ifm_cur
->ifm_media
)) {
106 /* software auto detect the media */
107 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
108 mcrb
&= ~(DP83905_MCRB_PHY_MASK
| DP83905_MCRB_GDLNK
|
110 mcrb
|= DP83905_MCRB_PHY_10_T
;
111 bus_space_write_1(nict
, nich
, DP83905_MCRB
, mcrb
);
112 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
113 if (mcrb
& DP83905_MCRB_GDLNK
)
119 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
120 mcrb
&= ~(DP83905_MCRB_PHY_MASK
| DP83905_MCRB_GDLNK
|
122 mcrb
|= DP83905_MCRB_PHY_10_2
;
123 bus_space_write_1(nict
, nich
, DP83905_MCRB
, mcrb
);
125 * seems that re-reading config B here is required to
126 * prevent the interface hanging when manually selecting.
128 bus_space_read_1(nict
, nich
, DP83905_MCRB
);
132 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
133 mcrb
&= ~(DP83905_MCRB_PHY_MASK
| DP83905_MCRB_GDLNK
|
135 mcrb
|= DP83905_MCRB_PHY_10_T
;
136 bus_space_write_1(nict
, nich
, DP83905_MCRB
, mcrb
);
138 * seems that re-reading config B here is required to
139 * prevent the interface hanging when manually selecting.
141 bus_space_read_1(nict
, nich
, DP83905_MCRB
);
145 mcrb
= bus_space_read_1(nict
, nich
, DP83905_MCRB
);
146 mcrb
&= ~(DP83905_MCRB_PHY_MASK
| DP83905_MCRB_GDLNK
|
148 mcrb
|= DP83905_MCRB_PHY_AUI
;
149 bus_space_write_1(nict
, nich
, DP83905_MCRB
, mcrb
);
151 * seems that re-reading config B here is required to
152 * prevent the interface hanging when manually selecting.
154 bus_space_read_1(nict
, nich
, DP83905_MCRB
);