mmc: renesas_sdhi: support manual calibration
Subsystems (2)
Wolfram Sang
maintainercover mmc: renesas_sdhi: support manual calibration
Some R-Car Gen3 SoCs need corrections after they tuned to HS400. This series implements that. Please have a look at the patch descriptions for details.
The origins were patches in the BSP from Takeshi Saito. However, this series is heavily refactored:
* DT configuration was dropped, there is no user for it
* the fixup offset is currently hardcoded because all affected SoCs use the same offset. We can add it later to the struct quirks if needed
* disabling HS400 for some SoCs was already upstreamed
* the callback in the TMIO was made more generic to allow other use cases in the future
* less impact on the TMIO driver by stricter seperation of the SDHI parts
* clearing the runtime flag in the error case was moved from select_tuning to hw_reset to catch all error cases
* cosmetic fixups
There is a branch for testing here:
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/topic/sdhi-manual-calib
The patches were developed against mmc/next. However, the above branch is based on v5.2-rc6 with some cherry-picked patches from mmc/next, so Geert can consume it easier for his renesas-drivers branch. There are two more patches in that branch worth mentioning. A clk driver WIP patch which I needed to get HS400 on my M3-N working at all. We are discussing this patch internally right now and its upstreaming is a seperate issue.
Also, there is a debug patch on top. I can't test that the manual fixup values improve HS400 because the actual issue only shows with temperatures I can't (and don't want to) provide here in my office. So, the debug patches add some trace_printk to demonstrate the functions are called and the outputs match the intended state machine.
Here are examples (with comments) from my M3-N. If you review this, please don't trust anything I write here.
An unaffected SDHI instance (no eMMC):
Adjustment and runtime flag get disabled during the reset in the beginning of the initialization. The same reset routine will be called when tuning fails.
kworker/0:2-965 [000] .... 1.413767: renesas_sdhi_reset_hs400_mode: ee100000.sd: adjustment disabled kworker/0:2-965 [000] .... 1.413768: renesas_sdhi_hw_reset: ee100000.sd: reset! flag disabled
An SDHI instance with a HS400 capable eMMC connected:
When preparing HS400 tuning, (potential) old HS400 tuning gets reset and the manual adjustment gets disabled, the runtime flag (signalling new manual adjustment will be needed) is set:
kworker/0:1H-1009 [000] .... 1.864628: renesas_sdhi_reset_hs400_mode: ee140000.sd: adjustment disabled kworker/0:1H-1009 [000] .... 1.864629: renesas_sdhi_prepare_hs400_tuning: ee140000.sd: flag enabled
Lots of tuning CMDs:
kworker/0:2-965 [000] .... 1.864673: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864706: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864735: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864765: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864797: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864825: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864855: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864882: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864909: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864935: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864966: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.864998: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.865025: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.865052: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.865079: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.865106: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.865130: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 1 kworker/0:2-965 [000] .... 1.865603: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 1
First CMD13 after tuning discovered, enable adjustment, clear runtime flag:
kworker/0:2-965 [000] .... 1.865609: renesas_sdhi_fixup_request: ee140000.sd: adjustment enabled, flag disabled kworker/0:2-965 [000] .... 1.865635: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.865654: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0 kworker/0:2-965 [000] .... 1.865676: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.866143: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0 kworker/0:2-965 [000] .... 1.866601: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0
Reading multiple blocks (CMD18) above failed
kworker/0:2-965 [000] .... 1.866867: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.867113: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0 kworker/0:2-965 [000] .... 1.867137: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.867384: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0 kworker/0:2-965 [000] .... 1.867409: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.867651: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0
Seems like another retune is need, start cycle again:
kworker/0:1H-1009 [000] .... 1.867880: renesas_sdhi_reset_hs400_mode: ee140000.sd: adjustment disabled kworker/0:1H-1009 [000] .... 1.867882: renesas_sdhi_prepare_hs400_tuning: ee140000.sd: flag enabled kworker/0:2-965 [000] .... 1.867926: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.867958: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.867986: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868019: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868048: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868076: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868103: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868129: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868156: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868181: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868208: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868237: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868267: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868294: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868321: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868347: renesas_sdhi_fixup_request: ee140000.sd: opcode 21, flag 1 kworker/0:2-965 [000] .... 1.868370: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 1 kworker/0:2-965 [000] .... 1.868837: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 1 kworker/0:2-965 [000] .... 1.868842: renesas_sdhi_fixup_request: ee140000.sd: adjustment enabled, flag disabled kworker/0:2-965 [000] .... 1.868869: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.868888: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0 kworker/0:2-965 [000] .... 1.868913: renesas_sdhi_fixup_request: ee140000.sd: opcode 6, flag 0 kworker/0:2-965 [000] .... 1.869381: renesas_sdhi_fixup_request: ee140000.sd: opcode 13, flag 0
Finally, we can read lots of blocks without problems. The manual adjustment is still enabled as desired:
kworker/0:2-965 [000] .... 1.870027: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0 kworker/0:2-965 [000] .... 1.871300: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0 kworker/0:2-965 [000] .... 1.871454: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0 kworker/0:2-965 [000] .... 1.871579: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0 kworker/0:2-965 [000] .... 1.871712: renesas_sdhi_fixup_request: ee140000.sd: opcode 18, flag 0
...
Okay, I know this is a lot of text, but it is a subtle issue, so I wanted to provide the details which enable other people to actually review what I have done.
Shimoda-san, if the BSP team could have a look and share their opinion or could test, I'd be most grateful.
Thanks and happy hacking,
Wolfram
Wolfram Sang (4):
mmc: renesas_sdhi: keep sorting
mmc: tmio: add generic hook to fixup after a completed request
mmc: renesas_sdhi: make quirks info accessible outside probe()
mmc: renesas_sdhi: support manual calibration
drivers/mmc/host/renesas_sdhi.h | 9 ++ drivers/mmc/host/renesas_sdhi_core.c | 129 +++++++++++++++++++++++++-- drivers/mmc/host/tmio_mmc.h | 1 + drivers/mmc/host/tmio_mmc_core.c | 3 + 4 files changed, 135 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
Wolfram Sang
maintainerPATCH 1/4 mmc: renesas_sdhi: keep sorting
The two devices next to each other are super similar, but still, let's keep the alphanumeric sorting for easier additions later.
--- drivers/mmc/host/renesas_sdhi_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/renesas_sdhi_core.c +1 -1
@@ -624,10 +624,10 @@ static const struct renesas_sdhi_quirks sdhi_quirks_nohs400 = { };static const struct soc_device_attribute sdhi_quirks_match[] = { + { .soc_id ="r8a774a1" , .revision ="ES1.[012]" , .data = &sdhi_quirks_4tap_nohs400 }, { .soc_id ="r8a7795" , .revision ="ES1.*" , .data = &sdhi_quirks_4tap_nohs400 }, { .soc_id ="r8a7795" , .revision ="ES2.0" , .data = &sdhi_quirks_4tap }, { .soc_id ="r8a7796" , .revision ="ES1.[012]" , .data = &sdhi_quirks_4tap_nohs400 }, - { .soc_id ="r8a774a1" , .revision ="ES1.[012]" , .data = &sdhi_quirks_4tap_nohs400 }, { .soc_id ="r8a77980" , .data = &sdhi_quirks_nohs400 }, {/* Sentinel. */ }, };
Signature · 1 line
2.20.1
Re: [PATCH RFT 1/4] mmc: renesas_sdhi: keep sorting
Quoted 4 lines · Wolfram Sang
The two devices next to each other are super similar, but still, let's keep the alphanumeric sorting for easier additions later.
Signed-off-by Wolfram Sang <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Wolfram Sang
maintainerPATCH 2/4 mmc: tmio: add generic hook to fixup after a completed request
In reply to Wolfram SangSadly, due to HW bugs, we need a callback to work around issues just before completing the request.
--- drivers/mmc/host/tmio_mmc.h | 1 + drivers/mmc/host/tmio_mmc_core.c | 3 +++ 2 files changed, 4 insertions(+)
drivers/mmc/host/tmio_mmc.h +1 -0
@@ -178,6 +178,7 @@ struct tmio_mmc_host {void (*hw_reset)(struct tmio_mmc_host *host);void (*prepare_tuning)(struct tmio_mmc_host *host,unsigned long tap);bool (*check_scc_error)(struct tmio_mmc_host *host); +void (*fixup_request)(struct tmio_mmc_host *host,struct mmc_request *mrq);/* * Mandatory callback for tuning to occur which is optional for SDR50
drivers/mmc/host/tmio_mmc_core.c +3 -0
@@ -852,6 +852,9 @@ static void tmio_mmc_finish_request(struct tmio_mmc_host *host)return ; } +if (host->fixup_request) + host->fixup_request (host, mrq); +mmc_request_done (host->mmc, mrq); }
Signature · 1 line
2.20.1
Re: [PATCH RFT 2/4] mmc: tmio: add generic hook to fixup after a completed request
Quoted 4 lines · Wolfram Sang
Sadly, due to HW bugs, we need a callback to work around issues just before completing the request.
Signed-off-by Wolfram Sang <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Wolfram Sang
maintainerPATCH 3/4 mmc: renesas_sdhi: make quirks info accessible outside probe()
In reply to Wolfram SangWe will need that for a later patch.
--- drivers/mmc/host/renesas_sdhi.h | 6 ++++++ drivers/mmc/host/renesas_sdhi_core.c | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/mmc/host/renesas_sdhi.h +6 -0
@@ -33,6 +33,11 @@ struct renesas_sdhi_of_data {unsigned short max_segs; }; +struct renesas_sdhi_quirks { +bool hs400_disabled; +bool hs400_4taps; +}; +struct tmio_mmc_dma {enum dma_slave_buswidth dma_buswidth;bool (*filter)(struct dma_chan *chan,void *arg);
@@ -46,6 +51,7 @@ struct renesas_sdhi {struct clk *clk_cd;struct tmio_mmc_data mmc_data;struct tmio_mmc_dma dma_priv; +const struct renesas_sdhi_quirks *quirks;struct pinctrl *pinctrl;struct pinctrl_state *pins_default, *pins_uhs;void __iomem *scc_ctl;
drivers/mmc/host/renesas_sdhi_core.c +1 -5
@@ -46,11 +46,6 @@#define SDHI_VER_GEN3_SD 0xcc10#define SDHI_VER_GEN3_SDMMC 0xcd10 -struct renesas_sdhi_quirks { -bool hs400_disabled; -bool hs400_4taps; -}; -static void renesas_sdhi_sdbuf_width (struct tmio_mmc_host *host,int width) {u32 val;
@@ -662,6 +657,7 @@ int renesas_sdhi_probe(struct platform_device *pdev,if (!priv)return -ENOMEM ; + priv->quirks = quirks; mmc_data = &priv->mmc_data; dma_priv = &priv->dma_priv;
Signature · 1 line
2.20.1
Re: [PATCH RFT 3/4] mmc: renesas_sdhi: make quirks info accessible outside probe()
Quoted 3 lines · Wolfram Sang
We will need that for a later patch.
Signed-off-by Wolfram Sang <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Wolfram Sang
maintainerPATCH 4/4 mmc: renesas_sdhi: support manual calibration
In reply to Wolfram SangSome R-Car Gen3 SoCs need some manual correction of timing parameters after the automatic tuning has finished but before next CMD13 is completed. This patch implements that by this state machine:
- introducing a configuration flag ('manual_calibration') to mark affected SoCs
- iff the configuration flag is set the 'fixup_request' callback is populated during probe
- iff the configuration flag is set, a runtime flag ('needs_adjust_hs400') is set when HS400 tuning gets prepared
- if tuning HS400 fails, the runtime flag is cleared again
- the callback will check the runtime flag and enable the corrected manual mode if the flag is set and CMD13 is encountered
- at the end of the enablement the runtime flag is cleared
- iff the configuration flag is set, the manual mode will be disabled when HS400 gets downgraded
There also some helper functions added to access the TMPPORT registers. The actual fixup value is SoC specific and also added to the quirks struct.
--- drivers/mmc/host/renesas_sdhi.h | 3 + drivers/mmc/host/renesas_sdhi_core.c | 121 ++++++++++++++++++++++++++- 2 files changed, 123 insertions(+), 1 deletion(-)
drivers/mmc/host/renesas_sdhi.h +3 -0
@@ -36,6 +36,8 @@ struct renesas_sdhi_of_data {struct renesas_sdhi_quirks {bool hs400_disabled;bool hs400_4taps; +bool manual_calibration; +u8 manual_calibration_fixup; };struct tmio_mmc_dma {
@@ -57,6 +59,7 @@ struct renesas_sdhi {void __iomem *scc_ctl;u32 scc_tappos;u32 scc_tappos_hs400; +bool needs_adjust_hs400; };#define host_to_priv (host) \
drivers/mmc/host/renesas_sdhi_core.c +120 -1
187 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 10 lines
drivers/mmc/host/renesas_sdhi_core.c +3
-0@@ -403,13 +492,20 @@ static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host, SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL) & sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2)); +if (priv->quirks->manual_calibration) +renesas_sdhi_adjust_hs400_mode_disable (host); +sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL ,CLK_CTL_SCLKEN |sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL ));
drivers/mmc/host/renesas_sdhi_core.c static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host, · line 508
Quoted 10 lines
drivers/mmc/host/renesas_sdhi_core.c +5
-1}static void renesas_sdhi_prepare_hs400_tuning (struct tmio_mmc_host *host) { -renesas_sdhi_reset_hs400_mode (host,host_to_priv (host)); +struct renesas_sdhi *priv =host_to_priv (host); + +renesas_sdhi_reset_hs400_mode (host, priv); +if (priv->quirks->manual_calibration) + priv->needs_adjust_hs400 = true;
I need to check for a valid 'quirks' here first!