0081-mmc-sunxi-Hack-up-the-driver-for-the-D1.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From 4df80766531bc35510981ebc5ea0bb07264beac9 Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Sun, 8 Aug 2021 19:31:20 -0500
  4. Subject: [PATCH 81/90] mmc: sunxi: Hack up the driver for the D1
  5. Signed-off-by: Samuel Holland <[email protected]>
  6. ---
  7. arch/riscv/include/asm/io.h | 1 +
  8. drivers/mmc/sunxi_mmc.c | 29 +++++++++++++++++++++++++----
  9. drivers/mmc/sunxi_mmc.h | 2 --
  10. 3 files changed, 26 insertions(+), 6 deletions(-)
  11. --- a/arch/riscv/include/asm/io.h
  12. +++ b/arch/riscv/include/asm/io.h
  13. @@ -85,6 +85,7 @@ static inline u16 readw(const volatile v
  14. return val;
  15. }
  16. +#define readl_relaxed readl
  17. static inline u32 readl(const volatile void __iomem *addr)
  18. {
  19. u32 val;
  20. --- a/drivers/mmc/sunxi_mmc.c
  21. +++ b/drivers/mmc/sunxi_mmc.c
  22. @@ -23,9 +23,9 @@
  23. #include <reset.h>
  24. #include <asm/gpio.h>
  25. #include <asm/io.h>
  26. +#if !CONFIG_IS_ENABLED(DM_MMC)
  27. #include <asm/arch/clock.h>
  28. #include <asm/arch/cpu.h>
  29. -#if !CONFIG_IS_ENABLED(DM_MMC)
  30. #include <asm/arch/mmc.h>
  31. #endif
  32. #include <linux/delay.h>
  33. @@ -36,6 +36,23 @@
  34. #define CCM_MMC_CTRL_MODE_SEL_NEW 0
  35. #endif
  36. +#include "../../arch/arm/include/asm/arch-sunxi/clock_sun50i_h6.h"
  37. +
  38. +unsigned int clock_get_pll6(void)
  39. +{
  40. + uint32_t rval = readl((void *)0x2001020);
  41. +
  42. + int n = ((rval & CCM_PLL6_CTRL_N_MASK) >> CCM_PLL6_CTRL_N_SHIFT) + 1;
  43. + int m = ((rval >> 1) & 0x1) + 1;
  44. + int p0 = ((rval >> 16) & 0x7) + 1;
  45. + /* The register defines PLL6-2X, not plain PLL6 */
  46. + uint32_t freq = 24000000UL * n / m / p0;
  47. +
  48. + printf("PLL reg = 0x%08x, freq = %d\n", rval, freq);
  49. +
  50. + return freq;
  51. +}
  52. +
  53. struct sunxi_mmc_plat {
  54. struct mmc_config cfg;
  55. struct mmc mmc;
  56. @@ -60,7 +77,8 @@ static bool sunxi_mmc_can_calibrate(void
  57. return IS_ENABLED(CONFIG_MACH_SUN50I) ||
  58. IS_ENABLED(CONFIG_MACH_SUN50I_H5) ||
  59. IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
  60. - IS_ENABLED(CONFIG_MACH_SUN8I_R40);
  61. + IS_ENABLED(CONFIG_MACH_SUN8I_R40) ||
  62. + IS_ENABLED(CONFIG_TARGET_SUN20I_D1);
  63. }
  64. static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz)
  65. @@ -194,7 +212,7 @@ static int mmc_config_clock(struct sunxi
  66. rval &= ~SUNXI_MMC_CLK_DIVIDER_MASK;
  67. writel(rval, &priv->reg->clkcr);
  68. -#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
  69. +#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_TARGET_SUN20I_D1)
  70. /* A64 supports calibration of delays on MMC controller and we
  71. * have to set delay of zero before starting calibration.
  72. * Allwinner BSP driver sets a delay only in the case of
  73. @@ -622,7 +640,8 @@ static unsigned get_mclk_offset(void)
  74. if (IS_ENABLED(CONFIG_MACH_SUN9I_A80))
  75. return 0x410;
  76. - if (IS_ENABLED(CONFIG_SUN50I_GEN_H6))
  77. + if (IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
  78. + IS_ENABLED(CONFIG_TARGET_SUN20I_D1))
  79. return 0x830;
  80. return 0x88;
  81. @@ -662,6 +681,7 @@ static int sunxi_mmc_probe(struct udevic
  82. return ret;
  83. ccu_reg = (u32 *)(uintptr_t)ofnode_get_addr(args.node);
  84. +#define SUNXI_MMC0_BASE 0x4020000
  85. priv->mmc_no = ((uintptr_t)priv->reg - SUNXI_MMC0_BASE) / 0x1000;
  86. priv->mclkreg = (void *)ccu_reg + get_mclk_offset() + priv->mmc_no * 4;
  87. @@ -703,6 +723,7 @@ static const struct udevice_id sunxi_mmc
  88. { .compatible = "allwinner,sun7i-a20-mmc" },
  89. { .compatible = "allwinner,sun8i-a83t-emmc" },
  90. { .compatible = "allwinner,sun9i-a80-mmc" },
  91. + { .compatible = "allwinner,sun20i-d1-mmc" },
  92. { .compatible = "allwinner,sun50i-a64-mmc" },
  93. { .compatible = "allwinner,sun50i-a64-emmc" },
  94. { .compatible = "allwinner,sun50i-h6-mmc" },
  95. --- a/drivers/mmc/sunxi_mmc.h
  96. +++ b/drivers/mmc/sunxi_mmc.h
  97. @@ -45,11 +45,9 @@ struct sunxi_mmc {
  98. u32 chda; /* 0x90 */
  99. u32 cbda; /* 0x94 */
  100. u32 res2[26];
  101. -#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
  102. u32 res3[17];
  103. u32 samp_dl;
  104. u32 res4[46];
  105. -#endif
  106. u32 fifo; /* 0x100 / 0x200 FIFO access address */
  107. };