nsphy.c revision 1.3 1 1.3 thorpej /* $NetBSD: nsphy.c,v 1.3 1998/01/12 09:28:53 thorpej Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.1 bouyer * must display the following acknowledgement:
16 1.2 thorpej * This product includes software developed by Manuel Bouyer.
17 1.1 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.1 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer */
31 1.1 bouyer
32 1.1 bouyer /*
33 1.1 bouyer * driver for National Semiconductor's DP83840A ethernet 10/100 PHY
34 1.1 bouyer * Data Sheet available from www.national.com
35 1.1 bouyer */
36 1.1 bouyer
37 1.1 bouyer #include <sys/param.h>
38 1.1 bouyer #include <sys/systm.h>
39 1.1 bouyer #include <sys/kernel.h>
40 1.1 bouyer #include <sys/device.h>
41 1.1 bouyer #include <sys/malloc.h>
42 1.1 bouyer #include <sys/proc.h>
43 1.1 bouyer #include <sys/socket.h>
44 1.1 bouyer #include <net/if.h>
45 1.1 bouyer #include <net/if_media.h>
46 1.1 bouyer
47 1.1 bouyer
48 1.1 bouyer #include <dev/mii/mii_adapter.h>
49 1.1 bouyer #include <dev/mii/mii_adapters_id.h>
50 1.1 bouyer #include <dev/mii/mii_phy.h>
51 1.1 bouyer #include <dev/mii/generic_phy.h>
52 1.1 bouyer
53 1.2 thorpej void nsphy_pdown __P((void *v));
54 1.2 thorpej int nsphy_media_set __P((int, void *));
55 1.1 bouyer
56 1.1 bouyer #ifdef __BROKEN_INDIRECT_CONFIG
57 1.2 thorpej int nsphymatch __P((struct device *, void *, void *));
58 1.1 bouyer #else
59 1.2 thorpej int nsphymatch __P((struct device *, struct cfdata *, void *));
60 1.1 bouyer #endif
61 1.2 thorpej void nsphyattach __P((struct device *, struct device *, void *));
62 1.1 bouyer
63 1.1 bouyer struct cfattach nsphy_ca = {
64 1.1 bouyer sizeof(struct phy_softc), nsphymatch, nsphyattach
65 1.1 bouyer };
66 1.1 bouyer
67 1.1 bouyer int
68 1.1 bouyer nsphymatch(parent, match, aux)
69 1.2 thorpej struct device *parent;
70 1.1 bouyer #ifdef __BROKEN_INDIRECT_CONFIG
71 1.1 bouyer void *match;
72 1.1 bouyer #else
73 1.1 bouyer struct cfdata *match;
74 1.1 bouyer #endif
75 1.1 bouyer void *aux;
76 1.1 bouyer {
77 1.1 bouyer mii_phy_t *phy = aux;
78 1.1 bouyer
79 1.1 bouyer if (phy->phy_id == 0x20005c01)
80 1.1 bouyer return 1;
81 1.1 bouyer return 0;
82 1.1 bouyer }
83 1.1 bouyer
84 1.1 bouyer void
85 1.1 bouyer nsphyattach(parent, self, aux)
86 1.2 thorpej struct device *parent, *self;
87 1.1 bouyer void *aux;
88 1.1 bouyer {
89 1.1 bouyer struct phy_softc *sc = (struct phy_softc *)self;
90 1.1 bouyer
91 1.1 bouyer sc->phy_link = aux;
92 1.1 bouyer sc->phy_link->phy_softc = sc;
93 1.1 bouyer sc->phy_link->phy_media_set = nsphy_media_set;
94 1.1 bouyer sc->phy_link->phy_status = phy_status;
95 1.1 bouyer sc->phy_link->phy_pdown = nsphy_pdown;
96 1.1 bouyer
97 1.1 bouyer phy_reset(sc);
98 1.1 bouyer
99 1.1 bouyer sc->phy_link->phy_media = 0;
100 1.1 bouyer if (phy_media_probe(sc) != 0) {
101 1.1 bouyer printf(": autoconfig failed\n");
102 1.1 bouyer return;
103 1.1 bouyer }
104 1.1 bouyer printf(": ");
105 1.1 bouyer phy_media_print(sc->phy_link->phy_media);
106 1.1 bouyer printf("\n");
107 1.1 bouyer }
108 1.1 bouyer
109 1.2 thorpej void
110 1.2 thorpej nsphy_pdown(v)
111 1.1 bouyer void *v;
112 1.1 bouyer {
113 1.1 bouyer struct phy_softc *sc = v;
114 1.1 bouyer mii_phy_t *phy_link = sc->phy_link;
115 1.2 thorpej
116 1.1 bouyer mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
117 1.2 thorpej CTRL_ISO);
118 1.1 bouyer }
119 1.1 bouyer
120 1.2 thorpej int
121 1.2 thorpej nsphy_media_set(media, v)
122 1.1 bouyer int media;
123 1.1 bouyer void *v;
124 1.1 bouyer {
125 1.1 bouyer struct phy_softc *sc = v;
126 1.1 bouyer int subtype;
127 1.1 bouyer
128 1.1 bouyer if (IFM_TYPE(media) != IFM_ETHER)
129 1.2 thorpej return (EINVAL);
130 1.1 bouyer
131 1.1 bouyer if (phy_reset(sc) == 0)
132 1.2 thorpej return (EIO);
133 1.1 bouyer
134 1.1 bouyer subtype = IFM_SUBTYPE(media);
135 1.1 bouyer switch (subtype) {
136 1.1 bouyer case IFM_10_2:
137 1.1 bouyer case IFM_10_5:
138 1.2 thorpej return (EINVAL);
139 1.1 bouyer case IFM_10_T:
140 1.1 bouyer case IFM_100_TX:
141 1.1 bouyer case IFM_100_T4:
142 1.2 thorpej return (phy_media_set_10_100(sc, media));
143 1.1 bouyer case IFM_AUTO:
144 1.2 thorpej return (ENODEV);
145 1.1 bouyer default:
146 1.2 thorpej return (EINVAL);
147 1.1 bouyer }
148 1.1 bouyer }
149