tspld.c revision 1.2 1 1.1 joff /* $NetBSD: tspld.c,v 1.2 2004/12/26 22:02:11 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.2 2004/12/26 22:02:11 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.2 joff #include <sys/wdog.h>
44 1.1 joff
45 1.1 joff #include <machine/bus.h>
46 1.2 joff #include <machine/cpu.h>
47 1.1 joff #include <machine/autoconf.h>
48 1.1 joff #include "isa.h"
49 1.1 joff #if NISA > 0
50 1.1 joff #include <dev/isa/isavar.h>
51 1.1 joff #include <machine/isa_machdep.h>
52 1.1 joff #endif
53 1.1 joff
54 1.1 joff #include <evbarm/tsarm/tsarmreg.h>
55 1.1 joff #include <evbarm/tsarm/tspldvar.h>
56 1.1 joff #include <arm/ep93xx/ep93xxvar.h>
57 1.2 joff #include <arm/arm32/machdep.h>
58 1.2 joff #include <arm/cpufunc.h>
59 1.2 joff #include <dev/sysmon/sysmonvar.h>
60 1.1 joff
61 1.1 joff int tspldmatch __P((struct device *, struct cfdata *, void *));
62 1.1 joff void tspldattach __P((struct device *, struct device *, void *));
63 1.2 joff static int tspld_wdog_setmode __P((struct sysmon_wdog *));
64 1.2 joff static int tspld_wdog_tickle __P((struct sysmon_wdog *));
65 1.1 joff
66 1.1 joff struct tspld_softc {
67 1.1 joff struct device sc_dev;
68 1.1 joff bus_space_tag_t sc_iot;
69 1.2 joff bus_space_handle_t sc_wdogfeed_ioh;
70 1.2 joff bus_space_handle_t sc_wdogctrl_ioh;
71 1.2 joff struct sysmon_wdog sc_wdog;
72 1.1 joff };
73 1.1 joff
74 1.1 joff
75 1.1 joff CFATTACH_DECL(tspld, sizeof(struct tspld_softc),
76 1.1 joff tspldmatch, tspldattach, NULL, NULL);
77 1.1 joff
78 1.1 joff void tspld_callback __P((struct device *));
79 1.1 joff
80 1.1 joff int
81 1.1 joff tspldmatch(parent, match, aux)
82 1.1 joff struct device *parent;
83 1.1 joff struct cfdata *match;
84 1.1 joff void *aux;
85 1.1 joff {
86 1.1 joff
87 1.1 joff return 1;
88 1.1 joff }
89 1.1 joff
90 1.1 joff void
91 1.1 joff tspldattach(parent, self, aux)
92 1.1 joff struct device *parent, *self;
93 1.1 joff void *aux;
94 1.1 joff {
95 1.1 joff int i, rev, features, jp, model;
96 1.1 joff struct tspld_softc *sc = (struct tspld_softc *)self;
97 1.1 joff struct tspld_attach_args ta;
98 1.1 joff bus_space_handle_t ioh;
99 1.1 joff
100 1.1 joff sc->sc_iot = &ep93xx_bs_tag;
101 1.1 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_MODEL, 2, 0,
102 1.1 joff &ioh);
103 1.1 joff model = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
104 1.1 joff bus_space_unmap(sc->sc_iot, ioh, 2);
105 1.1 joff
106 1.1 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_PLDREV, 2, 0,
107 1.1 joff &ioh);
108 1.1 joff rev = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
109 1.1 joff rev = 'A' + rev - 1;
110 1.1 joff bus_space_unmap(sc->sc_iot, ioh, 2);
111 1.1 joff
112 1.1 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_FEATURES, 2, 0,
113 1.1 joff &ioh);
114 1.1 joff features = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
115 1.1 joff bus_space_unmap(sc->sc_iot, ioh, 2);
116 1.1 joff
117 1.1 joff bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_STATUS1, 1, 0,
118 1.1 joff &ioh);
119 1.1 joff i = bus_space_read_1(sc->sc_iot, ioh, 0) & 0x1f;
120 1.1 joff jp = (~((i & 0x18) >> 1) & 0xc) | (i & 0x3);
121 1.1 joff bus_space_unmap(sc->sc_iot, ioh, 1);
122 1.1 joff
123 1.1 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_STATUS2, 2, 0,
124 1.1 joff &ioh);
125 1.1 joff i = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x1;
126 1.1 joff jp |= (i << 4);
127 1.1 joff bus_space_unmap(sc->sc_iot, ioh, 1);
128 1.1 joff
129 1.1 joff printf(": Technologic Systems TS-7%s rev %c, features 0x%x",
130 1.1 joff (model ? "250" : "200"), rev, features);
131 1.1 joff if (features == 0x1)
132 1.1 joff printf("<MAX197-ADC>");
133 1.1 joff else if (features == 0x2)
134 1.1 joff printf("<RS485>");
135 1.1 joff else if (features == 0x3)
136 1.1 joff printf("<MAX197-ADC,RS485>");
137 1.1 joff printf("\n");
138 1.1 joff printf("%s: jumpers 0x%x", sc->sc_dev.dv_xname, jp);
139 1.1 joff if (jp) {
140 1.1 joff printf("<");
141 1.1 joff for(i = 0; i < 5; i++) {
142 1.1 joff if (jp & (1 << i)) {
143 1.1 joff printf("JP%d", i + 2);
144 1.1 joff jp &= ~(1 << i);
145 1.1 joff if (jp) printf(",");
146 1.1 joff }
147 1.1 joff }
148 1.1 joff printf(">");
149 1.1 joff }
150 1.1 joff printf("\n");
151 1.1 joff
152 1.2 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGCTRL, 2, 0,
153 1.2 joff &sc->sc_wdogctrl_ioh);
154 1.2 joff bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGFEED, 2, 0,
155 1.2 joff &sc->sc_wdogfeed_ioh);
156 1.2 joff
157 1.2 joff sc->sc_wdog.smw_name = sc->sc_dev.dv_xname;
158 1.2 joff sc->sc_wdog.smw_cookie = sc;
159 1.2 joff sc->sc_wdog.smw_setmode = tspld_wdog_setmode;
160 1.2 joff sc->sc_wdog.smw_tickle = tspld_wdog_tickle;
161 1.2 joff sc->sc_wdog.smw_period = 8;
162 1.2 joff sysmon_wdog_register(&sc->sc_wdog);
163 1.2 joff tspld_wdog_setmode(&sc->sc_wdog);
164 1.2 joff
165 1.1 joff ta.ta_iot = sc->sc_iot;
166 1.1 joff config_found_ia(self, "tspldbus", &ta, NULL);
167 1.1 joff
168 1.1 joff /* Set the on board peripherals bus callback */
169 1.1 joff config_defer(self, tspld_callback);
170 1.1 joff }
171 1.1 joff
172 1.1 joff void
173 1.1 joff tspld_callback(self)
174 1.1 joff struct device *self;
175 1.1 joff {
176 1.1 joff #if NISA > 0
177 1.1 joff struct isabus_attach_args iba;
178 1.1 joff
179 1.1 joff /*
180 1.1 joff * Attach the ISA bus behind this bridge.
181 1.1 joff */
182 1.1 joff memset(&iba, 0, sizeof(iba));
183 1.1 joff iba.iba_iot = &isa_io_bs_tag;
184 1.1 joff iba.iba_memt = &isa_mem_bs_tag;
185 1.1 joff config_found_ia(self, "isabus", &iba, isabusprint);
186 1.1 joff #endif
187 1.1 joff }
188 1.2 joff
189 1.2 joff static int
190 1.2 joff tspld_wdog_tickle(smw)
191 1.2 joff struct sysmon_wdog *smw;
192 1.2 joff {
193 1.2 joff struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
194 1.2 joff
195 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
196 1.2 joff return 0;
197 1.2 joff }
198 1.2 joff
199 1.2 joff static int
200 1.2 joff tspld_wdog_setmode(smw)
201 1.2 joff struct sysmon_wdog *smw;
202 1.2 joff {
203 1.2 joff int i, ret = 0;
204 1.2 joff struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
205 1.2 joff
206 1.2 joff i = disable_interrupts(I32_bit|F32_bit);
207 1.2 joff if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
208 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
209 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0, 0);
210 1.2 joff } else {
211 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
212 1.2 joff switch (smw->smw_period) {
213 1.2 joff case 1:
214 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
215 1.2 joff 0x3);
216 1.2 joff break;
217 1.2 joff case 2:
218 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
219 1.2 joff 0x5);
220 1.2 joff break;
221 1.2 joff case 4:
222 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
223 1.2 joff 0x6);
224 1.2 joff break;
225 1.2 joff case 8:
226 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
227 1.2 joff 0x7);
228 1.2 joff break;
229 1.2 joff default:
230 1.2 joff ret = EINVAL;
231 1.2 joff }
232 1.2 joff }
233 1.2 joff restore_interrupts(i);
234 1.2 joff return ret;
235 1.2 joff }
236