orion.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 5181
  22. */
  23. #define SAR_MV88F5181_TCLK_FREQ 8
  24. #define SAR_MV88F5181_TCLK_FREQ_MASK 0x3
  25. static u32 __init mv88f5181_get_tclk_freq(void __iomem *sar)
  26. {
  27. u32 opt = (readl(sar) >> SAR_MV88F5181_TCLK_FREQ) &
  28. SAR_MV88F5181_TCLK_FREQ_MASK;
  29. if (opt == 0)
  30. return 133333333;
  31. else if (opt == 1)
  32. return 150000000;
  33. else if (opt == 2)
  34. return 166666667;
  35. else
  36. return 0;
  37. }
  38. #define SAR_MV88F5181_CPU_FREQ 4
  39. #define SAR_MV88F5181_CPU_FREQ_MASK 0xf
  40. static u32 __init mv88f5181_get_cpu_freq(void __iomem *sar)
  41. {
  42. u32 opt = (readl(sar) >> SAR_MV88F5181_CPU_FREQ) &
  43. SAR_MV88F5181_CPU_FREQ_MASK;
  44. if (opt == 0)
  45. return 333333333;
  46. else if (opt == 1 || opt == 2)
  47. return 400000000;
  48. else if (opt == 3)
  49. return 500000000;
  50. else
  51. return 0;
  52. }
  53. static void __init mv88f5181_get_clk_ratio(void __iomem *sar, int id,
  54. int *mult, int *div)
  55. {
  56. u32 opt = (readl(sar) >> SAR_MV88F5181_CPU_FREQ) &
  57. SAR_MV88F5181_CPU_FREQ_MASK;
  58. if (opt == 0 || opt == 1) {
  59. *mult = 1;
  60. *div = 2;
  61. } else if (opt == 2 || opt == 3) {
  62. *mult = 1;
  63. *div = 3;
  64. } else {
  65. *mult = 0;
  66. *div = 1;
  67. }
  68. }
  69. static const struct coreclk_soc_desc mv88f5181_coreclks = {
  70. .get_tclk_freq = mv88f5181_get_tclk_freq,
  71. .get_cpu_freq = mv88f5181_get_cpu_freq,
  72. .get_clk_ratio = mv88f5181_get_clk_ratio,
  73. .ratios = orion_coreclk_ratios,
  74. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  75. };
  76. static void __init mv88f5181_clk_init(struct device_node *np)
  77. {
  78. return mvebu_coreclk_setup(np, &mv88f5181_coreclks);
  79. }
  80. CLK_OF_DECLARE(mv88f5181_clk, "marvell,mv88f5181-core-clock", mv88f5181_clk_init);
  81. /*
  82. * Orion 5182
  83. */
  84. #define SAR_MV88F5182_TCLK_FREQ 8
  85. #define SAR_MV88F5182_TCLK_FREQ_MASK 0x3
  86. static u32 __init mv88f5182_get_tclk_freq(void __iomem *sar)
  87. {
  88. u32 opt = (readl(sar) >> SAR_MV88F5182_TCLK_FREQ) &
  89. SAR_MV88F5182_TCLK_FREQ_MASK;
  90. if (opt == 1)
  91. return 150000000;
  92. else if (opt == 2)
  93. return 166666667;
  94. else
  95. return 0;
  96. }
  97. #define SAR_MV88F5182_CPU_FREQ 4
  98. #define SAR_MV88F5182_CPU_FREQ_MASK 0xf
  99. static u32 __init mv88f5182_get_cpu_freq(void __iomem *sar)
  100. {
  101. u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
  102. SAR_MV88F5182_CPU_FREQ_MASK;
  103. if (opt == 0)
  104. return 333333333;
  105. else if (opt == 1 || opt == 2)
  106. return 400000000;
  107. else if (opt == 3)
  108. return 500000000;
  109. else
  110. return 0;
  111. }
  112. static void __init mv88f5182_get_clk_ratio(void __iomem *sar, int id,
  113. int *mult, int *div)
  114. {
  115. u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
  116. SAR_MV88F5182_CPU_FREQ_MASK;
  117. if (opt == 0 || opt == 1) {
  118. *mult = 1;
  119. *div = 2;
  120. } else if (opt == 2 || opt == 3) {
  121. *mult = 1;
  122. *div = 3;
  123. } else {
  124. *mult = 0;
  125. *div = 1;
  126. }
  127. }
  128. static const struct coreclk_soc_desc mv88f5182_coreclks = {
  129. .get_tclk_freq = mv88f5182_get_tclk_freq,
  130. .get_cpu_freq = mv88f5182_get_cpu_freq,
  131. .get_clk_ratio = mv88f5182_get_clk_ratio,
  132. .ratios = orion_coreclk_ratios,
  133. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  134. };
  135. static void __init mv88f5182_clk_init(struct device_node *np)
  136. {
  137. return mvebu_coreclk_setup(np, &mv88f5182_coreclks);
  138. }
  139. CLK_OF_DECLARE(mv88f5182_clk, "marvell,mv88f5182-core-clock", mv88f5182_clk_init);
  140. /*
  141. * Orion 5281
  142. */
  143. static u32 __init mv88f5281_get_tclk_freq(void __iomem *sar)
  144. {
  145. /* On 5281, tclk is always 166 Mhz */
  146. return 166666667;
  147. }
  148. #define SAR_MV88F5281_CPU_FREQ 4
  149. #define SAR_MV88F5281_CPU_FREQ_MASK 0xf
  150. static u32 __init mv88f5281_get_cpu_freq(void __iomem *sar)
  151. {
  152. u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
  153. SAR_MV88F5281_CPU_FREQ_MASK;
  154. if (opt == 1 || opt == 2)
  155. return 400000000;
  156. else if (opt == 3)
  157. return 500000000;
  158. else
  159. return 0;
  160. }
  161. static void __init mv88f5281_get_clk_ratio(void __iomem *sar, int id,
  162. int *mult, int *div)
  163. {
  164. u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
  165. SAR_MV88F5281_CPU_FREQ_MASK;
  166. if (opt == 1) {
  167. *mult = 1;
  168. *div = 2;
  169. } else if (opt == 2 || opt == 3) {
  170. *mult = 1;
  171. *div = 3;
  172. } else {
  173. *mult = 0;
  174. *div = 1;
  175. }
  176. }
  177. static const struct coreclk_soc_desc mv88f5281_coreclks = {
  178. .get_tclk_freq = mv88f5281_get_tclk_freq,
  179. .get_cpu_freq = mv88f5281_get_cpu_freq,
  180. .get_clk_ratio = mv88f5281_get_clk_ratio,
  181. .ratios = orion_coreclk_ratios,
  182. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  183. };
  184. static void __init mv88f5281_clk_init(struct device_node *np)
  185. {
  186. return mvebu_coreclk_setup(np, &mv88f5281_coreclks);
  187. }
  188. CLK_OF_DECLARE(mv88f5281_clk, "marvell,mv88f5281-core-clock", mv88f5281_clk_init);
  189. /*
  190. * Orion 6183
  191. */
  192. #define SAR_MV88F6183_TCLK_FREQ 9
  193. #define SAR_MV88F6183_TCLK_FREQ_MASK 0x1
  194. static u32 __init mv88f6183_get_tclk_freq(void __iomem *sar)
  195. {
  196. u32 opt = (readl(sar) >> SAR_MV88F6183_TCLK_FREQ) &
  197. SAR_MV88F6183_TCLK_FREQ_MASK;
  198. if (opt == 0)
  199. return 133333333;
  200. else if (opt == 1)
  201. return 166666667;
  202. else
  203. return 0;
  204. }
  205. #define SAR_MV88F6183_CPU_FREQ 1
  206. #define SAR_MV88F6183_CPU_FREQ_MASK 0x3f
  207. static u32 __init mv88f6183_get_cpu_freq(void __iomem *sar)
  208. {
  209. u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
  210. SAR_MV88F6183_CPU_FREQ_MASK;
  211. if (opt == 9)
  212. return 333333333;
  213. else if (opt == 17)
  214. return 400000000;
  215. else
  216. return 0;
  217. }
  218. static void __init mv88f6183_get_clk_ratio(void __iomem *sar, int id,
  219. int *mult, int *div)
  220. {
  221. u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
  222. SAR_MV88F6183_CPU_FREQ_MASK;
  223. if (opt == 9 || opt == 17) {
  224. *mult = 1;
  225. *div = 2;
  226. } else {
  227. *mult = 0;
  228. *div = 1;
  229. }
  230. }
  231. static const struct coreclk_soc_desc mv88f6183_coreclks = {
  232. .get_tclk_freq = mv88f6183_get_tclk_freq,
  233. .get_cpu_freq = mv88f6183_get_cpu_freq,
  234. .get_clk_ratio = mv88f6183_get_clk_ratio,
  235. .ratios = orion_coreclk_ratios,
  236. .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
  237. };
  238. static void __init mv88f6183_clk_init(struct device_node *np)
  239. {
  240. return mvebu_coreclk_setup(np, &mv88f6183_coreclks);
  241. }
  242. CLK_OF_DECLARE(mv88f6183_clk, "marvell,mv88f6183-core-clock", mv88f6183_clk_init);