This source file includes following definitions.
- mtdphymatch
- mtdphyattach
- mtdphy_service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/device.h>
37 #include <sys/socket.h>
38 #include <sys/errno.h>
39
40 #include <net/if.h>
41 #include <net/if_media.h>
42
43 #include <dev/mii/mii.h>
44 #include <dev/mii/miivar.h>
45 #include <dev/mii/miidevs.h>
46 #include <dev/mii/mtdphyreg.h>
47
48 int mtdphymatch(struct device *, void *, void *);
49 void mtdphyattach(struct device *, struct device *, void *);
50
51 struct cfattach mtdphy_ca = {
52 sizeof(struct mii_softc), mtdphymatch, mtdphyattach, mii_phy_detach,
53 mii_phy_activate
54 };
55
56 struct cfdriver mtdphy_cd = {
57 NULL, "mtdphy", DV_DULL
58 };
59
60 int mtdphy_service(struct mii_softc *, struct mii_data *, int);
61
62 const struct mii_phy_funcs mtdphy_funcs = {
63 mtdphy_service, ukphy_status, mii_phy_reset,
64 };
65
66 static const struct mii_phydesc mtdphys[] = {
67 { MII_OUI_MYSON, MII_MODEL_MYSON_MTD972,
68 MII_STR_MYSON_MTD972 },
69
70 { 0, 0,
71 NULL },
72 };
73
74 int
75 mtdphymatch(struct device *parent, void *match, void *aux)
76 {
77 struct mii_attach_args *ma = aux;
78
79 if (mii_phy_match(ma, mtdphys) != NULL)
80 return (10);
81
82 return (0);
83 }
84
85 void
86 mtdphyattach(struct device *parent, struct device *self, void *aux)
87 {
88 struct mii_softc *sc = (struct mii_softc *)self;
89 struct mii_attach_args *ma = aux;
90 struct mii_data *mii = ma->mii_data;
91 const struct mii_phydesc *mpd;
92
93 mpd = mii_phy_match(ma, mtdphys);
94 printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
95
96 sc->mii_inst = mii->mii_instance;
97 sc->mii_phy = ma->mii_phyno;
98 sc->mii_funcs = &mtdphy_funcs;
99 sc->mii_pdata = mii;
100 sc->mii_flags = ma->mii_flags;
101
102 PHY_RESET(sc);
103
104 sc->mii_capabilities =
105 PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
106 if (sc->mii_capabilities & BMSR_MEDIAMASK)
107 mii_phy_add_media(sc);
108 }
109
110 int
111 mtdphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
112 {
113 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
114 int reg;
115
116 if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
117 return (ENXIO);
118
119 switch (cmd) {
120 case MII_POLLSTAT:
121
122
123
124 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
125 return (0);
126 break;
127
128 case MII_MEDIACHG:
129
130
131
132 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
133 reg = PHY_READ(sc, MII_BMCR);
134 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
135 return (0);
136 }
137
138 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
139 break;
140
141 mii_phy_setmedia(sc);
142 break;
143
144 case MII_TICK:
145
146
147
148 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
149 return (0);
150
151 if (mii_phy_tick(sc) == EJUSTRETURN)
152 return (0);
153 break;
154
155 case MII_DOWN:
156 mii_phy_down(sc);
157 return (0);
158 }
159
160
161 mii_phy_status(sc);
162
163
164 mii_phy_update(sc, cmd);
165 return (0);
166 }