Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hi Thomas, On Tue, 21 Apr 2015, Thomas Gleixner wrote: > On Fri, 17 Apr 2015, Peter Griffin wrote: > > +/* Low Power Timer */ > > +#define LPC_LPT_LSB_OFF0x400 > > +#define LPC_LPT_MSB_OFF0x404 > > +#define LPC_LPT_START_OFF 0x408 > > + > > +struct st_lpc { > > + struct clk *clk; > > + void __iomem *iomem_cs; > > +}; > > + > > +static struct st_lpc *st_lpc; > > + > > +static u64 notrace st_lpc_counter_read(void) > > +{ > > + u64 counter; > > + u32 lower; > > + u32 upper, old_upper; > > + > > + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); > > + do { > > + old_upper = upper; > > + lower = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_LSB_OFF); > > + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); > > + } while (upper != old_upper); > > + > > + counter = upper; > > + counter <<= 32; > > + counter |= lower; > > + return counter; > > > What's the point of this exercise? The kernel can handle 32bit > clocksources nicely. So why do you want to artificially expand them to > 64bit by adding useless loops and hoops to a hotpath? Thanks for reviewing, yes your correct, we don't really need to be doing this. We will fix this in the v2 version. Lee Jones has also pointed out something which I was not aware of when submitting this, and that is this IP has shared registers with the RTC driver. He has been working on some patches here https://lkml.org/lkml/2015/4/9/609 which deal with configuring between watchdog and rtc and ensuring only one can be configured at a time, and this driver should also be making use of that mechanism. As he is already working on this, we decided it would be best if he takes over for the V2 submission, and aligns it with the work he has already done for this IP. regards, Peter. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hi Thomas, On Tue, 21 Apr 2015, Thomas Gleixner wrote: On Fri, 17 Apr 2015, Peter Griffin wrote: +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF0x400 +#define LPC_LPT_MSB_OFF0x404 +#define LPC_LPT_START_OFF 0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter = 32; + counter |= lower; + return counter; What's the point of this exercise? The kernel can handle 32bit clocksources nicely. So why do you want to artificially expand them to 64bit by adding useless loops and hoops to a hotpath? Thanks for reviewing, yes your correct, we don't really need to be doing this. We will fix this in the v2 version. Lee Jones has also pointed out something which I was not aware of when submitting this, and that is this IP has shared registers with the RTC driver. He has been working on some patches here https://lkml.org/lkml/2015/4/9/609 which deal with configuring between watchdog and rtc and ensuring only one can be configured at a time, and this driver should also be making use of that mechanism. As he is already working on this, we decided it would be best if he takes over for the V2 submission, and aligns it with the work he has already done for this IP. regards, Peter. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hello Thomas, On 04/21/2015 11:56 AM, Thomas Gleixner wrote: On Fri, 17 Apr 2015, Peter Griffin wrote: +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF0x400 +#define LPC_LPT_MSB_OFF0x404 +#define LPC_LPT_START_OFF 0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter <<= 32; + counter |= lower; + return counter; What's the point of this exercise? The kernel can handle 32bit clocksources nicely. So why do you want to artificially expand them to 64bit by adding useless loops and hoops to a hotpath? I agree we should use only the lower 32 bits. This timer is moreover clocked at a slow rate (30MHz), so we won't have too much interrupts. Peter, doing that, you could use something like this directly: clocksource_mmio_init(st_lpc->iomem_cs + LPC_LPT_LSB_OFF, "st_lpc_timer", rate, 200, 24, clocksource_mmio_readl_down); Thanks, Maxime Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hello Thomas, On 04/21/2015 11:56 AM, Thomas Gleixner wrote: On Fri, 17 Apr 2015, Peter Griffin wrote: +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF0x400 +#define LPC_LPT_MSB_OFF0x404 +#define LPC_LPT_START_OFF 0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter = 32; + counter |= lower; + return counter; What's the point of this exercise? The kernel can handle 32bit clocksources nicely. So why do you want to artificially expand them to 64bit by adding useless loops and hoops to a hotpath? I agree we should use only the lower 32 bits. This timer is moreover clocked at a slow rate (30MHz), so we won't have too much interrupts. Peter, doing that, you could use something like this directly: clocksource_mmio_init(st_lpc-iomem_cs + LPC_LPT_LSB_OFF, st_lpc_timer, rate, 200, 24, clocksource_mmio_readl_down); Thanks, Maxime Thanks, tglx -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
On Fri, 17 Apr 2015, Peter Griffin wrote: > +/* Low Power Timer */ > +#define LPC_LPT_LSB_OFF 0x400 > +#define LPC_LPT_MSB_OFF 0x404 > +#define LPC_LPT_START_OFF0x408 > + > +struct st_lpc { > + struct clk *clk; > + void __iomem *iomem_cs; > +}; > + > +static struct st_lpc *st_lpc; > + > +static u64 notrace st_lpc_counter_read(void) > +{ > + u64 counter; > + u32 lower; > + u32 upper, old_upper; > + > + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); > + do { > + old_upper = upper; > + lower = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_LSB_OFF); > + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); > + } while (upper != old_upper); > + > + counter = upper; > + counter <<= 32; > + counter |= lower; > + return counter; What's the point of this exercise? The kernel can handle 32bit clocksources nicely. So why do you want to artificially expand them to 64bit by adding useless loops and hoops to a hotpath? Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
On Fri, 17 Apr 2015, Peter Griffin wrote: +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF 0x400 +#define LPC_LPT_MSB_OFF 0x404 +#define LPC_LPT_START_OFF0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter = 32; + counter |= lower; + return counter; What's the point of this exercise? The kernel can handle 32bit clocksources nicely. So why do you want to artificially expand them to 64bit by adding useless loops and hoops to a hotpath? Thanks, tglx -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hi Paul, On Fri, 17 Apr 2015, Paul Bolle wrote: > On Fri, 2015-04-17 at 11:50 +0100, Peter Griffin wrote: > > --- a/drivers/clocksource/Kconfig > > +++ b/drivers/clocksource/Kconfig > > > +config CLKSRC_ST_LPC_CLOCK > > + bool > > + depends on ARCH_STI > > + select CLKSRC_OF if OF > > + help > > + Enable this option to use the Low Power controller timer > > + as clock source. > > + > > +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK > > + bool > > + depends on ST_LPC_CLOCK > > It looks like you meant > depends on CLKSRC_ST_LPC_CLOCK Yes your correct, will fix in v2. I did a last minute change to append CLKSRC_, and seem to have messed it up. > > --- /dev/null > > +++ b/drivers/clocksource/st_lpc.c > > > +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK > > #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? Yes, will fix in v2 > > > +static u64 notrace st_lpc_sched_clock_read(void) > > +{ > > + return st_lpc_counter_read(); > > +} > > +#endif > > > +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK > > Again, #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? Yes, will fix in v2 > > > + sched_clock_register(st_lpc_sched_clock_read, 64, rate); > > +#endif > > Assuming the above suggestions are correct: checkkconfigsymbols.py, as > shipped in linux-next, helps detect stuff like this. See > scripts/checkkconfigsymbols.py --help. Thanks for the pointer to the script, I'd not heard of that before, so will take a look. Thanks for reviewing, regards, Peter. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
Hi Paul, On Fri, 17 Apr 2015, Paul Bolle wrote: On Fri, 2015-04-17 at 11:50 +0100, Peter Griffin wrote: --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig +config CLKSRC_ST_LPC_CLOCK + bool + depends on ARCH_STI + select CLKSRC_OF if OF + help + Enable this option to use the Low Power controller timer + as clock source. + +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK + bool + depends on ST_LPC_CLOCK It looks like you meant depends on CLKSRC_ST_LPC_CLOCK Yes your correct, will fix in v2. I did a last minute change to append CLKSRC_, and seem to have messed it up. snip --- /dev/null +++ b/drivers/clocksource/st_lpc.c +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? Yes, will fix in v2 +static u64 notrace st_lpc_sched_clock_read(void) +{ + return st_lpc_counter_read(); +} +#endif +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK Again, #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? Yes, will fix in v2 + sched_clock_register(st_lpc_sched_clock_read, 64, rate); +#endif Assuming the above suggestions are correct: checkkconfigsymbols.py, as shipped in linux-next, helps detect stuff like this. See scripts/checkkconfigsymbols.py --help. Thanks for the pointer to the script, I'd not heard of that before, so will take a look. Thanks for reviewing, regards, Peter. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
On Fri, 2015-04-17 at 11:50 +0100, Peter Griffin wrote: > --- a/drivers/clocksource/Kconfig > +++ b/drivers/clocksource/Kconfig > +config CLKSRC_ST_LPC_CLOCK > + bool > + depends on ARCH_STI > + select CLKSRC_OF if OF > + help > + Enable this option to use the Low Power controller timer > + as clock source. > + > +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK > + bool > + depends on ST_LPC_CLOCK It looks like you meant depends on CLKSRC_ST_LPC_CLOCK > + default y > + help > + Use Low Power controller timer clock source as sched_clock > --- a/drivers/clocksource/Makefile > +++ b/drivers/clocksource/Makefile > +obj-$(CONFIG_CLKSRC_ST_LPC_CLOCK)+= st_lpc.o > --- /dev/null > +++ b/drivers/clocksource/st_lpc.c > +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? > +static u64 notrace st_lpc_sched_clock_read(void) > +{ > + return st_lpc_counter_read(); > +} > +#endif > +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK Again, #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? > + sched_clock_register(st_lpc_sched_clock_read, 64, rate); > +#endif Assuming the above suggestions are correct: checkkconfigsymbols.py, as shipped in linux-next, helps detect stuff like this. See scripts/checkkconfigsymbols.py --help. Thanks, Paul Bolle -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
This patch adds support for the LPC timer as a clocksource which is found on stih407 family SoCs. We wish to use the LPC timer as a clocksource instead of arm_global_timer, as the latter is tied to CPU frequency, and that driver currently makes no account for frequency scaling. Once this driver is merged cpufreq can be enabled for stih407 family SoCs without also effecting sched_clock. Signed-off-by: Ajit Pal Singh Signed-off-by: Peter Griffin --- drivers/clocksource/Kconfig | 16 + drivers/clocksource/Makefile | 1 + drivers/clocksource/st_lpc.c | 154 +++ 3 files changed, 171 insertions(+) create mode 100644 drivers/clocksource/st_lpc.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index a0b036c..29cd67d 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -253,4 +253,20 @@ config CLKSRC_PXA help This enables OST0 support available on PXA and SA-11x0 platforms. + +config CLKSRC_ST_LPC_CLOCK + bool + depends on ARCH_STI + select CLKSRC_OF if OF + help + Enable this option to use the Low Power controller timer + as clock source. + +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK + bool + depends on ST_LPC_CLOCK + default y + help + Use Low Power controller timer clock source as sched_clock + endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 752d5c7..356d331 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -51,3 +51,4 @@ obj-$(CONFIG_ARCH_INTEGRATOR_AP) += timer-integrator-ap.o obj-$(CONFIG_CLKSRC_VERSATILE) += versatile.o obj-$(CONFIG_CLKSRC_MIPS_GIC) += mips-gic-timer.o obj-$(CONFIG_ASM9260_TIMER)+= asm9260_timer.o +obj-$(CONFIG_CLKSRC_ST_LPC_CLOCK) += st_lpc.o diff --git a/drivers/clocksource/st_lpc.c b/drivers/clocksource/st_lpc.c new file mode 100644 index 000..f9abded --- /dev/null +++ b/drivers/clocksource/st_lpc.c @@ -0,0 +1,154 @@ +/* + * This driver implements a Clocksource using the Low Power Timer in + * the Low Power Controller (LPC) in some STMicroelectronics + * STi series SoCs + * + * Copyright (C) 2015 STMicroelectronics Limited + * Author: Francesco Virlinzi + * Author: Ajit Pal Singh + * + * May be copied or modified under the terms of the GNU General Public + * License. See linux/COPYING for more information. + */ + +#include +#include +#include +#include +#include +#include + +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF0x400 +#define LPC_LPT_MSB_OFF0x404 +#define LPC_LPT_START_OFF 0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc->iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter <<= 32; + counter |= lower; + return counter; +} + +static cycle_t st_lpc_clocksource_read(struct clocksource *cs) +{ + return st_lpc_counter_read(); +} + +static void st_lpc_clocksource_reset(struct clocksource *cs) +{ + writel_relaxed(0, st_lpc->iomem_cs + LPC_LPT_START_OFF); + writel_relaxed(0, st_lpc->iomem_cs + LPC_LPT_MSB_OFF); + writel_relaxed(0, st_lpc->iomem_cs + LPC_LPT_LSB_OFF); + writel_relaxed(1, st_lpc->iomem_cs + LPC_LPT_START_OFF); +} + +static struct clocksource st_lpc_clocksource = { + .name = "st-lpc clocksource", + .rating = 301, + .read = st_lpc_clocksource_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK +static u64 notrace st_lpc_sched_clock_read(void) +{ + return st_lpc_counter_read(); +} +#endif + +static void __init st_lpc_clocksource_init(void) +{ + unsigned long rate; + + st_lpc_clocksource_reset(_lpc_clocksource); + + rate = clk_get_rate(st_lpc->clk); +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK + sched_clock_register(st_lpc_sched_clock_read, 64, rate); +#endif + clocksource_register_hz(_lpc_clocksource, rate); + +} + +static int st_lpc_setup_clk(struct device_node *np) +{ + char *clk_name = "lpc_clk"; + struct clk *clk; + int ret; + + clk = of_clk_get_by_name(np, clk_name); + if (IS_ERR(clk)) { + pr_err("st-lpc: unable to get lpc clock\n"); + ret = PTR_ERR(clk); + return ret; + } + + if (clk_prepare_enable(clk)) { + pr_err("st-lpc: %s could not be enabled\n",
[PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
This patch adds support for the LPC timer as a clocksource which is found on stih407 family SoCs. We wish to use the LPC timer as a clocksource instead of arm_global_timer, as the latter is tied to CPU frequency, and that driver currently makes no account for frequency scaling. Once this driver is merged cpufreq can be enabled for stih407 family SoCs without also effecting sched_clock. Signed-off-by: Ajit Pal Singh ajitpal.si...@st.com Signed-off-by: Peter Griffin peter.grif...@linaro.org --- drivers/clocksource/Kconfig | 16 + drivers/clocksource/Makefile | 1 + drivers/clocksource/st_lpc.c | 154 +++ 3 files changed, 171 insertions(+) create mode 100644 drivers/clocksource/st_lpc.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index a0b036c..29cd67d 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -253,4 +253,20 @@ config CLKSRC_PXA help This enables OST0 support available on PXA and SA-11x0 platforms. + +config CLKSRC_ST_LPC_CLOCK + bool + depends on ARCH_STI + select CLKSRC_OF if OF + help + Enable this option to use the Low Power controller timer + as clock source. + +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK + bool + depends on ST_LPC_CLOCK + default y + help + Use Low Power controller timer clock source as sched_clock + endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 752d5c7..356d331 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -51,3 +51,4 @@ obj-$(CONFIG_ARCH_INTEGRATOR_AP) += timer-integrator-ap.o obj-$(CONFIG_CLKSRC_VERSATILE) += versatile.o obj-$(CONFIG_CLKSRC_MIPS_GIC) += mips-gic-timer.o obj-$(CONFIG_ASM9260_TIMER)+= asm9260_timer.o +obj-$(CONFIG_CLKSRC_ST_LPC_CLOCK) += st_lpc.o diff --git a/drivers/clocksource/st_lpc.c b/drivers/clocksource/st_lpc.c new file mode 100644 index 000..f9abded --- /dev/null +++ b/drivers/clocksource/st_lpc.c @@ -0,0 +1,154 @@ +/* + * This driver implements a Clocksource using the Low Power Timer in + * the Low Power Controller (LPC) in some STMicroelectronics + * STi series SoCs + * + * Copyright (C) 2015 STMicroelectronics Limited + * Author: Francesco Virlinzi francesco.virli...@st.com + * Author: Ajit Pal Singh ajitpal.si...@st.com + * + * May be copied or modified under the terms of the GNU General Public + * License. See linux/COPYING for more information. + */ + +#include linux/clk.h +#include linux/clocksource.h +#include linux/init.h +#include linux/of_address.h +#include linux/sched_clock.h +#include linux/slab.h + +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF0x400 +#define LPC_LPT_MSB_OFF0x404 +#define LPC_LPT_START_OFF 0x408 + +struct st_lpc { + struct clk *clk; + void __iomem *iomem_cs; +}; + +static struct st_lpc *st_lpc; + +static u64 notrace st_lpc_counter_read(void) +{ + u64 counter; + u32 lower; + u32 upper, old_upper; + + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + do { + old_upper = upper; + lower = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_LSB_OFF); + upper = readl_relaxed(st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + } while (upper != old_upper); + + counter = upper; + counter = 32; + counter |= lower; + return counter; +} + +static cycle_t st_lpc_clocksource_read(struct clocksource *cs) +{ + return st_lpc_counter_read(); +} + +static void st_lpc_clocksource_reset(struct clocksource *cs) +{ + writel_relaxed(0, st_lpc-iomem_cs + LPC_LPT_START_OFF); + writel_relaxed(0, st_lpc-iomem_cs + LPC_LPT_MSB_OFF); + writel_relaxed(0, st_lpc-iomem_cs + LPC_LPT_LSB_OFF); + writel_relaxed(1, st_lpc-iomem_cs + LPC_LPT_START_OFF); +} + +static struct clocksource st_lpc_clocksource = { + .name = st-lpc clocksource, + .rating = 301, + .read = st_lpc_clocksource_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK +static u64 notrace st_lpc_sched_clock_read(void) +{ + return st_lpc_counter_read(); +} +#endif + +static void __init st_lpc_clocksource_init(void) +{ + unsigned long rate; + + st_lpc_clocksource_reset(st_lpc_clocksource); + + rate = clk_get_rate(st_lpc-clk); +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK + sched_clock_register(st_lpc_sched_clock_read, 64, rate); +#endif + clocksource_register_hz(st_lpc_clocksource, rate); + +} + +static int st_lpc_setup_clk(struct device_node *np) +{ + char *clk_name = lpc_clk; + struct clk *clk; + int ret; + + clk = of_clk_get_by_name(np, clk_name); + if (IS_ERR(clk)) { + pr_err(st-lpc: unable to get lpc clock\n); +
Re: [PATCH 1/5] clocksource: st_lpc: Add LPC timer as a clocksource.
On Fri, 2015-04-17 at 11:50 +0100, Peter Griffin wrote: --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig +config CLKSRC_ST_LPC_CLOCK + bool + depends on ARCH_STI + select CLKSRC_OF if OF + help + Enable this option to use the Low Power controller timer + as clock source. + +config CLKSRC_ST_LPC_TIMER_SCHED_CLOCK + bool + depends on ST_LPC_CLOCK It looks like you meant depends on CLKSRC_ST_LPC_CLOCK + default y + help + Use Low Power controller timer clock source as sched_clock --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile +obj-$(CONFIG_CLKSRC_ST_LPC_CLOCK)+= st_lpc.o --- /dev/null +++ b/drivers/clocksource/st_lpc.c +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? +static u64 notrace st_lpc_sched_clock_read(void) +{ + return st_lpc_counter_read(); +} +#endif +#ifdef CONFIG_CLKSRC_LPC_TIMER_SCHED_CLOCK Again, #ifdef CONFIG_CLKSRC_ST_LPC_TIMER_SCHED_CLOCK here? + sched_clock_register(st_lpc_sched_clock_read, 64, rate); +#endif Assuming the above suggestions are correct: checkkconfigsymbols.py, as shipped in linux-next, helps detect stuff like this. See scripts/checkkconfigsymbols.py --help. Thanks, Paul Bolle -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/