1*f72d1cdaSmrg /* $NetBSD: fhc_mainbus.c,v 1.3 2012/03/18 05:26:58 mrg Exp $ */
239a57b1cSmrg /* $OpenBSD: fhc_mainbus.c,v 1.4 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_mainbus.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/fhcvar.h>
4539a57b1cSmrg
4639a57b1cSmrg int fhc_mainbus_match(device_t, cfdata_t, void *);
4739a57b1cSmrg void fhc_mainbus_attach(device_t, device_t, void *);
4839a57b1cSmrg
4939a57b1cSmrg CFATTACH_DECL_NEW(fhc_mainbus, sizeof(struct fhc_softc),
5039a57b1cSmrg fhc_mainbus_match, fhc_mainbus_attach, NULL, NULL);
5139a57b1cSmrg
5239a57b1cSmrg int
fhc_mainbus_match(device_t parent,cfdata_t match,void * aux)5339a57b1cSmrg fhc_mainbus_match(device_t parent, cfdata_t match, void *aux)
5439a57b1cSmrg {
5539a57b1cSmrg struct mainbus_attach_args *ma = aux;
5639a57b1cSmrg
5739a57b1cSmrg if (strcmp(ma->ma_name, "fhc") == 0)
5839a57b1cSmrg return (1);
5939a57b1cSmrg return (0);
6039a57b1cSmrg }
6139a57b1cSmrg
6239a57b1cSmrg void
fhc_mainbus_attach(device_t parent,device_t self,void * aux)6339a57b1cSmrg fhc_mainbus_attach(device_t parent, device_t self, void *aux)
6439a57b1cSmrg {
65a14d5855Smrg struct fhc_softc *sc = device_private(self);
6639a57b1cSmrg struct mainbus_attach_args *ma = aux;
6739a57b1cSmrg
6839a57b1cSmrg sc->sc_node = ma->ma_node;
6939a57b1cSmrg sc->sc_bt = ma->ma_bustag;
7039a57b1cSmrg sc->sc_is_central = 0;
7139a57b1cSmrg
7239a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[0].ur_paddr,
7339a57b1cSmrg ma->ma_reg[0].ur_len, 0, &sc->sc_preg)) {
7439a57b1cSmrg printf(": failed to map preg\n");
7539a57b1cSmrg return;
7639a57b1cSmrg }
7739a57b1cSmrg
7839a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[1].ur_paddr,
7939a57b1cSmrg ma->ma_reg[1].ur_len, 0, &sc->sc_ireg)) {
8039a57b1cSmrg printf(": failed to map ireg\n");
8139a57b1cSmrg return;
8239a57b1cSmrg }
8339a57b1cSmrg
8439a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[2].ur_paddr,
8539a57b1cSmrg ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
8639a57b1cSmrg printf(": failed to map freg\n");
8739a57b1cSmrg return;
8839a57b1cSmrg }
8939a57b1cSmrg
9039a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[3].ur_paddr,
9139a57b1cSmrg ma->ma_reg[3].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
9239a57b1cSmrg printf(": failed to map sreg\n");
9339a57b1cSmrg return;
9439a57b1cSmrg }
9539a57b1cSmrg
9639a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[4].ur_paddr,
9739a57b1cSmrg ma->ma_reg[4].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
9839a57b1cSmrg printf(": failed to map ureg\n");
9939a57b1cSmrg return;
10039a57b1cSmrg }
10139a57b1cSmrg
10239a57b1cSmrg if (bus_space_map(sc->sc_bt, ma->ma_reg[5].ur_paddr,
10339a57b1cSmrg ma->ma_reg[5].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
10439a57b1cSmrg printf(": failed to map treg\n");
10539a57b1cSmrg return;
10639a57b1cSmrg }
10739a57b1cSmrg
10839a57b1cSmrg sc->sc_board = prom_getpropint(sc->sc_node, "board#", -1);
10939a57b1cSmrg sc->sc_dev = self;
11039a57b1cSmrg
11139a57b1cSmrg fhc_attach(sc);
11239a57b1cSmrg
11339a57b1cSmrg return;
11439a57b1cSmrg }
115