Home | History | Annotate | Line # | Download | only in dev
intio.c revision 1.25.10.1
      1  1.25.10.1     rmind /*	$NetBSD: intio.c,v 1.25.10.1 2007/03/12 05:47:44 rmind Exp $	*/
      2        1.1   thorpej 
      3        1.1   thorpej /*-
      4        1.7  gmcgarry  * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
      5        1.1   thorpej  * All rights reserved.
      6        1.1   thorpej  *
      7        1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1   thorpej  * by Jason R. Thorpe.
      9        1.1   thorpej  *
     10        1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11        1.1   thorpej  * modification, are permitted provided that the following conditions
     12        1.1   thorpej  * are met:
     13        1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14        1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15        1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17        1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18        1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     19        1.1   thorpej  *    must display the following acknowledgement:
     20        1.1   thorpej  *        This product includes software developed by the NetBSD
     21        1.1   thorpej  *        Foundation, Inc. and its contributors.
     22        1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1   thorpej  *    contributors may be used to endorse or promote products derived
     24        1.1   thorpej  *    from this software without specific prior written permission.
     25        1.1   thorpej  *
     26        1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.3       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.3       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37        1.1   thorpej  */
     38        1.1   thorpej 
     39        1.1   thorpej /*
     40        1.1   thorpej  * Autoconfiguration support for hp300 internal i/o space.
     41        1.1   thorpej  */
     42        1.1   thorpej 
     43        1.8  gmcgarry #include <sys/cdefs.h>
     44  1.25.10.1     rmind __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.25.10.1 2007/03/12 05:47:44 rmind Exp $");
     45        1.8  gmcgarry 
     46        1.1   thorpej #include <sys/param.h>
     47        1.1   thorpej #include <sys/systm.h>
     48       1.18   tsutsui #include <sys/device.h>
     49        1.7  gmcgarry 
     50        1.7  gmcgarry #include <machine/hp300spu.h>
     51        1.7  gmcgarry 
     52       1.18   tsutsui #include <hp300/dev/intioreg.h>
     53        1.1   thorpej #include <hp300/dev/intiovar.h>
     54        1.1   thorpej 
     55       1.17   tsutsui struct intio_softc {
     56       1.17   tsutsui 	struct device sc_dev;
     57       1.17   tsutsui 	struct bus_space_tag sc_tag;
     58       1.17   tsutsui };
     59       1.17   tsutsui 
     60       1.19   thorpej static int	intiomatch(struct device *, struct cfdata *, void *);
     61       1.19   thorpej static void	intioattach(struct device *, struct device *, void *);
     62       1.19   thorpej static int	intioprint(void *, const char *);
     63        1.1   thorpej 
     64       1.17   tsutsui CFATTACH_DECL(intio, sizeof(struct intio_softc),
     65       1.12   thorpej     intiomatch, intioattach, NULL, NULL);
     66        1.1   thorpej 
     67        1.7  gmcgarry #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
     68        1.7  gmcgarry     defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
     69        1.7  gmcgarry     defined(HP380) || defined(HP385)
     70       1.19   thorpej static const struct intio_builtins intio_3xx_builtins[] = {
     71       1.22   tsutsui 	{ "rtc",	RTC_BASE,	-1},
     72       1.22   tsutsui 	{ "hil",	HIL_BASE,	1},
     73       1.22   tsutsui 	{ "hpib",	HPIB_BASE,	3},
     74       1.22   tsutsui 	{ "dma",	DMA_BASE,	1},
     75       1.22   tsutsui 	{ "fb",		FB_BASE,	-1},
     76        1.7  gmcgarry };
     77       1.21   tsutsui #define nintio_3xx_builtins	__arraycount(intio_3xx_builtins)
     78        1.7  gmcgarry #endif
     79        1.7  gmcgarry 
     80       1.25   tsutsui #if defined(HP362) || defined(HP382)
     81       1.25   tsutsui static const struct intio_builtins intio_3x2_builtins[] = {
     82       1.25   tsutsui 	{ "rtc",	RTC_BASE,	-1},
     83       1.25   tsutsui 	{ "frodo",	FRODO_BASE,	5},
     84       1.25   tsutsui 	{ "hil",	HIL_BASE,	1},
     85       1.25   tsutsui 	{ "hpib",	HPIB_BASE,	3},
     86       1.25   tsutsui 	{ "dma",	DMA_BASE,	1},
     87       1.25   tsutsui };
     88       1.25   tsutsui #define nintio_3x2_builtins	__arraycount(intio_3x2_builtins)
     89       1.25   tsutsui #endif
     90       1.25   tsutsui 
     91        1.7  gmcgarry #if defined(HP400) || defined(HP425) || defined(HP433)
     92       1.19   thorpej static const struct intio_builtins intio_4xx_builtins[] = {
     93       1.22   tsutsui 	{ "rtc",	RTC_BASE,	-1},
     94       1.22   tsutsui 	{ "frodo",	FRODO_BASE,	5},
     95       1.22   tsutsui 	{ "hil",	HIL_BASE,	1},
     96       1.22   tsutsui 	{ "hpib",	HPIB_BASE,	3},
     97       1.22   tsutsui 	{ "dma",	DMA_BASE,	1},
     98        1.7  gmcgarry };
     99       1.21   tsutsui #define nintio_4xx_builtins	__arraycount(intio_4xx_builtins)
    100        1.7  gmcgarry #endif
    101        1.7  gmcgarry 
    102        1.7  gmcgarry static int intio_matched = 0;
    103  1.25.10.1     rmind extern void *internalhpib;
    104        1.7  gmcgarry 
    105       1.19   thorpej static int
    106       1.19   thorpej intiomatch(struct device *parent, struct cfdata *match, void *aux)
    107        1.1   thorpej {
    108        1.1   thorpej 	/* Allow only one instance. */
    109        1.1   thorpej 	if (intio_matched)
    110       1.21   tsutsui 		return 0;
    111        1.1   thorpej 
    112        1.1   thorpej 	intio_matched = 1;
    113       1.21   tsutsui 	return 1;
    114        1.1   thorpej }
    115        1.1   thorpej 
    116       1.19   thorpej static void
    117       1.19   thorpej intioattach(struct device *parent, struct device *self, void *aux)
    118        1.1   thorpej {
    119       1.17   tsutsui 	struct intio_softc *sc = (struct intio_softc *)self;
    120        1.7  gmcgarry 	struct intio_attach_args ia;
    121        1.7  gmcgarry 	const struct intio_builtins *ib;
    122       1.17   tsutsui 	bus_space_tag_t bst = &sc->sc_tag;
    123        1.7  gmcgarry 	int ndevs;
    124        1.7  gmcgarry 	int i;
    125        1.1   thorpej 
    126        1.1   thorpej 	printf("\n");
    127        1.1   thorpej 
    128       1.17   tsutsui 	memset(bst, 0, sizeof(struct bus_space_tag));
    129       1.17   tsutsui 	bst->bustype = HP300_BUS_SPACE_INTIO;
    130       1.17   tsutsui 
    131        1.7  gmcgarry 	switch (machineid) {
    132        1.7  gmcgarry #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
    133        1.7  gmcgarry     defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
    134        1.7  gmcgarry     defined(HP380) || defined(HP385)
    135        1.7  gmcgarry 	case HP_320:
    136        1.7  gmcgarry 	case HP_330:
    137        1.7  gmcgarry 	case HP_340:
    138        1.7  gmcgarry 	case HP_345:
    139        1.7  gmcgarry 	case HP_350:
    140        1.7  gmcgarry 	case HP_360:
    141        1.7  gmcgarry 	case HP_370:
    142        1.7  gmcgarry 	case HP_375:
    143        1.7  gmcgarry 	case HP_380:
    144        1.7  gmcgarry 	case HP_385:
    145        1.7  gmcgarry 		ib = intio_3xx_builtins;
    146        1.7  gmcgarry 		ndevs = nintio_3xx_builtins;
    147        1.7  gmcgarry 		break;
    148        1.7  gmcgarry #endif
    149       1.25   tsutsui #if defined(HP362) || defined(HP382)
    150       1.25   tsutsui 	case HP_362:
    151       1.25   tsutsui 	case HP_382:
    152       1.25   tsutsui 		ib = intio_3x2_builtins;
    153       1.25   tsutsui 		ndevs = nintio_3x2_builtins;
    154       1.25   tsutsui 		break;
    155       1.25   tsutsui #endif
    156        1.7  gmcgarry #if defined(HP400) || defined(HP425) || defined(HP433)
    157        1.7  gmcgarry 	case HP_400:
    158        1.7  gmcgarry 	case HP_425:
    159        1.7  gmcgarry 	case HP_433:
    160        1.7  gmcgarry 		ib = intio_4xx_builtins;
    161        1.7  gmcgarry 		ndevs = nintio_4xx_builtins;
    162        1.7  gmcgarry 		break;
    163        1.7  gmcgarry #endif
    164        1.7  gmcgarry 	default:
    165        1.7  gmcgarry 		return;
    166        1.7  gmcgarry 	}
    167        1.7  gmcgarry 
    168        1.7  gmcgarry 	memset(&ia, 0, sizeof(ia));
    169        1.7  gmcgarry 
    170       1.16   tsutsui 	for (i = 0; i < ndevs; i++) {
    171       1.15  gmcgarry 
    172       1.15  gmcgarry 		/*
    173       1.15  gmcgarry 		 * Internal HP-IB doesn't always return a device ID,
    174       1.15  gmcgarry 		 * so we rely on the sysflags.
    175       1.15  gmcgarry 		 */
    176       1.22   tsutsui 		if (ib[i].ib_offset == HPIB_BASE && !internalhpib)
    177       1.15  gmcgarry 			continue;
    178       1.15  gmcgarry 
    179       1.23   tsutsui 		strlcpy(ia.ia_modname, ib[i].ib_modname,
    180       1.24   tsutsui 		    sizeof(ia.ia_modname));
    181       1.17   tsutsui 		ia.ia_bst = bst;
    182        1.7  gmcgarry 		ia.ia_iobase = ib[i].ib_offset;
    183        1.7  gmcgarry 		ia.ia_addr = (bus_addr_t)(intiobase + ib[i].ib_offset);
    184        1.7  gmcgarry 		ia.ia_ipl = ib[i].ib_ipl;
    185        1.7  gmcgarry 		config_found(self, &ia, intioprint);
    186        1.7  gmcgarry 	}
    187        1.1   thorpej }
    188        1.1   thorpej 
    189       1.19   thorpej static int
    190       1.19   thorpej intioprint(void *aux, const char *pnp)
    191        1.1   thorpej {
    192        1.1   thorpej 	struct intio_attach_args *ia = aux;
    193        1.1   thorpej 
    194        1.9  gmcgarry 	if (pnp != NULL)
    195       1.14   thorpej 		aprint_normal("%s at %s", ia->ia_modname, pnp);
    196       1.15  gmcgarry 	if (ia->ia_iobase != 0 && pnp == NULL) {
    197       1.15  gmcgarry 		aprint_normal(" addr 0x%lx", INTIOBASE + ia->ia_iobase);
    198       1.15  gmcgarry 		if (ia->ia_ipl != -1)
    199       1.14   thorpej 			aprint_normal(" ipl %d", ia->ia_ipl);
    200        1.7  gmcgarry 	}
    201       1.21   tsutsui 	return UNCONF;
    202        1.1   thorpej }
    203