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