ioplanar.c revision 1.5 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.5 2021/04/24 23:36:47 thorpej 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 config_search(self, aux,
90 CFARG_SEARCH, ioplanar_search,
91 CFARG_EOL);
92 }
93
94 static int
95 ioplanar_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
96 {
97 struct ioplanar_dev_attach_args idaa;
98 struct mca_attach_args *ma = aux;
99 int i;
100
101 idaa.idaa_mc = ma->ma_mc;
102 idaa.idaa_iot = ma->ma_iot;
103 idaa.idaa_memt = ma->ma_memt;
104 idaa.idaa_dmat = ma->ma_dmat;
105 idaa.idaa_devid = ma->ma_id;
106
107 switch (ma->ma_id) {
108 case MCA_PRODUCT_IBM_SIO_RAINBOW:
109 for (i=0; i < RAINBOW_DEVS; i++) {
110 idaa.idaa_device = rainbow_map[i];
111 if (config_probe(parent, cf, &idaa))
112 config_attach(parent, cf, &idaa,
113 ioplanar_print, CFARG_EOL);
114 }
115 break;
116 default:
117 return 0;
118 }
119 return 0;
120 }
121
122 static int
123 ioplanar_print(void *args, const char *name)
124 {
125 /*struct ioplanar_dev_attach_args *idaa = args;*/
126
127 aprint_normal(": ");
128 return (UNCONF);
129 }
130