Skip to content

Commit 479d8e6

Browse files
Linus WalleijUlf Hansson
authored andcommitted
mmc: mmci: Unwind big if() clause
This does two things: firsr replace the hard-to-read long if-expression: if (!host->busy_status && !(status & err_msk) && (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { With the more readable: if (!host->busy_status && !(status & err_msk)) { status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { Second notice that the re-read MMCISTATUS register is now stored into the status variable, using logic OR because what if something else changed too? While we are at it, explain what the function is doing. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230405-pl180-busydetect-fix-v7-2-69a7164f2a61@linaro.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 2673493 commit 479d8e6

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

drivers/mmc/host/mmci.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,23 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host)
654654
return MCI_DPSM_ENABLE | (host->data->blksz << 16);
655655
}
656656

657+
/*
658+
* ux500_busy_complete() - this will wait until the busy status
659+
* goes off, saving any status that occur in the meantime into
660+
* host->busy_status until we know the card is not busy any more.
661+
* The function returns true when the busy detection is ended
662+
* and we should continue processing the command.
663+
*
664+
* The Ux500 typically fires two IRQs over a busy cycle like this:
665+
*
666+
* DAT0 busy +-----------------+
667+
* | |
668+
* DAT0 not busy ----+ +--------
669+
*
670+
* ^ ^
671+
* | |
672+
* IRQ1 IRQ2
673+
*/
657674
static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk)
658675
{
659676
void __iomem *base = host->base;
@@ -671,14 +688,16 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk)
671688
* while, to allow it to be set, but tests indicates that it
672689
* isn't needed.
673690
*/
674-
if (!host->busy_status && !(status & err_msk) &&
675-
(readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) {
676-
writel(readl(base + MMCIMASK0) |
677-
host->variant->busy_detect_mask,
678-
base + MMCIMASK0);
691+
if (!host->busy_status && !(status & err_msk)) {
692+
status = readl(base + MMCISTATUS);
693+
if (status & host->variant->busy_detect_flag) {
694+
writel(readl(base + MMCIMASK0) |
695+
host->variant->busy_detect_mask,
696+
base + MMCIMASK0);
679697

680-
host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND);
681-
return false;
698+
host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND);
699+
return false;
700+
}
682701
}
683702

684703
/*

0 commit comments

Comments
 (0)