plum.c revision 1.1.8.2 1 1.1.8.2 bouyer /* $NetBSD: plum.c,v 1.1.8.2 2000/11/20 20:46:06 bouyer Exp $ */
2 1.1.8.2 bouyer
3 1.1.8.2 bouyer /*
4 1.1.8.2 bouyer * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1.8.2 bouyer * All rights reserved.
6 1.1.8.2 bouyer *
7 1.1.8.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.1.8.2 bouyer * modification, are permitted provided that the following conditions
9 1.1.8.2 bouyer * are met:
10 1.1.8.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.1.8.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.1.8.2 bouyer * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1.8.2 bouyer * derived from this software without specific prior written permission.
14 1.1.8.2 bouyer *
15 1.1.8.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1.8.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1.8.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1.8.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1.8.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1.8.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1.8.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1.8.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1.8.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1.8.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1.8.2 bouyer * SUCH DAMAGE.
26 1.1.8.2 bouyer *
27 1.1.8.2 bouyer */
28 1.1.8.2 bouyer
29 1.1.8.2 bouyer #include "opt_tx39_debug.h"
30 1.1.8.2 bouyer
31 1.1.8.2 bouyer #include <sys/param.h>
32 1.1.8.2 bouyer #include <sys/systm.h>
33 1.1.8.2 bouyer #include <sys/device.h>
34 1.1.8.2 bouyer #include <sys/malloc.h>
35 1.1.8.2 bouyer
36 1.1.8.2 bouyer #include <machine/bus.h>
37 1.1.8.2 bouyer #include <machine/intr.h>
38 1.1.8.2 bouyer
39 1.1.8.2 bouyer #include <hpcmips/tx/tx39var.h>
40 1.1.8.2 bouyer #include <hpcmips/tx/txcsbusvar.h>
41 1.1.8.2 bouyer #include <hpcmips/dev/plumvar.h>
42 1.1.8.2 bouyer #include <hpcmips/dev/plumreg.h>
43 1.1.8.2 bouyer
44 1.1.8.2 bouyer int plum_match __P((struct device*, struct cfdata*, void*));
45 1.1.8.2 bouyer void plum_attach __P((struct device*, struct device*, void*));
46 1.1.8.2 bouyer int plum_print __P((void*, const char*));
47 1.1.8.2 bouyer int plum_search __P((struct device*, struct cfdata*, void*));
48 1.1.8.2 bouyer
49 1.1.8.2 bouyer struct plum_softc {
50 1.1.8.2 bouyer struct device sc_dev;
51 1.1.8.2 bouyer plum_chipset_tag_t sc_pc;
52 1.1.8.2 bouyer bus_space_tag_t sc_csregt;
53 1.1.8.2 bouyer bus_space_tag_t sc_csiot;
54 1.1.8.2 bouyer bus_space_tag_t sc_csmemt;
55 1.1.8.2 bouyer int sc_irq;
56 1.1.8.2 bouyer int sc_pri;
57 1.1.8.2 bouyer };
58 1.1.8.2 bouyer
59 1.1.8.2 bouyer struct cfattach plum_ca = {
60 1.1.8.2 bouyer sizeof(struct plum_softc), plum_match, plum_attach
61 1.1.8.2 bouyer };
62 1.1.8.2 bouyer
63 1.1.8.2 bouyer plumreg_t plum_idcheck __P((bus_space_tag_t));
64 1.1.8.2 bouyer
65 1.1.8.2 bouyer int
66 1.1.8.2 bouyer plum_match(parent, cf, aux)
67 1.1.8.2 bouyer struct device *parent;
68 1.1.8.2 bouyer struct cfdata *cf;
69 1.1.8.2 bouyer void *aux;
70 1.1.8.2 bouyer {
71 1.1.8.2 bouyer struct cs_attach_args *ca = aux;
72 1.1.8.2 bouyer
73 1.1.8.2 bouyer switch (plum_idcheck(ca->ca_csreg.cstag)) {
74 1.1.8.2 bouyer default:
75 1.1.8.2 bouyer return 0;
76 1.1.8.2 bouyer case PLUM2_1:
77 1.1.8.2 bouyer case PLUM2_2:
78 1.1.8.2 bouyer }
79 1.1.8.2 bouyer
80 1.1.8.2 bouyer return 1;
81 1.1.8.2 bouyer }
82 1.1.8.2 bouyer
83 1.1.8.2 bouyer void
84 1.1.8.2 bouyer plum_attach(parent, self, aux)
85 1.1.8.2 bouyer struct device *parent;
86 1.1.8.2 bouyer struct device *self;
87 1.1.8.2 bouyer void *aux;
88 1.1.8.2 bouyer {
89 1.1.8.2 bouyer struct cs_attach_args *ca = aux;
90 1.1.8.2 bouyer struct plum_softc *sc = (void*)self;
91 1.1.8.2 bouyer plumreg_t reg;
92 1.1.8.2 bouyer
93 1.1.8.2 bouyer sc->sc_csregt = ca->ca_csreg.cstag;
94 1.1.8.2 bouyer sc->sc_csiot = ca->ca_csio.cstag;
95 1.1.8.2 bouyer sc->sc_csmemt = ca->ca_csmem.cstag;
96 1.1.8.2 bouyer sc->sc_irq = ca->ca_irq1;
97 1.1.8.2 bouyer
98 1.1.8.2 bouyer switch (plum_idcheck(sc->sc_csregt)) {
99 1.1.8.2 bouyer default:
100 1.1.8.2 bouyer printf(": unknown revision %#x\n", reg);
101 1.1.8.2 bouyer return;
102 1.1.8.2 bouyer case PLUM2_1:
103 1.1.8.2 bouyer printf(": Plum2 #1\n");
104 1.1.8.2 bouyer break;
105 1.1.8.2 bouyer case PLUM2_2:
106 1.1.8.2 bouyer printf(": Plum2 #2\n");
107 1.1.8.2 bouyer break;
108 1.1.8.2 bouyer }
109 1.1.8.2 bouyer if (!(sc->sc_pc = malloc(sizeof(struct plum_chipset_tag),
110 1.1.8.2 bouyer M_DEVBUF, M_NOWAIT))) {
111 1.1.8.2 bouyer panic("no memory");
112 1.1.8.2 bouyer }
113 1.1.8.2 bouyer memset(sc->sc_pc, 0, sizeof(struct plum_chipset_tag));
114 1.1.8.2 bouyer sc->sc_pc->pc_tc = ca->ca_tc;
115 1.1.8.2 bouyer
116 1.1.8.2 bouyer /* Attach Plum devices */
117 1.1.8.2 bouyer /*
118 1.1.8.2 bouyer * interrupt, power/clock module is used by other plum module.
119 1.1.8.2 bouyer * attach first.
120 1.1.8.2 bouyer */
121 1.1.8.2 bouyer sc->sc_pri = 2;
122 1.1.8.2 bouyer config_search(plum_search, self, plum_print);
123 1.1.8.2 bouyer /*
124 1.1.8.2 bouyer * Other plum module.
125 1.1.8.2 bouyer */
126 1.1.8.2 bouyer sc->sc_pri = 1;
127 1.1.8.2 bouyer config_search(plum_search, self, plum_print);
128 1.1.8.2 bouyer }
129 1.1.8.2 bouyer
130 1.1.8.2 bouyer plumreg_t
131 1.1.8.2 bouyer plum_idcheck(regt)
132 1.1.8.2 bouyer bus_space_tag_t regt;
133 1.1.8.2 bouyer {
134 1.1.8.2 bouyer bus_space_handle_t regh;
135 1.1.8.2 bouyer plumreg_t reg;
136 1.1.8.2 bouyer
137 1.1.8.2 bouyer if (bus_space_map(regt, PLUM_ID_REGBASE,
138 1.1.8.2 bouyer PLUM_ID_REGSIZE, 0, ®h)) {
139 1.1.8.2 bouyer printf("ID register map failed\n");
140 1.1.8.2 bouyer return 0;
141 1.1.8.2 bouyer }
142 1.1.8.2 bouyer reg = plum_conf_read(regt, regh, PLUM_ID_REG);
143 1.1.8.2 bouyer bus_space_unmap(regt, regh, PLUM_ID_REGSIZE);
144 1.1.8.2 bouyer
145 1.1.8.2 bouyer return reg;
146 1.1.8.2 bouyer }
147 1.1.8.2 bouyer
148 1.1.8.2 bouyer int
149 1.1.8.2 bouyer plum_print(aux, pnp)
150 1.1.8.2 bouyer void *aux;
151 1.1.8.2 bouyer const char *pnp;
152 1.1.8.2 bouyer {
153 1.1.8.2 bouyer return pnp ? QUIET : UNCONF;
154 1.1.8.2 bouyer }
155 1.1.8.2 bouyer
156 1.1.8.2 bouyer int
157 1.1.8.2 bouyer plum_search(parent, cf, aux)
158 1.1.8.2 bouyer struct device *parent;
159 1.1.8.2 bouyer struct cfdata *cf;
160 1.1.8.2 bouyer void *aux;
161 1.1.8.2 bouyer {
162 1.1.8.2 bouyer struct plum_softc *sc = (void*)parent;
163 1.1.8.2 bouyer struct plum_attach_args pa;
164 1.1.8.2 bouyer
165 1.1.8.2 bouyer pa.pa_pc = sc->sc_pc;
166 1.1.8.2 bouyer pa.pa_regt = sc->sc_csregt;
167 1.1.8.2 bouyer pa.pa_iot = sc->sc_csiot;
168 1.1.8.2 bouyer pa.pa_memt = sc->sc_csmemt;
169 1.1.8.2 bouyer pa.pa_irq = sc->sc_irq;
170 1.1.8.2 bouyer
171 1.1.8.2 bouyer if ((*cf->cf_attach->ca_match)(parent, cf, &pa) == sc->sc_pri) {
172 1.1.8.2 bouyer config_attach(parent, cf, &pa, plum_print);
173 1.1.8.2 bouyer }
174 1.1.8.2 bouyer
175 1.1.8.2 bouyer return 0;
176 1.1.8.2 bouyer }
177 1.1.8.2 bouyer
178 1.1.8.2 bouyer plumreg_t
179 1.1.8.2 bouyer plum_conf_read(t, h, o)
180 1.1.8.2 bouyer bus_space_tag_t t;
181 1.1.8.2 bouyer bus_space_handle_t h;
182 1.1.8.2 bouyer int o;
183 1.1.8.2 bouyer {
184 1.1.8.2 bouyer plumreg_t reg;
185 1.1.8.2 bouyer reg = bus_space_read_4(t, h, o);
186 1.1.8.2 bouyer return reg;
187 1.1.8.2 bouyer }
188 1.1.8.2 bouyer
189 1.1.8.2 bouyer void
190 1.1.8.2 bouyer plum_conf_write(t, h, o, v)
191 1.1.8.2 bouyer bus_space_tag_t t;
192 1.1.8.2 bouyer bus_space_handle_t h;
193 1.1.8.2 bouyer int o;
194 1.1.8.2 bouyer plumreg_t v;
195 1.1.8.2 bouyer {
196 1.1.8.2 bouyer bus_space_write_4(t, h, o, v);
197 1.1.8.2 bouyer }
198 1.1.8.2 bouyer
199 1.1.8.2 bouyer void
200 1.1.8.2 bouyer plum_conf_register_intr(t, intrt)
201 1.1.8.2 bouyer plum_chipset_tag_t t;
202 1.1.8.2 bouyer void *intrt;
203 1.1.8.2 bouyer {
204 1.1.8.2 bouyer if (t->pc_intrt) {
205 1.1.8.2 bouyer panic("duplicate intrt");
206 1.1.8.2 bouyer }
207 1.1.8.2 bouyer t->pc_intrt = intrt;
208 1.1.8.2 bouyer }
209 1.1.8.2 bouyer
210 1.1.8.2 bouyer void
211 1.1.8.2 bouyer plum_conf_register_power(t, powert)
212 1.1.8.2 bouyer plum_chipset_tag_t t;
213 1.1.8.2 bouyer void *powert;
214 1.1.8.2 bouyer {
215 1.1.8.2 bouyer if (t->pc_powert) {
216 1.1.8.2 bouyer panic("duplicate powert");
217 1.1.8.2 bouyer }
218 1.1.8.2 bouyer t->pc_powert = powert;
219 1.1.8.2 bouyer }
220