tspld.c revision 1.4 1 1.4 joff /* $NetBSD: tspld.c,v 1.4 2005/01/09 21:35:51 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.4 joff __KERNEL_RCSID(0, "$NetBSD: tspld.c,v 1.4 2005/01/09 21:35:51 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.3 joff int tspld_search __P((struct device *, struct cfdata *, void *));
66 1.3 joff int tspld_print __P((void *, const char *));
67 1.1 joff
68 1.1 joff struct tspld_softc {
69 1.1 joff struct device sc_dev;
70 1.1 joff bus_space_tag_t sc_iot;
71 1.2 joff bus_space_handle_t sc_wdogfeed_ioh;
72 1.2 joff bus_space_handle_t sc_wdogctrl_ioh;
73 1.2 joff struct sysmon_wdog sc_wdog;
74 1.1 joff };
75 1.1 joff
76 1.1 joff CFATTACH_DECL(tspld, sizeof(struct tspld_softc),
77 1.1 joff tspldmatch, tspldattach, NULL, NULL);
78 1.1 joff
79 1.1 joff void tspld_callback __P((struct device *));
80 1.1 joff
81 1.1 joff int
82 1.1 joff tspldmatch(parent, match, aux)
83 1.1 joff struct device *parent;
84 1.1 joff struct cfdata *match;
85 1.1 joff void *aux;
86 1.1 joff {
87 1.1 joff
88 1.1 joff return 1;
89 1.1 joff }
90 1.1 joff
91 1.1 joff void
92 1.1 joff tspldattach(parent, self, aux)
93 1.1 joff struct device *parent, *self;
94 1.1 joff void *aux;
95 1.1 joff {
96 1.1 joff int i, rev, features, jp, model;
97 1.1 joff struct tspld_softc *sc = (struct tspld_softc *)self;
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 /* Set the on board peripherals bus callback */
166 1.1 joff config_defer(self, tspld_callback);
167 1.1 joff }
168 1.1 joff
169 1.3 joff int
170 1.3 joff tspld_search(parent, cf, aux)
171 1.3 joff struct device *parent;
172 1.3 joff struct cfdata *cf;
173 1.3 joff void *aux;
174 1.3 joff {
175 1.3 joff struct tspld_softc *sc = (struct tspld_softc *)parent;
176 1.3 joff struct tspld_attach_args sa;
177 1.3 joff
178 1.3 joff sa.ta_iot = sc->sc_iot;
179 1.3 joff
180 1.3 joff if (config_match(parent, cf, &sa) > 0)
181 1.3 joff config_attach(parent, cf, &sa, tspld_print);
182 1.3 joff
183 1.3 joff return (0);
184 1.3 joff }
185 1.3 joff
186 1.3 joff int
187 1.3 joff tspld_print(aux, name)
188 1.3 joff void *aux;
189 1.3 joff const char *name;
190 1.3 joff {
191 1.3 joff
192 1.3 joff return (UNCONF);
193 1.3 joff }
194 1.3 joff
195 1.1 joff void
196 1.1 joff tspld_callback(self)
197 1.1 joff struct device *self;
198 1.1 joff {
199 1.1 joff #if NISA > 0
200 1.4 joff extern void isa_bs_mallocok(void);
201 1.1 joff struct isabus_attach_args iba;
202 1.1 joff
203 1.1 joff /*
204 1.1 joff * Attach the ISA bus behind this bridge.
205 1.1 joff */
206 1.1 joff memset(&iba, 0, sizeof(iba));
207 1.1 joff iba.iba_iot = &isa_io_bs_tag;
208 1.1 joff iba.iba_memt = &isa_mem_bs_tag;
209 1.4 joff isa_bs_mallocok();
210 1.1 joff config_found_ia(self, "isabus", &iba, isabusprint);
211 1.1 joff #endif
212 1.3 joff /*
213 1.3 joff * Attach each devices
214 1.3 joff */
215 1.3 joff config_search(tspld_search, self, NULL);
216 1.3 joff
217 1.1 joff }
218 1.2 joff
219 1.2 joff static int
220 1.2 joff tspld_wdog_tickle(smw)
221 1.2 joff struct sysmon_wdog *smw;
222 1.2 joff {
223 1.2 joff struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
224 1.2 joff
225 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
226 1.2 joff return 0;
227 1.2 joff }
228 1.2 joff
229 1.2 joff static int
230 1.2 joff tspld_wdog_setmode(smw)
231 1.2 joff struct sysmon_wdog *smw;
232 1.2 joff {
233 1.2 joff int i, ret = 0;
234 1.2 joff struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
235 1.2 joff
236 1.2 joff i = disable_interrupts(I32_bit|F32_bit);
237 1.2 joff if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
238 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
239 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0, 0);
240 1.2 joff } else {
241 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
242 1.2 joff switch (smw->smw_period) {
243 1.2 joff case 1:
244 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
245 1.2 joff 0x3);
246 1.2 joff break;
247 1.2 joff case 2:
248 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
249 1.2 joff 0x5);
250 1.2 joff break;
251 1.2 joff case 4:
252 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
253 1.2 joff 0x6);
254 1.2 joff break;
255 1.2 joff case 8:
256 1.2 joff bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
257 1.2 joff 0x7);
258 1.2 joff break;
259 1.2 joff default:
260 1.2 joff ret = EINVAL;
261 1.2 joff }
262 1.2 joff }
263 1.2 joff restore_interrupts(i);
264 1.2 joff return ret;
265 1.2 joff }
266