diff --git a/sys/conf/files b/sys/conf/files index c9bbe9a8087a..a67a535b3431 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -800,7 +800,7 @@ dev/xe/if_xe.c optional xe dev/xe/if_xe_pccard.c optional xe card dev/xe/if_xe_pccard.c optional xe pccard dev/zs/zs.c optional zs -dev/zs/zs_sbus.c optional zs sbus +dev/zs/zs_sbus.c optional zs fhc sbus fs/deadfs/dead_vnops.c standard fs/devfs/devfs_devs.c standard fs/devfs/devfs_rule.c standard diff --git a/sys/dev/zs/zs_sbus.c b/sys/dev/zs/zs_sbus.c index 01b76f370d8b..a1b266637fb6 100644 --- a/sys/dev/zs/zs_sbus.c +++ b/sys/dev/zs/zs_sbus.c @@ -37,22 +37,32 @@ #include #include + +#include +#include + #include #include #include -#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_sbus_attach(device_t dev); -static int zs_sbus_detach(device_t dev); +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 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) @@ -137,6 +186,33 @@ zs_sbus_probe(device_t dev) return (zs_probe(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) { @@ -181,6 +257,34 @@ zs_sbus_detach(device_t dev) return (0); } +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); }