-/* $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 <drahn@motorola.com>
*
#endif
#include <machine/bus.h>
+#include <machine/fdt.h>
#include <arm/armv7/armv7var.h>
#include <armv7/exynos/exuartreg.h>
#include <armv7/exynos/exuartvar.h>
#include <armv7/exynos/exclockvar.h>
#include <dev/ofw/fdt.h>
+#include <dev/ofw/openfirm.h>
#define DEVUNIT(x) (minor(x) & 0x7f)
#define DEVCUA(x) (minor(x) & 0x80)
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);
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;
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);
}
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);