1*f72d1cdaSmrg /* $NetBSD: fhc_central.c,v 1.3 2012/03/18 05:26:58 mrg Exp $ */
239a57b1cSmrg /* $OpenBSD: fhc_central.c,v 1.5 2004/09/27 18:32:35 jason Exp $ */
339a57b1cSmrg
439a57b1cSmrg /*
539a57b1cSmrg * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
639a57b1cSmrg * All rights reserved.
739a57b1cSmrg *
839a57b1cSmrg * Redistribution and use in source and binary forms, with or without
939a57b1cSmrg * modification, are permitted provided that the following conditions
1039a57b1cSmrg * are met:
1139a57b1cSmrg * 1. Redistributions of source code must retain the above copyright
1239a57b1cSmrg * notice, this list of conditions and the following disclaimer.
1339a57b1cSmrg * 2. Redistributions in binary form must reproduce the above copyright
1439a57b1cSmrg * notice, this list of conditions and the following disclaimer in the
1539a57b1cSmrg * documentation and/or other materials provided with the distribution.
1639a57b1cSmrg *
1739a57b1cSmrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1839a57b1cSmrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1939a57b1cSmrg * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2039a57b1cSmrg * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2139a57b1cSmrg * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2239a57b1cSmrg * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2339a57b1cSmrg * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2439a57b1cSmrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2539a57b1cSmrg * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2639a57b1cSmrg * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2739a57b1cSmrg * POSSIBILITY OF SUCH DAMAGE.
2839a57b1cSmrg */
2939a57b1cSmrg
30*f72d1cdaSmrg #include <sys/cdefs.h>
31*f72d1cdaSmrg __KERNEL_RCSID(0, "$NetBSD: fhc_central.c,v 1.3 2012/03/18 05:26:58 mrg Exp $");
32*f72d1cdaSmrg
3339a57b1cSmrg #include <sys/types.h>
3439a57b1cSmrg #include <sys/param.h>
3539a57b1cSmrg #include <sys/systm.h>
3639a57b1cSmrg #include <sys/kernel.h>
3739a57b1cSmrg #include <sys/device.h>
3839a57b1cSmrg #include <sys/conf.h>
3939a57b1cSmrg #include <sys/bus.h>
4039a57b1cSmrg
4139a57b1cSmrg #include <machine/autoconf.h>
4239a57b1cSmrg #include <machine/openfirm.h>
4339a57b1cSmrg
4439a57b1cSmrg #include <sparc64/dev/centralvar.h>
4539a57b1cSmrg #include <sparc64/dev/fhcreg.h>
4639a57b1cSmrg #include <sparc64/dev/fhcvar.h>
4739a57b1cSmrg
4839a57b1cSmrg int fhc_central_match(device_t, cfdata_t, void *);
4939a57b1cSmrg void fhc_central_attach(device_t, device_t, void *);
5039a57b1cSmrg
5139a57b1cSmrg CFATTACH_DECL_NEW(fhc_central, sizeof(struct fhc_softc),
5239a57b1cSmrg fhc_central_match, fhc_central_attach, NULL, NULL);
5339a57b1cSmrg
5439a57b1cSmrg int
fhc_central_match(device_t parent,cfdata_t match,void * aux)5539a57b1cSmrg fhc_central_match(device_t parent, cfdata_t match, void *aux)
5639a57b1cSmrg {
5739a57b1cSmrg struct central_attach_args *ca = aux;
5839a57b1cSmrg
5939a57b1cSmrg if (strcmp(ca->ca_name, "fhc") == 0)
6039a57b1cSmrg return (1);
6139a57b1cSmrg return (0);
6239a57b1cSmrg }
6339a57b1cSmrg
6439a57b1cSmrg void
fhc_central_attach(device_t parent,device_t self,void * aux)6539a57b1cSmrg fhc_central_attach(device_t parent, device_t self, void *aux)
6639a57b1cSmrg {
67a14d5855Smrg struct fhc_softc *sc = device_private(self);
6839a57b1cSmrg struct central_attach_args *ca = aux;
6939a57b1cSmrg u_int32_t board;
7039a57b1cSmrg
7139a57b1cSmrg sc->sc_node = ca->ca_node;
7239a57b1cSmrg sc->sc_bt = ca->ca_bustag;
7339a57b1cSmrg sc->sc_is_central = 1;
7439a57b1cSmrg
7539a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot,
7639a57b1cSmrg ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0,
7739a57b1cSmrg &sc->sc_preg)) {
7839a57b1cSmrg printf(": failed to map preg\n");
7939a57b1cSmrg return;
8039a57b1cSmrg }
8139a57b1cSmrg
8239a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot,
8339a57b1cSmrg ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0,
8439a57b1cSmrg &sc->sc_ireg)) {
8539a57b1cSmrg printf(": failed to map ireg\n");
8639a57b1cSmrg return;
8739a57b1cSmrg }
8839a57b1cSmrg
8939a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot,
9039a57b1cSmrg ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size,
9139a57b1cSmrg BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
9239a57b1cSmrg printf(": failed to map freg\n");
9339a57b1cSmrg return;
9439a57b1cSmrg }
9539a57b1cSmrg
9639a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot,
9739a57b1cSmrg ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size,
9839a57b1cSmrg BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
9939a57b1cSmrg printf(": failed to map sreg\n");
10039a57b1cSmrg return;
10139a57b1cSmrg }
10239a57b1cSmrg
10339a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot,
10439a57b1cSmrg ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size,
10539a57b1cSmrg BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
10639a57b1cSmrg printf(": failed to map ureg\n");
10739a57b1cSmrg return;
10839a57b1cSmrg }
10939a57b1cSmrg
11039a57b1cSmrg if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot,
11139a57b1cSmrg ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size,
11239a57b1cSmrg BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
11339a57b1cSmrg printf(": failed to map treg\n");
11439a57b1cSmrg return;
11539a57b1cSmrg }
11639a57b1cSmrg
11739a57b1cSmrg board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR);
11839a57b1cSmrg sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
11939a57b1cSmrg sc->sc_dev = self;
12039a57b1cSmrg
12139a57b1cSmrg fhc_attach(sc);
12239a57b1cSmrg return;
12339a57b1cSmrg }
124