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