From 2fbdf188dcc5ca78af83c075cb2f09ce7c0aaf16 Mon Sep 17 00:00:00 2001
From: Oliver Scott <Oliver.Scott@data61.csiro.au>
Date: Thu, 7 Mar 2019 16:44:55 +1100
Subject: [PATCH] timer-refactor: Move kernel timers and rename

This change moves all arm platform timers to drivers/timer
and renames them to the compatibility string specified in the dts.
Now the correct timer is included at build time based on the dts,
this follows the same pattern as the serial-refactor.
Have moved the arm generic_timer and priv_timer into the timer
folder and updated cmake configs appropriately.
---
 src/drivers/config.cmake                      |   1 +
 src/drivers/timer/am335x-timer.c              | 110 ++++++++++++++++++
 src/drivers/timer/config.cmake                |  23 ++++
 .../timer/exynos4210-mct.c}                   |   0
 .../timer/exynos4412-mct.c}                   |   0
 .../machine => drivers/timer}/generic_timer.c |   0
 src/drivers/timer/imx31-epit.c                |  79 +++++++++++++
 .../timer.c => drivers/timer/kpss-timer.c}    |   0
 src/drivers/timer/omap3430-timer.c            |  55 +++++++++
 .../machine => drivers/timer}/priv_timer.c    |   0
 src/plat/am335x/machine/hardware.c            |  89 --------------
 src/plat/apq8064/config.cmake                 |   1 -
 src/plat/bcm2837/config.cmake                 |   1 -
 src/plat/exynos4/config.cmake                 |   1 -
 src/plat/exynos5/config.cmake                 |   2 -
 src/plat/hikey/config.cmake                   |   1 -
 src/plat/imx31/machine/hardware.c             |  48 --------
 src/plat/imx6/config.cmake                    |   1 -
 src/plat/imx7/config.cmake                    |   1 -
 src/plat/omap3/machine/hardware.c             |  34 ------
 src/plat/tk1/config.cmake                     |   1 -
 src/plat/tx1/config.cmake                     |   1 -
 src/plat/tx2/config.cmake                     |   1 -
 src/plat/zynq7000/config.cmake                |   1 -
 src/plat/zynqmp/config.cmake                  |   2 -
 25 files changed, 268 insertions(+), 185 deletions(-)
 create mode 100644 src/drivers/timer/am335x-timer.c
 create mode 100644 src/drivers/timer/config.cmake
 rename src/{plat/exynos5/machine/hardware.c => drivers/timer/exynos4210-mct.c} (100%)
 rename src/{plat/exynos4/machine/hardware.c => drivers/timer/exynos4412-mct.c} (100%)
 rename src/{arch/arm/machine => drivers/timer}/generic_timer.c (100%)
 create mode 100644 src/drivers/timer/imx31-epit.c
 rename src/{plat/apq8064/machine/timer.c => drivers/timer/kpss-timer.c} (100%)
 create mode 100644 src/drivers/timer/omap3430-timer.c
 rename src/{arch/arm/machine => drivers/timer}/priv_timer.c (100%)

diff --git a/src/drivers/config.cmake b/src/drivers/config.cmake
index 1ffcd6960..d83a5e48b 100644
--- a/src/drivers/config.cmake
+++ b/src/drivers/config.cmake
@@ -23,3 +23,4 @@ macro(RegisterDriver compatibility_strings match_strings)
 endmacro()
 
 include(src/drivers/serial/config.cmake)
