Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.18.2.6
      1  1.18.2.6     skrll /*	$NetBSD: obio.c,v 1.18.2.6 2005/11/10 13:57:27 skrll 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.18.2.1     skrll #include <sys/cdefs.h>
     35  1.18.2.6     skrll __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.18.2.6 2005/11/10 13:57:27 skrll Exp $");
     36  1.18.2.1     skrll 
     37       1.1    tsubai #include <sys/param.h>
     38       1.1    tsubai #include <sys/systm.h>
     39       1.1    tsubai #include <sys/kernel.h>
     40       1.1    tsubai #include <sys/device.h>
     41       1.1    tsubai 
     42       1.1    tsubai #include <dev/pci/pcivar.h>
     43       1.1    tsubai #include <dev/pci/pcidevs.h>
     44       1.1    tsubai 
     45       1.1    tsubai #include <dev/ofw/openfirm.h>
     46       1.1    tsubai 
     47       1.1    tsubai #include <machine/autoconf.h>
     48       1.1    tsubai 
     49       1.1    tsubai static void obio_attach __P((struct device *, struct device *, void *));
     50       1.1    tsubai static int obio_match __P((struct device *, struct cfdata *, void *));
     51       1.1    tsubai static int obio_print __P((void *, const char *));
     52       1.1    tsubai 
     53       1.1    tsubai struct obio_softc {
     54       1.1    tsubai 	struct device sc_dev;
     55       1.1    tsubai 	int sc_node;
     56       1.1    tsubai };
     57       1.1    tsubai 
     58       1.1    tsubai 
     59      1.16   thorpej CFATTACH_DECL(obio, sizeof(struct obio_softc),
     60      1.16   thorpej     obio_match, obio_attach, NULL, NULL);
     61       1.1    tsubai 
     62       1.1    tsubai int
     63       1.1    tsubai obio_match(parent, cf, aux)
     64       1.1    tsubai 	struct device *parent;
     65       1.1    tsubai 	struct cfdata *cf;
     66       1.1    tsubai 	void *aux;
     67       1.1    tsubai {
     68       1.1    tsubai 	struct pci_attach_args *pa = aux;
     69       1.1    tsubai 
     70       1.2    tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
     71       1.2    tsubai 		switch (PCI_PRODUCT(pa->pa_id)) {
     72       1.7    tsubai 		case PCI_PRODUCT_APPLE_GC:
     73       1.7    tsubai 		case PCI_PRODUCT_APPLE_OHARE:
     74       1.7    tsubai 		case PCI_PRODUCT_APPLE_HEATHROW:
     75       1.7    tsubai 		case PCI_PRODUCT_APPLE_PADDINGTON:
     76       1.7    tsubai 		case PCI_PRODUCT_APPLE_KEYLARGO:
     77      1.14    tsubai 		case PCI_PRODUCT_APPLE_PANGEA_MACIO:
     78      1.18  hamajima 		case PCI_PRODUCT_APPLE_INTREPID:
     79       1.2    tsubai 			return 1;
     80       1.2    tsubai 		}
     81       1.1    tsubai 
     82       1.1    tsubai 	return 0;
     83       1.1    tsubai }
     84       1.1    tsubai 
     85       1.1    tsubai /*
     86       1.1    tsubai  * Attach all the sub-devices we can find
     87       1.1    tsubai  */
     88       1.1    tsubai void
     89       1.1    tsubai obio_attach(parent, self, aux)
     90       1.1    tsubai 	struct device *parent, *self;
     91       1.1    tsubai 	void *aux;
     92       1.1    tsubai {
     93       1.1    tsubai 	struct obio_softc *sc = (struct obio_softc *)self;
     94       1.2    tsubai 	struct pci_attach_args *pa = aux;
     95       1.1    tsubai 	struct confargs ca;
     96       1.1    tsubai 	int node, child, namelen;
     97       1.1    tsubai 	u_int reg[20];
     98  1.18.2.5     skrll 	int intr[6], parent_intr = 0, parent_nintr = 0;
     99       1.1    tsubai 	char name[32];
    100  1.18.2.5     skrll 	char compat[32];
    101       1.1    tsubai 
    102       1.2    tsubai 	switch (PCI_PRODUCT(pa->pa_id)) {
    103       1.2    tsubai 
    104       1.7    tsubai 	case PCI_PRODUCT_APPLE_GC:
    105       1.7    tsubai 	case PCI_PRODUCT_APPLE_OHARE:
    106       1.7    tsubai 	case PCI_PRODUCT_APPLE_HEATHROW:
    107       1.7    tsubai 	case PCI_PRODUCT_APPLE_PADDINGTON:
    108       1.7    tsubai 	case PCI_PRODUCT_APPLE_KEYLARGO:
    109      1.14    tsubai 	case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    110      1.18  hamajima 	case PCI_PRODUCT_APPLE_INTREPID:
    111  1.18.2.5     skrll 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    112       1.6    tsubai 		if (node == -1)
    113  1.18.2.5     skrll 			node = OF_finddevice("mac-io");
    114  1.18.2.5     skrll 			if (node == -1)
    115  1.18.2.5     skrll 				node = OF_finddevice("/pci/mac-io");
    116       1.2    tsubai 		break;
    117       1.2    tsubai 
    118       1.2    tsubai 	default:
    119       1.2    tsubai 		printf("obio_attach: unknown obio controller\n");
    120       1.2    tsubai 		return;
    121       1.2    tsubai 	}
    122       1.2    tsubai 
    123       1.1    tsubai 	sc->sc_node = node;
    124       1.1    tsubai 
    125       1.1    tsubai 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
    126       1.1    tsubai 		return;
    127       1.1    tsubai 	ca.ca_baseaddr = reg[2];
    128       1.1    tsubai 
    129       1.1    tsubai 	printf(": addr 0x%x\n", ca.ca_baseaddr);
    130      1.13    tsubai 
    131  1.18.2.4     skrll 	/* Enable internal modem (KeyLargo) */
    132  1.18.2.4     skrll 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
    133  1.18.2.4     skrll 		printf("enabling KeyLargo internal modem\n");
    134  1.18.2.4     skrll 		out32rb(ca.ca_baseaddr + 0x40,
    135  1.18.2.4     skrll 			in32rb(ca.ca_baseaddr + 0x40) & ~((u_int32_t)1<<25));
    136  1.18.2.4     skrll 	}
    137  1.18.2.4     skrll 
    138  1.18.2.4     skrll 	/* Enable internal modem (Pangea) */
    139  1.18.2.4     skrll 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
    140  1.18.2.4     skrll 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x04); /* set reset */
    141  1.18.2.4     skrll 		out8(ca.ca_baseaddr + 0x006a + 0x02, 0x04); /* power modem on */
    142  1.18.2.4     skrll 		out8(ca.ca_baseaddr + 0x006a + 0x03, 0x05); /* unset reset */
    143  1.18.2.4     skrll 	}
    144  1.18.2.4     skrll 
    145  1.18.2.5     skrll 	/* Gatwick and Paddington use same product ID */
    146  1.18.2.5     skrll 	namelen = OF_getprop(node, "compatible", compat, sizeof(compat));
    147       1.1    tsubai 
    148  1.18.2.5     skrll 	if (strcmp(compat, "gatwick") == 0) {
    149  1.18.2.5     skrll 		parent_nintr = OF_getprop(node, "AAPL,interrupts", intr,
    150  1.18.2.5     skrll 					sizeof(intr));
    151  1.18.2.5     skrll 		parent_intr = intr[0];
    152  1.18.2.5     skrll 	} else {
    153  1.18.2.5     skrll   		/* Enable CD and microphone sound input. */
    154  1.18.2.5     skrll 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    155  1.18.2.5     skrll 			out8(ca.ca_baseaddr + 0x37, 0x03);
    156  1.18.2.5     skrll 	}
    157  1.18.2.5     skrll 
    158       1.1    tsubai 	for (child = OF_child(node); child; child = OF_peer(child)) {
    159       1.1    tsubai 		namelen = OF_getprop(child, "name", name, sizeof(name));
    160       1.1    tsubai 		if (namelen < 0)
    161       1.1    tsubai 			continue;
    162       1.1    tsubai 		if (namelen >= sizeof(name))
    163       1.1    tsubai 			continue;
    164       1.1    tsubai 
    165       1.1    tsubai 		name[namelen] = 0;
    166       1.1    tsubai 		ca.ca_name = name;
    167       1.1    tsubai 		ca.ca_node = child;
    168       1.1    tsubai 
    169  1.18.2.5     skrll 		ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
    170       1.5    tsubai 
    171  1.18.2.5     skrll 		if (strcmp(compat, "gatwick") != 0) {
    172  1.18.2.5     skrll 			ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    173  1.18.2.5     skrll 					sizeof(intr));
    174  1.18.2.5     skrll 			if (ca.ca_nintr == -1)
    175  1.18.2.5     skrll 				ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    176  1.18.2.5     skrll 						sizeof(intr));
    177  1.18.2.5     skrll 		} else {
    178  1.18.2.5     skrll 			intr[0] = parent_intr;
    179  1.18.2.5     skrll 			ca.ca_nintr = parent_nintr;
    180  1.18.2.5     skrll 		}
    181       1.1    tsubai 		ca.ca_reg = reg;
    182       1.1    tsubai 		ca.ca_intr = intr;
    183       1.1    tsubai 
    184       1.1    tsubai 		config_found(self, &ca, obio_print);
    185       1.1    tsubai 	}
    186       1.1    tsubai }
    187       1.1    tsubai 
    188  1.18.2.6     skrll static const char *skiplist[] = {
    189       1.8    tsubai 	"interrupt-controller",
    190       1.8    tsubai 	"gpio",
    191       1.8    tsubai 	"escc-legacy",
    192       1.8    tsubai 	"timer",
    193       1.9    tsubai 	"i2c",
    194       1.9    tsubai 	"power-mgt"
    195       1.8    tsubai };
    196       1.8    tsubai 
    197       1.8    tsubai #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    198       1.8    tsubai 
    199       1.1    tsubai int
    200       1.1    tsubai obio_print(aux, obio)
    201       1.1    tsubai 	void *aux;
    202       1.1    tsubai 	const char *obio;
    203       1.1    tsubai {
    204       1.1    tsubai 	struct confargs *ca = aux;
    205       1.8    tsubai 	int i;
    206       1.8    tsubai 
    207       1.8    tsubai 	for (i = 0; i < N_LIST; i++)
    208       1.8    tsubai 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    209       1.8    tsubai 			return QUIET;
    210       1.1    tsubai 
    211       1.1    tsubai 	if (obio)
    212      1.17   thorpej 		aprint_normal("%s at %s", ca->ca_name, obio);
    213       1.1    tsubai 
    214       1.1    tsubai 	if (ca->ca_nreg > 0)
    215      1.17   thorpej 		aprint_normal(" offset 0x%x", ca->ca_reg[0]);
    216       1.1    tsubai 
    217       1.1    tsubai 	return UNCONF;
    218       1.1    tsubai }
    219