All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Marek Vasut <marek.vasut+renesas@mailbox.org>
Cc: u-boot@lists.denx.de,  Jaehoon Chung <jh80.chung@samsung.com>,
	 Peng Fan <peng.fan@nxp.com>,  Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH v6] mmc: Poll CD in case cyclic framework is enabled
Date: Mon, 09 Sep 2024 10:46:21 +0200	[thread overview]
Message-ID: <87wmjli59e.fsf@prevas.dk> (raw)
In-Reply-To: <20240906171110.91195-1-marek.vasut+renesas@mailbox.org> (Marek Vasut's message of "Fri, 6 Sep 2024 19:10:42 +0200")

Marek Vasut <marek.vasut+renesas@mailbox.org> writes:

> 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>
> Cc: Simon Glass <sjg@chromium.org>
> ---
> V2: Move the cyclic registration/unregistration into mmc init/deinit
> V3: Replace if (CONFIG_IS_ENABLED(CYCLIC)...) with #if as the former
>     does not work with structure members
> V4: Stuff the code with CONFIG_IS_ENABLED() variants to avoid #ifdefs
> V5: Rebase on u-boot/next
> V6: Rebase on u-boot/next
> ---
>  drivers/mmc/mmc.c | 25 +++++++++++++++++++++++++
>  include/mmc.h     |  3 +++
>  2 files changed, 28 insertions(+)
>

[rearranging hunks for easier reading]

> diff --git a/include/mmc.h b/include/mmc.h
> index f508cd15700..0044ff8bef7 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -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));


I think that you can simplify this quite a lot by dropping all of the
the CONFIG_IS_ENABLED stuff. If CYCLIC is not enabled, struct
cyclic_info is an empty struct, so takes up no space, but it still
exists in struct mmc, allowing it to be referenced in C code that need
not be guarded.

>  };
>  
>  #if CONFIG_IS_ENABLED(DM_MMC)

> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 0b881f11b4a..c787ff6bc49 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -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)
> +{

You can drop __maybe_unused.

> +	struct mmc *m = CONFIG_IS_ENABLED(CYCLIC, (container_of(c, struct mmc, cyclic)), (NULL));
> +

No need for the CONFIG_IS_ENABLED(), container_of works just fine when
the cyclic member exists unconditionally.

> +	if (!m->has_init)
> +		return;
> +

(I'd assume that in the !CYCLIC case the compiler might warn about this
unconditional NULL deref; that you avoid with the above.)

> +	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)));
> +	}
> +

No need for any of the CONFIG_IS_ENABLED nesting. Just do
cyclic_register() - that's a no-op when !CYCLIC, and the compiler will
see the reference to mmc_cyclic_cd_poll, so not warn about it being
unused, yet also see that it is not actually called, so elide it from
the compiled code.

>  	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)));
> +

Again, just do cyclic_unregister() unconditionally.

Rasmus

  reply	other threads:[~2024-09-09  8:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 17:10 [PATCH v6] mmc: Poll CD in case cyclic framework is enabled Marek Vasut
2024-09-09  8:46 ` Rasmus Villemoes [this message]
2024-09-09 14:32   ` Tom Rini
2024-09-10  9:34     ` Rasmus Villemoes
2024-09-21 17:49       ` Tom Rini
2024-09-11 15:06 ` Simon Glass
2024-09-23 14:10 ` Tom Rini
2024-09-23 14:10 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wmjli59e.fsf@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=jh80.chung@samsung.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=peng.fan@nxp.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.