+include(src/drivers/timer/config.cmake)
\ No newline at end of file
diff --git a/src/drivers/timer/am335x-timer.c b/src/drivers/timer/am335x-timer.c
new file mode 100644
index 000000000..af56cbeba
--- /dev/null
+++ b/src/drivers/timer/am335x-timer.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2014, General Dynamics C4 Systems
+ *
+ * This software may be distributed and modified according to the terms of
+ * the GNU General Public License version 2. Note that NO WARRANTY is provided.
+ * See "LICENSE_GPLv2.txt" for details.
+ *
+ * @TAG(GD_GPL)
+ */
+
+#include <config.h>
+#include <types.h>
+#include <machine/io.h>
+#include <kernel/vspace.h>
+#include <arch/machine.h>
+#include <arch/kernel/vspace.h>
+#include <plat/machine.h>
+#include <linker.h>
+#include <plat/machine/devices_gen.h>
+#include <plat/machine/hardware.h>
+#include <plat/machine/timer.h>
+
+#define TIOCP_CFG_SOFTRESET BIT(0)
+
+#define TIER_MATCHENABLE BIT(0)
+#define TIER_OVERFLOWENABLE BIT(1)
+#define TIER_COMPAREENABLE BIT(2)
+
+#define TCLR_AUTORELOAD BIT(1)
+#define TCLR_COMPAREENABLE BIT(6)
+#define TCLR_STARTTIMER BIT(0)
+
+timer_t *timer = (timer_t *) TIMER_PPTR;
+
+#define WDT_REG(base, off) ((volatile uint32_t *)((base) + (off)))
+#define WDT_REG_WWPS 0x34
+#define WDT_REG_WSPR 0x48
+#define WDT_WWPS_PEND_WSPR BIT(4)
+
+static BOOT_CODE void
+disableWatchdog(void)
+{
+    uint32_t wdt = WDT1_PPTR;
+
+    // am335x ref man, sec 20.4.3.8
+    *WDT_REG(wdt, WDT_REG_WSPR) = 0xaaaa;
+    while ((*WDT_REG(wdt, WDT_REG_WWPS) & WDT_WWPS_PEND_WSPR)) {
+        continue;
+    }
+    *WDT_REG(wdt, WDT_REG_WSPR) = 0x5555;
+    while ((*WDT_REG(wdt, WDT_REG_WWPS) & WDT_WWPS_PEND_WSPR)) {
+        continue;
+    }
+}
+
+/*
+ * Enable DMTIMER clocks, otherwise their registers wont be accessible.
+ * This could be moved out of kernel.
+ */
+static BOOT_CODE void
+enableTimers(void)
+{
+    uint32_t cmper = CMPER_PPTR;
+
+    /* XXX repeat this for DMTIMER4..7 */
+    /* select clock */
+    *CMPER_REG(cmper, CMPER_CLKSEL_TIMER3) = CMPER_CKLSEL_MOSC;
+    while ((*CMPER_REG(cmper, CMPER_CLKSEL_TIMER3) & 3) != CMPER_CKLSEL_MOSC) {
+        continue;
+    }
+
+    /* enable clock */
+    *CMPER_REG(cmper, CMPER_TIMER3_CLKCTRL) = CMPER_CLKCTRL_ENABLE;
+    while ((*CMPER_REG(cmper, CMPER_TIMER3_CLKCTRL) & 3) != CMPER_CLKCTRL_ENABLE) {
+        continue;
+    }
+}
+
+/* Configure dmtimer0 as kernel preemption timer */
+BOOT_CODE void
+initTimer(void)
+{
+    int timeout;
+
+    disableWatchdog();
+    enableTimers();
+
+    timer->cfg = TIOCP_CFG_SOFTRESET;
+
+    for (timeout = 10000; (timer->cfg & TIOCP_CFG_SOFTRESET) && timeout > 0; timeout--)
+        ;
+    if (!timeout) {
+        printf("init timer failed\n");
+        return;
+    }
+
+    maskInterrupt(/*disable*/ true, KERNEL_TIMER_IRQ);
+
+    /* Set the reload value */
+    timer->tldr = 0xFFFFFFFFUL - TIMER_RELOAD;
+
+    /* Enables interrupt on overflow */
+    timer->tier = TIER_OVERFLOWENABLE;
+
+    /* Clear the read register */
+    timer->tcrr = 0xFFFFFFFFUL - TIMER_RELOAD;
+
+    /* Set autoreload and start the timer */
+    timer->tclr = TCLR_AUTORELOAD | TCLR_STARTTIMER;
+}
diff --git a/src/drivers/timer/config.cmake b/src/drivers/timer/config.cmake
new file mode 100644
index 000000000..97816e598
--- /dev/null
+++ b/src/drivers/timer/config.cmake
@@ -0,0 +1,23 @@
+#
+# Copyright 2019, Data61
+# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
+# ABN 41 687 119 230.
+#
+# This software may be distributed and modified according to the terms of
+# the GNU General Public License version 2. Note that NO WARRANTY is provided.
+# See "LICENSE_GPLv2.txt" for details.
+#
+# @TAG(DATA61_GPL)
+#
+
+cmake_minimum_required(VERSION 3.7.2)
+
+RegisterDriver(compatibility_strings "ti,am335x-timer" PREFIX src/drivers/timer CFILES "am335x-timer.c")
+RegisterDriver(compatibility_strings "qcom,kpss-timer" PREFIX src/drivers/timer CFILES "kpss-timer.c")
+RegisterDriver(compatibility_strings "samsung,exynos4210-mct" PREFIX src/drivers/timer CFILES "exynos4210-mct.c")
+RegisterDriver(compatibility_strings "samsung,exynos4412-mct" PREFIX src/drivers/timer CFILES "exynos4412-mct.c")
+RegisterDriver(compatibility_strings "fsl,imx31-epit" PREFIX src/drivers/timer CFILES "imx31-epit.c")
+RegisterDriver(compatibility_strings "ti,omap3430-timer" PREFIX src/drivers/timer CFILES "omap3430-timer.c")
+RegisterDriver(compatibility_strings "arm,cortex-a9-twd-timer" PREFIX src/drivers/timer CFILES "priv_timer.c")
+RegisterDriver(compatibility_strings "arm,armv7-timer" PREFIX src/drivers/timer CFILES "generic_timer.c")
+RegisterDriver(compatibility_strings "arm,armv8-timer" PREFIX src/drivers/timer CFILES "generic_timer.c")
\ No newline at end of file
diff --git a/src/plat/exynos5/machine/hardware.c b/src/drivers/timer/exynos4210-mct.c
similarity index 100%
rename from src/plat/exynos5/machine/hardware.c
rename to src/drivers/timer/exynos4210-mct.c
diff --git a/src/plat/exynos4/machine/hardware.c b/src/drivers/timer/exynos4412-mct.c
similarity index 100%
rename from src/plat/exynos4/machine/hardware.c
rename to src/drivers/timer/exynos4412-mct.c
diff --git a/src/arch/arm/machine/generic_timer.c b/src/drivers/timer/generic_timer.c
similarity index 100%
rename from src/arch/arm/machine/generic_timer.c
rename to src/drivers/timer/generic_timer.c
diff --git a/src/drivers/timer/imx31-epit.c b/src/drivers/timer/imx31-epit.c
new file mode 100644
index 000000000..7229f37b1
--- /dev/null
+++ b/src/drivers/timer/imx31-epit.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2014, General Dynamics C4 Systems
+ *
+ * This software may be distributed and modified according to the terms of
+ * the GNU General Public License version 2. Note that NO WARRANTY is provided.
+ * See "LICENSE_GPLv2.txt" for details.
+ *
+ * @TAG(GD_GPL)
+ */
+
+#include <config.h>
+#include <types.h>
+#include <machine/io.h>
+#include <kernel/vspace.h>
+#include <arch/machine.h>
+#include <arch/kernel/vspace.h>
+#include <plat/machine.h>
+#include <linker.h>
+#include <plat/machine/devices.h>
+#include <plat/machine/devices_gen.h>
+#include <plat/machine/hardware.h>
+#include <plat/machine/timer.h>
+#include <plat/machine/hardware_gen.h>
+#include <arch/benchmark_overflowHandler.h>
+
+#define L2_LINE_SIZE_BITS 5
+#define L2_LINE_SIZE BIT(L2_LINE_SIZE_BITS)
+
+#define L2_LINE_START(a) ROUND_DOWN(a, L2_LINE_SIZE_BITS)
+#define L2_LINE_INDEX(a) (L2_LINE_START(a)>>L2_LINE_SIZE_BITS)
+
+timer_t *epit1 = (timer_t *) EPIT_PPTR;
+
+enum IPGConstants {
+    IPG_CLK = 1,
+    IPG_CLK_HIGHFREQ = 2,
+    IPG_CLK_32K = 3
+};
+
+#define TIMER_CLOCK_SRC   IPG_CLK_32K
+
+interrupt_t active_irq = irqInvalid;
+
+/* Configure EPIT1 as kernel preemption timer */
+BOOT_CODE void
+initTimer(void)
+{
+    epitcr_t epitcr_kludge;
+
+    /* Stop timer */
+    epit1->epitcr = 0;
+
+    /* Configure timer */
+    epitcr_kludge.words[0] = 0; /* Zero struct */
+    epitcr_kludge = epitcr_set_clksrc(epitcr_kludge, TIMER_CLOCK_SRC);
+    /* Overwrite counter immediately on write */
+    epitcr_kludge = epitcr_set_iovw(epitcr_kludge, 1);
+    /* Reload from modulus register */
+    epitcr_kludge = epitcr_set_rld(epitcr_kludge, 1);
+    /* Enable interrupt */
+    epitcr_kludge = epitcr_set_ocien(epitcr_kludge, 1);
+    /* Count from modulus value on restart */
+    epitcr_kludge = epitcr_set_enmod(epitcr_kludge, 1);
+    epit1->epitcr = epitcr_kludge.words[0];
+
+    /* Set counter modulus */
+    epit1->epitlr = TIMER_RELOAD;
+
+    /* Interrupt at zero count */
+    epit1->epitcmpr = 0;
+
+    /* Clear pending interrupt */
+    epit1->epitsr = 1;
+
+    /* Enable timer */
+    epitcr_kludge = epitcr_set_en(epitcr_kludge, 1);
+    epit1->epitcr = epitcr_kludge.words[0];
+}
+
diff --git a/src/plat/apq8064/machine/timer.c b/src/drivers/timer/kpss-timer.c
similarity index 100%
rename from src/plat/apq8064/machine/timer.c
rename to src/drivers/timer/kpss-timer.c
diff --git a/src/drivers/timer/omap3430-timer.c b/src/drivers/timer/omap3430-timer.c
new file mode 100644
index 000000000..101f0c3e5
--- /dev/null
+++ b/src/drivers/timer/omap3430-timer.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014, General Dynamics C4 Systems
+ *
+ * This software may be distributed and modified according to the terms of
+ * the GNU General Public License version 2. Note that NO WARRANTY is provided.
+ * See "LICENSE_GPLv2.txt" for details.
+ *
+ * @TAG(GD_GPL)
+ */
+
+#include <config.h>
+#include <types.h>
+#include <machine/io.h>
+#include <kernel/vspace.h>
+#include <arch/machine.h>
+#include <arch/kernel/vspace.h>
+#include <plat/machine.h>
+#include <linker.h>
+#include <plat/machine/devices_gen.h>
+#include <plat/machine/hardware.h>
+#include <plat/machine/timer.h>
+
+#define TIMER_INTERVAL_MS (CONFIG_TIMER_TICK_MS)
+
+#define TIOCP_CFG_SOFTRESET BIT(1)
+#define TCLR_AUTORELOAD     BIT(1)
+#define TCLR_COMPAREENABLE  BIT(6)
+#define TCLR_STARTTIMER     BIT(0)
+#define TIER_MATCHENABLE    BIT(0)
+#define TIER_OVERFLOWENABLE BIT(1)
+
+timer_t *timer = (timer_t *) TIMER_PPTR;
+
+BOOT_CODE void
+initTimer(void)
+{
+    /* Configure gptimer9 as kernel timer */
+    timer->cfg = TIOCP_CFG_SOFTRESET;
+
+    while (!timer->tistat);
+
+    maskInterrupt(/*disable*/ true, KERNEL_TIMER_IRQ);
+
+    /* Set the reload value */
+    timer->tldr = 0xFFFFFFFFUL - TIMER_RELOAD;
+
+    /* Enables interrupt on overflow */
+    timer->tier = TIER_OVERFLOWENABLE;
+
+    /* Clear the read register */
+    timer->tcrr = 0xFFFFFFFFUL - TIMER_RELOAD;
+
+    /* Set autoreload and start the timer */
+    timer->tclr = TCLR_AUTORELOAD | TCLR_STARTTIMER;
+}
diff --git a/src/arch/arm/machine/priv_timer.c b/src/drivers/timer/priv_timer.c
similarity index 100%
rename from src/arch/arm/machine/priv_timer.c
rename to src/drivers/timer/priv_timer.c
diff --git a/src/plat/am335x/machine/hardware.c b/src/plat/am335x/machine/hardware.c
index 264408eaf..5d680e980 100644
--- a/src/plat/am335x/machine/hardware.c
+++ b/src/plat/am335x/machine/hardware.c
@@ -20,95 +20,6 @@
 #include <plat/machine/hardware.h>
 #include <plat/machine/timer.h>
 
