1 /* $NetBSD: tspld.c,v 1.19 2009/03/14 21:04:08 dsl Exp $ */
4 * Copyright (c) 2004 Jesse Off
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: tspld.c,v 1.19 2009/03/14 21:04:08 dsl Exp $");
33 #include <sys/param.h>
34 #include <sys/callout.h>
35 #include <sys/kernel.h>
36 #include <sys/sysctl.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
41 #include <machine/bus.h>
42 #include <machine/cpu.h>
43 #include <machine/autoconf.h>
46 #include <dev/isa/isavar.h>
47 #include <machine/isa_machdep.h>
50 #include <evbarm/tsarm/tsarmreg.h>
51 #include <evbarm/tsarm/tspldvar.h>
52 #include <arm/ep93xx/ep93xxvar.h>
53 #include <arm/ep93xx/ep93xxreg.h>
54 #include <arm/ep93xx/epgpioreg.h>
55 #include <arm/arm32/machdep.h>
56 #include <arm/cpufunc.h>
57 #include <dev/sysmon/sysmonvar.h>
59 int tspldmatch (struct device
*, struct cfdata
*, void *);
60 void tspldattach (struct device
*, struct device
*, void *);
61 static int tspld_wdog_setmode (struct sysmon_wdog
*);
62 static int tspld_wdog_tickle (struct sysmon_wdog
*);
63 int tspld_search (struct device
*, struct cfdata
*, const int *, void *);
64 int tspld_print (void *, const char *);
65 void boardtemp_poll (void *);
69 bus_space_tag_t sc_iot
;
70 bus_space_handle_t sc_wdogfeed_ioh
;
71 bus_space_handle_t sc_wdogctrl_ioh
;
72 struct sysmon_wdog sc_wdog
;
73 bus_space_handle_t sc_ssph
;
74 bus_space_handle_t sc_gpioh
;
75 unsigned const char * sc_com2mode
;
76 unsigned const char * sc_model
;
77 unsigned char sc_pldrev
[4];
81 uint32_t sc_blaster_present
;
82 uint32_t sc_blaster_boot
;
84 uint32_t boardtemp_5s
;
85 uint32_t boardtemp_30s
;
86 struct callout boardtemp_callout
;
89 CFATTACH_DECL(tspld
, sizeof(struct tspld_softc
),
90 tspldmatch
, tspldattach
, NULL
, NULL
);
92 void tspld_callback(struct device
*);
94 #define GPIO_GET(x) bus_space_read_4(sc->sc_iot, sc->sc_gpioh, \
97 #define GPIO_SET(x, y) bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
98 (EP93XX_GPIO_ ## x), (y))
100 #define GPIO_SETBITS(x, y) bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
101 (EP93XX_GPIO_ ## x), GPIO_GET(x) | (y))
103 #define GPIO_CLEARBITS(x, y) bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
104 (EP93XX_GPIO_ ## x), GPIO_GET(x) & (~(y)))
106 #define SSP_GET(x) bus_space_read_4(sc->sc_iot, sc->sc_ssph, \
109 #define SSP_SET(x, y) bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
110 (EP93XX_SSP_ ## x), (y))
112 #define SSP_SETBITS(x, y) bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
113 (EP93XX_SSP_ ## x), SSP_GET(x) | (y))
115 #define SSP_CLEARBITS(x, y) bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
116 (EP93XX_SSP_ ## x), SSP_GET(x) & (~(y)))
119 tspldmatch(struct device
*parent
, struct cfdata
*match
, void *aux
)
126 boardtemp_poll(void *arg
)
128 struct tspld_softc
*sc
= arg
;
131 /* Disable chip select */
132 GPIO_SET(PFDDR
, 0x0);
134 val
= SSP_GET(SSPDR
) & 0xffff;
135 sc
->boardtemp
= ((int16_t)val
>> 3) * 62500;
136 sc
->boardtemp_5s
= sc
->boardtemp_5s
/ 20 * 19 + sc
->boardtemp
/ 20;
137 sc
->boardtemp_30s
= sc
->boardtemp_30s
/ 120 * 119 + sc
->boardtemp
/ 120;
139 callout_schedule(&sc
->boardtemp_callout
, hz
/ 4);
141 /* Enable chip select */
142 GPIO_SET(PFDDR
, 0x4);
144 /* Send read command */
145 SSP_SET(SSPDR
, 0x8000);
149 tspldattach(struct device
*parent
, struct device
*self
, void *aux
)
151 int i
, rev
, features
, jp
, model
;
152 struct tspld_softc
*sc
= (struct tspld_softc
*)self
;
153 bus_space_handle_t ioh
;
154 const struct sysctlnode
*node
;
156 if (sysctl_createv(NULL
, 0, NULL
, NULL
,
157 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "hw",
158 NULL
, NULL
, 0, NULL
, 0,
159 CTL_HW
, CTL_EOL
) != 0) {
160 printf("%s: could not create sysctl\n",
161 sc
->sc_dev
.dv_xname
);
164 if (sysctl_createv(NULL
, 0, NULL
, &node
,
165 0, CTLTYPE_NODE
, sc
->sc_dev
.dv_xname
,
168 CTL_HW
, CTL_CREATE
, CTL_EOL
) != 0) {
169 printf("%s: could not create sysctl\n",
170 sc
->sc_dev
.dv_xname
);
174 sc
->sc_iot
= &ep93xx_bs_tag
;
175 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_MODEL
, 2, 0,
177 model
= bus_space_read_2(sc
->sc_iot
, ioh
, 0) & 0x7;
178 sc
->sc_model
= (model
? "TS-7250" : "TS-7200");
179 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
180 0, CTLTYPE_STRING
, "boardmodel",
181 SYSCTL_DESCR("Technologic Systems board model"),
182 NULL
, 0, __UNCONST(sc
->sc_model
), 0,
183 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
185 printf("%s: could not create sysctl\n",
186 sc
->sc_dev
.dv_xname
);
189 bus_space_unmap(sc
->sc_iot
, ioh
, 2);
191 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_PLDREV
, 2, 0,
193 rev
= bus_space_read_2(sc
->sc_iot
, ioh
, 0) & 0x7;
195 sc
->sc_pldrev
[0] = rev
;
196 sc
->sc_pldrev
[1] = 0;
197 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
198 0, CTLTYPE_STRING
, "pldrev",
199 SYSCTL_DESCR("CPLD revision"),
200 NULL
, 0, sc
->sc_pldrev
, 0,
201 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
203 printf("%s: could not create sysctl\n",
204 sc
->sc_dev
.dv_xname
);
207 bus_space_unmap(sc
->sc_iot
, ioh
, 2);
209 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_FEATURES
, 2, 0,
211 features
= bus_space_read_2(sc
->sc_iot
, ioh
, 0) & 0x7;
212 bus_space_unmap(sc
->sc_iot
, ioh
, 2);
214 bus_space_map(sc
->sc_iot
, TS7XXX_IO8_HWBASE
+ TS7XXX_STATUS1
, 1, 0,
216 i
= bus_space_read_1(sc
->sc_iot
, ioh
, 0) & 0x1f;
217 jp
= (~((i
& 0x18) >> 1) & 0xc) | (i
& 0x3);
218 bus_space_unmap(sc
->sc_iot
, ioh
, 1);
220 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
221 0, CTLTYPE_INT
, "blaster_present",
222 SYSCTL_DESCR("Whether or not a TS-9420/TS-9202 blaster board is connected"),
223 NULL
, 0, &sc
->sc_blaster_present
, 0,
224 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
226 printf("%s: could not create sysctl\n",
227 sc
->sc_dev
.dv_xname
);
230 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
231 0, CTLTYPE_INT
, "blaster_boot",
232 SYSCTL_DESCR("Whether or not a blast board was used to boot"),
233 NULL
, 0, &sc
->sc_blaster_boot
, 0,
234 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
236 printf("%s: could not create sysctl\n",
237 sc
->sc_dev
.dv_xname
);
240 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_STATUS2
, 2, 0,
242 i
= bus_space_read_2(sc
->sc_iot
, ioh
, 0) & 0x6;
243 sc
->sc_blaster_boot
= sc
->sc_blaster_present
= 0;
245 sc
->sc_blaster_boot
= 1;
247 sc
->sc_blaster_present
= 1;
249 bus_space_unmap(sc
->sc_iot
, ioh
, 1);
251 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
252 0, CTLTYPE_INT
, "rs485_avail",
253 SYSCTL_DESCR("RS485 level driver for COM2 available"),
254 NULL
, 0, &sc
->sc_rs485
, 0,
255 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
257 printf("%s: could not create sysctl\n",
258 sc
->sc_dev
.dv_xname
);
261 sc
->sc_com2mode
= "rs232";
262 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
263 0, CTLTYPE_STRING
, "com2_mode",
264 SYSCTL_DESCR("line driver type for COM2"),
265 NULL
, 0, __UNCONST(sc
->sc_com2mode
), 0,
266 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
268 printf("%s: could not create sysctl\n",
269 sc
->sc_dev
.dv_xname
);
272 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
273 0, CTLTYPE_INT
, "max197adc_avail",
274 SYSCTL_DESCR("Maxim 197 Analog to Digital Converter available"),
275 NULL
, 0, &sc
->sc_adc
, 0,
276 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
278 printf("%s: could not create sysctl\n",
279 sc
->sc_dev
.dv_xname
);
282 printf(": Technologic Systems %s rev %c, features 0x%x",
283 sc
->sc_model
, rev
, features
);
284 sc
->sc_adc
= sc
->sc_rs485
= 0;
285 if (features
== 0x1) {
286 printf("<MAX197-ADC>");
288 } else if (features
== 0x2) {
291 } else if (features
== 0x3) {
292 printf("<MAX197-ADC,RS485>");
293 sc
->sc_adc
= sc
->sc_rs485
= 1;
296 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
297 0, CTLTYPE_INT
, "jp1",
298 SYSCTL_DESCR("onboard jumper setting"),
299 NULL
, 0, &sc
->sc_jp
[0], 0,
300 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
302 printf("%s: could not create sysctl\n",
303 sc
->sc_dev
.dv_xname
);
306 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
307 0, CTLTYPE_INT
, "jp2",
308 SYSCTL_DESCR("onboard jumper setting"),
309 NULL
, 0, &sc
->sc_jp
[1], 0,
310 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
312 printf("%s: could not create sysctl\n",
313 sc
->sc_dev
.dv_xname
);
316 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
317 0, CTLTYPE_INT
, "jp3",
318 SYSCTL_DESCR("onboard jumper setting"),
319 NULL
, 0, &sc
->sc_jp
[2], 0,
320 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
322 printf("%s: could not create sysctl\n",
323 sc
->sc_dev
.dv_xname
);
326 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
327 0, CTLTYPE_INT
, "jp4",
328 SYSCTL_DESCR("onboard jumper setting"),
329 NULL
, 0, &sc
->sc_jp
[3], 0,
330 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
332 printf("%s: could not create sysctl\n",
333 sc
->sc_dev
.dv_xname
);
336 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
337 0, CTLTYPE_INT
, "jp5",
338 SYSCTL_DESCR("onboard jumper setting"),
339 NULL
, 0, &sc
->sc_jp
[4], 0,
340 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
342 printf("%s: could not create sysctl\n",
343 sc
->sc_dev
.dv_xname
);
346 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
347 0, CTLTYPE_INT
, "jp6",
348 SYSCTL_DESCR("onboard jumper setting"),
349 NULL
, 0, &sc
->sc_jp
[5], 0,
350 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
352 printf("%s: could not create sysctl\n",
353 sc
->sc_dev
.dv_xname
);
356 printf("%s: jumpers 0x%x", sc
->sc_dev
.dv_xname
, jp
);
359 for(i
= 0; i
< 5; i
++) {
361 sc
->sc_jp
[i
+ 1] = 1;
362 printf("JP%d", i
+ 2);
366 sc
->sc_jp
[i
+ 2] = 0;
374 bus_space_map(sc
->sc_iot
, EP93XX_APB_HWBASE
+ EP93XX_APB_SSP
,
375 EP93XX_APB_SSP_SIZE
, 0, &sc
->sc_ssph
);
376 bus_space_map(sc
->sc_iot
, EP93XX_APB_HWBASE
+ EP93XX_APB_GPIO
,
377 EP93XX_APB_GPIO_SIZE
, 0, &sc
->sc_gpioh
);
378 SSP_SETBITS(SSPCR1
, 0x10);
379 SSP_SET(SSPCR0
, 0xf);
380 SSP_SET(SSPCPSR
, 0xfe);
381 SSP_CLEARBITS(SSPCR1
, 0x10);
382 SSP_SETBITS(SSPCR1
, 0x10);
384 callout_init(&sc
->boardtemp_callout
, 0);
385 callout_setfunc(&sc
->boardtemp_callout
, boardtemp_poll
, sc
);
389 sc
->boardtemp_5s
= sc
->boardtemp_30s
= sc
->boardtemp
;
390 #define DEGF(c) ((c) * 9 / 5 + 32000000)
391 printf("%s: board temperature %d.%02d degC (%d.%02d degF)\n",
393 sc
->boardtemp
/ 1000000, sc
->boardtemp
/ 10000 % 100,
394 DEGF(sc
->boardtemp
) / 1000000, DEGF(sc
->boardtemp
) / 10000 % 100);
396 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
397 0, CTLTYPE_INT
, "board_temp",
398 SYSCTL_DESCR("board temperature in micro degrees Celsius"),
399 NULL
, 0, &sc
->boardtemp
, 0,
400 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
402 printf("%s: could not create sysctl\n",
403 sc
->sc_dev
.dv_xname
);
407 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
408 0, CTLTYPE_INT
, "board_temp_5s",
409 SYSCTL_DESCR("5 second average board temperature in micro degrees Celsius"),
410 NULL
, 0, &sc
->boardtemp_5s
, 0,
411 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
413 printf("%s: could not create sysctl\n",
414 sc
->sc_dev
.dv_xname
);
418 if ((i
= sysctl_createv(NULL
, 0, NULL
, NULL
,
419 0, CTLTYPE_INT
, "board_temp_30s",
420 SYSCTL_DESCR("30 second average board temperature in micro degrees Celsius"),
421 NULL
, 0, &sc
->boardtemp_30s
, 0,
422 CTL_HW
, node
->sysctl_num
, CTL_CREATE
, CTL_EOL
))
424 printf("%s: could not create sysctl\n",
425 sc
->sc_dev
.dv_xname
);
429 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_WDOGCTRL
, 2, 0,
430 &sc
->sc_wdogctrl_ioh
);
431 bus_space_map(sc
->sc_iot
, TS7XXX_IO16_HWBASE
+ TS7XXX_WDOGFEED
, 2, 0,
432 &sc
->sc_wdogfeed_ioh
);
434 sc
->sc_wdog
.smw_name
= sc
->sc_dev
.dv_xname
;
435 sc
->sc_wdog
.smw_cookie
= sc
;
436 sc
->sc_wdog
.smw_setmode
= tspld_wdog_setmode
;
437 sc
->sc_wdog
.smw_tickle
= tspld_wdog_tickle
;
438 sc
->sc_wdog
.smw_period
= 8;
439 sysmon_wdog_register(&sc
->sc_wdog
);
440 tspld_wdog_setmode(&sc
->sc_wdog
);
442 /* Set the on board peripherals bus callback */
443 config_defer(self
, tspld_callback
);
447 tspld_search(struct device
*parent
, struct cfdata
*cf
, const int *ldesc
, void *aux
)
449 struct tspld_softc
*sc
= (struct tspld_softc
*)parent
;
450 struct tspld_attach_args sa
;
452 sa
.ta_iot
= sc
->sc_iot
;
454 if (config_match(parent
, cf
, &sa
) > 0)
455 config_attach(parent
, cf
, &sa
, tspld_print
);
461 tspld_print(void *aux
, const char *name
)
468 tspld_callback(struct device
*self
)
471 extern void isa_bs_mallocok(void);
472 struct isabus_attach_args iba
;
475 * Attach the ISA bus behind this bridge.
477 memset(&iba
, 0, sizeof(iba
));
478 iba
.iba_iot
= &isa_io_bs_tag
;
479 iba
.iba_memt
= &isa_mem_bs_tag
;
481 config_found_ia(self
, "isabus", &iba
, isabusprint
);
484 * Attach each devices
486 config_search_ia(tspld_search
, self
, "tspldbus", NULL
);
491 tspld_wdog_tickle(struct sysmon_wdog
*smw
)
493 struct tspld_softc
*sc
= (struct tspld_softc
*)smw
->smw_cookie
;
495 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogfeed_ioh
, 0, 0x5);
500 tspld_wdog_setmode(struct sysmon_wdog
*smw
)
503 struct tspld_softc
*sc
= (struct tspld_softc
*)smw
->smw_cookie
;
505 i
= disable_interrupts(I32_bit
|F32_bit
);
506 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
507 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogfeed_ioh
, 0, 0x5);
508 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogctrl_ioh
, 0, 0);
510 if (smw
->smw_period
== WDOG_PERIOD_DEFAULT
) {
514 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogfeed_ioh
, 0, 0x5);
515 switch (smw
->smw_period
) {
517 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogctrl_ioh
, 0,
521 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogctrl_ioh
, 0,
525 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogctrl_ioh
, 0,
529 bus_space_write_2(sc
->sc_iot
, sc
->sc_wdogctrl_ioh
, 0,
536 restore_interrupts(i
);