Home | History | Annotate | Line # | Download | only in dev
plum.c revision 1.2.4.3
      1  1.2.4.3  nathanw /*	$NetBSD: plum.c,v 1.2.4.3 2002/10/18 02:37:06 nathanw Exp $ */
      2  1.2.4.2  nathanw 
      3  1.2.4.2  nathanw /*-
      4  1.2.4.2  nathanw  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.2.4.2  nathanw  * All rights reserved.
      6  1.2.4.2  nathanw  *
      7  1.2.4.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.4.2  nathanw  * by UCHIYAMA Yasushi.
      9  1.2.4.2  nathanw  *
     10  1.2.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.2.4.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.2.4.2  nathanw  * are met:
     13  1.2.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.2.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.2.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.2.4.2  nathanw  *    must display the following acknowledgement:
     20  1.2.4.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.2.4.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.2.4.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.4.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.2.4.2  nathanw  *    from this software without specific prior written permission.
     25  1.2.4.2  nathanw  *
     26  1.2.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.4.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.4.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.4.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.4.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.4.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.4.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.4.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.4.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.4.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.4.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.4.2  nathanw  */
     38  1.2.4.2  nathanw 
     39  1.2.4.2  nathanw #include <sys/param.h>
     40  1.2.4.2  nathanw #include <sys/systm.h>
     41  1.2.4.2  nathanw #include <sys/device.h>
     42  1.2.4.2  nathanw #include <sys/malloc.h>
     43  1.2.4.2  nathanw 
     44  1.2.4.2  nathanw #include <machine/bus.h>
     45  1.2.4.2  nathanw #include <machine/intr.h>
     46  1.2.4.2  nathanw 
     47  1.2.4.2  nathanw #include <hpcmips/tx/tx39var.h>
     48  1.2.4.2  nathanw #include <hpcmips/tx/txcsbusvar.h>
     49  1.2.4.2  nathanw #include <hpcmips/dev/plumvar.h>
     50  1.2.4.2  nathanw #include <hpcmips/dev/plumreg.h>
     51  1.2.4.2  nathanw 
     52  1.2.4.2  nathanw int plum_match(struct device *, struct cfdata *, void *);
     53  1.2.4.2  nathanw void plum_attach(struct device *, struct device *, void *);
     54  1.2.4.2  nathanw int plum_print(void *, const char *);
     55  1.2.4.2  nathanw int plum_search(struct device *, struct cfdata *, void *);
     56  1.2.4.2  nathanw 
     57  1.2.4.2  nathanw struct plum_softc {
     58  1.2.4.2  nathanw 	struct	device		sc_dev;
     59  1.2.4.2  nathanw 	plum_chipset_tag_t	sc_pc;
     60  1.2.4.2  nathanw 	bus_space_tag_t		sc_csregt;
     61  1.2.4.2  nathanw 	bus_space_tag_t		sc_csiot;
     62  1.2.4.2  nathanw 	bus_space_tag_t		sc_csmemt;
     63  1.2.4.2  nathanw 	int			sc_irq;
     64  1.2.4.2  nathanw 	int			sc_pri;
     65  1.2.4.2  nathanw };
     66  1.2.4.2  nathanw 
     67  1.2.4.3  nathanw CFATTACH_DECL(plum, sizeof(struct plum_softc),
     68  1.2.4.3  nathanw     plum_match, plum_attach, NULL, NULL);
     69  1.2.4.2  nathanw 
     70  1.2.4.2  nathanw plumreg_t plum_idcheck(bus_space_tag_t);
     71  1.2.4.2  nathanw 
     72  1.2.4.2  nathanw int
     73  1.2.4.2  nathanw plum_match(struct device *parent, struct cfdata *cf, void *aux)
     74  1.2.4.2  nathanw {
     75  1.2.4.2  nathanw 	struct cs_attach_args *ca = aux;
     76  1.2.4.2  nathanw 
     77  1.2.4.2  nathanw 	switch (plum_idcheck(ca->ca_csreg.cstag)) {
     78  1.2.4.2  nathanw 	default:
     79  1.2.4.2  nathanw 		return (0);
     80  1.2.4.2  nathanw 	case PLUM2_1:
     81  1.2.4.2  nathanw 	case PLUM2_2:
     82  1.2.4.2  nathanw 	}
     83  1.2.4.2  nathanw 
     84  1.2.4.2  nathanw 	return (1);
     85  1.2.4.2  nathanw }
     86  1.2.4.2  nathanw 
     87  1.2.4.2  nathanw void
     88  1.2.4.2  nathanw plum_attach(struct device *parent, struct device *self, void *aux)
     89  1.2.4.2  nathanw {
     90  1.2.4.2  nathanw 	struct cs_attach_args *ca = aux;
     91  1.2.4.2  nathanw 	struct plum_softc *sc = (void*)self;
     92  1.2.4.2  nathanw 	plumreg_t reg;
     93  1.2.4.2  nathanw 
     94  1.2.4.2  nathanw 	sc->sc_csregt	= ca->ca_csreg.cstag;
     95  1.2.4.2  nathanw 	sc->sc_csiot	= ca->ca_csio.cstag;
     96  1.2.4.2  nathanw 	sc->sc_csmemt	= ca->ca_csmem.cstag;
     97  1.2.4.2  nathanw 	sc->sc_irq	= ca->ca_irq1;
     98  1.2.4.2  nathanw 
     99  1.2.4.2  nathanw 	switch (plum_idcheck(sc->sc_csregt)) {
    100  1.2.4.2  nathanw 	default:
    101  1.2.4.2  nathanw 		printf(": unknown revision %#x\n", reg);
    102  1.2.4.2  nathanw 		return;
    103  1.2.4.2  nathanw 	case PLUM2_1:
    104  1.2.4.2  nathanw 		printf(": Plum2 #1\n");
    105  1.2.4.2  nathanw 		break;
    106  1.2.4.2  nathanw 	case PLUM2_2:
    107  1.2.4.2  nathanw 		printf(": Plum2 #2\n");
    108  1.2.4.2  nathanw 		break;
    109  1.2.4.2  nathanw 	}
    110  1.2.4.2  nathanw 	if (!(sc->sc_pc = malloc(sizeof(struct plum_chipset_tag),
    111  1.2.4.2  nathanw 	    M_DEVBUF, M_NOWAIT))) {
    112  1.2.4.2  nathanw 		panic("no memory");
    113  1.2.4.2  nathanw 	}
    114  1.2.4.2  nathanw 	memset(sc->sc_pc, 0, sizeof(struct plum_chipset_tag));
    115  1.2.4.2  nathanw 	sc->sc_pc->pc_tc = ca->ca_tc;
    116  1.2.4.2  nathanw 
    117  1.2.4.2  nathanw 	/* Attach Plum devices */
    118  1.2.4.2  nathanw 	/*
    119  1.2.4.2  nathanw 	 * interrupt, power/clock module is used by other plum module.
    120  1.2.4.2  nathanw 	 * attach first.
    121  1.2.4.2  nathanw 	 */
    122  1.2.4.2  nathanw 	sc->sc_pri = 2;
    123  1.2.4.2  nathanw 	config_search(plum_search, self, plum_print);
    124  1.2.4.2  nathanw 	/*
    125  1.2.4.2  nathanw 	 * Other plum module.
    126  1.2.4.2  nathanw 	 */
    127  1.2.4.2  nathanw 	sc->sc_pri = 1;
    128  1.2.4.2  nathanw 	config_search(plum_search, self, plum_print);
    129  1.2.4.2  nathanw }
    130  1.2.4.2  nathanw 
    131  1.2.4.2  nathanw plumreg_t
    132  1.2.4.2  nathanw plum_idcheck(bus_space_tag_t regt)
    133  1.2.4.2  nathanw {
    134  1.2.4.2  nathanw 	bus_space_handle_t regh;
    135  1.2.4.2  nathanw 	plumreg_t reg;
    136  1.2.4.2  nathanw 
    137  1.2.4.2  nathanw 	if (bus_space_map(regt, PLUM_ID_REGBASE,
    138  1.2.4.2  nathanw 	    PLUM_ID_REGSIZE, 0, &regh)) {
    139  1.2.4.2  nathanw 		printf("ID register map failed\n");
    140  1.2.4.2  nathanw 		return (0);
    141  1.2.4.2  nathanw 	}
    142  1.2.4.2  nathanw 	reg = plum_conf_read(regt, regh, PLUM_ID_REG);
    143  1.2.4.2  nathanw 	bus_space_unmap(regt, regh, PLUM_ID_REGSIZE);
    144  1.2.4.2  nathanw 
    145  1.2.4.2  nathanw 	return (reg);
    146  1.2.4.2  nathanw }
    147  1.2.4.2  nathanw 
    148  1.2.4.2  nathanw int
    149  1.2.4.2  nathanw plum_print(void *aux, const char *pnp)
    150  1.2.4.2  nathanw {
    151  1.2.4.2  nathanw 
    152  1.2.4.2  nathanw 	return (pnp ? QUIET : UNCONF);
    153  1.2.4.2  nathanw }
    154  1.2.4.2  nathanw 
    155  1.2.4.2  nathanw int
    156  1.2.4.2  nathanw plum_search(struct device *parent, struct cfdata *cf, void *aux)
    157  1.2.4.2  nathanw {
    158  1.2.4.2  nathanw 	struct plum_softc *sc = (void*)parent;
    159  1.2.4.2  nathanw 	struct plum_attach_args pa;
    160  1.2.4.2  nathanw 
    161  1.2.4.2  nathanw 	pa.pa_pc	= sc->sc_pc;
    162  1.2.4.2  nathanw 	pa.pa_regt	= sc->sc_csregt;
    163  1.2.4.2  nathanw 	pa.pa_iot	= sc->sc_csiot;
    164  1.2.4.2  nathanw 	pa.pa_memt	= sc->sc_csmemt;
    165  1.2.4.2  nathanw 	pa.pa_irq	= sc->sc_irq;
    166  1.2.4.2  nathanw 
    167  1.2.4.3  nathanw 	if (config_match(parent, cf, &pa) == sc->sc_pri) {
    168  1.2.4.2  nathanw 		config_attach(parent, cf, &pa, plum_print);
    169  1.2.4.2  nathanw 	}
    170  1.2.4.2  nathanw 
    171  1.2.4.2  nathanw 	return 0;
    172  1.2.4.2  nathanw }
    173  1.2.4.2  nathanw 
    174  1.2.4.2  nathanw plumreg_t
    175  1.2.4.2  nathanw plum_conf_read(bus_space_tag_t t, bus_space_handle_t h, int o)
    176  1.2.4.2  nathanw {
    177  1.2.4.2  nathanw 	plumreg_t reg;
    178  1.2.4.2  nathanw 
    179  1.2.4.2  nathanw 	reg = bus_space_read_4(t, h, o);
    180  1.2.4.2  nathanw 
    181  1.2.4.2  nathanw 	return (reg);
    182  1.2.4.2  nathanw }
    183  1.2.4.2  nathanw 
    184  1.2.4.2  nathanw void
    185  1.2.4.2  nathanw plum_conf_write(bus_space_tag_t t, bus_space_handle_t h, int o, plumreg_t v)
    186  1.2.4.2  nathanw {
    187  1.2.4.2  nathanw 
    188  1.2.4.2  nathanw 	bus_space_write_4(t, h, o, v);
    189  1.2.4.2  nathanw }
    190  1.2.4.2  nathanw 
    191  1.2.4.2  nathanw void
    192  1.2.4.2  nathanw plum_conf_register_intr(plum_chipset_tag_t t, void *intrt)
    193  1.2.4.2  nathanw {
    194  1.2.4.2  nathanw 
    195  1.2.4.2  nathanw 	if (t->pc_intrt) {
    196  1.2.4.2  nathanw 		panic("duplicate intrt");
    197  1.2.4.2  nathanw 	}
    198  1.2.4.2  nathanw 
    199  1.2.4.2  nathanw 	t->pc_intrt = intrt;
    200  1.2.4.2  nathanw }
    201  1.2.4.2  nathanw 
    202  1.2.4.2  nathanw void
    203  1.2.4.2  nathanw plum_conf_register_power(plum_chipset_tag_t t, void *powert)
    204  1.2.4.2  nathanw {
    205  1.2.4.2  nathanw 
    206  1.2.4.2  nathanw 	if (t->pc_powert) {
    207  1.2.4.2  nathanw 		panic("duplicate powert");
    208  1.2.4.2  nathanw 	}
    209  1.2.4.2  nathanw 
    210  1.2.4.2  nathanw 	t->pc_powert = powert;
    211  1.2.4.2  nathanw }
    212