Introduce clocksource driver for Keystone platform
Subsystems (3)
v2 cover Introduce clocksource driver for Keystone platform
Add a broadcast timer64 based clockevent driver for keystone arch. This driver uses timer in 64-bit general purpose mode as clock event device.
Documentation:
http://www.ti.com/lit/ug/sprugv5a/sprugv5a.pdf
Based ongit://git.kernel.org/pub/scm/linux/kernel/git/ssantosh/linux-keystone.git
keystone/master
v1..v2:
- clocksource: timer-keystone: introduce clocksource driver for renamed timer on "timer-keystone"
in keystone_timer_interrupt() evet pointer is passed via "dev_id" used __relaxed variants of writel/readl and added explicit barriers added "keystone_timer_disable()" for using in keystone_set_mode() keystone_timer_config() is not used for disabling the timer any more in case of an unsupported mode the keystone_timer_config() returns -1. used request_irq() instead of setup_irq()
assigned irq for event_device in event_dev->irq calculated timer.hz_period for CLOCK_EVT_MODE_PERIODIC at init deleted spare call of keystone_timer_config() in keystone_timer_init()
Ivan Khoronzhuk (3):
clocksource: timer-keystone: introduce clocksource driver for
Keystone
clocksource: keystone: add bindings for keystone timer
arm: dts: keystone: add keystone timer entry
.../bindings/timer/ti,keystone-timer.txt | 29 +++ arch/arm/boot/dts/keystone-clocks.dtsi | 10 + arch/arm/boot/dts/keystone.dtsi | 7 + drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-keystone.c | 233 ++++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/ti,keystone-timer.txt create mode 100644 drivers/clocksource/timer-keystone.c
Signature · 1 line
1.7.9.5
PATCH v2 1/3 clocksource: timer-keystone: introduce clocksource driver for Keystone
Add broadcast clock-event device for the Keystone arch.
The timer can be configured as a general-purpose 64-bit timer, dual general-purpose 32-bit timers. When configured as dual 32-bit timers, each half can operate in conjunction (chain mode) or independently (unchained mode) of each other.
--- drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-keystone.c | 233 ++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 drivers/clocksource/timer-keystone.c
drivers/clocksource/Makefile +1 -0
@@ -36,3 +36,4 @@ obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o obj-$(CONFIG_ARCH_HAS_TICK_BROADCAST) += dummy_timer.o +obj-$(CONFIG_ARCH_KEYSTONE) += timer-keystone.o
drivers/clocksource/timer-keystone.c new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 1/3 clocksource: timer-keystone: introduce clocksource driver for Keystone
Quoted 121 lines · Ivan Khoronzhuk
Add broadcast clock-event device for the Keystone arch.
The timer can be configured as a general-purpose 64-bit timer, dual general-purpose 32-bit timers. When configured as dual 32-bit timers, each half can operate in conjunction (chain mode) or independently (unchained mode) of each other.
Signed-off-by Ivan Khoronzhuk <[email protected]>--- drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-keystone.c | 233 ++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 drivers/clocksource/timer-keystone.cdrivers/clocksource/Makefile +1
-0@@ -36,3 +36,4 @@ obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o obj-$(CONFIG_ARCH_HAS_TICK_BROADCAST) += dummy_timer.o +obj-$(CONFIG_ARCH_KEYSTONE) += timer-keystone.odrivers/clocksource/timer-keystone.c new file +92
-0@@ -0,0 +1,233 @@ +/* +* Keystone broadcast clock-event +* +* Copyright 2013 Texas Instruments, Inc. +* +* Author: Ivan Khoronzhuk <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#include <linux/clk.h> +#include <linux/clockchips.h> +#include <linux/clocksource.h> +#include <linux/interrupt.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> + +#define TIMER_NAME "timer-keystone" + +/* Timer register offsets */ +#define TIM12 0x10 +#define TIM34 0x14 +#define PRD12 0x18 +#define PRD34 0x1c +#define TCR 0x20 +#define TGCR 0x24 +#define INTCTLSTAT 0x44 + +/* Timer register bitfields */ +#define TCR_ENAMODE_MASK 0xC0 +#define TCR_ENAMODE_ONESHOT_MASK 0x40 +#define TCR_ENAMODE_PERIODIC_MASK 0x80 + +#define TGCR_TIM_UNRESET_MASK 0x03 +#define INTCTLSTAT_ENINT_MASK 0x01 + +/** +* struct keystone_timer: holds timer's data +* @base: timer memory base address +* @period: source clock rate +* @irqacrion: interrupt action descriptor +* @event_dev: event device based on timer +*/ +static struct keystone_timer { +u64 hz_period; +void __iomem *base; +struct clock_event_device event_dev; +} timer; + +static inline u32 keystone_timer_readl (unsigned long rg) +{ +return readl_relaxed (timer.base + rg); +} + +static inline void keystone_timer_writel (u32 val,unsigned long rg) +{ +writel_relaxed (val, timer.base + rg); +} + +/** +* keystone_timer_config: configures timer to work in oneshot/periodic modes. +* @ mode: mode to configure +* @ period: cycles number to configure for +*/ +static int keystone_timer_config (u64 period,enum clock_event_mode mode) +{ +u32 tcr; +u32 off; + + tcr =keystone_timer_readl (TCR ); + off = tcr & ~(TCR_ENAMODE_MASK ); + +/* set enable mode */ +switch (mode) { +case CLOCK_EVT_MODE_ONESHOT : + tcr |=TCR_ENAMODE_ONESHOT_MASK ; +break ; +case CLOCK_EVT_MODE_PERIODIC : + tcr |=TCR_ENAMODE_PERIODIC_MASK ; +break ; +default : +return -1 ; + } + +/* disable timer */ +keystone_timer_writel (off,TCR ); +/* here we have to be sure the timer has been disabled */ +wmb (); +
drivers/clocksource/timer-keystone.c line 102
Quoted 10 lines
drivers/clocksource/timer-keystone.c new file +10
-0+/* reset counter to zero, set new period */ +keystone_timer_writel (0 ,TIM12 ); +keystone_timer_writel (0 ,TIM34 ); +keystone_timer_writel (period &0xffffffff ,PRD12 ); +keystone_timer_writel (period >>32 ,PRD34 ); + +/* enable timer +* here we have to be sure that CNTLO, CNTHI, PRDLO, PRDHI registers +* have been written. +*/
Comment style ?
/*
*
*/
Other than the minor comment. The patch looks fine to me..
PATCH v2 1/3 clocksource: timer-keystone: introduce clocksource driver for Keystone
In reply to Ivan KhoronzhukQuoted 4 lines · Ivan Khoronzhuk
drivers/clocksource/timer-keystone.c new file +4
-0+static void __init keystone_timer_init (struct device_node *np) +{ +struct clock_event_device *event_dev = &timer.event_dev; +unsigned long rate;
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+ + timer.hz_period = rate / (HZ);
Unnecessary parentheses here. Also, do you need to use do_div() here? I'm lost how the hz_period is ever greater than 32 bits though because HZ is most likely very small and the rate is unsigned long.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/3 clocksource: timer-keystone: introduce clocksource driver for Keystone
Quoted 6 lines · Stephen Boyd
Quoted 4 lines · Ivan Khoronzhuk
drivers/clocksource/timer-keystone.c new file +4
-0+static void __init keystone_timer_init (struct device_node *np) +{ +struct clock_event_device *event_dev = &timer.event_dev; +unsigned long rate;[...]
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + timer.hz_period = rate / (HZ);Unnecessary parentheses here. Also, do you need to use
do_div()here? I'm lost how thehz_periodis ever greater than 32 bits though because HZ is most likely very small and the rate is unsigned long.
You are right.
I'll do the following:
timer.hz_period = rate / (HZ) ---> timer.hz_period = rate / HZ
u64 hz_period ---> unsigned long hz_period
Signature · 2 lines
Regards, Ivan Khoronzhuk
PATCH v2 1/3 clocksource: timer-keystone: introduce clocksource driver for Keystone
Quoted 16 lines · ivan.khoronzhuk
Quoted 6 lines · Stephen Boyd
Quoted 4 lines · Ivan Khoronzhuk
drivers/clocksource/timer-keystone.c new file +4
-0+static void __init keystone_timer_init (struct device_node *np) +{ +struct clock_event_device *event_dev = &timer.event_dev; +unsigned long rate;[...]
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + timer.hz_period = rate / (HZ);Unnecessary parentheses here. Also, do you need to use
do_div()here? I'm lost how thehz_periodis ever greater than 32 bits though because HZ is most likely very small and the rate is unsigned long.
Quoted 6 lines
You are right.
I'll do the following:timer.hz_period = rate / (HZ) ---> timer.hz_period = rate / HZ
u64hz_period---> unsigned longhz_period
... maybe it be better to use DIV_ROUND_UP to be sure in no less than HZ period:
timer.hz_period = rate / (HZ) --> timer.hz_period = DIV_ROUND_UP(rate, HZ)
Signature · 2 lines
Regards, Ivan Khoronzhuk
PATCH v2 2/3 clocksource: keystone: add bindings for keystone timer
In reply to Ivan KhoronzhukThis patch provides bindings for the 64-bit timer in the KeyStone architecture devices. The timer can be configured as a general-purpose 64-bit timer, dual general-purpose 32-bit timers. When configured as dual 32-bit timers, each half can operate in conjunction (chain mode) or independently (unchained mode) of each other.
It is global timer is a free running up-counter and can generate interrupt when the counter reaches preset counter values.
Documentation:
http://www.ti.com/lit/ug/sprugv5a/sprugv5a.pdf
--- .../bindings/timer/ti,keystone-timer.txt | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/ti,keystone-timer.txt
Documentation/devicetree/bindings/timer/ti,keystone-timer.txt new file +29 -0
@@ -0,0 +1,29 @@ +* Device tree bindings for Texas instruments Keystone timer + +This document provides bindings for the 64-bit timer in the KeyStone +architecture devices. The timer can be configured as a general-purpose 64-bit +timer, dual general-purpose 32-bit timers. When configured as dual 32-bit +timers, each half can operate in conjunction (chain mode) or independently +(unchained mode) of each other. + +It is global timer is a free running up-counter and can generate interrupt +when the counter reaches preset counter values. + +Documentation: +http://www.ti.com/lit/ug/sprugv5a/sprugv5a.pdf + +Required properties: + +- compatible : should be "ti,keystone-timer". +- reg : specifies base physical address and count of the registers. +- interrupts : interrupt generated by the timer. +- clocks : the clock feeding the timer clock. + +Example: + +timer at 22f0000 { + compatible = "ti,keystone-timer"; + reg = <0x022f0000 0x80>; + interrupts = <GIC_SPI 110 IRQ_TYPE_EDGE_RISING>; + clocks = <&clktimer15>; +};
Signature · 1 line
1.7.9.5
PATCH v2 2/3 clocksource: keystone: add bindings for keystone timer
Quoted 6 lines · Ivan Khoronzhuk
This patch provides bindings for the 64-bit timer in the KeyStone architecture devices. The timer can be configured as a general-purpose 64-bit timer, dual general-purpose 32-bit timers. When configured as dual 32-bit timers, each half can operate in conjunction (chain mode) or independently (unchained mode) of each other.
Quoted 8 lines
It is global timer is a free running up-counter and can generate interrupt when the counter reaches preset counter values.
Documentation:
http://www.ti.com/lit/ug/sprugv5a/sprugv5a.pdfSigned-off-by Ivan Khoronzhuk <[email protected]>---
PATCH v2 3/3 arm: dts: keystone: add keystone timer entry
In reply to Ivan KhoronzhukAdd keystone timer entry to keystone device tree. This 64-bit timer is used as backup clock event device.
--- arch/arm/boot/dts/keystone-clocks.dtsi | 10 ++++++++++ arch/arm/boot/dts/keystone.dtsi | 7 +++++++ 2 files changed, 17 insertions(+)
arch/arm/boot/dts/keystone-clocks.dtsi +10 -0
@@ -737,6 +737,16 @@ clocks { domain-id = <0>; }; + clktimer15: clktimer15 { + #clock-cells = <0>; + compatible = "ti,keystone,psc-clock"; + clocks = <&clkmodrst0>; + clock-output-names = "timer15"; + reg = <0x02350000 0xb00>, <0x02350000 0x400>; + reg-names = "control", "domain"; + domain-id = <0>; + }; + clkuart0: clkuart0 { #clock-cells = <0>; compatible = "ti,keystone,psc-clock";
arch/arm/boot/dts/keystone.dtsi +7 -0
@@ -181,5 +181,12 @@ interrupts = <GIC_SPI 300 IRQ_TYPE_EDGE_RISING>; clocks = <&clkspi>; }; + + clock_event: timer at 22f0000 { + compatible = "ti,keystone-timer"; + reg = <0x022f0000 0x80>; + interrupts = <GIC_SPI 110 IRQ_TYPE_EDGE_RISING>; + clocks = <&clktimer15>; + }; }; };
Signature · 1 line
1.7.9.5
PATCH v2 3/3 arm: dts: keystone: add keystone timer entry
Quoted 5 lines · Ivan Khoronzhuk
Add keystone timer entry to keystone device tree. This 64-bit timer is used as backup clock event device.
Signed-off-by Ivan Khoronzhuk <[email protected]>---
I can pick this up once patch 1 and 2 are picked up. Thanks for the Patches Ivan.
Regards,
Santosh