Merge tag 'regmap-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[firefly-linux-kernel-4.4.55.git] / drivers / clocksource / time-orion.c
index 20066222f3f29cdb052c2282eafd1dadb8519d8b..0ece7427b497844848b89a09f4b4d9f0a7067624 100644 (file)
 #define ORION_ONESHOT_MAX      0xfffffffe
 
 static void __iomem *timer_base;
-static DEFINE_SPINLOCK(timer_ctrl_lock);
-
-/*
- * Thread-safe access to TIMER_CTRL register
- * (shared with watchdog timer)
- */
-void orion_timer_ctrl_clrset(u32 clr, u32 set)
-{
-       spin_lock(&timer_ctrl_lock);
-       writel((readl(timer_base + TIMER_CTRL) & ~clr) | set,
-               timer_base + TIMER_CTRL);
-       spin_unlock(&timer_ctrl_lock);
-}
-EXPORT_SYMBOL(orion_timer_ctrl_clrset);
 
 /*
  * Free-running clocksource handling.
@@ -68,32 +54,42 @@ static int orion_clkevt_next_event(unsigned long delta,
 {
        /* setup and enable one-shot timer */
        writel(delta, timer_base + TIMER1_VAL);
-       orion_timer_ctrl_clrset(TIMER1_RELOAD_EN, TIMER1_EN);
+       atomic_io_modify(timer_base + TIMER_CTRL,
+               TIMER1_RELOAD_EN | TIMER1_EN, TIMER1_EN);
 
        return 0;
 }
 
-static void orion_clkevt_mode(enum clock_event_mode mode,
-                             struct clock_event_device *dev)
+static int orion_clkevt_shutdown(struct clock_event_device *dev)
 {
-       if (mode == CLOCK_EVT_MODE_PERIODIC) {
-               /* setup and enable periodic timer at 1/HZ intervals */
-               writel(ticks_per_jiffy - 1, timer_base + TIMER1_RELOAD);
-               writel(ticks_per_jiffy - 1, timer_base + TIMER1_VAL);
-               orion_timer_ctrl_clrset(0, TIMER1_RELOAD_EN | TIMER1_EN);
-       } else {
-               /* disable timer */
-               orion_timer_ctrl_clrset(TIMER1_RELOAD_EN | TIMER1_EN, 0);
-       }
+       /* disable timer */
+       atomic_io_modify(timer_base + TIMER_CTRL,
+                        TIMER1_RELOAD_EN | TIMER1_EN, 0);
+       return 0;
+}
+
+static int orion_clkevt_set_periodic(struct clock_event_device *dev)
+{
+       /* setup and enable periodic timer at 1/HZ intervals */
+       writel(ticks_per_jiffy - 1, timer_base + TIMER1_RELOAD);
+       writel(ticks_per_jiffy - 1, timer_base + TIMER1_VAL);
+       atomic_io_modify(timer_base + TIMER_CTRL,
+                        TIMER1_RELOAD_EN | TIMER1_EN,
+                        TIMER1_RELOAD_EN | TIMER1_EN);
+       return 0;
 }
 
 static struct clock_event_device orion_clkevt = {
-       .name           = "orion_event",
-       .features       = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
-       .shift          = 32,
-       .rating         = 300,
-       .set_next_event = orion_clkevt_next_event,
-       .set_mode       = orion_clkevt_mode,
+       .name                   = "orion_event",
+       .features               = CLOCK_EVT_FEAT_ONESHOT |
+                                 CLOCK_EVT_FEAT_PERIODIC,
+       .shift                  = 32,
+       .rating                 = 300,
+       .set_next_event         = orion_clkevt_next_event,
+       .set_state_shutdown     = orion_clkevt_shutdown,
+       .set_state_periodic     = orion_clkevt_set_periodic,
+       .set_state_oneshot      = orion_clkevt_shutdown,
+       .tick_resume            = orion_clkevt_shutdown,
 };
 
 static irqreturn_t orion_clkevt_irq_handler(int irq, void *dev_id)
@@ -131,7 +127,9 @@ static void __init orion_timer_init(struct device_node *np)
        /* setup timer0 as free-running clocksource */
        writel(~0, timer_base + TIMER0_VAL);
        writel(~0, timer_base + TIMER0_RELOAD);
-       orion_timer_ctrl_clrset(0, TIMER0_RELOAD_EN | TIMER0_EN);
+       atomic_io_modify(timer_base + TIMER_CTRL,
+               TIMER0_RELOAD_EN | TIMER0_EN,
+               TIMER0_RELOAD_EN | TIMER0_EN);
        clocksource_mmio_init(timer_base + TIMER0_VAL, "orion_clocksource",
                              clk_get_rate(clk), 300, 32,
                              clocksource_mmio_readl_down);