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