Home | History | Annotate | Line # | Download | only in tsarm
tspld.c revision 1.4.4.4
      1  1.4.4.4  skrll /*	$NetBSD: tspld.c,v 1.4.4.4 2005/11/10 13:55:54 skrll Exp $	*/
      2  1.4.4.2  skrll 
      3  1.4.4.2  skrll /*-
      4  1.4.4.2  skrll  * Copyright (c) 2004 Jesse Off
      5  1.4.4.2  skrll  * All rights reserved.
      6  1.4.4.2  skrll  *
      7  1.4.4.2  skrll  * Redistribution and use in source and binary forms, with or without
      8  1.4.4.2  skrll  * modification, are permitted provided that the following conditions
      9  1.4.4.2  skrll  * are met:
     10  1.4.4.2  skrll  * 1. Redistributions of source code must retain the above copyright
     11  1.4.4.2  skrll  *    notice, this list of conditions and the following disclaimer.
     12  1.4.4.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.4.4.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     14  1.4.4.2  skrll  *    documentation and/or other materials provided with the distribution.
     15  1.4.4.2  skrll  * 3. All advertising materials mentioning features or use of this software
     16  1.4.4.2  skrll  *    must display the following acknowledgement:
     17  1.4.4.2  skrll  *        This product includes software developed by the NetBSD
     18  1.4.4.2  skrll  *        Foundation, Inc. and its contributors.
     19  1.4.4.2  skrll  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.4.4.2  skrll  *    contributors may be used to endorse or promote products derived
     21  1.4.4.2  skrll  *    from this software without specific prior written permission.
     22  1.4.4.2  skrll  *
     23  1.4.4.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.4.4.2  skrll  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.4.4.2  skrll  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.4.4.2  skrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.4.4.2  skrll  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.4.4.2  skrll  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.4.4.2  skrll  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.4.4.2  skrll  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.4.4.2  skrll  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.4.4.2  skrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.4.4.2  skrll  * POSSIBILITY OF SUCH DAMAGE.
     34  1.4.4.2  skrll  *
     35  1.4.4.2  skrll  */
     36  1.4.4.2  skrll 
     37  1.4.4.2  skrll #include <sys/cdefs.h>
     38  1.4.4.4  skrll __KERNEL_RCSID(0, "$NetBSD: tspld.c,v 1.4.4.4 2005/11/10 13:55:54 skrll Exp $");
     39  1.4.4.2  skrll 
     40  1.4.4.2  skrll #include <sys/param.h>
     41  1.4.4.4  skrll #include <sys/callout.h>
     42  1.4.4.4  skrll #include <sys/kernel.h>
     43  1.4.4.3  skrll #include <sys/sysctl.h>
     44  1.4.4.2  skrll #include <sys/systm.h>
     45  1.4.4.2  skrll #include <sys/device.h>
     46  1.4.4.2  skrll #include <sys/wdog.h>
     47  1.4.4.2  skrll 
     48  1.4.4.2  skrll #include <machine/bus.h>
     49  1.4.4.2  skrll #include <machine/cpu.h>
     50  1.4.4.2  skrll #include <machine/autoconf.h>
     51  1.4.4.2  skrll #include "isa.h"
     52  1.4.4.2  skrll #if NISA > 0
     53  1.4.4.2  skrll #include <dev/isa/isavar.h>
     54  1.4.4.2  skrll #include <machine/isa_machdep.h>
     55  1.4.4.2  skrll #endif
     56  1.4.4.2  skrll 
     57  1.4.4.2  skrll #include <evbarm/tsarm/tsarmreg.h>
     58  1.4.4.2  skrll #include <evbarm/tsarm/tspldvar.h>
     59  1.4.4.2  skrll #include <arm/ep93xx/ep93xxvar.h>
     60  1.4.4.4  skrll #include <arm/ep93xx/ep93xxreg.h>
     61  1.4.4.2  skrll #include <arm/arm32/machdep.h>
     62  1.4.4.2  skrll #include <arm/cpufunc.h>
     63  1.4.4.2  skrll #include <dev/sysmon/sysmonvar.h>
     64  1.4.4.2  skrll 
     65  1.4.4.4  skrll int	tspldmatch (struct device *, struct cfdata *, void *);
     66  1.4.4.4  skrll void	tspldattach (struct device *, struct device *, void *);
     67  1.4.4.4  skrll static int	tspld_wdog_setmode (struct sysmon_wdog *);
     68  1.4.4.4  skrll static int	tspld_wdog_tickle (struct sysmon_wdog *);
     69  1.4.4.4  skrll int tspld_search (struct device *, struct cfdata *, const int *, void *);
     70  1.4.4.4  skrll int tspld_print (void *, const char *);
     71  1.4.4.4  skrll void boardtemp_poll (void *);
     72  1.4.4.2  skrll 
     73  1.4.4.2  skrll struct tspld_softc {
     74  1.4.4.2  skrll         struct device           sc_dev;
     75  1.4.4.2  skrll         bus_space_tag_t         sc_iot;
     76  1.4.4.2  skrll 	bus_space_handle_t	sc_wdogfeed_ioh;
     77  1.4.4.2  skrll 	bus_space_handle_t	sc_wdogctrl_ioh;
     78  1.4.4.2  skrll 	struct sysmon_wdog	sc_wdog;
     79  1.4.4.4  skrll 	bus_space_handle_t	sc_ssph;
     80  1.4.4.4  skrll 	bus_space_handle_t	sc_gpioh;
     81  1.4.4.4  skrll 	unsigned const char *	sc_com2mode;
     82  1.4.4.4  skrll 	unsigned const char *	sc_model;
     83  1.4.4.3  skrll 	unsigned char		sc_pldrev[4];
     84  1.4.4.3  skrll 	uint32_t		sc_rs485;
     85  1.4.4.3  skrll 	uint32_t		sc_adc;
     86  1.4.4.3  skrll 	uint32_t		sc_jp[6];
     87  1.4.4.3  skrll 	uint32_t		sc_blaster_present;
     88  1.4.4.3  skrll 	uint32_t		sc_blaster_boot;
     89  1.4.4.4  skrll 	uint32_t		boardtemp;
     90  1.4.4.4  skrll 	uint32_t		boardtemp_5s;
     91  1.4.4.4  skrll 	uint32_t		boardtemp_30s;
     92  1.4.4.4  skrll 	struct callout		boardtemp_callout;
     93  1.4.4.2  skrll };
     94  1.4.4.2  skrll 
     95  1.4.4.2  skrll CFATTACH_DECL(tspld, sizeof(struct tspld_softc),
     96  1.4.4.2  skrll     tspldmatch, tspldattach, NULL, NULL);
     97  1.4.4.2  skrll 
     98  1.4.4.2  skrll void	tspld_callback __P((struct device *));
     99  1.4.4.2  skrll 
    100  1.4.4.4  skrll #define GPIO_GET(x)	bus_space_read_4(sc->sc_iot, sc->sc_gpioh, \
    101  1.4.4.4  skrll 	(EP93XX_GPIO_ ## x))
    102  1.4.4.4  skrll 
    103  1.4.4.4  skrll #define GPIO_SET(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
    104  1.4.4.4  skrll 	(EP93XX_GPIO_ ## x), (y))
    105  1.4.4.4  skrll 
    106  1.4.4.4  skrll #define GPIO_SETBITS(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
    107  1.4.4.4  skrll 	(EP93XX_GPIO_ ## x), GPIO_GET(x) | (y))
    108  1.4.4.4  skrll 
    109  1.4.4.4  skrll #define GPIO_CLEARBITS(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, \
    110  1.4.4.4  skrll 	(EP93XX_GPIO_ ## x), GPIO_GET(x) & (~(y)))
    111  1.4.4.4  skrll 
    112  1.4.4.4  skrll #define SSP_GET(x)	bus_space_read_4(sc->sc_iot, sc->sc_ssph, \
    113  1.4.4.4  skrll 	(EP93XX_SSP_ ## x))
    114  1.4.4.4  skrll 
    115  1.4.4.4  skrll #define SSP_SET(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
    116  1.4.4.4  skrll 	(EP93XX_SSP_ ## x), (y))
    117  1.4.4.4  skrll 
    118  1.4.4.4  skrll #define SSP_SETBITS(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
    119  1.4.4.4  skrll 	(EP93XX_SSP_ ## x), SSP_GET(x) | (y))
    120  1.4.4.4  skrll 
    121  1.4.4.4  skrll #define SSP_CLEARBITS(x, y)	bus_space_write_4(sc->sc_iot, sc->sc_ssph, \
    122  1.4.4.4  skrll 	(EP93XX_SSP_ ## x), SSP_GET(x) & (~(y)))
    123  1.4.4.4  skrll 
    124  1.4.4.2  skrll int
    125  1.4.4.2  skrll tspldmatch(parent, match, aux)
    126  1.4.4.2  skrll 	struct device *parent;
    127  1.4.4.2  skrll 	struct cfdata *match;
    128  1.4.4.2  skrll 	void *aux;
    129  1.4.4.2  skrll {
    130  1.4.4.2  skrll 
    131  1.4.4.2  skrll 	return 1;
    132  1.4.4.2  skrll }
    133  1.4.4.2  skrll 
    134  1.4.4.2  skrll void
    135  1.4.4.4  skrll boardtemp_poll(arg)
    136  1.4.4.4  skrll 	void *arg;
    137  1.4.4.4  skrll {
    138  1.4.4.4  skrll 	struct tspld_softc *sc = arg;
    139  1.4.4.4  skrll 	u_int16_t val;
    140  1.4.4.4  skrll 
    141  1.4.4.4  skrll 	/* Disable chip select */
    142  1.4.4.4  skrll 	GPIO_SET(PFDDR, 0x0);
    143  1.4.4.4  skrll 
    144  1.4.4.4  skrll 	val = SSP_GET(SSPDR) & 0xffff;
    145  1.4.4.4  skrll 	sc->boardtemp = ((int16_t)val >> 3) * 62500;
    146  1.4.4.4  skrll 	sc->boardtemp_5s = sc->boardtemp_5s / 20 * 19 + sc->boardtemp / 20;
    147  1.4.4.4  skrll 	sc->boardtemp_30s = sc->boardtemp_30s / 120 * 119 + sc->boardtemp / 120;
    148  1.4.4.4  skrll 
    149  1.4.4.4  skrll 	callout_schedule(&sc->boardtemp_callout, hz / 4);
    150  1.4.4.4  skrll 
    151  1.4.4.4  skrll 	/* Enable chip select */
    152  1.4.4.4  skrll 	GPIO_SET(PFDDR, 0x4);
    153  1.4.4.4  skrll 
    154  1.4.4.4  skrll 	/* Send read command */
    155  1.4.4.4  skrll 	SSP_SET(SSPDR, 0x8000);
    156  1.4.4.4  skrll }
    157  1.4.4.4  skrll 
    158  1.4.4.4  skrll void
    159  1.4.4.2  skrll tspldattach(parent, self, aux)
    160  1.4.4.2  skrll 	struct device *parent, *self;
    161  1.4.4.2  skrll 	void *aux;
    162  1.4.4.2  skrll {
    163  1.4.4.2  skrll 	int	i, rev, features, jp, model;
    164  1.4.4.2  skrll 	struct tspld_softc *sc = (struct tspld_softc *)self;
    165  1.4.4.2  skrll 	bus_space_handle_t 	ioh;
    166  1.4.4.4  skrll         const struct sysctlnode *node;
    167  1.4.4.3  skrll 
    168  1.4.4.3  skrll 	if (sysctl_createv(NULL, 0, NULL, NULL,
    169  1.4.4.3  skrll 				CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw",
    170  1.4.4.3  skrll 				NULL, NULL, 0, NULL, 0,
    171  1.4.4.3  skrll 				CTL_HW, CTL_EOL) != 0) {
    172  1.4.4.3  skrll 		printf("%s: could not create sysctl\n",
    173  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    174  1.4.4.3  skrll 		return;
    175  1.4.4.3  skrll 	}
    176  1.4.4.3  skrll 	if (sysctl_createv(NULL, 0, NULL, &node,
    177  1.4.4.4  skrll         			0, CTLTYPE_NODE, sc->sc_dev.dv_xname,
    178  1.4.4.3  skrll         			NULL,
    179  1.4.4.3  skrll         			NULL, 0, NULL, 0,
    180  1.4.4.3  skrll 				CTL_HW, CTL_CREATE, CTL_EOL) != 0) {
    181  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    182  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    183  1.4.4.3  skrll 		return;
    184  1.4.4.3  skrll 	}
    185  1.4.4.2  skrll 
    186  1.4.4.2  skrll 	sc->sc_iot = &ep93xx_bs_tag;
    187  1.4.4.4  skrll 	bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_MODEL, 2, 0,
    188  1.4.4.2  skrll 		&ioh);
    189  1.4.4.2  skrll 	model = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    190  1.4.4.3  skrll 	sc->sc_model = (model ? "TS-7250" : "TS-7200");
    191  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    192  1.4.4.3  skrll         			0, CTLTYPE_STRING, "boardmodel",
    193  1.4.4.3  skrll         			SYSCTL_DESCR("Technologic Systems board model"),
    194  1.4.4.4  skrll         			NULL, 0, __UNCONST(sc->sc_model), 0,
    195  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    196  1.4.4.3  skrll 				!= 0) {
    197  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    198  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    199  1.4.4.3  skrll 		return;
    200  1.4.4.3  skrll 	}
    201  1.4.4.2  skrll 	bus_space_unmap(sc->sc_iot, ioh, 2);
    202  1.4.4.2  skrll 
    203  1.4.4.4  skrll 	bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_PLDREV, 2, 0,
    204  1.4.4.2  skrll 		&ioh);
    205  1.4.4.2  skrll 	rev = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    206  1.4.4.2  skrll 	rev = 'A' + rev - 1;
    207  1.4.4.3  skrll 	sc->sc_pldrev[0] = rev;
    208  1.4.4.3  skrll 	sc->sc_pldrev[1] = 0;
    209  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    210  1.4.4.3  skrll         			0, CTLTYPE_STRING, "pldrev",
    211  1.4.4.3  skrll         			SYSCTL_DESCR("CPLD revision"),
    212  1.4.4.3  skrll         			NULL, 0, sc->sc_pldrev, 0,
    213  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    214  1.4.4.3  skrll 				!= 0) {
    215  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    216  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    217  1.4.4.3  skrll 		return;
    218  1.4.4.3  skrll 	}
    219  1.4.4.2  skrll 	bus_space_unmap(sc->sc_iot, ioh, 2);
    220  1.4.4.2  skrll 
    221  1.4.4.4  skrll 	bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_FEATURES, 2, 0,
    222  1.4.4.2  skrll 		&ioh);
    223  1.4.4.2  skrll 	features = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    224  1.4.4.2  skrll 	bus_space_unmap(sc->sc_iot, ioh, 2);
    225  1.4.4.2  skrll 
    226  1.4.4.2  skrll         bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_STATUS1, 1, 0,
    227  1.4.4.2  skrll 		&ioh);
    228  1.4.4.2  skrll 	i = bus_space_read_1(sc->sc_iot, ioh, 0) & 0x1f;
    229  1.4.4.2  skrll 	jp = (~((i & 0x18) >> 1) & 0xc) | (i & 0x3);
    230  1.4.4.2  skrll 	bus_space_unmap(sc->sc_iot, ioh, 1);
    231  1.4.4.2  skrll 
    232  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    233  1.4.4.3  skrll         			0, CTLTYPE_INT, "blaster_present",
    234  1.4.4.3  skrll         			SYSCTL_DESCR("Whether or not a TS-9420/TS-9202 blaster board is connected"),
    235  1.4.4.3  skrll         			NULL, 0, &sc->sc_blaster_present, 0,
    236  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    237  1.4.4.3  skrll 				!= 0) {
    238  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    239  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    240  1.4.4.3  skrll 		return;
    241  1.4.4.3  skrll 	}
    242  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    243  1.4.4.3  skrll         			0, CTLTYPE_INT, "blaster_boot",
    244  1.4.4.3  skrll         			SYSCTL_DESCR("Whether or not a blast board was used to boot"),
    245  1.4.4.3  skrll         			NULL, 0, &sc->sc_blaster_boot, 0,
    246  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    247  1.4.4.3  skrll 				!= 0) {
    248  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    249  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    250  1.4.4.3  skrll 		return;
    251  1.4.4.3  skrll 	}
    252  1.4.4.2  skrll         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_STATUS2, 2, 0,
    253  1.4.4.2  skrll 		&ioh);
    254  1.4.4.4  skrll 	i = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x6;
    255  1.4.4.3  skrll 	sc->sc_blaster_boot = sc->sc_blaster_present = 0;
    256  1.4.4.3  skrll 	if (i & 0x2)
    257  1.4.4.3  skrll 		sc->sc_blaster_boot = 1;
    258  1.4.4.3  skrll 	if (i & 0x4)
    259  1.4.4.3  skrll 		sc->sc_blaster_present = 1;
    260  1.4.4.2  skrll 	jp |= (i << 4);
    261  1.4.4.2  skrll 	bus_space_unmap(sc->sc_iot, ioh, 1);
    262  1.4.4.2  skrll 
    263  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    264  1.4.4.3  skrll         			0, CTLTYPE_INT, "rs485_avail",
    265  1.4.4.3  skrll         			SYSCTL_DESCR("RS485 level driver for COM2 available"),
    266  1.4.4.3  skrll         			NULL, 0, &sc->sc_rs485, 0,
    267  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    268  1.4.4.3  skrll 				!= 0) {
    269  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    270  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    271  1.4.4.3  skrll 		return;
    272  1.4.4.3  skrll 	}
    273  1.4.4.3  skrll 	sc->sc_com2mode = "rs232";
    274  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    275  1.4.4.3  skrll         			0, CTLTYPE_STRING, "com2_mode",
    276  1.4.4.3  skrll         			SYSCTL_DESCR("line driver type for COM2"),
    277  1.4.4.4  skrll         			NULL, 0, __UNCONST(sc->sc_com2mode), 0,
    278  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    279  1.4.4.3  skrll 				!= 0) {
    280  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    281  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    282  1.4.4.3  skrll 		return;
    283  1.4.4.3  skrll 	}
    284  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    285  1.4.4.3  skrll         			0, CTLTYPE_INT, "max197adc_avail",
    286  1.4.4.3  skrll         			SYSCTL_DESCR("Maxim 197 Analog to Digital Converter available"),
    287  1.4.4.3  skrll         			NULL, 0, &sc->sc_adc, 0,
    288  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    289  1.4.4.3  skrll 				!= 0) {
    290  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    291  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    292  1.4.4.3  skrll 		return;
    293  1.4.4.3  skrll 	}
    294  1.4.4.3  skrll 	printf(": Technologic Systems %s rev %c, features 0x%x",
    295  1.4.4.3  skrll 		sc->sc_model, rev, features);
    296  1.4.4.3  skrll 	sc->sc_adc = sc->sc_rs485 = 0;
    297  1.4.4.3  skrll 	if (features == 0x1) {
    298  1.4.4.2  skrll 		printf("<MAX197-ADC>");
    299  1.4.4.3  skrll 		sc->sc_adc = 1;
    300  1.4.4.3  skrll 	} else if (features == 0x2) {
    301  1.4.4.2  skrll 		printf("<RS485>");
    302  1.4.4.3  skrll 		sc->sc_rs485 = 1;
    303  1.4.4.3  skrll 	} else if (features == 0x3) {
    304  1.4.4.2  skrll 		printf("<MAX197-ADC,RS485>");
    305  1.4.4.3  skrll 		sc->sc_adc = sc->sc_rs485 = 1;
    306  1.4.4.3  skrll 	}
    307  1.4.4.2  skrll 	printf("\n");
    308  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    309  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp1",
    310  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    311  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[0], 0,
    312  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    313  1.4.4.3  skrll 				!= 0) {
    314  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    315  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    316  1.4.4.3  skrll 		return;
    317  1.4.4.3  skrll 	}
    318  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    319  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp2",
    320  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    321  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[1], 0,
    322  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    323  1.4.4.3  skrll 				!= 0) {
    324  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    325  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    326  1.4.4.3  skrll 		return;
    327  1.4.4.3  skrll 	}
    328  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    329  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp3",
    330  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    331  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[2], 0,
    332  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    333  1.4.4.3  skrll 				!= 0) {
    334  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    335  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    336  1.4.4.3  skrll 		return;
    337  1.4.4.3  skrll 	}
    338  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    339  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp4",
    340  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    341  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[3], 0,
    342  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    343  1.4.4.3  skrll 				!= 0) {
    344  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    345  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    346  1.4.4.3  skrll 		return;
    347  1.4.4.3  skrll 	}
    348  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    349  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp5",
    350  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    351  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[4], 0,
    352  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    353  1.4.4.3  skrll 				!= 0) {
    354  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    355  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    356  1.4.4.3  skrll 		return;
    357  1.4.4.3  skrll 	}
    358  1.4.4.3  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    359  1.4.4.3  skrll         			0, CTLTYPE_INT, "jp6",
    360  1.4.4.3  skrll         			SYSCTL_DESCR("onboard jumper setting"),
    361  1.4.4.3  skrll         			NULL, 0, &sc->sc_jp[5], 0,
    362  1.4.4.3  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    363  1.4.4.3  skrll 				!= 0) {
    364  1.4.4.3  skrll                 printf("%s: could not create sysctl\n",
    365  1.4.4.3  skrll 			sc->sc_dev.dv_xname);
    366  1.4.4.3  skrll 		return;
    367  1.4.4.3  skrll 	}
    368  1.4.4.2  skrll 	printf("%s: jumpers 0x%x", sc->sc_dev.dv_xname, jp);
    369  1.4.4.2  skrll 	if (jp) {
    370  1.4.4.2  skrll 		printf("<");
    371  1.4.4.2  skrll 		for(i = 0; i < 5; i++) {
    372  1.4.4.2  skrll 			if (jp & (1 << i)) {
    373  1.4.4.3  skrll 				sc->sc_jp[i + 1] = 1;
    374  1.4.4.2  skrll 				printf("JP%d", i + 2);
    375  1.4.4.2  skrll 				jp &= ~(1 << i);
    376  1.4.4.2  skrll 				if (jp) printf(",");
    377  1.4.4.3  skrll 			} else {
    378  1.4.4.3  skrll 				sc->sc_jp[i + 2] = 0;
    379  1.4.4.2  skrll 			}
    380  1.4.4.2  skrll 		}
    381  1.4.4.2  skrll 		printf(">");
    382  1.4.4.2  skrll 	}
    383  1.4.4.2  skrll 	printf("\n");
    384  1.4.4.2  skrll 
    385  1.4.4.4  skrll 
    386  1.4.4.4  skrll         bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_SSP,
    387  1.4.4.4  skrll 		EP93XX_APB_SSP_SIZE, 0, &sc->sc_ssph);
    388  1.4.4.4  skrll         bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_GPIO,
    389  1.4.4.4  skrll 		EP93XX_APB_GPIO_SIZE, 0, &sc->sc_gpioh);
    390  1.4.4.4  skrll 	SSP_SETBITS(SSPCR1, 0x10);
    391  1.4.4.4  skrll 	SSP_SET(SSPCR0, 0xf);
    392  1.4.4.4  skrll 	SSP_SET(SSPCPSR, 0xfe);
    393  1.4.4.4  skrll 	SSP_CLEARBITS(SSPCR1, 0x10);
    394  1.4.4.4  skrll 	SSP_SETBITS(SSPCR1, 0x10);
    395  1.4.4.4  skrll 	GPIO_SET(PFDR, 0x0);
    396  1.4.4.4  skrll 	callout_init(&sc->boardtemp_callout);
    397  1.4.4.4  skrll 	callout_setfunc(&sc->boardtemp_callout, boardtemp_poll, sc);
    398  1.4.4.4  skrll 	boardtemp_poll(sc);
    399  1.4.4.4  skrll 	delay(1000);
    400  1.4.4.4  skrll 	boardtemp_poll(sc);
    401  1.4.4.4  skrll 	sc->boardtemp_5s = sc->boardtemp_30s = sc->boardtemp;
    402  1.4.4.4  skrll #define DEGF(c)	((c) * 9 / 5 + 32000000)
    403  1.4.4.4  skrll 	printf("%s: board temperature %d.%02d degC (%d.%02d degF)\n",
    404  1.4.4.4  skrll 		sc->sc_dev.dv_xname,
    405  1.4.4.4  skrll 		sc->boardtemp / 1000000, sc->boardtemp / 10000 % 100,
    406  1.4.4.4  skrll 		DEGF(sc->boardtemp) / 1000000, DEGF(sc->boardtemp) / 10000 % 100);
    407  1.4.4.4  skrll #undef DEGF
    408  1.4.4.4  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    409  1.4.4.4  skrll         			0, CTLTYPE_INT, "board_temp",
    410  1.4.4.4  skrll         			SYSCTL_DESCR("board temperature in micro degrees Celsius"),
    411  1.4.4.4  skrll         			NULL, 0, &sc->boardtemp, 0,
    412  1.4.4.4  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    413  1.4.4.4  skrll 				!= 0) {
    414  1.4.4.4  skrll                 printf("%s: could not create sysctl\n",
    415  1.4.4.4  skrll 			sc->sc_dev.dv_xname);
    416  1.4.4.4  skrll 		return;
    417  1.4.4.4  skrll 	}
    418  1.4.4.4  skrll 
    419  1.4.4.4  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    420  1.4.4.4  skrll         			0, CTLTYPE_INT, "board_temp_5s",
    421  1.4.4.4  skrll         			SYSCTL_DESCR("5 second average board temperature in micro degrees Celsius"),
    422  1.4.4.4  skrll         			NULL, 0, &sc->boardtemp_5s, 0,
    423  1.4.4.4  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    424  1.4.4.4  skrll 				!= 0) {
    425  1.4.4.4  skrll                 printf("%s: could not create sysctl\n",
    426  1.4.4.4  skrll 			sc->sc_dev.dv_xname);
    427  1.4.4.4  skrll 		return;
    428  1.4.4.4  skrll 	}
    429  1.4.4.4  skrll 
    430  1.4.4.4  skrll 	if ((i = sysctl_createv(NULL, 0, NULL, NULL,
    431  1.4.4.4  skrll         			0, CTLTYPE_INT, "board_temp_30s",
    432  1.4.4.4  skrll         			SYSCTL_DESCR("30 second average board temperature in micro degrees Celsius"),
    433  1.4.4.4  skrll         			NULL, 0, &sc->boardtemp_30s, 0,
    434  1.4.4.4  skrll 				CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL))
    435  1.4.4.4  skrll 				!= 0) {
    436  1.4.4.4  skrll                 printf("%s: could not create sysctl\n",
    437  1.4.4.4  skrll 			sc->sc_dev.dv_xname);
    438  1.4.4.4  skrll 		return;
    439  1.4.4.4  skrll 	}
    440  1.4.4.4  skrll 
    441  1.4.4.2  skrll         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGCTRL, 2, 0,
    442  1.4.4.2  skrll 		&sc->sc_wdogctrl_ioh);
    443  1.4.4.2  skrll         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGFEED, 2, 0,
    444  1.4.4.2  skrll 		&sc->sc_wdogfeed_ioh);
    445  1.4.4.2  skrll 
    446  1.4.4.2  skrll 	sc->sc_wdog.smw_name = sc->sc_dev.dv_xname;
    447  1.4.4.2  skrll 	sc->sc_wdog.smw_cookie = sc;
    448  1.4.4.2  skrll 	sc->sc_wdog.smw_setmode = tspld_wdog_setmode;
    449  1.4.4.2  skrll 	sc->sc_wdog.smw_tickle = tspld_wdog_tickle;
    450  1.4.4.2  skrll 	sc->sc_wdog.smw_period = 8;
    451  1.4.4.2  skrll 	sysmon_wdog_register(&sc->sc_wdog);
    452  1.4.4.2  skrll 	tspld_wdog_setmode(&sc->sc_wdog);
    453  1.4.4.2  skrll 
    454  1.4.4.2  skrll 	/* Set the on board peripherals bus callback */
    455  1.4.4.2  skrll 	config_defer(self, tspld_callback);
    456  1.4.4.2  skrll }
    457  1.4.4.2  skrll 
    458  1.4.4.2  skrll int
    459  1.4.4.4  skrll tspld_search(parent, cf, ldesc, aux)
    460  1.4.4.2  skrll 	struct device *parent;
    461  1.4.4.2  skrll 	struct cfdata *cf;
    462  1.4.4.4  skrll 	const int *ldesc;
    463  1.4.4.2  skrll 	void *aux;
    464  1.4.4.2  skrll {
    465  1.4.4.2  skrll 	struct tspld_softc *sc = (struct tspld_softc *)parent;
    466  1.4.4.2  skrll 	struct tspld_attach_args sa;
    467  1.4.4.2  skrll 
    468  1.4.4.2  skrll 	sa.ta_iot = sc->sc_iot;
    469  1.4.4.2  skrll 
    470  1.4.4.2  skrll 	if (config_match(parent, cf, &sa) > 0)
    471  1.4.4.2  skrll 		config_attach(parent, cf, &sa, tspld_print);
    472  1.4.4.2  skrll 
    473  1.4.4.2  skrll 	return (0);
    474  1.4.4.2  skrll }
    475  1.4.4.2  skrll 
    476  1.4.4.2  skrll int
    477  1.4.4.2  skrll tspld_print(aux, name)
    478  1.4.4.2  skrll 	void *aux;
    479  1.4.4.2  skrll 	const char *name;
    480  1.4.4.2  skrll {
    481  1.4.4.2  skrll 
    482  1.4.4.2  skrll 	return (UNCONF);
    483  1.4.4.2  skrll }
    484  1.4.4.2  skrll 
    485  1.4.4.2  skrll void
    486  1.4.4.2  skrll tspld_callback(self)
    487  1.4.4.2  skrll 	struct device *self;
    488  1.4.4.2  skrll {
    489  1.4.4.2  skrll #if NISA > 0
    490  1.4.4.2  skrll 	extern void isa_bs_mallocok(void);
    491  1.4.4.2  skrll 	struct isabus_attach_args iba;
    492  1.4.4.2  skrll 
    493  1.4.4.2  skrll 	/*
    494  1.4.4.2  skrll 	 * Attach the ISA bus behind this bridge.
    495  1.4.4.2  skrll 	 */
    496  1.4.4.2  skrll 	memset(&iba, 0, sizeof(iba));
    497  1.4.4.2  skrll 	iba.iba_iot = &isa_io_bs_tag;
    498  1.4.4.2  skrll 	iba.iba_memt = &isa_mem_bs_tag;
    499  1.4.4.2  skrll 	isa_bs_mallocok();
    500  1.4.4.2  skrll 	config_found_ia(self, "isabus", &iba, isabusprint);
    501  1.4.4.2  skrll #endif
    502  1.4.4.2  skrll 	/*
    503  1.4.4.2  skrll 	 *  Attach each devices
    504  1.4.4.2  skrll 	 */
    505  1.4.4.4  skrll 	config_search_ia(tspld_search, self, "tspldbus", NULL);
    506  1.4.4.2  skrll 
    507  1.4.4.2  skrll }
    508  1.4.4.2  skrll 
    509  1.4.4.2  skrll static int
    510  1.4.4.2  skrll tspld_wdog_tickle(smw)
    511  1.4.4.2  skrll 	struct sysmon_wdog *smw;
    512  1.4.4.2  skrll {
    513  1.4.4.2  skrll 	struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
    514  1.4.4.2  skrll 
    515  1.4.4.2  skrll 	bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    516  1.4.4.2  skrll 	return 0;
    517  1.4.4.2  skrll }
    518  1.4.4.2  skrll 
    519  1.4.4.2  skrll static int
    520  1.4.4.2  skrll tspld_wdog_setmode(smw)
    521  1.4.4.2  skrll 	struct sysmon_wdog *smw;
    522  1.4.4.2  skrll {
    523  1.4.4.2  skrll 	int i, ret = 0;
    524  1.4.4.2  skrll 	struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
    525  1.4.4.2  skrll 
    526  1.4.4.2  skrll 	i = disable_interrupts(I32_bit|F32_bit);
    527  1.4.4.2  skrll 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    528  1.4.4.2  skrll 		bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    529  1.4.4.2  skrll 		bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0, 0);
    530  1.4.4.2  skrll 	} else {
    531  1.4.4.2  skrll 		bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    532  1.4.4.2  skrll 		switch (smw->smw_period) {
    533  1.4.4.2  skrll 		case 1:
    534  1.4.4.2  skrll 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    535  1.4.4.2  skrll 				0x3);
    536  1.4.4.2  skrll 			break;
    537  1.4.4.2  skrll 		case 2:
    538  1.4.4.2  skrll 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    539  1.4.4.2  skrll 				0x5);
    540  1.4.4.2  skrll 			break;
    541  1.4.4.2  skrll 		case 4:
    542  1.4.4.2  skrll 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    543  1.4.4.2  skrll 				0x6);
    544  1.4.4.2  skrll 			break;
    545  1.4.4.2  skrll 		case 8:
    546  1.4.4.2  skrll 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    547  1.4.4.2  skrll 				0x7);
    548  1.4.4.2  skrll 			break;
    549  1.4.4.2  skrll 		default:
    550  1.4.4.2  skrll 			ret = EINVAL;
    551  1.4.4.2  skrll 		}
    552  1.4.4.2  skrll 	}
    553  1.4.4.2  skrll 	restore_interrupts(i);
    554  1.4.4.2  skrll 	return ret;
    555  1.4.4.2  skrll }
    556