Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.27.26.1
      1  1.27.26.1      haad /*	$NetBSD: obio.c,v 1.27.26.1 2008/10/19 22:15:52 haad 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.27.26.1      haad __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.27.26.1 2008/10/19 22:15:52 haad 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.27   garbled #include <sys/sysctl.h>
     42        1.1    tsubai 
     43        1.1    tsubai #include <dev/pci/pcivar.h>
     44        1.1    tsubai #include <dev/pci/pcidevs.h>
     45        1.1    tsubai 
     46        1.1    tsubai #include <dev/ofw/openfirm.h>
     47        1.1    tsubai 
     48        1.1    tsubai #include <machine/autoconf.h>
     49        1.1    tsubai 
     50  1.27.26.1      haad #include <macppc/dev/obiovar.h>
     51  1.27.26.1      haad 
     52       1.27   garbled #include "opt_obio.h"
     53       1.27   garbled 
     54       1.27   garbled #ifdef OBIO_DEBUG
     55       1.27   garbled # define DPRINTF printf
     56       1.27   garbled #else
     57       1.27   garbled # define DPRINTF while (0) printf
     58       1.27   garbled #endif
     59       1.27   garbled 
     60       1.27   garbled static void obio_attach(struct device *, struct device *, void *);
     61       1.27   garbled static int obio_match(struct device *, struct cfdata *, void *);
     62       1.27   garbled static int obio_print(void *, const char *);
     63        1.1    tsubai 
     64        1.1    tsubai struct obio_softc {
     65        1.1    tsubai 	struct device sc_dev;
     66       1.27   garbled 	bus_space_tag_t sc_tag;
     67       1.27   garbled 	bus_space_handle_t sc_bh;
     68        1.1    tsubai 	int sc_node;
     69       1.27   garbled #ifdef OBIO_SPEED_CONTROL
     70       1.27   garbled 	int sc_voltage;
     71       1.27   garbled 	int sc_busspeed;
     72       1.27   garbled #endif
     73        1.1    tsubai };
     74        1.1    tsubai 
     75  1.27.26.1      haad static struct obio_softc *obio0 = NULL;
     76  1.27.26.1      haad 
     77       1.27   garbled #ifdef OBIO_SPEED_CONTROL
     78       1.27   garbled static void obio_setup_gpios(struct obio_softc *, int);
     79       1.27   garbled static void obio_set_cpu_speed(struct obio_softc *, int);
     80       1.27   garbled static int  obio_get_cpu_speed(struct obio_softc *);
     81       1.27   garbled static int  sysctl_cpuspeed_temp(SYSCTLFN_ARGS);
     82       1.27   garbled 
     83       1.27   garbled static const char *keylargo[] = {"Keylargo",
     84       1.27   garbled 				 "AAPL,Keylargo",
     85       1.27   garbled 				 NULL};
     86       1.27   garbled 
     87       1.27   garbled #endif
     88        1.1    tsubai 
     89       1.16   thorpej CFATTACH_DECL(obio, sizeof(struct obio_softc),
     90       1.16   thorpej     obio_match, obio_attach, NULL, NULL);
     91        1.1    tsubai 
     92        1.1    tsubai int
     93       1.27   garbled obio_match(struct device *parent, struct cfdata *cf, void *aux)
     94        1.1    tsubai {
     95        1.1    tsubai 	struct pci_attach_args *pa = aux;
     96        1.1    tsubai 
     97        1.2    tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
     98        1.2    tsubai 		switch (PCI_PRODUCT(pa->pa_id)) {
     99        1.7    tsubai 		case PCI_PRODUCT_APPLE_GC:
    100        1.7    tsubai 		case PCI_PRODUCT_APPLE_OHARE:
    101        1.7    tsubai 		case PCI_PRODUCT_APPLE_HEATHROW:
    102        1.7    tsubai 		case PCI_PRODUCT_APPLE_PADDINGTON:
    103        1.7    tsubai 		case PCI_PRODUCT_APPLE_KEYLARGO:
    104       1.14    tsubai 		case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    105       1.18  hamajima 		case PCI_PRODUCT_APPLE_INTREPID:
    106       1.24   sanjayl 		case PCI_PRODUCT_APPLE_K2:
    107        1.2    tsubai 			return 1;
    108        1.2    tsubai 		}
    109        1.1    tsubai 
    110        1.1    tsubai 	return 0;
    111        1.1    tsubai }
    112        1.1    tsubai 
    113        1.1    tsubai /*
    114        1.1    tsubai  * Attach all the sub-devices we can find
    115        1.1    tsubai  */
    116        1.1    tsubai void
    117       1.27   garbled obio_attach(struct device *parent, struct device *self, void *aux)
    118        1.1    tsubai {
    119        1.1    tsubai 	struct obio_softc *sc = (struct obio_softc *)self;
    120        1.2    tsubai 	struct pci_attach_args *pa = aux;
    121        1.1    tsubai 	struct confargs ca;
    122       1.27   garbled 	bus_space_handle_t bsh;
    123       1.27   garbled 	int node, child, namelen, error;
    124        1.1    tsubai 	u_int reg[20];
    125       1.21    briggs 	int intr[6], parent_intr = 0, parent_nintr = 0;
    126        1.1    tsubai 	char name[32];
    127       1.21    briggs 	char compat[32];
    128        1.1    tsubai 
    129       1.27   garbled #ifdef OBIO_SPEED_CONTROL
    130       1.27   garbled 	sc->sc_voltage = -1;
    131       1.27   garbled 	sc->sc_busspeed = -1;
    132       1.27   garbled #endif
    133       1.27   garbled 
    134        1.2    tsubai 	switch (PCI_PRODUCT(pa->pa_id)) {
    135        1.2    tsubai 
    136        1.7    tsubai 	case PCI_PRODUCT_APPLE_GC:
    137        1.7    tsubai 	case PCI_PRODUCT_APPLE_OHARE:
    138        1.7    tsubai 	case PCI_PRODUCT_APPLE_HEATHROW:
    139        1.7    tsubai 	case PCI_PRODUCT_APPLE_PADDINGTON:
    140        1.7    tsubai 	case PCI_PRODUCT_APPLE_KEYLARGO:
    141       1.14    tsubai 	case PCI_PRODUCT_APPLE_PANGEA_MACIO:
    142       1.18  hamajima 	case PCI_PRODUCT_APPLE_INTREPID:
    143       1.21    briggs 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    144        1.6    tsubai 		if (node == -1)
    145       1.21    briggs 			node = OF_finddevice("mac-io");
    146       1.21    briggs 			if (node == -1)
    147       1.21    briggs 				node = OF_finddevice("/pci/mac-io");
    148        1.2    tsubai 		break;
    149       1.24   sanjayl 	case PCI_PRODUCT_APPLE_K2:
    150       1.24   sanjayl 		node = OF_finddevice("mac-io");
    151       1.24   sanjayl 		break;
    152        1.2    tsubai 
    153        1.2    tsubai 	default:
    154       1.27   garbled 		node = -1;
    155       1.27   garbled 		break;
    156        1.2    tsubai 	}
    157       1.27   garbled 	if (node == -1)
    158       1.27   garbled 		panic("macio not found or unknown");
    159        1.2    tsubai 
    160        1.1    tsubai 	sc->sc_node = node;
    161        1.1    tsubai 
    162       1.24   sanjayl #if defined (PMAC_G5)
    163       1.24   sanjayl 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 20)
    164       1.24   sanjayl 	{
    165       1.24   sanjayl 		return;
    166       1.24   sanjayl 	}
    167       1.24   sanjayl #else
    168        1.1    tsubai 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
    169        1.1    tsubai 		return;
    170       1.24   sanjayl #endif /* PMAC_G5 */
    171       1.24   sanjayl 
    172  1.27.26.1      haad 	/*
    173  1.27.26.1      haad 	 * XXX
    174  1.27.26.1      haad 	 * This relies on the primary obio always attaching first which is
    175  1.27.26.1      haad 	 * true on the PowerBook 3400c and similar machines but may or may
    176  1.27.26.1      haad 	 * not work on others. We can't rely on the node name since Apple
    177  1.27.26.1      haad 	 * didn't follow anything remotely resembling a consistent naming
    178  1.27.26.1      haad 	 * scheme.
    179  1.27.26.1      haad 	 */
    180  1.27.26.1      haad 	if (obio0 == NULL)
    181  1.27.26.1      haad 		obio0 = sc;
    182  1.27.26.1      haad 
    183        1.1    tsubai 	ca.ca_baseaddr = reg[2];
    184       1.27   garbled 	ca.ca_tag = pa->pa_memt;
    185       1.27   garbled 	sc->sc_tag = pa->pa_memt;
    186       1.27   garbled 	error = bus_space_map (pa->pa_memt, ca.ca_baseaddr, 0x80, 0, &bsh);
    187       1.27   garbled 	if (error)
    188       1.27   garbled 		panic(": failed to map mac-io %#x", ca.ca_baseaddr);
    189       1.27   garbled 	sc->sc_bh = bsh;
    190        1.1    tsubai 
    191        1.1    tsubai 	printf(": addr 0x%x\n", ca.ca_baseaddr);
    192       1.13    tsubai 
    193       1.20    briggs 	/* Enable internal modem (KeyLargo) */
    194       1.20    briggs 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
    195       1.27   garbled 		aprint_normal("%s: enabling KeyLargo internal modem\n",
    196       1.27   garbled 		    self->dv_xname);
    197       1.27   garbled 		bus_space_write_4(ca.ca_tag, bsh, 0x40,
    198       1.27   garbled 		    bus_space_read_4(ca.ca_tag, bsh, 0x40) & ~(1<<25));
    199       1.20    briggs 	}
    200       1.26  macallan 
    201       1.20    briggs 	/* Enable internal modem (Pangea) */
    202       1.20    briggs 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
    203       1.27   garbled 		/* set reset */
    204       1.27   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x04);
    205       1.27   garbled 		/* power modem on */
    206       1.27   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x02, 0x04);
    207       1.27   garbled 		/* unset reset */
    208       1.27   garbled 		bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x05);
    209       1.20    briggs 	}
    210       1.20    briggs 
    211       1.21    briggs 	/* Gatwick and Paddington use same product ID */
    212       1.21    briggs 	namelen = OF_getprop(node, "compatible", compat, sizeof(compat));
    213        1.1    tsubai 
    214       1.21    briggs 	if (strcmp(compat, "gatwick") == 0) {
    215       1.21    briggs 		parent_nintr = OF_getprop(node, "AAPL,interrupts", intr,
    216       1.21    briggs 					sizeof(intr));
    217       1.21    briggs 		parent_intr = intr[0];
    218       1.21    briggs 	} else {
    219       1.21    briggs   		/* Enable CD and microphone sound input. */
    220       1.21    briggs 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
    221       1.27   garbled 			bus_space_write_1(ca.ca_tag, bsh, 0x37, 0x03);
    222       1.21    briggs 	}
    223       1.27   garbled 
    224        1.1    tsubai 	for (child = OF_child(node); child; child = OF_peer(child)) {
    225        1.1    tsubai 		namelen = OF_getprop(child, "name", name, sizeof(name));
    226        1.1    tsubai 		if (namelen < 0)
    227        1.1    tsubai 			continue;
    228        1.1    tsubai 		if (namelen >= sizeof(name))
    229        1.1    tsubai 			continue;
    230        1.1    tsubai 
    231       1.27   garbled #ifdef OBIO_SPEED_CONTROL
    232       1.27   garbled 		if (strcmp(name, "gpio") == 0) {
    233       1.27   garbled 
    234       1.27   garbled 			obio_setup_gpios(sc, child);
    235       1.27   garbled 			continue;
    236       1.27   garbled 		}
    237       1.27   garbled #endif
    238       1.27   garbled 
    239        1.1    tsubai 		name[namelen] = 0;
    240        1.1    tsubai 		ca.ca_name = name;
    241        1.1    tsubai 		ca.ca_node = child;
    242       1.25  macallan 		ca.ca_tag = pa->pa_memt;
    243       1.26  macallan 
    244       1.21    briggs 		ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
    245       1.26  macallan 
    246       1.21    briggs 		if (strcmp(compat, "gatwick") != 0) {
    247       1.21    briggs 			ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
    248        1.5    tsubai 					sizeof(intr));
    249       1.21    briggs 			if (ca.ca_nintr == -1)
    250       1.21    briggs 				ca.ca_nintr = OF_getprop(child, "interrupts", intr,
    251       1.21    briggs 						sizeof(intr));
    252       1.21    briggs 		} else {
    253       1.21    briggs 			intr[0] = parent_intr;
    254       1.21    briggs 			ca.ca_nintr = parent_nintr;
    255       1.21    briggs 		}
    256        1.1    tsubai 		ca.ca_reg = reg;
    257        1.1    tsubai 		ca.ca_intr = intr;
    258        1.1    tsubai 
    259        1.1    tsubai 		config_found(self, &ca, obio_print);
    260        1.1    tsubai 	}
    261        1.1    tsubai }
    262        1.1    tsubai 
    263       1.27   garbled static const char * const skiplist[] = {
    264        1.8    tsubai 	"interrupt-controller",
    265        1.8    tsubai 	"gpio",
    266        1.8    tsubai 	"escc-legacy",
    267        1.8    tsubai 	"timer",
    268        1.9    tsubai 	"i2c",
    269       1.24   sanjayl 	"power-mgt",
    270       1.27   garbled 	"escc",
    271       1.27   garbled 	"battery",
    272       1.27   garbled 	"backlight"
    273       1.24   sanjayl 
    274        1.8    tsubai };
    275        1.8    tsubai 
    276        1.8    tsubai #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
    277        1.8    tsubai 
    278        1.1    tsubai int
    279        1.1    tsubai obio_print(aux, obio)
    280        1.1    tsubai 	void *aux;
    281        1.1    tsubai 	const char *obio;
    282        1.1    tsubai {
    283        1.1    tsubai 	struct confargs *ca = aux;
    284        1.8    tsubai 	int i;
    285        1.8    tsubai 
    286        1.8    tsubai 	for (i = 0; i < N_LIST; i++)
    287        1.8    tsubai 		if (strcmp(ca->ca_name, skiplist[i]) == 0)
    288        1.8    tsubai 			return QUIET;
    289        1.1    tsubai 
    290        1.1    tsubai 	if (obio)
    291       1.17   thorpej 		aprint_normal("%s at %s", ca->ca_name, obio);
    292        1.1    tsubai 
    293        1.1    tsubai 	if (ca->ca_nreg > 0)
    294       1.17   thorpej 		aprint_normal(" offset 0x%x", ca->ca_reg[0]);
    295        1.1    tsubai 
    296        1.1    tsubai 	return UNCONF;
    297        1.1    tsubai }
    298       1.27   garbled 
    299  1.27.26.1      haad void obio_write_4(int offset, uint32_t value)
    300  1.27.26.1      haad {
    301  1.27.26.1      haad 	if (obio0 == NULL)
    302  1.27.26.1      haad 		return;
    303  1.27.26.1      haad 	bus_space_write_4(obio0->sc_tag, obio0->sc_bh, offset, value);
    304  1.27.26.1      haad }
    305  1.27.26.1      haad 
    306  1.27.26.1      haad void obio_write_1(int offset, uint8_t value)
    307  1.27.26.1      haad {
    308  1.27.26.1      haad 	if (obio0 == NULL)
    309  1.27.26.1      haad 		return;
    310  1.27.26.1      haad 	bus_space_write_1(obio0->sc_tag, obio0->sc_bh, offset, value);
    311  1.27.26.1      haad }
    312  1.27.26.1      haad 
    313  1.27.26.1      haad uint32_t obio_read_4(int offset)
    314  1.27.26.1      haad {
    315  1.27.26.1      haad 	if (obio0 == NULL)
    316  1.27.26.1      haad 		return 0xffffffff;
    317  1.27.26.1      haad 	return bus_space_read_4(obio0->sc_tag, obio0->sc_bh, offset);
    318  1.27.26.1      haad }
    319  1.27.26.1      haad 
    320  1.27.26.1      haad uint8_t obio_read_1(int offset)
    321  1.27.26.1      haad {
    322  1.27.26.1      haad 	if (obio0 == NULL)
    323  1.27.26.1      haad 		return 0xff;
    324  1.27.26.1      haad 	return bus_space_read_1(obio0->sc_tag, obio0->sc_bh, offset);
    325  1.27.26.1      haad }
    326  1.27.26.1      haad 
    327       1.27   garbled #ifdef OBIO_SPEED_CONTROL
    328       1.27   garbled 
    329       1.27   garbled static void
    330       1.27   garbled obio_setup_gpios(struct obio_softc *sc, int node)
    331       1.27   garbled {
    332       1.27   garbled 	uint32_t reg[6];
    333       1.27   garbled 	struct sysctlnode *sysctl_node = NULL;
    334       1.27   garbled 	char name[32];
    335       1.27   garbled 	int gpio_base, child;
    336       1.27   garbled 
    337       1.27   garbled 	if (of_compatible(sc->sc_node, keylargo) == -1)
    338       1.27   garbled 		return;
    339       1.27   garbled 
    340       1.27   garbled 	if (OF_getprop(node, "reg", reg, sizeof(reg)) < 4)
    341       1.27   garbled 		return;
    342       1.27   garbled 
    343       1.27   garbled 	gpio_base = reg[0];
    344       1.27   garbled 	DPRINTF("gpio_base: %02x\n", gpio_base);
    345       1.27   garbled 
    346       1.27   garbled 	/* now look for voltage and bus speed gpios */
    347       1.27   garbled 	for (child = OF_child(node); child; child = OF_peer(child)) {
    348       1.27   garbled 
    349       1.27   garbled 		if (OF_getprop(child, "name", name, sizeof(name)) < 1)
    350       1.27   garbled 			continue;
    351       1.27   garbled 
    352       1.27   garbled 		if (OF_getprop(child, "reg", reg, sizeof(reg)) < 4)
    353       1.27   garbled 			continue;
    354       1.27   garbled 
    355       1.27   garbled 		if (strcmp(name, "frequency-gpio") == 0) {
    356       1.27   garbled 			DPRINTF("found frequency_gpio at %02x\n", reg[0]);
    357       1.27   garbled 			sc->sc_busspeed = gpio_base + reg[0];
    358       1.27   garbled 		}
    359       1.27   garbled 		if (strcmp(name, "voltage-gpio") == 0) {
    360       1.27   garbled 			DPRINTF("found voltage_gpio at %02x\n", reg[0]);
    361       1.27   garbled 			sc->sc_voltage = gpio_base + reg[0];
    362       1.27   garbled 		}
    363       1.27   garbled 	}
    364       1.27   garbled 
    365       1.27   garbled 	if ((sc->sc_voltage < 0) || (sc->sc_busspeed < 0))
    366       1.27   garbled 		return;
    367       1.27   garbled 
    368       1.27   garbled 	printf("%s: enabling Intrepid CPU speed control\n",
    369       1.27   garbled 	    sc->sc_dev.dv_xname);
    370       1.27   garbled 
    371       1.27   garbled 	sysctl_createv(NULL, 0, NULL,
    372       1.27   garbled 	    (const struct sysctlnode **)&sysctl_node,
    373       1.27   garbled 	    CTLFLAG_READWRITE | CTLFLAG_OWNDESC | CTLFLAG_IMMEDIATE,
    374       1.27   garbled 	    CTLTYPE_INT, "cpu_speed", "CPU speed", sysctl_cpuspeed_temp,
    375       1.27   garbled 	    (unsigned long)sc, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
    376       1.27   garbled 	if (sysctl_node != NULL) {
    377       1.27   garbled 		sysctl_node->sysctl_data = (void *)sc;
    378       1.27   garbled 	}
    379       1.27   garbled }
    380       1.27   garbled 
    381       1.27   garbled static void
    382       1.27   garbled obio_set_cpu_speed(struct obio_softc *sc, int fast)
    383       1.27   garbled {
    384       1.27   garbled 
    385       1.27   garbled 	if ((sc->sc_voltage < 0) || (sc->sc_busspeed < 0))
    386       1.27   garbled 		return;
    387       1.27   garbled 
    388       1.27   garbled 	if (fast) {
    389       1.27   garbled 		bus_space_write_1(sc->sc_tag, sc->sc_bh, sc->sc_voltage, 5);
    390       1.27   garbled 		bus_space_write_1(sc->sc_tag, sc->sc_bh, sc->sc_busspeed, 5);
    391       1.27   garbled 	} else {
    392       1.27   garbled 		bus_space_write_1(sc->sc_tag, sc->sc_bh, sc->sc_busspeed, 4);
    393       1.27   garbled 		bus_space_write_1(sc->sc_tag, sc->sc_bh, sc->sc_voltage, 4);
    394       1.27   garbled 	}
    395       1.27   garbled }
    396       1.27   garbled 
    397       1.27   garbled static int
    398       1.27   garbled obio_get_cpu_speed(struct obio_softc *sc)
    399       1.27   garbled {
    400       1.27   garbled 
    401       1.27   garbled 	if ((sc->sc_voltage < 0) || (sc->sc_busspeed < 0))
    402       1.27   garbled 		return 0;
    403       1.27   garbled 
    404       1.27   garbled 	if (bus_space_read_1(sc->sc_tag, sc->sc_bh, sc->sc_busspeed) & 1)
    405       1.27   garbled 		return 1;
    406       1.27   garbled 
    407       1.27   garbled 	return 0;
    408       1.27   garbled }
    409       1.27   garbled 
    410       1.27   garbled static int
    411       1.27   garbled sysctl_cpuspeed_temp(SYSCTLFN_ARGS)
    412       1.27   garbled {
    413       1.27   garbled 	struct sysctlnode node = *rnode;
    414       1.27   garbled 	struct obio_softc *sc = node.sysctl_data;
    415       1.27   garbled 	const int *np = newp;
    416       1.27   garbled 	int speed, nd = 0;
    417       1.27   garbled 
    418       1.27   garbled 	speed = obio_get_cpu_speed(sc);
    419       1.27   garbled 	node.sysctl_idata = speed;
    420       1.27   garbled 	if (np) {
    421       1.27   garbled 		/* we're asked to write */
    422       1.27   garbled 		nd = *np;
    423       1.27   garbled 		node.sysctl_data = &speed;
    424       1.27   garbled 		if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
    425       1.27   garbled 			int new_reg;
    426       1.27   garbled 
    427       1.27   garbled 			new_reg = (max(0, min(1, node.sysctl_idata)));
    428       1.27   garbled 			obio_set_cpu_speed(sc, new_reg);
    429       1.27   garbled 			return 0;
    430       1.27   garbled 		}
    431       1.27   garbled 		return EINVAL;
    432       1.27   garbled 	} else {
    433       1.27   garbled 		node.sysctl_size = 4;
    434       1.27   garbled 		return(sysctl_lookup(SYSCTLFN_CALL(&node)));
    435       1.27   garbled 	}
    436       1.27   garbled }
    437       1.27   garbled 
    438       1.27   garbled #endif /* OBIO_SPEEDCONTROL */
    439       1.27   garbled 
    440