x86, mrst: share APB timer code with other platforms
Subsystems (2)
PATCH v3 1/1 x86, mrst: share APB timer code with other platforms
The APB timers are an IP block from Synopsys (DesignWare APB timers) and are also found in other systems including ARM SoC's. This patch adds functions for creating clock_event_devices and clocksources from APB timers but does not do the resource allocation. This is handled in a higher layer to allow the timers to be created from multiple methods such as platform_devices.
Changes since v2:
- Make eoi() for clock_event_device optional for x86 where eoi is handled in firmware.
Changes since v1:
- Use the correct timer for clocksource on x86
- Select the correct timer rating for x86
- Restore freerunning timer behaviour for oneshot event devices
- Reenable event irq correctly for hotplug
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/apb_timer.h | 22 +-- arch/x86/kernel/apb_timer.c | 417 ++++++------------------------------ drivers/Kconfig | 2 + drivers/clocksource/Kconfig | 6 + drivers/clocksource/Makefile | 1 + drivers/clocksource/dw_apb_timer.c | 323 ++++++++++++++++++++++++++++ include/linux/dw_apb_timer.h | 129 +++++++++++ 8 files changed, 533 insertions(+), 368 deletions(-) create mode 100644 drivers/clocksource/Kconfig create mode 100644 drivers/clocksource/dw_apb_timer.c create mode 100644 include/linux/dw_apb_timer.h
arch/x86/Kconfig +1 -0
@@ -623,6 +623,7 @@ config HPET_EMULATE_RTC config APB_TIMER def_bool y if MRST prompt "Langwell APB Timer Support" if X86_MRST + select DW_APB_TIMER help APB timer is the replacement for 8254, HPET on X86 MID platforms. The APBT provides a stable time base on SMP
arch/x86/include/asm/apb_timer.h +2 -20
@@ -18,24 +18,6 @@#ifdef CONFIG_APB_TIMER -/* Langwell DW APB timer registers */ -#define APBTMR_N_LOAD_COUNT 0x00 -#define APBTMR_N_CURRENT_VALUE 0x04 -#define APBTMR_N_CONTROL 0x08 -#define APBTMR_N_EOI 0x0c -#define APBTMR_N_INT_STATUS 0x10 - -#define APBTMRS_INT_STATUS 0xa0 -#define APBTMRS_EOI 0xa4 -#define APBTMRS_RAW_INT_STATUS 0xa8 -#define APBTMRS_COMP_VERSION 0xac -#define APBTMRS_REG_SIZE 0x14 - -/* register bits */ -#define APBTMR_CONTROL_ENABLE (1<<0) -#define APBTMR_CONTROL_MODE_PERIODIC (1<<1)/*1: periodic 0:free running */ -#define APBTMR_CONTROL_INT (1<<2) -/* default memory mapped register base */ #define LNW_SCU_ADDR 0xFF100000#define LNW_EXT_TIMER_OFFSET 0x1B800
@@ -43,8 +25,8 @@#define LNW_EXT_TIMER_PGOFFSET 0x800/* APBT clock speed range from PCLK to fabric base, 25-100MHz */ -#define APBT_MAX_FREQ 50 -#define APBT_MIN_FREQ 1 +#define APBT_MAX_FREQ 50000000 +#define APBT_MIN_FREQ 1000000#define APBT_MMAP_SIZE 1024#define APBT_DEV_USED 1
arch/x86/kernel/apb_timer.c +69 -348
617 lines not on this page · raw message
drivers/Kconfig +2 -0
@@ -119,4 +119,6 @@ source "drivers/platform/Kconfig" source "drivers/clk/Kconfig" source "drivers/hwspinlock/Kconfig" + +source "drivers/clocksource/Kconfig" endmenu
drivers/clocksource/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +# +# Clocksource configuration +# + +config DW_APB_TIMER + bool
drivers/clocksource/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o 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_DW_APB_TIMER) += dw_apb_timer.o
drivers/clocksource/dw_apb_timer.c new file +323 -0
323 lines not on this page · raw message
include/linux/dw_apb_timer.h new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
1.7.4.2
Quoted 16 lines · Jamie Iles
The APB timers are an IP block from Synopsys (DesignWare APB timers) and are also found in other systems including ARM SoC's. This patch adds functions for creating
clock_event_devicesand clocksources from APB timers but does not do the resource allocation. This is handled in a higher layer to allow the timers to be created from multiple methods such asplatform_devices.Changes since v2:
- Makeeoi()forclock_event_deviceoptional for x86 where eoi is handled in firmware.
Changes since v1:
- Use the correct timer for clocksource on x86
- Select the correct timer rating for x86
- Restore freerunning timer behaviour for oneshot event devices
- Reenable event irq correctly for hotplug
Quoted 6 lines
Cc John Stultz <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Jacob Pan <[email protected]>Signed-off-by Jamie Iles <[email protected]>
Ping?
Jamie
Quoted 18 lines · On Sun, 8 May 2011 18:16:17 +0100 Jamie Iles <[email protected]> wrote:
Quoted 17 lines · Jamie Iles
The APB timers are an IP block from Synopsys (DesignWare APB timers) and are also found in other systems including ARM SoC's. This patch adds functions for creating
clock_event_devicesand clocksources from APB timers but does not do the resource allocation. This is handled in a higher layer to allow the timers to be created from multiple methods such asplatform_devices.Changes since v2:
- Makeeoi()forclock_event_deviceoptional for x86 where
eoi is handled in firmware.
Changes since v1:
- Use the correct timer for clocksource on x86
- Select the correct timer rating for x86
- Restore freerunning timer behaviour for oneshot event
devices
- Reenable event irq correctly for hotplug
Quoted 8 lines
Quoted 6 lines
Cc John Stultz <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Jacob Pan <[email protected]>Signed-off-by Jamie Iles <[email protected]>Ping?
Just to confirm on my side of testing, they are good on Moorestown platform.
Quoted 7 lines · Jamie Iles
The APB timers are an IP block from Synopsys (DesignWare APB timers) and are also found in other systems including ARM SoC's. This patch adds functions for creating
clock_event_devicesand clocksources from APB timers but does not do the resource allocation. This is handled in a higher layer to allow the timers to be created from multiple methods such asplatform_devices.
Quoted 8 lines
Changes since v2:
- Makeeoi()forclock_event_deviceoptional for x86 where eoi is handled in firmware.
Changes since v1:
- Use the correct timer for clocksource on x86
- Select the correct timer rating for x86
- Restore freerunning timer behaviour for oneshot event devices
- Reenable event irq correctly for hotplug
Sorry for being slow to review this.
Just a minor nit below.
Quoted 10 lines
drivers/clocksource/dw_apb_timer.c new file +10
-0+struct dw_apb_clocksource * +dw_apb_clocksource_init (unsigned rating,char *name,void __iomem *base, +unsigned long freq) +{ +struct dw_apb_clocksource *dw_cs =kzalloc (sizeof (*dw_cs),GFP_KERNEL ); + +if (!dw_cs) +return NULL ; + + dw_cs->timer.base = base;
drivers/clocksource/dw_apb_timer.c line 313
Quoted 10 lines
drivers/clocksource/dw_apb_timer.c new file +10
-0+ dw_cs->timer.freq = freq; + dw_cs->cs.name = name; + dw_cs->cs.rating = rating; + dw_cs->cs.read = __apbt_read_clocksource; + dw_cs->cs.mask =CLOCKSOURCE_MASK (32 ); + dw_cs->cs.flags =CLOCK_SOURCE_IS_CONTINUOUS ; + dw_cs->cs.resume = apbt_restart_clocksource; + +return dw_cs; +}
So I don't see anything that frees the dw_apb_clocksource structure after it has been allocated. Should this instead be allocated by the caller and passed in to be initialized here?
thanks
-john
Quoted 17 lines · john stultz
Quoted 7 lines · Jamie Iles
The APB timers are an IP block from Synopsys (DesignWare APB timers) and are also found in other systems including ARM SoC's. This patch adds functions for creating
clock_event_devicesand clocksources from APB timers but does not do the resource allocation. This is handled in a higher layer to allow the timers to be created from multiple methods such asplatform_devices.Quoted 8 lines
Changes since v2:
- Makeeoi()forclock_event_deviceoptional for x86 where eoi is handled in firmware.
Changes since v1:
- Use the correct timer for clocksource on x86
- Select the correct timer rating for x86
- Restore freerunning timer behaviour for oneshot event devices
- Reenable event irq correctly for hotplug
Quoted 1 line
Sorry for being slow to review this.
No worries, appreciate the review.
Quoted 18 lines
Just a minor nit below.
Quoted 16 lines
drivers/clocksource/dw_apb_timer.c new file +16
-0+struct dw_apb_clocksource * +dw_apb_clocksource_init (unsigned rating,char *name,void __iomem *base, +unsigned long freq) +{ +struct dw_apb_clocksource *dw_cs =kzalloc (sizeof (*dw_cs),GFP_KERNEL ); + +if (!dw_cs) +return NULL ; + + dw_cs->timer.base = base; + dw_cs->timer.freq = freq; + dw_cs->cs.name = name; + dw_cs->cs.rating = rating; + dw_cs->cs.read = __apbt_read_clocksource; + dw_cs->cs.mask =CLOCKSOURCE_MASK (32 ); + dw_cs->cs.flags =CLOCK_SOURCE_IS_CONTINUOUS ;
Quoted 8 lines
drivers/clocksource/dw_apb_timer.c line 313
Quoted 4 lines
drivers/clocksource/dw_apb_timer.c new file +4
-0+ dw_cs->cs.resume = apbt_restart_clocksource; + +return dw_cs; +}So I don't see anything that frees the
dw_apb_clocksourcestructure after it has been allocated. Should this instead be allocated by the caller and passed in to be initialized here?
Yeah, either that or I could add a dw_apb_clocksource_remove() that does the clocksource_unregister() and kfree(). That's probably a little more consistent with the rest of the driver.
Jamie