cregit-Linux how code gets into the kernel

Release 4.14 arch/blackfin/kernel/time-ts.c

/*
 * Based on arm clockevents implementation and old bfin time tick.
 *
 * Copyright 2008-2009 Analog Devics Inc.
 *                2008 GeoTechnologies
 *                     Vitja Makarov
 *
 * Licensed under the GPL-2
 */

#include <linux/module.h>
#include <linux/profile.h>
#include <linux/interrupt.h>
#include <linux/time.h>
#include <linux/timex.h>
#include <linux/irq.h>
#include <linux/clocksource.h>
#include <linux/clockchips.h>
#include <linux/cpufreq.h>

#include <asm/blackfin.h>
#include <asm/time.h>
#include <asm/gptimers.h>
#include <asm/nmi.h>


#if defined(CONFIG_CYCLES_CLOCKSOURCE)


static notrace u64 bfin_read_cycles(struct clocksource *cs) { #ifdef CONFIG_CPU_FREQ return __bfin_cycles_off + (get_cycles() << __bfin_cycles_mod); #else return get_cycles(); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov1339.39%225.00%
Graf Yang1236.36%225.00%
Magnus Damm412.12%112.50%
Mike Frysinger26.06%112.50%
Yi Li13.03%112.50%
Thomas Gleixner13.03%112.50%
Total33100.00%8100.00%

static struct clocksource bfin_cs_cycles = { .name = "bfin_cs_cycles", .rating = 400, .read = bfin_read_cycles, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, };
static inline unsigned long long bfin_cs_cycles_sched_clock(void) { return clocksource_cyc2ns(bfin_read_cycles(&bfin_cs_cycles), bfin_cs_cycles.mult, bfin_cs_cycles.shift); }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm1551.72%125.00%
Mike Frysinger931.03%125.00%
Yi Li310.34%125.00%
Graf Yang26.90%125.00%
Total29100.00%4100.00%


static int __init bfin_cs_cycles_init(void) { if (clocksource_register_hz(&bfin_cs_cycles, get_cclk())) panic("failed to register clocksource"); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang1760.71%133.33%
Vitja Makarov725.00%133.33%
John Stultz414.29%133.33%
Total28100.00%3100.00%

#else # define bfin_cs_cycles_init() #endif #ifdef CONFIG_GPTMR0_CLOCKSOURCE
void __init setup_gptimer0(void) { disable_gptimers(TIMER0bit); #ifdef CONFIG_BF60x bfin_write16(TIMER_DATA_IMSK, 0); set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_MODE_PWM_CONT | TIMER_PULSE_HI | TIMER_IRQ_PER); #else set_gptimer_config(TIMER0_id, \ TIMER_OUT_DIS | TIMER_PERIOD_CNT | TIMER_MODE_PWM); #endif set_gptimer_period(TIMER0_id, -1); set_gptimer_pwidth(TIMER0_id, -2); SSYNC(); enable_gptimers(TIMER0bit); }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang4864.00%150.00%
Steven Miao2736.00%150.00%
Total75100.00%2100.00%


static u64 bfin_read_gptimer0(struct clocksource *cs) { return bfin_read_TIMER0_COUNTER(); }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang1066.67%133.33%
Yi Li426.67%133.33%
Thomas Gleixner16.67%133.33%
Total15100.00%3100.00%

static struct clocksource bfin_cs_gptimer0 = { .name = "bfin_cs_gptimer0", .rating = 350, .read = bfin_read_gptimer0, .mask = CLOCKSOURCE_MASK(32), .flags = CLOCK_SOURCE_IS_CONTINUOUS, };
static inline unsigned long long bfin_cs_gptimer0_sched_clock(void) { return clocksource_cyc2ns(bfin_read_TIMER0_COUNTER(), bfin_cs_gptimer0.mult, bfin_cs_gptimer0.shift); }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li1765.38%150.00%
Mike Frysinger934.62%150.00%
Total26100.00%2100.00%


static int __init bfin_cs_gptimer0_init(void) { setup_gptimer0(); if (clocksource_register_hz(&bfin_cs_gptimer0, get_sclk())) panic("failed to register clocksource"); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang2787.10%150.00%
John Stultz412.90%150.00%
Total31100.00%2100.00%

#else # define bfin_cs_gptimer0_init() #endif #if defined(CONFIG_GPTMR0_CLOCKSOURCE) || defined(CONFIG_CYCLES_CLOCKSOURCE) /* prefer to use cycles since it has higher rating */
notrace unsigned long long sched_clock(void) { #if defined(CONFIG_CYCLES_CLOCKSOURCE) return bfin_cs_cycles_sched_clock(); #else return bfin_cs_gptimer0_sched_clock(); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li28100.00%1100.00%
Total28100.00%1100.00%

#endif #if defined(CONFIG_TICKSOURCE_GPTMR0)
static int bfin_gptmr0_set_next_event(unsigned long cycles, struct clock_event_device *evt) { disable_gptimers(TIMER0bit); /* it starts counting three SCLK cycles after the TIMENx bit is set */ set_gptimer_pwidth(TIMER0_id, cycles - 3); enable_gptimers(TIMER0bit); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang3797.37%150.00%
Yi Li12.63%150.00%
Total38100.00%2100.00%


static int bfin_gptmr0_set_periodic(struct clock_event_device *evt) { #ifndef CONFIG_BF60x set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_IRQ_ENA | TIMER_PERIOD_CNT | TIMER_MODE_PWM); #else set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_MODE_PWM_CONT | TIMER_PULSE_HI | TIMER_IRQ_PER); #endif set_gptimer_period(TIMER0_id, get_sclk() / HZ); set_gptimer_pwidth(TIMER0_id, get_sclk() / HZ - 1); enable_gptimers(TIMER0bit); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang4864.86%133.33%
Steven Miao2027.03%133.33%
Viresh Kumar68.11%133.33%
Total74100.00%3100.00%


static int bfin_gptmr0_set_oneshot(struct clock_event_device *evt) { disable_gptimers(TIMER0bit); #ifndef CONFIG_BF60x set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_IRQ_ENA | TIMER_MODE_PWM); #else set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_MODE_PWM | TIMER_PULSE_HI | TIMER_IRQ_WID_DLY); #endif set_gptimer_period(TIMER0_id, 0); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang2238.60%133.33%
Steven Miao2035.09%133.33%
Viresh Kumar1526.32%133.33%
Total57100.00%3100.00%


static int bfin_gptmr0_shutdown(struct clock_event_device *evt) { disable_gptimers(TIMER0bit); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar1368.42%150.00%
Graf Yang631.58%150.00%
Total19100.00%2100.00%


static void bfin_gptmr0_ack(void) { clear_gptimer_intr(TIMER0_id); }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang1076.92%133.33%
Steven Miao215.38%133.33%
Yi Li17.69%133.33%
Total13100.00%3100.00%


static void __init bfin_gptmr0_init(void) { disable_gptimers(TIMER0bit); }

Contributors

PersonTokensPropCommitsCommitProp
Graf Yang1178.57%133.33%
Vitja Makarov214.29%133.33%
Yi Li17.14%133.33%
Total14100.00%3100.00%

#ifdef CONFIG_CORE_TIMER_IRQ_L1 __attribute__((l1_text)) #endif
irqreturn_t bfin_gptmr0_interrupt(int irq, void *dev_id) { struct clock_event_device *evt = dev_id; smp_mb(); /* * We want to ACK before we handle so that we can handle smaller timer * intervals. This way if the timer expires again while we're handling * things, we're more likely to see that 2nd int rather than swallowing * it by ACKing the int at the end of this handler. */ bfin_gptmr0_ack(); evt->event_handler(evt); return IRQ_HANDLED; }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li2466.67%125.00%
Mike Frysinger411.11%125.00%
Vitja Makarov411.11%125.00%
Graf Yang411.11%125.00%
Total36100.00%4100.00%

static struct irqaction gptmr0_irq = { .name = "Blackfin GPTimer0", .flags = IRQF_TIMER | IRQF_IRQPOLL | IRQF_PERCPU, .handler = bfin_gptmr0_interrupt, }; static struct clock_event_device clockevent_gptmr0 = { .name = "bfin_gptimer0", .rating = 300, .irq = IRQ_TIMER0, .shift = 32, .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, .set_next_event = bfin_gptmr0_set_next_event, .set_state_shutdown = bfin_gptmr0_shutdown, .set_state_periodic = bfin_gptmr0_set_periodic, .set_state_oneshot = bfin_gptmr0_set_oneshot, };
static void __init bfin_gptmr0_clockevent_init(struct clock_event_device *evt) { unsigned long clock_tick; clock_tick = get_sclk(); evt->mult = div_sc(clock_tick, NSEC_PER_SEC, evt->shift); evt->max_delta_ns = clockevent_delta2ns(-1, evt); evt->max_delta_ticks = (unsigned long)-1; evt->min_delta_ns = clockevent_delta2ns(100, evt); evt->min_delta_ticks = 100; evt->cpumask = cpumask_of(0); clockevents_register_device(evt); }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li7077.78%125.00%
Nicolai Stange1718.89%125.00%
Graf Yang22.22%125.00%
Vitja Makarov11.11%125.00%
Total90100.00%4100.00%

#endif /* CONFIG_TICKSOURCE_GPTMR0 */ #if defined(CONFIG_TICKSOURCE_CORETMR) /* per-cpu local core timer */ DEFINE_PER_CPU(struct clock_event_device, coretmr_events);
static int bfin_coretmr_set_next_event(unsigned long cycles, struct clock_event_device *evt) { bfin_write_TCNTL(TMPWR); CSYNC(); bfin_write_TCOUNT(cycles); CSYNC(); bfin_write_TCNTL(TMPWR | TMREN); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov2560.98%133.33%
Graf Yang1536.59%133.33%
Yi Li12.44%133.33%
Total41100.00%3100.00%


static int bfin_coretmr_set_periodic(struct clock_event_device *evt) { unsigned long tcount = ((get_cclk() / (HZ * TIME_SCALE)) - 1); bfin_write_TCNTL(TMPWR); CSYNC(); bfin_write_TSCALE(TIME_SCALE - 1); bfin_write_TPERIOD(tcount); bfin_write_TCOUNT(tcount); CSYNC(); bfin_write_TCNTL(TMPWR | TMREN | TAUTORLD); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov5172.86%125.00%
Michael Hennerich811.43%125.00%
Graf Yang68.57%125.00%
Viresh Kumar57.14%125.00%
Total70100.00%4100.00%


static int bfin_coretmr_set_oneshot(struct clock_event_device *evt) { bfin_write_TCNTL(TMPWR); CSYNC(); bfin_write_TSCALE(TIME_SCALE - 1); bfin_write_TPERIOD(0); bfin_write_TCOUNT(0); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar1435.90%120.00%
Graf Yang1128.21%120.00%
Vitja Makarov1025.64%240.00%
Michael Hennerich410.26%120.00%
Total39100.00%5100.00%


static int bfin_coretmr_shutdown(struct clock_event_device *evt) { bfin_write_TCNTL(0); CSYNC(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar1359.09%133.33%
Vitja Makarov836.36%133.33%
Yi Li14.55%133.33%
Total22100.00%3100.00%


void bfin_coretmr_init(void) { /* power up the timer, but don't enable it just yet */ bfin_write_TCNTL(TMPWR); CSYNC(); /* the TSCALE prescaler counter. */ bfin_write_TSCALE(TIME_SCALE - 1); bfin_write_TPERIOD(0); bfin_write_TCOUNT(0); CSYNC(); }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov3286.49%133.33%
Michael Hennerich38.11%133.33%
Yi Li25.41%133.33%
Total37100.00%3100.00%

#ifdef CONFIG_CORE_TIMER_IRQ_L1 __attribute__((l1_text)) #endif
irqreturn_t bfin_coretmr_interrupt(int irq, void *dev_id) { int cpu = smp_processor_id(); struct clock_event_device *evt = &per_cpu(coretmr_events, cpu); smp_mb(); evt->event_handler(evt); touch_nmi_watchdog(); return IRQ_HANDLED; }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov2757.45%125.00%
Yi Li1429.79%125.00%
Graf Yang612.77%250.00%
Total47100.00%4100.00%

static struct irqaction coretmr_irq = { .name = "Blackfin CoreTimer", .flags = IRQF_TIMER | IRQF_IRQPOLL | IRQF_PERCPU, .handler = bfin_coretmr_interrupt, };
void bfin_coretmr_clockevent_init(void) { unsigned long clock_tick; unsigned int cpu = smp_processor_id(); struct clock_event_device *evt = &per_cpu(coretmr_events, cpu); #ifdef CONFIG_SMP evt->broadcast = smp_timer_broadcast; #endif evt->name = "bfin_core_timer"; evt->rating = 350; evt->irq = -1; evt->shift = 32; evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; evt->set_next_event = bfin_coretmr_set_next_event; evt->set_state_shutdown = bfin_coretmr_shutdown; evt->set_state_periodic = bfin_coretmr_set_periodic; evt->set_state_oneshot = bfin_coretmr_set_oneshot; clock_tick = get_cclk() / TIME_SCALE; evt->mult = div_sc(clock_tick, NSEC_PER_SEC, evt->shift); evt->max_delta_ns = clockevent_delta2ns(-1, evt); evt->max_delta_ticks = (unsigned long)-1; evt->min_delta_ns = clockevent_delta2ns(100, evt); evt->min_delta_ticks = 100; evt->cpumask = cpumask_of(cpu); clockevents_register_device(evt); }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li8448.00%114.29%
Vitja Makarov4324.57%228.57%
Nicolai Stange179.71%114.29%
Viresh Kumar148.00%114.29%
Bob Liu116.29%114.29%
Rusty Russell63.43%114.29%
Total175100.00%7100.00%

#endif /* CONFIG_TICKSOURCE_CORETMR */
void read_persistent_clock(struct timespec *ts) { time_t secs_since_1970 = (365 * 37 + 9) * 24 * 60 * 60; /* 1 Jan 2007 */ ts->tv_sec = secs_since_1970; ts->tv_nsec = 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vitja Makarov2255.00%150.00%
John Stultz1845.00%150.00%
Total40100.00%2100.00%


void __init time_init(void) { #ifdef CONFIG_RTC_DRV_BFIN /* [#2663] hack to filter junk RTC values that would cause * userspace to have to deal with time values greater than * 2^31 seconds (which uClibc cannot cope with yet) */ if ((bfin_read_RTC_STAT() & 0xC0000000) == 0xC0000000) { printk(KERN_NOTICE "bfin-rtc: invalid date; resetting\n"); bfin_write_RTC_STAT(0); } #endif bfin_cs_cycles_init(); bfin_cs_gptimer0_init(); #if defined(CONFIG_TICKSOURCE_CORETMR) bfin_coretmr_init(); setup_irq(IRQ_CORETMR, &coretmr_irq); bfin_coretmr_clockevent_init(); #endif #if defined(CONFIG_TICKSOURCE_GPTMR0) bfin_gptmr0_init(); setup_irq(IRQ_TIMER0, &gptmr0_irq); gptmr0_irq.dev_id = &clockevent_gptmr0; bfin_gptmr0_clockevent_init(&clockevent_gptmr0); #endif #if !defined(CONFIG_TICKSOURCE_CORETMR) && !defined(CONFIG_TICKSOURCE_GPTMR0) # error at least one clock event device is required #endif }

Contributors

PersonTokensPropCommitsCommitProp
Yi Li7060.34%125.00%
Vitja Makarov3530.17%125.00%
John Stultz76.03%125.00%
Graf Yang43.45%125.00%
Total116100.00%4100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Yi Li47031.48%313.04%
Graf Yang36824.65%417.39%
Vitja Makarov34022.77%28.70%
Viresh Kumar926.16%14.35%
Steven Miao694.62%14.35%
Nicolai Stange342.28%14.35%
John Stultz332.21%28.70%
Mike Frysinger271.81%313.04%
Michael Hennerich211.41%14.35%
Magnus Damm191.27%14.35%
Bob Liu110.74%14.35%
Rusty Russell60.40%14.35%
Thomas Gleixner20.13%14.35%
Robin Getz10.07%14.35%
Total1493100.00%23100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.