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