Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.24
      1 /*	$NetBSD: obio.c,v 1.24 2006/08/05 21:26:48 sanjayl 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.24 2006/08/05 21:26:48 sanjayl 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 		case PCI_PRODUCT_APPLE_GC:
     73 		case PCI_PRODUCT_APPLE_OHARE:
     74 		case PCI_PRODUCT_APPLE_HEATHROW:
     75 		case PCI_PRODUCT_APPLE_PADDINGTON:
     76 		case PCI_PRODUCT_APPLE_KEYLARGO:
     77 		case PCI_PRODUCT_APPLE_PANGEA_MACIO:
     78 		case PCI_PRODUCT_APPLE_INTREPID:
     79 		case PCI_PRODUCT_APPLE_K2:
     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], parent_intr = 0, parent_nintr = 0;
    100 	char name[32];
    101 	char compat[32];
    102 
    103 	switch (PCI_PRODUCT(pa->pa_id)) {
    104 
    105 	case PCI_PRODUCT_APPLE_GC:
    106 	case PCI_PRODUCT_APPLE_OHARE:
    107 	case PCI_PRODUCT_APPLE_HEATHROW:
    108 	case PCI_PRODUCT_APPLE_PADDINGTON:
    109 	case PCI_PRODUCT_APPLE_KEYLARGO:
    110 	case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    111 	case PCI_PRODUCT_APPLE_INTREPID:
    112 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    113 		if (node == -1)
    114 			node = OF_finddevice("mac-io");
    115 			if (node == -1)
    116 				node = OF_finddevice("/pci/mac-io");
    117 		break;
    118 	case PCI_PRODUCT_APPLE_K2:
    119 		node = OF_finddevice("mac-io");
    120 		if (node == -1)
    121 			panic("macio not found");
    122 		break;
    123 
    124 	default:
    125 		printf("obio_attach: unknown obio controller\n");
    126 		return;
    127 	}
    128 
    129 	sc->sc_node = node;
    130 
    131 #if defined (PMAC_G5)
    132 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 20)
    133 	{
    134 		return;
    135 	}
    136 #else
    137 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
    138 		return;
    139 #endif /* PMAC_G5 */
    140 
    141 	ca.ca_baseaddr = reg[2];
    142 
    143 	printf(": addr 0x%x\n", ca.ca_baseaddr);
    144 
    145 	/* Enable internal modem (KeyLargo) */
    146 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
    147 		printf("enabling KeyLargo internal modem\n");
    148 		out32rb(ca.ca_baseaddr + 0x40,
    149 			in32rb(ca.ca_baseaddr + 0x40) & ~((u_int32_t)1<<25));
    150 	}
    151 
    152 	/* Enable internal modem (Pangea) */
    153 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
    154 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x04); /* set reset */
    155 		out8(ca.ca_baseaddr + 0x006a + 0x02, 0x04); /* power modem on */
    156 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x05); /* unset reset */
    157 	}
    158 
    159 	/* Gatwick and Paddington use same product ID */
    160 	namelen = OF_getprop(node, "compatible", compat, sizeof(compat));
    161 
    162 	if (strcmp(compat, "gatwick") == 0) {
    163 		parent_nintr = OF_getprop(node, "AAPL,interrupts", intr,
    164 					sizeof(intr));
    165 		parent_intr = intr[0];
    166 	} else {
    167   		/* Enable CD and microphone sound input. */
    168 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    169 			out8(ca.ca_baseaddr + 0x37, 0x03);
    170 	}
    171 
    172 	for (child = OF_child(node); child; child = OF_peer(child)) {
    173 		namelen = OF_getprop(child, "name", name, sizeof(name));
    174 		if (namelen < 0)
    175 			continue;
    176 		if (namelen >= sizeof(name))
    177 			continue;
    178 
    179 		name[namelen] = 0;
    180 		ca.ca_name = name;
    181 		ca.ca_node = child;
    182 
    183 		ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
    184 
    185 		if (strcmp(compat, "gatwick") != 0) {
    186 			ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    187 					sizeof(intr));
    188 			if (ca.ca_nintr == -1)
    189 				ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    190 						sizeof(intr));
    191 		} else {
    192 			intr[0] = parent_intr;
    193 			ca.ca_nintr = parent_nintr;
    194 		}
    195 		ca.ca_reg = reg;
    196 		ca.ca_intr = intr;
    197 
    198 		config_found(self, &ca, obio_print);
    199 	}
    200 }
    201 
    202 static const char *skiplist[] = {
    203 	"interrupt-controller",
    204 	"gpio",
    205 	"escc-legacy",
    206 	"timer",
    207 	"i2c",
    208 	"power-mgt",
    209 	"escc"
    210 
    211 };
    212 
    213 #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    214 
    215 int
    216 obio_print(aux, obio)
    217 	void *aux;
    218 	const char *obio;
    219 {
    220 	struct confargs *ca = aux;
    221 	int i;
    222 
    223 	for (i = 0; i < N_LIST; i++)
    224 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    225 			return QUIET;
    226 
    227 	if (obio)
    228 		aprint_normal("%s at %s", ca->ca_name, obio);
    229 
    230 	if (ca->ca_nreg > 0)
    231 		aprint_normal(" offset 0x%x", ca->ca_reg[0]);
    232 
    233 	return UNCONF;
    234 }
    235