mmc: core: Add infrastructure for undervoltage handling
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 21 Aug 2025 13:07:50 +0000 (15:07 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 22 Aug 2025 10:08:07 +0000 (12:08 +0200)
commit3202d6ed9368fc1e842fda73727553ae614633f8
tree41a05e76aee84feb40f467faba3f8fe611168a33
parent6fb942b85a1ab9728a4551d4161ec6fd6fab94f3
mmc: core: Add infrastructure for undervoltage handling

Implement the core infrastructure to allow MMC bus types to handle
REGULATOR_EVENT_UNDER_VOLTAGE events from power regulators. This is
primarily aimed at allowing devices like eMMC to perform an emergency
shutdown to prevent data corruption when a power failure is imminent.

This patch introduces:
- A new 'handle_undervoltage' function pointer to 'struct mmc_bus_ops'.
  Bus drivers (e.g., for eMMC) can implement this to define their
  emergency procedures.
- A workqueue ('uv_work') in 'struct mmc_supply' to handle the event
  asynchronously in a high-priority context.
- A new function 'mmc_handle_undervoltage()' which is called from the
  workqueue. It stops the host queue to prevent races with card removal,
  checks for the bus op, and invokes the handler.
- Functions to register and unregister the regulator notifier, intended
  to be called by bus drivers like 'mmc_attach_mmc' when a compatible
  card is detected.

The notifier is only registered for the main vmmc supply, as
undervoltage handling for vqmmc or vqmmc2 is not required at this
time.

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