mmc: sdhci: Minor fixes
Adrian Hunter
maintainercover mmc: sdhci: Minor fixes
Hi
Here are a couple of minor fixes. While it would be good to have them in 4.9 or a 4.9-rc, they are not urgent.
Adrian Hunter (4):
mmc: sdhci: Fix SDHCI_QUIRK2_STOP_WITH_TC
mmc: sdhci: Rename sdhci_set_power() to sdhci_set_power_noreg()
mmc: sdhci-pci: Let devices define their own sdhci_ops
mmc: sdhci-pci: Fix bus power failing to enable for some Intel controllers
drivers/mmc/host/sdhci-pci-core.c | 54 ++++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci-pci.h | 2 ++ drivers/mmc/host/sdhci-pxav3.c | 2 +- drivers/mmc/host/sdhci.c | 40 ++++++++++++++--------------- drivers/mmc/host/sdhci.h | 2 ++ 5 files changed, 77 insertions(+), 23 deletions(-)
Regards
Adrian
Adrian Hunter
maintainerPATCH 1/4 mmc: sdhci: Fix SDHCI_QUIRK2_STOP_WITH_TC
Multi-block data transfers can specify the number of blocks either using a Set Block Count command (CMD23) or by sending a STOP command (CMD12) after the required number of blocks has transferred. CMD23 is preferred, but some cards don't support it. CMD12 with R1b response is used for writes, and R1 response for reads.
Some SDHCI host controllers give a Transfer Complete (TC) interrupt for the STOP command (CMD12) whether or not a R1b response has been specified. The quirk SDHCI_QUIRK2_STOP_WITH_TC identifies those host controllers, but the implementation only considers the case where the TC interrupt arrives at the same time as the Command Complete (CC) interrupt. However, occasionally TC arrives before CC. That is harmless, but does generate an error message "Got data interrupt 0x00000002 even though no data operation was in progress".
A simpler approach is to force R1b response onto all STOP commands, because SDHCI will handle TC before CC in the general case, so do that.
--- drivers/mmc/host/sdhci.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +6 -8
@@ -1077,6 +1077,10 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)/* Initially, a command has no error */ cmd->error =0 ; +if ((host->quirks2 &SDHCI_QUIRK2_STOP_WITH_TC ) && + cmd->opcode ==MMC_STOP_TRANSMISSION ) + cmd->flags |=MMC_RSP_BUSY ; +/* Wait max 10 ms */ timeout =10 ;
@@ -2409,7 +2413,7 @@ static void sdhci_timeout_data_timer(unsigned long data)* * \*****************************************************************************/ -static void sdhci_cmd_irq (struct sdhci_host *host,u32 intmask,u32 *mask) +static void sdhci_cmd_irq (struct sdhci_host *host,u32 intmask) {if (!host->cmd) {/*
@@ -2453,11 +2457,6 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *mask)return ; } -if ((host->quirks2 &SDHCI_QUIRK2_STOP_WITH_TC ) && - !(host->cmd->flags &MMC_RSP_BUSY ) && !host->data && - host->cmd->opcode ==MMC_STOP_TRANSMISSION ) - *mask &= ~SDHCI_INT_DATA_END ; -if (intmask &SDHCI_INT_RESPONSE )sdhci_finish_command (host); }
@@ -2680,8 +2679,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) }if (intmask &SDHCI_INT_CMD_MASK ) -sdhci_cmd_irq (host, intmask &SDHCI_INT_CMD_MASK , - &intmask); +sdhci_cmd_irq (host, intmask &SDHCI_INT_CMD_MASK );if (intmask &SDHCI_INT_DATA_MASK )sdhci_data_irq (host, intmask &SDHCI_INT_DATA_MASK );
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 2/4 mmc: sdhci: Rename sdhci_set_power() to sdhci_set_power_noreg()
In reply to Adrian HunterUnlike other cases, sdhci_set_power() does not reflect the default implementation of the ->set_power() callback. Rename it and create sdhci_set_power() that is the default implementation.
--- drivers/mmc/host/sdhci-pxav3.c | 2 +- drivers/mmc/host/sdhci.c | 26 +++++++++++++------------- drivers/mmc/host/sdhci.h | 2 ++ 3 files changed, 16 insertions(+), 14 deletions(-)
drivers/mmc/host/sdhci-pxav3.c +1 -1
@@ -315,7 +315,7 @@ static void pxav3_set_power(struct sdhci_host *host, unsigned char mode,struct mmc_host *mmc = host->mmc;u8 pwr = host->pwr; -sdhci_set_power (host, mode, vdd); +sdhci_set_power_noreg (host, mode, vdd);if (host->pwr == pwr)return ;
drivers/mmc/host/sdhci.c +13 -13
@@ -1394,8 +1394,8 @@ static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode,sdhci_writeb (host,0 ,SDHCI_POWER_CONTROL ); } -void sdhci_set_power (struct sdhci_host *host,unsigned char mode, -unsigned short vdd) +void sdhci_set_power_noreg (struct sdhci_host *host,unsigned char mode, +unsigned short vdd) {u8 pwr =0 ;
@@ -1459,20 +1459,17 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode,mdelay (10 ); } } -EXPORT_SYMBOL_GPL (sdhci_set_power); +EXPORT_SYMBOL_GPL (sdhci_set_power_noreg); -static void __sdhci_set_power (struct sdhci_host *host,unsigned char mode, -unsigned short vdd) +void sdhci_set_power (struct sdhci_host *host,unsigned char mode, +unsigned short vdd) { -struct mmc_host *mmc = host->mmc; - -if (host->ops->set_power) - host->ops->set_power (host, mode, vdd); -else if (!IS_ERR (mmc->supply.vmmc)) -sdhci_set_power_reg (host, mode, vdd); +if (IS_ERR (host->mmc->supply.vmmc)) +sdhci_set_power_noreg (host, mode, vdd);else -sdhci_set_power (host, mode, vdd); +sdhci_set_power_reg (host, mode, vdd); } +EXPORT_SYMBOL_GPL (sdhci_set_power);/*****************************************************************************\ * *
@@ -1613,7 +1610,10 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) } } -__sdhci_set_power (host, ios->power_mode, ios->vdd); +if (host->ops->set_power) + host->ops->set_power (host, ios->power_mode, ios->vdd); +else +sdhci_set_power (host, ios->power_mode, ios->vdd);if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks (host, ios->power_mode);
drivers/mmc/host/sdhci.h +2 -0
@@ -683,6 +683,8 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,void sdhci_set_clock (struct sdhci_host *host,unsigned int clock);void sdhci_set_power (struct sdhci_host *host,unsigned char mode,unsigned short vdd); +void sdhci_set_power_noreg (struct sdhci_host *host,unsigned char mode, +unsigned short vdd);void sdhci_set_bus_width (struct sdhci_host *host,int width);void sdhci_reset (struct sdhci_host *host,u8 mask);void sdhci_set_uhs_signaling (struct sdhci_host *host,unsigned timing);
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 3/4 mmc: sdhci-pci: Let devices define their own sdhci_ops
In reply to Adrian HunterLet devices define their own sdhci_ops so that device-specific variations can be implemented without adding quirks.
--- drivers/mmc/host/sdhci-pci-core.c | 4 +++- drivers/mmc/host/sdhci-pci.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-pci-core.c +3 -1
@@ -1648,7 +1648,9 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot( } host->hw_name ="PCI" ; - host->ops = &sdhci_pci_ops; + host->ops = chip->fixes && chip->fixes->ops ? + chip->fixes->ops : + &sdhci_pci_ops; host->quirks = chip->quirks; host->quirks2 = chip->quirks2;
drivers/mmc/host/sdhci-pci.h +2 -0
@@ -65,6 +65,8 @@ struct sdhci_pci_fixes {int (*suspend) (struct sdhci_pci_chip *);int (*resume) (struct sdhci_pci_chip *); + +const struct sdhci_ops *ops; };struct sdhci_pci_slot {
Signature · 1 line
1.9.1
Adrian Hunter
maintainerPATCH 4/4 mmc: sdhci-pci: Fix bus power failing to enable for some Intel controllers
In reply to Adrian HunterSome Intel controllers (e.g. BXT) might fail to set bus power after a D3 -> D0 transition due to the present state not yet having propagated. Retry for up to 2 milliseconds.
--- drivers/mmc/host/sdhci-pci-core.c | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
drivers/mmc/host/sdhci-pci-core.c +50 -0
@@ -32,6 +32,14 @@#include "sdhci-pci.h" #include "sdhci-pci-o2micro.h" +static int sdhci_pci_enable_dma (struct sdhci_host *host); +static void sdhci_pci_set_bus_width (struct sdhci_host *host,int width); +static void sdhci_pci_hw_reset (struct sdhci_host *host); +static int sdhci_pci_select_drive_strength (struct sdhci_host *host, +struct mmc_card *card, +unsigned int max_dtr,int host_drv, +int card_drv,int *drv_type); +/*****************************************************************************\ * * * Hardware specific quirk handling *
@@ -390,6 +398,45 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)return 0 ; } +#define SDHCI_INTEL_PWR_TIMEOUT_CNT 20 +#define SDHCI_INTEL_PWR_TIMEOUT_UDELAY 100 + +static void sdhci_intel_set_power (struct sdhci_host *host,unsigned char mode, +unsigned short vdd) +{ +int cntr; +u8 reg; + +sdhci_set_power (host, mode, vdd); + +if (mode ==MMC_POWER_OFF ) +return ; + +/* +* Bus power might not enable after D3 -> D0 transition due to the +* present state not yet having propagated. Retry for up to 2ms. +*/ +for (cntr =0 ; cntr <SDHCI_INTEL_PWR_TIMEOUT_CNT ; cntr++) { + reg =sdhci_readb (host,SDHCI_POWER_CONTROL ); +if (reg &SDHCI_POWER_ON ) +break ; +udelay (SDHCI_INTEL_PWR_TIMEOUT_UDELAY ); + reg |=SDHCI_POWER_ON ; +sdhci_writeb (host, reg,SDHCI_POWER_CONTROL ); + } +} + +static const struct sdhci_ops sdhci_intel_byt_ops = { + .set_clock = sdhci_set_clock, + .set_power = sdhci_intel_set_power, + .enable_dma = sdhci_pci_enable_dma, + .set_bus_width = sdhci_pci_set_bus_width, + .reset = sdhci_reset, + .set_uhs_signaling = sdhci_set_uhs_signaling, + .hw_reset = sdhci_pci_hw_reset, + .select_drive_strength = sdhci_pci_select_drive_strength, +}; +static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { .allow_runtime_pm = true, .probe_slot = byt_emmc_probe_slot,
@@ -397,6 +444,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 | SDHCI_QUIRK2_STOP_WITH_TC, + .ops = &sdhci_intel_byt_ops, };static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
@@ -405,6 +453,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { SDHCI_QUIRK2_PRESET_VALUE_BROKEN, .allow_runtime_pm = true, .probe_slot = byt_sdio_probe_slot, + .ops = &sdhci_intel_byt_ops, };static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
@@ -415,6 +464,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { .allow_runtime_pm = true, .own_cd_for_runtime_pm = true, .probe_slot = byt_sd_probe_slot, + .ops = &sdhci_intel_byt_ops, };/* Define Host controllers for Intel Merrifield platform */
Signature · 1 line
1.9.1
Ulf Hansson
AppliedQuoted 20 lines · Adrian Hunter
Hi
Here are a couple of minor fixes. While it would be good to have them in 4.9 or a 4.9-rc, they are not urgent.
Adrian Hunter (4):
mmc: sdhci: FixSDHCI_QUIRK2_STOP_WITH_TC
mmc: sdhci: Renamesdhci_set_power()tosdhci_set_power_noreg()
mmc: sdhci-pci: Let devices define their ownsdhci_ops
mmc: sdhci-pci: Fix bus power failing to enable for some Intel controllersdrivers/mmc/host/sdhci-pci-core.c | 54 ++++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci-pci.h | 2 ++ drivers/mmc/host/sdhci-pxav3.c | 2 +- drivers/mmc/host/sdhci.c | 40 ++++++++++++++--------------- drivers/mmc/host/sdhci.h | 2 ++ 5 files changed, 77 insertions(+), 23 deletions(-)
Quoted 2 lines
Regards
Adrian
Thanks, applied for fixes!
Kind regards
Uffe