clocksource: Emma Mobile STI V2 patches
Subsystems (6)
Magnus Damm
maintainercover clocksource: Emma Mobile STI V2 patches
clocksource: Emma Mobile STI V2 patches
[PATCH 01/03] clockevents: Make clockevents_config() a global symbol [PATCH 02/03] clocksource: em_sti: Emma Mobile STI driver V2 [PATCH 03/03] clocksource: em_sti: Add DT support
This is the second version of Emma Mobile STI driver. Now with significantly cleaner clockevent intergration and DT support.
The driver is implemented as a regular platform device which makes use of the STI hardware and provides both clocksource and clockevent interfaces with a single 48-bit hardware counter.
It is worth mentioning that the driver makes use of clockevents_config() to update the timer frequency after registration time. This is done to save power by making sure that unused timer hardware is stopped whenever possible.
The reason behind allowing the driver to use clockevents_config() is in detail as follows. The clock associated with the timer gets enabled when starting the clocksource/clockevent and it gets disabled when the clocksource or clockevent gets stopped. Due to the design of the clock framework the rate of the clock is only known after the clock has been enabled. And to save power the clock is only enabled when it is known that it will be used - and to know that the clocksource/clockevent needs to be registered first. This in turn means that we are unaware of the frequency at registration time. Which leads to that it is not sufficient to use a fixed frequency at registration time but we must instead make sure the frequency is updated after each clk_enable().
Many thanks to Thomas Gleixner for very useful V1 feedback.
---
arch/arm/mach-shmobile/Kconfig | 12 drivers/clocksource/Makefile | 2 drivers/clocksource/em_sti.c | 843 ++++++++++++++++++++++++++++++++++++++++ include/linux/clockchips.h | 1 kernel/time/clockevents.c | 3 5 files changed, 859 insertions(+), 2 deletions(-)
Magnus Damm
maintainerPATCH 1/3 clockevents: Make clockevents_config() a global symbol
From: Magnus Damm <[email protected]>
Make clockevents_config() into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.
---
include/linux/clockchips.h | 1 + kernel/time/clockevents.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/clockchips.h +1 -0
@@ -132,6 +132,7 @@ extern u64 clockevent_delta2ns(unsigned struct clock_event_device *evt);extern void clockevents_register_device (struct clock_event_device *dev); +extern void clockevents_config (struct clock_event_device *dev,u32 freq);extern void clockevents_config_and_register (struct clock_event_device *dev,u32 freq,unsigned long min_delta,unsigned long max_delta);
kernel/time/clockevents.c +1 -2
@@ -297,8 +297,7 @@ void clockevents_register_device(struct }EXPORT_SYMBOL_GPL (clockevents_register_device); -static void clockevents_config (struct clock_event_device *dev, -u32 freq) +void clockevents_config (struct clock_event_device *dev,u32 freq) {u64 sec;
Magnus Damm
maintainerPATCH 2/3 clocksource: em_sti: Emma Mobile STI driver V2
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
This is V2 of the Emma Mobile STI timer driver.
The STI hardware is based on a single 48-bit 32kHz counter that together with two individual compare registers can generate interrupts. There are no timer operating modes selectable which means that the timer can not clear on match.
This driver is providing clocksource support for the 48-bit counter. Clockevents are also supported using the same timer in periodic or oneshot modes.
---
Changes since V1 :
- removed unused early timer cruft
- reduce number of functions
- use request_irq() instead setup_irq() since we run late during boot
- replace confusing flags with perhaps equally confusing active[] array
- use clockevents_config_and_register() for registration
- update frequency with clockevents_config()
- use 2 ticks as minimum
- verify oneshot timer and return error to clock event layer
Verified in the following modes on EMEV2:
- clocksource only
- clockevent in periodic mode only
- clocksource and clockevent in periodic mode
- clocksource and clockevent in oneshot mode
arch/arm/mach-shmobile/Kconfig | 6 drivers/clocksource/Makefile | 1 drivers/clocksource/em_sti.c | 418 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 425 insertions(+)
arch/arm/mach-shmobile/Kconfig +6 -0
@@ -168,6 +168,12 @@ config SH_TIMER_TMU help This enables build of the TMU timer driver. +config EM_TIMER_STI + bool "STI timer driver" + default y + help + This enables build of the STI timer driver. + endmenu config SH_CLK_CPG
drivers/clocksource/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o +obj-$(CONFIG_EM_TIMER_STI) += em_sti.o obj-$(CONFIG_CLKBLD_I8253) += i8253.o obj-$(CONFIG_CLKSRC_MMIO) += mmio.o obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o
drivers/clocksource/em_sti.c new file +418 -0
418 lines not on this page · raw message
Magnus Damm
maintainerPATCH 3/3 clocksource: em_sti: Add DT support
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Update the em-sti driver to support DT.
---
drivers/clocksource/em_sti.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/clocksource/em_sti.c +7 -0
@@ -403,11 +403,18 @@ static int __devexit em_sti_remove(strucreturn -EBUSY ;/* cannot unregister clockevent and clocksource */ } +static const struct of_device_id em_sti_dt_ids[]__devinitconst = { + { .compatible ="renesas,em-sti" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, em_sti_dt_ids); +static struct platform_driver em_sti_device_driver = { .probe = em_sti_probe, .remove =__devexit_p (em_sti_remove), .driver = { .name ="em_sti" , + .of_match_table = em_sti_dt_ids, } };
Quoted 4 lines · Magnus Damm
clocksource: Emma Mobile STI V2 patches
[PATCH 01/03] clockevents: Make
clockevents_config()a global symbol [PATCH 02/03] clocksource:em_sti: Emma Mobile STI driver V2
Patches 1 & 2.
Quoted 1 line
[PATCH 03/03] clocksource:
em_sti: Add DT support
I am unsure how to exercise this code.
Re: [PATCH 01/03] clockevents: Make clockevents_config() a global symbol
In reply to Magnus DammQuoted 8 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Make
clockevents_config()into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.Signed-off-by Magnus Damm <[email protected]>
Any update on this?
Magnus Damm
maintainerRe: [PATCH 01/03] clockevents: Make clockevents_config() a global symbol
Quoted 11 lines · Paul Mundt
Quoted 8 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Make
clockevents_config()into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.Signed-off-by Magnus Damm <[email protected]>Any update on this?
Thanks, not from my side at least. I intend to resend the same series later this week unless it gets picked up before that.
Cheers,
/ magnus
Re: [PATCH 01/03] clockevents: Make clockevents_config() a global symbol
In reply to Paul MundtQuoted 11 lines · Paul Mundt
Quoted 8 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Make
clockevents_config()into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.Signed-off-by Magnus Damm <[email protected]>Any update on this?
Ooops, I missed that. Can you take it through your tree with my acked-by please?
Thanks,
tglx
Re: [PATCH 01/03] clockevents: Make clockevents_config() a global symbol
Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · Paul Mundt
Quoted 7 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Make
clockevents_config()into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Magnus Damm <[email protected]>Any update on this?
Ooops, I missed that. Can you take it through your tree with my acked-by please?
Gah crap. I take the whole lot. Didn't notice that the driver is in drivers/clocksource.
Sorry for the confusion.
Re: [PATCH 02/03] clocksource: em_sti: Emma Mobile STI driver V2
In reply to Magnus Dammdrivers/clocksource/em_sti.c line 164
Quoted 7 lines · Magnus Damm
drivers/clocksource/em_sti.c new file +7
-0+static irqreturn_t em_sti_interrupt (int irq,void *dev_id) +{ +struct em_sti_priv *p = dev_id; + +/* Always regprogram timer compare A */ +if (p->ced.mode =CLOCK_EVT_MODE_PERIODIC ) +em_sti_update (p);
Why do you want to do that? The core code already handles timers which only support oneshot mode.
Review
Quoted 1 line
(quoted diff) +1
-0+ spin_lock_irqsave(&p->lock, flags);
Please make that a raw_spinlock.
Quoted 14 lines
drivers/clocksource/em_sti.c new file +14
-0+static void em_sti_clock_event_mode (enum clock_event_mode mode, +struct clock_event_device *ced) +{ +struct em_sti_priv *p =ced_to_em_sti (ced); + +/* deal with old setting first */ +switch (ced->mode) { +case CLOCK_EVT_MODE_PERIODIC : +case CLOCK_EVT_MODE_ONESHOT : +em_sti_stop (p,USER_CLOCKEVENT ); +break ; +default : +break ; + }
drivers/clocksource/em_sti.c line 284
Quoted 10 lines
drivers/clocksource/em_sti.c new file +10
-0+ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +dev_info (&p->pdev->dev,"used for periodic clock events\n" ); +em_sti_start (p,USER_CLOCKEVENT ); +clockevents_config (&p->ced, p->rate); + p->delta = (p->rate +HZ /2 ) /HZ ; + p->next =em_sti_count (p); +em_sti_update (p); +break ;
All that code in this case can go away.
drivers/clocksource/em_sti.c line 321
Quoted 8 lines
drivers/clocksource/em_sti.c new file +8
-0+static void em_sti_register_clockevent (struct em_sti_priv *p) +{ +struct clock_event_device *ced = &p->ced; + +memset (ced,0 ,sizeof (*ced)); + ced->name =dev_name (&p->pdev->dev); + ced->features =CLOCK_EVT_FEAT_PERIODIC ; + ced->features |=CLOCK_EVT_FEAT_ONESHOT ;
If you make that:
ced->features = CLOCK_EVT_FEAT_ONESHOT;
Thanks,
tglx
tip-bot for Magnus Damm
maintainer[tip:timers/core] clockevents: Make clockevents_config() a global symbol
In reply to Magnus DammCommit-ID: e5400321a6f15ce0fe77c8455954f213ef7dcc54 Gitweb: http://git.kernel.org/tip/e5400321a6f15ce0fe77c8455954f213ef7dcc54 Author: Magnus Damm <[email protected]> AuthorDate: Wed, 9 May 2012 23:39:34 +0900 Committer: Thomas Gleixner <[email protected]> CommitDate: Fri, 25 May 2012 01:44:51 +0200
clockevents: Make clockevents_config() a global symbol
Make clockevents_config() into a global symbol to allow it to be used by compiled-in clockevent drivers. This is needed by drivers that want to update the timer frequency after registration time.
--- include/linux/clockchips.h | 1 + kernel/time/clockevents.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/clockchips.h +1 -0
@@ -132,6 +132,7 @@ extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);extern void clockevents_register_device (struct clock_event_device *dev); +extern void clockevents_config (struct clock_event_device *dev,u32 freq);extern void clockevents_config_and_register (struct clock_event_device *dev,u32 freq,unsigned long min_delta,unsigned long max_delta);
kernel/time/clockevents.c +1 -2
@@ -297,8 +297,7 @@ void clockevents_register_device(struct clock_event_device *dev) }EXPORT_SYMBOL_GPL (clockevents_register_device); -static void clockevents_config (struct clock_event_device *dev, -u32 freq) +void clockevents_config (struct clock_event_device *dev,u32 freq) {u64 sec;
Magnus Damm
maintainerRe: [PATCH 02/03] clocksource: em_sti: Emma Mobile STI driver V2
In reply to Thomas GleixnerHi Thomas,
Quoted 11 lines · Thomas Gleixner
drivers/clocksource/em_sti.c line 164
Quoted 7 lines · Magnus Damm
drivers/clocksource/em_sti.c new file +7
-0+static irqreturn_t em_sti_interrupt (int irq,void *dev_id) +{ + struct em_sti_priv *p = dev_id; + + /* Always regprogram timer compare A */ + if (p->ced.mode = CLOCK_EVT_MODE_PERIODIC) + em_sti_update(p);Why do you want to do that? The core code already handles timers which only support oneshot mode.
Oh, I wasn't aware that oneshot only is a valid combination. Thanks for pointing that out, the code will surely become cleaner!
Quoted 3 lines
Quoted 1 line
+
spin_lock_irqsave(&p->lock, flags);Please make that a
raw_spinlock.
Ok!
Quoted 18 lines
Quoted 18 lines
drivers/clocksource/em_sti.c new file +18
-0+static void em_sti_clock_event_mode (enum clock_event_mode mode, + struct clock_event_device *ced) +{ + struct em_sti_priv *p = ced_to_em_sti(ced); + + /* deal with old setting first */ + switch (ced->mode) { + case CLOCK_EVT_MODE_PERIODIC: + case CLOCK_EVT_MODE_ONESHOT: + em_sti_stop(p, USER_CLOCKEVENT); + break; + default: + break; + } + + switch (mode) { + case CLOCK_EVT_MODE_PERIODIC: + dev_info(&p->pdev->dev, "used for periodic clock events\n");
Quoted 8 lines
Quoted 6 lines
+
em_sti_start(p, USER_CLOCKEVENT);
+clockevents_config(&p->ced, p->rate);
+p->delta= (p->rate+ HZ/2) / HZ;
+p->next=em_sti_count(p);
+em_sti_update(p);
+ break;All that code in this case can go away.
Right!
Quoted 11 lines
drivers/clocksource/em_sti.c line 321
Quoted 8 lines
drivers/clocksource/em_sti.c new file +8
-0+static void em_sti_register_clockevent (struct em_sti_priv *p) +{ + struct clock_event_device *ced = &p->ced; + + memset(ced, 0, sizeof(*ced)); + ced->name = dev_name(&p->pdev->dev); + ced->features = CLOCK_EVT_FEAT_PERIODIC; + ced->features |= CLOCK_EVT_FEAT_ONESHOT;If you make that:
Quoted 1 line
ced->features =
CLOCK_EVT_FEAT_ONESHOT;
Gotcha!
Thanks,
/ magnus
tip-bot for Magnus Damm
maintainer[tip:timers/core] clocksource: em_sti: Add DT support
In reply to Magnus DammCommit-ID: fc0830fe017d02b7b4995b5c402b484b65d9dfc6 Gitweb: http://git.kernel.org/tip/fc0830fe017d02b7b4995b5c402b484b65d9dfc6 Author: Magnus Damm <[email protected]> AuthorDate: Wed, 9 May 2012 23:39:50 +0900 Committer: Thomas Gleixner <[email protected]> CommitDate: Fri, 25 May 2012 11:32:06 +0200
clocksource: em_sti: Add DT support
Update the em-sti driver to support DT.
--- drivers/clocksource/em_sti.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/clocksource/em_sti.c +7 -0
@@ -384,11 +384,18 @@ static int __devexit em_sti_remove(struct platform_device *pdev)return -EBUSY ;/* cannot unregister clockevent and clocksource */ } +static const struct of_device_id em_sti_dt_ids[]__devinitconst = { + { .compatible ="renesas,em-sti" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, em_sti_dt_ids); +static struct platform_driver em_sti_device_driver = { .probe = em_sti_probe, .remove =__devexit_p (em_sti_remove), .driver = { .name ="em_sti" , + .of_match_table = em_sti_dt_ids, } };