xref: /netbsd-src/sys/arch/sparc64/dev/fhc_central.c (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: fhc_central.c,v 1.2 2011/08/01 08:36:39 mrg Exp $	*/
2 /*	$OpenBSD: fhc_central.c,v 1.5 2004/09/27 18:32:35 jason Exp $	*/
3 
4 /*
5  * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <sys/conf.h>
36 #include <sys/bus.h>
37 
38 #include <machine/autoconf.h>
39 #include <machine/openfirm.h>
40 
41 #include <sparc64/dev/centralvar.h>
42 #include <sparc64/dev/fhcreg.h>
43 #include <sparc64/dev/fhcvar.h>
44 
45 int	fhc_central_match(device_t, cfdata_t, void *);
46 void	fhc_central_attach(device_t, device_t, void *);
47 
48 CFATTACH_DECL_NEW(fhc_central, sizeof(struct fhc_softc),
49     fhc_central_match, fhc_central_attach, NULL, NULL);
50 
51 int
52 fhc_central_match(device_t parent, cfdata_t match, void *aux)
53 {
54 	struct central_attach_args *ca = aux;
55 
56 	if (strcmp(ca->ca_name, "fhc") == 0)
57 		return (1);
58 	return (0);
59 }
60 
61 void
62 fhc_central_attach(device_t parent, device_t self, void *aux)
63 {
64 	struct fhc_softc *sc = device_private(self);
65 	struct central_attach_args *ca = aux;
66 	u_int32_t board;
67 
68 	sc->sc_node = ca->ca_node;
69 	sc->sc_bt = ca->ca_bustag;
70 	sc->sc_is_central = 1;
71 
72 	if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot,
73 	    ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0,
74 	    &sc->sc_preg)) {
75 		printf(": failed to map preg\n");
76 		return;
77 	}
78 
79 	if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot,
80 	    ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0,
81 	    &sc->sc_ireg)) {
82 		printf(": failed to map ireg\n");
83 		return;
84 	}
85 
86 	if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot,
87 	    ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size,
88 	    BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
89 		printf(": failed to map freg\n");
90 		return;
91 	}
92 
93 	if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot,
94 	    ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size,
95 	    BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
96 		printf(": failed to map sreg\n");
97 		return;
98 	}
99 
100 	if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot,
101 	    ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size,
102 	    BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
103 		printf(": failed to map ureg\n");
104 		return;
105 	}
106 
107 	if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot,
108 	    ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size,
109 	    BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
110 		printf(": failed to map treg\n");
111 		return;
112 	}
113 
114 	board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR);
115 	sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
116 	sc->sc_dev = self;
117 
118 	fhc_attach(sc);
119 	return;
120 }
121