Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <shawn.lin@rock-chips.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Shawn Lin and committed by
Ulf Hansson
7597d68c 29d3f6a6

+18 -35
+14 -30
drivers/mmc/host/dw_mmc.c
··· 881 881 882 882 static int dw_mci_get_cd(struct mmc_host *mmc) 883 883 { 884 - int present; 885 884 struct dw_mci *host = mmc_priv(mmc); 886 885 int gpio_cd = mmc_gpio_get_cd(mmc); 887 886 888 - /* Use platform get_cd function, else try onboard card detect */ 889 - if (((mmc->caps & MMC_CAP_NEEDS_POLL) 890 - || !mmc_card_is_removable(mmc))) { 891 - present = 1; 887 + if (mmc->caps & MMC_CAP_NEEDS_POLL) 888 + return 1; 892 889 893 - if (!test_bit(DW_MMC_CARD_PRESENT, &host->flags)) { 894 - if (mmc->caps & MMC_CAP_NEEDS_POLL) { 895 - dev_info(&mmc->class_dev, 896 - "card is polling.\n"); 897 - } else { 898 - dev_info(&mmc->class_dev, 899 - "card is non-removable.\n"); 900 - } 901 - set_bit(DW_MMC_CARD_PRESENT, &host->flags); 902 - } 890 + if (!mmc_card_is_removable(mmc)) 891 + return 1; 903 892 904 - return present; 905 - } else if (gpio_cd >= 0) 906 - present = gpio_cd; 907 - else 908 - present = (mci_readl(host, CDETECT) & BIT(0)) 909 - == 0 ? 1 : 0; 893 + /* Try slot gpio detection */ 894 + if (gpio_cd >= 0) 895 + return !!gpio_cd; 910 896 911 - spin_lock_bh(&host->lock); 912 - if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &host->flags)) 913 - dev_dbg(&mmc->class_dev, "card is present\n"); 914 - else if (!present && 915 - !test_and_clear_bit(DW_MMC_CARD_PRESENT, &host->flags)) 916 - dev_dbg(&mmc->class_dev, "card is not present\n"); 917 - spin_unlock_bh(&host->lock); 918 - 919 - return present; 897 + /* Host native card detect */ 898 + return !(mci_readl(host, CDETECT) & BIT(0)); 920 899 } 921 900 922 901 static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data) ··· 2896 2917 mmc->max_blk_count; 2897 2918 mmc->max_seg_size = mmc->max_req_size; 2898 2919 } 2920 + 2921 + if (mmc->caps & MMC_CAP_NEEDS_POLL) 2922 + dev_info(&mmc->class_dev, "card is polling.\n"); 2923 + else if (!mmc_card_is_removable(mmc)) 2924 + dev_info(&mmc->class_dev, "card is non-removable.\n"); 2899 2925 2900 2926 dw_mci_get_cd(mmc); 2901 2927
+4 -5
drivers/mmc/host/dw_mmc.h
··· 240 240 #endif 241 241 struct mmc_host *mmc; 242 242 unsigned long flags; 243 - #define DW_MMC_CARD_PRESENT 0 244 - #define DW_MMC_CARD_NEED_INIT 1 245 - #define DW_MMC_CARD_NO_LOW_PWR 2 246 - #define DW_MMC_CARD_NO_USE_HOLD 3 247 - #define DW_MMC_CARD_NEEDS_POLL 4 243 + #define DW_MMC_CARD_NEED_INIT 0 244 + #define DW_MMC_CARD_NO_LOW_PWR 1 245 + #define DW_MMC_CARD_NO_USE_HOLD 2 246 + #define DW_MMC_CARD_NEEDS_POLL 3 248 247 u32 ctype; 249 248 unsigned int clock; 250 249 unsigned int clk_old;