Add SD UHS-I and eMMC HS200 support for eSDHC
v5 cover Add SD UHS-I and eMMC HS200 support for eSDHC
It's complicated to support SD UHS-I and eMMC HS200 for eSDHC because there're many differences between eSDHC and SD/eMMC spec. Several differences as below must be considered:
1. Peripheral clock must be used instead of platform clock.
- eSDHC could select peripheral clock or platform clock as its clock source. According to RM, UHS-I/HS200 must use peripheral clock since it supports higher frequency than platform clock.
- Patch 1 is to support this.
2. Signal voltage switching requires a control circuit out of eSDHC.
- eSDHC supports signal voltage switch from 3.3v to 1.8v by eSDHC_PROCTL[VOLT_SEL] bit. This bit changes the value of output signal SDHC_VS, and there must be a control circuit out of eSDHC to change the signal voltage according to SDHC_VS output signal.
- Patch 2 is to support this.
3. eSDHC uses tuning block for tuning procedure.
- Tuning clock control register must be configured before tuning.
- Patch 3 is to support this.
4. Delay is needed between tuning cycles for HS200 tuning.
- Once a patch removed mdelay between tuning cycles.
But eSDHC needs it.
- Patch 4 and patch 5 is to support this.
Adrian Hunter (1):
mmc: sdhci: Control the delay between tuning commands
Yangbo Lu (4):
mmc: sdhci-of-esdhc: add peripheral clock support
mmc: sdhci-of-esdhc: add support for signal voltage switch
mmc: sdhci-of-esdhc: add tuning support
mmc: sdhci-of-esdhc: add delay between tuning cycles
drivers/mmc/host/sdhci-esdhc.h | 7 ++ drivers/mmc/host/sdhci-of-esdhc.c | 168 +++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci.c | 11 ++- drivers/mmc/host/sdhci.h | 2 + 4 files changed, 183 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.0.27.g96db324
PATCH v5 1/5 mmc: sdhci-of-esdhc: add peripheral clock support
eSDHC could select peripheral clock or platform clock as clock source by the PCS bit of eSDHC Control Register, and this bit couldn't be reset by software reset for all. In default, the platform clock is used. But we have to use peripheral clock since it has a higher frequency to support eMMC HS200 mode and SD UHS-I mode. This patch is to add peripheral clock support and use it instead of platform clock if it's declared in eSDHC dts node.
---
Changes for v2:
- None
Changes for v3:
- None
Changes for v4:
- Added clk_put()
- Used udelay() to poll ESDHC_CLOCK_STABLE
Changes for v5:
- Included ktime.h
- Added Adrian's ACK
--- drivers/mmc/host/sdhci-esdhc.h | 1 + drivers/mmc/host/sdhci-of-esdhc.c | 73 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +1 -0
@@ -54,6 +54,7 @@/* Control Register for DMA transfer */ #define ESDHC_DMA_SYSCTL 0x40c +#define ESDHC_PERIPHERAL_CLK_SEL 0x00080000#define ESDHC_DMA_SNOOP 0x00000040#endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
drivers/mmc/host/sdhci-of-esdhc.c +71 -2
116 lines not on this page · raw message
Signature · 1 line
2.1.0.27.g96db324
PATCH v5 2/5 mmc: sdhci-of-esdhc: add support for signal voltage switch
In reply to Yangbo LueSDHC supports signal voltage switch from 3.3v to 1.8v by eSDHC_PROCTL[VOLT_SEL] bit. This bit changes the value of output signal SDHC_VS, and there must be a control circuit out of eSDHC to change the signal voltage according to SDHC_VS output signal.
---
Changes for v2:
- Used Adrain's method to support voltage switching:
host->mmc_host_ops.start_signal_voltage_switch =
esdhc_signal_voltage_switch;Changes for v3:
- Put .start_signal_voltage_switch assigning after IS_ERR(host) check.
Changes for v4:
- None
Changes for v5:
- Added Adrian's ACK
--- drivers/mmc/host/sdhci-esdhc.h | 1 + drivers/mmc/host/sdhci-of-esdhc.c | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
drivers/mmc/host/sdhci-esdhc.h +1 -0
@@ -37,6 +37,7 @@/* Protocol Control Register */ #define ESDHC_PROCTL 0x28 +#define ESDHC_VOLT_SEL 0x00000400#define ESDHC_CTRL_4BITBUS (0x1 << 1)#define ESDHC_CTRL_8BITBUS (0x2 << 1)#define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
drivers/mmc/host/sdhci-of-esdhc.c +74 -0
92 lines not on this page · raw message
Signature · 1 line
2.1.0.27.g96db324
Re: [v5, 2/5] mmc: sdhci-of-esdhc: add support for signal voltage switch
[...]
drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_reset(struct sdhci_host *host, u8 mask) · line 608
Quoted 9 lines
drivers/mmc/host/sdhci-of-esdhc.c +9
-0+switch (ios->signal_voltage) { +case MMC_SIGNAL_VOLTAGE_330 : + val &= ~ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); +return 0 ; +case MMC_SIGNAL_VOLTAGE_180 : + scfg_node =of_find_matching_node (NULL , scfg_device_ids); +if (scfg_node) + scfg_base =of_iomap (scfg_node,0 );
Why don't you do this at probe time instead of every time you do the voltage switch?
Never mind at this point, I have queued this up for 4.12, however feel free to send a new patch on top.
Quoted 14 lines
drivers/mmc/host/sdhci-of-esdhc.c +14
-0+if (scfg_base) { + sdhciovselcr =SDHCIOVSELCR_TGLEN | +SDHCIOVSELCR_VSELVAL ; +iowrite32be (sdhciovselcr, + scfg_base +SCFG_SDHCIOVSELCR ); + + val |=ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); +mdelay (5 ); + + sdhciovselcr =SDHCIOVSELCR_TGLEN | +SDHCIOVSELCR_SDHC_VS ; +iowrite32be (sdhciovselcr, + scfg_base +SCFG_SDHCIOVSELCR );
drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_reset(struct sdhci_host *host, u8 mask) · line 632
Quoted 10 lines
drivers/mmc/host/sdhci-of-esdhc.c +10
-0+iounmap (scfg_base); + }else { + val |=ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); + } +return 0 ; +default : +return 0 ; + } +}
[...]
Kind regards
Uffe
RE: [v5, 2/5] mmc: sdhci-of-esdhc: add support for signal voltage switch
Hi Uffe,
Quoted 18 lines
-----Original Message-----
From: Ulf Hansson [mailto:[email protected]]
Sent: Thursday, April 20, 2017 10:06 PM
To: Y.B. Lu
Cc: [email protected]; Adrian Hunter; Xiaobo Xie
Subject: Re: [v5, 2/5] mmc: sdhci-of-esdhc: add support for signal voltage switch[...]
drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_reset(struct sdhci_host *host, u8 mask)
Quoted 7 lines
drivers/mmc/host/sdhci-of-esdhc.c +7
-0+switch (ios->signal_voltage) { +case MMC_SIGNAL_VOLTAGE_330 : + val &= ~ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); +return 0 ; +case MMC_SIGNAL_VOLTAGE_180 : + scfg_node = of_find_matching_node(NULL,
scfg_device_ids);
Quoted 8 lines
drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_reset(struct sdhci_host *host, u8 mask) · line 608
Quoted 2 lines
drivers/mmc/host/sdhci-of-esdhc.c +2
-0+if (scfg_node) + scfg_base =of_iomap (scfg_node,0 );Why don't you do this at probe time instead of every time you do the voltage switch?
Never mind at this point, I have queued this up for 4.12, however feel free to send a new patch on top.
[Lu Yangbo-B47093] Thank you very much for point out this. I will work on another patch to fix this :)
- Yangbo Lu
Quoted 30 lines
Quoted 15 lines
drivers/mmc/host/sdhci-of-esdhc.c +14
-0+if (scfg_base) { + sdhciovselcr =SDHCIOVSELCR_TGLEN | +SDHCIOVSELCR_VSELVAL ; +iowrite32be (sdhciovselcr, + scfg_base +SCFG_SDHCIOVSELCR ); + + val |=ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); +mdelay (5 ); + + sdhciovselcr =SDHCIOVSELCR_TGLEN | +SDHCIOVSELCR_SDHC_VS ; +iowrite32be (sdhciovselcr, + scfg_base +SCFG_SDHCIOVSELCR );drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_reset(struct sdhci_host *host, u8 mask) · line 632
Quoted 10 lines
drivers/mmc/host/sdhci-of-esdhc.c +10
-0+iounmap (scfg_base); + }else { + val |=ESDHC_VOLT_SEL ; +sdhci_writel (host, val,ESDHC_PROCTL ); + } +return 0 ; +default : +return 0 ; + } +}[...]
Kind regards
Uffe
PATCH v5 3/5 mmc: sdhci-of-esdhc: add tuning support
In reply to Yangbo LueSDHC uses tuning block for tuning procedure. So the tuning block control register must be configured properly before tuning.
---
Changes for v2:
- Replaced old function for mmc_host_ops.execute_tuning with esdhc_execute_tuning to support eSDHC tuning.
Changes for v3:
- Put .execute_tuning assigning after after IS_ERR(host) check.
Changes for v4:
- None
Changes for v5:
- Added Adrian's ACK
--- drivers/mmc/host/sdhci-esdhc.h | 5 +++++ drivers/mmc/host/sdhci-of-esdhc.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+)
drivers/mmc/host/sdhci-esdhc.h +5 -0
@@ -53,9 +53,14 @@#define ESDHC_CLOCK_HCKEN 0x00000002#define ESDHC_CLOCK_IPGEN 0x00000001 +/* Tuning Block Control Register */ +#define ESDHC_TBCTL 0x120 +#define ESDHC_TB_EN 0x00000004 +/* Control Register for DMA transfer */ #define ESDHC_DMA_SYSCTL 0x40c#define ESDHC_PERIPHERAL_CLK_SEL 0x00080000 +#define ESDHC_FLUSH_ASYNC_FIFO 0x00040000#define ESDHC_DMA_SNOOP 0x00000040#endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
drivers/mmc/host/sdhci-of-esdhc.c +20 -0
@@ -631,6 +631,25 @@ static int esdhc_signal_voltage_switch(struct mmc_host *mmc, } } +static int esdhc_execute_tuning (struct mmc_host *mmc,u32 opcode) +{ +struct sdhci_host *host =mmc_priv (mmc); +u32 val; + +/* Use tuning block for tuning procedure */ +esdhc_clock_enable (host, false); + val =sdhci_readl (host,ESDHC_DMA_SYSCTL ); + val |=ESDHC_FLUSH_ASYNC_FIFO ; +sdhci_writel (host, val,ESDHC_DMA_SYSCTL ); + + val =sdhci_readl (host,ESDHC_TBCTL ); + val |=ESDHC_TB_EN ; +sdhci_writel (host, val,ESDHC_TBCTL ); +esdhc_clock_enable (host, true); + +return sdhci_execute_tuning (mmc, opcode); +} +#ifdef CONFIG_PM_SLEEP static u32 esdhc_proctl;static int esdhc_of_suspend (struct device *dev)
@@ -790,6 +809,7 @@ static int sdhci_esdhc_probe(struct platform_device *pdev) host->mmc_host_ops.start_signal_voltage_switch = esdhc_signal_voltage_switch; + host->mmc_host_ops.execute_tuning = esdhc_execute_tuning;esdhc_init (pdev, host);
Signature · 1 line
2.1.0.27.g96db324
PATCH v5 4/5 mmc: sdhci: Control the delay between tuning commands
In reply to Yangbo LuFrom: Adrian Hunter <[email protected]>
The delay between tuning commands for SD cards is not part of the specification. A driver that needs it probably needs it for eMMC too, whereas most drivers would probably like to set it to 0. Make it a host member (host->tuning_delay) that defaults to the existing behaviour. Drivers can set it to zero to eliminate the delay, or set it to a positive value to always have a delay.
---
Changes for v2:
- None
Changes for v3:
- Used a host member for tuning delay instead of a quirk.(Adrian's patch)
- Addressed warning in checkpatch.
Changes for v4:
- None
Changes for v5:
- None
--- drivers/mmc/host/sdhci.c | 11 ++++++++--- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci.c +8 -3
@@ -2108,9 +2108,9 @@ static void __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)break ; } -/* eMMC spec does not require a delay between tuning cycles */ -if (opcode ==MMC_SEND_TUNING_BLOCK ) -mdelay (1 ); +/* Spec does not require a delay between tuning cycles */ +if (host->tuning_delay >0 ) +mdelay (host->tuning_delay); } pr_info("%s: Tuning failed, falling back to fixed sampling clock\n",
@@ -2172,6 +2172,9 @@ int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) host->mmc->retune_period = tuning_count; +if (host->tuning_delay <0 ) + host->tuning_delay = opcode ==MMC_SEND_TUNING_BLOCK ; +sdhci_start_tuning (host);__sdhci_execute_tuning (host, opcode);
@@ -3114,6 +3117,8 @@ struct sdhci_host *sdhci_alloc_host(struct device *dev, host->cqe_ier =SDHCI_CQE_INT_MASK ; host->cqe_err_ier =SDHCI_CQE_INT_ERR_MASK ; + host->tuning_delay =-1 ; +return host; }
drivers/mmc/host/sdhci.h +2 -0
@@ -538,6 +538,8 @@ struct sdhci_host {#define SDHCI_TUNING_MODE_1 0#define SDHCI_TUNING_MODE_2 1#define SDHCI_TUNING_MODE_3 2 +/* Delay (ms) between tuning commands */ +int tuning_delay;unsigned long private[0 ]____cacheline_aligned ; };
Signature · 1 line
2.1.0.27.g96db324
PATCH v5 5/5 mmc: sdhci-of-esdhc: add delay between tuning cycles
In reply to Yangbo LuIt's observed that eSDHC needed delay between tuning cycles for HS200 successful tuning. This patch is to set 1ms delay for that.
---
Changes for v2:
- None
Changes for v3:
- Used a host member for tuning delay instead of a quirk.
Changes for v4:
- None
Changes for v5:
- Added Adrian's ACK
--- drivers/mmc/host/sdhci-of-esdhc.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci-of-esdhc.c +1 -0
@@ -810,6 +810,7 @@ static int sdhci_esdhc_probe(struct platform_device *pdev) host->mmc_host_ops.start_signal_voltage_switch = esdhc_signal_voltage_switch; host->mmc_host_ops.execute_tuning = esdhc_execute_tuning; + host->tuning_delay =1 ;esdhc_init (pdev, host);
Signature · 1 line
2.1.0.27.g96db324
Ulf Hansson
AppliedQuoted 31 lines · Yangbo Lu
It's complicated to support SD UHS-I and eMMC HS200 for eSDHC because there're many differences between eSDHC and SD/eMMC spec. Several differences as below must be considered:
1. Peripheral clock must be used instead of platform clock.
- eSDHC could select peripheral clock or platform clock as its clock source. According to RM, UHS-I/HS200 must use peripheral clock since it supports higher frequency than platform clock.
- Patch 1 is to support this.
2. Signal voltage switching requires a control circuit out of eSDHC.
- eSDHC supports signal voltage switch from 3.3v to 1.8v by eSDHC_PROCTL[VOLT_SEL] bit. This bit changes the value of output signalSDHC_VS, and there must be a control circuit out of eSDHC to change the signal voltage according toSDHC_VSoutput signal.
- Patch 2 is to support this.
3. eSDHC uses tuning block for tuning procedure.
- Tuning clock control register must be configured before tuning.
- Patch 3 is to support this.
4. Delay is needed between tuning cycles for HS200 tuning.
- Once a patch removed mdelay between tuning cycles.
But eSDHC needs it.
- Patch 4 and patch 5 is to support this.Adrian Hunter (1):
mmc: sdhci: Control the delay between tuning commandsYangbo Lu (4):
mmc: sdhci-of-esdhc: add peripheral clock support
mmc: sdhci-of-esdhc: add support for signal voltage switch
mmc: sdhci-of-esdhc: add tuning support
mmc: sdhci-of-esdhc: add delay between tuning cycles
Quoted 9 lines
drivers/mmc/host/sdhci-esdhc.h | 7 ++ drivers/mmc/host/sdhci-of-esdhc.c | 168 +++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci.c | 11 ++- drivers/mmc/host/sdhci.h | 2 + 4 files changed, 183 insertions(+), 5 deletions(-)--
2.1.0.27.g96db324
Thanks, applied for next!
Kind regards
Uffe