2
0

002-0024-clk-mediatek-add-infrasys-clock-mux-support.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From c53d249df9a75f77f5d0abb986a8913bc13070d0 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Wed, 31 Aug 2022 19:05:09 +0800
  4. Subject: [PATCH 24/32] clk: mediatek: add infrasys clock mux support
  5. This patch adds infrasys clock mux support for mediatek clock drivers.
  6. Reviewed-by: Simon Glass <[email protected]>
  7. Signed-off-by: Weijie Gao <[email protected]>
  8. ---
  9. drivers/clk/mediatek/clk-mtk.c | 71 ++++++++++++++++++++++++++++++++++
  10. drivers/clk/mediatek/clk-mtk.h | 4 +-
  11. 2 files changed, 74 insertions(+), 1 deletion(-)
  12. --- a/drivers/clk/mediatek/clk-mtk.c
  13. +++ b/drivers/clk/mediatek/clk-mtk.c
  14. @@ -303,6 +303,24 @@ static ulong mtk_topckgen_get_factor_rat
  15. return mtk_factor_recalc_rate(fdiv, rate);
  16. }
  17. +static ulong mtk_infrasys_get_factor_rate(struct clk *clk, u32 off)
  18. +{
  19. + struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  20. + const struct mtk_fixed_factor *fdiv = &priv->tree->fdivs[off];
  21. + ulong rate;
  22. +
  23. + switch (fdiv->flags & CLK_PARENT_MASK) {
  24. + case CLK_PARENT_TOPCKGEN:
  25. + rate = mtk_clk_find_parent_rate(clk, fdiv->parent,
  26. + priv->parent);
  27. + break;
  28. + default:
  29. + rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL);
  30. + }
  31. +
  32. + return mtk_factor_recalc_rate(fdiv, rate);
  33. +}
  34. +
  35. static ulong mtk_topckgen_get_mux_rate(struct clk *clk, u32 off)
  36. {
  37. struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  38. @@ -331,6 +349,33 @@ static ulong mtk_topckgen_get_mux_rate(s
  39. return priv->tree->xtal_rate;
  40. }
  41. +static ulong mtk_infrasys_get_mux_rate(struct clk *clk, u32 off)
  42. +{
  43. + struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  44. + const struct mtk_composite *mux = &priv->tree->muxes[off];
  45. + u32 index;
  46. +
  47. + index = readl(priv->base + mux->mux_reg);
  48. + index &= mux->mux_mask << mux->mux_shift;
  49. + index = index >> mux->mux_shift;
  50. +
  51. + if (mux->parent[index] > 0 ||
  52. + (mux->parent[index] == CLK_XTAL &&
  53. + priv->tree->flags & CLK_BYPASS_XTAL)) {
  54. + switch (mux->flags & CLK_PARENT_MASK) {
  55. + case CLK_PARENT_TOPCKGEN:
  56. + return mtk_clk_find_parent_rate(clk, mux->parent[index],
  57. + priv->parent);
  58. + break;
  59. + default:
  60. + return mtk_clk_find_parent_rate(clk, mux->parent[index],
  61. + NULL);
  62. + break;
  63. + }
  64. + }
  65. + return 0;
  66. +}
  67. +
  68. static ulong mtk_topckgen_get_rate(struct clk *clk)
  69. {
  70. struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  71. @@ -345,6 +390,25 @@ static ulong mtk_topckgen_get_rate(struc
  72. priv->tree->muxes_offs);
  73. }
  74. +static ulong mtk_infrasys_get_rate(struct clk *clk)
  75. +{
  76. + struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  77. +
  78. + ulong rate;
  79. +
  80. + if (clk->id < priv->tree->fdivs_offs) {
  81. + rate = priv->tree->fclks[clk->id].rate;
  82. + } else if (clk->id < priv->tree->muxes_offs) {
  83. + rate = mtk_infrasys_get_factor_rate(clk, clk->id -
  84. + priv->tree->fdivs_offs);
  85. + } else {
  86. + rate = mtk_infrasys_get_mux_rate(clk, clk->id -
  87. + priv->tree->muxes_offs);
  88. + }
  89. +
  90. + return rate;
  91. +}
  92. +
  93. static int mtk_clk_mux_enable(struct clk *clk)
  94. {
  95. struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
  96. @@ -493,6 +557,13 @@ const struct clk_ops mtk_clk_topckgen_op
  97. .set_parent = mtk_common_clk_set_parent,
  98. };
  99. +const struct clk_ops mtk_clk_infrasys_ops = {
  100. + .enable = mtk_clk_mux_enable,
  101. + .disable = mtk_clk_mux_disable,
  102. + .get_rate = mtk_infrasys_get_rate,
  103. + .set_parent = mtk_common_clk_set_parent,
  104. +};
  105. +
  106. const struct clk_ops mtk_clk_gate_ops = {
  107. .enable = mtk_clk_gate_enable,
  108. .disable = mtk_clk_gate_disable,
  109. --- a/drivers/clk/mediatek/clk-mtk.h
  110. +++ b/drivers/clk/mediatek/clk-mtk.h
  111. @@ -28,7 +28,8 @@
  112. #define CLK_PARENT_APMIXED BIT(4)
  113. #define CLK_PARENT_TOPCKGEN BIT(5)
  114. -#define CLK_PARENT_MASK GENMASK(5, 4)
  115. +#define CLK_PARENT_INFRASYS BIT(6)
  116. +#define CLK_PARENT_MASK GENMASK(6, 4)
  117. #define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
  118. @@ -220,6 +221,7 @@ struct mtk_cg_priv {
  119. extern const struct clk_ops mtk_clk_apmixedsys_ops;
  120. extern const struct clk_ops mtk_clk_topckgen_ops;
  121. +extern const struct clk_ops mtk_clk_infrasys_ops;
  122. extern const struct clk_ops mtk_clk_gate_ops;
  123. int mtk_common_clk_init(struct udevice *dev,