[PATCH] mmc: Poll CD in case cyclic framework is enabled

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 --- Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com --- drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index cdead044177..c4c9881c40b 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY UCLASS_MMC
#include <common.h> +#include <cyclic.h> #include <bootdev.h> #include <log.h> #include <mmc.h> @@ -343,8 +344,23 @@ struct blk_desc *mmc_get_blk_desc(struct mmc *mmc) return desc; }
+static void mmc_cyclic_cd_poll(void *ctx) +{ + struct mmc *m = ctx; + + if (!m->has_init) + return; + + if (mmc_getcd(m)) + return; + + mmc_deinit(m); + m->has_init = 0; +} + void mmc_do_preinit(void) { + struct cyclic_info *cyclic; struct udevice *dev; struct uclass *uc; int ret; @@ -362,6 +378,17 @@ void mmc_do_preinit(void)
if (m->preinit) mmc_start_init(m); + + if (!CONFIG_IS_ENABLED(CYCLIC)) + continue; + + /* Register cyclic function for card detect polling */ + cyclic = cyclic_register(mmc_cyclic_cd_poll, 100 * 1000, + m->cfg->name, m); + if (cyclic) + continue; + + printf("Failed to register %s CD poll function\n", m->cfg->name); } }

Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
Is there a remove() method where we could unregister the cyclic?
Reviewed-by: Simon Glass sjg@chromium.org

On 12/3/23 18:44, Simon Glass wrote:
Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
I wonder whether we can use this cyclic stuff for USB , that's on my roadmap to look at . We could auto-detect new devices in the background, which would be tidy. And maybe do block transfers in the background ?
Is there a remove() method where we could unregister the cyclic?
I guess I need to move this into mmc_init/mmc_deinit .

Hi Marek,
On Sun, 3 Dec 2023 at 14:01, Marek Vasut marek.vasut@mailbox.org wrote:
On 12/3/23 18:44, Simon Glass wrote:
Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
I wonder whether we can use this cyclic stuff for USB , that's on my roadmap to look at . We could auto-detect new devices in the background, which would be tidy. And maybe do block transfers in the background ?
Just the detect would be amazing!!
One thing on my mind is that we could have a console buffer, so that output from background tasks can be collected and written just before displaying the U-Boot prompt. I am itching to implement that part of it :-)
Is there a remove() method where we could unregister the cyclic?
I guess I need to move this into mmc_init/mmc_deinit .
Yes, I suppose so.
Regards, Simon

On 12/4/23 01:44, Simon Glass wrote:
Hi Marek,
On Sun, 3 Dec 2023 at 14:01, Marek Vasut marek.vasut@mailbox.org wrote:
On 12/3/23 18:44, Simon Glass wrote:
Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
I wonder whether we can use this cyclic stuff for USB , that's on my roadmap to look at . We could auto-detect new devices in the background, which would be tidy. And maybe do block transfers in the background ?
Just the detect would be amazing!!
One thing on my mind is that we could have a console buffer, so that output from background tasks can be collected and written just before displaying the U-Boot prompt. I am itching to implement that part of it :-)
And a 'dmesg' command to go along with it ?
Go for it.

On 12/4/23 02:05, Marek Vasut wrote:
On 12/4/23 01:44, Simon Glass wrote:
Hi Marek,
On Sun, 3 Dec 2023 at 14:01, Marek Vasut marek.vasut@mailbox.org wrote:
On 12/3/23 18:44, Simon Glass wrote:
Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
I wonder whether we can use this cyclic stuff for USB , that's on my roadmap to look at . We could auto-detect new devices in the background, which would be tidy. And maybe do block transfers in the background ?
Just the detect would be amazing!!
One thing on my mind is that we could have a console buffer, so that output from background tasks can be collected and written just before displaying the U-Boot prompt. I am itching to implement that part of it :-)
And a 'dmesg' command to go along with it ?
Go for it.
It's very nice to see, that the cyclic infrastructure is finally getting used by other interfaces / devices etc. Really interesting. I assume there are many more potential use cases where it may be helpful.
Thanks for all your work on this, Stefan

On 12/4/23 08:27, Stefan Roese wrote:
On 12/4/23 02:05, Marek Vasut wrote:
On 12/4/23 01:44, Simon Glass wrote:
Hi Marek,
On Sun, 3 Dec 2023 at 14:01, Marek Vasut marek.vasut@mailbox.org wrote:
On 12/3/23 18:44, Simon Glass wrote:
Hi Marek,
On Sat, 2 Dec 2023 at 16:41, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
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
Cc: Jaehoon Chung jh80.chung@samsung.com Cc: Peng Fan peng.fan@nxp.com
drivers/mmc/mmc-uclass.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
This is really nice!
I wonder whether we can use this cyclic stuff for USB , that's on my roadmap to look at . We could auto-detect new devices in the background, which would be tidy. And maybe do block transfers in the background ?
Just the detect would be amazing!!
One thing on my mind is that we could have a console buffer, so that output from background tasks can be collected and written just before displaying the U-Boot prompt. I am itching to implement that part of it :-)
And a 'dmesg' command to go along with it ?
Go for it.
It's very nice to see, that the cyclic infrastructure is finally getting used by other interfaces / devices etc. Really interesting. I assume there are many more potential use cases where it may be helpful.
Yes, many indeed.
participants (4)
-
Marek Vasut
-
Marek Vasut
-
Simon Glass
-
Stefan Roese