mmc: core: add undervoltage handler for MMC/eMMC devices
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 21 Aug 2025 13:07:51 +0000 (15:07 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 22 Aug 2025 10:09:22 +0000 (12:09 +0200)
commit533c62f5c1d5a52807bdd434a44e3cbc6e77b416
tree82790ed612bfd2194a7fa6f7907beef23d139b10
parent3202d6ed9368fc1e842fda73727553ae614633f8
mmc: core: add undervoltage handler for MMC/eMMC devices

Add infrastructure to handle regulator undervoltage events for MMC/eMMC
cards. When an undervoltage is detected, the new handler performs a
controlled emergency suspend using a short power-off notification,
skipping the cache flush to maximize the chance of a safe shutdown.
After the operation, the card is marked as removed to prevent further
I/O and possible data corruption.

This is implemented by introducing MMC_POWEROFF_UNDERVOLTAGE to the
mmc_poweroff_type enum and refactoring the suspend logic into an
internal __mmc_suspend() helper that allows the caller to skip the cache
flush if required. The undervoltage handler is registered as a bus
operation and invoked from the core undervoltage path.

If power-off notification is not supported by the card, the handler
falls back to sleep or deselecting the card.

Additionally, update the shutdown path to avoid redundant shutdown
steps if the card is already removed

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20250821130751.2089587-3-o.rempel@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/mmc.c