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