slhci_intio.c revision 1.1.6.3 1 /* $NetBSD: slhci_intio.c,v 1.1.6.3 2002/10/10 18:37:37 jdolecek Exp $ */
2
3 /*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tetsuya Isaki.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * USB part of Nereid Ethernet/USB/Memory board
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46
47 #include <machine/bus.h>
48 #include <machine/cpu.h>
49
50 #include <dev/usb/usb.h>
51 #include <dev/usb/usbdi.h>
52 #include <dev/usb/usbdivar.h>
53
54 #include <dev/ic/sl811hsreg.h>
55 #include <dev/ic/sl811hsvar.h>
56
57 #include <arch/x68k/dev/intiovar.h>
58
59 #include <arch/x68k/dev/slhci_intio_var.h>
60
61 static int slhci_intio_match(struct device *, struct cfdata *, void *);
62 static void slhci_intio_attach(struct device *, struct device *, void *);
63 static void slhci_intio_enable_power(void *, int);
64 static void slhci_intio_enable_intr(void *, int);
65 static int slhci_intio_intr(void *);
66
67 CFATTACH_DECL(slhci_intio, sizeof(struct slhci_intio_softc),
68 slhci_intio_match, slhci_intio_attach, NULL, NULL);
69
70 static int
71 slhci_intio_match(struct device *parent, struct cfdata *cf, void *aux)
72 {
73 struct intio_attach_args *ia = aux;
74 bus_space_tag_t iot = ia->ia_bst;
75 bus_space_handle_t ioh;
76 bus_space_handle_t nch;
77 int nc_addr;
78 int nc_size;
79
80 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
81 ia->ia_addr = SLHCI_INTIO_ADDR1;
82 if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
83 ia->ia_intr = SLHCI_INTIO_INTR1;
84
85 /* fixed parameters */
86 if ( !(ia->ia_addr == SLHCI_INTIO_ADDR1 &&
87 ia->ia_intr == SLHCI_INTIO_INTR1 ) &&
88 !(ia->ia_addr == SLHCI_INTIO_ADDR2 &&
89 ia->ia_intr == SLHCI_INTIO_INTR2 ) )
90 return 0;
91
92 /* Whether the control port is accessible or not */
93 nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
94 nc_size = 0x02;
95 if (badbaddr((caddr_t)INTIO_ADDR(nc_addr)))
96 return 0;
97
98 /* Map two I/O spaces */
99 ia->ia_size = SL11_PORTSIZE * 2;
100 if (bus_space_map(iot, ia->ia_addr, ia->ia_size,
101 BUS_SPACE_MAP_SHIFTED, &ioh))
102 return 0;
103
104 if (bus_space_map(iot, nc_addr, nc_size,
105 BUS_SPACE_MAP_SHIFTED, &nch))
106 return 0;
107
108 bus_space_unmap(iot, ioh, ia->ia_size);
109 bus_space_unmap(iot, nch, nc_size);
110
111 return 1;
112 }
113
114 static void
115 slhci_intio_attach(struct device *parent, struct device *self, void *aux)
116 {
117 struct slhci_intio_softc *sc = (struct slhci_intio_softc *)self;
118 struct intio_attach_args *ia = aux;
119 bus_space_tag_t iot = ia->ia_bst;
120 bus_space_handle_t ioh;
121 int nc_addr;
122 int nc_size;
123
124 printf(": Nereid USB\n");
125
126 /* Map I/O space */
127 if (bus_space_map(iot, ia->ia_addr, SL11_PORTSIZE * 2,
128 BUS_SPACE_MAP_SHIFTED, &ioh)) {
129 printf("%s: can't map I/O space\n",
130 sc->sc_sc.sc_bus.bdev.dv_xname);
131 return;
132 }
133
134 nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
135 nc_size = 0x02;
136 if (bus_space_map(iot, nc_addr, nc_size,
137 BUS_SPACE_MAP_SHIFTED, &sc->sc_nch)) {
138 printf("%s: can't map I/O control space\n",
139 sc->sc_sc.sc_bus.bdev.dv_xname);
140 return;
141 }
142
143 /* Initialize sc */
144 sc->sc_sc.sc_iot = iot;
145 sc->sc_sc.sc_ioh = ioh;
146 sc->sc_sc.sc_dmat = ia->ia_dmat;
147 sc->sc_sc.sc_enable_power = slhci_intio_enable_power;
148 sc->sc_sc.sc_enable_intr = slhci_intio_enable_intr;
149 sc->sc_sc.sc_arg = sc;
150
151 /* Establish the interrupt handler */
152 if (intio_intr_establish(ia->ia_intr, "slhci", slhci_intio_intr, sc)) {
153 printf("%s: can't establish interrupt\n",
154 sc->sc_sc.sc_bus.bdev.dv_xname);
155 return;
156 }
157
158 /* Reset controller */
159 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL, NEREID_CTRL_RESET);
160 delay(40000);
161
162 /* Attach SL811HS/T */
163 if (slhci_attach(&sc->sc_sc, self))
164 return;
165 }
166
167 static void
168 slhci_intio_enable_power(void *arg, int mode)
169 {
170 struct slhci_intio_softc *sc = arg;
171 bus_space_tag_t iot = sc->sc_sc.sc_iot;
172 u_int8_t r;
173
174 r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
175 if (mode == POWER_ON)
176 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
177 r | NEREID_CTRL_POWER);
178 else
179 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
180 r & ~NEREID_CTRL_POWER);
181 }
182
183 static void
184 slhci_intio_enable_intr(void *arg, int mode)
185 {
186 struct slhci_intio_softc *sc = arg;
187 bus_space_tag_t iot = sc->sc_sc.sc_iot;
188 u_int8_t r;
189
190 r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
191 if (mode == INTR_ON)
192 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
193 r | NEREID_CTRL_INTR);
194 else
195 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
196 r & ~NEREID_CTRL_INTR);
197 }
198
199 static int
200 slhci_intio_intr(void *arg)
201 {
202 struct slhci_intio_softc *sc = arg;
203
204 return slhci_intr(&sc->sc_sc);
205 }
206