From 2d7feac778a76a888deee8d22fb355b45968090b Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 20 Aug 2016 10:41:54 +0000 Subject: [PATCH] Figuring out the clock frequency used for a com(4) device on armv7 is hard. Avoid doing so for the early console and instead rely on the firmware to set up the right baud rate and such. ok visa@, millert@, jsg@ --- sys/arch/armv7/dev/com_fdt.c | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/sys/arch/armv7/dev/com_fdt.c b/sys/arch/armv7/dev/com_fdt.c index ab7ac2a6fc9..3dbb46dbb06 100644 --- a/sys/arch/armv7/dev/com_fdt.c +++ b/sys/arch/armv7/dev/com_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com_fdt.c,v 1.6 2016/08/17 13:44:48 patrick Exp $ */ +/* $OpenBSD: com_fdt.c,v 1.7 2016/08/20 10:41:54 kettenis Exp $ */ /* * Copyright (c) 2016 Patrick Wildt * @@ -26,6 +26,7 @@ #include #include +#include /* pick up armv7_a4x_bs_tag */ #include @@ -55,12 +56,20 @@ struct cfattach com_fdt_ca = { sizeof (struct com_fdt_softc), com_fdt_match, com_fdt_attach }; +int com_fdt_cngetc(dev_t); +void com_fdt_cnputc(dev_t, int); +void com_fdt_cnpollc(dev_t, int); + +struct consdev com_fdt_cons = { + NULL, NULL, com_fdt_cngetc, com_fdt_cnputc, com_fdt_cnpollc, NULL, + NODEV, CN_LOWPRI +}; + void com_fdt_init_cons(void) { struct fdt_reg reg; void *node; - int freq = 48000000; if ((node = fdt_find_cons("ti,omap3-uart")) == NULL && (node = fdt_find_cons("ti,omap4-uart")) == NULL && @@ -69,16 +78,21 @@ com_fdt_init_cons(void) if (fdt_get_reg(node, 0, ®)) return; - if ((node = fdt_find_node("/")) != NULL && - (fdt_is_compatible(node, "allwinner,sun4i-a10") || - fdt_is_compatible(node, "allwinner,sun5i-a10s") || - fdt_is_compatible(node, "allwinner,sun5i-r8") || - fdt_is_compatible(node, "allwinner,sun7i-a20"))) - freq = 24000000; + /* + * Figuring out the clock frequency is rather complicated as + * om many SoCs this requires traversing a fair amount of the + * clock tree. Instead we rely on the firmware to set up the + * console for us and bypass the cominit() call that + * comcnattach() does by doing the minimal setup here. + */ + + comconsiot = &armv7_a4x_bs_tag; + if (bus_space_map(comconsiot, reg.addr, reg.size, 0, &comconsioh)) + return; - comcnattach(&armv7_a4x_bs_tag, reg.addr, comcnspeed, freq, - comcnmode); - comdefaultrate = comcnspeed; + comconsrate = comcnspeed; + comconscflag = comcnmode; + cn_tab = &com_fdt_cons; } int @@ -130,6 +144,7 @@ com_fdt_attach(struct device *parent, struct device *self, void *aux) if (stdout_node == faa->fa_node) { SET(sc->sc.sc_hwflags, COM_HW_CONSOLE); SET(sc->sc.sc_swflags, COM_SW_SOFTCAR); + comconsfreq = sc->sc.sc_frequency; } if (bus_space_map(sc->sc.sc_iot, sc->sc.sc_iobase, @@ -155,3 +170,20 @@ com_fdt_intr_designware(void *cookie) return comintr(sc); } + +int +com_fdt_cngetc(dev_t dev) +{ + return com_common_getc(comconsiot, comconsioh); +} + +void +com_fdt_cnputc(dev_t dev, int c) +{ + com_common_putc(comconsiot, comconsioh, c); +} + +void +com_fdt_cnpollc(dev_t dev, int on) +{ +} -- 2.20.1