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