From: jsg Date: Sun, 21 Aug 2016 06:36:23 +0000 (+0000) Subject: Dynamically attach exuart using the FDT. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f93c0438b3b1de76562d1da9d9c77304750ea62e;p=openbsd Dynamically attach exuart using the FDT. --- diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC index cccaaea52e2..c8b3d9c2e49 100644 --- a/sys/arch/armv7/conf/GENERIC +++ b/sys/arch/armv7/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.51 2016/08/20 19:44:02 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.52 2016/08/21 06:36:23 jsg Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -126,7 +126,7 @@ exehci* at exynos? ehci* at exehci? exesdhc* at exynos? sdmmc* at exesdhc? -exuart* at exynos? +exuart* at fdt? # Raspberry Pi 2/3 bcmintc* at fdt? diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK index 54d2c87d2a5..75364d33f95 100644 --- a/sys/arch/armv7/conf/RAMDISK +++ b/sys/arch/armv7/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.47 2016/08/20 19:44:02 kettenis Exp $ +# $OpenBSD: RAMDISK,v 1.48 2016/08/21 06:36:23 jsg Exp $ machine armv7 arm @@ -124,7 +124,7 @@ exehci* at exynos? ehci* at exehci? exesdhc* at exynos? sdmmc* at exesdhc? -exuart* at exynos? +exuart* at fdt? # Raspberry Pi 2/3 bcmintc* at fdt? diff --git a/sys/arch/armv7/exynos/exuart.c b/sys/arch/armv7/exynos/exuart.c index 58d24361765..81453164748 100644 --- a/sys/arch/armv7/exynos/exuart.c +++ b/sys/arch/armv7/exynos/exuart.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exuart.c,v 1.6 2016/07/26 22:10:10 patrick Exp $ */ +/* $OpenBSD: exuart.c,v 1.7 2016/08/21 06:36:23 jsg Exp $ */ /* * Copyright (c) 2005 Dale Rahn * @@ -36,6 +36,7 @@ #endif #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include +#include #define DEVUNIT(x) (minor(x) & 0x7f) #define DEVCUA(x) (minor(x) & 0x80) @@ -89,7 +91,6 @@ struct exuart_softc { int exuartprobe(struct device *parent, void *self, void *aux); -int exuartprobe_fdt(struct device *parent, void *self, void *aux); void exuartattach(struct device *parent, struct device *self, void *aux); void exuartcnprobe(struct consdev *cp); @@ -124,9 +125,6 @@ struct cfdriver exuart_cd = { struct cfattach exuart_ca = { sizeof(struct exuart_softc), exuartprobe, exuartattach }; -struct cfattach exuart_fdt_ca = { - sizeof(struct exuart_softc), exuartprobe_fdt, exuartattach -}; bus_space_tag_t exuartconsiot; bus_space_handle_t exuartconsioh; @@ -138,16 +136,24 @@ void exuart_init_cons(void) { struct fdt_reg reg; - void *node; + void *node, *root; if ((node = fdt_find_cons("samsung,exynos4210-uart")) == NULL) return; - if (fdt_get_reg(node, 0, ®)) - return; /* dtb uses serial2, qemu uses serial0 */ - if (board_id == BOARD_ID_EXYNOS4_SMDKC210) - reg.addr = 0x13800000; + root = fdt_find_node("/"); + if (root == NULL) + panic("%s: could not get fdt root node", __func__); + if (fdt_is_compatible(root, "samsung,universal_c210")) { + if ((node = fdt_find_node("/serial@13800000")) == NULL) { + return; + } + stdout_node = OF_finddevice("/serial@13800000"); + } + + if (fdt_get_reg(node, 0, ®)) + return; exuartcnattach(&armv7_bs_tag, reg.addr, comcnspeed, comcnmode); } @@ -155,68 +161,41 @@ exuart_init_cons(void) int exuartprobe(struct device *parent, void *self, void *aux) { - return 1; -} - -int -exuartprobe_fdt(struct device *parent, void *self, void *aux) -{ -#if NFDT > 0 - struct armv7_attach_args *aa = aux; + struct fdt_attach_args *faa = aux; - if (fdt_node_compatible("samsung,exynos4210-uart", aa->aa_node)) - return 1; -#endif - - return 0; + return OF_is_compatible(faa->fa_node, "samsung,exynos4210-uart"); } struct cdevsw exuartdev = cdev_tty_init(3/*XXX NEXUART */ ,exuart); /* 12: serial port */ void -exuartattach(struct device *parent, struct device *self, void *args) +exuartattach(struct device *parent, struct device *self, void *aux) { - struct armv7_attach_args *aa = args; + struct fdt_attach_args *faa = aux; struct exuart_softc *sc = (struct exuart_softc *) self; - struct armv7mem mem; - int irq; - - sc->sc_iot = aa->aa_iot; -#if NFDT > 0 - if (aa->aa_node) { - struct fdt_reg reg; - uint32_t ints[3]; - - if (fdt_get_reg(aa->aa_node, 0, ®)) - panic("%s: could not extract memory data from FDT", - __func__); - - /* TODO: Add interrupt FDT API. */ - if (fdt_node_property_ints(aa->aa_node, "interrupts", - ints, 3) != 3) - panic("%s: could not extract interrupt data from FDT", - __func__); - - mem.addr = reg.addr; - mem.size = reg.size; - - irq = ints[1]; - } else -#endif - { - irq = aa->aa_dev->irq[0]; - mem.addr = aa->aa_dev->mem[0].addr; - mem.size = aa->aa_dev->mem[0].size; - } + int maj; - sc->sc_irq = arm_intr_establish(irq, IPL_TTY, + if (faa->fa_nreg < 1) + return; + + sc->sc_iot = faa->fa_iot; + + sc->sc_irq = arm_intr_establish_fdt(faa->fa_node, IPL_TTY, exuart_intr, sc, sc->sc_dev.dv_xname); - if (bus_space_map(sc->sc_iot, mem.addr, mem.size, 0, &sc->sc_ioh)) + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size, + 0, &sc->sc_ioh)) panic("%s: bus_space_map failed!", __func__); - if (mem.addr == exuartconsaddr) - printf(" console"); + if (stdout_node == faa->fa_node) { + /* Locate the major number. */ + for (maj = 0; maj < nchrdev; maj++) + if (cdevsw[maj].d_open == exuartopen) + break; + cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit); + + printf(": console"); + } timeout_set(&sc->sc_diag_tmo, exuart_diag, sc); timeout_set(&sc->sc_dtr_tmo, exuart_raisedtr, sc); diff --git a/sys/arch/armv7/exynos/exynos.c b/sys/arch/armv7/exynos/exynos.c index 175888e14cc..bec588a53ae 100644 --- a/sys/arch/armv7/exynos/exynos.c +++ b/sys/arch/armv7/exynos/exynos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exynos.c,v 1.12 2016/06/04 18:09:16 jsg Exp $ */ +/* $OpenBSD: exynos.c,v 1.13 2016/08/21 06:36:23 jsg Exp $ */ /* * Copyright (c) 2005,2008 Dale Rahn * Copyright (c) 2012-2013 Patrick Wildt @@ -43,7 +43,6 @@ struct board_dev chromebook_devs[] = { { "exclock", 0 }, { "expower", 0 }, { "exsysreg", 0 }, -// { "exuart", 1 }, { "exgpio", 0 }, { "exgpio", 1 }, { "exgpio", 2 }, @@ -65,10 +64,6 @@ struct board_dev nuri_devs[] = { // { "exclock", 0 }, { "expower", 0 }, { "exsysreg", 0 }, -// { "exuart", 0 }, - { "exuart", 1 }, - { "exuart", 2 }, - { "exuart", 3 }, { "exgpio", 0 }, { "exgpio", 1 }, { "exgpio", 2 }, @@ -91,10 +86,6 @@ struct board_dev smdkc210_devs[] = { // { "exclock", 0 }, { "expower", 0 }, { "exsysreg", 0 }, -// { "exuart", 0 }, - { "exuart", 1 }, - { "exuart", 2 }, - { "exuart", 3 }, { "exgpio", 0 }, { "exgpio", 1 }, { "exgpio", 2 }, diff --git a/sys/arch/armv7/exynos/files.exynos b/sys/arch/armv7/exynos/files.exynos index ca121ce8b7c..d9a6832e9ff 100644 --- a/sys/arch/armv7/exynos/files.exynos +++ b/sys/arch/armv7/exynos/files.exynos @@ -1,4 +1,4 @@ -# $OpenBSD: files.exynos,v 1.4 2016/05/02 08:15:55 patrick Exp $ +# $OpenBSD: files.exynos,v 1.5 2016/08/21 06:36:23 jsg Exp $ define exynos {} device exynos: exynos @@ -10,7 +10,7 @@ file arch/armv7/exynos/exynos5.c exynos # serial ports device exuart -attach exuart at exynos +attach exuart at fdt file arch/armv7/exynos/exuart.c exuart device exdisplay: wsemuldisplaydev, rasops16