i2c: spacemit: Avoid sleeping during bus reset in atomic context
Subsystems (5)
PATCH v2 1/3 i2c: spacemit: Avoid sleeping during bus reset in atomic context
The spacemit_i2c_conditionally_reset_bus() function uses usleep_range() to wait after triggering a bus reset request. However, this function can be invoked during atomic I2C transfers (such as power-off or restart handlers running in atomic notifier chains), where sleeping is illegal.
Replace the sleep operation with the driver's internal helper, spacemit_i2c_delay(), which conditionally uses udelay() when running in an atomic context, avoiding "scheduling while atomic" bugs.
---
v1: https://lore.kernel.org/all/[email protected]/
collected all te reviewed-by
--- drivers/i2c/busses/i2c-k1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-k1.c +1 -1
@@ -332,7 +332,7 @@ static void spacemit_i2c_conditionally_reset_bus(struct spacemit_i2c_dev *i2c)writel (FIELD_PREP (SPACEMIT_RCR_FIELD_RST_CYC ,1 ), i2c->base +SPACEMIT_IRCR );writel (SPACEMIT_CR_RSTREQ , i2c->base +SPACEMIT_ICR ); -usleep_range (20 ,30 ); +spacemit_i2c_delay (i2c,20 ); }/* check sda again here */
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
Signature · 1 line
2.56.0
PATCH v2 2/3 riscv: sbi: Register SRST handlers with firmware priority
The SBI System Reset (SRST) extension currently registers its poweroff handler using register_platform_power_off(), which assigns it a lower priority than the default PMIC poweroff handlers.
On platforms where OpenSBI handles system poweroff, a PMIC handler may run first and perform I2C-backed regmap operations in atomic context, triggering invalid wait context and scheduling-while-atomic warnings.
Register both SBI SRST restart and poweroff handlers using register_sys_off_handler() with SYS_OFF_PRIO_FIRMWARE. This gives firmware handlers precedence over default-priority PMIC handlers and avoids board-specific workarounds in individual PMIC drivers.
Defer handler registration to a device initcall because sbi_init() runs during early architecture initialization, before dynamic memory allocation required by register_sys_off_handler() is available.
Preserve warm and cold reboot selection, retain the existing legacy poweroff fallback, and report handler registration failures.
---
New patch:
--- arch/riscv/kernel/sbi.c | 43 +++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-)
arch/riscv/kernel/sbi.c +33 -10
@@ -512,23 +512,50 @@ static void sbi_srst_reset(unsigned long type, unsigned long reason) __func__, type, reason); } -static int sbi_srst_reboot (struct notifier_block *this, -unsigned long mode,void *cmd) +static int sbi_srst_reboot (struct sys_off_data *data) { -sbi_srst_reset ((mode ==REBOOT_WARM || mode ==REBOOT_SOFT ) ? +sbi_srst_reset ((reboot_mode ==REBOOT_WARM || + reboot_mode ==REBOOT_SOFT ) ?SBI_SRST_RESET_TYPE_WARM_REBOOT :SBI_SRST_RESET_TYPE_COLD_REBOOT ,SBI_SRST_RESET_REASON_NONE ); +return NOTIFY_DONE ; } -static struct notifier_block sbi_srst_reboot_nb; - -static void sbi_srst_power_off (void ) +static int sbi_srst_power_off (struct sys_off_data *data) {sbi_srst_reset (SBI_SRST_RESET_TYPE_SHUTDOWN ,SBI_SRST_RESET_REASON_NONE ); + +return NOTIFY_DONE ; +} + +static int __init sbi_srst_sys_off_init (void ) +{ +struct sys_off_handler *handler; + +if (sbi_spec_version <sbi_mk_version (0 ,3 ) || + !sbi_probe_extension (SBI_EXT_SRST )) +return 0 ; + + handler =register_sys_off_handler (SYS_OFF_MODE_RESTART , +SYS_OFF_PRIO_FIRMWARE , + sbi_srst_reboot,NULL ); +if (IS_ERR (handler)) +pr_warn ("Failed to register SBI SRST restart handler: %ld\n" , +PTR_ERR (handler)); + + handler =register_sys_off_handler (SYS_OFF_MODE_POWER_OFF , +SYS_OFF_PRIO_FIRMWARE , + sbi_srst_power_off,NULL ); +if (IS_ERR (handler)) +pr_warn ("Failed to register SBI SRST poweroff handler: %ld\n" , +PTR_ERR (handler)); + +return 0 ; } +device_initcall (sbi_srst_sys_off_init);/** * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
@@ -677,11 +704,7 @@ void __init sbi_init(void)if (sbi_spec_version >=sbi_mk_version (0 ,3 ) &&sbi_probe_extension (SBI_EXT_SRST )) {pr_info ("SBI SRST extension detected\n" ); -register_platform_power_off (sbi_srst_power_off); srst_power_off = true; - sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot; - sbi_srst_reboot_nb.priority =192 ; -register_restart_handler (&sbi_srst_reboot_nb); }if (sbi_spec_version >=sbi_mk_version (2 ,0 ) &&sbi_probe_extension (SBI_EXT_DBCN ) >0 ) {
Signature · 1 line
2.56.0
PATCH v2 3/3 power: reset: Remove SpacemiT P1 reboot driver
In reply to Anand MoonThe SpacemiT P1 reboot driver uses I2C-backed regmap operations to request system shutdown and restart through the PMIC.
The system-off handlers run in atomic context, where regmap operations may sleep. This can trigger invalid wait context and scheduling-while-atomic warnings during shutdown or restart.
On SpacemiT K1 platforms, system poweroff and restart are handled by OpenSBI through the SBI System Reset (SRST) extension. The Linux PMIC reboot driver duplicates this firmware functionality and is no longer needed.
Remove the driver along with its Kconfig and Makefile entries. The P1 MFD driver and its other functionality remain unaffected.
---
New patch
--- drivers/power/reset/Kconfig | 9 --- drivers/power/reset/Makefile | 1 - drivers/power/reset/spacemit-p1-reboot.c | 87 ------------------------ 3 files changed, 97 deletions(-) delete mode 100644 drivers/power/reset/spacemit-p1-reboot.c
drivers/power/reset/Kconfig +0 -9
@@ -295,15 +295,6 @@ config POWER_RESET_KEYSTONE help Reboot support for the KEYSTONE SoCs. -config POWER_RESET_SPACEMIT_P1 - tristate "SpacemiT P1 poweroff and reset driver" - depends on ARCH_SPACEMIT || COMPILE_TEST - depends on MFD_SPACEMIT_P1 - default MFD_SPACEMIT_P1 - help - This driver supports power-off and reset operations for the SpacemiT - P1 PMIC. - config POWER_RESET_SYSCON bool "Generic SYSCON regmap reset driver" depends on OF
drivers/power/reset/Makefile +0 -1
@@ -25,7 +25,6 @@ obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o -obj-$(CONFIG_POWER_RESET_SPACEMIT_P1) += spacemit-p1-reboot.o obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o obj-$(CONFIG_POWER_RESET_TH1520_AON) += th1520-aon-reboot.o obj-$(CONFIG_POWER_RESET_TORADEX_EC) += tdx-ec-poweroff.o
drivers/power/reset/spacemit-p1-reboot.c deleted +0 -87
87 lines not on this page · raw message
Signature · 1 line
2.56.0