Path: blob/master/drivers/clocksource/clksrc-dbx500-prcmu.c
26278 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) ST-Ericsson SA 20113*4* Author: Mattias Wallin <[email protected]> for ST-Ericsson5* Author: Sundar Iyer for ST-Ericsson6* sched_clock implementation is based on:7* plat-nomadik/timer.c Linus Walleij <[email protected]>8*9* DBx500-PRCMU Timer10* The PRCMU has 5 timers which are available in a always-on11* power domain. We use the Timer 4 for our always-on clock12* source on DB8500.13*/14#include <linux/of.h>15#include <linux/of_address.h>16#include <linux/clockchips.h>1718#define RATE_32K 327681920#define TIMER_MODE_CONTINUOUS 0x121#define TIMER_DOWNCOUNT_VAL 0xffffffff2223#define PRCMU_TIMER_REF 024#define PRCMU_TIMER_DOWNCOUNT 0x425#define PRCMU_TIMER_MODE 0x82627static void __iomem *clksrc_dbx500_timer_base;2829static u64 notrace clksrc_dbx500_prcmu_read(struct clocksource *cs)30{31void __iomem *base = clksrc_dbx500_timer_base;32u32 count, count2;3334do {35count = readl_relaxed(base + PRCMU_TIMER_DOWNCOUNT);36count2 = readl_relaxed(base + PRCMU_TIMER_DOWNCOUNT);37} while (count2 != count);3839/* Negate because the timer is a decrementing counter */40return ~count;41}4243static struct clocksource clocksource_dbx500_prcmu = {44.name = "dbx500-prcmu-timer",45.rating = 100,46.read = clksrc_dbx500_prcmu_read,47.mask = CLOCKSOURCE_MASK(32),48.flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP,49};5051static int __init clksrc_dbx500_prcmu_init(struct device_node *node)52{53clksrc_dbx500_timer_base = of_iomap(node, 0);5455/*56* The A9 sub system expects the timer to be configured as57* a continuous looping timer.58* The PRCMU should configure it but if it for some reason59* don't we do it here.60*/61if (readl(clksrc_dbx500_timer_base + PRCMU_TIMER_MODE) !=62TIMER_MODE_CONTINUOUS) {63writel(TIMER_MODE_CONTINUOUS,64clksrc_dbx500_timer_base + PRCMU_TIMER_MODE);65writel(TIMER_DOWNCOUNT_VAL,66clksrc_dbx500_timer_base + PRCMU_TIMER_REF);67}68return clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);69}70TIMER_OF_DECLARE(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4",71clksrc_dbx500_prcmu_init);727374