Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.20
      1 /*	$NetBSD: obio.c,v 1.20 2004/12/09 03:19:56 briggs 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.20 2004/12/09 03:19:56 briggs 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 internal modem (KeyLargo) */
    137 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
    138 		printf("enabling KeyLargo internal modem\n");
    139 		out32rb(ca.ca_baseaddr + 0x40,
    140 			in32rb(ca.ca_baseaddr + 0x40) & ~((u_int32_t)1<<25));
    141 	}
    142 
    143 	/* Enable internal modem (Pangea) */
    144 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
    145 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x04); /* set reset */
    146 		out8(ca.ca_baseaddr + 0x006a + 0x02, 0x04); /* power modem on */
    147 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x05); /* unset reset */
    148 	}
    149 
    150 	/* Enable CD and microphone sound input. */
    151 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    152 		out8(ca.ca_baseaddr + 0x37, 0x03);
    153 
    154 	for (child = OF_child(node); child; child = OF_peer(child)) {
    155 		namelen = OF_getprop(child, "name", name, sizeof(name));
    156 		if (namelen < 0)
    157 			continue;
    158 		if (namelen >= sizeof(name))
    159 			continue;
    160 
    161 		name[namelen] = 0;
    162 		ca.ca_name = name;
    163 		ca.ca_node = child;
    164 
    165 		ca.ca_nreg  = OF_getprop(child, "reg", reg, sizeof(reg));
    166 		ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    167 				sizeof(intr));
    168 		if (ca.ca_nintr == -1)
    169 			ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    170 					sizeof(intr));
    171 
    172 		ca.ca_reg = reg;
    173 		ca.ca_intr = intr;
    174 
    175 		config_found(self, &ca, obio_print);
    176 	}
    177 }
    178 
    179 static char *skiplist[] = {
    180 	"interrupt-controller",
    181 	"gpio",
    182 	"escc-legacy",
    183 	"timer",
    184 	"i2c",
    185 	"power-mgt"
    186 };
    187 
    188 #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    189 
    190 int
    191 obio_print(aux, obio)
    192 	void *aux;
    193 	const char *obio;
    194 {
    195 	struct confargs *ca = aux;
    196 	int i;
    197 
    198 	for (i = 0; i < N_LIST; i++)
    199 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    200 			return QUIET;
    201 
    202 	if (obio)
    203 		aprint_normal("%s at %s", ca->ca_name, obio);
    204 
    205 	if (ca->ca_nreg > 0)
    206 		aprint_normal(" offset 0x%x", ca->ca_reg[0]);
    207 
    208 	return UNCONF;
    209 }
    210