clocksource: davinci-timer: new driver
v3 cover clocksource: davinci-timer: new driver
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
v1 -> v2:
- changed the format of the copyright notice
- removed all mentiones of the periodic timer setting
- added caching of the TCR register value so that its updating doesn't require a read
- split the timer configuration for clock events into the set_state_oneshot() and set_state_shutdown() callbacks
v2 -> v3:
- tim34, if used, should run in periodic mode for clocksource, now fixed
- dropped all the configuration variables from struct davinci_clockevent as clockevent always uses tim12
- dropped caching of the TCR register with the following reasoning: on systems using tim34 for clocksource, the TCR register is only touched by the clock driver and we know that we need to keep tim34 in periodic mode; on da830 the RTOS running on the DSP may modify the TCR register but we on the other hand never change its settings when only using tim12
- subsequently the whole routine for TCR updating was dropped
- dropped the shift variable from most places
- added separate routines for initializing clocksource for da830 and all other systems
- sprinkled a bunch of comments all over the driver to explain things that caused confusion before
Bartosz Golaszewski (2):
clocksource: davinci-timer: add support for clockevents
clocksource: timer-davinci: add support for clocksource
drivers/clocksource/Kconfig | 5 + drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-davinci.c | 370 ++++++++++++++++++++++++++++ include/clocksource/timer-davinci.h | 44 ++++ 4 files changed, 420 insertions(+) create mode 100644 drivers/clocksource/timer-davinci.c create mode 100644 include/clocksource/timer-davinci.h
Signature · 1 line
2.21.0
RFC v3 1/2 clocksource: davinci-timer: add support for clockevents
From: Bartosz Golaszewski <[email protected]>
Currently the clocksource and clockevent support for davinci platforms lives in mach-davinci. It hard-codes many things, uses global variables, implements functionalities unused by any platform and has code fragments scattered across many (often unrelated) files.
Implement a new, modern and simplified timer driver and put it into drivers/clocksource. We still need to support legacy board files so export a config structure and a function that allows machine code to register the timer.
The timer we're using is 64-bit but can be programmed in dual 32-bit mode (both chained and unchained).
On all davinci SoCs except for da830 we're using both halves. Lower half for clockevents and upper half for clocksource. On da830 we're using the lower half for both with the help of a compare register.
This patch contains the core code and support for clockevent. The clocksource code will be included in a subsequent patch.
--- drivers/clocksource/Kconfig | 5 + drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-davinci.c | 285 ++++++++++++++++++++++++++++ include/clocksource/timer-davinci.h | 44 +++++ 4 files changed, 335 insertions(+) create mode 100644 drivers/clocksource/timer-davinci.c create mode 100644 include/clocksource/timer-davinci.h
drivers/clocksource/Kconfig +5 -0
@@ -43,6 +43,11 @@ config BCM_KONA_TIMER help Enables the support for the BCM Kona mobile timer driver. +config DAVINCI_TIMER + bool "Texas Instruments DaVinci timer driver" if COMPILE_TEST + help + Enables the support for the TI DaVinci timer driver. + config DIGICOLOR_TIMER bool "Digicolor timer driver" if COMPILE_TEST select CLKSRC_MMIO
drivers/clocksource/Makefile +1 -0
@@ -15,6 +15,7 @@ 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_DAVINCI_TIMER) += timer-davinci.o obj-$(CONFIG_DIGICOLOR_TIMER) += timer-digicolor.o obj-$(CONFIG_OMAP_DM_TIMER) += timer-ti-dm.o obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o
drivers/clocksource/timer-davinci.c new file +285 -0
285 lines not on this page · raw message
include/clocksource/timer-davinci.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.21.0
RFC v3 2/2 clocksource: timer-davinci: add support for clocksource
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Extend the davinci-timer driver to also register a clock source.
--- drivers/clocksource/timer-davinci.c | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/clocksource/timer-davinci.c +85 -0
@@ -43,6 +43,8 @@#define DAVINCI_TIMER_MIN_DELTA 0x01#define DAVINCI_TIMER_MAX_DELTA 0xfffffffe +#define DAVINCI_TIMER_CLKSRC_BITS 32 +#define DAVINCI_TIMER_TGCR_DEFAULT \ (DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED | DAVINCI_TIMER_UNRESET)
@@ -52,6 +54,16 @@ struct davinci_clockevent {unsigned int cmp_off; }; +/* +* This must be globally accessible by davinci_timer_read_sched_clock(), so +* let's keep it here. +*/ +static struct { +struct clocksource dev; +void __iomem *base; +unsigned int tim_off; +} davinci_clocksource; +static struct davinci_clockevent *to_davinci_clockevent (struct clock_event_device *clockevent) {
@@ -166,6 +178,53 @@ static irqreturn_t davinci_timer_irq_timer(int irq, void *data)return IRQ_HANDLED ; } +static u64 notrace davinci_timer_read_sched_clock(void) +{ +return readl_relaxed (davinci_clocksource.base + + davinci_clocksource.tim_off); +} + +static u64 davinci_clocksource_read (struct clocksource *dev) +{ +return davinci_timer_read_sched_clock (); +} + +/* +* Standard use-case: we're using tim12 for clockevent and tim34 for +* clocksource. The default is making the former run in oneshot mode +* and the latter in periodic mode. +*/ +static void davinci_clocksource_init_tim34 (void __iomem *base) +{ +int tcr; + + tcr =DAVINCI_TIMER_ENAMODE_PERIODIC << +DAVINCI_TIMER_ENAMODE_SHIFT_TIM34 ; + tcr |=DAVINCI_TIMER_ENAMODE_ONESHOT << +DAVINCI_TIMER_ENAMODE_SHIFT_TIM12 ; + +writel_relaxed (0x0 , base +DAVINCI_TIMER_REG_TIM34 ); +writel_relaxed (UINT_MAX , base +DAVINCI_TIMER_REG_PRD34 ); +writel_relaxed (tcr, base +DAVINCI_TIMER_REG_TCR ); +} + +/* +* Special use-case on da830: the DSP may use tim34. We're using tim12 for +* both clocksource and clockevent. We set tim12 to periodic and don't touch +* tim34. +*/ +static void davinci_clocksource_init_tim12 (void __iomem *base) +{ +unsigned int tcr; + + tcr =DAVINCI_TIMER_ENAMODE_PERIODIC << +DAVINCI_TIMER_ENAMODE_SHIFT_TIM12 ; + +writel_relaxed (0x0 , base +DAVINCI_TIMER_REG_TIM12 ); +writel_relaxed (UINT_MAX , base +DAVINCI_TIMER_REG_PRD12 ); +writel_relaxed (tcr, base +DAVINCI_TIMER_REG_TCR ); +} +static void davinci_timer_init (void __iomem *base) {/* Set clock to internal mode and disable it. */
@@ -248,6 +307,32 @@ int __init davinci_timer_register(struct clk *clk,DAVINCI_TIMER_MIN_DELTA , DAVINCI_TIMER_MAX_DELTA); + davinci_clocksource.dev.rating =300 ; + davinci_clocksource.dev.read = davinci_clocksource_read; + davinci_clocksource.dev.mask = +CLOCKSOURCE_MASK (DAVINCI_TIMER_CLKSRC_BITS ); + davinci_clocksource.dev.flags =CLOCK_SOURCE_IS_CONTINUOUS ; + davinci_clocksource.base = base; + +if (timer_cfg->cmp_off) { + davinci_clocksource.dev.name ="tim12" ; + davinci_clocksource.tim_off =DAVINCI_TIMER_REG_TIM12 ; +davinci_clocksource_init_tim12 (base); + }else { + davinci_clocksource.dev.name ="tim34" ; + davinci_clocksource.tim_off =DAVINCI_TIMER_REG_TIM34 ; +davinci_clocksource_init_tim34 (base); + } + + rv =clocksource_register_hz (&davinci_clocksource.dev, tick_rate); +if (rv) { +pr_err ("Unable to register clocksource" ); +return rv; + } + +sched_clock_register (davinci_timer_read_sched_clock, +DAVINCI_TIMER_CLKSRC_BITS , tick_rate); +return 0 ; }
Signature · 1 line
2.21.0
Hi Daniel,
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
Does this look good to you now? If yes, can you please merge and provide an immutable branch to me so I can merge dependent mach-davinci patches?
Thanks,
Sekhar
Quoted 10 lines · Sekhar Nori
Hi Daniel,
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
Does this look good to you now? If yes, can you please merge and provide an immutable branch to me so I can merge dependent mach-davinci patches?
Yes, I think it is fine.
http://[email protected]/people/daniel.lezcano/linux.git
timers/drivers/davinci
It is v5.2-rc4 + (2 x patches)
It is merged in clockevents/next which is exported to linux-next and for kernel-ci.
AFAIU, the patch was compiled and tested. If not, please let me know.
Please, wait a couple of days I confirm the tests passed and you can consider the branch immutable.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 19 lines · Daniel Lezcano
Quoted 10 lines · Sekhar Nori
Hi Daniel,
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
Does this look good to you now? If yes, can you please merge and provide an immutable branch to me so I can merge dependent mach-davinci patches?
Yes, I think it is fine.
http://[email protected]/people/daniel.lezcano/linux.git
timers/drivers/davinciIt is v5.2-rc4 + (2 x patches)
Quoted 7 lines
It is merged in clockevents/next which is exported to linux-next and for kernel-ci.
AFAIU, the patch was compiled and tested. If not, please let me know.
Please, wait a couple of days I confirm the tests passed and you can consider the branch immutable.
lkp complained, please do not use the branch.
I'm waiting for Bartosz to fix the issue.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 23 lines · Daniel Lezcano
Quoted 22 lines · Daniel Lezcano
Quoted 10 lines · Sekhar Nori
Hi Daniel,
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
Does this look good to you now? If yes, can you please merge and provide an immutable branch to me so I can merge dependent mach-davinci patches?
Yes, I think it is fine.
http://[email protected]/people/daniel.lezcano/linux.git
timers/drivers/davinciIt is v5.2-rc4 + (2 x patches)
It is merged in clockevents/next which is exported to linux-next and for kernel-ci.
Quoted 8 lines
Quoted 4 lines
AFAIU, the patch was compiled and tested. If not, please let me know.
Please, wait a couple of days I confirm the tests passed and you can consider the branch immutable.
lkp complained, please do not use the branch.
I'm waiting for Bartosz to fix the issue.
Alright, noted.
Thanks,
Sekhar
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sekhar, Bartosz,
if the sparse warning is not fixed, the driver won't hit this kernel version. Please fix it before the two next days otherwise it won't make it for v5.4.
Thanks
-- Daniel
Quoted 10 lines · Sekhar Nori
Hi Daniel,
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This is another version of the new davinci clocksource driver. After much discussion this contains many changes to simplify and improve the driver.
Does this look good to you now? If yes, can you please merge and provide an immutable branch to me so I can merge dependent mach-davinci patches?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
pon., 24 cze 2019 o 07:40 Daniel Lezcano <[email protected]> napisał(a):
Quoted 10 lines
Sekhar, Bartosz,
if the sparse warning is not fixed, the driver won't hit this kernel version. Please fix it before the two next days otherwise it won't make it for v5.4.
Thanks
Hi Daniel,
will do, I just came back to the office.
Sekhar, how do we want to handle the rest of the platform code with this driver? Do you think it can make it for the next release?
Bart
Quoted 12 lines · Bartosz Golaszewski
pon., 24 cze 2019 o 07:40 Daniel Lezcano <[email protected]> napisał(a):
Quoted 10 lines
Sekhar, Bartosz,
if the sparse warning is not fixed, the driver won't hit this kernel version. Please fix it before the two next days otherwise it won't make it for v5.4.
Thanks
Quoted 6 lines
Hi Daniel,
will do, I just came back to the office.
Sekhar, how do we want to handle the rest of the platform code with this driver? Do you think it can make it for the next release?
It may have to wait till next release, I am afraid. Lets first try to get the driver in though. I can try a late pull request with no guarantees.
Thanks,
Sekhar
Quoted 15 lines · Sekhar Nori
Quoted 14 lines · Bartosz Golaszewski
pon., 24 cze 2019 o 07:40 Daniel Lezcano <[email protected]> napisał(a):
Quoted 10 lines
Sekhar, Bartosz,
if the sparse warning is not fixed, the driver won't hit this kernel version. Please fix it before the two next days otherwise it won't make it for v5.4.
Thanks
Hi Daniel,
Quoted 7 lines
Quoted 4 lines
will do, I just came back to the office.
Sekhar, how do we want to handle the rest of the platform code with this driver? Do you think it can make it for the next release?
It may have to wait till next release, I am afraid. Lets first try to get the driver in though. I can try a late pull request with no guarantees.
The driver is merged in tip/timers/core, however I messed up with the davinci branch, please do not consider it as an immutable branch.
Sorry for that.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog