summaryrefslogtreecommitdiffstats
path: root/sys/dev/zs
diff options
context:
space:
mode:
authorjake <jake@FreeBSD.org>2003-02-19 08:29:17 +0000
committerjake <jake@FreeBSD.org>2003-02-19 08:29:17 +0000
commit4755bfb6cec23073d70386b9d148349d36c48e89 (patch)
treed09cb01574c5bf5b8e7867c3bd4d7b03ab6533ed /sys/dev/zs
parent677f252b3cd2b8923d91bf6702179cefe3c41f72 (diff)
downloadFreeBSD-src-4755bfb6cec23073d70386b9d148349d36c48e89.zip
FreeBSD-src-4755bfb6cec23073d70386b9d148349d36c48e89.tar.gz
Munge the zs sbus attachment to work with fhc. This is a bit of a hack,
but they would otherwise be almost identical so there's not much point in splitting it up further.
Diffstat (limited to 'sys/dev/zs')
-rw-r--r--sys/dev/zs/zs_sbus.c126
1 files changed, 113 insertions, 13 deletions
diff --git a/sys/dev/zs/zs_sbus.c b/sys/dev/zs/zs_sbus.c
index 01b76f3..a1b2666 100644
--- a/sys/dev/zs/zs_sbus.c
+++ b/sys/dev/zs/zs_sbus.c
@@ -37,22 +37,32 @@
#include <sys/rman.h>
#include <ofw/openfirm.h>
+
+#include <sparc64/fhc/fhcreg.h>
+#include <sparc64/fhc/fhcvar.h>
+
#include <sparc64/sbus/sbusvar.h>
#include <dev/zs/z8530reg.h>
#include <dev/zs/z8530var.h>
-#define ZS_SBUS_CHAN_A 4
-#define ZS_SBUS_CHAN_B 0
+#define ZS_SBUS_CHAN_A 4
+#define ZS_SBUS_CHAN_B 0
-#define ZS_SBUS_CSR 0
-#define ZS_SBUS_DATA 2
+#define ZS_SBUS_CSR 0
+#define ZS_SBUS_DATA 2
#define ZS_SBUS_CLOCK (9600 * 512)
#define ZS_SBUS_CLOCK_DIV (16)
#define ZS_SBUS_DEF_SPEED (9600)
+enum zs_device_ivars {
+ ZS_IVAR_NODE
+};
+
+__BUS_ACCESSOR(zs, node, ZS, NODE, phandle_t)
+
struct zs_sbus_softc {
struct zs_softc sc_zs;
struct resource *sc_irqres;
@@ -62,21 +72,41 @@ struct zs_sbus_softc {
int sc_memrid;
};
+static int zs_fhc_probe(device_t dev);
+static int zs_fhc_attach(device_t dev);
+static int zs_fhc_read_ivar(device_t dev, device_t child, int which,
+ uintptr_t *result);
+
+static int zs_sbus_probe(device_t dev);
static int zs_sbus_attach(device_t dev);
+static int zs_sbus_read_ivar(device_t dev, device_t child, int which,
+ uintptr_t *result);
+
static int zs_sbus_detach(device_t dev);
-static int zs_sbus_probe(device_t dev);
static int zstty_sbus_attach(device_t dev);
static int zstty_sbus_probe(device_t dev);
static int zstty_keyboard(device_t dev);
+static device_method_t zs_fhc_methods[] = {
+ DEVMETHOD(device_probe, zs_fhc_probe),
+ DEVMETHOD(device_attach, zs_fhc_attach),
+ DEVMETHOD(device_detach, zs_sbus_detach),
+
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_read_ivar, zs_fhc_read_ivar),
+
+ { 0, 0 }
+};
+
static device_method_t zs_sbus_methods[] = {
DEVMETHOD(device_probe, zs_sbus_probe),
DEVMETHOD(device_attach, zs_sbus_attach),
DEVMETHOD(device_detach, zs_sbus_detach),
DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_read_ivar, zs_sbus_read_ivar),
{ 0, 0 }
};
@@ -89,6 +119,12 @@ static device_method_t zstty_sbus_methods[] = {
{ 0, 0 }
};
+static driver_t zs_fhc_driver = {
+ "zs",
+ zs_fhc_methods,
+ sizeof(struct zs_sbus_softc),
+};
+
static driver_t zs_sbus_driver = {
"zs",
zs_sbus_methods,
@@ -101,11 +137,15 @@ static driver_t zstty_sbus_driver = {
sizeof(struct zstty_softc),
};
+static devclass_t zs_fhc_devclass;
static devclass_t zs_sbus_devclass;
+
+DRIVER_MODULE(zs, fhc, zs_fhc_driver, zs_fhc_devclass, 0, 0);
+DRIVER_MODULE(zs, sbus, zs_sbus_driver, zs_sbus_devclass, 0, 0);
+
static devclass_t zstty_sbus_devclass;
DRIVER_MODULE(zstty, zs, zstty_sbus_driver, zstty_sbus_devclass, 0, 0);
-DRIVER_MODULE(zs, sbus, zs_sbus_driver, zs_sbus_devclass, 0, 0);
static uint8_t zs_sbus_init_reg[16] = {
0, /* 0: CMD (reset, etc.) */
@@ -126,6 +166,15 @@ static uint8_t zs_sbus_init_reg[16] = {
ZSWR15_BREAK_IE,
};
+static int
+zs_fhc_probe(device_t dev)
+{
+
+ if (strcmp(fhc_get_name(dev), "zs") != 0 ||
+ device_get_unit(dev) != 0)
+ return (ENXIO);
+ return (zs_probe(dev));
+}
static int
zs_sbus_probe(device_t dev)
@@ -138,6 +187,33 @@ zs_sbus_probe(device_t dev)
}
static int
+zs_fhc_attach(device_t dev)
+{
+ struct zs_sbus_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->sc_memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->sc_memrid,
+ 0, ~0, 1, RF_ACTIVE);
+ if (sc->sc_memres == NULL)
+ goto error;
+ sc->sc_irqrid = FHC_UART;
+ sc->sc_irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irqrid, 0,
+ ~0, 1, RF_ACTIVE);
+ if (sc->sc_irqres == NULL)
+ goto error;
+ if (bus_setup_intr(dev, sc->sc_irqres, INTR_TYPE_TTY | INTR_FAST,
+ zs_intr, sc, &sc->sc_ih) != 0)
+ goto error;
+ sc->sc_zs.sc_bt = rman_get_bustag(sc->sc_memres);
+ sc->sc_zs.sc_bh = rman_get_bushandle(sc->sc_memres);
+ return (zs_attach(dev));
+
+error:
+ zs_sbus_detach(dev);
+ return (ENXIO);
+}
+
+static int
zs_sbus_attach(device_t dev)
{
struct zs_sbus_softc *sc;
@@ -182,6 +258,34 @@ zs_sbus_detach(device_t dev)
}
static int
+zs_fhc_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
+{
+
+ switch (which) {
+ case ZS_IVAR_NODE:
+ *result = fhc_get_node(dev);
+ break;
+ default:
+ return (ENOENT);
+ }
+ return (0);
+}
+
+static int
+zs_sbus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
+{
+
+ switch (which) {
+ case ZS_IVAR_NODE:
+ *result = sbus_get_node(dev);
+ break;
+ default:
+ return (ENOENT);
+ }
+ return (0);
+}
+
+static int
zstty_sbus_probe(device_t dev)
{
@@ -241,7 +345,6 @@ zstty_set_speed(struct zstty_softc *sc, int ospeed)
int
zstty_console(device_t dev, char *mode, int len)
{
- device_t parent;
phandle_t chosen;
phandle_t options;
ihandle_t stdin;
@@ -250,7 +353,6 @@ zstty_console(device_t dev, char *mode, int len)
char input[32];
char name[32];
- parent = device_get_parent(dev);
chosen = OF_finddevice("/chosen");
options = OF_finddevice("/options");
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1 ||
@@ -258,8 +360,8 @@ zstty_console(device_t dev, char *mode, int len)
OF_getprop(options, "input-device", input, sizeof(input)) == -1 ||
OF_getprop(options, "output-device", output, sizeof(output)) == -1)
return (0);
- if (sbus_get_node(parent) != OF_instance_to_package(stdin) ||
- sbus_get_node(parent) != OF_instance_to_package(stdout))
+ if (zs_get_node(dev) != OF_instance_to_package(stdin) ||
+ zs_get_node(dev) != OF_instance_to_package(stdout))
return (0);
if ((strcmp(input, device_get_desc(dev)) == 0 &&
strcmp(output, device_get_desc(dev)) == 0) ||
@@ -277,8 +379,6 @@ zstty_console(device_t dev, char *mode, int len)
static int
zstty_keyboard(device_t dev)
{
- device_t parent;
- parent = device_get_parent(dev);
- return (OF_getproplen(sbus_get_node(parent), "keyboard") == 0);
+ return (OF_getproplen(zs_get_node(dev), "keyboard") == 0);
}
OpenPOWER on IntegriCloud