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