* [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL
@ 2026-11-26 11:00 Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Andreas Kemnade @ 2026-11-26 11:00 UTC (permalink / raw)
To: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, imx, linux-kernel, devicetree, linux,
Andreas Kemnade
On Ebook readers there are often situations in which the system waits
only for some GPIO IRQs and no module is active, all the clock system
is using most of the power, not every clock gets disabled via RPM,
esp. those are marked as CLK_IS_CRITICAL.
A usual he situation might be mainly wating for touchscreen input.
Since nothing needs to be sent to the display continously, clocks
are not in use. Maybe some frontlight is consuming power, but if it
is not used in maximum brightness mode, the clock system is still
using a significant portion of power.
In contrast to suspend state, that is not forcefully turning things of
and wake up only on selected important things when the device is not used.
E.g. you might still want to have frontlight enabled.
Vendor kernel work around this by adding an extended suspend mode in
which more things are disabled, e.g. the touchscreen.
So rather add another idle state, which is only conditionally used
depending on clock usage.
System timekeeping is currently using a high speed clock, which is a
major blocker for this idle state.
Use 32K clock for the timer and the clock source to avoid that
dependency and allow the timer to be used in stop mode if that low
power clock source is used.
Other things preventing entering that idle state:
- imx-thermal driver: probaly needs some notifier block called by
cpu_cluster_pm_enter to avoid false alarms like ti-bandgap does
- PXP and DCP drivers are missing RPM, so they keep clocks enabled.
- serial console: needs to be unbound
With these patches are applied (and the not-yet-upstreamed EPDC driver)
I can run a loop displaying the current consumption in every 20 seconds
for about one week. Power saving is around 70% in such
situations.
Patch 1 and 2 can go in independently, patch 3 should go in afterwards
since it will break things if the timer driver is not prepared.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
Changes in v2:
- honor disabled idle states when rejecting the new state
- remove redundant imx6_set_int_mem_clk_lpm
- more comments
- do not show new idle state on other cpus and when thermal driver is
enabled. The latter to avoid misreadings until things are fixed
- block new idle state on dcp activity
- adapt min_delta for clocksource if 32K clock is used
- Link to v1: https://patch.msgid.link/20261123-imx6-idlestop-v1-0-e32f1f44e46f@kemnade.info
---
Andreas Kemnade (3):
ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
timer-imx-gpt: Allow 32K clock to be used as a clock source
ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer
arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts | 5 ++
arch/arm/mach-imx/common.h | 1 +
arch/arm/mach-imx/cpuidle-imx6sx.c | 54 +++++++++++++++++++++-
arch/arm/mach-imx/pm-imx6.c | 31 +++++++++++++
drivers/clocksource/timer-imx-gpt.c | 17 +++++--
5 files changed, 102 insertions(+), 6 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
change-id: 20261123-imx6-idlestop-b14454a91e67
Best regards,
--
Andreas Kemnade <andreas@kemnade.info>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
@ 2026-11-26 11:00 ` Andreas Kemnade
2026-11-26 11:13 ` sashiko-bot
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Andreas Kemnade @ 2026-11-26 11:00 UTC (permalink / raw)
To: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, imx, linux-kernel, devicetree, linux,
Andreas Kemnade
Since there are situations when only wakeup from some GPIO IRQs is
required (besides the timekeeping infrastructure which can be fed by
an always on 32K clock), add another idle state to allow power-hungry
PLLs to be turned off in that condition.
Since some clocks are not turned off by RPM and
implementing it seems not feasible, keep a list of clocks to be ignored.
This includes clocks marked as CLK_IS_CRITICAL (romclk, aips_tzX clocks).
Collecting references to every clock feels a bit too much, so just list
the bits with comments.
To avoid spurios thermal misreadings, disable the new state when thermal
might be on, until these misreadings are sorted out.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
arch/arm/mach-imx/common.h | 1 +
arch/arm/mach-imx/cpuidle-imx6sx.c | 54 +++++++++++++++++++++++++++++++++++++-
arch/arm/mach-imx/pm-imx6.c | 31 ++++++++++++++++++++++
3 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h
index d7ecaa822adbd..7804cf5d83922 100644
--- a/arch/arm/mach-imx/common.h
+++ b/arch/arm/mach-imx/common.h
@@ -35,6 +35,7 @@ void imx_gpc_set_arm_power_down_timing(u32 sw2iso, u32 sw);
void imx25_pm_init(void);
void imx27_pm_init(void);
void imx5_pmu_init(void);
+bool imx6sll_check_pll_are_used(void);
enum mxc_cpu_pwr_mode {
WAIT_CLOCKED, /* wfi only */
diff --git a/arch/arm/mach-imx/cpuidle-imx6sx.c b/arch/arm/mach-imx/cpuidle-imx6sx.c
index 83c5cbd3748e1..d2e8a98cc6ebb 100644
--- a/arch/arm/mach-imx/cpuidle-imx6sx.c
+++ b/arch/arm/mach-imx/cpuidle-imx6sx.c
@@ -65,6 +65,40 @@ static __cpuidle int imx6sx_enter_wait(struct cpuidle_device *dev,
return index;
}
+static __cpuidle int imx6sx_enter_pll_off(struct cpuidle_device *dev,
+ struct cpuidle_driver *drv, int index)
+{
+ if (imx6sll_check_pll_are_used()) {
+ for (index--; index >= 0; index--)
+ if (!dev->states_usage[index].disable)
+ return imx6sx_enter_wait(dev, drv, index);
+
+ return -EBUSY;
+ }
+
+ imx6_set_lpm(STOP_POWER_ON);
+ imx6_enable_rbc(true);
+ imx_gpc_set_arm_power_in_lpm(true);
+ imx_set_cpu_jump(0, v7_cpu_resume);
+ /* Need to notify there is a cpu pm operation. */
+ cpu_pm_enter();
+ cpu_cluster_pm_enter();
+
+ ct_cpuidle_enter();
+
+ cpu_suspend(0, imx6sx_idle_finish);
+
+ ct_cpuidle_exit();
+
+ cpu_cluster_pm_exit();
+ cpu_pm_exit();
+ imx6_enable_rbc(false);
+ imx_gpc_set_arm_power_in_lpm(false);
+
+ imx6_set_lpm(WAIT_CLOCKED);
+ return index;
+}
+
static struct cpuidle_driver imx6sx_cpuidle_driver = {
.name = "imx6sx_cpuidle",
.owner = THIS_MODULE,
@@ -95,8 +129,19 @@ static struct cpuidle_driver imx6sx_cpuidle_driver = {
.name = "LOW-POWER-IDLE",
.desc = "ARM power off",
},
+ /* STOP ON */
+ {
+ /* times not measured, just hopefully safe values */
+ .exit_latency = 500,
+ .target_residency = 800,
+ .flags = CPUIDLE_FLAG_TIMER_STOP |
+ CPUIDLE_FLAG_RCU_IDLE,
+ .enter = imx6sx_enter_pll_off,
+ .name = "STOP ON",
+ .desc = "ARM power off + PLL off",
+ },
},
- .state_count = 3,
+ .state_count = 4,
.safe_state_index = 0,
};
@@ -114,5 +159,12 @@ int __init imx6sx_cpuidle_init(void)
imx_gpc_set_arm_power_up_timing(cpu_is_imx6sx() ? 0xf : 0x2, 1);
imx_gpc_set_arm_power_down_timing(1, 1);
+ /*
+ * play safe for now and try to avoid spurios false thermal readouts
+ * and unexpected actions on that
+ */
+ if (!cpu_is_imx6sll() || IS_ENABLED(CONFIG_IMX_THERMAL))
+ imx6sx_cpuidle_driver.state_count--;
+
return cpuidle_register(&imx6sx_cpuidle_driver, NULL);
}
diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
index 3c73e2cdb8ceb..2494ee4d20c3a 100644
--- a/arch/arm/mach-imx/pm-imx6.c
+++ b/arch/arm/mach-imx/pm-imx6.c
@@ -64,6 +64,14 @@
#define MX6Q_SUSPEND_OCRAM_SIZE 0x1000
#define MX6_MAX_MMDC_IO_NUM 33
+#define CCGR0 0x68
+#define CCGR1 0x6c
+#define CCGR2 0x70
+#define CCGR3 0x74
+#define CCGR4 0x78
+#define CCGR5 0x7c
+#define CCGR6 0x80
+
static void __iomem *ccm_base __ro_after_init;
static void __iomem *suspend_ocram_base __ro_after_init;
static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase) __ro_after_init;
@@ -287,6 +295,29 @@ void imx6_enable_rbc(bool enable)
imx_gpc_restore_all();
}
+bool imx6sll_check_pll_are_used(void)
+{
+ /* check for any clock active which provides more than register access */
+
+ /* uart2 | dcp */
+ return readl_relaxed(ccm_base + CCGR0) & (BIT(29) | BIT(11)) ||
+ /* uart | gpt_serial | epit | ecspi */
+ readl_relaxed(ccm_base + CCGR1) & (BIT(25) | BIT(23) | BIT(15) | BIT(13) |
+ BIT(11) | BIT(7) | BIT(5) | BIT(3) | BIT(1)) ||
+ /* pxp | lcd | i2c */
+ readl_relaxed(ccm_base + CCGR2) & (BIT(31) | BIT(29) | BIT(11) | BIT(9) |
+ BIT(7) | BIT(3)) ||
+ /* lcdif | epdc | pxp */
+ readl_relaxed(ccm_base + CCGR3) & (BIT(11) | BIT(5) | BIT(3)) ||
+ /* pwm */
+ readl_relaxed(ccm_base + CCGR4) & (BIT(23) | BIT(21) | BIT(19) | BIT(17)) ||
+ /* uart1 | ssi | spdif | sdma */
+ readl_relaxed(ccm_base + CCGR5) & (BIT(25) | BIT(23) | BIT(21) |
+ BIT(19) | BIT(15) | BIT(7)) ||
+ /* usdhc | usboh3 */
+ readl_relaxed(ccm_base + CCGR6) & (BIT(7) | BIT(5) | BIT(3) | BIT(1));
+}
+
static void imx6q_enable_wb(bool enable)
{
u32 val;
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
@ 2026-11-26 11:00 ` Andreas Kemnade
2026-11-26 11:14 ` sashiko-bot
2026-11-26 16:56 ` Frank Li
2026-11-26 11:00 ` [PATCH v2 3/3] ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer Andreas Kemnade
2026-11-26 17:01 ` [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Frank Li
3 siblings, 2 replies; 9+ messages in thread
From: Andreas Kemnade @ 2026-11-26 11:00 UTC (permalink / raw)
To: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, imx, linux-kernel, devicetree, linux,
Andreas Kemnade
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@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);
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
@ 2026-11-26 11:00 ` Andreas Kemnade
2026-11-26 17:01 ` [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Frank Li
3 siblings, 0 replies; 9+ messages in thread
From: Andreas Kemnade @ 2026-11-26 11:00 UTC (permalink / raw)
To: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, imx, linux-kernel, devicetree, linux,
Andreas Kemnade
To avoid depending on PLL infrastructure for timekeeping, use 32K clock
for the timer. Avoid changing the clock globally since other boards
might not profit from a slower clock in the same way.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts b/arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts
index 1000ee8b807aa..2e907c4163629 100644
--- a/arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts
+++ b/arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts
@@ -46,6 +46,11 @@ &gpio_keys {
pinctrl-0 = <&pinctrl_gpio_keys>;
};
+&gpt1 {
+ clocks = <&clks IMX6SLL_CLK_GPT_BUS>,
+ <&clks IMX6SLL_CLK_CKIL>;
+};
+
&i2c1 {
pinctrl-names = "default","sleep";
pinctrl-0 = <&pinctrl_i2c1>;
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
@ 2026-11-26 11:13 ` sashiko-bot
2026-11-26 12:46 ` Andreas Kemnade
0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 11:13 UTC (permalink / raw)
To: Andreas Kemnade; +Cc: imx, devicetree, robh, conor+dt, Frank.Li
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ARM: imx: broken fallback to states 0 and 1 in
imx6sx_enter_pll_off()
- [Low] ARM: imx: wrong clock names in imx6sll_check_pll_are_used()
comments
--
commit 6724bea26c43aa799d88abd3c3139a314f0fea52
Author: Andreas Kemnade <andreas@kemnade.info>
ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
This commit adds a STOP ON cpuidle state on i.MX6SLL that powers off the
ARM core and PLLs when no peripheral clocks requiring PLLs are active.
> diff --git a/arch/arm/mach-imx/cpuidle-imx6sx.c b/arch/arm/mach-imx/cpuidle-imx6sx.c
> index 83c5cbd3748e1..d2e8a98cc6ebb 100644
> --- a/arch/arm/mach-imx/cpuidle-imx6sx.c
> +++ b/arch/arm/mach-imx/cpuidle-imx6sx.c
> @@ -65,6 +65,40 @@ static __cpuidle int imx6sx_enter_wait(struct cpuidle_device *dev,
> return index;
> }
>
> +static __cpuidle int imx6sx_enter_pll_off(struct cpuidle_device *dev,
> + struct cpuidle_driver *drv, int index)
> +{
> + if (imx6sll_check_pll_are_used()) {
> + for (index--; index >= 0; index--)
> + if (!dev->states_usage[index].disable)
> + return imx6sx_enter_wait(dev, drv, index);
> +
> + return -EBUSY;
> + }
[Severity: Medium]
Can this fallback call imx6sx_enter_wait() with index 1 or 0?
State 3 sets CPUIDLE_FLAG_RCU_IDLE, so cpuidle_enter_state() skips
ct_cpuidle_enter() and ct_cpuidle_exit() around target_state->enter().
If state 2 is disabled in sysfs and imx6sll_check_pll_are_used() returns
true, falling back to index 1 runs case 1 in imx6sx_enter_wait(), which
calls cpu_do_idle() without ct_cpuidle_enter() / ct_cpuidle_exit() and
leaves RCU non-idle while the CPU sleeps with its local timer stopped.
If states 2 and 1 are both disabled, falling back to index 0 hits
default: break in imx6sx_enter_wait() and returns 0 without calling
cpu_do_idle() at all, causing the idle loop to busy-spin while counting
entries into state 0.
Calling drv->states[index].enter(dev, drv, index) wrapped in
ct_cpuidle_enter() and ct_cpuidle_exit() when the fallback state does not
have CPUIDLE_FLAG_RCU_IDLE set would handle all shallower states.
> diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
> index 3c73e2cdb8ceb..2494ee4d20c3a 100644
> --- a/arch/arm/mach-imx/pm-imx6.c
> +++ b/arch/arm/mach-imx/pm-imx6.c
[ ... ]
> @@ -287,6 +295,29 @@ void imx6_enable_rbc(bool enable)
> imx_gpc_restore_all();
> }
>
> +bool imx6sll_check_pll_are_used(void)
> +{
> + /* check for any clock active which provides more than register access */
> +
> + /* uart2 | dcp */
> + return readl_relaxed(ccm_base + CCGR0) & (BIT(29) | BIT(11)) ||
> + /* uart | gpt_serial | epit | ecspi */
> + readl_relaxed(ccm_base + CCGR1) & (BIT(25) | BIT(23) | BIT(15) | BIT(13) |
> + BIT(11) | BIT(7) | BIT(5) | BIT(3) | BIT(1)) ||
> + /* pxp | lcd | i2c */
> + readl_relaxed(ccm_base + CCGR2) & (BIT(31) | BIT(29) | BIT(11) | BIT(9) |
> + BIT(7) | BIT(3)) ||
> + /* lcdif | epdc | pxp */
> + readl_relaxed(ccm_base + CCGR3) & (BIT(11) | BIT(5) | BIT(3)) ||
[Severity: Low]
This isn't a bug, but in drivers/clk/imx/clk-imx6sll.c, BIT(3) of CCGR2
(0x70) gates csi (omitted from the CCGR2 comment) and BIT(3) of CCGR3
(0x74) gates uart5_ipg / uart5_serial rather than pxp.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-imx6-idlestop-v2-0-c6987e7a392f@kemnade.info?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
@ 2026-11-26 11:14 ` sashiko-bot
2026-11-26 16:56 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 11:14 UTC (permalink / raw)
To: Andreas Kemnade; +Cc: imx, devicetree, robh, conor+dt, Frank.Li
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] clocksource/drivers/timer-imx-gpt: use-after-free in
mxc_timer_init_dt() [1]
--
commit 870748ba8cec003b2bb83b77fde7449ddd3b4055
Author: Andreas Kemnade <andreas@kemnade.info>
timer-imx-gpt: Allow 32K clock to be used as a clock source
This commit configures the i.MX GPT timer control register and minimum
clockevent delta to allow using the 32.768 kHz clock as a clock source.
> 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
[ ... ]
> @@ -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);
>
> return request_irq(imxtm->irq, mxc_timer_interrupt,
> IRQF_TIMER | IRQF_IRQPOLL, "i.MX Timer Tick", ced);
[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in
request_irq() cause a use-after-free on imxtm->ced [1]?
mxc_clockevent_init() registers imxtm->ced with
clockevents_config_and_register() before calling request_irq(). If
request_irq() fails, the error propagates through _mxc_timer_init() to
mxc_timer_init_dt(), which frees imxtm while the clockevents core still
holds a reference to the registered ced:
drivers/clocksource/timer-imx-gpt.c:mxc_timer_init_dt() {
...
ret = _mxc_timer_init(imxtm);
if (ret)
goto err_kfree;
...
err_kfree:
kfree(imxtm);
return ret;
}
Requesting the IRQ before calling clockevents_config_and_register() would
avoid leaving a registered clock_event_device behind on failure.
[1] https://sashiko.dev/#/bug/linux-b33465da-04a0-4dc9-8c09-6d0b6a5ad47b
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-imx6-idlestop-v2-0-c6987e7a392f@kemnade.info?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
2026-11-26 11:13 ` sashiko-bot
@ 2026-11-26 12:46 ` Andreas Kemnade
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Kemnade @ 2026-11-26 12:46 UTC (permalink / raw)
To: sashiko-bot; +Cc: sashiko-reviews, imx, devicetree, robh, conor+dt, Frank.Li
On Thu, 26 Nov 2026 11:13:50 +0000
sashiko-bot@kernel.org wrote:
> > +bool imx6sll_check_pll_are_used(void)
> > +{
> > + /* check for any clock active which provides more than register access */
> > +
> > + /* uart2 | dcp */
> > + return readl_relaxed(ccm_base + CCGR0) & (BIT(29) | BIT(11)) ||
> > + /* uart | gpt_serial | epit | ecspi */
> > + readl_relaxed(ccm_base + CCGR1) & (BIT(25) | BIT(23) | BIT(15) | BIT(13) |
> > + BIT(11) | BIT(7) | BIT(5) | BIT(3) | BIT(1)) ||
> > + /* pxp | lcd | i2c */
> > + readl_relaxed(ccm_base + CCGR2) & (BIT(31) | BIT(29) | BIT(11) | BIT(9) |
> > + BIT(7) | BIT(3)) ||
> > + /* lcdif | epdc | pxp */
> > + readl_relaxed(ccm_base + CCGR3) & (BIT(11) | BIT(5) | BIT(3)) ||
>
> [Severity: Low]
> This isn't a bug, but in drivers/clk/imx/clk-imx6sll.c, BIT(3) of CCGR2
> (0x70) gates csi (omitted from the CCGR2 comment) and BIT(3) of CCGR3
> (0x74) gates uart5_ipg / uart5_serial rather than pxp.
>
According to page 536 of i.MX 6SLL Applications Processor Reference Manual, Rev. 0,
it is a second pxp clock. Is there any autoritative source here?
I have tested pxp a bit, had no problems with just one clock but did
not really test all functions. I do not have access to uart5 to test anything.
For the scope of this patch it does not matter, both belong into this list.
Regards,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
2026-11-26 11:14 ` sashiko-bot
@ 2026-11-26 16:56 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: Frank Li @ 2026-11-26 16:56 UTC (permalink / raw)
To: Andreas Kemnade
Cc: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-arm-kernel, imx,
linux-kernel, devicetree, linux
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@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
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
` (2 preceding siblings ...)
2026-11-26 11:00 ` [PATCH v2 3/3] ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer Andreas Kemnade
@ 2026-11-26 17:01 ` Frank Li
3 siblings, 0 replies; 9+ messages in thread
From: Frank Li @ 2026-11-26 17:01 UTC (permalink / raw)
To: Andreas Kemnade
Cc: Russell King, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Daniel Lezcano, Thomas Gleixner, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-arm-kernel, imx,
linux-kernel, devicetree, linux
On Thu, Nov 26, 2026 at 12:00:53PM +0100, Andreas Kemnade wrote:
> On Ebook readers there are often situations in which the system waits
> only for some GPIO IRQs and no module is active, all the clock system
> is using most of the power, not every clock gets disabled via RPM,
> esp. those are marked as CLK_IS_CRITICAL.
> A usual he situation might be mainly wating for touchscreen input.
> Since nothing needs to be sent to the display continously, clocks
> are not in use. Maybe some frontlight is consuming power, but if it
> is not used in maximum brightness mode, the clock system is still
> using a significant portion of power.
>
> In contrast to suspend state, that is not forcefully turning things of
> and wake up only on selected important things when the device is not used.
> E.g. you might still want to have frontlight enabled.
> Vendor kernel work around this by adding an extended suspend mode in
> which more things are disabled, e.g. the touchscreen.
>
> So rather add another idle state, which is only conditionally used
> depending on clock usage.
>
> System timekeeping is currently using a high speed clock, which is a
> major blocker for this idle state.
> Use 32K clock for the timer and the clock source to avoid that
> dependency and allow the timer to be used in stop mode if that low
> power clock source is used.
>
> Other things preventing entering that idle state:
> - imx-thermal driver: probaly needs some notifier block called by
> cpu_cluster_pm_enter to avoid false alarms like ti-bandgap does
> - PXP and DCP drivers are missing RPM, so they keep clocks enabled.
> - serial console: needs to be unbound
>
> With these patches are applied (and the not-yet-upstreamed EPDC driver)
> I can run a loop displaying the current consumption in every 20 seconds
> for about one week. Power saving is around 70% in such
> situations.
Nice feature, but how to make sure don't cause regression?
Frank
>
> Patch 1 and 2 can go in independently, patch 3 should go in afterwards
> since it will break things if the timer driver is not prepared.
>
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> ---
> Changes in v2:
> - honor disabled idle states when rejecting the new state
> - remove redundant imx6_set_int_mem_clk_lpm
> - more comments
> - do not show new idle state on other cpus and when thermal driver is
> enabled. The latter to avoid misreadings until things are fixed
> - block new idle state on dcp activity
> - adapt min_delta for clocksource if 32K clock is used
>
> - Link to v1: https://patch.msgid.link/20261123-imx6-idlestop-v1-0-e32f1f44e46f@kemnade.info
>
> ---
> Andreas Kemnade (3):
> ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit
> timer-imx-gpt: Allow 32K clock to be used as a clock source
> ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer
>
> arch/arm/boot/dts/nxp/imx/imx6sll-kobo-clarahd.dts | 5 ++
> arch/arm/mach-imx/common.h | 1 +
> arch/arm/mach-imx/cpuidle-imx6sx.c | 54 +++++++++++++++++++++-
> arch/arm/mach-imx/pm-imx6.c | 31 +++++++++++++
> drivers/clocksource/timer-imx-gpt.c | 17 +++++--
> 5 files changed, 102 insertions(+), 6 deletions(-)
> ---
> base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
> base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> change-id: 20261123-imx6-idlestop-b14454a91e67
>
> Best regards,
> --
> Andreas Kemnade <andreas@kemnade.info>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-26 17:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
2026-11-26 11:13 ` sashiko-bot
2026-11-26 12:46 ` Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
2026-11-26 11:14 ` sashiko-bot
2026-11-26 16:56 ` Frank Li
2026-11-26 11:00 ` [PATCH v2 3/3] ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer Andreas Kemnade
2026-11-26 17:01 ` [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox