Skip to content

Commit 254274c

Browse files
ahunter6Ulf Hansson
authored andcommitted
mmc: sdhci: Eliminate SDHCI_QUIRK_UNSTABLE_RO_DETECT
SDHCI_QUIRK_UNSTABLE_RO_DETECT is used by only one driver variant. It was added in 2011 by commit 82b0e23 ("mmc: sdhci: Fix read-only detection with JMicron 388 chip"). Simplify sdhci by moving the logic to the only place it is used. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Link: https://lore.kernel.org/r/20240614080051.4005-4-adrian.hunter@intel.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 8d46e04 commit 254274c

3 files changed

Lines changed: 29 additions & 32 deletions

File tree

drivers/mmc/host/sdhci-pci-core.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,23 @@ static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc = {
13191319
.probe_slot = intel_mrfld_mmc_probe_slot,
13201320
};
13211321

1322+
#define JMB388_SAMPLE_COUNT 5
1323+
1324+
static int jmicron_jmb388_get_ro(struct mmc_host *mmc)
1325+
{
1326+
int i, ro_count;
1327+
1328+
ro_count = 0;
1329+
for (i = 0; i < JMB388_SAMPLE_COUNT; i++) {
1330+
if (sdhci_get_ro(mmc) > 0) {
1331+
if (++ro_count > JMB388_SAMPLE_COUNT / 2)
1332+
return 1;
1333+
}
1334+
msleep(30);
1335+
}
1336+
return 0;
1337+
}
1338+
13221339
static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
13231340
{
13241341
u8 scratch;
@@ -1403,11 +1420,6 @@ static int jmicron_probe(struct sdhci_pci_chip *chip)
14031420
return ret;
14041421
}
14051422

1406-
/* quirk for unsable RO-detection on JM388 chips */
1407-
if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
1408-
chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
1409-
chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
1410-
14111423
return 0;
14121424
}
14131425

@@ -1462,6 +1474,11 @@ static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
14621474

14631475
slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
14641476

1477+
/* Handle unstable RO-detection on JM388 chips */
1478+
if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
1479+
slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
1480+
slot->host->mmc_host_ops.get_ro = jmicron_jmb388_get_ro;
1481+
14651482
return 0;
14661483
}
14671484

drivers/mmc/host/sdhci.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,19 +2513,20 @@ int sdhci_get_cd_nogpio(struct mmc_host *mmc)
25132513
}
25142514
EXPORT_SYMBOL_GPL(sdhci_get_cd_nogpio);
25152515

2516-
static int sdhci_check_ro(struct sdhci_host *host)
2516+
int sdhci_get_ro(struct mmc_host *mmc)
25172517
{
2518+
struct sdhci_host *host = mmc_priv(mmc);
25182519
bool allow_invert = false;
25192520
int is_readonly;
25202521

25212522
if (host->flags & SDHCI_DEVICE_DEAD) {
25222523
is_readonly = 0;
25232524
} else if (host->ops->get_ro) {
25242525
is_readonly = host->ops->get_ro(host);
2525-
} else if (mmc_can_gpio_ro(host->mmc)) {
2526-
is_readonly = mmc_gpio_get_ro(host->mmc);
2526+
} else if (mmc_can_gpio_ro(mmc)) {
2527+
is_readonly = mmc_gpio_get_ro(mmc);
25272528
/* Do not invert twice */
2528-
allow_invert = !(host->mmc->caps2 & MMC_CAP2_RO_ACTIVE_HIGH);
2529+
allow_invert = !(mmc->caps2 & MMC_CAP2_RO_ACTIVE_HIGH);
25292530
} else {
25302531
is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
25312532
& SDHCI_WRITE_PROTECT);
@@ -2539,27 +2540,7 @@ static int sdhci_check_ro(struct sdhci_host *host)
25392540

25402541
return is_readonly;
25412542
}
2542-
2543-
#define SAMPLE_COUNT 5
2544-
2545-
static int sdhci_get_ro(struct mmc_host *mmc)
2546-
{
2547-
struct sdhci_host *host = mmc_priv(mmc);
2548-
int i, ro_count;
2549-
2550-
if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT))
2551-
return sdhci_check_ro(host);
2552-
2553-
ro_count = 0;
2554-
for (i = 0; i < SAMPLE_COUNT; i++) {
2555-
if (sdhci_check_ro(host)) {
2556-
if (++ro_count > SAMPLE_COUNT / 2)
2557-
return 1;
2558-
}
2559-
msleep(30);
2560-
}
2561-
return 0;
2562-
}
2543+
EXPORT_SYMBOL_GPL(sdhci_get_ro);
25632544

25642545
static void sdhci_hw_reset(struct mmc_host *mmc)
25652546
{

drivers/mmc/host/sdhci.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ struct sdhci_host {
437437
#define SDHCI_QUIRK_NO_HISPD_BIT (1<<29)
438438
/* Controller treats ADMA descriptors with length 0000h incorrectly */
439439
#define SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC (1<<30)
440-
/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */
441-
#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31)
442440

443441
unsigned int quirks2; /* More deviations from spec. */
444442

@@ -788,6 +786,7 @@ void sdhci_set_power_and_bus_voltage(struct sdhci_host *host,
788786
void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
789787
unsigned short vdd);
790788
int sdhci_get_cd_nogpio(struct mmc_host *mmc);
789+
int sdhci_get_ro(struct mmc_host *mmc);
791790
void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq);
792791
int sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq);
793792
void sdhci_set_bus_width(struct sdhci_host *host, int width);

0 commit comments

Comments
 (0)