Home | History | Annotate | Line # | Download | only in adm5120
mainbus.c revision 1.1.74.1
      1  1.1.74.1  bouyer /* $NetBSD: mainbus.c,v 1.1.74.1 2011/03/05 15:09:36 bouyer Exp $ */
      2       1.1  dyoung 
      3       1.1  dyoung /*-
      4       1.1  dyoung  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
      5       1.1  dyoung  * All rights reserved.
      6       1.1  dyoung  *
      7       1.1  dyoung  * Redistribution and use in source and binary forms, with or
      8       1.1  dyoung  * without modification, are permitted provided that the following
      9       1.1  dyoung  * conditions are met:
     10       1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     11       1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     12       1.1  dyoung  * 2. Redistributions in binary form must reproduce the above
     13       1.1  dyoung  *    copyright notice, this list of conditions and the following
     14       1.1  dyoung  *    disclaimer in the documentation and/or other materials provided
     15       1.1  dyoung  *    with the distribution.
     16       1.1  dyoung  * 3. The names of the authors may not be used to endorse or promote
     17       1.1  dyoung  *    products derived from this software without specific prior
     18       1.1  dyoung  *    written permission.
     19       1.1  dyoung  *
     20       1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
     21       1.1  dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22       1.1  dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23       1.1  dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS
     24       1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     25       1.1  dyoung  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26       1.1  dyoung  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
     27       1.1  dyoung  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     29       1.1  dyoung  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     30       1.1  dyoung  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     31       1.1  dyoung  * OF SUCH DAMAGE.
     32       1.1  dyoung  */
     33       1.1  dyoung /*
     34       1.1  dyoung  * Copyright 2002 Wasabi Systems, Inc.
     35       1.1  dyoung  * All rights reserved.
     36       1.1  dyoung  *
     37       1.1  dyoung  * Written by Simon Burge for Wasabi Systems, Inc.
     38       1.1  dyoung  *
     39       1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     40       1.1  dyoung  * modification, are permitted provided that the following conditions
     41       1.1  dyoung  * are met:
     42       1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     43       1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     44       1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     45       1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     46       1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     47       1.1  dyoung  * 3. All advertising materials mentioning features or use of this software
     48       1.1  dyoung  *    must display the following acknowledgement:
     49       1.1  dyoung  *      This product includes software developed for the NetBSD Project by
     50       1.1  dyoung  *      Wasabi Systems, Inc.
     51       1.1  dyoung  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     52       1.1  dyoung  *    or promote products derived from this software without specific prior
     53       1.1  dyoung  *    written permission.
     54       1.1  dyoung  *
     55       1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     56       1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     57       1.1  dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     58       1.1  dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     59       1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     60       1.1  dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     61       1.1  dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     62       1.1  dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     63       1.1  dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     64       1.1  dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     65       1.1  dyoung  * POSSIBILITY OF SUCH DAMAGE.
     66       1.1  dyoung  */
     67       1.1  dyoung 
     68       1.1  dyoung #include <sys/cdefs.h>
     69  1.1.74.1  bouyer __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1.74.1 2011/03/05 15:09:36 bouyer Exp $");
     70       1.1  dyoung 
     71       1.1  dyoung #include <sys/param.h>
     72       1.1  dyoung #include <sys/systm.h>
     73       1.1  dyoung #include <sys/device.h>
     74       1.1  dyoung 
     75       1.1  dyoung #include <machine/bus.h>
     76       1.1  dyoung 
     77       1.1  dyoung #include <mips/cache.h>
     78       1.1  dyoung #include <mips/cpuregs.h>
     79       1.1  dyoung 
     80       1.1  dyoung #include <mips/adm5120/include/adm5120reg.h>
     81       1.1  dyoung #include <mips/adm5120/include/adm5120var.h>
     82       1.1  dyoung #include <mips/adm5120/include/adm5120_mainbusvar.h>
     83       1.1  dyoung 
     84       1.1  dyoung #include "locators.h"
     85       1.1  dyoung 
     86  1.1.74.1  bouyer static int	mainbus_match(device_t, cfdata_t, void *);
     87  1.1.74.1  bouyer static void	mainbus_attach(device_t, device_t, void *);
     88       1.1  dyoung static int	mainbus_print(void *, const char *);
     89       1.1  dyoung 
     90  1.1.74.1  bouyer CFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc),
     91       1.1  dyoung     mainbus_match, mainbus_attach, NULL, NULL);
     92       1.1  dyoung 
     93       1.1  dyoung /* There can be only one. */
     94       1.1  dyoung int	mainbus_found;
     95       1.1  dyoung 
     96       1.1  dyoung struct mainbusdev {
     97       1.1  dyoung 	const char *md_name;
     98       1.1  dyoung };
     99       1.1  dyoung 
    100  1.1.74.1  bouyer const struct mainbusdev mainbusdevs[] = {
    101       1.1  dyoung 	{"cpu"		},
    102       1.1  dyoung 	{"obio"		},
    103       1.1  dyoung 	{"extio"	},
    104       1.1  dyoung 	{"admpci"	},
    105       1.1  dyoung 	{NULL		}
    106       1.1  dyoung };
    107       1.1  dyoung 
    108       1.1  dyoung static void
    109       1.1  dyoung mainbus_gpio_attach(struct mainbus_softc *sc)
    110       1.1  dyoung {
    111       1.1  dyoung 	if (bus_space_map(sc->sc_obiot, ADM5120_BASE_SWITCH, 512, 0,
    112       1.1  dyoung 	                  &sc->sc_gpioh) != 0){
    113  1.1.74.1  bouyer 		aprint_error_dev(sc->sc_dev, "unable to map switch\n");
    114       1.1  dyoung 		return;
    115       1.1  dyoung 	}
    116       1.1  dyoung #if 0
    117  1.1.74.1  bouyer 	aprint_normal_dev(sc->sc_dev, "memcont 0x%08" PRIx32 "\n",
    118       1.1  dyoung 	    bus_space_read_4(sc->sc_obiot, sc->sc_gpioh, 0x1c));
    119       1.1  dyoung #endif
    120       1.1  dyoung 	sc->sc_gpio = admgpio_attach(sc);
    121       1.1  dyoung }
    122       1.1  dyoung 
    123       1.1  dyoung 
    124       1.1  dyoung static int
    125  1.1.74.1  bouyer mainbus_match(device_t parent, cfdata_t match, void *aux)
    126       1.1  dyoung {
    127       1.1  dyoung 	return !mainbus_found;
    128       1.1  dyoung }
    129       1.1  dyoung 
    130       1.1  dyoung static void
    131  1.1.74.1  bouyer mainbus_attach(device_t parent, device_t self, void *aux)
    132       1.1  dyoung {
    133  1.1.74.1  bouyer 	struct mainbus_softc *sc = device_private(self);
    134       1.1  dyoung 	struct mainbus_attach_args ma;
    135  1.1.74.1  bouyer 	const struct mainbusdev *md;
    136       1.1  dyoung 	struct adm5120_config *admc = &adm5120_configuration;
    137       1.1  dyoung 
    138       1.1  dyoung 	mainbus_found = 1;
    139  1.1.74.1  bouyer 	aprint_normal("\n");
    140       1.1  dyoung 
    141  1.1.74.1  bouyer 	sc->sc_dev = self;
    142       1.1  dyoung 	sc->sc_obiot = &admc->obio_space;
    143       1.1  dyoung 
    144       1.1  dyoung 	mainbus_gpio_attach(sc);
    145       1.1  dyoung 
    146       1.1  dyoung 	ma.ma_dmat = &admc->obio_dmat;
    147       1.1  dyoung 	ma.ma_obiot = sc->sc_obiot;
    148       1.1  dyoung 	ma.ma_gpioh = sc->sc_gpioh;
    149       1.1  dyoung 	ma.ma_gpio = sc->sc_gpio;
    150       1.1  dyoung 	ma.ma_gpio_offset = -1;
    151       1.1  dyoung 	ma.ma_gpio_mask = 0x0;
    152       1.1  dyoung 
    153       1.1  dyoung 	for (md = mainbusdevs; md->md_name != NULL; md++) {
    154       1.1  dyoung 		ma.ma_name = md->md_name;
    155       1.1  dyoung 		config_found_ia(self, "mainbus", &ma, mainbus_print);
    156       1.1  dyoung 	}
    157       1.1  dyoung }
    158       1.1  dyoung 
    159       1.1  dyoung static int
    160       1.1  dyoung mainbus_print(void *aux, const char *pnp)
    161       1.1  dyoung {
    162       1.1  dyoung 	struct mainbus_attach_args *ma = aux;
    163       1.1  dyoung 
    164       1.1  dyoung 	if (pnp != NULL)
    165       1.1  dyoung 		aprint_normal("%s at %s", ma->ma_name, pnp);
    166       1.1  dyoung 
    167       1.1  dyoung 	return UNCONF;
    168       1.1  dyoung }
    169