-#define TIOCP_CFG_SOFTRESET BIT(0)
-
-#define TIER_MATCHENABLE BIT(0)
-#define TIER_OVERFLOWENABLE BIT(1)
-#define TIER_COMPAREENABLE BIT(2)
-
-#define TCLR_AUTORELOAD BIT(1)
-#define TCLR_COMPAREENABLE BIT(6)
-#define TCLR_STARTTIMER BIT(0)
-
-timer_t *timer = (timer_t *) TIMER_PPTR;
-
-#define WDT_REG(base, off) ((volatile uint32_t *)((base) + (off)))
-#define WDT_REG_WWPS 0x34
-#define WDT_REG_WSPR 0x48
-#define WDT_WWPS_PEND_WSPR BIT(4)
-
-static BOOT_CODE void
-disableWatchdog(void)
-{
-    uint32_t wdt = WDT1_PPTR;
-
-    // am335x ref man, sec 20.4.3.8
-    *WDT_REG(wdt, WDT_REG_WSPR) = 0xaaaa;
-    while ((*WDT_REG(wdt, WDT_REG_WWPS) & WDT_WWPS_PEND_WSPR)) {
-        continue;
-    }
-    *WDT_REG(wdt, WDT_REG_WSPR) = 0x5555;
-    while ((*WDT_REG(wdt, WDT_REG_WWPS) & WDT_WWPS_PEND_WSPR)) {
-        continue;
-    }
-}
-
-/*
- * Enable DMTIMER clocks, otherwise their registers wont be accessible.
- * This could be moved out of kernel.
- */
-static BOOT_CODE void
-enableTimers(void)
-{
-    uint32_t cmper = CMPER_PPTR;
-
-    /* XXX repeat this for DMTIMER4..7 */
-    /* select clock */
-    *CMPER_REG(cmper, CMPER_CLKSEL_TIMER3) = CMPER_CKLSEL_MOSC;
-    while ((*CMPER_REG(cmper, CMPER_CLKSEL_TIMER3) & 3) != CMPER_CKLSEL_MOSC) {
-        continue;
-    }
-
-    /* enable clock */
-    *CMPER_REG(cmper, CMPER_TIMER3_CLKCTRL) = CMPER_CLKCTRL_ENABLE;
-    while ((*CMPER_REG(cmper, CMPER_TIMER3_CLKCTRL) & 3) != CMPER_CLKCTRL_ENABLE) {
-        continue;
-    }
-}
-
-/* Configure dmtimer0 as kernel preemption timer */
-BOOT_CODE void
-initTimer(void)
-{
-    int timeout;
-
-    disableWatchdog();
-    enableTimers();
-
-    timer->cfg = TIOCP_CFG_SOFTRESET;
-
-    for (timeout = 10000; (timer->cfg & TIOCP_CFG_SOFTRESET) && timeout > 0; timeout--)
-        ;
-    if (!timeout) {
-        printf("init timer failed\n");
-        return;
-    }
-
-    maskInterrupt(/*disable*/ true, KERNEL_TIMER_IRQ);
-
-    /* Set the reload value */
-    timer->tldr = 0xFFFFFFFFUL - TIMER_RELOAD;
-
-    /* Enables interrupt on overflow */
-    timer->tier = TIER_OVERFLOWENABLE;
-
-    /* Clear the read register */
-    timer->tcrr = 0xFFFFFFFFUL - TIMER_RELOAD;
-
-    /* Set autoreload and start the timer */
-    timer->tclr = TCLR_AUTORELOAD | TCLR_STARTTIMER;
-}
-
 BOOT_CODE void
 initIRQController(void)
 {
diff --git a/src/plat/apq8064/config.cmake b/src/plat/apq8064/config.cmake
index 74e31b25b..410c1a959 100644
--- a/src/plat/apq8064/config.cmake
+++ b/src/plat/apq8064/config.cmake
@@ -24,7 +24,6 @@ endif()
 add_sources(
     DEP "KernelPlatformAPQ8064"
     CFILES
-        src/plat/apq8064/machine/timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/bcm2837/config.cmake b/src/plat/bcm2837/config.cmake
index c64844112..95887e942 100644
--- a/src/plat/bcm2837/config.cmake
+++ b/src/plat/bcm2837/config.cmake
@@ -28,6 +28,5 @@ add_sources(
     DEP "KernelPlatformRpi3"
     CFILES
         src/plat/bcm2837/machine/intc.c
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/exynos4/config.cmake b/src/plat/exynos4/config.cmake
index 63fcfbc8a..e633bfea9 100644
--- a/src/plat/exynos4/config.cmake
+++ b/src/plat/exynos4/config.cmake
@@ -23,7 +23,6 @@ endif()
 add_sources(
     DEP "KernelPlatformExynos4"
     CFILES
-        src/plat/exynos4/machine/hardware.c
         src/arch/arm/machine/l2c_310.c
         src/arch/arm/machine/gic_pl390.c
 )
diff --git a/src/plat/exynos5/config.cmake b/src/plat/exynos5/config.cmake
index 685123a81..4ef0d2668 100644
--- a/src/plat/exynos5/config.cmake
+++ b/src/plat/exynos5/config.cmake
@@ -34,8 +34,6 @@ endif()
 add_sources(
     DEP "KernelPlatExynos5"
     CFILES
-        src/arch/arm/machine/generic_timer.c
-        src/plat/exynos5/machine/hardware.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/hikey/config.cmake b/src/plat/hikey/config.cmake
index 66ef6e0b2..f3205d083 100644
--- a/src/plat/hikey/config.cmake
+++ b/src/plat/hikey/config.cmake
@@ -73,7 +73,6 @@ endif()
 add_sources(
     DEP "KernelPlatformHikey"
     CFILES
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/imx31/machine/hardware.c b/src/plat/imx31/machine/hardware.c
index 720da49e5..3773bbef6 100644
--- a/src/plat/imx31/machine/hardware.c
+++ b/src/plat/imx31/machine/hardware.c
@@ -29,54 +29,6 @@
 #define L2_LINE_START(a) ROUND_DOWN(a, L2_LINE_SIZE_BITS)
 #define L2_LINE_INDEX(a) (L2_LINE_START(a)>>L2_LINE_SIZE_BITS)
 
-timer_t *epit1 = (timer_t *) EPIT_PPTR;
-
-enum IPGConstants {
-    IPG_CLK = 1,
-    IPG_CLK_HIGHFREQ = 2,
-    IPG_CLK_32K = 3
-};
-
-#define TIMER_CLOCK_SRC   IPG_CLK_32K
-
-interrupt_t active_irq = irqInvalid;
-
-/* Configure EPIT1 as kernel preemption timer */
-BOOT_CODE void
-initTimer(void)
-{
-    epitcr_t epitcr_kludge;
-
-    /* Stop timer */
-    epit1->epitcr = 0;
-
-    /* Configure timer */
-    epitcr_kludge.words[0] = 0; /* Zero struct */
-    epitcr_kludge = epitcr_set_clksrc(epitcr_kludge, TIMER_CLOCK_SRC);
-    /* Overwrite counter immediately on write */
-    epitcr_kludge = epitcr_set_iovw(epitcr_kludge, 1);
-    /* Reload from modulus register */
-    epitcr_kludge = epitcr_set_rld(epitcr_kludge, 1);
-    /* Enable interrupt */
-    epitcr_kludge = epitcr_set_ocien(epitcr_kludge, 1);
-    /* Count from modulus value on restart */
-    epitcr_kludge = epitcr_set_enmod(epitcr_kludge, 1);
-    epit1->epitcr = epitcr_kludge.words[0];
-
-    /* Set counter modulus */
-    epit1->epitlr = TIMER_RELOAD;
-
-    /* Interrupt at zero count */
-    epit1->epitcmpr = 0;
-
-    /* Clear pending interrupt */
-    epit1->epitsr = 1;
-
-    /* Enable timer */
-    epitcr_kludge = epitcr_set_en(epitcr_kludge, 1);
-    epit1->epitcr = epitcr_kludge.words[0];
-}
-
 static void cleanL2(void)
 {
     /* clean all ways */
diff --git a/src/plat/imx6/config.cmake b/src/plat/imx6/config.cmake
index dc87ced34..9738178fc 100644
--- a/src/plat/imx6/config.cmake
+++ b/src/plat/imx6/config.cmake
@@ -34,6 +34,5 @@ add_sources(
     DEP "KernelPlatImx6"
     CFILES
         src/arch/arm/machine/l2c_310.c
-        src/arch/arm/machine/priv_timer.c
         src/arch/arm/machine/gic_pl390.c
 )
diff --git a/src/plat/imx7/config.cmake b/src/plat/imx7/config.cmake
index c486b6063..21269ae60 100644
--- a/src/plat/imx7/config.cmake
+++ b/src/plat/imx7/config.cmake
@@ -27,7 +27,6 @@ endif()
 add_sources(
     DEP "KernelPlatImx7"
     CFILES 
-           src/arch/arm/machine/generic_timer.c
            src/arch/arm/machine/gic_pl390.c
            src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/omap3/machine/hardware.c b/src/plat/omap3/machine/hardware.c
index 18a36899b..465e90f6c 100644
--- a/src/plat/omap3/machine/hardware.c
+++ b/src/plat/omap3/machine/hardware.c
@@ -23,40 +23,6 @@
 #define INTCPS_SYSCONFIG_SOFTRESET BIT(1)
 #define INTCPS_SYSSTATUS_RESETDONE BIT(0)
 
-#define TIMER_INTERVAL_MS (CONFIG_TIMER_TICK_MS)
-
-#define TIOCP_CFG_SOFTRESET BIT(1)
-#define TCLR_AUTORELOAD     BIT(1)
-#define TCLR_COMPAREENABLE  BIT(6)
-#define TCLR_STARTTIMER     BIT(0)
-#define TIER_MATCHENABLE    BIT(0)
-#define TIER_OVERFLOWENABLE BIT(1)
-
-timer_t *timer = (timer_t *) TIMER_PPTR;
-
-BOOT_CODE void
-initTimer(void)
-{
-    /* Configure gptimer9 as kernel timer */
-    timer->cfg = TIOCP_CFG_SOFTRESET;
-
-    while (!timer->tistat);
-
-    maskInterrupt(/*disable*/ true, KERNEL_TIMER_IRQ);
-
-    /* Set the reload value */
-    timer->tldr = 0xFFFFFFFFUL - TIMER_RELOAD;
-
-    /* Enables interrupt on overflow */
-    timer->tier = TIER_OVERFLOWENABLE;
-
-    /* Clear the read register */
-    timer->tcrr = 0xFFFFFFFFUL - TIMER_RELOAD;
-
-    /* Set autoreload and start the timer */
-    timer->tclr = TCLR_AUTORELOAD | TCLR_STARTTIMER;
-}
-
 BOOT_CODE void
 initIRQController(void)
 {
diff --git a/src/plat/tk1/config.cmake b/src/plat/tk1/config.cmake
index b24d67abb..dcf1e6526 100644
--- a/src/plat/tk1/config.cmake
+++ b/src/plat/tk1/config.cmake
@@ -26,7 +26,6 @@ add_sources(
     DEP "KernelPlatformTK1"
     CFILES
         src/plat/tk1/machine/smmu.c
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/tx1/config.cmake b/src/plat/tx1/config.cmake
index 574525647..ba376cea0 100644
--- a/src/plat/tx1/config.cmake
+++ b/src/plat/tx1/config.cmake
@@ -26,7 +26,6 @@ endif()
 add_sources(
     DEP "KernelPlatformTx1"
     CFILES
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/tx2/config.cmake b/src/plat/tx2/config.cmake
index 8b6307dee..caf109758 100644
--- a/src/plat/tx2/config.cmake
+++ b/src/plat/tx2/config.cmake
@@ -29,7 +29,6 @@ endif()
 add_sources(
     DEP "KernelPlatformTx2"
     CFILES
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
diff --git a/src/plat/zynq7000/config.cmake b/src/plat/zynq7000/config.cmake
index d3e34f53a..def5904a0 100644
--- a/src/plat/zynq7000/config.cmake
+++ b/src/plat/zynq7000/config.cmake
@@ -24,6 +24,5 @@ add_sources(
     DEP "KernelPlatformZynq7000"
     CFILES
         src/arch/arm/machine/l2c_310.c
-        src/arch/arm/machine/priv_timer.c
         src/arch/arm/machine/gic_pl390.c
 )
diff --git a/src/plat/zynqmp/config.cmake b/src/plat/zynqmp/config.cmake
index f6c916b53..3e7fb36ac 100644
--- a/src/plat/zynqmp/config.cmake
+++ b/src/plat/zynqmp/config.cmake
@@ -36,8 +36,6 @@ endif()
 add_sources(
     DEP "KernelPlatformZynqmp"
     CFILES
-        src/plat/zynqmp/machine/hardware.c
-        src/arch/arm/machine/generic_timer.c
         src/arch/arm/machine/gic_pl390.c
         src/arch/arm/machine/l2c_nop.c
 )
-- 
GitLab