From dfb7098a47e1dce7adfc1862a2a464f6fdbb4ecd Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 22 Aug 2016 09:37:27 +0000 Subject: [PATCH] Use the new clock API to get the clock frequency from the device tree and the actual hardware that controls the clock. This gets rid of all the hardcoded clock frequencies for specific hardware. Tested by jsg@ on the BBB, mglocker@ on the C.H.I.P. and myself on the Banana Pi and Raspberry Pi 3. ok jsg@ --- sys/arch/armv7/dev/com_fdt.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/sys/arch/armv7/dev/com_fdt.c b/sys/arch/armv7/dev/com_fdt.c index 2058c226a9b..30b0e8683cf 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.8 2016/08/20 15:44:04 kettenis Exp $ */ +/* $OpenBSD: com_fdt.c,v 1.9 2016/08/22 09:37:27 kettenis Exp $ */ /* * Copyright (c) 2016 Patrick Wildt * @@ -36,6 +36,7 @@ #include #include +#include #include #define com_usr 31 /* Synopsys DesignWare UART */ @@ -113,11 +114,22 @@ com_fdt_attach(struct device *parent, struct device *self, void *aux) struct com_fdt_softc *sc = (struct com_fdt_softc *)self; struct fdt_attach_args *faa = aux; int (*intr)(void *) = comintr; - int node; + uint32_t freq; if (faa->fa_nreg < 1) return; + clock_enable(faa->fa_node, NULL); + + /* + * Determine the clock frequency after enabling the clock. + * This gives the clock code a chance to configure the + * appropriate frequency for us. + */ + freq = OF_getpropint(faa->fa_node, "clock-frequency", 0); + if (freq == 0) + freq = clock_get_frequency(faa->fa_node, NULL); + /* * XXX This sucks. We need to get rid of the a4x bus tag * altogether. For this we will need to change com(4). @@ -129,26 +141,14 @@ com_fdt_attach(struct device *parent, struct device *self, void *aux) sc->sc.sc_iot = &sc->sc_iot; sc->sc.sc_iobase = faa->fa_reg[0].addr; sc->sc.sc_uarttype = COM_UART_16550; - sc->sc.sc_frequency = COM_FREQ; + sc->sc.sc_frequency = freq ? freq : COM_FREQ; if (OF_is_compatible(faa->fa_node, "snps,dw-apb-uart")) intr = com_fdt_intr_designware; - if (OF_is_compatible(faa->fa_node, "brcm,bcm2835-aux-uart")) - sc->sc.sc_frequency = 500000000; - if (OF_is_compatible(faa->fa_node, "ti,omap3-uart") || - OF_is_compatible(faa->fa_node, "ti,omap4-uart")) { + OF_is_compatible(faa->fa_node, "ti,omap4-uart")) sc->sc.sc_uarttype = COM_UART_TI16750; - sc->sc.sc_frequency = 48000000; - } - - if ((node = OF_finddevice("/")) != 0 && - (OF_is_compatible(node, "allwinner,sun4i-a10") || - OF_is_compatible(node, "allwinner,sun5i-a10s") || - OF_is_compatible(node, "allwinner,sun5i-r8") || - OF_is_compatible(node, "allwinner,sun7i-a20"))) - sc->sc.sc_frequency = 24000000; if (stdout_node == faa->fa_node) { SET(sc->sc.sc_hwflags, COM_HW_CONSOLE); -- 2.20.1