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