Author: mw
Date: Tue Apr 3 22:21:12 2018
New Revision: 331961
URL: https://svnweb.freebsd.org/changeset/base/331961
Log:
Make Marvell AmadaXP timer driver more generic
Store pointers to SoC specific functions in mv_timer_config structure
and determine proper config in runtime based on compatible string from FDT.
Compatible string for ArmadaXP timers is changed to match Linux FDT.
Armada 38x uses generic Cortex-A9 timer and separate watchdog drivers, so
it does not need to be supported by timer driver.
Submitted by: Rafal Kozik
Reviewed by: manu
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D14741
Modified:
head/sys/arm/mv/timer.c
head/sys/dts/arm/db78460.dts
Modified: head/sys/arm/mv/timer.c
==
--- head/sys/arm/mv/timer.c Tue Apr 3 22:15:53 2018(r331960)
+++ head/sys/arm/mv/timer.c Tue Apr 3 22:21:12 2018(r331961)
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include
#include
#include
+#include
#include
#include
@@ -60,18 +61,20 @@ __FBSDID("$FreeBSD$");
#defineMV_WDT 0x2
#defineMV_NONE 0x0
-#if defined(SOC_MV_ARMADAXP) || defined(SOC_MV_ARMADA38X)
-#define MV_CLOCK_SRC 2500/* Timers' 25MHz mode */
-#else
-#define MV_CLOCK_SRC get_tclk()
-#endif
+#defineMV_CLOCK_SRC_ARMV7 2500/* Timers' 25MHz mode */
-#if defined(SOC_MV_ARMADA38X)
-#defineWATCHDOG_TIMER 4
-#else
-#defineWATCHDOG_TIMER 2
-#endif
+#defineWATCHDOG_TIMER_ARMV52
+typedef void (*mv_watchdog_enable_t)(void);
+typedef void (*mv_watchdog_disable_t)(void);
+
+struct mv_timer_config {
+ enum soc_family soc_family;
+ mv_watchdog_enable_twatchdog_enable;
+ mv_watchdog_disable_t watchdog_disable;
+ unsigned intclock_src;
+};
+
struct mv_timer_softc {
struct resource * timer_res[2];
bus_space_tag_t timer_bst;
@@ -79,6 +82,7 @@ struct mv_timer_softc {
struct mtx timer_mtx;
struct eventtimer et;
boolean_t has_wdt;
+ struct mv_timer_config* config;
};
static struct resource_spec mv_timer_spec[] = {
@@ -89,8 +93,9 @@ static struct resource_spec mv_timer_spec[] = {
/* Interrupt is not required by MV_WDT devices */
static struct ofw_compat_data mv_timer_compat[] = {
+ {"marvell,armada-380-timer",MV_NONE },
+ {"marvell,armada-xp-timer", MV_TMR | MV_WDT },
{"mrvl,timer", MV_TMR | MV_WDT },
- {"marvell,armada-380-wdt", MV_WDT },
{NULL, MV_NONE }
};
@@ -108,14 +113,42 @@ static void mv_set_timer_control(uint32_t);
static uint32_tmv_get_timer(uint32_t);
static voidmv_set_timer(uint32_t, uint32_t);
static voidmv_set_timer_rel(uint32_t, uint32_t);
-static voidmv_watchdog_enable(void);
-static voidmv_watchdog_disable(void);
static voidmv_watchdog_event(void *, unsigned int, int *);
static int mv_timer_start(struct eventtimer *et,
sbintime_t first, sbintime_t period);
static int mv_timer_stop(struct eventtimer *et);
static voidmv_setup_timers(void);
+static void mv_watchdog_enable_armv5(void);
+static void mv_watchdog_enable_armadaxp(void);
+static void mv_watchdog_disable_armv5(void);
+static void mv_watchdog_disable_armadaxp(void);
+
+#ifdef PLATFORM
+void mv_delay(int usec, void* arg);
+#endif
+
+static struct mv_timer_config timer_armadaxp_config =
+{
+ MV_SOC_ARMADA_XP,
+ &mv_watchdog_enable_armadaxp,
+ &mv_watchdog_disable_armadaxp,
+ MV_CLOCK_SRC_ARMV7,
+};
+static struct mv_timer_config timer_armv5_config =
+{
+ MV_SOC_ARMV5,
+ &mv_watchdog_enable_armv5,
+ &mv_watchdog_disable_armv5,
+ 0,
+};
+
+static struct ofw_compat_data mv_timer_soc_config[] = {
+ {"marvell,armada-xp-timer", (uintptr_t)&timer_armadaxp_config },
+ {"mrvl,timer", (uintptr_t)&timer_armv5_config },
+ {NULL, (uintptr_t)NULL },
+};
+
static struct timecounter mv_timer_timecounter = {
.tc_get_timecount = mv_timer_get_timecount,
.tc_name = "CPUTimer1",
@@ -144,9 +177,7 @@ mv_timer_attach(device_t dev)
int error;
void*ihl;
struct mv_timer_softc *sc;
-#if !defined(SOC_MV_ARMADAXP) && !defined(SOC_MV_ARMADA38X)
uint32_t irq_cause, irq_mask;
-#endif
if (timer_softc != NULL)
return (ENXIO);
@@ -154,6 +185,12 @@ mv_timer_attach(device_t dev)
sc = (struct mv_timer_softc *)device_get_softc(dev);
timer_softc = sc;
+ sc->config = (struct mv_timer_config*)
+ ofw_bus_search_compatible(dev, mv_timer_soc_config)->ocd_data;
+
+ if (sc->config->clock_src == 0)
+