From: Shawn Lin Date: Tue, 6 Jan 2026 02:17:04 +0000 (+0800) Subject: mmc: dw_mmc: Improve dw_mci_get_cd() X-Git-Tag: v7.1-rc1~157^2~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7597d68cea6827f721e66b69d85e50e8ba820b09;p=thirdparty%2Fkernel%2Fstable.git mmc: dw_mmc: Improve dw_mci_get_cd() The current dw_mci_get_cd() implementation maintains a DW_MMC_CARD_PRESENT flag primarily for logging purposes, which adds unnecessary complexity. Additionally, the if-else-elif control flow does not align with the Linux kernel coding style. This commit simplifies the function by: - Removing the redundant card presence flag - Replacing the conditional chain with a cleaner implementation - Improving code readability while maintaining functionality The change reduces code complexity without affecting the actual card detection behavior. Signed-off-by: Shawn Lin Signed-off-by: Ulf Hansson --- diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index e563998b846cd..1d085b41920ed 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -881,42 +881,21 @@ static void dw_mci_post_req(struct mmc_host *mmc, static int dw_mci_get_cd(struct mmc_host *mmc) { - int present; struct dw_mci *host = mmc_priv(mmc); int gpio_cd = mmc_gpio_get_cd(mmc); - /* Use platform get_cd function, else try onboard card detect */ - if (((mmc->caps & MMC_CAP_NEEDS_POLL) - || !mmc_card_is_removable(mmc))) { - present = 1; + if (mmc->caps & MMC_CAP_NEEDS_POLL) + return 1; - if (!test_bit(DW_MMC_CARD_PRESENT, &host->flags)) { - if (mmc->caps & MMC_CAP_NEEDS_POLL) { - dev_info(&mmc->class_dev, - "card is polling.\n"); - } else { - dev_info(&mmc->class_dev, - "card is non-removable.\n"); - } - set_bit(DW_MMC_CARD_PRESENT, &host->flags); - } - - return present; - } else if (gpio_cd >= 0) - present = gpio_cd; - else - present = (mci_readl(host, CDETECT) & BIT(0)) - == 0 ? 1 : 0; + if (!mmc_card_is_removable(mmc)) + return 1; - spin_lock_bh(&host->lock); - if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &host->flags)) - dev_dbg(&mmc->class_dev, "card is present\n"); - else if (!present && - !test_and_clear_bit(DW_MMC_CARD_PRESENT, &host->flags)) - dev_dbg(&mmc->class_dev, "card is not present\n"); - spin_unlock_bh(&host->lock); + /* Try slot gpio detection */ + if (gpio_cd >= 0) + return !!gpio_cd; - return present; + /* Host native card detect */ + return !(mci_readl(host, CDETECT) & BIT(0)); } static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data) @@ -2918,6 +2897,11 @@ static int dw_mci_init_host(struct dw_mci *host) mmc->max_seg_size = mmc->max_req_size; } + if (mmc->caps & MMC_CAP_NEEDS_POLL) + dev_info(&mmc->class_dev, "card is polling.\n"); + else if (!mmc_card_is_removable(mmc)) + dev_info(&mmc->class_dev, "card is non-removable.\n"); + dw_mci_get_cd(mmc); ret = mmc_add_host(mmc); diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 5c17bcc85bf59..6800e7ce1d7f1 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -240,11 +240,10 @@ struct dw_mci { #endif struct mmc_host *mmc; unsigned long flags; -#define DW_MMC_CARD_PRESENT 0 -#define DW_MMC_CARD_NEED_INIT 1 -#define DW_MMC_CARD_NO_LOW_PWR 2 -#define DW_MMC_CARD_NO_USE_HOLD 3 -#define DW_MMC_CARD_NEEDS_POLL 4 +#define DW_MMC_CARD_NEED_INIT 0 +#define DW_MMC_CARD_NO_LOW_PWR 1 +#define DW_MMC_CARD_NO_USE_HOLD 2 +#define DW_MMC_CARD_NEEDS_POLL 3 u32 ctype; unsigned int clock; unsigned int clk_old;