pbus.c revision 1.2 1 1.2 thorpej /* $NetBSD: pbus.c,v 1.2 2003/01/01 01:31:50 thorpej 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.1 scw
68 1.1 scw #include "locators.h"
69 1.1 scw #include "pckbc.h"
70 1.1 scw
71 1.1 scw #include <sys/param.h>
72 1.1 scw #include <sys/systm.h>
73 1.1 scw #include <sys/device.h>
74 1.1 scw
75 1.1 scw #include <machine/bus.h>
76 1.1 scw #include <machine/walnut.h>
77 1.1 scw
78 1.1 scw #include <evbppc/walnut/dev/pbusvar.h>
79 1.1 scw
80 1.1 scw #include <powerpc/ibm4xx/ibm405gp.h>
81 1.1 scw #include <powerpc/ibm4xx/dev/plbvar.h>
82 1.1 scw
83 1.1 scw /*
84 1.1 scw * The devices built in to the 405GP cpu.
85 1.1 scw */
86 1.1 scw const struct pbus_dev {
87 1.1 scw const char *name;
88 1.1 scw bus_addr_t addr;
89 1.1 scw int irq;
90 1.1 scw } pbus_devs [] = {
91 1.1 scw { "dsrtc", NVRAM_BASE, -1 },
92 1.1 scw { "pckbc", KEY_MOUSE_BASE, 25 }, /* XXX: really irq x..x+1 */
93 1.1 scw { NULL }
94 1.1 scw };
95 1.1 scw
96 1.1 scw static int pbus_match(struct device *, struct cfdata *, void *);
97 1.1 scw static void pbus_attach(struct device *, struct device *, void *);
98 1.1 scw static int pbus_submatch(struct device *, struct cfdata *, void *);
99 1.1 scw static int pbus_print(void *, const char *);
100 1.1 scw
101 1.1 scw CFATTACH_DECL(pbus, sizeof(struct device),
102 1.1 scw pbus_match, pbus_attach, NULL, NULL);
103 1.1 scw
104 1.1 scw /*
105 1.1 scw * Probe for the peripheral bus.
106 1.1 scw */
107 1.1 scw static int
108 1.1 scw pbus_match(struct device *parent, struct cfdata *cf, void *aux)
109 1.1 scw {
110 1.1 scw struct pbus_attach_args *pba = aux;
111 1.1 scw
112 1.1 scw /* match only pbus devices */
113 1.1 scw if (strcmp(pba->pb_name, cf->cf_name) != 0)
114 1.1 scw return (0);
115 1.1 scw
116 1.1 scw return (1);
117 1.1 scw }
118 1.1 scw
119 1.1 scw static int
120 1.1 scw pbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
121 1.1 scw {
122 1.1 scw struct pbus_attach_args *pba = aux;
123 1.1 scw
124 1.1 scw if (cf->cf_loc[PBUSCF_ADDR] != PBUSCF_ADDR_DEFAULT &&
125 1.1 scw cf->cf_loc[PBUSCF_ADDR] != pba->pb_addr)
126 1.1 scw return (0);
127 1.1 scw
128 1.1 scw return (config_match(parent, cf, aux));
129 1.1 scw }
130 1.1 scw
131 1.1 scw /*
132 1.1 scw * Attach the peripheral bus.
133 1.1 scw */
134 1.1 scw static void
135 1.1 scw pbus_attach(struct device *parent, struct device *self, void *aux)
136 1.1 scw {
137 1.1 scw struct plb_attach_args *paa = aux;
138 1.1 scw struct pbus_attach_args pba;
139 1.1 scw int i;
140 1.1 scw #if NPCKBC > 0
141 1.1 scw bus_space_handle_t ioh_fpga;
142 1.1 scw bus_space_tag_t iot_fpga = paa->plb_bt;
143 1.1 scw uint8_t fpga_reg;
144 1.1 scw #endif
145 1.1 scw
146 1.1 scw printf("\n");
147 1.1 scw
148 1.1 scw for (i = 0; pbus_devs[i].name != NULL; i++) {
149 1.1 scw pba.pb_name = pbus_devs[i].name;
150 1.1 scw pba.pb_addr = pbus_devs[i].addr;
151 1.1 scw pba.pb_irq = pbus_devs[i].irq;
152 1.1 scw pba.pb_bt = paa->plb_bt;
153 1.1 scw pba.pb_dmat = paa->plb_dmat;
154 1.1 scw
155 1.1 scw (void) config_found_sm(self, &pba, pbus_print, pbus_submatch);
156 1.1 scw }
157 1.1 scw
158 1.1 scw #if NPCKBC > 0
159 1.1 scw /* Configure FPGA */
160 1.1 scw if (bus_space_map(iot_fpga, FPGA_BASE, FPGA_SIZE, 0, &ioh_fpga)) {
161 1.1 scw printf("pbus_attach: can't map FPGA\n");
162 1.1 scw /* XXX - disable keyboard probe? */
163 1.1 scw } else {
164 1.1 scw /* Use separate interrupts for keyboard and mouse */
165 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_BRDC);
166 1.1 scw fpga_reg |= FPGA_BRDC_INT;
167 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_BRDC, fpga_reg);
168 1.1 scw
169 1.1 scw /* Set interrupts to active high */
170 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_POL);
171 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
172 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_POL, fpga_reg);
173 1.1 scw
174 1.1 scw /* Set interrupts to level triggered */
175 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG);
176 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
177 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG, fpga_reg);
178 1.1 scw
179 1.1 scw /* Enable interrupts */
180 1.1 scw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE);
181 1.1 scw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
182 1.1 scw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE, fpga_reg);
183 1.1 scw
184 1.1 scw bus_space_unmap(&iot_fpga, ioh_fpga, 2);
185 1.1 scw }
186 1.1 scw #endif
187 1.1 scw
188 1.1 scw }
189 1.1 scw
190 1.1 scw static int
191 1.1 scw pbus_print(void *aux, const char *pnp)
192 1.1 scw {
193 1.1 scw struct pbus_attach_args *pba = aux;
194 1.1 scw
195 1.1 scw if (pnp)
196 1.1 scw printf("%s at %s", pba->pb_name, pnp);
197 1.1 scw
198 1.1 scw if (pba->pb_addr != PBUSCF_ADDR_DEFAULT)
199 1.2 thorpej aprint_normal(" addr 0x%08lx", pba->pb_addr);
200 1.1 scw if (pba->pb_irq != PBUSCF_IRQ_DEFAULT)
201 1.2 thorpej aprint_normal(" irq %d", pba->pb_irq);
202 1.1 scw
203 1.1 scw return (UNCONF);
204 1.1 scw }
205