Deleted Added
full compact
jmphy.c (217414) jmphy.c (221407)
1/*-
2 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/mii/jmphy.c 217414 2011-01-14 19:33:58Z marius $");
29__FBSDID("$FreeBSD: head/sys/dev/mii/jmphy.c 221407 2011-05-03 19:51:29Z marius $");
30
31/*
32 * Driver for the JMicron JMP211 10/100/1000, JMP202 10/100 PHY.
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>

--- 13 unchanged lines hidden (view full) ---

51#include "miibus_if.h"
52
53static int jmphy_probe(device_t);
54static int jmphy_attach(device_t);
55static void jmphy_reset(struct mii_softc *);
56static uint16_t jmphy_anar(struct ifmedia_entry *);
57static int jmphy_setmedia(struct mii_softc *, struct ifmedia_entry *);
58
30
31/*
32 * Driver for the JMicron JMP211 10/100/1000, JMP202 10/100 PHY.
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>

--- 13 unchanged lines hidden (view full) ---

51#include "miibus_if.h"
52
53static int jmphy_probe(device_t);
54static int jmphy_attach(device_t);
55static void jmphy_reset(struct mii_softc *);
56static uint16_t jmphy_anar(struct ifmedia_entry *);
57static int jmphy_setmedia(struct mii_softc *, struct ifmedia_entry *);
58
59struct jmphy_softc {
60 struct mii_softc mii_sc;
61 int mii_oui;
62 int mii_model;
63 int mii_rev;
64};
65
66static device_method_t jmphy_methods[] = {
67 /* Device interface. */
68 DEVMETHOD(device_probe, jmphy_probe),
69 DEVMETHOD(device_attach, jmphy_attach),
70 DEVMETHOD(device_detach, mii_phy_detach),
71 DEVMETHOD(device_shutdown, bus_generic_shutdown),
72 { NULL, NULL }
73};
74
75static devclass_t jmphy_devclass;
76static driver_t jmphy_driver = {
77 "jmphy",
78 jmphy_methods,
59static device_method_t jmphy_methods[] = {
60 /* Device interface. */
61 DEVMETHOD(device_probe, jmphy_probe),
62 DEVMETHOD(device_attach, jmphy_attach),
63 DEVMETHOD(device_detach, mii_phy_detach),
64 DEVMETHOD(device_shutdown, bus_generic_shutdown),
65 { NULL, NULL }
66};
67
68static devclass_t jmphy_devclass;
69static driver_t jmphy_driver = {
70 "jmphy",
71 jmphy_methods,
79 sizeof(struct jmphy_softc)
72 sizeof(struct mii_softc)
80};
81
82DRIVER_MODULE(jmphy, miibus, jmphy_driver, jmphy_devclass, 0, 0);
83
84static int jmphy_service(struct mii_softc *, struct mii_data *, int);
85static void jmphy_status(struct mii_softc *);
86
87static const struct mii_phydesc jmphys[] = {
88 MII_PHY_DESC(JMICRON, JMP202),
89 MII_PHY_DESC(JMICRON, JMP211),
90 MII_PHY_END
91};
92
73};
74
75DRIVER_MODULE(jmphy, miibus, jmphy_driver, jmphy_devclass, 0, 0);
76
77static int jmphy_service(struct mii_softc *, struct mii_data *, int);
78static void jmphy_status(struct mii_softc *);
79
80static const struct mii_phydesc jmphys[] = {
81 MII_PHY_DESC(JMICRON, JMP202),
82 MII_PHY_DESC(JMICRON, JMP211),
83 MII_PHY_END
84};
85
86static const struct mii_phy_funcs jmphy_funcs = {
87 jmphy_service,
88 jmphy_status,
89 jmphy_reset
90};
91
93static int
94jmphy_probe(device_t dev)
95{
96
97 return (mii_phy_dev_probe(dev, jmphys, BUS_PROBE_DEFAULT));
98}
99
100static int
101jmphy_attach(device_t dev)
102{
92static int
93jmphy_probe(device_t dev)
94{
95
96 return (mii_phy_dev_probe(dev, jmphys, BUS_PROBE_DEFAULT));
97}
98
99static int
100jmphy_attach(device_t dev)
101{
103 struct jmphy_softc *jsc;
104 struct mii_softc *sc;
105 struct mii_attach_args *ma;
102 struct mii_attach_args *ma;
106 struct mii_data *mii;
107 struct ifnet *ifp;
103 u_int flags;
108
104
109 jsc = device_get_softc(dev);
110 sc = &jsc->mii_sc;
111 ma = device_get_ivars(dev);
105 ma = device_get_ivars(dev);
112 sc->mii_dev = device_get_parent(dev);
113 mii = ma->mii_data;
114 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
115
116 sc->mii_flags = miibus_get_flags(dev);
117 sc->mii_inst = mii->mii_instance++;
118 sc->mii_phy = ma->mii_phyno;
119 sc->mii_service = jmphy_service;
120 sc->mii_pdata = mii;
121
122 ifp = sc->mii_pdata->mii_ifp;
123 if (strcmp(ifp->if_dname, "jme") == 0 &&
124 (sc->mii_flags & MIIF_MACPRIV0) != 0)
125 sc->mii_flags |= MIIF_PHYPRIV0;
126 jsc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
127 jsc->mii_model = MII_MODEL(ma->mii_id2);
128 jsc->mii_rev = MII_REV(ma->mii_id2);
129 if (bootverbose)
130 device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
131 jsc->mii_oui, jsc->mii_model, jsc->mii_rev);
132
133 jmphy_reset(sc);
134
135 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
136 if (sc->mii_capabilities & BMSR_EXTSTAT)
137 sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
138 device_printf(dev, " ");
139 mii_phy_add_media(sc);
140 printf("\n");
141
142 MIIBUS_MEDIAINIT(sc->mii_dev);
106 flags = 0;
107 if (strcmp(ma->mii_data->mii_ifp->if_dname, "jme") == 0 &&
108 (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
109 flags |= MIIF_PHYPRIV0;
110 mii_phy_dev_attach(dev, flags, &jmphy_funcs, 1);
143 return (0);
144}
145
146static int
147jmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
148{
149 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
150

--- 40 unchanged lines hidden (view full) ---

191 return (0);
192
193 sc->mii_ticks = 0;
194 (void)jmphy_setmedia(sc, ife);
195 break;
196 }
197
198 /* Update the media status. */
111 return (0);
112}
113
114static int
115jmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
116{
117 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
118

--- 40 unchanged lines hidden (view full) ---

159 return (0);
160
161 sc->mii_ticks = 0;
162 (void)jmphy_setmedia(sc, ife);
163 break;
164 }
165
166 /* Update the media status. */
199 jmphy_status(sc);
167 PHY_STATUS(sc);
200
201 /* Callback if something changed. */
202 mii_phy_update(sc, cmd);
203 return (0);
204}
205
206static void
207jmphy_status(struct mii_softc *sc)

