orion.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Marvell Orion SoC clocks
  3. *
  4. * Copyright (C) 2014 Thomas Petazzoni
  5. *
  6. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/io.h>
  15. #include <linux/of.h>
  16. #include "common.h"
  17. static const struct coreclk_ratio orion_coreclk_ratios[] __initconst = {
  18. { .id = 0, .name = "ddrclk", }
  19. };
  20. /*
  21. * Orion 5182
  22. */
  23. #define SAR_MV88F5182_TCLK_FREQ 8
  24. #define SAR_MV88F5182_TCLK_FREQ_MASK 0x3
  25. static u32 __init mv88f5182_get_tclk_freq(void __iomem *sar)
  26. {
  27. u32 opt = (readl(sar) >> SAR_MV88F5182_TCLK_FREQ) &
  28. SAR_MV88F5182_TCLK_FREQ_MASK;
  29. if (opt == 1)
  30. return 150000000;
  31. else if (opt == 2)
  32. return 166666667;
  33. else
  34. return 0;
  35. }
  36. #define SAR_MV88F5182_CPU_FREQ 4
  37. #define SAR_MV88F5182_CPU_FREQ_MASK 0xf
  38. static u32 __init mv88f5182_get_cpu_freq(void __iomem *sar)
  39. {
  40. u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
  41. SAR_MV88F5182_CPU_FREQ_MASK;
  42. if (opt == 0)
  43. return 333333333;
  44. else if (opt == 1 || opt == 2)
  45. return 400000000;
  46. else if (opt == 3)
  47. return 500000000;
  48. else
  49. return 0;
  50. }
  51. static void __init mv88f5182_get_clk_ratio(void __iomem *sar, int id,
  52. int *mult, int *div)
  53. {
  54. u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
  55. SAR_MV88F5182_CPU_FREQ_MASK;
  56. if (opt == 0 || opt == 1) {
  57. *mult = 1;
  58. *div = 2;
  59. } else if (opt == 2 || opt == 3) {
  60. *mult = 1;
  61. *div = 3;
  62. } else {
  63. *mult = 0;
  64. *div = 1;
  65. }
  66. }
  67. static const struct coreclk_soc_desc mv88f5182_coreclks = {
  68. .get_tclk_freq = mv88f5182_get_tclk_freq,
  69. .get_cpu_freq = mv88f5182_get_cpu_freq,
  70. .get_clk_ratio = mv88f5182_get_clk_ratio,
  71. .ratios = orion_coreclk_ratios,
  72. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  73. };
  74. static void __init mv88f5182_clk_init(struct device_node *np)
  75. {
  76. return mvebu_coreclk_setup(np, &mv88f5182_coreclks);
  77. }
  78. CLK_OF_DECLARE(mv88f5182_clk, "marvell,mv88f5182-core-clock", mv88f5182_clk_init);
  79. /*
  80. * Orion 5281
  81. */
  82. static u32 __init mv88f5281_get_tclk_freq(void __iomem *sar)
  83. {
  84. /* On 5281, tclk is always 166 Mhz */
  85. return 166666667;
  86. }
  87. #define SAR_MV88F5281_CPU_FREQ 4
  88. #define SAR_MV88F5281_CPU_FREQ_MASK 0xf
  89. static u32 __init mv88f5281_get_cpu_freq(void __iomem *sar)
  90. {
  91. u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
  92. SAR_MV88F5281_CPU_FREQ_MASK;
  93. if (opt == 1 || opt == 2)
  94. return 400000000;
  95. else if (opt == 3)
  96. return 500000000;
  97. else
  98. return 0;
  99. }
  100. static void __init mv88f5281_get_clk_ratio(void __iomem *sar, int id,
  101. int *mult, int *div)
  102. {
  103. u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
  104. SAR_MV88F5281_CPU_FREQ_MASK;
  105. if (opt == 1) {
  106. *mult = 1;
  107. *div = 2;
  108. } else if (opt == 2 || opt == 3) {
  109. *mult = 1;
  110. *div = 3;
  111. } else {
  112. *mult = 0;
  113. *div = 1;
  114. }
  115. }
  116. static const struct coreclk_soc_desc mv88f5281_coreclks = {
  117. .get_tclk_freq = mv88f5281_get_tclk_freq,
  118. .get_cpu_freq = mv88f5281_get_cpu_freq,
  119. .get_clk_ratio = mv88f5281_get_clk_ratio,
  120. .ratios = orion_coreclk_ratios,
  121. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  122. };
  123. static void __init mv88f5281_clk_init(struct device_node *np)
  124. {
  125. return mvebu_coreclk_setup(np, &mv88f5281_coreclks);
  126. }
  127. CLK_OF_DECLARE(mv88f5281_clk, "marvell,mv88f5281-core-clock", mv88f5281_clk_init);
  128. /*
  129. * Orion 6183
  130. */
  131. #define SAR_MV88F6183_TCLK_FREQ 9
  132. #define SAR_MV88F6183_TCLK_FREQ_MASK 0x1
  133. static u32 __init mv88f6183_get_tclk_freq(void __iomem *sar)
  134. {
  135. u32 opt = (readl(sar) >> SAR_MV88F6183_TCLK_FREQ) &
  136. SAR_MV88F6183_TCLK_FREQ_MASK;
  137. if (opt == 0)
  138. return 133333333;
  139. else if (opt == 1)
  140. return 166666667;
  141. else
  142. return 0;
  143. }
  144. #define SAR_MV88F6183_CPU_FREQ 1
  145. #define SAR_MV88F6183_CPU_FREQ_MASK 0x3f
  146. static u32 __init mv88f6183_get_cpu_freq(void __iomem *sar)
  147. {
  148. u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
  149. SAR_MV88F6183_CPU_FREQ_MASK;
  150. if (opt == 9)
  151. return 333333333;
  152. else if (opt == 17)
  153. return 400000000;
  154. else
  155. return 0;
  156. }
  157. static void __init mv88f6183_get_clk_ratio(void __iomem *sar, int id,
  158. int *mult, int *div)
  159. {
  160. u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
  161. SAR_MV88F6183_CPU_FREQ_MASK;
  162. if (opt == 9 || opt == 17) {
  163. *mult = 1;
  164. *div = 2;
  165. } else {
  166. *mult = 0;
  167. *div = 1;
  168. }
  169. }
  170. static const struct coreclk_soc_desc mv88f6183_coreclks = {
  171. .get_tclk_freq = mv88f6183_get_tclk_freq,
  172. .get_cpu_freq = mv88f6183_get_cpu_freq,
  173. .get_clk_ratio = mv88f6183_get_clk_ratio,
  174. .ratios = orion_coreclk_ratios,
  175. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  176. };
  177. static void __init mv88f6183_clk_init(struct device_node *np)
  178. {
  179. return mvebu_coreclk_setup(np, &mv88f6183_coreclks);
  180. }
  181. CLK_OF_DECLARE(mv88f6183_clk, "marvell,mv88f6183-core-clock", mv88f6183_clk_init);