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