Re: [PATCH] Add generic clock events support for w90p910 timer

From: Wan ZongShun
Date: Fri Aug 07 2009 - 06:48:24 EST


Dear Russell,

When involving the clocksource function by means of timer1, I find my
system running seems to be slow,
and the printed console information shown slowly too.

Regarding timer1 setting, I only set the counter enable bit, periodic
mode bit and fill in the timer initial count register, which is a
24bit register, I think it can work ok.

Any else setting missed regarding linux api of clocksource ?

2009/8/5 Wan ZongShun <mcuos.com@xxxxxxxxx>:
> Dear sirs,
>
> I fixed this patch according to Russell's advice, and added
> time1 for clocksource.
>
> Either setting 'LOCK_EVT_MODE_PERIODIC' or setting 'CLOCK_EVT_FEAT_ONESHOT' can
> run in my w90p910 evaluation board. but, if I set 'future' to following:
>
> ".features   Â= CLOCK_EVT_MODE_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,"
>
> If so, the timer works on the periodic mode.
>
>
> Signed-off-by: Wan ZongShun <mcuos.com@xxxxxxxxx>
>
> ---
> Âarch/arm/Kconfig        Â|  Â2 +
> Âarch/arm/mach-w90x900/clock.c  |  Â6 ++
> Âarch/arm/mach-w90x900/time.c  Â| Â151 ++++++++++++++++++++++++++++++++------
> Âarch/arm/mach-w90x900/w90p910.c | Â Â2 +
> Â4 files changed, 137 insertions(+), 24 deletions(-)
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index c3fed1e..8c4f03d 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -495,6 +495,8 @@ config ARCH_W90X900
> Â Â Â Âselect GENERIC_GPIO
> Â Â Â Âselect HAVE_CLK
> Â Â Â Âselect COMMON_CLKDEV
> + Â Â Â select GENERIC_TIME
> + Â Â Â select GENERIC_CLOCKEVENTS
> Â Â Â Âhelp
> Â Â Â Â Â Â Â ÂSupport for Nuvoton (Winbond logic dept.) ARM9 processor,You
> Â Â Â Â Â Â Â Âcan login www.mcuos.com or www.nuvoton.com to know more.
> diff --git a/arch/arm/mach-w90x900/clock.c b/arch/arm/mach-w90x900/clock.c
> index 49cf1fb..70b6710 100644
> --- a/arch/arm/mach-w90x900/clock.c
> +++ b/arch/arm/mach-w90x900/clock.c
> @@ -55,6 +55,12 @@ void clk_disable(struct clk *clk)
> Â}
> ÂEXPORT_SYMBOL(clk_disable);
>
> +unsigned long clk_get_rate(struct clk *clk)
> +{
> + Â Â Â return 15000000;
> +}
> +EXPORT_SYMBOL(clk_get_rate);
> +
> Âvoid w90x900_clk_enable(struct clk *clk, int enable)
> Â{
> Â Â Â Âunsigned int clocks = clk->cken;
> diff --git a/arch/arm/mach-w90x900/time.c b/arch/arm/mach-w90x900/time.c
> index bcc838f..5e06770 100644
> --- a/arch/arm/mach-w90x900/time.c
> +++ b/arch/arm/mach-w90x900/time.c
> @@ -3,7 +3,7 @@
> Â*
> Â* Based on linux/arch/arm/plat-s3c24xx/time.c by Ben Dooks
> Â*
> - * Copyright (c) 2008 Nuvoton technology corporation
> + * Copyright (c) 2009 Nuvoton technology corporation
> Â* All rights reserved.
> Â*
> Â* Wan ZongShun <mcuos.com@xxxxxxxxx>
> @@ -23,6 +23,8 @@
> Â#include <linux/clk.h>
> Â#include <linux/io.h>
> Â#include <linux/leds.h>
> +#include <linux/clocksource.h>
> +#include <linux/clockchips.h>
>
> Â#include <asm/mach-types.h>
> Â#include <asm/mach/irq.h>
> @@ -31,49 +33,150 @@
> Â#include <mach/map.h>
> Â#include <mach/regs-timer.h>
>
> -static unsigned long w90x900_gettimeoffset(void)
> +#define RESETINT Â Â Â 0x1f
> +#define PERIOD Â Â Â Â (0x01 << 27)
> +#define ONESHOT Â Â Â Â Â Â Â Â(0x00 << 27)
> +#define COUNTEN Â Â Â Â Â Â Â Â(0x01 << 30)
> +#define INTEN Â Â Â Â Â(0x01 << 29)
> +
> +#define TICKS_PER_SEC Â100
> +#define PRESCALE Â Â Â 0x63 /* Divider = prescale + 1 */
> +
> +unsigned int timer0_load;
> +
> +static void w90p910_clockevent_setmode(enum clock_event_mode mode,
> + Â Â Â Â Â Â Â struct clock_event_device *clk)
> Â{
> + Â Â Â unsigned int val;
> +
> + Â Â Â val = __raw_readl(REG_TCSR0);
> + Â Â Â val &= ~(0x03 << 27);
> +
> + Â Â Â switch (mode) {
> + Â Â Â case CLOCK_EVT_MODE_PERIODIC:
> + Â Â Â Â Â Â Â __raw_writel(timer0_load, REG_TICR0);
> + Â Â Â Â Â Â Â val |= (PERIOD | COUNTEN | INTEN | PRESCALE);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case CLOCK_EVT_MODE_ONESHOT:
> + Â Â Â Â Â Â Â val |= (ONESHOT | COUNTEN | INTEN | PRESCALE);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case CLOCK_EVT_MODE_UNUSED:
> + Â Â Â case CLOCK_EVT_MODE_SHUTDOWN:
> + Â Â Â case CLOCK_EVT_MODE_RESUME:
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â __raw_writel(val, REG_TCSR0);
> +}
> +
> +static int w90p910_clockevent_setnextevent(unsigned long evt,
> + Â Â Â Â Â Â Â struct clock_event_device *clk)
> +{
> + Â Â Â unsigned int val;
> +
> + Â Â Â __raw_writel(evt, REG_TICR0);
> +
> + Â Â Â val = __raw_readl(REG_TCSR0);
> + Â Â Â val |= (COUNTEN | INTEN | PRESCALE);
> + Â Â Â __raw_writel(val, REG_TCSR0);
> +
> Â Â Â Âreturn 0;
> Â}
>
> +static struct clock_event_device w90p910_clockevent_device = {
> +    .name      = "w90p910-timer0",
> +    .shift     Â= 32,
> +    .features    = CLOCK_EVT_MODE_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
> +    .set_mode    = w90p910_clockevent_setmode,
> + Â Â Â .set_next_event = w90p910_clockevent_setnextevent,
> +    .rating     = 300,
> +};
> +
> Â/*IRQ handler for the timer*/
>
> -static irqreturn_t
> -w90x900_timer_interrupt(int irq, void *dev_id)
> +static irqreturn_t w90p910_timer0_interrupt(int irq, void *dev_id)
> Â{
> - Â Â Â timer_tick();
> + Â Â Â struct clock_event_device *evt = &w90p910_clockevent_device;
> +
> Â Â Â Â__raw_writel(0x01, REG_TISR); /* clear TIF0 */
> +
> + Â Â Â evt->event_handler(evt);
> Â Â Â Âreturn IRQ_HANDLED;
> Â}
>
> -static struct irqaction w90x900_timer_irq = {
> -    .name      = "w90x900 Timer Tick",
> +static struct irqaction w90p910_timer0_irq = {
> +    .name      = "w90p910-timer0",
>    Â.flags     Â= IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
> -    .handler    Â= w90x900_timer_interrupt,
> +    .handler    Â= w90p910_timer0_interrupt,
> Â};
>
> -/*Set up timer reg.*/
> +static void __init w90p910_clockevents_init(unsigned int rate)
> +{
> + Â Â Â w90p910_clockevent_device.mult = div_sc(rate, NSEC_PER_SEC,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â w90p910_clockevent_device.shift);
> + Â Â Â w90p910_clockevent_device.max_delta_ns = clockevent_delta2ns(0xffffffff,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &w90p910_clockevent_device);
> + Â Â Â w90p910_clockevent_device.min_delta_ns = clockevent_delta2ns(0xf,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &w90p910_clockevent_device);
> + Â Â Â w90p910_clockevent_device.cpumask = cpumask_of(0);
>
> -static void w90x900_timer_setup(void)
> + Â Â Â clockevents_register_device(&w90p910_clockevent_device);
> +}
> +
> +static cycle_t w90p910_get_cycles(struct clocksource *cs)
> Â{
> - Â Â Â __raw_writel(0, REG_TCSR0);
> - Â Â Â __raw_writel(0, REG_TCSR1);
> - Â Â Â __raw_writel(0, REG_TCSR2);
> - Â Â Â __raw_writel(0, REG_TCSR3);
> - Â Â Â __raw_writel(0, REG_TCSR4);
> - Â Â Â __raw_writel(0x1F, REG_TISR);
> - Â Â Â __raw_writel(15000000/(100 * 100), REG_TICR0);
> - Â Â Â __raw_writel(0x68000063, REG_TCSR0);
> + Â Â Â return ~__raw_readl(REG_TDR1);
> Â}
>
> -static void __init w90x900_timer_init(void)
> +static struct clocksource clocksource_w90p910 = {
> +    .name  = "w90p910-timer1",
> + Â Â Â .rating = 200,
> +    .read  = w90p910_get_cycles,
> +    .mask  = CLOCKSOURCE_MASK(32),
> + Â Â Â .shift Â= 20,
> + Â Â Â .flags Â= CLOCK_SOURCE_IS_CONTINUOUS,
> +};
> +
> +static void __init w90p910_clocksource_init(unsigned int rate)
> Â{
> - Â Â Â w90x900_timer_setup();
> - Â Â Â setup_irq(IRQ_TIMER0, &w90x900_timer_irq);
> + Â Â Â unsigned int val;
> +
> + Â Â Â __raw_writel(0xffffffff, REG_TICR1);
> +
> + Â Â Â val = __raw_readl(REG_TCSR1);
> + Â Â Â val |= (COUNTEN | PERIOD);
> + Â Â Â __raw_writel(val, REG_TCSR1);
> +
> + Â Â Â clocksource_w90p910.mult =
> + Â Â Â Â Â Â Â clocksource_khz2mult((rate / 1000), clocksource_w90p910.shift);
> + Â Â Â clocksource_register(&clocksource_w90p910);
> +}
> +
> +static void __init w90p910_timer_init(void)
> +{
> + Â Â Â struct clk *ck_ext = clk_get(NULL, "ext");
> +    unsigned int  Ârate;
> +
> + Â Â Â BUG_ON(IS_ERR(ck_ext));
> +
> + Â Â Â rate = clk_get_rate(ck_ext);
> + Â Â Â clk_put(ck_ext);
> + Â Â Â rate = rate / (PRESCALE + 0x01);
> +
> + Â Â Â Â/* set a known state */
> + Â Â Â __raw_writel(0x00, REG_TCSR0);
> + Â Â Â __raw_writel(0x00, REG_TCSR1);
> + Â Â Â __raw_writel(RESETINT, REG_TISR);
> + Â Â Â timer0_load = (rate / TICKS_PER_SEC);
> +
> + Â Â Â setup_irq(IRQ_TIMER0, &w90p910_timer0_irq);
> +
> + Â Â Â w90p910_clocksource_init(rate);
> + Â Â Â w90p910_clockevents_init(rate);
> Â}
>
> Âstruct sys_timer w90x900_timer = {
> -    .init      = w90x900_timer_init,
> -    .offset     = w90x900_gettimeoffset,
> -    .resume     = w90x900_timer_setup
> +    .init      = w90p910_timer_init,
> Â};
> diff --git a/arch/arm/mach-w90x900/w90p910.c b/arch/arm/mach-w90x900/w90p910.c
> index 8444eab..d33723b 100644
> --- a/arch/arm/mach-w90x900/w90p910.c
> +++ b/arch/arm/mach-w90x900/w90p910.c
> @@ -76,6 +76,7 @@ static DEFINE_CLK(wdt, 26);
> Âstatic DEFINE_CLK(gdma, 27);
> Âstatic DEFINE_CLK(adc, 28);
> Âstatic DEFINE_CLK(usi, 29);
> +static DEFINE_CLK(ext, 0);
>
> Âstatic struct clk_lookup w90p910_clkregs[] = {
> Â Â Â ÂDEF_CLKLOOK(&clk_lcd, "w90p910-lcd", NULL),
> @@ -97,6 +98,7 @@ static struct clk_lookup w90p910_clkregs[] = {
> Â Â Â ÂDEF_CLKLOOK(&clk_gdma, "w90p910-gdma", NULL),
> Â Â Â ÂDEF_CLKLOOK(&clk_adc, "w90p910-adc", NULL),
> Â Â Â ÂDEF_CLKLOOK(&clk_usi, "w90p910-spi", NULL),
> + Â Â Â DEF_CLKLOOK(&clk_ext, NULL, "ext"),
> Â};
>
> Â/* Initial serial platform data */
> --
> 1.5.6.3
>



--
Wan z.s
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/