Path: blob/master/arch/arm/mach-footbridge/dc21285-timer.c
26292 views
// SPDX-License-Identifier: GPL-2.01/*2* linux/arch/arm/mach-footbridge/dc21285-timer.c3*4* Copyright (C) 1998 Russell King.5* Copyright (C) 1998 Phil Blundell6*/7#include <linux/clockchips.h>8#include <linux/clocksource.h>9#include <linux/init.h>10#include <linux/interrupt.h>11#include <linux/irq.h>12#include <linux/sched_clock.h>1314#include <asm/irq.h>1516#include <asm/hardware/dec21285.h>17#include <asm/mach/time.h>18#include <asm/system_info.h>1920#include "common.h"2122static u64 cksrc_dc21285_read(struct clocksource *cs)23{24return cs->mask - *CSR_TIMER2_VALUE;25}2627static int cksrc_dc21285_enable(struct clocksource *cs)28{29*CSR_TIMER2_LOAD = cs->mask;30*CSR_TIMER2_CLR = 0;31*CSR_TIMER2_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;32return 0;33}3435static void cksrc_dc21285_disable(struct clocksource *cs)36{37*CSR_TIMER2_CNTL = 0;38}3940static struct clocksource cksrc_dc21285 = {41.name = "dc21285_timer2",42.rating = 200,43.read = cksrc_dc21285_read,44.enable = cksrc_dc21285_enable,45.disable = cksrc_dc21285_disable,46.mask = CLOCKSOURCE_MASK(24),47.flags = CLOCK_SOURCE_IS_CONTINUOUS,48};4950static int ckevt_dc21285_set_next_event(unsigned long delta,51struct clock_event_device *c)52{53*CSR_TIMER1_CLR = 0;54*CSR_TIMER1_LOAD = delta;55*CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;5657return 0;58}5960static int ckevt_dc21285_shutdown(struct clock_event_device *c)61{62*CSR_TIMER1_CNTL = 0;63return 0;64}6566static int ckevt_dc21285_set_periodic(struct clock_event_device *c)67{68*CSR_TIMER1_CLR = 0;69*CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ);70*CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD |71TIMER_CNTL_DIV16;72return 0;73}7475static struct clock_event_device ckevt_dc21285 = {76.name = "dc21285_timer1",77.features = CLOCK_EVT_FEAT_PERIODIC |78CLOCK_EVT_FEAT_ONESHOT,79.rating = 200,80.irq = IRQ_TIMER1,81.set_next_event = ckevt_dc21285_set_next_event,82.set_state_shutdown = ckevt_dc21285_shutdown,83.set_state_periodic = ckevt_dc21285_set_periodic,84.set_state_oneshot = ckevt_dc21285_shutdown,85.tick_resume = ckevt_dc21285_set_periodic,86};8788static irqreturn_t timer1_interrupt(int irq, void *dev_id)89{90struct clock_event_device *ce = dev_id;9192*CSR_TIMER1_CLR = 0;9394/* Stop the timer if in one-shot mode */95if (clockevent_state_oneshot(ce))96*CSR_TIMER1_CNTL = 0;9798ce->event_handler(ce);99100return IRQ_HANDLED;101}102103/*104* Set up timer interrupt.105*/106void __init footbridge_timer_init(void)107{108struct clock_event_device *ce = &ckevt_dc21285;109unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);110111clocksource_register_hz(&cksrc_dc21285, rate);112113if (request_irq(ce->irq, timer1_interrupt, IRQF_TIMER | IRQF_IRQPOLL,114"dc21285_timer1", &ckevt_dc21285))115pr_err("Failed to request irq %d (dc21285_timer1)", ce->irq);116117ce->cpumask = cpumask_of(smp_processor_id());118clockevents_config_and_register(ce, rate, 0x4, 0xffffff);119}120121static u64 notrace footbridge_read_sched_clock(void)122{123return ~*CSR_TIMER3_VALUE;124}125126void __init footbridge_sched_clock(void)127{128unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);129130*CSR_TIMER3_LOAD = 0;131*CSR_TIMER3_CLR = 0;132*CSR_TIMER3_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;133134sched_clock_register(footbridge_read_sched_clock, 24, rate);135}136137138