summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authoryongari <yongari@FreeBSD.org>2004-10-09 07:31:03 +0000
committeryongari <yongari@FreeBSD.org>2004-10-09 07:31:03 +0000
commit0323c1151ec4b49b6bef5cfebd2829b7fa1242c5 (patch)
treed9e1ed67aa6fb6403cfbc6d5edc540acf61b8129 /sys
parent1ec2d0e4b01c36af63790dafaea4bcc5927e3c1e (diff)
downloadFreeBSD-src-0323c1151ec4b49b6bef5cfebd2829b7fa1242c5.zip
FreeBSD-src-0323c1151ec4b49b6bef5cfebd2829b7fa1242c5.tar.gz
Port NetBSD auxio driver. The driver was modified to use led(4) and can
be used to announce various system activity. The auxio device provides auxiliary I/O functions and is found on various SBus/EBus UltraSPARC models. At present, only front panel LED is controlled by this driver. Approved by: jake (mentor) Reviewed by: joerg Tested by: joerg
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files.sparc642
-rw-r--r--sys/dev/auxio/auxio.c335
-rw-r--r--sys/dev/auxio/auxioreg.h73
-rw-r--r--sys/modules/Makefile2
-rw-r--r--sys/modules/auxio/Makefile10
-rw-r--r--sys/sparc64/conf/GENERIC1
-rw-r--r--sys/sparc64/conf/NOTES1
7 files changed, 424 insertions, 0 deletions
diff --git a/sys/conf/files.sparc64 b/sys/conf/files.sparc64
index 562d6d3..64572e3 100644
--- a/sys/conf/files.sparc64
+++ b/sys/conf/files.sparc64
@@ -12,6 +12,8 @@ crypto/blowfish/bf_enc.c optional ipsec ipsec_esp
crypto/des/des_enc.c optional ipsec ipsec_esp
crypto/blowfish/bf_enc.c optional crypto
crypto/des/des_enc.c optional crypto
+dev/auxio/auxio.c optional auxio sbus
+dev/auxio/auxio.c optional auxio ebus
dev/esp/esp_sbus.c optional esp sbus
dev/esp/lsi64854.c optional esp sbus
dev/fb/creator.c optional creator sc
diff --git a/sys/dev/auxio/auxio.c b/sys/dev/auxio/auxio.c
new file mode 100644
index 0000000..74d6880
--- /dev/null
+++ b/sys/dev/auxio/auxio.c
@@ -0,0 +1,335 @@
+/*-
+ * Copyright (c) 2004 Pyun YongHyeon
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* $NetBSD: auxio.c,v 1.11 2003/07/15 03:36:04 lukem Exp $ */
+
+/*
+ * Copyright (c) 2000, 2001 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * AUXIO registers support on the sbus & ebus2, used for the floppy driver
+ * and to control the system LED, for the BLINK option.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/resource.h>
+#include <sys/rman.h>
+
+#include <dev/led/led.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/openfirm.h>
+
+#include <machine/bus.h>
+#include <machine/ofw_machdep.h>
+#include <machine/resource.h>
+
+#include <sparc64/sbus/sbusvar.h>
+#include <dev/auxio/auxioreg.h>
+
+/*
+ * on sun4u, auxio exists with one register (LED) on the sbus, and 5
+ * registers on the ebus2 (pci) (LED, PCIMODE, FREQUENCY, SCSI
+ * OSCILLATOR, and TEMP SENSE.
+ */
+
+#define AUXIO_PCIO_LED 0
+#define AUXIO_PCIO_PCI 1
+#define AUXIO_PCIO_FREQ 2
+#define AUXIO_PCIO_OSC 3
+#define AUXIO_PCIO_TEMP 4
+#define AUXIO_PCIO_MAX 8
+
+struct auxio_softc {
+ struct device *sc_dev;
+
+ int sc_nauxio;
+ struct resource *sc_res[AUXIO_PCIO_MAX];
+ int sc_rid[AUXIO_PCIO_MAX];
+ bus_space_tag_t sc_regt[AUXIO_PCIO_MAX];
+ bus_space_handle_t sc_regh[AUXIO_PCIO_MAX];
+ struct cdev *sc_led_dev;
+ u_int32_t sc_led_stat;
+
+ int sc_flags;
+#define AUXIO_LEDONLY 0x1
+#define AUXIO_EBUS 0x2
+#define AUXIO_SBUS 0x4
+
+ struct mtx sc_lock;
+};
+
+static void auxio_led_func(void *arg, int onoff);
+static void auxio_attach_common(struct auxio_softc *);
+static int auxio_bus_probe(device_t);
+static int auxio_sbus_attach(device_t);
+static int auxio_ebus_attach(device_t);
+static int auxio_bus_detach(device_t);
+static void auxio_free_resource(struct auxio_softc *);
+static __inline u_int32_t auxio_led_read(struct auxio_softc *);
+static __inline void auxio_led_write(struct auxio_softc *, u_int32_t);
+
+/* SBus */
+static device_method_t auxio_sbus_methods[] = {
+ DEVMETHOD(device_probe, auxio_bus_probe),
+ DEVMETHOD(device_attach, auxio_sbus_attach),
+ DEVMETHOD(device_detach, auxio_bus_detach),
+ {0, 0}
+};
+
+static driver_t auxio_sbus_driver = {
+ "auxio",
+ auxio_sbus_methods,
+ sizeof(struct auxio_softc)
+};
+
+static devclass_t auxio_devclass;
+DRIVER_MODULE(auxio, sbus, auxio_sbus_driver, auxio_devclass, 0, 0);
+
+/* EBus */
+static device_method_t auxio_ebus_methods[] = {
+ DEVMETHOD(device_probe, auxio_bus_probe),
+ DEVMETHOD(device_attach, auxio_ebus_attach),
+ DEVMETHOD(device_detach, auxio_bus_detach),
+ {0, 0}
+};
+
+static driver_t auxio_ebus_driver = {
+ "auxio",
+ auxio_ebus_methods,
+ sizeof(struct auxio_softc)
+};
+
+DRIVER_MODULE(auxio, ebus, auxio_ebus_driver, auxio_devclass, 0, 0);
+MODULE_VERSION(auxio, 1);
+
+#define AUXIO_LOCK_INIT(sc) \
+ mtx_init(&sc->sc_lock, "auxio mtx", NULL, MTX_DEF)
+#define AUXIO_LOCK(sc) mtx_lock(&sc->sc_lock)
+#define AUXIO_UNLOCK(sc) mtx_unlock(&sc->sc_lock)
+#define AUXIO_LOCK_DESTROY(sc) mtx_destroy(&sc->sc_lock)
+
+static __inline void
+auxio_led_write(struct auxio_softc *sc, u_int32_t v)
+{
+ if (sc->sc_flags & AUXIO_EBUS)
+ bus_space_write_4(sc->sc_regt[AUXIO_PCIO_LED],
+ sc->sc_regh[AUXIO_PCIO_LED], 0, v);
+ else
+ bus_space_write_1(sc->sc_regt[AUXIO_PCIO_LED],
+ sc->sc_regh[AUXIO_PCIO_LED], 0, v);
+}
+
+static __inline u_int32_t
+auxio_led_read(struct auxio_softc *sc)
+{
+ u_int32_t led;
+
+ if (sc->sc_flags & AUXIO_EBUS)
+ led = bus_space_read_4(sc->sc_regt[AUXIO_PCIO_LED],
+ sc->sc_regh[AUXIO_PCIO_LED], 0);
+ else
+ led = bus_space_read_1(sc->sc_regt[AUXIO_PCIO_LED],
+ sc->sc_regh[AUXIO_PCIO_LED], 0);
+
+ return (led);
+}
+
+static void
+auxio_led_func(void *arg, int onoff)
+{
+ struct auxio_softc *sc;
+ u_int32_t led;
+
+ sc = (struct auxio_softc *)arg;
+
+ led = onoff ? AUXIO_LED_LED : 0;
+ AUXIO_LOCK(sc);
+ auxio_led_write(sc, led);
+ AUXIO_UNLOCK(sc);
+}
+
+static int
+auxio_bus_probe(device_t dev)
+{
+ const char *name;
+
+ name = ofw_bus_get_name(dev);
+ if (strcmp("auxio", name) == 0) {
+ device_set_desc(dev, "Sun Auxiliary I/O");
+ return (0);
+ }
+
+ return (ENXIO);
+}
+
+static int
+auxio_ebus_attach(device_t dev)
+{
+ struct auxio_softc *sc;
+ struct resource *res;
+ u_long start, count;
+ int i;
+
+ sc = device_get_softc(dev);
+ bzero(sc, sizeof(*sc));
+ sc->sc_dev = dev;
+
+ AUXIO_LOCK_INIT(sc);
+ sc->sc_nauxio = AUXIO_PCIO_MAX;
+ sc->sc_flags = AUXIO_LEDONLY | AUXIO_EBUS;
+ for (i = 0;
+ i < AUXIO_PCIO_MAX &&
+ bus_get_resource(dev, SYS_RES_IOPORT, i, &start, &count) == 0;
+ i++) {
+ sc->sc_rid[i] = i;
+ if (bootverbose)
+ device_printf(sc->sc_dev,
+ "Got rid %d, start %#lx, count %#lx\n",
+ i, start, count);
+ res = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
+ &sc->sc_rid[i], RF_ACTIVE);
+ if (res == NULL) {
+ device_printf(sc->sc_dev,
+ "could not allocate resources\n");
+ goto attach_fail;
+ }
+ sc->sc_res[i] = res;
+ sc->sc_regt[i] = rman_get_bustag(res);
+ sc->sc_regh[i] = rman_get_bushandle(res);
+ }
+ sc->sc_nauxio = i;
+ auxio_attach_common(sc);
+
+ return (0);
+
+attach_fail:
+ auxio_free_resource(sc);
+
+ return (ENXIO);
+}
+
+static void
+auxio_attach_common(struct auxio_softc *sc)
+{
+ sc->sc_led_stat = auxio_led_read(sc);
+ sc->sc_led_dev = led_create(auxio_led_func, sc, "auxioled");
+ /* turn on the LED */
+ auxio_led_func(sc, 1);
+}
+
+static int
+auxio_bus_detach(device_t dev)
+{
+ struct auxio_softc *sc;
+
+ sc = device_get_softc(dev);
+ led_destroy(sc->sc_led_dev);
+ auxio_led_func(sc, sc->sc_led_stat);
+ auxio_free_resource(sc);
+
+ return (0);
+}
+
+static void
+auxio_free_resource(struct auxio_softc *sc)
+{
+ int i, n;
+
+ n = sc->sc_nauxio;
+ for (i = 0; i < n; i++)
+ if (sc->sc_res[i])
+ bus_release_resource(sc->sc_dev,
+ (sc->sc_flags & AUXIO_SBUS) ? SYS_RES_MEMORY :
+ SYS_RES_IOPORT, sc->sc_rid[i], sc->sc_res[i]);
+ AUXIO_LOCK_DESTROY(sc);
+}
+
+static int
+auxio_sbus_attach(device_t dev)
+{
+ struct auxio_softc *sc;
+ struct resource *res;
+
+ sc = device_get_softc(dev);
+ bzero(sc, sizeof(*sc));
+ sc->sc_dev = dev;
+
+ AUXIO_LOCK_INIT(sc);
+ sc->sc_nauxio = 1;
+ sc->sc_flags = AUXIO_LEDONLY | AUXIO_SBUS;
+ sc->sc_rid[AUXIO_PCIO_LED] = 0;
+ res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
+ &sc->sc_rid[AUXIO_PCIO_LED], RF_ACTIVE);
+ if (res == NULL) {
+ device_printf(sc->sc_dev, "could not allocate resources\n");
+ goto attach_fail;
+ }
+ sc->sc_res[AUXIO_PCIO_LED] = res;
+ sc->sc_regt[AUXIO_PCIO_LED] = rman_get_bustag(res);
+ sc->sc_regh[AUXIO_PCIO_LED] = rman_get_bushandle(res);
+ auxio_attach_common(sc);
+ return (0);
+
+attach_fail:
+ auxio_free_resource(sc);
+
+ return (ENXIO);
+}
diff --git a/sys/dev/auxio/auxioreg.h b/sys/dev/auxio/auxioreg.h
new file mode 100644
index 0000000..439bf34
--- /dev/null
+++ b/sys/dev/auxio/auxioreg.h
@@ -0,0 +1,73 @@
+/* $FreeBSD$ */
+/* $NetBSD: auxioreg.h,v 1.4 2001/10/22 07:31:41 mrg Exp $ */
+
+/*
+ * Copyright (c) 2000 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * The AUXIO registers; their offset in the Ebus2 address space, plus the
+ * bits for each register. Note that the fdthree (FD), SUNW,CS4231 (AUDIO)
+ * and power (POWER) devices on the Ebus2 have their AUXIO regsiters mapped
+ * into their own "reg" properties, not the "auxio" device's "reg" properties.
+ */
+#define AUXIO_FD 0x00720000
+#define AUXIO_FD_DENSENSE_INPUT 0x0
+#define AUXIO_FD_DENSENSE_OUTPUT 0x1
+
+#define AUXIO_AUDIO 0x00722000
+#define AUXIO_AUDIO_POWERDOWN 0x0
+
+#define AUXIO_POWER 0x00724000
+#define AUXIO_POWER_SYSTEM_OFF 0x0
+#define AUXIO_POWER_COURTESY_OFF 0x1
+
+#define AUXIO_LED 0x00726000
+#define AUXIO_LED_LED 1
+
+#define AUXIO_PCI 0x00728000
+#define AUXIO_PCI_SLOT0 0x0 /* two bits each */
+#define AUXIO_PCI_SLOT1 0x2
+#define AUXIO_PCI_SLOT2 0x4
+#define AUXIO_PCI_SLOT3 0x6
+#define AUXIO_PCI_MODE 0x8
+
+#define AUXIO_FREQ 0x0072a000
+#define AUXIO_FREQ_FREQ0 0x0
+#define AUXIO_FREQ_FREQ1 0x1
+#define AUXIO_FREQ_FREQ2 0x2
+
+#define AUXIO_SCSI 0x0072c000
+#define AUXIO_SCSI_INT_OSC_EN 0x0
+#define AUXIO_SCSI_EXT_OSC_EN 0x1
+
+#define AUXIO_TEMP 0x0072f000
+#define AUXIO_TEMP_SELECT 0x0
+#define AUXIO_TEMP_CLOCK 0x1
+#define AUXIO_TEMP_ENABLE 0x2
+#define AUXIO_TEMP_DATAOUT 0x3
+#define AUXIO_TEMP_DATAINT 0x4
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index 1c2478d..a3cceea 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -28,6 +28,7 @@ SUBDIR= ${_3dfx} \
${_ath_hal} \
aue \
autofs \
+ ${_auxio} \
${_awi} \
axe \
bfe \
@@ -438,6 +439,7 @@ _gem= gem
.endif
.if ${MACHINE_ARCH} == "sparc64"
+_auxio= auxio
_gem= gem
.endif
diff --git a/sys/modules/auxio/Makefile b/sys/modules/auxio/Makefile
new file mode 100644
index 0000000..06c3028
--- /dev/null
+++ b/sys/modules/auxio/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../../dev/auxio
+
+KMOD= auxio
+
+SRCS= auxio.c
+SRCS+= device_if.h bus_if.h
+
+.include <bsd.kmod.mk>
diff --git a/sys/sparc64/conf/GENERIC b/sys/sparc64/conf/GENERIC
index b325783..f24a998 100644
--- a/sys/sparc64/conf/GENERIC
+++ b/sys/sparc64/conf/GENERIC
@@ -124,6 +124,7 @@ device ses # SCSI Environmental Services (and SAF-TE)
device ofw_console # Open Firmware console device
# Builtin hardware
+device auxio # auxiliary I/O device
device genclock # Generic clock interface
device eeprom # eeprom (really a front-end for the MK48Txx)
device "mk48txx" # Mostek MK48T02, MK48T08, MK48T59 clock
diff --git a/sys/sparc64/conf/NOTES b/sys/sparc64/conf/NOTES
index 311b80f..7fd6e274 100644
--- a/sys/sparc64/conf/NOTES
+++ b/sys/sparc64/conf/NOTES
@@ -47,6 +47,7 @@ device "mk48txx" # Mostek MK48T02, MK48T08, MK48T59 clock
# Optional devices:
#
+device auxio # auxiliary I/O device
device creator # Creator, Creator3D and Elite3D graphics cards
device ofw_console # Open Firmware console device
OpenPOWER on IntegriCloud