On Fri, 29 Sept 2023 at 15:00, Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx> wrote: > > Hi, > > I'm working on a project aiming to protect eMMC during power loss. Our > hardware setup includes an under-voltage detector, circuits to disable > non-critical components, and enough capacitance to allow the CPU to run > for 100ms. > > I've added an interrupt handler to the fixed regulator to emit > REGULATOR_EVENT_UNDER_VOLTAGE events, and modified > drivers/mmc/host/sdhci.c to receive these events. Currently, the handler > only produces debug output. > > What is the recommended approach for handling under-voltage situations? > Should the driver finish ongoing write commands, block new ones, and > shut down the eMMC? I'm looking for direction here. That's indeed a very good question. From a general point of view, I think the best we can do is to stop any new I/O requests from being managed - and try to complete only the last ongoing one, if any. Exactly how to do that can be a bit tricky though. Beyond that, we should probably try to send the eMMC specific commands that allow us to inform the eMMC that it's about to be powered-off. Although, I am not sure that we actually will be able to complete these operations within 100ms, so maybe it's not really worth trying? See mmc_poweroff_notify(), for example. Kind regards Uffe