gxio.c revision 1.2.4.3 1 1.2.4.3 ad /* $NetBSD: gxio.c,v 1.2.4.3 2007/02/01 08:47:59 ad Exp $ */
2 1.2.4.2 ad /*
3 1.2.4.3 ad * Copyright (C) 2005, 2006, 2007 WIDE Project and SOUM Corporation.
4 1.2.4.2 ad * All rights reserved.
5 1.2.4.2 ad *
6 1.2.4.2 ad * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
7 1.2.4.2 ad * Corporation.
8 1.2.4.2 ad *
9 1.2.4.2 ad * Redistribution and use in source and binary forms, with or without
10 1.2.4.2 ad * modification, are permitted provided that the following conditions
11 1.2.4.2 ad * are met:
12 1.2.4.2 ad * 1. Redistributions of source code must retain the above copyright
13 1.2.4.2 ad * notice, this list of conditions and the following disclaimer.
14 1.2.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.4.2 ad * notice, this list of conditions and the following disclaimer in the
16 1.2.4.2 ad * documentation and/or other materials provided with the distribution.
17 1.2.4.2 ad * 3. Neither the name of the project nor the name of SOUM Corporation
18 1.2.4.2 ad * may be used to endorse or promote products derived from this software
19 1.2.4.2 ad * without specific prior written permission.
20 1.2.4.2 ad *
21 1.2.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
22 1.2.4.2 ad * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.2.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.2.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
25 1.2.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.2.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.2.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.2.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.2.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.2.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.2.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
32 1.2.4.2 ad */
33 1.2.4.2 ad #include <sys/cdefs.h>
34 1.2.4.3 ad __KERNEL_RCSID(0, "$NetBSD: gxio.c,v 1.2.4.3 2007/02/01 08:47:59 ad Exp $");
35 1.2.4.3 ad
36 1.2.4.3 ad #include "opt_gxio.h"
37 1.2.4.2 ad
38 1.2.4.2 ad #include <sys/param.h>
39 1.2.4.2 ad #include <sys/device.h>
40 1.2.4.2 ad #include <sys/errno.h>
41 1.2.4.2 ad
42 1.2.4.2 ad #include <sys/systm.h>
43 1.2.4.2 ad
44 1.2.4.2 ad #include <machine/bootconfig.h>
45 1.2.4.2 ad
46 1.2.4.2 ad #include <arm/xscale/pxa2x0cpu.h>
47 1.2.4.2 ad #include <arm/xscale/pxa2x0reg.h>
48 1.2.4.2 ad #include <arm/xscale/pxa2x0var.h>
49 1.2.4.2 ad #include <arm/xscale/pxa2x0_gpio.h>
50 1.2.4.2 ad #include <evbarm/gumstix/gumstixvar.h>
51 1.2.4.2 ad
52 1.2.4.2 ad #include "locators.h"
53 1.2.4.2 ad
54 1.2.4.2 ad
55 1.2.4.3 ad struct gpioconf {
56 1.2.4.3 ad int pin;
57 1.2.4.3 ad u_int value;
58 1.2.4.3 ad };
59 1.2.4.3 ad struct gxioconf {
60 1.2.4.3 ad const char *name;
61 1.2.4.3 ad void (*config)(struct gxio_softc *);
62 1.2.4.3 ad };
63 1.2.4.3 ad
64 1.2.4.2 ad static int gxiomatch(struct device *, struct cfdata *, void *);
65 1.2.4.2 ad static void gxioattach(struct device *, struct device *, void *);
66 1.2.4.2 ad static int gxiosearch(struct device *, struct cfdata *, const int *, void *);
67 1.2.4.2 ad static int gxioprint(void *, const char *);
68 1.2.4.2 ad
69 1.2.4.3 ad void gxio_config_pin(void);
70 1.2.4.3 ad static void
71 1.2.4.3 ad gxio_config_gpio(struct gxio_softc *, const struct gxioconf *, char *);
72 1.2.4.2 ad static void cfstix_config(struct gxio_softc *);
73 1.2.4.2 ad static void etherstix_config(struct gxio_softc *);
74 1.2.4.2 ad static void netcf_config(struct gxio_softc *);
75 1.2.4.3 ad static void netduommc_config(struct gxio_softc *);
76 1.2.4.2 ad static void netduo_config(struct gxio_softc *);
77 1.2.4.2 ad static void netmmc_config(struct gxio_softc *);
78 1.2.4.2 ad
79 1.2.4.2 ad CFATTACH_DECL(
80 1.2.4.2 ad gxio, sizeof(struct gxio_softc), gxiomatch, gxioattach, NULL, NULL);
81 1.2.4.2 ad
82 1.2.4.2 ad char busheader[MAX_BOOT_STRING];
83 1.2.4.2 ad
84 1.2.4.3 ad struct gpioconf gpioconf[] = {
85 1.2.4.3 ad /* Bluetooth module configuration */
86 1.2.4.3 ad { 7, GPIO_OUT | GPIO_SET }, /* power on */
87 1.2.4.3 ad { 12, GPIO_ALT_FN_1_OUT }, /* 32kHz out. required by SingleStone */
88 1.2.4.3 ad
89 1.2.4.3 ad /* AC97 configuration */
90 1.2.4.3 ad #if 1
91 1.2.4.3 ad /* this configuration set by pxaacu_attach()::pxa2x0_ac97.c */
92 1.2.4.3 ad #else
93 1.2.4.3 ad /* Don't reorder */
94 1.2.4.3 ad { 31, GPIO_ALT_FN_2_OUT }, /* SYNC */
95 1.2.4.3 ad { 30, GPIO_ALT_FN_2_OUT }, /* SDATA_OUT */
96 1.2.4.3 ad { 28, GPIO_ALT_FN_1_IN }, /* BITCLK */
97 1.2.4.3 ad { 29, GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
98 1.2.4.3 ad #endif
99 1.2.4.3 ad
100 1.2.4.3 ad /* FFUART configuration : is connected only TXD/RXD */
101 1.2.4.3 ad { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */
102 1.2.4.3 ad { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */
103 1.2.4.3 ad
104 1.2.4.3 ad #ifndef GXIO_BLUETOOTH_ON_HWUART
105 1.2.4.3 ad /* BTUART configuration */
106 1.2.4.3 ad { 42, GPIO_ALT_FN_1_IN }, /* BTRXD */
107 1.2.4.3 ad { 43, GPIO_ALT_FN_2_OUT }, /* BTTXD */
108 1.2.4.3 ad { 44, GPIO_ALT_FN_1_IN }, /* BTCST */
109 1.2.4.3 ad { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */
110 1.2.4.3 ad #else
111 1.2.4.3 ad /* HWUART configuration */
112 1.2.4.3 ad { 42, GPIO_ALT_FN_3_IN }, /* HWRXD */
113 1.2.4.3 ad { 43, GPIO_ALT_FN_3_OUT }, /* HWTXD */
114 1.2.4.3 ad { 44, GPIO_ALT_FN_3_IN }, /* HWCST */
115 1.2.4.3 ad { 45, GPIO_ALT_FN_3_OUT }, /* HWRST */
116 1.2.4.3 ad #endif
117 1.2.4.3 ad
118 1.2.4.3 ad /* STUART configuration : is connected only TXD/RXD */
119 1.2.4.3 ad { 46, GPIO_ALT_FN_2_IN }, /* RXD */
120 1.2.4.3 ad { 47, GPIO_ALT_FN_1_OUT }, /* TXD */
121 1.2.4.3 ad
122 1.2.4.3 ad #ifndef GXIO_BLUETOOTH_ON_HWUART
123 1.2.4.3 ad /* HWUART configuration */
124 1.2.4.3 ad { 48, GPIO_ALT_FN_1_OUT }, /* HWTXD */
125 1.2.4.3 ad { 49, GPIO_ALT_FN_1_IN }, /* HWRXD */
126 1.2.4.3 ad { 50, GPIO_ALT_FN_1_IN }, /* HWCTS */
127 1.2.4.3 ad { 51, GPIO_ALT_FN_1_OUT }, /* HWRTS */
128 1.2.4.3 ad #endif
129 1.2.4.2 ad
130 1.2.4.3 ad { -1 }
131 1.2.4.2 ad };
132 1.2.4.3 ad
133 1.2.4.2 ad static const struct gxioconf busheader_conf[] = {
134 1.2.4.2 ad { "cfstix", cfstix_config },
135 1.2.4.2 ad { "etherstix", etherstix_config },
136 1.2.4.2 ad { "netcf", netcf_config },
137 1.2.4.3 ad { "netduo-mmc", netduommc_config },
138 1.2.4.2 ad { "netduo", netduo_config },
139 1.2.4.2 ad { "netmmc", netmmc_config },
140 1.2.4.3 ad { "wifistix", cfstix_config },
141 1.2.4.2 ad { NULL }
142 1.2.4.2 ad };
143 1.2.4.2 ad
144 1.2.4.2 ad
145 1.2.4.2 ad /* ARGSUSED */
146 1.2.4.2 ad static int
147 1.2.4.2 ad gxiomatch(struct device *parent, struct cfdata *match, void *aux)
148 1.2.4.2 ad {
149 1.2.4.2 ad bus_space_tag_t iot = &pxa2x0_bs_tag;
150 1.2.4.2 ad bus_space_handle_t ioh;
151 1.2.4.2 ad
152 1.2.4.2 ad if (bus_space_map(iot,
153 1.2.4.2 ad PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &ioh))
154 1.2.4.2 ad return (0);
155 1.2.4.2 ad bus_space_unmap(iot, ioh, PXA2X0_MEMCTL_SIZE);
156 1.2.4.2 ad
157 1.2.4.2 ad /* nothing */
158 1.2.4.2 ad return (1);
159 1.2.4.2 ad }
160 1.2.4.2 ad
161 1.2.4.2 ad /* ARGSUSED */
162 1.2.4.2 ad static void
163 1.2.4.2 ad gxioattach(struct device *parent, struct device *self, void *aux)
164 1.2.4.2 ad {
165 1.2.4.3 ad struct gxio_softc *sc = device_private(self);
166 1.2.4.2 ad
167 1.2.4.3 ad aprint_normal("\n");
168 1.2.4.3 ad aprint_naive("\n");
169 1.2.4.2 ad
170 1.2.4.2 ad sc->sc_iot = &pxa2x0_bs_tag;
171 1.2.4.2 ad
172 1.2.4.2 ad if (bus_space_map(sc->sc_iot,
173 1.2.4.2 ad PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &sc->sc_ioh))
174 1.2.4.2 ad return;
175 1.2.4.2 ad
176 1.2.4.3 ad /* configuration for GPIOs of busheader side */
177 1.2.4.3 ad gxio_config_gpio(sc, busheader_conf, busheader);
178 1.2.4.2 ad
179 1.2.4.2 ad /*
180 1.2.4.3 ad * Attach each gumstix expantion of busheader side devices
181 1.2.4.2 ad */
182 1.2.4.2 ad config_search_ia(gxiosearch, self, "gxio", NULL);
183 1.2.4.2 ad }
184 1.2.4.2 ad
185 1.2.4.2 ad /* ARGSUSED */
186 1.2.4.2 ad static int
187 1.2.4.2 ad gxiosearch(
188 1.2.4.2 ad struct device *parent, struct cfdata *cf, const int *ldesc, void *aux)
189 1.2.4.2 ad {
190 1.2.4.3 ad struct gxio_softc *sc = device_private(parent);
191 1.2.4.2 ad struct gxio_attach_args gxa;
192 1.2.4.2 ad
193 1.2.4.2 ad gxa.gxa_sc = sc;
194 1.2.4.2 ad gxa.gxa_iot = sc->sc_iot;
195 1.2.4.2 ad gxa.gxa_addr = cf->cf_loc[GXIOCF_ADDR];
196 1.2.4.2 ad gxa.gxa_gpirq = cf->cf_loc[GXIOCF_GPIRQ];
197 1.2.4.2 ad
198 1.2.4.2 ad if (config_match(parent, cf, &gxa))
199 1.2.4.2 ad config_attach(parent, cf, &gxa, gxioprint);
200 1.2.4.2 ad
201 1.2.4.2 ad return (0);
202 1.2.4.2 ad }
203 1.2.4.2 ad
204 1.2.4.2 ad /* ARGSUSED */
205 1.2.4.2 ad static int
206 1.2.4.2 ad gxioprint(void *aux, const char *name)
207 1.2.4.2 ad {
208 1.2.4.2 ad struct gxio_attach_args *gxa = (struct gxio_attach_args *)aux;
209 1.2.4.2 ad
210 1.2.4.2 ad if (gxa->gxa_addr != GXIOCF_ADDR_DEFAULT)
211 1.2.4.2 ad printf(" addr 0x%lx", gxa->gxa_addr);
212 1.2.4.2 ad if (gxa->gxa_gpirq > 0)
213 1.2.4.2 ad printf(" gpirq %d", gxa->gxa_gpirq);
214 1.2.4.2 ad return (UNCONF);
215 1.2.4.2 ad }
216 1.2.4.2 ad
217 1.2.4.2 ad
218 1.2.4.2 ad /*
219 1.2.4.3 ad * configure for GPIO pin and expansion boards.
220 1.2.4.2 ad */
221 1.2.4.2 ad void
222 1.2.4.3 ad gxio_config_pin()
223 1.2.4.2 ad {
224 1.2.4.3 ad int i;
225 1.2.4.2 ad
226 1.2.4.3 ad /* XXX: turn off for power of bluetooth module */
227 1.2.4.3 ad pxa2x0_gpio_set_function(7, GPIO_OUT | GPIO_CLR);
228 1.2.4.3 ad delay(100);
229 1.2.4.3 ad
230 1.2.4.3 ad for (i = 0; gpioconf[i].pin != -1; i++)
231 1.2.4.3 ad pxa2x0_gpio_set_function(gpioconf[i].pin, gpioconf[i].value);
232 1.2.4.3 ad }
233 1.2.4.3 ad
234 1.2.4.3 ad static void
235 1.2.4.3 ad gxio_config_gpio(struct gxio_softc *sc,
236 1.2.4.3 ad const struct gxioconf *gxioconflist, char *expansion)
237 1.2.4.3 ad {
238 1.2.4.3 ad int i, rv;
239 1.2.4.2 ad
240 1.2.4.3 ad for (i = 0; i < strlen(expansion); i++)
241 1.2.4.3 ad expansion[i] = tolower(expansion[i]);
242 1.2.4.3 ad for (i = 0; gxioconflist[i].name != NULL; i++) {
243 1.2.4.3 ad rv = strncmp(expansion, gxioconflist[i].name,
244 1.2.4.3 ad strlen(gxioconflist[i].name) + 1);
245 1.2.4.2 ad if (rv == 0) {
246 1.2.4.3 ad gxioconflist[i].config(sc);
247 1.2.4.2 ad break;
248 1.2.4.2 ad }
249 1.2.4.2 ad }
250 1.2.4.2 ad }
251 1.2.4.2 ad
252 1.2.4.3 ad
253 1.2.4.2 ad static void
254 1.2.4.2 ad cfstix_config(struct gxio_softc *sc)
255 1.2.4.2 ad {
256 1.2.4.2 ad u_int gpio, npoe_fn;
257 1.2.4.2 ad
258 1.2.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, MEMCTL_MECR,
259 1.2.4.2 ad bus_space_read_4(sc->sc_iot, sc->sc_ioh, MEMCTL_MECR) & ~MECR_NOS);
260 1.2.4.2 ad
261 1.2.4.2 ad pxa2x0_gpio_set_function(8, GPIO_OUT | GPIO_SET); /* RESET */
262 1.2.4.2 ad delay(50);
263 1.2.4.2 ad pxa2x0_gpio_set_function(8, GPIO_OUT | GPIO_CLR);
264 1.2.4.2 ad
265 1.2.4.3 ad pxa2x0_gpio_set_function(4, GPIO_IN); /* nBVD1/~nSTSCHG */
266 1.2.4.2 ad pxa2x0_gpio_set_function(27, GPIO_IN); /* ~INPACK */
267 1.2.4.2 ad pxa2x0_gpio_set_function(11, GPIO_IN); /* nPCD1 */
268 1.2.4.3 ad pxa2x0_gpio_set_function(26, GPIO_IN); /* PRDY/~IRQ */
269 1.2.4.2 ad
270 1.2.4.2 ad for (gpio = 48, npoe_fn = 0; gpio <= 53 ; gpio++)
271 1.2.4.2 ad npoe_fn |= pxa2x0_gpio_get_function(gpio);
272 1.2.4.2 ad npoe_fn &= GPIO_SET;
273 1.2.4.2 ad
274 1.2.4.2 ad pxa2x0_gpio_set_function(48, GPIO_ALT_FN_2_OUT | npoe_fn); /* nPOE */
275 1.2.4.2 ad pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
276 1.2.4.2 ad pxa2x0_gpio_set_function(50, GPIO_ALT_FN_2_OUT); /* nPIOR */
277 1.2.4.2 ad pxa2x0_gpio_set_function(51, GPIO_ALT_FN_2_OUT); /* nPIOW */
278 1.2.4.2 ad pxa2x0_gpio_set_function(52, GPIO_ALT_FN_2_OUT); /* nPCE1 */
279 1.2.4.2 ad pxa2x0_gpio_set_function(54, GPIO_ALT_FN_2_OUT); /* pSKTSEL */
280 1.2.4.2 ad pxa2x0_gpio_set_function(55, GPIO_ALT_FN_2_OUT); /* nPREG */
281 1.2.4.2 ad pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN); /* nPWAIT */
282 1.2.4.2 ad pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN); /* nIOIS16 */
283 1.2.4.2 ad }
284 1.2.4.2 ad
285 1.2.4.2 ad /* ARGSUSED */
286 1.2.4.2 ad static void
287 1.2.4.2 ad etherstix_config(struct gxio_softc *sc)
288 1.2.4.2 ad {
289 1.2.4.2 ad
290 1.2.4.2 ad pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
291 1.2.4.2 ad pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT); /* nCS 1 */
292 1.2.4.2 ad pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET); /* RESET 1 */
293 1.2.4.2 ad delay(1);
294 1.2.4.2 ad pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_CLR);
295 1.2.4.2 ad delay(50000);
296 1.2.4.2 ad }
297 1.2.4.2 ad
298 1.2.4.2 ad static void
299 1.2.4.2 ad netcf_config(struct gxio_softc *sc)
300 1.2.4.2 ad {
301 1.2.4.2 ad
302 1.2.4.2 ad etherstix_config(sc);
303 1.2.4.2 ad cfstix_config(sc);
304 1.2.4.2 ad }
305 1.2.4.2 ad
306 1.2.4.2 ad static void
307 1.2.4.3 ad netduommc_config(struct gxio_softc *sc)
308 1.2.4.3 ad {
309 1.2.4.3 ad
310 1.2.4.3 ad netduo_config(sc);
311 1.2.4.3 ad
312 1.2.4.3 ad /* mmc not yet... */
313 1.2.4.3 ad }
314 1.2.4.3 ad
315 1.2.4.3 ad static void
316 1.2.4.2 ad netduo_config(struct gxio_softc *sc)
317 1.2.4.2 ad {
318 1.2.4.2 ad
319 1.2.4.2 ad etherstix_config(sc);
320 1.2.4.2 ad
321 1.2.4.2 ad pxa2x0_gpio_set_function(78, GPIO_ALT_FN_2_OUT); /* nCS 2 */
322 1.2.4.2 ad pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_SET); /* RESET 2 */
323 1.2.4.2 ad delay(1);
324 1.2.4.2 ad pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_CLR);
325 1.2.4.2 ad delay(50000);
326 1.2.4.2 ad }
327 1.2.4.2 ad
328 1.2.4.2 ad static void
329 1.2.4.2 ad netmmc_config(struct gxio_softc *sc)
330 1.2.4.2 ad {
331 1.2.4.2 ad
332 1.2.4.2 ad etherstix_config(sc);
333 1.2.4.2 ad
334 1.2.4.2 ad /* mmc not yet... */
335 1.2.4.2 ad }
336