[PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source

Frank Li Frank.li at oss.nxp.com
Thu Nov 26 08:56:35 PST 2026


On Thu, Nov 26, 2026 at 12:00:55PM +0100, Andreas Kemnade wrote:
> To avoid depending on PLL infrastructure for timekeeping, prepare for
> using the 32K clock by configuring the clock source accordingly.
>
> Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
> ---
>  drivers/clocksource/timer-imx-gpt.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c
> index 8335bd7f8c6ce..85fd36fe1c760 100644
> --- a/drivers/clocksource/timer-imx-gpt.c
> +++ b/drivers/clocksource/timer-imx-gpt.c
> @@ -50,8 +50,10 @@ enum imx_gpt_type {
>
>  /* MX31, MX35, MX25, MX5, MX6 */
>  #define V2_TCTL_WAITEN		(1 << 3) /* Wait enable mode */
> +#define V2_TCTL_STOPEN		(1 << 5) /* Stop enable mode */
>  #define V2_TCTL_CLK_IPG		(1 << 6)
>  #define V2_TCTL_CLK_PER		(2 << 6)
> +#define V2_TCTL_CLK_32K		(4 << 6)
>  #define V2_TCTL_CLK_OSC_DIV8	(5 << 6)
>  #define V2_TCTL_FRR		(1 << 9)
>  #define V2_TCTL_24MEN		(1 << 10)
> @@ -271,6 +273,7 @@ static irqreturn_t mxc_timer_interrupt(int irq, void *dev_id)
>  static int __init mxc_clockevent_init(struct imx_timer *imxtm)
>  {
>  	struct clock_event_device *ced = &imxtm->ced;
> +	unsigned long rate = clk_get_rate(imxtm->clk_per);
>
>  	ced->name = "mxc_timer1";
>  	ced->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ;
> @@ -281,8 +284,7 @@ static int __init mxc_clockevent_init(struct imx_timer *imxtm)
>  	ced->rating = 200;
>  	ced->cpumask = cpumask_of(0);
>  	ced->irq = imxtm->irq;
> -	clockevents_config_and_register(ced, clk_get_rate(imxtm->clk_per),
> -					0xff, 0xfffffffe);
> +	clockevents_config_and_register(ced, rate, rate == 32768 ? 3 : 0xff, 0xfffffffe);

Check 32768 is not good enough, in case board use 32000 osc. Add optional
clock osc? Or check clk_per is NULL?  OSC clk should always existing.

Frank

>
>  	return request_irq(imxtm->irq, mxc_timer_interrupt,
>  			   IRQF_TIMER | IRQF_IRQPOLL, "i.MX Timer Tick", ced);
> @@ -314,14 +316,19 @@ static void imx6dl_gpt_setup_tctl(struct imx_timer *imxtm)
>  	u32 tctl_val;
>
>  	tctl_val = V2_TCTL_FRR | V2_TCTL_WAITEN | MXC_TCTL_TEN;
> -	if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8) {
> +	if (clk_get_rate(imxtm->clk_per) == V2_TIMER_RATE_OSC_DIV8)  {
>  		tctl_val |= V2_TCTL_CLK_OSC_DIV8;
>  		/* 24 / 8 = 3 MHz */
>  		writel_relaxed(7 << V2_TPRER_PRE24M, imxtm->base + MXC_TPRER);
>  		tctl_val |= V2_TCTL_24MEN;
> -	} else {
> +	} else if (clk_get_rate(imxtm->clk_per) == 32768)
> +		/*
> +		 * if powered by that always on clock, it is feasible to let
> +		 * it run in stop mode, too, allowing lower idle states
> +		 */
> +		tctl_val |= V2_TCTL_CLK_32K | V2_TCTL_STOPEN;
> +	else
>  		tctl_val |= V2_TCTL_CLK_PER;
> -	}
>
>  	writel_relaxed(tctl_val, imxtm->base + MXC_TCTL);
>  }
>
> --
> 2.47.3
>
>



More information about the linux-arm-kernel mailing list