#include <linux/clocksource.h>
#include <linux/of_address.h>
#include <linux/sched_clock.h>
#include <dt-bindings/mfd/st-lpc.h>
#define LPC_LPT_LSB_OFF 0x400
#define LPC_LPT_MSB_OFF 0x404
#define LPC_LPT_START_OFF 0x408
static struct st_clksrc_ddata {
static void __init st_clksrc_reset(void)
writel_relaxed(0, ddata.base + LPC_LPT_START_OFF);
writel_relaxed(0, ddata.base + LPC_LPT_MSB_OFF);
writel_relaxed(0, ddata.base + LPC_LPT_LSB_OFF);
writel_relaxed(1, ddata.base + LPC_LPT_START_OFF);
static u64 notrace st_clksrc_sched_clock_read(void)
return (u64)readl_relaxed(ddata.base + LPC_LPT_LSB_OFF);
static int __init st_clksrc_init(void)
rate = clk_get_rate(ddata.clk);
sched_clock_register(st_clksrc_sched_clock_read, 32, rate);
ret = clocksource_mmio_init(ddata.base + LPC_LPT_LSB_OFF,
"clksrc-st-lpc", rate, 300, 32,
clocksource_mmio_readl_up);
pr_err("clksrc-st-lpc: Failed to register clocksource\n");