xref: /netbsd-src/sys/arch/next68k/dev/intio.c (revision fd5cb0acea84d278e04e640d37ca2398f894991f)
1 /*	$NetBSD: intio.c,v 1.9 2005/01/19 01:58:21 chs Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996 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 next68k internal i/o space.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.9 2005/01/19 01:58:21 chs Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 #include <sys/reboot.h>
50 
51 #include <machine/autoconf.h>
52 
53 #include <next68k/dev/intiovar.h>
54 
55 int	intiomatch(struct device *, struct cfdata *, void *);
56 void	intioattach(struct device *, struct device *, void *);
57 int	intioprint(void *, const char *);
58 int	intiosearch(struct device *, struct cfdata *, void *);
59 
60 CFATTACH_DECL(intio, sizeof(struct device),
61     intiomatch, intioattach, NULL, NULL);
62 
63 #if 0
64 struct cfdriver intio_cd = {
65 	NULL, "intio", DV_DULL
66 };
67 #endif
68 
69 static int intio_attached = 0;
70 
71 int
72 intiomatch(struct device *parent, struct cfdata *match, void *aux)
73 {
74 	/* Allow only one instance. */
75 	if (intio_attached)
76 		return (0);
77 
78 	return (1);
79 }
80 
81 void
82 intioattach(struct device *parent, struct device *self, void *aux)
83 {
84 
85 	printf("\n");
86 
87 	/* Search for and attach children. */
88 	config_search(intiosearch, self, aux);
89 
90 	intio_attached = 1;
91 }
92 
93 int
94 intioprint(void *aux, const char *pnp)
95 {
96 	struct intio_attach_args *ia = aux;
97 
98 	if (ia->ia_addr)
99 		aprint_normal(" addr %p", ia->ia_addr);
100 
101 	return (UNCONF);
102 }
103 
104 int
105 intiosearch(struct device *parent, struct cfdata *cf, void *aux)
106 {
107 	struct mainbus_attach_args *mba = (struct mainbus_attach_args *) aux;
108 	struct intio_attach_args ia;
109 
110 	do {
111 		ia.ia_addr = NULL;
112 		ia.ia_bst = NEXT68K_INTIO_BUS_SPACE;
113 		ia.ia_dmat = mba->mba_dmat;
114 
115 		if (config_match(parent, cf, &ia) == 0)
116 			break;
117 		config_attach(parent, cf, &ia, intioprint);
118 	} while (cf->cf_fstate == FSTATE_STAR);
119 
120 	return (0);
121 }
122