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