diff options
| author | Linus Torvalds <[email protected]> | 2022-08-01 12:37:54 -0700 | 
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2022-08-01 12:37:54 -0700 | 
| commit | dfea84827f7eb49ca41d837d92ac1cbd5353a742 (patch) | |
| tree | 2d7312288f16b0effadafb5db5218553ea7c61f8 /drivers/clocksource/timer-mediatek.c | |
| parent | 63e6053add5a6cec4dbfa3dec12e0d4439daac4a (diff) | |
| parent | cceeeb6a6d02e7b9a74ddd27a3225013b34174aa (diff) | |
Merge tag 'timers-core-2022-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Thomas Gleixner:
 "Timers, timekeeping and related drivers update:
  Core:
   - Make wait_event_hrtimeout() aware of RT/DL tasks
  New drivers:
   - R-Car Gen4 timer
   - Tegra186 timer
   - Mediatek MT6795 CPUXGPT timer
  Updates:
   - Rework suspend/resume handling in timer drivers so it
     takes inactive clocks into account.
   - The usual device tree compatible add ons
   - Small fixed and cleanups all over the place"
* tag 'timers-core-2022-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (24 commits)
  wait: Fix __wait_event_hrtimeout for RT/DL tasks
  clocksource/drivers/sun5i: Remove unnecessary (void*) conversions
  dt-bindings: timer: allwinner,sun4i-a10-timer: Add D1 compatible
  dt-bindings: timer: ingenic,tcu: use absolute path to other schema
  clocksource/drivers/sun4i: Remove unnecessary (void*) conversions
  dt-bindings: timer: renesas,cmt: Fix R-Car Gen4 fall-out
  clocksource/drivers/tegra186: Put Kconfig option 'tristate' to 'bool'
  clocksource/drivers/timer-ti-dm: Make driver selection bool for TI K3
  clocksource/drivers/timer-ti-dm: Add compatible for am6 SoCs
  clocksource/drivers/timer-ti-dm: Make timer selectable for ARCH_K3
  clocksource/drivers/timer-ti-dm: Move inline functions to driver for am6
  clocksource/drivers/sh_cmt: Add R-Car Gen4 support
  dt-bindings: timer: renesas,cmt: R-Car V3U is R-Car Gen4
  dt-bindings: timer: renesas,cmt: Add r8a779f0 and generic Gen4 CMT support
  clocksource/drivers/timer-microchip-pit64b: Fix compilation warnings
  clocksource/drivers/timer-microchip-pit64b: Use mchp_pit64b_{suspend, resume}
  clocksource/drivers/timer-microchip-pit64b: Remove suspend/resume ops for ce
  thermal/drivers/rcar_gen3_thermal: Add r8a779f0 support
  clocksource/drivers/timer-mediatek: Implement CPUXGPT timers
  dt-bindings: timer: mediatek: Add CPUX System Timer and MT6795 compatible
  ...
