Author: ganbold Date: Sat Apr 11 08:34:41 2015 New Revision: 281418 URL: https://svnweb.freebsd.org/changeset/base/281418
Log: This modifies several FreeBSD drivers to use the GNU approach to supply clk81 information. It also changes the hardware strings in some of the drivers to match what's present in the GNU files. Submitted by: John Wehle Reviewed by: imp Modified: head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c head/sys/arm/amlogic/aml8726/aml8726_identsoc.c head/sys/arm/amlogic/aml8726/aml8726_machdep.c head/sys/arm/amlogic/aml8726/aml8726_mmc.c head/sys/arm/amlogic/aml8726/aml8726_soc.h head/sys/arm/amlogic/aml8726/uart_dev_aml8726.c Modified: head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c ============================================================================== --- head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c Sat Apr 11 08:34:41 2015 (r281418) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include <dev/ofw/ofw_bus.h> #include <dev/ofw/ofw_bus_subr.h> +#include <arm/amlogic/aml8726/aml8726_soc.h> #include <arm/amlogic/aml8726/aml8726_clkmsr.h> @@ -147,6 +148,30 @@ aml8726_clkmsr_clock_frequency(struct am return value; } +static void +aml8726_clkmsr_fixup_clk81(struct aml8726_clkmsr_softc *sc, int freq) +{ + pcell_t prop; + ssize_t len; + phandle_t clk_node; + phandle_t node; + + node = ofw_bus_get_node(sc->dev); + + len = OF_getencprop(node, "clocks", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop == 0 || + (clk_node = OF_node_from_xref(prop)) == 0) + return; + + len = OF_getencprop(clk_node, "clock-frequency", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop != 0) + return; + + freq = cpu_to_fdt32(freq); + + OF_setprop(clk_node, "clock-frequency", (void *)&freq, sizeof(freq)); +} + static int aml8726_clkmsr_probe(device_t dev) { @@ -178,6 +203,8 @@ aml8726_clkmsr_attach(device_t dev) freq = aml8726_clkmsr_clock_frequency(sc, AML_CLKMSR_CLK81); device_printf(sc->dev, "bus clock %u MHz\n", freq); + aml8726_clkmsr_fixup_clk81(sc, freq * 1000000); + return (0); } @@ -209,8 +236,8 @@ static driver_t aml8726_clkmsr_driver = static devclass_t aml8726_clkmsr_devclass; -DRIVER_MODULE(clkmsr, simplebus, aml8726_clkmsr_driver, - aml8726_clkmsr_devclass, 0, 0); +EARLY_DRIVER_MODULE(clkmsr, simplebus, aml8726_clkmsr_driver, + aml8726_clkmsr_devclass, 0, 0, BUS_PASS_CPU + BUS_PASS_ORDER_EARLY); int aml8726_clkmsr_bus_frequency() @@ -222,6 +249,9 @@ aml8726_clkmsr_bus_frequency() u_long start, size; int freq; + KASSERT(aml8726_soc_hw_rev != AML_SOC_HW_REV_UNKNOWN, + ("aml8726_soc_hw_rev isn't initialized")); + /* * Try to access the clkmsr node directly i.e. through /aliases/. */ Modified: head/sys/arm/amlogic/aml8726/aml8726_identsoc.c ============================================================================== --- head/sys/arm/amlogic/aml8726/aml8726_identsoc.c Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/aml8726_identsoc.c Sat Apr 11 08:34:41 2015 (r281418) @@ -59,8 +59,8 @@ __FBSDID("$FreeBSD$"); #include <arm/amlogic/aml8726/aml8726_soc.h> -uint32_t aml8726_soc_hw_rev = 0xffffffff; -uint32_t aml8726_soc_metal_rev = 0xffffffff; +uint32_t aml8726_soc_hw_rev = AML_SOC_HW_REV_UNKNOWN; +uint32_t aml8726_soc_metal_rev = AML_SOC_METAL_REV_UNKNOWN; static const struct { uint32_t hw_rev; @@ -86,11 +86,10 @@ static const struct { { 0xff, NULL } }; -static void -aml8726_identify_soc(void *dummy) +void +aml8726_identify_soc() { int err; - int i; struct resource res; memset(&res, 0, sizeof(res)); @@ -108,6 +107,12 @@ aml8726_identify_soc(void *dummy) aml8726_soc_metal_rev = bus_read_4(&res, AML_SOC_METAL_REV_REG); bus_space_unmap(res.r_bustag, res.r_bushandle, 0x100000); +} + +static void +aml8726_identify_announce_soc(void *dummy) +{ + int i; for (i = 0; aml8726_soc_desc[i].desc; i++) if (aml8726_soc_desc[i].hw_rev == aml8726_soc_hw_rev) @@ -133,5 +138,5 @@ aml8726_identify_soc(void *dummy) printf("\n"); } -SYSINIT(aml8726_identify_soc, SI_SUB_CPU, SI_ORDER_SECOND, - aml8726_identify_soc, NULL); +SYSINIT(aml8726_identify_announce_soc, SI_SUB_CPU, SI_ORDER_SECOND, + aml8726_identify_announce_soc, NULL); Modified: head/sys/arm/amlogic/aml8726/aml8726_machdep.c ============================================================================== --- head/sys/arm/amlogic/aml8726/aml8726_machdep.c Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/aml8726_machdep.c Sat Apr 11 08:34:41 2015 (r281418) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include <dev/fdt/fdt_common.h> +#include <arm/amlogic/aml8726/aml8726_soc.h> #include <arm/amlogic/aml8726/aml8726_clkmsr.h> #if defined(SOCDEV_PA) && defined(SOCDEV_VA) @@ -55,12 +56,12 @@ vm_offset_t aml8726_aobus_kva_base; static void aml8726_fixup_busfreq() { - phandle_t node, child; + phandle_t node; pcell_t freq, prop; ssize_t len; /* - * Set the bus-frequency for any top level SoC simple-bus which + * Set the bus-frequency for the SoC simple-bus if it * needs updating (meaning the current frequency is zero). */ @@ -74,16 +75,6 @@ aml8726_fixup_busfreq() len = OF_getencprop(node, "bus-frequency", &prop, sizeof(prop)); if ((len / sizeof(prop)) == 1 && prop == 0) OF_setprop(node, "bus-frequency", (void *)&freq, sizeof(freq)); - - for (child = OF_child(node); child != 0; child = OF_peer(child)) { - if (fdt_is_compatible_strict(child, "simple-bus")) { - len = OF_getencprop(child, "bus-frequency", - &prop, sizeof(prop)); - if ((len / sizeof(prop)) == 1 && prop == 0) - OF_setprop(child, "bus-frequency", - (void *)&freq, sizeof(freq)); - } - } } vm_offset_t @@ -116,6 +107,13 @@ platform_gpio_init(void) (vm_offset_t)arm_devmap_ptov(0xc8100000, 0x100000); /* + * The hardware mux used by clkmsr is unique to the SoC (though + * currently clk81 is at a fixed location, however that might + * change in the future). + */ + aml8726_identify_soc(); + + /* * This FDT fixup should arguably be called through fdt_fixup_table, * however currently there's no mechanism to specify a fixup which * should always be invoked. @@ -179,13 +177,13 @@ fdt_pic_decode_ic(phandle_t node, pcell_ * multi core chips also have a GIC. */ #ifdef SMP - if (!fdt_is_compatible_strict(node, "arm,gic")) + if (!fdt_is_compatible_strict(node, "arm,cortex-a9-gic")) #else if (!fdt_is_compatible_strict(node, "amlogic,aml8726-pic")) #endif return (ENXIO); - *interrupt = fdt32_to_cpu(intr[0]); + *interrupt = fdt32_to_cpu(intr[1]); *trig = INTR_TRIGGER_EDGE; *pol = INTR_POLARITY_HIGH; Modified: head/sys/arm/amlogic/aml8726/aml8726_mmc.c ============================================================================== --- head/sys/arm/amlogic/aml8726/aml8726_mmc.c Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/aml8726_mmc.c Sat Apr 11 08:34:41 2015 (r281418) @@ -107,6 +107,25 @@ static struct resource_spec aml8726_mmc_ #define PWR_OFF_FLAG(pol) ((pol) == 0 ? GPIO_PIN_HIGH : \ GPIO_PIN_LOW) +static unsigned int +aml8726_mmc_clk(phandle_t node) +{ + pcell_t prop; + ssize_t len; + phandle_t clk_node; + + len = OF_getencprop(node, "clocks", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop == 0 || + (clk_node = OF_node_from_xref(prop)) == 0) + return (0); + + len = OF_getencprop(clk_node, "clock-frequency", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop == 0) + return (0); + + return ((unsigned int)prop); +} + static void aml8726_mmc_mapmem(void *arg, bus_dma_segment_t *segs, int nseg, int error) { @@ -502,15 +521,13 @@ aml8726_mmc_attach(device_t dev) node = ofw_bus_get_node(dev); - len = OF_getencprop(OF_parent(node), "bus-frequency", - prop, sizeof(prop)); - if ((len / sizeof(prop[0])) != 1 || prop[0] == 0) { - device_printf(dev, "missing bus-frequency attribute in FDT\n"); + sc->ref_freq = aml8726_mmc_clk(node); + + if (sc->ref_freq == 0) { + device_printf(dev, "missing clocks attribute in FDT\n"); return (ENXIO); } - sc->ref_freq = prop[0]; - /* * The pins must be specified as part of the device in order * to know which port to used. Modified: head/sys/arm/amlogic/aml8726/aml8726_soc.h ============================================================================== --- head/sys/arm/amlogic/aml8726/aml8726_soc.h Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/aml8726_soc.h Sat Apr 11 08:34:41 2015 (r281418) @@ -32,8 +32,11 @@ #define AML_SOC_AOBUS_BASE_ADDR 0xc8100000 #define AML_SOC_CBUS_BASE_ADDR 0xc1100000 +void aml8726_identify_soc(void); + /* cbus */ #define AML_SOC_HW_REV_REG 0x7d4c +#define AML_SOC_HW_REV_UNKNOWN 0xffffffff #define AML_SOC_HW_REV_M3 0x15 #define AML_SOC_HW_REV_M6 0x16 #define AML_SOC_HW_REV_M6TV 0x17 @@ -42,6 +45,7 @@ #define AML_SOC_HW_REV_M8B 0x1b #define AML_SOC_METAL_REV_REG 0x81a8 +#define AML_SOC_METAL_REV_UNKNOWN 0xffffffff #define AML_SOC_M8_METAL_REV_A 0x11111111 #define AML_SOC_M8_METAL_REV_M2_A 0x11111112 #define AML_SOC_M8_METAL_REV_B 0x11111113 Modified: head/sys/arm/amlogic/aml8726/uart_dev_aml8726.c ============================================================================== --- head/sys/arm/amlogic/aml8726/uart_dev_aml8726.c Sat Apr 11 08:34:34 2015 (r281417) +++ head/sys/arm/amlogic/aml8726/uart_dev_aml8726.c Sat Apr 11 08:34:41 2015 (r281418) @@ -48,6 +48,10 @@ __FBSDID("$FreeBSD$"); #include <machine/bus.h> #include <machine/cpu.h> +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + #include <dev/uart/uart.h> #include <dev/uart/uart_cpu.h> #include <dev/uart/uart_cpu_fdt.h> @@ -262,6 +266,25 @@ struct uart_ops aml8726_uart_ops = { .getc = aml8726_uart_getc, }; +static unsigned int +aml8726_uart_bus_clk(phandle_t node) +{ + pcell_t prop; + ssize_t len; + phandle_t clk_node; + + len = OF_getencprop(node, "clocks", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop == 0 || + (clk_node = OF_node_from_xref(prop)) == 0) + return (0); + + len = OF_getencprop(clk_node, "clock-frequency", &prop, sizeof(prop)); + if ((len / sizeof(prop)) != 1 || prop == 0) + return (0); + + return ((unsigned int)prop); +} + static int aml8726_uart_bus_probe(struct uart_softc *sc) { @@ -330,8 +353,10 @@ aml8726_uart_bus_attach(struct uart_soft bas = &sc->sc_bas; + bas->rclk = aml8726_uart_bus_clk(ofw_bus_get_node(sc->sc_dev)); + if (bas->rclk == 0) { - device_printf(sc->sc_dev, "missing clock attribute in FDT\n"); + device_printf(sc->sc_dev, "missing clocks attribute in FDT\n"); return (ENXIO); } @@ -703,7 +728,7 @@ struct uart_class uart_aml8726_class = { }; static struct ofw_compat_data compat_data[] = { - { "amlogic,aml8726-uart", (uintptr_t)&uart_aml8726_class }, + { "amlogic,meson-uart", (uintptr_t)&uart_aml8726_class }, { NULL, (uintptr_t)NULL } }; UART_FDT_CLASS_AND_DEVICE(compat_data); _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"