tspld.c revision 1.1 1 /* $NetBSD: tspld.c,v 1.1 2004/12/23 04:30:19 joff Exp $ */
2
3 /*-
4 * Copyright (c) 2004 Jesse Off
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: tspld.c,v 1.1 2004/12/23 04:30:19 joff Exp $");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43
44 #include <machine/bus.h>
45 #include <machine/autoconf.h>
46 #include "isa.h"
47 #if NISA > 0
48 #include <dev/isa/isavar.h>
49 #include <machine/isa_machdep.h>
50 #endif
51
52 #include <evbarm/tsarm/tsarmreg.h>
53 #include <evbarm/tsarm/tspldvar.h>
54 #include <arm/ep93xx/ep93xxvar.h>
55
56 int tspldmatch __P((struct device *, struct cfdata *, void *));
57 void tspldattach __P((struct device *, struct device *, void *));
58
59 struct tspld_softc {
60 struct device sc_dev;
61 bus_space_tag_t sc_iot;
62 };
63
64
65 CFATTACH_DECL(tspld, sizeof(struct tspld_softc),
66 tspldmatch, tspldattach, NULL, NULL);
67
68 void tspld_callback __P((struct device *));
69
70 int
71 tspldmatch(parent, match, aux)
72 struct device *parent;
73 struct cfdata *match;
74 void *aux;
75 {
76
77 return 1;
78 }
79
80 void
81 tspldattach(parent, self, aux)
82 struct device *parent, *self;
83 void *aux;
84 {
85 int i, rev, features, jp, model;
86 struct tspld_softc *sc = (struct tspld_softc *)self;
87 struct tspld_attach_args ta;
88 bus_space_handle_t ioh;
89
90 sc->sc_iot = &ep93xx_bs_tag;
91 bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_MODEL, 2, 0,
92 &ioh);
93 model = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
94 bus_space_unmap(sc->sc_iot, ioh, 2);
95
96 bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_PLDREV, 2, 0,
97 &ioh);
98 rev = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
99 rev = 'A' + rev - 1;
100 bus_space_unmap(sc->sc_iot, ioh, 2);
101
102 bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_FEATURES, 2, 0,
103 &ioh);
104 features = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
105 bus_space_unmap(sc->sc_iot, ioh, 2);
106
107 bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_STATUS1, 1, 0,
108 &ioh);
109 i = bus_space_read_1(sc->sc_iot, ioh, 0) & 0x1f;
110 jp = (~((i & 0x18) >> 1) & 0xc) | (i & 0x3);
111 bus_space_unmap(sc->sc_iot, ioh, 1);
112
113 bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_STATUS2, 2, 0,
114 &ioh);
115 i = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x1;
116 jp |= (i << 4);
117 bus_space_unmap(sc->sc_iot, ioh, 1);
118
119 printf(": Technologic Systems TS-7%s rev %c, features 0x%x",
120 (model ? "250" : "200"), rev, features);
121 if (features == 0x1)
122 printf("<MAX197-ADC>");
123 else if (features == 0x2)
124 printf("<RS485>");
125 else if (features == 0x3)
126 printf("<MAX197-ADC,RS485>");
127 printf("\n");
128 printf("%s: jumpers 0x%x", sc->sc_dev.dv_xname, jp);
129 if (jp) {
130 printf("<");
131 for(i = 0; i < 5; i++) {
132 if (jp & (1 << i)) {
133 printf("JP%d", i + 2);
134 jp &= ~(1 << i);
135 if (jp) printf(",");
136 }
137 }
138 printf(">");
139 }
140 printf("\n");
141
142 ta.ta_iot = sc->sc_iot;
143 config_found_ia(self, "tspldbus", &ta, NULL);
144
145 /* Set the on board peripherals bus callback */
146 config_defer(self, tspld_callback);
147 }
148
149 void
150 tspld_callback(self)
151 struct device *self;
152 {
153 #if NISA > 0
154 struct isabus_attach_args iba;
155
156 /*
157 * Attach the ISA bus behind this bridge.
158 */
159 memset(&iba, 0, sizeof(iba));
160 iba.iba_iot = &isa_io_bs_tag;
161 iba.iba_memt = &isa_mem_bs_tag;
162 config_found_ia(self, "isabus", &iba, isabusprint);
163 #endif
164 }
165