0156-mmc-mediatek-add-stop_clk-fix-and-enhance_rx-support.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. From 9257240bcaf8f9ee6878357e00e7ab511ad6d325 Mon Sep 17 00:00:00 2001
  2. From: Chaotian Jing <[email protected]>
  3. Date: Mon, 16 Oct 2017 09:46:35 +0800
  4. Subject: [PATCH 156/224] mmc: mediatek: add stop_clk fix and enhance_rx
  5. support
  6. mt2712 supports stop_clk fix and enhance_rx, which can improve
  7. host stability.
  8. Signed-off-by: Chaotian Jing <[email protected]>
  9. Tested-by: Sean Wang <[email protected]>
  10. Signed-off-by: Ulf Hansson <[email protected]>
  11. ---
  12. drivers/mmc/host/mtk-sd.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
  13. 1 file changed, 43 insertions(+), 4 deletions(-)
  14. --- a/drivers/mmc/host/mtk-sd.c
  15. +++ b/drivers/mmc/host/mtk-sd.c
  16. @@ -67,6 +67,7 @@
  17. #define SDC_RESP2 0x48
  18. #define SDC_RESP3 0x4c
  19. #define SDC_BLK_NUM 0x50
  20. +#define SDC_ADV_CFG0 0x64
  21. #define EMMC_IOCON 0x7c
  22. #define SDC_ACMD_RESP 0x80
  23. #define MSDC_DMA_SA 0x90
  24. @@ -80,6 +81,7 @@
  25. #define PAD_DS_TUNE 0x188
  26. #define PAD_CMD_TUNE 0x18c
  27. #define EMMC50_CFG0 0x208
  28. +#define SDC_FIFO_CFG 0x228
  29. /*--------------------------------------------------------------------------*/
  30. /* Register Mask */
  31. @@ -188,6 +190,9 @@
  32. #define SDC_STS_CMDBUSY (0x1 << 1) /* RW */
  33. #define SDC_STS_SWR_COMPL (0x1 << 31) /* RW */
  34. +/* SDC_ADV_CFG0 mask */
  35. +#define SDC_RX_ENHANCE_EN (0x1 << 20) /* RW */
  36. +
  37. /* MSDC_DMA_CTRL mask */
  38. #define MSDC_DMA_CTRL_START (0x1 << 0) /* W */
  39. #define MSDC_DMA_CTRL_STOP (0x1 << 1) /* W */
  40. @@ -217,6 +222,8 @@
  41. #define MSDC_PATCH_BIT_SPCPUSH (0x1 << 29) /* RW */
  42. #define MSDC_PATCH_BIT_DECRCTMO (0x1 << 30) /* RW */
  43. +#define MSDC_PATCH_BIT1_STOP_DLY (0xf << 8) /* RW */
  44. +
  45. #define MSDC_PATCH_BIT2_CFGRESP (0x1 << 15) /* RW */
  46. #define MSDC_PATCH_BIT2_CFGCRCSTS (0x1 << 28) /* RW */
  47. #define MSDC_PB2_RESPWAIT (0x3 << 2) /* RW */
  48. @@ -242,6 +249,9 @@
  49. #define EMMC50_CFG_CRCSTS_EDGE (0x1 << 3) /* RW */
  50. #define EMMC50_CFG_CFCSTS_SEL (0x1 << 4) /* RW */
  51. +#define SDC_FIFO_CFG_WRVALIDSEL (0x1 << 24) /* RW */
  52. +#define SDC_FIFO_CFG_RDVALIDSEL (0x1 << 25) /* RW */
  53. +
  54. #define REQ_CMD_EIO (0x1 << 0)
  55. #define REQ_CMD_TMO (0x1 << 1)
  56. #define REQ_DAT_ERR (0x1 << 2)
  57. @@ -308,6 +318,7 @@ struct msdc_save_para {
  58. u32 pad_ds_tune;
  59. u32 pad_cmd_tune;
  60. u32 emmc50_cfg0;
  61. + u32 sdc_fifo_cfg;
  62. };
  63. struct mtk_mmc_compatible {
  64. @@ -317,6 +328,8 @@ struct mtk_mmc_compatible {
  65. bool async_fifo;
  66. bool data_tune;
  67. bool busy_check;
  68. + bool stop_clk_fix;
  69. + bool enhance_rx;
  70. };
  71. struct msdc_tune_para {
  72. @@ -382,6 +395,8 @@ static const struct mtk_mmc_compatible m
  73. .async_fifo = false,
  74. .data_tune = false,
  75. .busy_check = false,
  76. + .stop_clk_fix = false,
  77. + .enhance_rx = false,
  78. };
  79. static const struct mtk_mmc_compatible mt8173_compat = {
  80. @@ -391,6 +406,8 @@ static const struct mtk_mmc_compatible m
  81. .async_fifo = false,
  82. .data_tune = false,
  83. .busy_check = false,
  84. + .stop_clk_fix = false,
  85. + .enhance_rx = false,
  86. };
  87. static const struct mtk_mmc_compatible mt2701_compat = {
  88. @@ -400,6 +417,8 @@ static const struct mtk_mmc_compatible m
  89. .async_fifo = true,
  90. .data_tune = true,
  91. .busy_check = false,
  92. + .stop_clk_fix = false,
  93. + .enhance_rx = false,
  94. };
  95. static const struct mtk_mmc_compatible mt2712_compat = {
  96. @@ -409,6 +428,8 @@ static const struct mtk_mmc_compatible m
  97. .async_fifo = true,
  98. .data_tune = true,
  99. .busy_check = true,
  100. + .stop_clk_fix = true,
  101. + .enhance_rx = true,
  102. };
  103. static const struct of_device_id msdc_of_ids[] = {
  104. @@ -1280,15 +1301,31 @@ static void msdc_init_hw(struct msdc_hos
  105. sdr_set_field(host->base + MSDC_PATCH_BIT, MSDC_CKGEN_MSDC_DLY_SEL, 1);
  106. writel(0xffff4089, host->base + MSDC_PATCH_BIT1);
  107. sdr_set_bits(host->base + EMMC50_CFG0, EMMC50_CFG_CFCSTS_SEL);
  108. +
  109. + if (host->dev_comp->stop_clk_fix) {
  110. + sdr_set_field(host->base + MSDC_PATCH_BIT1,
  111. + MSDC_PATCH_BIT1_STOP_DLY, 3);
  112. + sdr_clr_bits(host->base + SDC_FIFO_CFG,
  113. + SDC_FIFO_CFG_WRVALIDSEL);
  114. + sdr_clr_bits(host->base + SDC_FIFO_CFG,
  115. + SDC_FIFO_CFG_RDVALIDSEL);
  116. + }
  117. +
  118. if (host->dev_comp->busy_check)
  119. sdr_clr_bits(host->base + MSDC_PATCH_BIT1, (1 << 7));
  120. +
  121. if (host->dev_comp->async_fifo) {
  122. sdr_set_field(host->base + MSDC_PATCH_BIT2,
  123. MSDC_PB2_RESPWAIT, 3);
  124. - sdr_set_field(host->base + MSDC_PATCH_BIT2,
  125. - MSDC_PB2_RESPSTSENSEL, 2);
  126. - sdr_set_field(host->base + MSDC_PATCH_BIT2,
  127. - MSDC_PB2_CRCSTSENSEL, 2);
  128. + if (host->dev_comp->enhance_rx) {
  129. + sdr_set_bits(host->base + SDC_ADV_CFG0,
  130. + SDC_RX_ENHANCE_EN);
  131. + } else {
  132. + sdr_set_field(host->base + MSDC_PATCH_BIT2,
  133. + MSDC_PB2_RESPSTSENSEL, 2);
  134. + sdr_set_field(host->base + MSDC_PATCH_BIT2,
  135. + MSDC_PB2_CRCSTSENSEL, 2);
  136. + }
  137. /* use async fifo, then no need tune internal delay */
  138. sdr_clr_bits(host->base + MSDC_PATCH_BIT2,
  139. MSDC_PATCH_BIT2_CFGRESP);
  140. @@ -1933,6 +1970,7 @@ static void msdc_save_reg(struct msdc_ho
  141. host->save_para.pad_ds_tune = readl(host->base + PAD_DS_TUNE);
  142. host->save_para.pad_cmd_tune = readl(host->base + PAD_CMD_TUNE);
  143. host->save_para.emmc50_cfg0 = readl(host->base + EMMC50_CFG0);
  144. + host->save_para.sdc_fifo_cfg = readl(host->base + SDC_FIFO_CFG);
  145. }
  146. static void msdc_restore_reg(struct msdc_host *host)
  147. @@ -1949,6 +1987,7 @@ static void msdc_restore_reg(struct msdc
  148. writel(host->save_para.pad_ds_tune, host->base + PAD_DS_TUNE);
  149. writel(host->save_para.pad_cmd_tune, host->base + PAD_CMD_TUNE);
  150. writel(host->save_para.emmc50_cfg0, host->base + EMMC50_CFG0);
  151. + writel(host->save_para.sdc_fifo_cfg, host->base + SDC_FIFO_CFG);
  152. }
  153. static int msdc_runtime_suspend(struct device *dev)