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