Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.14.18.1
      1  1.14.18.1   grant /*	$NetBSD: obio.c,v 1.14.18.1 2003/06/19 11:18:56 grant Exp $	*/
      2        1.2  tsubai 
      3        1.2  tsubai /*-
      4        1.2  tsubai  * Copyright (C) 1998	Internet Research Institute, Inc.
      5        1.2  tsubai  * All rights reserved.
      6        1.2  tsubai  *
      7        1.2  tsubai  * Redistribution and use in source and binary forms, with or without
      8        1.2  tsubai  * modification, are permitted provided that the following conditions
      9        1.2  tsubai  * are met:
     10        1.2  tsubai  * 1. Redistributions of source code must retain the above copyright
     11        1.2  tsubai  *    notice, this list of conditions and the following disclaimer.
     12        1.2  tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.2  tsubai  *    notice, this list of conditions and the following disclaimer in the
     14        1.2  tsubai  *    documentation and/or other materials provided with the distribution.
     15        1.2  tsubai  * 3. All advertising materials mentioning features or use of this software
     16        1.2  tsubai  *    must display the following acknowledgement:
     17        1.2  tsubai  *	This product includes software developed by
     18        1.2  tsubai  *	Internet Research Institute, Inc.
     19        1.2  tsubai  * 4. The name of the author may not be used to endorse or promote products
     20        1.2  tsubai  *    derived from this software without specific prior written permission.
     21        1.2  tsubai  *
     22        1.2  tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23        1.2  tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24        1.2  tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25        1.2  tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26        1.2  tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27        1.2  tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28        1.2  tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29        1.2  tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30        1.2  tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31        1.2  tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32        1.2  tsubai  */
     33        1.2  tsubai 
     34        1.1  tsubai #include <sys/param.h>
     35        1.1  tsubai #include <sys/systm.h>
     36        1.1  tsubai #include <sys/kernel.h>
     37        1.1  tsubai #include <sys/device.h>
     38        1.1  tsubai 
     39        1.1  tsubai #include <dev/pci/pcivar.h>
     40        1.1  tsubai #include <dev/pci/pcidevs.h>
     41        1.1  tsubai 
     42        1.1  tsubai #include <dev/ofw/openfirm.h>
     43        1.1  tsubai 
     44        1.1  tsubai #include <machine/autoconf.h>
     45        1.1  tsubai 
     46        1.1  tsubai static void obio_attach __P((struct device *, struct device *, void *));
     47        1.1  tsubai static int obio_match __P((struct device *, struct cfdata *, void *));
     48        1.1  tsubai static int obio_print __P((void *, const char *));
     49        1.1  tsubai 
     50        1.1  tsubai struct obio_softc {
     51        1.1  tsubai 	struct device sc_dev;
     52        1.1  tsubai 	int sc_node;
     53        1.1  tsubai };
     54        1.1  tsubai 
     55        1.1  tsubai 
     56        1.1  tsubai struct cfattach obio_ca = {
     57        1.1  tsubai 	sizeof(struct obio_softc), obio_match, obio_attach
     58        1.1  tsubai };
     59        1.1  tsubai 
     60        1.1  tsubai int
     61        1.1  tsubai obio_match(parent, cf, aux)
     62        1.1  tsubai 	struct device *parent;
     63        1.1  tsubai 	struct cfdata *cf;
     64        1.1  tsubai 	void *aux;
     65        1.1  tsubai {
     66        1.1  tsubai 	struct pci_attach_args *pa = aux;
     67        1.1  tsubai 
     68        1.2  tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
     69        1.2  tsubai 		switch (PCI_PRODUCT(pa->pa_id)) {
     70        1.2  tsubai 
     71        1.7  tsubai 		case PCI_PRODUCT_APPLE_GC:
     72        1.7  tsubai 		case PCI_PRODUCT_APPLE_OHARE:
     73        1.7  tsubai 		case PCI_PRODUCT_APPLE_HEATHROW:
     74        1.7  tsubai 		case PCI_PRODUCT_APPLE_PADDINGTON:
     75        1.7  tsubai 		case PCI_PRODUCT_APPLE_KEYLARGO:
     76       1.14  tsubai 		case PCI_PRODUCT_APPLE_PANGEA_MACIO:
     77  1.14.18.1   grant 		case PCI_PRODUCT_APPLE_INTREPID:
     78        1.2  tsubai 			return 1;
     79        1.2  tsubai 		}
     80        1.1  tsubai 
     81        1.1  tsubai 	return 0;
     82        1.1  tsubai }
     83        1.1  tsubai 
     84        1.1  tsubai /*
     85        1.1  tsubai  * Attach all the sub-devices we can find
     86        1.1  tsubai  */
     87        1.1  tsubai void
     88        1.1  tsubai obio_attach(parent, self, aux)
     89        1.1  tsubai 	struct device *parent, *self;
     90        1.1  tsubai 	void *aux;
     91        1.1  tsubai {
     92        1.1  tsubai 	struct obio_softc *sc = (struct obio_softc *)self;
     93        1.2  tsubai 	struct pci_attach_args *pa = aux;
     94        1.1  tsubai 	struct confargs ca;
     95        1.1  tsubai 	int node, child, namelen;
     96        1.1  tsubai 	u_int reg[20];
     97       1.10  tsubai 	int intr[6];
     98        1.1  tsubai 	char name[32];
     99        1.1  tsubai 
    100        1.2  tsubai 	switch (PCI_PRODUCT(pa->pa_id)) {
    101        1.2  tsubai 
    102        1.6  tsubai 	/* XXX should not use name */
    103        1.7  tsubai 	case PCI_PRODUCT_APPLE_GC:
    104        1.2  tsubai 		node = OF_finddevice("/bandit/gc");
    105        1.2  tsubai 		break;
    106        1.2  tsubai 
    107        1.7  tsubai 	case PCI_PRODUCT_APPLE_OHARE:
    108        1.2  tsubai 		node = OF_finddevice("/bandit/ohare");
    109        1.3  tsubai 		break;
    110        1.3  tsubai 
    111        1.7  tsubai 	case PCI_PRODUCT_APPLE_HEATHROW:
    112        1.7  tsubai 	case PCI_PRODUCT_APPLE_PADDINGTON:
    113        1.7  tsubai 	case PCI_PRODUCT_APPLE_KEYLARGO:
    114       1.14  tsubai 	case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    115  1.14.18.1   grant 	case PCI_PRODUCT_APPLE_INTREPID:
    116        1.6  tsubai 		node = OF_finddevice("mac-io");
    117        1.6  tsubai 		if (node == -1)
    118        1.6  tsubai 			node = OF_finddevice("/pci/mac-io");
    119        1.2  tsubai 		break;
    120        1.2  tsubai 
    121        1.2  tsubai 	default:
    122        1.2  tsubai 		printf("obio_attach: unknown obio controller\n");
    123        1.2  tsubai 		return;
    124        1.2  tsubai 	}
    125        1.2  tsubai 
    126        1.1  tsubai 	sc->sc_node = node;
    127        1.1  tsubai 
    128        1.1  tsubai 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
    129        1.1  tsubai 		return;
    130        1.1  tsubai 	ca.ca_baseaddr = reg[2];
    131        1.1  tsubai 
    132        1.1  tsubai 	printf(": addr 0x%x\n", ca.ca_baseaddr);
    133       1.13  tsubai 
    134       1.13  tsubai 	/* Enable CD and microphone sound input. */
    135       1.13  tsubai 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    136       1.13  tsubai 		out8(ca.ca_baseaddr + 0x37, 0x03);
    137        1.1  tsubai 
    138        1.1  tsubai 	for (child = OF_child(node); child; child = OF_peer(child)) {
    139        1.1  tsubai 		namelen = OF_getprop(child, "name", name, sizeof(name));
    140        1.1  tsubai 		if (namelen < 0)
    141        1.1  tsubai 			continue;
    142        1.1  tsubai 		if (namelen >= sizeof(name))
    143        1.1  tsubai 			continue;
    144        1.1  tsubai 
    145        1.1  tsubai 		name[namelen] = 0;
    146        1.1  tsubai 		ca.ca_name = name;
    147        1.1  tsubai 		ca.ca_node = child;
    148        1.1  tsubai 
    149        1.1  tsubai 		ca.ca_nreg  = OF_getprop(child, "reg", reg, sizeof(reg));
    150        1.1  tsubai 		ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    151        1.1  tsubai 				sizeof(intr));
    152        1.5  tsubai 		if (ca.ca_nintr == -1)
    153        1.5  tsubai 			ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    154        1.5  tsubai 					sizeof(intr));
    155        1.5  tsubai 
    156        1.1  tsubai 		ca.ca_reg = reg;
    157        1.1  tsubai 		ca.ca_intr = intr;
    158        1.1  tsubai 
    159        1.1  tsubai 		config_found(self, &ca, obio_print);
    160        1.1  tsubai 	}
    161        1.1  tsubai }
    162        1.1  tsubai 
    163        1.8  tsubai static char *skiplist[] = {
    164        1.8  tsubai 	"interrupt-controller",
    165        1.8  tsubai 	"gpio",
    166        1.8  tsubai 	"escc-legacy",
    167        1.8  tsubai 	"timer",
    168        1.9  tsubai 	"i2c",
    169        1.9  tsubai 	"power-mgt"
    170        1.8  tsubai };
    171        1.8  tsubai 
    172        1.8  tsubai #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    173        1.8  tsubai 
    174        1.1  tsubai int
    175        1.1  tsubai obio_print(aux, obio)
    176        1.1  tsubai 	void *aux;
    177        1.1  tsubai 	const char *obio;
    178        1.1  tsubai {
    179        1.1  tsubai 	struct confargs *ca = aux;
    180        1.8  tsubai 	int i;
    181        1.8  tsubai 
    182        1.8  tsubai 	for (i = 0; i < N_LIST; i++)
    183        1.8  tsubai 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    184        1.8  tsubai 			return QUIET;
    185        1.1  tsubai 
    186        1.1  tsubai 	if (obio)
    187        1.1  tsubai 		printf("%s at %s", ca->ca_name, obio);
    188        1.1  tsubai 
    189        1.1  tsubai 	if (ca->ca_nreg > 0)
    190        1.1  tsubai 		printf(" offset 0x%x", ca->ca_reg[0]);
    191        1.1  tsubai 
    192        1.1  tsubai 	return UNCONF;
    193        1.1  tsubai }
    194