xref: /netbsd-src/sys/arch/rs6000/mca/ioplanar.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*-
2  * Copyright (c) 2007 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Tim Rightnour
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ioplanar.c,v 1.4 2011/07/18 17:26:56 dyoung Exp $");
32 
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/bus.h>
36 
37 #include <machine/intr.h>
38 
39 #include <dev/mca/mcavar.h>
40 #include <dev/mca/mcadevs.h>
41 
42 #include <rs6000/ioplanar/ioplanarvar.h>
43 
44 static int	ioplanar_match(device_t, cfdata_t, void *);
45 static void	ioplanar_attach(device_t, device_t, void *);
46 static int	ioplanar_print(void *, const char *);
47 static int	ioplanar_search(device_t, cfdata_t, const int *, void *);
48 
49 CFATTACH_DECL_NEW(ioplanar, sizeof(struct ioplanar_softc),
50     ioplanar_match, ioplanar_attach, NULL, NULL);
51 
52 struct ioplanar_softc *ioplanar_softc;
53 extern struct cfdriver ioplanar_cd;
54 
55 #define RAINBOW_DEVS	7
56 int rainbow_map[RAINBOW_DEVS] =
57 	{ IOP_COM0, IOP_COM1, IOP_LPD, IOP_KBD_2,
58 	  IOP_TABLET_2, IOP_MOUSE, IOP_FDC_2 };
59 
60 static int
61 ioplanar_match(device_t parent, cfdata_t cf, void *aux)
62 {
63 	struct mca_attach_args *ma = aux;
64 
65 	switch (ma->ma_id) {
66 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
67 		return 1;
68 	}
69 
70 	return 0;
71 }
72 
73 static void
74 ioplanar_attach(device_t parent, device_t self, void *aux)
75 {
76 	struct ioplanar_softc *sc = device_private(self);
77 	struct mca_attach_args *ma = aux;
78 
79 	aprint_normal("\n");
80 
81 	ioplanar_softc = sc;
82 	sc->sc_dev = self;
83 	sc->sc_ic = ma->ma_mc;
84 	sc->sc_iot = ma->ma_iot;
85 	sc->sc_memt = ma->ma_memt;
86 	sc->sc_dmat = ma->ma_dmat;
87 	sc->sc_devid = ma->ma_id;
88 
89 	(void)config_search_ia(ioplanar_search, self, "ioplanar", aux);
90 }
91 
92 static int
93 ioplanar_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
94 {
95 	struct ioplanar_dev_attach_args idaa;
96 	struct mca_attach_args *ma = aux;
97 	int i;
98 
99 	idaa.idaa_mc = ma->ma_mc;
100 	idaa.idaa_iot = ma->ma_iot;
101 	idaa.idaa_memt = ma->ma_memt;
102 	idaa.idaa_dmat = ma->ma_dmat;
103 	idaa.idaa_devid = ma->ma_id;
104 
105 	switch (ma->ma_id) {
106 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
107 		for (i=0; i < RAINBOW_DEVS; i++) {
108 			idaa.idaa_device = rainbow_map[i];
109 			if (config_match(parent, cf, &idaa) > 0)
110 				config_attach(parent, cf, &idaa,
111 				    ioplanar_print);
112 		}
113 		break;
114 	default:
115 		return 0;
116 	}
117 	return 0;
118 }
119 
120 static int
121 ioplanar_print(void *args, const char *name)
122 {
123 	/*struct ioplanar_dev_attach_args *idaa = args;*/
124 
125 	aprint_normal(": ");
126 	return (UNCONF);
127 }
128