Module Name:    src
Committed By:   jmcneill
Date:           Tue Jan 22 15:17:33 UTC 2019

Modified Files:
        src/sys/arch/arm/fdt: a9tmr_fdt.c

Log Message:
Listen for PMFE_SPEED_CHANGED events and automatically update a9tmr frequency


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/fdt/a9tmr_fdt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/fdt/a9tmr_fdt.c
diff -u src/sys/arch/arm/fdt/a9tmr_fdt.c:1.2 src/sys/arch/arm/fdt/a9tmr_fdt.c:1.3
--- src/sys/arch/arm/fdt/a9tmr_fdt.c:1.2	Sat Jan 19 20:56:03 2019
+++ src/sys/arch/arm/fdt/a9tmr_fdt.c	Tue Jan 22 15:17:33 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: a9tmr_fdt.c,v 1.2 2019/01/19 20:56:03 jmcneill Exp $ */
+/* $NetBSD: a9tmr_fdt.c,v 1.3 2019/01/22 15:17:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: a9tmr_fdt.c,v 1.2 2019/01/19 20:56:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: a9tmr_fdt.c,v 1.3 2019/01/22 15:17:33 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -48,8 +48,15 @@ static int	a9tmr_fdt_match(device_t, cfd
 static void	a9tmr_fdt_attach(device_t, device_t, void *);
 
 static void	a9tmr_fdt_cpu_hatch(void *, struct cpu_info *);
+static void	a9tmr_fdt_speed_changed(device_t);
 
-CFATTACH_DECL_NEW(a9tmr_fdt, 0, a9tmr_fdt_match, a9tmr_fdt_attach, NULL, NULL);
+struct a9tmr_fdt_softc {
+	device_t	sc_dev;
+	struct clk	*sc_clk;
+};
+
+CFATTACH_DECL_NEW(a9tmr_fdt, sizeof(struct a9tmr_fdt_softc),
+    a9tmr_fdt_match, a9tmr_fdt_attach, NULL, NULL);
 
 static int
 a9tmr_fdt_match(device_t parent, cfdata_t cf, void *aux)
@@ -67,21 +74,23 @@ a9tmr_fdt_match(device_t parent, cfdata_
 static void
 a9tmr_fdt_attach(device_t parent, device_t self, void *aux)
 {
+	struct a9tmr_fdt_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
 	bus_space_handle_t bsh;
 
-	struct clk *clk = fdtbus_clock_get_index(phandle, 0);
-	if (clk == NULL) {
+	sc->sc_dev = self;
+	sc->sc_clk = fdtbus_clock_get_index(phandle, 0);
+	if (sc->sc_clk == NULL) {
 		aprint_error(": couldn't get clock\n");
 		return;
 	}
-	if (clk_enable(clk) != 0) {
+	if (clk_enable(sc->sc_clk) != 0) {
 		aprint_error(": couldn't enable clock\n");
 		return;
 	}
 
-	uint32_t rate = clk_get_rate(clk);
+	uint32_t rate = clk_get_rate(sc->sc_clk);
 	prop_dictionary_t dict = device_properties(self);
 	prop_dictionary_set_uint32(dict, "frequency", rate);
 
@@ -124,6 +133,8 @@ a9tmr_fdt_attach(device_t parent, device
 
 	arm_fdt_cpu_hatch_register(self, a9tmr_fdt_cpu_hatch);
 	arm_fdt_timer_register(a9tmr_cpu_initclocks);
+
+	pmf_event_register(self, PMFE_SPEED_CHANGED, a9tmr_fdt_speed_changed, true);
 }
 
 static void
@@ -131,3 +142,16 @@ a9tmr_fdt_cpu_hatch(void *priv, struct c
 {
 	a9tmr_init_cpu_clock(ci);
 }
+
+static void
+a9tmr_fdt_speed_changed(device_t dev)
+{
+	struct a9tmr_fdt_softc * const sc = device_private(dev);
+	prop_dictionary_t dict = device_properties(dev);
+	uint32_t rate;
+
+	rate = clk_get_rate(sc->sc_clk);
+	prop_dictionary_set_uint32(dict, "frequency", rate);
+
+	a9tmr_update_freq(rate);
+}

Reply via email to