]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: Poll CD in case cyclic framework is enabled
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Fri, 6 Sep 2024 17:10:42 +0000 (19:10 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 21 Sep 2024 17:49:20 +0000 (11:49 -0600)
In case the cyclic framework is enabled, poll the card detect of already
initialized cards and deinitialize them in case they are removed. Since
the card initialization is a longer process and card initialization is
done on first access to an uninitialized card anyway, avoid initializing
newly detected uninitialized cards in the cyclic callback.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/mmc/mmc.c
include/mmc.h

index 7e702c3ae854d347a7b5b447761143a52bd54c00..96b0e20d6695d836bfcf112450a8346a2e9de52c 100644 (file)
@@ -3039,6 +3039,20 @@ static int mmc_complete_init(struct mmc *mmc)
        return err;
 }
 
+static void __maybe_unused mmc_cyclic_cd_poll(struct cyclic_info *c)
+{
+       struct mmc *m = CONFIG_IS_ENABLED(CYCLIC, (container_of(c, struct mmc, cyclic)), (NULL));
+
+       if (!m->has_init)
+               return;
+
+       if (mmc_getcd(m))
+               return;
+
+       mmc_deinit(m);
+       m->has_init = 0;
+}
+
 int mmc_init(struct mmc *mmc)
 {
        int err = 0;
@@ -3061,6 +3075,14 @@ int mmc_init(struct mmc *mmc)
        if (err)
                pr_info("%s: %d, time %lu\n", __func__, err, get_timer(start));
 
+       if (CONFIG_IS_ENABLED(CYCLIC, (!mmc->cyclic.func), (NULL))) {
+               /* Register cyclic function for card detect polling */
+               CONFIG_IS_ENABLED(CYCLIC, (cyclic_register(&mmc->cyclic,
+                                                          mmc_cyclic_cd_poll,
+                                                          100 * 1000,
+                                                          mmc->cfg->name)));
+       }
+
        return err;
 }
 
@@ -3068,6 +3090,9 @@ int mmc_deinit(struct mmc *mmc)
 {
        u32 caps_filtered;
 
+       if (CONFIG_IS_ENABLED(CYCLIC, (mmc->cyclic.func), (NULL)))
+               CONFIG_IS_ENABLED(CYCLIC, (cyclic_unregister(&mmc->cyclic)));
+
        if (!CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) &&
            !CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) &&
            !CONFIG_IS_ENABLED(MMC_HS400_SUPPORT))
index f508cd15700d1b6adab594a27309099d949f0751..0044ff8bef7921503e3e798f9f3145aabc1d265b 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/sizes.h>
 #include <linux/compiler.h>
 #include <linux/dma-direction.h>
+#include <cyclic.h>
 #include <part.h>
 
 struct bd_info;
@@ -757,6 +758,8 @@ struct mmc {
        bool hs400_tuning:1;
 
        enum bus_mode user_speed_mode; /* input speed mode from user */
+
+       CONFIG_IS_ENABLED(CYCLIC, (struct cyclic_info cyclic));
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)