This source file includes following definitions.
- ath_cardbus_match
- ath_cardbus_attach
- ath_cardbus_detach
- ath_cardbus_enable
- ath_cardbus_disable
- ath_cardbus_power
- ath_cardbus_setup
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
34
35
36
37
38
39
40
41 #include "bpfilter.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/mbuf.h>
46 #include <sys/malloc.h>
47 #include <sys/kernel.h>
48 #include <sys/socket.h>
49 #include <sys/ioctl.h>
50 #include <sys/errno.h>
51 #include <sys/device.h>
52 #include <sys/gpio.h>
53
54 #include <machine/endian.h>
55
56 #include <net/if.h>
57 #include <net/if_dl.h>
58 #include <net/if_media.h>
59
60 #ifdef INET
61 #include <netinet/in.h>
62 #include <netinet/if_ether.h>
63 #endif
64
65 #include <net80211/ieee80211_var.h>
66 #include <net80211/ieee80211_rssadapt.h>
67
68 #if NBPFILTER > 0
69 #include <net/bpf.h>
70 #endif
71
72 #include <machine/bus.h>
73 #include <machine/intr.h>
74
75 #include <dev/gpio/gpiovar.h>
76
77 #include <dev/pci/pcivar.h>
78 #include <dev/pci/pcireg.h>
79 #include <dev/pci/pcidevs.h>
80
81 #include <dev/cardbus/cardbusvar.h>
82
83 #include <dev/ic/athvar.h>
84
85
86
87
88 #define ATH_PCI_MMBA 0x10
89
90 struct ath_cardbus_softc {
91 struct ath_softc sc_ath;
92
93
94 void *sc_ih;
95 cardbus_devfunc_t sc_ct;
96 cardbustag_t sc_tag;
97 bus_size_t sc_mapsize;
98
99 pcireg_t sc_bar_val;
100
101 int sc_intrline;
102 };
103
104 int ath_cardbus_match(struct device *, void *, void *);
105 void ath_cardbus_attach(struct device *, struct device *, void *);
106 int ath_cardbus_detach(struct device *, int);
107
108 struct cfattach ath_cardbus_ca = {
109 sizeof(struct ath_cardbus_softc),
110 ath_cardbus_match,
111 ath_cardbus_attach,
112 ath_cardbus_detach
113 };
114
115
116 void ath_cardbus_setup(struct ath_cardbus_softc *);
117
118 int ath_cardbus_enable(struct ath_softc *);
119 void ath_cardbus_disable(struct ath_softc *);
120 void ath_cardbus_power(struct ath_softc *, int);
121
122 int
123 ath_cardbus_match(struct device *parent, void *match, void *aux)
124 {
125 struct cardbus_attach_args *ca = aux;
126 const char* devname;
127
128 devname = ath_hal_probe(PCI_VENDOR(ca->ca_id),
129 PCI_PRODUCT(ca->ca_id));
130
131 if (devname)
132 return (1);
133
134 return (0);
135 }
136
137 void
138 ath_cardbus_attach(struct device *parent, struct device *self, void *aux)
139 {
140 struct ath_cardbus_softc *csc = (void *)self;
141 struct ath_softc *sc = &csc->sc_ath;
142 struct cardbus_attach_args *ca = aux;
143 cardbus_devfunc_t ct = ca->ca_ct;
144 bus_addr_t adr;
145
146 sc->sc_dmat = ca->ca_dmat;
147 csc->sc_ct = ct;
148 csc->sc_tag = ca->ca_tag;
149
150
151
152
153 sc->sc_enable = ath_cardbus_enable;
154 sc->sc_disable = ath_cardbus_disable;
155 sc->sc_power = ath_cardbus_power;
156
157
158
159
160 if (Cardbus_mapreg_map(ct, ATH_PCI_MMBA, CARDBUS_MAPREG_TYPE_MEM, 0,
161 &sc->sc_st, &sc->sc_sh, &adr, &csc->sc_mapsize) == 0) {
162 csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
163 }
164
165 else {
166 printf(": unable to map device registers\n");
167 return;
168 }
169
170
171
172
173 ath_cardbus_setup(csc);
174
175
176 csc->sc_intrline = ca->ca_intrline;
177
178 printf(": irq %d\n", csc->sc_intrline);
179
180
181
182
183 ath_attach(PCI_PRODUCT(ca->ca_id), sc);
184
185
186
187
188 Cardbus_function_disable(csc->sc_ct);
189 }
190
191 int
192 ath_cardbus_detach(struct device *self, int flags)
193 {
194 struct ath_cardbus_softc *csc = (void *)self;
195 struct ath_softc *sc = &csc->sc_ath;
196 struct cardbus_devfunc *ct = csc->sc_ct;
197 int rv;
198
199 #if defined(DIAGNOSTIC)
200 if (ct == NULL)
201 panic("%s: data structure lacks", sc->sc_dev.dv_xname);
202 #endif
203
204 rv = ath_detach(sc, flags);
205 if (rv)
206 return (rv);
207
208
209
210
211 if (csc->sc_ih != NULL) {
212 cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
213 csc->sc_ih = NULL;
214 }
215
216
217
218
219 Cardbus_mapreg_unmap(ct, ATH_PCI_MMBA,
220 sc->sc_st, sc->sc_sh, csc->sc_mapsize);
221
222 return (0);
223 }
224
225 int
226 ath_cardbus_enable(struct ath_softc *sc)
227 {
228 struct ath_cardbus_softc *csc = (void *) sc;
229 cardbus_devfunc_t ct = csc->sc_ct;
230 cardbus_chipset_tag_t cc = ct->ct_cc;
231 cardbus_function_tag_t cf = ct->ct_cf;
232
233
234
235
236 Cardbus_function_enable(ct);
237
238
239
240
241 ath_cardbus_setup(csc);
242
243
244
245
246 csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
247 ath_intr, sc, sc->sc_dev.dv_xname);
248 if (csc->sc_ih == NULL) {
249 printf(": unable to establish irq %d\n",
250 csc->sc_intrline);
251 Cardbus_function_disable(csc->sc_ct);
252 return (1);
253 }
254 return (0);
255 }
256
257 void
258 ath_cardbus_disable(struct ath_softc *sc)
259 {
260 struct ath_cardbus_softc *csc = (void *) sc;
261 cardbus_devfunc_t ct = csc->sc_ct;
262 cardbus_chipset_tag_t cc = ct->ct_cc;
263 cardbus_function_tag_t cf = ct->ct_cf;
264
265
266 cardbus_intr_disestablish(cc, cf, csc->sc_ih);
267 csc->sc_ih = NULL;
268
269
270 Cardbus_function_disable(ct);
271 }
272
273 void
274 ath_cardbus_power(struct ath_softc *sc, int why)
275 {
276 if (why == PWR_RESUME)
277 ath_enable(sc);
278 }
279
280 void
281 ath_cardbus_setup(struct ath_cardbus_softc *csc)
282 {
283 cardbus_devfunc_t ct = csc->sc_ct;
284 cardbus_chipset_tag_t cc = ct->ct_cc;
285 cardbus_function_tag_t cf = ct->ct_cf;
286 pcireg_t reg;
287
288 #ifdef notyet
289 (void)cardbus_setpowerstate(sc->sc_dev.dv_xname, ct, csc->sc_tag,
290 PCI_PWR_D0);
291 #endif
292
293
294 cardbus_conf_write(cc, cf, csc->sc_tag, ATH_PCI_MMBA,
295 csc->sc_bar_val);
296
297
298 (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
299 (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
300
301
302 reg = cardbus_conf_read(cc, cf, csc->sc_tag,
303 CARDBUS_COMMAND_STATUS_REG);
304 reg |= CARDBUS_COMMAND_MASTER_ENABLE | CARDBUS_COMMAND_MEM_ENABLE;
305 cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_COMMAND_STATUS_REG,
306 reg);
307
308
309
310
311
312 reg = cardbus_conf_read(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG);
313 if (CARDBUS_LATTIMER(reg) < 0x20) {
314 reg &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
315 reg |= (0x20 << CARDBUS_LATTIMER_SHIFT);
316 cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG, reg);
317 }
318 }