1 /* $NetBSD: if_wi_obio.c,v 1.18 2008/09/10 00:33:12 macallan Exp $ */
4 * Copyright (c) 2001 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: if_wi_obio.c,v 1.18 2008/09/10 00:33:12 macallan Exp $");
34 #include <sys/param.h>
35 #include <sys/callout.h>
36 #include <sys/device.h>
37 #include <sys/socket.h>
38 #include <sys/systm.h>
42 #include <net/if_ether.h>
43 #include <net/if_media.h>
44 #include <net80211/ieee80211_var.h>
45 #include <net80211/ieee80211_radiotap.h>
46 #include <net80211/ieee80211_rssadapt.h>
49 #include <machine/autoconf.h>
50 #include <machine/bus.h>
52 #include <dev/ic/wi_ieee.h>
53 #include <dev/ic/wireg.h>
54 #include <dev/ic/wivar.h>
55 #include <macppc/dev/obiovar.h>
57 static int wi_obio_match(struct device
*, struct cfdata
*, void *);
58 static void wi_obio_attach(struct device
*, struct device
*, void *);
59 static int wi_obio_enable(struct wi_softc
*);
60 static void wi_obio_disable(struct wi_softc
*);
62 struct wi_obio_softc
{
63 struct wi_softc sc_wi
;
64 bus_space_tag_t sc_tag
;
67 CFATTACH_DECL(wi_obio
, sizeof(struct wi_obio_softc
),
68 wi_obio_match
, wi_obio_attach
, NULL
, NULL
);
71 wi_obio_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
73 struct confargs
*ca
= aux
;
75 if (ca
->ca_nintr
< 4 || ca
->ca_nreg
< 8)
78 if (strcmp(ca
->ca_name
, "radio") != 0)
84 #define OBIO_WI_FCR2 0x40
85 #define OBIO_WI_GPIO 0x6a
86 #define OBIO_WI_EXTINT 0x58
89 wi_obio_attach(struct device
*parent
, struct device
*self
, void *aux
)
91 struct wi_obio_softc
* const sc
= (void *)self
;
92 struct wi_softc
* const wisc
= &sc
->sc_wi
;
93 struct confargs
* const ca
= aux
;
95 aprint_normal(" irq %d:", ca
->ca_intr
[0]);
96 intr_establish(ca
->ca_intr
[0], IST_LEVEL
, IPL_NET
, wi_intr
, sc
);
98 sc
->sc_tag
= wisc
->sc_iot
= ca
->ca_tag
;
100 if (bus_space_map(wisc
->sc_iot
, ca
->ca_baseaddr
+ ca
->ca_reg
[0],
101 ca
->ca_reg
[1], 0, &wisc
->sc_ioh
)) {
102 printf(" can't map i/o space\n");
106 wisc
->sc_enabled
= 1;
107 wisc
->sc_enable
= wi_obio_enable
;
108 wisc
->sc_disable
= wi_obio_disable
;
110 if (wi_attach(wisc
, 0)) {
111 printf("%s: failed to attach controller\n", self
->dv_xname
);
115 if (!pmf_device_register(self
, NULL
, NULL
))
116 aprint_error_dev(self
, "couldn't establish power handler\n");
118 pmf_class_network_register(self
, &sc
->sc_wi
.sc_if
);
120 /* Disable the card. */
121 wisc
->sc_enabled
= 0;
122 wi_obio_disable(wisc
);
126 wi_obio_enable(struct wi_softc
*wisc
)
130 x
= obio_read_4(OBIO_WI_FCR2
);
132 obio_write_4(OBIO_WI_FCR2
, x
);
134 /* Enable card slot. */
135 obio_write_1(OBIO_WI_GPIO
+ 0x0f, 5);
137 obio_write_1(OBIO_WI_GPIO
+ 0x0f, 4);
139 x
= obio_read_4(OBIO_WI_FCR2
);
142 obio_write_4(OBIO_WI_FCR2
, x
);
143 /* out8(gpio + 0x10, 4); */
145 obio_write_1(OBIO_WI_EXTINT
+ 0x0b, 0);
146 obio_write_1(OBIO_WI_EXTINT
+ 0x0a, 0x28);
147 obio_write_1(OBIO_WI_EXTINT
+ 0x0d, 0x28);
148 obio_write_1(OBIO_WI_GPIO
+ 0x0d, 0x28);
149 obio_write_1(OBIO_WI_GPIO
+ 0x0e, 0x28);
150 obio_write_4(0x1c000, 0);
152 /* Initialize the card. */
153 obio_write_4(0x1a3e0, 0x41);
154 x
= obio_read_4(OBIO_WI_FCR2
);
156 obio_write_4(OBIO_WI_FCR2
, x
);
162 wi_obio_disable(struct wi_softc
*wisc
)
166 x
= obio_read_4(OBIO_WI_FCR2
);
168 obio_write_4(OBIO_WI_FCR2
, x
);
169 /* out8(gpio + 0x10, 0); */