obio.c revision 1.14.18.1 1 /* $NetBSD: obio.c,v 1.14.18.1 2003/06/19 11:18:56 grant Exp $ */
2
3 /*-
4 * Copyright (C) 1998 Internet Research Institute, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by
18 * Internet Research Institute, Inc.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
38
39 #include <dev/pci/pcivar.h>
40 #include <dev/pci/pcidevs.h>
41
42 #include <dev/ofw/openfirm.h>
43
44 #include <machine/autoconf.h>
45
46 static void obio_attach __P((struct device *, struct device *, void *));
47 static int obio_match __P((struct device *, struct cfdata *, void *));
48 static int obio_print __P((void *, const char *));
49
50 struct obio_softc {
51 struct device sc_dev;
52 int sc_node;
53 };
54
55
56 struct cfattach obio_ca = {
57 sizeof(struct obio_softc), obio_match, obio_attach
58 };
59
60 int
61 obio_match(parent, cf, aux)
62 struct device *parent;
63 struct cfdata *cf;
64 void *aux;
65 {
66 struct pci_attach_args *pa = aux;
67
68 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
69 switch (PCI_PRODUCT(pa->pa_id)) {
70
71 case PCI_PRODUCT_APPLE_GC:
72 case PCI_PRODUCT_APPLE_OHARE:
73 case PCI_PRODUCT_APPLE_HEATHROW:
74 case PCI_PRODUCT_APPLE_PADDINGTON:
75 case PCI_PRODUCT_APPLE_KEYLARGO:
76 case PCI_PRODUCT_APPLE_PANGEA_MACIO:
77 case PCI_PRODUCT_APPLE_INTREPID:
78 return 1;
79 }
80
81 return 0;
82 }
83
84 /*
85 * Attach all the sub-devices we can find
86 */
87 void
88 obio_attach(parent, self, aux)
89 struct device *parent, *self;
90 void *aux;
91 {
92 struct obio_softc *sc = (struct obio_softc *)self;
93 struct pci_attach_args *pa = aux;
94 struct confargs ca;
95 int node, child, namelen;
96 u_int reg[20];
97 int intr[6];
98 char name[32];
99
100 switch (PCI_PRODUCT(pa->pa_id)) {
101
102 /* XXX should not use name */
103 case PCI_PRODUCT_APPLE_GC:
104 node = OF_finddevice("/bandit/gc");
105 break;
106
107 case PCI_PRODUCT_APPLE_OHARE:
108 node = OF_finddevice("/bandit/ohare");
109 break;
110
111 case PCI_PRODUCT_APPLE_HEATHROW:
112 case PCI_PRODUCT_APPLE_PADDINGTON:
113 case PCI_PRODUCT_APPLE_KEYLARGO:
114 case PCI_PRODUCT_APPLE_PANGEA_MACIO:
115 case PCI_PRODUCT_APPLE_INTREPID:
116 node = OF_finddevice("mac-io");
117 if (node == -1)
118 node = OF_finddevice("/pci/mac-io");
119 break;
120
121 default:
122 printf("obio_attach: unknown obio controller\n");
123 return;
124 }
125
126 sc->sc_node = node;
127
128 if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
129 return;
130 ca.ca_baseaddr = reg[2];
131
132 printf(": addr 0x%x\n", ca.ca_baseaddr);
133
134 /* Enable CD and microphone sound input. */
135 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
136 out8(ca.ca_baseaddr + 0x37, 0x03);
137
138 for (child = OF_child(node); child; child = OF_peer(child)) {
139 namelen = OF_getprop(child, "name", name, sizeof(name));
140 if (namelen < 0)
141 continue;
142 if (namelen >= sizeof(name))
143 continue;
144
145 name[namelen] = 0;
146 ca.ca_name = name;
147 ca.ca_node = child;
148
149 ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
150 ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
151 sizeof(intr));
152 if (ca.ca_nintr == -1)
153 ca.ca_nintr = OF_getprop(child, "interrupts", intr,
154 sizeof(intr));
155
156 ca.ca_reg = reg;
157 ca.ca_intr = intr;
158
159 config_found(self, &ca, obio_print);
160 }
161 }
162
163 static char *skiplist[] = {
164 "interrupt-controller",
165 "gpio",
166 "escc-legacy",
167 "timer",
168 "i2c",
169 "power-mgt"
170 };
171
172 #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
173
174 int
175 obio_print(aux, obio)
176 void *aux;
177 const char *obio;
178 {
179 struct confargs *ca = aux;
180 int i;
181
182 for (i = 0; i < N_LIST; i++)
183 if (strcmp(ca->ca_name, skiplist[i]) == 0)
184 return QUIET;
185
186 if (obio)
187 printf("%s at %s", ca->ca_name, obio);
188
189 if (ca->ca_nreg > 0)
190 printf(" offset 0x%x", ca->ca_reg[0]);
191
192 return UNCONF;
193 }
194