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