0017-sunxi-mmc-group-non-DM-specific-functions.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. From 74afc3a4e0ff780eddd859a25de7142e4baeeed5 Mon Sep 17 00:00:00 2001
  2. From: Andre Przywara <[email protected]>
  3. Date: Wed, 13 Jul 2022 17:21:44 +0100
  4. Subject: [PATCH 17/90] sunxi: mmc: group non-DM specific functions
  5. As the SPL code for sunxi boards does not use the driver model, we have
  6. two mmc_ops structures, one for DM, one for non-DM. The actual hardware
  7. access code is shared, with the respective callback functions using that
  8. common code.
  9. To make this more obvious and easier to read, reorder the functions to
  10. group them: we first have the common code, then the non-DM bits, and
  11. the proper DM implementation at the end.
  12. Also document this structure in the comment at the beginning of the file.
  13. No functional change intended.
  14. Signed-off-by: Andre Przywara <[email protected]>
  15. ---
  16. drivers/mmc/sunxi_mmc.c | 117 +++++++++++++++++++++-------------------
  17. 1 file changed, 61 insertions(+), 56 deletions(-)
  18. --- a/drivers/mmc/sunxi_mmc.c
  19. +++ b/drivers/mmc/sunxi_mmc.c
  20. @@ -5,6 +5,12 @@
  21. * Aaron <[email protected]>
  22. *
  23. * MMC driver for allwinner sunxi platform.
  24. + *
  25. + * This driver is used by the (ARM) SPL with the legacy MMC interface, and
  26. + * by U-Boot proper using the full DM interface. The actual hardware access
  27. + * code is common, and comes first in this file.
  28. + * The legacy MMC interface implementation comes next, followed by the
  29. + * proper DM_MMC implementation at the end.
  30. */
  31. #include <common.h>
  32. @@ -40,48 +46,6 @@ struct sunxi_mmc_priv {
  33. struct mmc_config cfg;
  34. };
  35. -#if !CONFIG_IS_ENABLED(DM_MMC)
  36. -/* support 4 mmc hosts */
  37. -struct sunxi_mmc_priv mmc_host[4];
  38. -
  39. -static int mmc_resource_init(int sdc_no)
  40. -{
  41. - struct sunxi_mmc_priv *priv = &mmc_host[sdc_no];
  42. - struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  43. -
  44. - debug("init mmc %d resource\n", sdc_no);
  45. -
  46. - switch (sdc_no) {
  47. - case 0:
  48. - priv->reg = (struct sunxi_mmc *)SUNXI_MMC0_BASE;
  49. - priv->mclkreg = &ccm->sd0_clk_cfg;
  50. - break;
  51. - case 1:
  52. - priv->reg = (struct sunxi_mmc *)SUNXI_MMC1_BASE;
  53. - priv->mclkreg = &ccm->sd1_clk_cfg;
  54. - break;
  55. -#ifdef SUNXI_MMC2_BASE
  56. - case 2:
  57. - priv->reg = (struct sunxi_mmc *)SUNXI_MMC2_BASE;
  58. - priv->mclkreg = &ccm->sd2_clk_cfg;
  59. - break;
  60. -#endif
  61. -#ifdef SUNXI_MMC3_BASE
  62. - case 3:
  63. - priv->reg = (struct sunxi_mmc *)SUNXI_MMC3_BASE;
  64. - priv->mclkreg = &ccm->sd3_clk_cfg;
  65. - break;
  66. -#endif
  67. - default:
  68. - printf("Wrong mmc number %d\n", sdc_no);
  69. - return -1;
  70. - }
  71. - priv->mmc_no = sdc_no;
  72. -
  73. - return 0;
  74. -}
  75. -#endif
  76. -
  77. /*
  78. * All A64 and later MMC controllers feature auto-calibration. This would
  79. * normally be detected via the compatible string, but we need something
  80. @@ -269,19 +233,6 @@ static int sunxi_mmc_set_ios_common(stru
  81. return 0;
  82. }
  83. -#if !CONFIG_IS_ENABLED(DM_MMC)
  84. -static int sunxi_mmc_core_init(struct mmc *mmc)
  85. -{
  86. - struct sunxi_mmc_priv *priv = mmc->priv;
  87. -
  88. - /* Reset controller */
  89. - writel(SUNXI_MMC_GCTRL_RESET, &priv->reg->gctrl);
  90. - udelay(1000);
  91. -
  92. - return 0;
  93. -}
  94. -#endif
  95. -
  96. static int mmc_trans_data_by_cpu(struct sunxi_mmc_priv *priv, struct mmc *mmc,
  97. struct mmc_data *data)
  98. {
  99. @@ -486,7 +437,60 @@ out:
  100. return error;
  101. }
  102. +/* non-DM code here is used by the (ARM) SPL only */
  103. +
  104. #if !CONFIG_IS_ENABLED(DM_MMC)
  105. +/* support 4 mmc hosts */
  106. +struct sunxi_mmc_priv mmc_host[4];
  107. +
  108. +static int mmc_resource_init(int sdc_no)
  109. +{
  110. + struct sunxi_mmc_priv *priv = &mmc_host[sdc_no];
  111. + struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  112. +
  113. + debug("init mmc %d resource\n", sdc_no);
  114. +
  115. + switch (sdc_no) {
  116. + case 0:
  117. + priv->reg = (struct sunxi_mmc *)SUNXI_MMC0_BASE;
  118. + priv->mclkreg = &ccm->sd0_clk_cfg;
  119. + break;
  120. + case 1:
  121. + priv->reg = (struct sunxi_mmc *)SUNXI_MMC1_BASE;
  122. + priv->mclkreg = &ccm->sd1_clk_cfg;
  123. + break;
  124. +#ifdef SUNXI_MMC2_BASE
  125. + case 2:
  126. + priv->reg = (struct sunxi_mmc *)SUNXI_MMC2_BASE;
  127. + priv->mclkreg = &ccm->sd2_clk_cfg;
  128. + break;
  129. +#endif
  130. +#ifdef SUNXI_MMC3_BASE
  131. + case 3:
  132. + priv->reg = (struct sunxi_mmc *)SUNXI_MMC3_BASE;
  133. + priv->mclkreg = &ccm->sd3_clk_cfg;
  134. + break;
  135. +#endif
  136. + default:
  137. + printf("Wrong mmc number %d\n", sdc_no);
  138. + return -1;
  139. + }
  140. + priv->mmc_no = sdc_no;
  141. +
  142. + return 0;
  143. +}
  144. +
  145. +static int sunxi_mmc_core_init(struct mmc *mmc)
  146. +{
  147. + struct sunxi_mmc_priv *priv = mmc->priv;
  148. +
  149. + /* Reset controller */
  150. + writel(SUNXI_MMC_GCTRL_RESET, &priv->reg->gctrl);
  151. + udelay(1000);
  152. +
  153. + return 0;
  154. +}
  155. +
  156. static int sunxi_mmc_set_ios_legacy(struct mmc *mmc)
  157. {
  158. struct sunxi_mmc_priv *priv = mmc->priv;
  159. @@ -562,7 +566,8 @@ struct mmc *sunxi_mmc_init(int sdc_no)
  160. return mmc_create(cfg, priv);
  161. }
  162. -#else
  163. +
  164. +#else /* CONFIG_DM_MMC code below, as used by U-Boot proper */
  165. static int sunxi_mmc_set_ios(struct udevice *dev)
  166. {