Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.26.14.2
      1  1.26.14.2  macallan /*	$NetBSD: obio.c,v 1.26.14.2 2007/06/18 03:00:17 macallan 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.19     lukem 
     34       1.19     lukem #include <sys/cdefs.h>
     35  1.26.14.2  macallan __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.26.14.2 2007/06/18 03:00:17 macallan Exp $");
     36        1.2    tsubai 
     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.26.14.1   garbled static void obio_attach(struct device *, struct device *, void *);
     50  1.26.14.1   garbled static int obio_match(struct device *, struct cfdata *, void *);
     51  1.26.14.1   garbled static int obio_print(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.26.14.1   garbled obio_match(struct device *parent, struct cfdata *cf, void *aux)
     64        1.1    tsubai {
     65        1.1    tsubai 	struct pci_attach_args *pa = aux;
     66        1.1    tsubai 
     67        1.2    tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
     68        1.2    tsubai 		switch (PCI_PRODUCT(pa->pa_id)) {
     69        1.7    tsubai 		case PCI_PRODUCT_APPLE_GC:
     70        1.7    tsubai 		case PCI_PRODUCT_APPLE_OHARE:
     71        1.7    tsubai 		case PCI_PRODUCT_APPLE_HEATHROW:
     72        1.7    tsubai 		case PCI_PRODUCT_APPLE_PADDINGTON:
     73        1.7    tsubai 		case PCI_PRODUCT_APPLE_KEYLARGO:
     74       1.14    tsubai 		case PCI_PRODUCT_APPLE_PANGEA_MACIO:
     75       1.18  hamajima 		case PCI_PRODUCT_APPLE_INTREPID:
     76       1.24   sanjayl 		case PCI_PRODUCT_APPLE_K2:
     77        1.2    tsubai 			return 1;
     78        1.2    tsubai 		}
     79        1.1    tsubai 
     80        1.1    tsubai 	return 0;
     81        1.1    tsubai }
     82        1.1    tsubai 
     83        1.1    tsubai /*
     84        1.1    tsubai  * Attach all the sub-devices we can find
     85        1.1    tsubai  */
     86        1.1    tsubai void
     87  1.26.14.1   garbled obio_attach(struct device *parent, struct device *self, void *aux)
     88        1.1    tsubai {
     89        1.1    tsubai 	struct obio_softc *sc = (struct obio_softc *)self;
     90        1.2    tsubai 	struct pci_attach_args *pa = aux;
     91        1.1    tsubai 	struct confargs ca;
     92  1.26.14.1   garbled 	bus_space_handle_t bsh;
     93  1.26.14.1   garbled 	int node, child, namelen, error;
     94        1.1    tsubai 	u_int reg[20];
     95       1.21    briggs 	int intr[6], parent_intr = 0, parent_nintr = 0;
     96        1.1    tsubai 	char name[32];
     97       1.21    briggs 	char compat[32];
     98        1.1    tsubai 
     99        1.2    tsubai 	switch (PCI_PRODUCT(pa->pa_id)) {
    100        1.2    tsubai 
    101        1.7    tsubai 	case PCI_PRODUCT_APPLE_GC:
    102        1.7    tsubai 	case PCI_PRODUCT_APPLE_OHARE:
    103        1.7    tsubai 	case PCI_PRODUCT_APPLE_HEATHROW:
    104        1.7    tsubai 	case PCI_PRODUCT_APPLE_PADDINGTON:
    105        1.7    tsubai 	case PCI_PRODUCT_APPLE_KEYLARGO:
    106       1.14    tsubai 	case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    107       1.18  hamajima 	case PCI_PRODUCT_APPLE_INTREPID:
    108       1.21    briggs 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    109        1.6    tsubai 		if (node == -1)
    110       1.21    briggs 			node = OF_finddevice("mac-io");
    111       1.21    briggs 			if (node == -1)
    112       1.21    briggs 				node = OF_finddevice("/pci/mac-io");
    113        1.2    tsubai 		break;
    114       1.24   sanjayl 	case PCI_PRODUCT_APPLE_K2:
    115       1.24   sanjayl 		node = OF_finddevice("mac-io");
    116       1.24   sanjayl 		break;
    117        1.2    tsubai 
    118        1.2    tsubai 	default:
    119  1.26.14.1   garbled 		node = -1;
    120  1.26.14.1   garbled 		break;
    121        1.2    tsubai 	}
    122  1.26.14.2  macallan 	if (node == -1)
    123  1.26.14.1   garbled 		panic("macio not found or unknown");
    124        1.2    tsubai 
    125        1.1    tsubai 	sc->sc_node = node;
    126        1.1    tsubai 
    127       1.24   sanjayl #if defined (PMAC_G5)
    128       1.24   sanjayl 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 20)
    129       1.24   sanjayl 	{
    130       1.24   sanjayl 		return;
    131       1.24   sanjayl 	}
    132       1.24   sanjayl #else
    133        1.1    tsubai 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
    134        1.1    tsubai 		return;
    135       1.24   sanjayl #endif /* PMAC_G5 */
    136       1.24   sanjayl 
    137        1.1    tsubai 	ca.ca_baseaddr = reg[2];
    138  1.26.14.2  macallan 	ca.ca_tag = pa->pa_memt;
    139  1.26.14.2  macallan 	error = bus_space_map (pa->pa_memt, ca.ca_baseaddr, 0x80, 0, &bsh);
    140  1.26.14.1   garbled 	if (error)
    141  1.26.14.1   garbled 		panic(": failed to map mac-io %#x", ca.ca_baseaddr);
    142        1.1    tsubai 
    143  1.26.14.2  macallan 	printf(": addr 0x%x\n", ca.ca_baseaddr);
    144       1.13    tsubai 
    145       1.20    briggs 	/* Enable internal modem (KeyLargo) */
    146       1.20    briggs 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
    147  1.26.14.1   garbled 		aprint_normal("%s: enabling KeyLargo internal modem\n",
    148  1.26.14.1   garbled 		    self->dv_xname);
    149  1.26.14.1   garbled 		bus_space_write_4(ca.ca_tag, bsh, 0x40,
    150  1.26.14.1   garbled 		    bus_space_read_4(ca.ca_tag, bsh, 0x40) & ~(1<<25));
    151       1.20    briggs 	}
    152       1.26  macallan 
    153       1.20    briggs 	/* Enable internal modem (Pangea) */
    154       1.20    briggs 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
    155  1.26.14.1   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x04); /* set reset */
    156  1.26.14.1   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x02, 0x04); /* power modem on */
    157  1.26.14.1   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x05); /* unset reset */
    158       1.20    briggs 	}
    159       1.20    briggs 
    160       1.21    briggs 	/* Gatwick and Paddington use same product ID */
    161       1.21    briggs 	namelen = OF_getprop(node, "compatible", compat, sizeof(compat));
    162        1.1    tsubai 
    163       1.21    briggs 	if (strcmp(compat, "gatwick") == 0) {
    164       1.21    briggs 		parent_nintr = OF_getprop(node, "AAPL,interrupts", intr,
    165       1.21    briggs 					sizeof(intr));
    166       1.21    briggs 		parent_intr = intr[0];
    167       1.21    briggs 	} else {
    168       1.21    briggs   		/* Enable CD and microphone sound input. */
    169       1.21    briggs 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    170  1.26.14.1   garbled 			bus_space_write_1(ca.ca_tag, bsh, 0x37, 0x03);
    171       1.21    briggs 	}
    172  1.26.14.2  macallan 
    173  1.26.14.1   garbled 	bus_space_unmap(ca.ca_tag, bsh, 0x80);
    174  1.26.14.2  macallan 
    175        1.1    tsubai 	for (child = OF_child(node); child; child = OF_peer(child)) {
    176        1.1    tsubai 		namelen = OF_getprop(child, "name", name, sizeof(name));
    177        1.1    tsubai 		if (namelen < 0)
    178        1.1    tsubai 			continue;
    179        1.1    tsubai 		if (namelen >= sizeof(name))
    180        1.1    tsubai 			continue;
    181        1.1    tsubai 
    182        1.1    tsubai 		name[namelen] = 0;
    183        1.1    tsubai 		ca.ca_name = name;
    184        1.1    tsubai 		ca.ca_node = child;
    185       1.25  macallan 		ca.ca_tag = pa->pa_memt;
    186       1.26  macallan 
    187       1.21    briggs 		ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
    188       1.26  macallan 
    189       1.21    briggs 		if (strcmp(compat, "gatwick") != 0) {
    190       1.21    briggs 			ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    191        1.5    tsubai 					sizeof(intr));
    192       1.21    briggs 			if (ca.ca_nintr == -1)
    193       1.21    briggs 				ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    194       1.21    briggs 						sizeof(intr));
    195       1.21    briggs 		} else {
    196       1.21    briggs 			intr[0] = parent_intr;
    197       1.21    briggs 			ca.ca_nintr = parent_nintr;
    198       1.21    briggs 		}
    199        1.1    tsubai 		ca.ca_reg = reg;
    200        1.1    tsubai 		ca.ca_intr = intr;
    201        1.1    tsubai 
    202        1.1    tsubai 		config_found(self, &ca, obio_print);
    203        1.1    tsubai 	}
    204        1.1    tsubai }
    205        1.1    tsubai 
    206  1.26.14.1   garbled static const char * const skiplist[] = {
    207        1.8    tsubai 	"interrupt-controller",
    208        1.8    tsubai 	"gpio",
    209        1.8    tsubai 	"escc-legacy",
    210        1.8    tsubai 	"timer",
    211        1.9    tsubai 	"i2c",
    212       1.24   sanjayl 	"power-mgt",
    213       1.24   sanjayl 	"escc"
    214       1.24   sanjayl 
    215        1.8    tsubai };
    216        1.8    tsubai 
    217        1.8    tsubai #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    218        1.8    tsubai 
    219        1.1    tsubai int
    220        1.1    tsubai obio_print(aux, obio)
    221        1.1    tsubai 	void *aux;
    222        1.1    tsubai 	const char *obio;
    223        1.1    tsubai {
    224        1.1    tsubai 	struct confargs *ca = aux;
    225        1.8    tsubai 	int i;
    226        1.8    tsubai 
    227        1.8    tsubai 	for (i = 0; i < N_LIST; i++)
    228        1.8    tsubai 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    229        1.8    tsubai 			return QUIET;
    230        1.1    tsubai 
    231        1.1    tsubai 	if (obio)
    232       1.17   thorpej 		aprint_normal("%s at %s", ca->ca_name, obio);
    233        1.1    tsubai 
    234        1.1    tsubai 	if (ca->ca_nreg > 0)
    235       1.17   thorpej 		aprint_normal(" offset 0x%x", ca->ca_reg[0]);
    236        1.1    tsubai 
    237        1.1    tsubai 	return UNCONF;
    238        1.1    tsubai }
    239