Diffstat (limited to 'drivers/clocksource/timer-mediatek.c')
| -rw-r--r-- | drivers/clocksource/timer-mediatek.c | 114 | 
1 files changed, 114 insertions, 0 deletions
| diff --git a/drivers/clocksource/timer-mediatek.c b/drivers/clocksource/timer-mediatek.c index 7bcb4a3f26fb..d5b29fd03ca2 100644 --- a/drivers/clocksource/timer-mediatek.c +++ b/drivers/clocksource/timer-mediatek.c @@ -22,6 +22,19 @@  #define TIMER_SYNC_TICKS        (3) +/* cpux mcusys wrapper */ +#define CPUX_CON_REG		0x0 +#define CPUX_IDX_REG		0x4 + +/* cpux */ +#define CPUX_IDX_GLOBAL_CTRL	0x0 + #define CPUX_ENABLE		BIT(0) + #define CPUX_CLK_DIV_MASK	GENMASK(10, 8) + #define CPUX_CLK_DIV1		BIT(8) + #define CPUX_CLK_DIV2		BIT(9) + #define CPUX_CLK_DIV4		BIT(10) +#define CPUX_IDX_GLOBAL_IRQ	0x30 +  /* gpt */  #define GPT_IRQ_EN_REG          0x00  #define GPT_IRQ_ENABLE(val)     BIT((val) - 1) @@ -72,6 +85,52 @@  static void __iomem *gpt_sched_reg __read_mostly; +static u32 mtk_cpux_readl(u32 reg_idx, struct timer_of *to) +{ +	writel(reg_idx, timer_of_base(to) + CPUX_IDX_REG); +	return readl(timer_of_base(to) + CPUX_CON_REG); +} + +static void mtk_cpux_writel(u32 val, u32 reg_idx, struct timer_of *to) +{ +	writel(reg_idx, timer_of_base(to) + CPUX_IDX_REG); +	writel(val, timer_of_base(to) + CPUX_CON_REG); +} + +static void mtk_cpux_set_irq(struct timer_of *to, bool enable) +{ +	const unsigned long *irq_mask = cpumask_bits(cpu_possible_mask); +	u32 val; + +	val = mtk_cpux_readl(CPUX_IDX_GLOBAL_IRQ, to); + +	if (enable) +		val |= *irq_mask; +	else +		val &= ~(*irq_mask); + +	mtk_cpux_writel(val, CPUX_IDX_GLOBAL_IRQ, to); +} + +static int mtk_cpux_clkevt_shutdown(struct clock_event_device *clkevt) +{ +	/* Clear any irq */ +	mtk_cpux_set_irq(to_timer_of(clkevt), false); + +	/* +	 * Disabling CPUXGPT timer will crash the platform, especially +	 * if Trusted Firmware is using it (usually, for sleep states), +	 * so we only mask the IRQ and call it a day. +	 */ +	return 0; +} + +static int mtk_cpux_clkevt_resume(struct clock_event_device *clkevt) +{ +	mtk_cpux_set_irq(to_timer_of(clkevt), true); +	return 0; +} +  static void mtk_syst_ack_irq(struct timer_of *to)  {  	/* Clear and disable interrupt */ @@ -281,6 +340,60 @@ static struct timer_of to = {  	},  }; +static int __init mtk_cpux_init(struct device_node *node) +{ +	static struct timer_of to_cpux; +	u32 freq, val; +	int ret; + +	/* +	 * There are per-cpu interrupts for the CPUX General Purpose Timer +	 * but since this timer feeds the AArch64 System Timer we can rely +	 * on the CPU timer PPIs as well, so we don't declare TIMER_OF_IRQ. +	 */ +	to_cpux.flags = TIMER_OF_BASE | TIMER_OF_CLOCK; +	to_cpux.clkevt.name = "mtk-cpuxgpt"; +	to_cpux.clkevt.rating = 10; +	to_cpux.clkevt.cpumask = cpu_possible_mask; +	to_cpux.clkevt.set_state_shutdown = mtk_cpux_clkevt_shutdown; +	to_cpux.clkevt.tick_resume = mtk_cpux_clkevt_resume; + +	/* If this fails, bad things are about to happen... */ +	ret = timer_of_init(node, &to_cpux); +	if (ret) { +		WARN(1, "Cannot start CPUX timers.\n"); +		return ret; +	} + +	/* +	 * Check if we're given a clock with the right frequency for this +	 * timer, otherwise warn but keep going with the setup anyway, as +	 * that makes it possible to still boot the kernel, even though +	 * it may not work correctly (random lockups, etc). +	 * The reason behind this is that having an early UART may not be +	 * possible for everyone and this gives a chance to retrieve kmsg +	 * for eventual debugging even on consumer devices. +	 */ +	freq = timer_of_rate(&to_cpux); +	if (freq > 13000000) +		WARN(1, "Requested unsupported timer frequency %u\n", freq); + +	/* Clock input is 26MHz, set DIV2 to achieve 13MHz clock */ +	val = mtk_cpux_readl(CPUX_IDX_GLOBAL_CTRL, &to_cpux); +	val &= ~CPUX_CLK_DIV_MASK; +	val |= CPUX_CLK_DIV2; +	mtk_cpux_writel(val, CPUX_IDX_GLOBAL_CTRL, &to_cpux); + +	/* Enable all CPUXGPT timers */ +	val = mtk_cpux_readl(CPUX_IDX_GLOBAL_CTRL, &to_cpux); +	mtk_cpux_writel(val | CPUX_ENABLE, CPUX_IDX_GLOBAL_CTRL, &to_cpux); + +	clockevents_config_and_register(&to_cpux.clkevt, timer_of_rate(&to_cpux), +					TIMER_SYNC_TICKS, 0xffffffff); + +	return 0; +} +  static int __init mtk_syst_init(struct device_node *node)  {  	int ret; @@ -339,3 +452,4 @@ static int __init mtk_gpt_init(struct device_node *node)  }  TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);  TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init); +TIMER_OF_DECLARE(mtk_mt6795, "mediatek,mt6795-systimer", mtk_cpux_init); |