Home | History | Annotate | Line # | Download | only in tsarm
tspld.c revision 1.2
      1 /*	$NetBSD: tspld.c,v 1.2 2004/12/26 22:02:11 joff Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2004 Jesse Off
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *        This product includes software developed by the NetBSD
     18  *        Foundation, Inc. and its contributors.
     19  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  *    contributors may be used to endorse or promote products derived
     21  *    from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  * POSSIBILITY OF SUCH DAMAGE.
     34  *
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: tspld.c,v 1.2 2004/12/26 22:02:11 joff Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/device.h>
     43 #include <sys/wdog.h>
     44 
     45 #include <machine/bus.h>
     46 #include <machine/cpu.h>
     47 #include <machine/autoconf.h>
     48 #include "isa.h"
     49 #if NISA > 0
     50 #include <dev/isa/isavar.h>
     51 #include <machine/isa_machdep.h>
     52 #endif
     53 
     54 #include <evbarm/tsarm/tsarmreg.h>
     55 #include <evbarm/tsarm/tspldvar.h>
     56 #include <arm/ep93xx/ep93xxvar.h>
     57 #include <arm/arm32/machdep.h>
     58 #include <arm/cpufunc.h>
     59 #include <dev/sysmon/sysmonvar.h>
     60 
     61 int	tspldmatch __P((struct device *, struct cfdata *, void *));
     62 void	tspldattach __P((struct device *, struct device *, void *));
     63 static int	tspld_wdog_setmode __P((struct sysmon_wdog *));
     64 static int	tspld_wdog_tickle __P((struct sysmon_wdog *));
     65 
     66 struct tspld_softc {
     67         struct device           sc_dev;
     68         bus_space_tag_t         sc_iot;
     69 	bus_space_handle_t	sc_wdogfeed_ioh;
     70 	bus_space_handle_t	sc_wdogctrl_ioh;
     71 	struct sysmon_wdog	sc_wdog;
     72 };
     73 
     74 
     75 CFATTACH_DECL(tspld, sizeof(struct tspld_softc),
     76     tspldmatch, tspldattach, NULL, NULL);
     77 
     78 void	tspld_callback __P((struct device *));
     79 
     80 int
     81 tspldmatch(parent, match, aux)
     82 	struct device *parent;
     83 	struct cfdata *match;
     84 	void *aux;
     85 {
     86 
     87 	return 1;
     88 }
     89 
     90 void
     91 tspldattach(parent, self, aux)
     92 	struct device *parent, *self;
     93 	void *aux;
     94 {
     95 	int	i, rev, features, jp, model;
     96 	struct tspld_softc *sc = (struct tspld_softc *)self;
     97 	struct tspld_attach_args ta;
     98 	bus_space_handle_t 	ioh;
     99 
    100 	sc->sc_iot = &ep93xx_bs_tag;
    101         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_MODEL, 2, 0,
    102 		&ioh);
    103 	model = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    104 	bus_space_unmap(sc->sc_iot, ioh, 2);
    105 
    106         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_PLDREV, 2, 0,
    107 		&ioh);
    108 	rev = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    109 	rev = 'A' + rev - 1;
    110 	bus_space_unmap(sc->sc_iot, ioh, 2);
    111 
    112         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_FEATURES, 2, 0,
    113 		&ioh);
    114 	features = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x7;
    115 	bus_space_unmap(sc->sc_iot, ioh, 2);
    116 
    117         bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_STATUS1, 1, 0,
    118 		&ioh);
    119 	i = bus_space_read_1(sc->sc_iot, ioh, 0) & 0x1f;
    120 	jp = (~((i & 0x18) >> 1) & 0xc) | (i & 0x3);
    121 	bus_space_unmap(sc->sc_iot, ioh, 1);
    122 
    123         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_STATUS2, 2, 0,
    124 		&ioh);
    125 	i = bus_space_read_2(sc->sc_iot, ioh, 0) & 0x1;
    126 	jp |= (i << 4);
    127 	bus_space_unmap(sc->sc_iot, ioh, 1);
    128 
    129 	printf(": Technologic Systems TS-7%s rev %c, features 0x%x",
    130 		(model ? "250" : "200"), rev, features);
    131 	if (features == 0x1)
    132 		printf("<MAX197-ADC>");
    133 	else if (features == 0x2)
    134 		printf("<RS485>");
    135 	else if (features == 0x3)
    136 		printf("<MAX197-ADC,RS485>");
    137 	printf("\n");
    138 	printf("%s: jumpers 0x%x", sc->sc_dev.dv_xname, jp);
    139 	if (jp) {
    140 		printf("<");
    141 		for(i = 0; i < 5; i++) {
    142 			if (jp & (1 << i)) {
    143 				printf("JP%d", i + 2);
    144 				jp &= ~(1 << i);
    145 				if (jp) printf(",");
    146 			}
    147 		}
    148 		printf(">");
    149 	}
    150 	printf("\n");
    151 
    152         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGCTRL, 2, 0,
    153 		&sc->sc_wdogctrl_ioh);
    154         bus_space_map(sc->sc_iot, TS7XXX_IO16_HWBASE + TS7XXX_WDOGFEED, 2, 0,
    155 		&sc->sc_wdogfeed_ioh);
    156 
    157 	sc->sc_wdog.smw_name = sc->sc_dev.dv_xname;
    158 	sc->sc_wdog.smw_cookie = sc;
    159 	sc->sc_wdog.smw_setmode = tspld_wdog_setmode;
    160 	sc->sc_wdog.smw_tickle = tspld_wdog_tickle;
    161 	sc->sc_wdog.smw_period = 8;
    162 	sysmon_wdog_register(&sc->sc_wdog);
    163 	tspld_wdog_setmode(&sc->sc_wdog);
    164 
    165 	ta.ta_iot = sc->sc_iot;
    166 	config_found_ia(self, "tspldbus", &ta, NULL);
    167 
    168 	/* Set the on board peripherals bus callback */
    169 	config_defer(self, tspld_callback);
    170 }
    171 
    172 void
    173 tspld_callback(self)
    174 	struct device *self;
    175 {
    176 #if NISA > 0
    177 	struct isabus_attach_args iba;
    178 
    179 	/*
    180 	 * Attach the ISA bus behind this bridge.
    181 	 */
    182 	memset(&iba, 0, sizeof(iba));
    183 	iba.iba_iot = &isa_io_bs_tag;
    184 	iba.iba_memt = &isa_mem_bs_tag;
    185 	config_found_ia(self, "isabus", &iba, isabusprint);
    186 #endif
    187 }
    188 
    189 static int
    190 tspld_wdog_tickle(smw)
    191 	struct sysmon_wdog *smw;
    192 {
    193 	struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
    194 
    195 	bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    196 	return 0;
    197 }
    198 
    199 static int
    200 tspld_wdog_setmode(smw)
    201 	struct sysmon_wdog *smw;
    202 {
    203 	int i, ret = 0;
    204 	struct tspld_softc *sc = (struct tspld_softc *)smw->smw_cookie;
    205 
    206 	i = disable_interrupts(I32_bit|F32_bit);
    207 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    208 		bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    209 		bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0, 0);
    210 	} else {
    211 		bus_space_write_2(sc->sc_iot, sc->sc_wdogfeed_ioh, 0, 0x5);
    212 		switch (smw->smw_period) {
    213 		case 1:
    214 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    215 				0x3);
    216 			break;
    217 		case 2:
    218 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    219 				0x5);
    220 			break;
    221 		case 4:
    222 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    223 				0x6);
    224 			break;
    225 		case 8:
    226 			bus_space_write_2(sc->sc_iot, sc->sc_wdogctrl_ioh, 0,
    227 				0x7);
    228 			break;
    229 		default:
    230 			ret = EINVAL;
    231 		}
    232 	}
    233 	restore_interrupts(i);
    234 	return ret;
    235 }
    236