From: Alexander Kochetkov <al.kochet@gmail.com> To: daniel.lezcano@linaro.org, tglx@linutronix.de, heiko@sntech.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Cc: Alexander Kochetkov <al.kochet@gmail.com> Subject: [PATCH 7/9] clocksource/drivers/rockchip_timer: implement clocksource timer Date: Wed, 23 Nov 2016 20:29:35 +0300 [thread overview] Message-ID: <1479922177-20136-7-git-send-email-al.kochet@gmail.com> (raw) In-Reply-To: <1479922177-20136-1-git-send-email-al.kochet@gmail.com> The patch implement stable clocksource for rk3188. It register one of the timers as clocksource and sched_clock. Also it override arm_global_timer clocksource using rating property (350). arm_global_timer enabled on rk3188 provide unstable clocksource. It's rate depend on ARM CPU rate. As result the command 'sleep 60' could run either ~60s (with CPU freq 312 MHZ) or ~45s (with CPU freq 1.6GHz). In order to use the patch you have to setup the timer using 'rockchip,clocksource' device tree property. timer6 was used as clocksource in kernel 3.0 from rockchip SDK. cpufreq-set -f 1.6GHZ date; sleep 60; date Signed-off-by: Alexander Kochetkov <al.kochet@gmail.com> --- drivers/clocksource/rockchip_timer.c | 79 +++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c index 61787c5..77bea97 100644 --- a/drivers/clocksource/rockchip_timer.c +++ b/drivers/clocksource/rockchip_timer.c @@ -11,6 +11,7 @@ #include <linux/clockchips.h> #include <linux/init.h> #include <linux/interrupt.h> +#include <linux/sched_clock.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> @@ -42,7 +43,13 @@ struct rk_clock_event_device { struct rk_timer timer; }; +struct rk_clocksource { + struct clocksource cs; + struct rk_timer timer; +}; + static struct rk_clock_event_device bc_timer; +static struct rk_clocksource cs_timer; static inline struct rk_clock_event_device* rk_clock_event_device(struct clock_event_device *ce) @@ -139,14 +146,35 @@ static irqreturn_t rk_timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +static cycle_t rk_timer_clocksource_read(struct clocksource *cs) +{ + struct rk_clocksource *_cs = container_of(cs, struct rk_clocksource, cs); + return ~rk_timer_counter_read(&_cs->timer); +} + +static u64 notrace rk_timer_sched_clock_read(void) +{ + struct rk_clocksource *_cs = &cs_timer; + return ~rk_timer_counter_read(&_cs->timer); +} + static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg) { - struct clock_event_device *ce = &bc_timer.ce; - struct rk_timer *timer = &bc_timer.timer; + struct clock_event_device *ce = NULL; + struct clocksource *cs = NULL; + struct rk_timer *timer = NULL; struct clk *timer_clk; struct clk *pclk; int ret = -EINVAL, irq; + if (of_property_read_bool(np, "rockchip,clocksource")) { + cs = &cs_timer.cs; + timer = &cs_timer.timer; + } else { + ce = &bc_timer.ce; + timer = &bc_timer.timer; + } + timer->base = of_iomap(np, 0); if (!timer->base) { pr_err("Failed to get base address for '%s'\n", TIMER_NAME); @@ -189,26 +217,45 @@ static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg) goto out_irq; } - ce->name = TIMER_NAME; - ce->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | - CLOCK_EVT_FEAT_DYNIRQ; - ce->set_next_event = rk_timer_set_next_event; - ce->set_state_shutdown = rk_timer_shutdown; - ce->set_state_periodic = rk_timer_set_periodic; - ce->irq = irq; - ce->cpumask = cpu_possible_mask; - ce->rating = 250; + if (ce) { + ce->name = TIMER_NAME; + ce->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | + CLOCK_EVT_FEAT_DYNIRQ; + ce->set_next_event = rk_timer_set_next_event; + ce->set_state_shutdown = rk_timer_shutdown; + ce->set_state_periodic = rk_timer_set_periodic; + ce->irq = irq; + ce->cpumask = cpu_possible_mask; + ce->rating = 250; + } + + if (cs) { + cs->name = TIMER_NAME; + cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; + cs->mask = CLOCKSOURCE_MASK(64); + cs->read = rk_timer_clocksource_read; + cs->rating = 350; + } rk_timer_interrupt_clear(timer); rk_timer_disable(timer); - ret = request_irq(irq, rk_timer_interrupt, IRQF_TIMER, TIMER_NAME, ce); - if (ret) { - pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); - goto out_irq; + if (ce) { + ret = request_irq(irq, rk_timer_interrupt, IRQF_TIMER, TIMER_NAME, ce); + if (ret) { + pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); + goto out_irq; + } + + clockevents_config_and_register(ce, timer->freq, 1, UINT_MAX); } - clockevents_config_and_register(ce, timer->freq, 1, UINT_MAX); + if (cs) { + rk_timer_update_counter(U64_MAX, timer); + rk_timer_enable(timer, 0); + clocksource_register_hz(cs, timer->freq); + sched_clock_register(rk_timer_sched_clock_read, 64, timer->freq); + } return 0; -- 1.7.9.5
WARNING: multiple messages have this Message-ID (diff)
From: al.kochet@gmail.com (Alexander Kochetkov) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 7/9] clocksource/drivers/rockchip_timer: implement clocksource timer Date: Wed, 23 Nov 2016 20:29:35 +0300 [thread overview] Message-ID: <1479922177-20136-7-git-send-email-al.kochet@gmail.com> (raw) In-Reply-To: <1479922177-20136-1-git-send-email-al.kochet@gmail.com> The patch implement stable clocksource for rk3188. It register one of the timers as clocksource and sched_clock. Also it override arm_global_timer clocksource using rating property (350). arm_global_timer enabled on rk3188 provide unstable clocksource. It's rate depend on ARM CPU rate. As result the command 'sleep 60' could run either ~60s (with CPU freq 312 MHZ) or ~45s (with CPU freq 1.6GHz). In order to use the patch you have to setup the timer using 'rockchip,clocksource' device tree property. timer6 was used as clocksource in kernel 3.0 from rockchip SDK. cpufreq-set -f 1.6GHZ date; sleep 60; date Signed-off-by: Alexander Kochetkov <al.kochet@gmail.com> --- drivers/clocksource/rockchip_timer.c | 79 +++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c index 61787c5..77bea97 100644 --- a/drivers/clocksource/rockchip_timer.c +++ b/drivers/clocksource/rockchip_timer.c @@ -11,6 +11,7 @@ #include <linux/clockchips.h> #include <linux/init.h> #include <linux/interrupt.h> +#include <linux/sched_clock.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> @@ -42,7 +43,13 @@ struct rk_clock_event_device { struct rk_timer timer; }; +struct rk_clocksource { + struct clocksource cs; + struct rk_timer timer; +}; + static struct rk_clock_event_device bc_timer; +static struct rk_clocksource cs_timer; static inline struct rk_clock_event_device* rk_clock_event_device(struct clock_event_device *ce) @@ -139,14 +146,35 @@ static irqreturn_t rk_timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +static cycle_t rk_timer_clocksource_read(struct clocksource *cs) +{ + struct rk_clocksource *_cs = container_of(cs, struct rk_clocksource, cs); + return ~rk_timer_counter_read(&_cs->timer); +} + +static u64 notrace rk_timer_sched_clock_read(void) +{ + struct rk_clocksource *_cs = &cs_timer; + return ~rk_timer_counter_read(&_cs->timer); +} + static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg) { - struct clock_event_device *ce = &bc_timer.ce; - struct rk_timer *timer = &bc_timer.timer; + struct clock_event_device *ce = NULL; + struct clocksource *cs = NULL; + struct rk_timer *timer = NULL; struct clk *timer_clk; struct clk *pclk; int ret = -EINVAL, irq; + if (of_property_read_bool(np, "rockchip,clocksource")) { + cs = &cs_timer.cs; + timer = &cs_timer.timer; + } else { + ce = &bc_timer.ce; + timer = &bc_timer.timer; + } + timer->base = of_iomap(np, 0); if (!timer->base) { pr_err("Failed to get base address for '%s'\n", TIMER_NAME); @@ -189,26 +217,45 @@ static int __init rk_timer_init(struct device_node *np, u32 ctrl_reg) goto out_irq; } - ce->name = TIMER_NAME; - ce->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | - CLOCK_EVT_FEAT_DYNIRQ; - ce->set_next_event = rk_timer_set_next_event; - ce->set_state_shutdown = rk_timer_shutdown; - ce->set_state_periodic = rk_timer_set_periodic; - ce->irq = irq; - ce->cpumask = cpu_possible_mask; - ce->rating = 250; + if (ce) { + ce->name = TIMER_NAME; + ce->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | + CLOCK_EVT_FEAT_DYNIRQ; + ce->set_next_event = rk_timer_set_next_event; + ce->set_state_shutdown = rk_timer_shutdown; + ce->set_state_periodic = rk_timer_set_periodic; + ce->irq = irq; + ce->cpumask = cpu_possible_mask; + ce->rating = 250; + } + + if (cs) { + cs->name = TIMER_NAME; + cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; + cs->mask = CLOCKSOURCE_MASK(64); + cs->read = rk_timer_clocksource_read; + cs->rating = 350; + } rk_timer_interrupt_clear(timer); rk_timer_disable(timer); - ret = request_irq(irq, rk_timer_interrupt, IRQF_TIMER, TIMER_NAME, ce); - if (ret) { - pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); - goto out_irq; + if (ce) { + ret = request_irq(irq, rk_timer_interrupt, IRQF_TIMER, TIMER_NAME, ce); + if (ret) { + pr_err("Failed to initialize '%s': %d\n", TIMER_NAME, ret); + goto out_irq; + } + + clockevents_config_and_register(ce, timer->freq, 1, UINT_MAX); } - clockevents_config_and_register(ce, timer->freq, 1, UINT_MAX); + if (cs) { + rk_timer_update_counter(U64_MAX, timer); + rk_timer_enable(timer, 0); + clocksource_register_hz(cs, timer->freq); + sched_clock_register(rk_timer_sched_clock_read, 64, timer->freq); + } return 0; -- 1.7.9.5
next prev parent reply other threads:[~2016-11-23 17:30 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-11-23 17:29 [PATCH 1/9] clocksource/drivers/rockchip_timer: split bc_timer into rk_timer and rk_clock_event_device Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 2/9] clocksource/drivers/rockchip_timer: low level routines take rk_timer as parameter Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 3/9] clocksource/drivers/rockchip_timer: drop unused rk_base() and rk_ctrl() Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 4/9] clocksource/drivers/rockchip_timer: move TIMER_INT_UNMASK out of rk_timer_enable() Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 5/9] clocksource/drivers/rockchip_timer: implement loading 64bit value into timer Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 6/9] clocksource/drivers/rockchip_timer: implement reading 64bit value from timer Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov [this message] 2016-11-23 17:29 ` [PATCH 7/9] clocksource/drivers/rockchip_timer: implement clocksource timer Alexander Kochetkov 2016-11-24 9:36 ` Alexander Kochetkov 2016-11-24 9:36 ` Alexander Kochetkov 2016-11-24 9:36 ` Alexander Kochetkov 2016-11-24 12:17 ` Heiko Stübner 2016-11-24 12:17 ` Heiko Stübner 2016-11-24 12:17 ` Heiko Stübner 2016-11-24 13:05 ` Alexander Kochetkov 2016-11-24 13:05 ` Alexander Kochetkov 2016-11-24 13:21 ` Heiko Stübner 2016-11-24 13:21 ` Heiko Stübner 2016-11-24 14:14 ` Alexander Kochetkov 2016-11-24 14:14 ` Alexander Kochetkov 2016-11-24 14:32 ` Heiko Stübner 2016-11-24 14:32 ` Heiko Stübner 2016-11-25 9:17 ` Alexander Kochetkov 2016-11-25 9:17 ` Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 8/9] dt-bindings: add rockchip,clocksource property to rk-timer Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 8/9] dt-bindings: add rockchip, clocksource " Alexander Kochetkov 2016-11-23 17:29 ` [PATCH 9/9] ARM: dts: rockchip: add timer entries to rk3188.dtsi Alexander Kochetkov 2016-11-23 17:29 ` Alexander Kochetkov 2016-11-24 12:01 ` [PATCH 1/9] clocksource/drivers/rockchip_timer: split bc_timer into rk_timer and rk_clock_event_device Heiko Stübner 2016-11-24 12:01 ` Heiko Stübner 2016-11-24 12:12 ` Alexander Kochetkov 2016-11-24 12:12 ` Alexander Kochetkov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1479922177-20136-7-git-send-email-al.kochet@gmail.com \ --to=al.kochet@gmail.com \ --cc=daniel.lezcano@linaro.org \ --cc=heiko@sntech.de \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=tglx@linutronix.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.