• Ulf Hansson's avatar
    mmc: rtsx_usb_sdmmc: Re-work card detection/removal support · 4dad599b
    Ulf Hansson authored
    The rtsx USB parent device, has logic to detect when a card is inserted
    into the card slot. Although, the logic can't detect when a card is
    removed. This makes things a bit tricky, which is why the current method is
    simply to turn on MMC_CAP_NEEDS_POLL during probe.
    
    Using MMC_CAP_NEEDS_POLL means lots of energy being wasted, as the mmc host
    becomes runtime resumed frequently by the mmc core, while it polls for new
    cards being inserted.
    
    To address this problem, let's start relying on that the rtsx USB driver
    runtime resumes its child device, which is the rtsx_usb_sdmmc device, when
    it detects that a new card being inserted.
    
    This means dropping MMC_CAP_NEEDS_POLL from being set during probe. Instead
    let's implement a ->runtime_resume() callback to schedule a detect work and
    to set MMC_CAP_NEEDS_POLL. In this way, polling is enabled as long as there
    is card inserted, thus we can rely on the mmc core to detect also when the
    card becomes removed.
    
    Furthermore, to avoid polling forever after a card has been removed, let's
    implement a ->runtime_suspend() callback and make it clear
    MMC_CAP_NEEDS_POLL.
    Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
    Tested-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
    Tested-by: default avatarOleksandr Natalenko <oleksandr@natalenko.name>
    4dad599b
rtsx_usb_sdmmc.c 36.5 KB