gb225_slhci.c revision 1.1 1 /* $NetBSD: gb225_slhci.c,v 1.1 2005/02/26 10:49:53 bsh 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 * SL811HS USB host controller for GB-225 Option board of G4250EBX.
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/arm/xscale/pxa2x0reg.h>
58 #include <arch/arm/xscale/pxa2x0var.h>
59 #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
60 #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
61 #include <arch/evbarm/g42xxeb/gb225reg.h>
62 #include <arch/evbarm/g42xxeb/gb225var.h>
63
64 struct slhci_opio_softc {
65 struct slhci_softc sc_sc;
66
67 void *sc_ih;
68 };
69
70 static int slhci_opio_match(struct device *, struct cfdata *, void *);
71 static void slhci_opio_attach(struct device *, struct device *, void *);
72 static void slhci_opio_enable_power(void *, int);
73 static void slhci_opio_enable_intr(void *, int);
74 static int slhci_opio_intr(void *);
75
76 CFATTACH_DECL(slhci_opio, sizeof(struct slhci_opio_softc),
77 slhci_opio_match, slhci_opio_attach, NULL, NULL);
78
79 #define PORTSIZE (SL11_PORTSIZE*4)
80
81 static int
82 slhci_opio_match(struct device *parent, struct cfdata *cf, void *aux)
83 {
84 struct obio_attach_args *oba = aux;
85 bus_space_tag_t iot = &pxa2x0_a4x_bs_tag; /* Use special BS funcs */
86 bus_space_handle_t ioh;
87 struct obio_softc *bsc = (struct obio_softc *)parent->dv_parent;
88 struct pxa2x0_softc *psc;
89 int type;
90 uint32_t reg;
91
92 struct slhci_softc sc;
93
94 obio_peripheral_reset(bsc, 2, 0);
95 psc = (struct pxa2x0_softc *)bsc->sc_dev.dv_parent;
96
97 reg = bus_space_read_4(psc->saip.sc_iot, psc->sc_memctl_ioh,
98 MEMCTL_MSC2);
99 #if 0
100 bus_space_write_4(psc->saip.sc_iot, psc->sc_memctl_ioh, MEMCTL_MSC2,xxx)
101 #endif
102
103
104 oba->oba_iot = iot;
105 if (oba->oba_addr == OBIOCF_ADDR_DEFAULT)
106 oba->oba_addr = PXA2X0_CS5_START;
107 if (oba->oba_intr == OBIOCF_INTR_DEFAULT)
108 oba->oba_intr = G4250EBX_INT_EXT2;
109
110 if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh))
111 return 0;
112
113 /* construct fake softc to call sl811hs */
114 sc.sc_iot = iot;
115 sc.sc_ioh = ioh;
116 type = sl811hs_find(&sc);
117
118 bus_space_unmap(iot, ioh, PORTSIZE);
119
120 return type >= 0;
121 }
122
123 static void
124 slhci_opio_attach(struct device *parent, struct device *self, void *aux)
125 {
126 struct slhci_opio_softc *sc = (struct slhci_opio_softc *)self;
127 struct obio_attach_args *oba = aux;
128 struct opio_softc *psc = (struct opio_softc *)self->dv_parent;
129 struct obio_softc *bsc = (struct obio_softc *)psc->sc_dev.dv_parent;
130 bus_space_tag_t iot = oba->oba_iot;
131 bus_space_handle_t ioh;
132
133 printf("\n");
134
135 /* Map I/O space */
136 if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh)) {
137 printf("%s: can't map I/O space\n",
138 sc->sc_sc.sc_bus.bdev.dv_xname);
139 return;
140 }
141
142 /* Initialize sc */
143 sc->sc_sc.sc_iot = iot;
144 sc->sc_sc.sc_ioh = ioh;
145 sc->sc_sc.sc_dmat = &pxa2x0_bus_dma_tag; /* XXX */
146 sc->sc_sc.sc_enable_power = slhci_opio_enable_power;
147 sc->sc_sc.sc_enable_intr = slhci_opio_enable_intr;
148 sc->sc_sc.sc_arg = sc;
149
150 /* Establish the interrupt handler */
151 sc->sc_ih = obio_intr_establish(bsc, oba->oba_intr, IPL_BIO,
152 IST_LEVEL_HIGH, slhci_opio_intr, sc);
153 if( sc->sc_ih == NULL) {
154 printf("%s: can't establish interrupt\n",
155 sc->sc_sc.sc_bus.bdev.dv_xname);
156 return;
157 }
158
159 #if 0
160 /* Reset controller */
161 obio_peripheral_reset(bsc, 2, 1);
162 delay(100);
163 obio_peripheral_reset(bsc, 2, 0);
164 delay(40000);
165 #endif
166
167 bus_space_write_1(iot, ioh, SL11_IDX_ADDR, SL11_CTRL);
168 bus_space_write_1(iot, ioh, SL11_IDX_DATA, 0x01);
169
170 /* Attach SL811HS/T */
171 if (slhci_attach(&sc->sc_sc, self))
172 return;
173 }
174
175 static void
176 slhci_opio_enable_power(void *arg, int mode)
177 {
178 #if 0
179 struct slhci_opio_softc *sc = arg;
180 bus_space_tag_t iot = sc->sc_sc.sc_iot;
181 u_int8_t r;
182
183 r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
184 if (mode == POWER_ON)
185 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
186 r | NEREID_CTRL_POWER);
187 else
188 bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
189 r & ~NEREID_CTRL_POWER);
190 #endif
191 }
192
193 static void
194 slhci_opio_enable_intr(void *arg, int mode)
195 {
196 struct slhci_opio_softc *sc = arg;
197 struct obio_softc *bsc;
198
199 bsc = (struct obio_softc *)sc->sc_sc.sc_bus.bdev.dv_parent->dv_parent;
200
201 if (mode == INTR_ON)
202 obio_intr_unmask(bsc, sc->sc_ih);
203 else
204 obio_intr_mask(bsc, sc->sc_ih);
205 }
206
207 static int
208 slhci_opio_intr(void *arg)
209 {
210 struct slhci_opio_softc *sc = arg;
211
212 return slhci_intr(&sc->sc_sc);
213 }
214