--- zzzz-none-000/linux-3.10.107/arch/arm/mach-footbridge/dc21285-timer.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/arch/arm/mach-footbridge/dc21285-timer.c 2021-02-04 17:41:59.000000000 +0000 @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -46,30 +47,42 @@ .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; -static void ckevt_dc21285_set_mode(enum clock_event_mode mode, +static int ckevt_dc21285_set_next_event(unsigned long delta, struct clock_event_device *c) { - switch (mode) { - case CLOCK_EVT_MODE_RESUME: - case CLOCK_EVT_MODE_PERIODIC: - *CSR_TIMER1_CLR = 0; - *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ); - *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD | - TIMER_CNTL_DIV16; - break; + *CSR_TIMER1_CLR = 0; + *CSR_TIMER1_LOAD = delta; + *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; - default: - *CSR_TIMER1_CNTL = 0; - break; - } + return 0; +} + +static int ckevt_dc21285_shutdown(struct clock_event_device *c) +{ + *CSR_TIMER1_CNTL = 0; + return 0; +} + +static int ckevt_dc21285_set_periodic(struct clock_event_device *c) +{ + *CSR_TIMER1_CLR = 0; + *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ); + *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD | + TIMER_CNTL_DIV16; + return 0; } static struct clock_event_device ckevt_dc21285 = { - .name = "dc21285_timer1", - .features = CLOCK_EVT_FEAT_PERIODIC, - .rating = 200, - .irq = IRQ_TIMER1, - .set_mode = ckevt_dc21285_set_mode, + .name = "dc21285_timer1", + .features = CLOCK_EVT_FEAT_PERIODIC | + CLOCK_EVT_FEAT_ONESHOT, + .rating = 200, + .irq = IRQ_TIMER1, + .set_next_event = ckevt_dc21285_set_next_event, + .set_state_shutdown = ckevt_dc21285_shutdown, + .set_state_periodic = ckevt_dc21285_set_periodic, + .set_state_oneshot = ckevt_dc21285_shutdown, + .tick_resume = ckevt_dc21285_set_periodic, }; static irqreturn_t timer1_interrupt(int irq, void *dev_id) @@ -78,6 +91,10 @@ *CSR_TIMER1_CLR = 0; + /* Stop the timer if in one-shot mode */ + if (clockevent_state_oneshot(ce)) + *CSR_TIMER1_CNTL = 0; + ce->event_handler(ce); return IRQ_HANDLED; @@ -86,7 +103,7 @@ static struct irqaction footbridge_timer_irq = { .name = "dc21285_timer1", .handler = timer1_interrupt, - .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, + .flags = IRQF_TIMER | IRQF_IRQPOLL, .dev_id = &ckevt_dc21285, }; @@ -105,3 +122,19 @@ ce->cpumask = cpumask_of(smp_processor_id()); clockevents_config_and_register(ce, rate, 0x4, 0xffffff); } + +static u64 notrace footbridge_read_sched_clock(void) +{ + return ~*CSR_TIMER3_VALUE; +} + +void __init footbridge_sched_clock(void) +{ + unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16); + + *CSR_TIMER3_LOAD = 0; + *CSR_TIMER3_CLR = 0; + *CSR_TIMER3_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; + + sched_clock_register(footbridge_read_sched_clock, 24, rate); +}