Deleted Added
sdiff udiff text old ( 217414 ) new ( 221407 )
full compact
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 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
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,
72 sizeof(struct mii_softc)
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
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{
102 struct mii_attach_args *ma;
103 u_int flags;
104
105 ma = device_get_ivars(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);
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. */
167 PHY_STATUS(sc);
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{
240 uint16_t t2cr, val;
241 int i;
242
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
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 ---