mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 11:33:28 +02:00
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>
This commit is contained in:
parent
29d3f6a643
commit
7597d68cea
|
|
@ -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);
|
||||
}
|
||||
if (!mmc_card_is_removable(mmc))
|
||||
return 1;
|
||||
|
||||
return present;
|
||||
} else if (gpio_cd >= 0)
|
||||
present = gpio_cd;
|
||||
else
|
||||
present = (mci_readl(host, CDETECT) & BIT(0))
|
||||
== 0 ? 1 : 0;
|
||||
/* Try slot gpio detection */
|
||||
if (gpio_cd >= 0)
|
||||
return !!gpio_cd;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user