pbus.c revision 1.4 1 1.4 simonb /* $NetBSD: pbus.c,v 1.4 2003/07/16 08:06:10 simonb Exp $ */
2 1.1 scw
3 1.1 scw /*
4 1.1 scw * Copyright 2001 Wasabi Systems, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 1.1 scw *
9 1.1 scw * Redistribution and use in source and binary forms, with or without
10 1.1 scw * modification, are permitted provided that the following conditions
11 1.1 scw * are met:
12 1.1 scw * 1. Redistributions of source code must retain the above copyright
13 1.1 scw * notice, this list of conditions and the following disclaimer.
14 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 scw * notice, this list of conditions and the following disclaimer in the
16 1.1 scw * documentation and/or other materials provided with the distribution.
17 1.1 scw * 3. All advertising materials mentioning features or use of this software
18 1.1 scw * must display the following acknowledgement:
19 1.1 scw * This product includes software developed for the NetBSD Project by
20 1.1 scw * Wasabi Systems, Inc.
21 1.1 scw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 scw * or promote products derived from this software without specific prior
23 1.1 scw * written permission.
24 1.1 scw *
25 1.1 scw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 scw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
36 1.1 scw */
37 1.1 scw
38 1.1 scw /*
39 1.1 scw * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
40 1.1 scw *
41 1.1 scw * Redistribution and use in source and binary forms, with or without
42 1.1 scw * modification, are permitted provided that the following conditions
43 1.1 scw * are met:
44 1.1 scw * 1. Redistributions of source code must retain the above copyright
45 1.1 scw * notice, this list of conditions and the following disclaimer.
46 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
47 1.1 scw * notice, this list of conditions and the following disclaimer in the
48 1.1 scw * documentation and/or other materials provided with the distribution.
49 1.1 scw * 3. All advertising materials mentioning features or use of this software
50 1.1 scw * must display the following acknowledgement:
51 1.1 scw * This product includes software developed by Christopher G. Demetriou
52 1.1 scw * for the NetBSD Project.
53 1.1 scw * 4. The name of the author may not be used to endorse or promote products
54 1.1 scw * derived from this software without specific prior written permission
55 1.1 scw *
56 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 1.1 scw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 1.1 scw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.1 scw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 1.1 scw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 1.1 scw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 1.1 scw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 1.1 scw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 1.1 scw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 1.1 scw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 1.1 scw */
67 1.3 lukem
68 1.3 lukem #include <sys/cdefs.h>
69 1.4 simonb __KERNEL_RCSID(0, "$NetBSD: pbus.c,v 1.4 2003/07/16 08:06:10 simonb Exp $");
70 1.1 scw
71 1.1 scw #include "locators.h"
72 1.1 scw #include "pckbc.h"
73 1.1 scw
74 1.1 scw #include <sys/param.h>
75 1.1 scw #include <sys/systm.h>
76 1.1 scw #include <sys/device.h>
77 1.1 scw
78 1.1 scw #include <machine/bus.h>
79 1.1 scw #include <machine/walnut.h>
80 1.1 scw
81 1.1 scw #include <evbppc/walnut/dev/pbusvar.h>
82 1.1 scw
83 1.1 scw #include <powerpc/ibm4xx/ibm405gp.h>
84 1.1 scw #include <powerpc/ibm4xx/dev/plbvar.h>
85 1.1 scw
86 1.1 scw /*
87 1.4 simonb * The external devices on the Walnut 405GP evaluation board.
88 1.1 scw */
89 1.1 scw const struct pbus_dev {
90 1.1 scw const char *name;
91 1.1 scw bus_addr_t addr;
92 1.1 scw int irq;
93 1.1 scw } pbus_devs [] = {
94 1.1 scw { "dsrtc", NVRAM_BASE, -1 },
95 1.1 scw { "pckbc", KEY_MOUSE_BASE, 25 }, /* XXX: really irq x..x+1 */
96 1.1 scw { NULL }
97 1.1 scw };
98 1.1 scw
99 1.1 scw static int pbus_match(struct device *, struct cfdata *, void *);
100 1.1 scw static void pbus_attach(struct device *, struct device *, void *);
101 1.1 scw static int pbus_submatch(struct device *, struct cfdata *, void *);
102 1.1 scw static int pbus_print(void *, const char *);
103 1.1 scw
104 1.1 scw CFATTACH_DECL(pbus, sizeof(struct device),
105 1.1 scw pbus_match, pbus_attach, NULL, NULL);
106 1.1 scw
107 1.1 scw /*
108 1.1 scw * Probe for the peripheral bus.
109 1.1 scw */
110 1.1 scw static int
111 1.1 scw pbus_match(struct device *parent, struct cfdata *cf, void *aux)
112 1.1 scw {
113 1.1 scw struct pbus_attach_args *pba = aux;
114 1.1 scw
115 1.1 scw /* match only pbus devices */
116 1.1 scw if (strcmp(pba->pb_name, cf->cf_name) != 0)
117 1.1 scw return (0);
118 1.1 scw
119 1.1 scw return (1);
120 1.1 scw }
121 1.1 scw
122 1.1 scw static int
123 1.1 scw pbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
124 1.1 scw {
125 1.1 scw struct pbus_attach_args *pba = aux;
126 1.1 scw
127 1.1 scw if (cf->cf_loc[PBUSCF_ADDR] != PBUSCF_ADDR_DEFAULT &&
128 1.1 scw cf->cf_loc[PBUSCF_ADDR] != pba->pb_addr)
129 1.1 scw return (0);
130 1.1 scw
131 1.1 scw return (config_match(parent, cf, aux));
132 1.1 scw }
133 1.1 scw
134 1.1 scw /*
135 1.1 scw * Attach the peripheral bus.
136 1.1 scw */
137 1.1 scw static void
138 1.1 scw pbus_attach(struct device *parent, struct device *self, void *aux)
139 1.1 scw {
140 1.1 scw struct plb_attach_args *paa = aux;
141 1.1 scw struct pbus_attach_args pba;
142 1.1 scw int i;
143 1.1 scw #if NPCKBC > 0
144 1.1 scw bus_space_handle_t ioh_fpga;
145 1.1 scw bus_space_tag_t iot_fpga = paa->plb_bt;
146 1.1 scw uint8_t fpga_reg;
147 1.1 scw #endif
148 1.1 scw
149 1.1 scw printf("\n");
150 1.1 scw
151 1.1 scw for (i = 0; pbus_devs[i].name != NULL; i++) {
152 1.1 scw pba.pb_name = pbus_devs[i].name;
153 1.1 scw pba.pb_addr = pbus_devs[i].addr;
154 1.1 scw pba.pb_irq = pbus_devs[i].irq;
155 1.1 scw pba.pb_bt = paa->plb_bt;
156 1.1 scw pba.pb_dmat = paa->plb_dmat;
157 1.1 scw
158 1.1 scw (void) config_found_sm(self, &pba, pbus_print, pbus_submatch);
159 1.1 scw }
160 1.1 scw
161 1.1 scw #if NPCKBC > 0
162 1.1 scw /* Configure FPGA */
163 1.1 scw if (bus_space_map(iot_fpga, FPGA_BASE, FPGA_SIZE, 0, &ioh_fpga)) {
164 1.1 scw printf("pbus_attach: can't map FPGA\n");
165 1.1 scw /* XXX - disable keyboard probe? */
166 1.1 scw } else {
167 1.1 scw /* Use separate interrupts for keyboard and mouse */
168 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_BRDC);
169 1.1 scw fpga_reg |= FPGA_BRDC_INT;
170 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_BRDC, fpga_reg);
171 1.1 scw
172 1.1 scw /* Set interrupts to active high */
173 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_POL);
174 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
175 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_POL, fpga_reg);
176 1.1 scw
177 1.1 scw /* Set interrupts to level triggered */
178 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG);
179 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
180 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG, fpga_reg);
181 1.1 scw
182 1.1 scw /* Enable interrupts */
183 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE);
184 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
185 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE, fpga_reg);
186 1.1 scw
187 1.1 scw bus_space_unmap(&iot_fpga, ioh_fpga, 2);
188 1.1 scw }
189 1.1 scw #endif
190 1.1 scw
191 1.1 scw }
192 1.1 scw
193 1.1 scw static int
194 1.1 scw pbus_print(void *aux, const char *pnp)
195 1.1 scw {
196 1.1 scw struct pbus_attach_args *pba = aux;
197 1.1 scw
198 1.1 scw if (pnp)
199 1.1 scw printf("%s at %s", pba->pb_name, pnp);
200 1.1 scw
201 1.1 scw if (pba->pb_addr != PBUSCF_ADDR_DEFAULT)
202 1.2 thorpej aprint_normal(" addr 0x%08lx", pba->pb_addr);
203 1.1 scw if (pba->pb_irq != PBUSCF_IRQ_DEFAULT)
204 1.2 thorpej aprint_normal(" irq %d", pba->pb_irq);
205 1.1 scw
206 1.1 scw return (UNCONF);
207 1.1 scw }
208