Home | History | Annotate | Line # | Download | only in dev
plum.c revision 1.1.12.1
      1 /*	$NetBSD: plum.c,v 1.1.12.1 2002/01/10 19:43:50 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 "opt_tx39_debug.h"
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/device.h>
     44 #include <sys/malloc.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <hpcmips/tx/tx39var.h>
     50 #include <hpcmips/tx/txcsbusvar.h>
     51 #include <hpcmips/dev/plumvar.h>
     52 #include <hpcmips/dev/plumreg.h>
     53 
     54 int plum_match(struct device *, struct cfdata *, void *);
     55 void plum_attach(struct device *, struct device *, void *);
     56 int plum_print(void *, const char *);
     57 int plum_search(struct device *, struct cfdata *, void *);
     58 
     59 struct plum_softc {
     60 	struct	device		sc_dev;
     61 	plum_chipset_tag_t	sc_pc;
     62 	bus_space_tag_t		sc_csregt;
     63 	bus_space_tag_t		sc_csiot;
     64 	bus_space_tag_t		sc_csmemt;
     65 	int			sc_irq;
     66 	int			sc_pri;
     67 };
     68 
     69 struct cfattach plum_ca = {
     70 	sizeof(struct plum_softc), plum_match, plum_attach
     71 };
     72 
     73 plumreg_t plum_idcheck(bus_space_tag_t);
     74 
     75 int
     76 plum_match(struct device *parent, struct cfdata *cf, void *aux)
     77 {
     78 	struct cs_attach_args *ca = aux;
     79 
     80 	switch (plum_idcheck(ca->ca_csreg.cstag)) {
     81 	default:
     82 		return (0);
     83 	case PLUM2_1:
     84 	case PLUM2_2:
     85 	}
     86 
     87 	return (1);
     88 }
     89 
     90 void
     91 plum_attach(struct device *parent, struct device *self, void *aux)
     92 {
     93 	struct cs_attach_args *ca = aux;
     94 	struct plum_softc *sc = (void*)self;
     95 	plumreg_t reg;
     96 
     97 	sc->sc_csregt	= ca->ca_csreg.cstag;
     98 	sc->sc_csiot	= ca->ca_csio.cstag;
     99 	sc->sc_csmemt	= ca->ca_csmem.cstag;
    100 	sc->sc_irq	= ca->ca_irq1;
    101 
    102 	switch (plum_idcheck(sc->sc_csregt)) {
    103 	default:
    104 		printf(": unknown revision %#x\n", reg);
    105 		return;
    106 	case PLUM2_1:
    107 		printf(": Plum2 #1\n");
    108 		break;
    109 	case PLUM2_2:
    110 		printf(": Plum2 #2\n");
    111 		break;
    112 	}
    113 	if (!(sc->sc_pc = malloc(sizeof(struct plum_chipset_tag),
    114 	    M_DEVBUF, M_NOWAIT))) {
    115 		panic("no memory");
    116 	}
    117 	memset(sc->sc_pc, 0, sizeof(struct plum_chipset_tag));
    118 	sc->sc_pc->pc_tc = ca->ca_tc;
    119 
    120 	/* Attach Plum devices */
    121 	/*
    122 	 * interrupt, power/clock module is used by other plum module.
    123 	 * attach first.
    124 	 */
    125 	sc->sc_pri = 2;
    126 	config_search(plum_search, self, plum_print);
    127 	/*
    128 	 * Other plum module.
    129 	 */
    130 	sc->sc_pri = 1;
    131 	config_search(plum_search, self, plum_print);
    132 }
    133 
    134 plumreg_t
    135 plum_idcheck(bus_space_tag_t regt)
    136 {
    137 	bus_space_handle_t regh;
    138 	plumreg_t reg;
    139 
    140 	if (bus_space_map(regt, PLUM_ID_REGBASE,
    141 	    PLUM_ID_REGSIZE, 0, &regh)) {
    142 		printf("ID register map failed\n");
    143 		return (0);
    144 	}
    145 	reg = plum_conf_read(regt, regh, PLUM_ID_REG);
    146 	bus_space_unmap(regt, regh, PLUM_ID_REGSIZE);
    147 
    148 	return (reg);
    149 }
    150 
    151 int
    152 plum_print(void *aux, const char *pnp)
    153 {
    154 
    155 	return (pnp ? QUIET : UNCONF);
    156 }
    157 
    158 int
    159 plum_search(struct device *parent, struct cfdata *cf, void *aux)
    160 {
    161 	struct plum_softc *sc = (void*)parent;
    162 	struct plum_attach_args pa;
    163 
    164 	pa.pa_pc	= sc->sc_pc;
    165 	pa.pa_regt	= sc->sc_csregt;
    166 	pa.pa_iot	= sc->sc_csiot;
    167 	pa.pa_memt	= sc->sc_csmemt;
    168 	pa.pa_irq	= sc->sc_irq;
    169 
    170 	if ((*cf->cf_attach->ca_match)(parent, cf, &pa) == sc->sc_pri) {
    171 		config_attach(parent, cf, &pa, plum_print);
    172 	}
    173 
    174 	return 0;
    175 }
    176 
    177 plumreg_t
    178 plum_conf_read(bus_space_tag_t t, bus_space_handle_t h, int o)
    179 {
    180 	plumreg_t reg;
    181 
    182 	reg = bus_space_read_4(t, h, o);
    183 
    184 	return (reg);
    185 }
    186 
    187 void
    188 plum_conf_write(bus_space_tag_t t, bus_space_handle_t h, int o, plumreg_t v)
    189 {
    190 
    191 	bus_space_write_4(t, h, o, v);
    192 }
    193 
    194 void
    195 plum_conf_register_intr(plum_chipset_tag_t t, void *intrt)
    196 {
    197 
    198 	if (t->pc_intrt) {
    199 		panic("duplicate intrt");
    200 	}
    201 
    202 	t->pc_intrt = intrt;
    203 }
    204 
    205 void
    206 plum_conf_register_power(plum_chipset_tag_t t, void *powert)
    207 {
    208 
    209 	if (t->pc_powert) {
    210 		panic("duplicate powert");
    211 	}
    212 
    213 	t->pc_powert = powert;
    214 }
    215