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