1 /* $NetBSD: plum.c,v 1.12 2005/12/11 12:17:33 christos Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: plum.c,v 1.12 2005/12/11 12:17:33 christos Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
40 #include <machine/bus.h>
41 #include <machine/intr.h>
43 #include <hpcmips/tx/tx39var.h>
44 #include <hpcmips/tx/txcsbusvar.h>
45 #include <hpcmips/dev/plumvar.h>
46 #include <hpcmips/dev/plumreg.h>
48 int plum_match(struct device
*, struct cfdata
*, void *);
49 void plum_attach(struct device
*, struct device
*, void *);
50 int plum_print(void *, const char *);
51 int plum_search(struct device
*, struct cfdata
*, const int *, void *);
55 plum_chipset_tag_t sc_pc
;
56 bus_space_tag_t sc_csregt
;
57 bus_space_tag_t sc_csiot
;
58 bus_space_tag_t sc_csmemt
;
63 CFATTACH_DECL(plum
, sizeof(struct plum_softc
),
64 plum_match
, plum_attach
, NULL
, NULL
);
66 plumreg_t
plum_idcheck(bus_space_tag_t
);
69 plum_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
71 struct cs_attach_args
*ca
= aux
;
73 switch (plum_idcheck(ca
->ca_csreg
.cstag
)) {
85 plum_attach(struct device
*parent
, struct device
*self
, void *aux
)
87 struct cs_attach_args
*ca
= aux
;
88 struct plum_softc
*sc
= (void*)self
;
91 sc
->sc_csregt
= ca
->ca_csreg
.cstag
;
92 sc
->sc_csiot
= ca
->ca_csio
.cstag
;
93 sc
->sc_csmemt
= ca
->ca_csmem
.cstag
;
94 sc
->sc_irq
= ca
->ca_irq1
;
96 switch (reg
= plum_idcheck(sc
->sc_csregt
)) {
98 printf(": unknown revision %#x\n", reg
);
101 printf(": Plum2 #1\n");
104 printf(": Plum2 #2\n");
107 if (!(sc
->sc_pc
= malloc(sizeof(struct plum_chipset_tag
),
108 M_DEVBUF
, M_NOWAIT
))) {
111 memset(sc
->sc_pc
, 0, sizeof(struct plum_chipset_tag
));
112 sc
->sc_pc
->pc_tc
= ca
->ca_tc
;
114 /* Attach Plum devices */
116 * interrupt, power/clock module is used by other plum module.
120 config_search_ia(plum_search
, self
, "plumif", plum_print
);
125 config_search_ia(plum_search
, self
, "plumif", plum_print
);
129 plum_idcheck(bus_space_tag_t regt
)
131 bus_space_handle_t regh
;
134 if (bus_space_map(regt
, PLUM_ID_REGBASE
,
135 PLUM_ID_REGSIZE
, 0, ®h
)) {
136 printf("ID register map failed\n");
139 reg
= plum_conf_read(regt
, regh
, PLUM_ID_REG
);
140 bus_space_unmap(regt
, regh
, PLUM_ID_REGSIZE
);
146 plum_print(void *aux
, const char *pnp
)
149 return (pnp
? QUIET
: UNCONF
);
153 plum_search(struct device
*parent
, struct cfdata
*cf
,
154 const int *ldesc
, void *aux
)
156 struct plum_softc
*sc
= (void*)parent
;
157 struct plum_attach_args pa
;
159 pa
.pa_pc
= sc
->sc_pc
;
160 pa
.pa_regt
= sc
->sc_csregt
;
161 pa
.pa_iot
= sc
->sc_csiot
;
162 pa
.pa_memt
= sc
->sc_csmemt
;
163 pa
.pa_irq
= sc
->sc_irq
;
165 if (config_match(parent
, cf
, &pa
) == sc
->sc_pri
) {
166 config_attach(parent
, cf
, &pa
, plum_print
);
173 plum_conf_read(bus_space_tag_t t
, bus_space_handle_t h
, int o
)
177 reg
= bus_space_read_4(t
, h
, o
);
183 plum_conf_write(bus_space_tag_t t
, bus_space_handle_t h
, int o
, plumreg_t v
)
186 bus_space_write_4(t
, h
, o
, v
);
190 plum_conf_register_intr(plum_chipset_tag_t t
, void *intrt
)
194 panic("duplicate intrt");
201 plum_conf_register_power(plum_chipset_tag_t t
, void *powert
)
205 panic("duplicate powert");
208 t
->pc_powert
= powert
;