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