* [PATCH v2 0/2] MIPS: SGI-IP30: power off through the RTC
@ 2026-11-02 9:41 Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 1/2] MIPS: SGI-IP30: power off through the DS1687 RTC Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 2/2] MIPS: SGI-IP30: shut down cleanly on a power button press Imre Kaloz
0 siblings, 2 replies; 4+ messages in thread
From: Imre Kaloz @ 2026-11-02 9:41 UTC (permalink / raw)
To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Lee Jones, mfd
The Octane's power supply is switched by its DS1687 RTC. Patch 1 uses
it for power-off and halt. Patch 2 turns a power button press into an
orderly power-off, and adds the hook to the IOC3 RTC platform data in
drivers/mfd/ioc3.c.
Both take effect only with CONFIG_RTC_DRV_DS1685_FAMILY=y, which
ip30_defconfig sets with "MIPS: SGI-IP30: fix the defconfig defaults
for the Bridge PROM and RTC" from the "MIPS: SGI fixes" series. They
build without it. Patch 2 drives the RTC with interrupts disabled, so
at run time it needs "rtc: ds1685: do not sleep in the power-off
handler" from the rtc-ds1685 v2 series sent to the RTC tree.
v1 was tested on an Octane with poweroff, one and two power button
presses, and a stalled shutdown.
Changes in v2:
- Patch 1: drop the device reference when the RTC has no driver data.
- Patch 2: only the first power-off drives the RTC and later callers
wait for the power to drop; the 120 second timeout holds the device
lock against an unbind of rtc-ds1685. The RTC's power-off message
is printed from the power-off context, as the console thread cannot
run once interrupts are off.
v1: https://lore.kernel.org/all/20261013115820.13293-1-kaloz@kernel.org/
Imre Kaloz (2):
MIPS: SGI-IP30: power off through the DS1687 RTC
MIPS: SGI-IP30: shut down cleanly on a power button press
arch/mips/include/asm/sgi/heart.h | 2 +
arch/mips/sgi-ip30/ip30-power.c | 94 +++++++++++++++++++++++++++++++
drivers/mfd/ioc3.c | 6 ++
3 files changed, 102 insertions(+)
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] MIPS: SGI-IP30: power off through the DS1687 RTC
2026-11-02 9:41 [PATCH v2 0/2] MIPS: SGI-IP30: power off through the RTC Imre Kaloz
@ 2026-11-02 9:41 ` Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 2/2] MIPS: SGI-IP30: shut down cleanly on a power button press Imre Kaloz
1 sibling, 0 replies; 4+ messages in thread
From: Imre Kaloz @ 2026-11-02 9:41 UTC (permalink / raw)
To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Lee Jones
The Octane's power supply is switched by its DS1687 RTC. Use
ds1685_rtc_poweroff() for power-off and halt, with all HEART interrupts
masked first, instead of leaving the machine halted.
Signed-off-by: Imre Kaloz <kaloz@kernel.org>
---
arch/mips/sgi-ip30/ip30-power.c | 34 +++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/arch/mips/sgi-ip30/ip30-power.c b/arch/mips/sgi-ip30/ip30-power.c
index 66851e17c5a7..b1b33c9cfd76 100644
--- a/arch/mips/sgi-ip30/ip30-power.c
+++ b/arch/mips/sgi-ip30/ip30-power.c
@@ -15,6 +15,7 @@
#include <linux/delay.h>
#include <linux/rtc/ds1685.h>
#include <linux/interrupt.h>
+#include <linux/platform_device.h>
#include <linux/pm.h>
#include <asm/reboot.h>
@@ -31,10 +32,43 @@ static void __noreturn ip30_machine_restart(char *cmd)
unreachable();
}
+static void ip30_machine_power_off(void)
+{
+ struct device *dev;
+ int cpu;
+
+ if (!IS_REACHABLE(CONFIG_RTC_DRV_DS1685_FAMILY))
+ return;
+
+ dev = bus_find_device_by_name(&platform_bus_type, NULL, "rtc-ds1685");
+ if (!dev)
+ return;
+ if (!dev_get_drvdata(dev)) {
+ put_device(dev);
+ return;
+ }
+
+ /* Devices losing power may still interrupt; keep their handlers out. */
+ for (cpu = 0; cpu < HEART_MAX_CPUS; cpu++)
+ heart_write(HEART_CLR_ALL_MASK, &heart_regs->imr[cpu]);
+ heart_write(HEART_ACK_ALL_MASK, &heart_regs->clear_isr);
+
+ ds1685_rtc_poweroff(to_platform_device(dev));
+}
+
static int __init ip30_reboot_setup(void)
{
_machine_restart = ip30_machine_restart;
+ /*
+ * The DS1687 RTC switches the power supply off. Halt powers off
+ * too, as the power button needs a running kernel.
+ */
+ if (IS_REACHABLE(CONFIG_RTC_DRV_DS1685_FAMILY)) {
+ _machine_halt = ip30_machine_power_off;
+ pm_power_off = ip30_machine_power_off;
+ }
+
return 0;
}
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] MIPS: SGI-IP30: shut down cleanly on a power button press
2026-11-02 9:41 [PATCH v2 0/2] MIPS: SGI-IP30: power off through the RTC Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 1/2] MIPS: SGI-IP30: power off through the DS1687 RTC Imre Kaloz
@ 2026-11-02 9:41 ` Imre Kaloz
[not found] ` <sashiko-outbox-193229@kernel.org>
1 sibling, 1 reply; 4+ messages in thread
From: Imre Kaloz @ 2026-11-02 9:41 UTC (permalink / raw)
To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Lee Jones, Sashiko, mfd
The power button raises a kickstart interrupt on the DS1687, and
rtc-ds1685 cuts power at once unless the platform supplies a
prepare_poweroff hook. Supply one that starts an orderly power-off,
cutting power directly on a second press or after 120 seconds.
Power-off drives the RTC's index/data register pair, so only the first
of several concurrent callers proceeds and the rest wait. The timeout
holds the device lock against an unbind of rtc-ds1685.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-169717@kernel.org/
Signed-off-by: Imre Kaloz <kaloz@kernel.org>
---
arch/mips/include/asm/sgi/heart.h | 2 ++
arch/mips/sgi-ip30/ip30-power.c | 60 +++++++++++++++++++++++++++++++
drivers/mfd/ioc3.c | 6 ++++
3 files changed, 68 insertions(+)
diff --git a/arch/mips/include/asm/sgi/heart.h b/arch/mips/include/asm/sgi/heart.h
index c224c2e3575a..736cabb7fdbb 100644
--- a/arch/mips/include/asm/sgi/heart.h
+++ b/arch/mips/include/asm/sgi/heart.h
@@ -317,6 +317,8 @@ struct ip30_heart_regs { /* 0x0ff00000 */
extern struct ip30_heart_regs __iomem *heart_regs;
+void ip30_prepare_poweroff(void);
+
#define heart_read ____raw_readq
#define heart_write ____raw_writeq
diff --git a/arch/mips/sgi-ip30/ip30-power.c b/arch/mips/sgi-ip30/ip30-power.c
index b1b33c9cfd76..cff8f4875429 100644
--- a/arch/mips/sgi-ip30/ip30-power.c
+++ b/arch/mips/sgi-ip30/ip30-power.c
@@ -7,6 +7,7 @@
* 2009 Johannes Dickgreber <tanzy@gmx.de>
*/
+#include <linux/console.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -17,6 +18,8 @@
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
+#include <linux/reboot.h>
+#include <linux/workqueue.h>
#include <asm/reboot.h>
#include <asm/sgi/heart.h>
@@ -32,6 +35,8 @@ static void __noreturn ip30_machine_restart(char *cmd)
unreachable();
}
+static atomic_t ip30_power_off_claimed = ATOMIC_INIT(0);
+
static void ip30_machine_power_off(void)
{
struct device *dev;
@@ -48,14 +53,69 @@ static void ip30_machine_power_off(void)
return;
}
+ /*
+ * The RTC registers are reached through an index/data pair, so one
+ * CPU at a time may drive them, and a second button press, the
+ * timeout and pm_power_off can arrive together. Interrupts go off
+ * first so the claimant cannot be preempted by a waiter on its CPU;
+ * the waiters spin until the power drops.
+ */
+ local_irq_disable();
+ if (atomic_xchg(&ip30_power_off_claimed, 1))
+ for (;;)
+ cpu_relax();
+
/* Devices losing power may still interrupt; keep their handlers out. */
for (cpu = 0; cpu < HEART_MAX_CPUS; cpu++)
heart_write(HEART_CLR_ALL_MASK, &heart_regs->imr[cpu]);
heart_write(HEART_ACK_ALL_MASK, &heart_regs->clear_isr);
+ /*
+ * Nothing schedules before the power drops, so the RTC's message must
+ * be printed from this context, not left to the console thread. The
+ * emergency section is never left.
+ */
+ nbcon_cpu_emergency_enter();
ds1685_rtc_poweroff(to_platform_device(dev));
}
+#define IP30_POWERDOWN_TIMEOUT 120 /* seconds */
+
+static bool ip30_shutting_down;
+
+static void ip30_power_timeout(struct work_struct *work)
+{
+ struct device *dev;
+
+ dev = bus_find_device_by_name(&platform_bus_type, NULL, "rtc-ds1685");
+ if (!dev)
+ return;
+
+ /*
+ * Unbinding rtc-ds1685 frees the RTC under the device lock, so hold
+ * it across the drvdata check and the power-off.
+ */
+ device_lock(dev);
+ ip30_machine_power_off();
+ device_unlock(dev);
+ put_device(dev);
+}
+
+static DECLARE_DELAYED_WORK(ip30_power_work, ip30_power_timeout);
+
+/* Called by the RTC driver when the power button is pressed. */
+void ip30_prepare_poweroff(void)
+{
+ /* A second press powers off at once. */
+ if (ip30_shutting_down)
+ ip30_machine_power_off();
+
+ /* Shut down through userspace, powering off anyway if it stalls. */
+ ip30_shutting_down = true;
+ orderly_poweroff(true);
+ schedule_delayed_work(&ip30_power_work, IP30_POWERDOWN_TIMEOUT * HZ);
+}
+
static int __init ip30_reboot_setup(void)
{
_machine_restart = ip30_machine_restart;
diff --git a/drivers/mfd/ioc3.c b/drivers/mfd/ioc3.c
index 5f8ac364b610..8f603651cc8e 100644
--- a/drivers/mfd/ioc3.c
+++ b/drivers/mfd/ioc3.c
@@ -24,6 +24,9 @@
#include <asm/pci/bridge.h>
#include <asm/sn/ioc3.h>
+#ifdef CONFIG_SGI_IP30
+#include <asm/sgi/heart.h>
+#endif
#define IOC3_IRQ_SERIAL_A 6
#define IOC3_IRQ_SERIAL_B 15
@@ -321,6 +324,9 @@ static struct ds1685_rtc_platform_data ip30_rtc_platform_data = {
.no_irq = false,
.uie_unsupported = true,
.access_type = ds1685_reg_indirect,
+#ifdef CONFIG_SGI_IP30
+ .plat_prepare_poweroff = ip30_prepare_poweroff,
+#endif
};
static const struct resource ioc3_rtc_ds1685_resources[] = {
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] MIPS: SGI-IP30: shut down cleanly on a power button press
[not found] ` <sashiko-outbox-193229@kernel.org>
@ 2026-11-02 11:29 ` Imre Kaloz
0 siblings, 0 replies; 4+ messages in thread
From: Imre Kaloz @ 2026-11-02 11:29 UTC (permalink / raw)
To: sashiko-bot; +Cc: Thomas Bogendoerfer, linux-mips, linux-kernel, Lee Jones, mfd
>> + local_irq_disable();
>> + if (atomic_xchg(&ip30_power_off_claimed, 1))
>> + for (;;)
>> + cpu_relax();
>
> As reported by Sashiko on v1 [1], can another CPU still race on the
> indirect RTC index/data registers and bank selection while
> ds1685_rtc_poweroff() is running?
On dual-CPU Octanes the second CPU can still move the index or the
bank. v3 will stop the other CPU with smp_send_stop() before touching
HEART or the RTC.
>> ds1685_rtc_poweroff(to_platform_device(dev));
>
> Doesn't ds1685_rtc_poweroff() sleep in msleep(20) before cutting power,
> violating the atomic context established by local_irq_disable() and
> nbcon_cpu_emergency_enter()?
Not with the dependency named in the cover letter. Commit 21a829af60a7
("rtc: ds1685: do not sleep in the power-off handler"), in v7.4-rc1,
replaces that msleep() with mdelay().
>> +#ifdef CONFIG_SGI_IP30
>> + .plat_prepare_poweroff = ip30_prepare_poweroff,
>> +#endif
>
> What happens on a power button press when CONFIG_SGI_IP30=y and
> CONFIG_RTC_DRV_DS1685_FAMILY=m?
The button stops cutting the power, as the built-in
ip30_machine_power_off() cannot reach the module. v3 will set the hook
only when rtc-ds1685 is built in, so a modular driver will power off
on a press as it did before this series, and the second-press branch
will return.
Thanks,
Imre
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-02 11:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 9:41 [PATCH v2 0/2] MIPS: SGI-IP30: power off through the RTC Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 1/2] MIPS: SGI-IP30: power off through the DS1687 RTC Imre Kaloz
2026-11-02 9:41 ` [PATCH v2 2/2] MIPS: SGI-IP30: shut down cleanly on a power button press Imre Kaloz
[not found] ` <sashiko-outbox-193229@kernel.org>
2026-11-02 11:29 ` Imre Kaloz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®