--- 56 unchanged lines hidden (view full) ---

264 if ((PHY_READ(sc, MII_100T2SR) & GTSR_MS_RES) != 0)
265 mii->mii_media_active |= IFM_ETH_MASTER;
266 }
267}
268
269static void
270jmphy_reset(struct mii_softc *sc)
271{
168
169 /* Callback if something changed. */
170 mii_phy_update(sc, cmd);
171 return (0);
172}
173
174static void
175jmphy_status(struct mii_softc *sc)

--- 56 unchanged lines hidden (view full) ---

232 if ((PHY_READ(sc, MII_100T2SR) & GTSR_MS_RES) != 0)
233 mii->mii_media_active |= IFM_ETH_MASTER;
234 }
235}
236
237static void
238jmphy_reset(struct mii_softc *sc)
239{
272 struct jmphy_softc *jsc;
273 uint16_t t2cr, val;
274 int i;
275
240 uint16_t t2cr, val;
241 int i;
242
276 jsc = (struct jmphy_softc *)sc;
277
278 /* Disable sleep mode. */
279 PHY_WRITE(sc, JMPHY_TMCTL,
280 PHY_READ(sc, JMPHY_TMCTL) & ~JMPHY_TMCTL_SLEEP_ENB);
281 PHY_WRITE(sc, MII_BMCR, BMCR_RESET | BMCR_AUTOEN);
282
283 for (i = 0; i < 1000; i++) {
284 DELAY(1);
285 if ((PHY_READ(sc, MII_BMCR) & BMCR_RESET) == 0)

--- 78 unchanged lines hidden (view full) ---

364 break;
365 case IFM_NONE:
366 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO | BMCR_PDOWN);
367 return (EJUSTRETURN);
368 default:
369 return (EINVAL);
370 }
371
243 /* Disable sleep mode. */
244 PHY_WRITE(sc, JMPHY_TMCTL,
245 PHY_READ(sc, JMPHY_TMCTL) & ~JMPHY_TMCTL_SLEEP_ENB);
246 PHY_WRITE(sc, MII_BMCR, BMCR_RESET | BMCR_AUTOEN);
247
248 for (i = 0; i < 1000; i++) {
249 DELAY(1);
250 if ((PHY_READ(sc, MII_BMCR) & BMCR_RESET) == 0)

--- 78 unchanged lines hidden (view full) ---

329 break;
330 case IFM_NONE:
331 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO | BMCR_PDOWN);
332 return (EJUSTRETURN);
333 default:
334 return (EINVAL);
335 }
336
372 if ((ife->ifm_media & IFM_LOOP) != 0)
373 bmcr |= BMCR_LOOP;
374
375 anar = jmphy_anar(ife);
376 if ((IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO ||
377 (ife->ifm_media & IFM_FDX) != 0) &&
378 ((ife->ifm_media & IFM_FLOW) != 0 ||
379 (sc->mii_flags & MIIF_FORCEPAUSE) != 0))
380 anar |= ANAR_PAUSE_TOWARDS;
381
382 if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) {

--- 12 unchanged lines hidden ---
337 anar = jmphy_anar(ife);
338 if ((IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO ||
339 (ife->ifm_media & IFM_FDX) != 0) &&
340 ((ife->ifm_media & IFM_FLOW) != 0 ||
341 (sc->mii_flags & MIIF_FORCEPAUSE) != 0))
342 anar |= ANAR_PAUSE_TOWARDS;
343
344 if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) {

--- 12 unchanged lines hidden ---