clk.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2010 John Crispin <john@phrozen.org>
  7. * Copyright (C) 2013-2015 Lantiq Beteiligungs-GmbH & Co.KG
  8. */
  9. #include <linux/io.h>
  10. #include <linux/export.h>
  11. #include <linux/clk.h>
  12. #include <asm/time.h>
  13. #include <asm/irq.h>
  14. #include <asm/div64.h>
  15. #include <lantiq_soc.h>
  16. #include "../clk.h"
  17. static unsigned int ram_clocks[] = {
  18. CLOCK_167M, CLOCK_133M, CLOCK_111M, CLOCK_83M };
  19. #define DDR_HZ ram_clocks[ltq_cgu_r32(CGU_SYS) & 0x3]
  20. /* legacy xway clock */
  21. #define CGU_SYS 0x10
  22. /* vr9, ar10/grx390 clock */
  23. #define CGU_SYS_XRX 0x0c
  24. #define CGU_IF_CLK_AR10 0x24
  25. unsigned long ltq_danube_fpi_hz(void)
  26. {
  27. unsigned long ddr_clock = DDR_HZ;
  28. if (ltq_cgu_r32(CGU_SYS) & 0x40)
  29. return ddr_clock >> 1;
  30. return ddr_clock;
  31. }
  32. unsigned long ltq_danube_cpu_hz(void)
  33. {
  34. switch (ltq_cgu_r32(CGU_SYS) & 0xc) {
  35. case 0:
  36. return CLOCK_333M;
  37. case 4:
  38. return DDR_HZ;
  39. case 8:
  40. return DDR_HZ << 1;
  41. default:
  42. return DDR_HZ >> 1;
  43. }
  44. }
  45. unsigned long ltq_danube_pp32_hz(void)
  46. {
  47. unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 7) & 3;
  48. unsigned long clk;
  49. switch (clksys) {
  50. case 1:
  51. clk = CLOCK_240M;
  52. break;
  53. case 2:
  54. clk = CLOCK_222M;
  55. break;
  56. case 3:
  57. clk = CLOCK_133M;
  58. break;
  59. default:
  60. clk = CLOCK_266M;
  61. break;
  62. }
  63. return clk;
  64. }
  65. unsigned long ltq_ar9_sys_hz(void)
  66. {
  67. if (((ltq_cgu_r32(CGU_SYS) >> 3) & 0x3) == 0x2)
  68. return CLOCK_393M;
  69. return CLOCK_333M;
  70. }
  71. unsigned long ltq_ar9_fpi_hz(void)
  72. {
  73. unsigned long sys = ltq_ar9_sys_hz();
  74. if (ltq_cgu_r32(CGU_SYS) & BIT(0))
  75. return sys / 3;
  76. else
  77. return sys / 2;
  78. }
  79. unsigned long ltq_ar9_cpu_hz(void)
  80. {
  81. if (ltq_cgu_r32(CGU_SYS) & BIT(2))
  82. return ltq_ar9_fpi_hz();
  83. else
  84. return ltq_ar9_sys_hz();
  85. }
  86. unsigned long ltq_vr9_cpu_hz(void)
  87. {
  88. unsigned int cpu_sel;
  89. unsigned long clk;
  90. cpu_sel = (ltq_cgu_r32(CGU_SYS_XRX) >> 4) & 0xf;
  91. switch (cpu_sel) {
  92. case 0:
  93. clk = CLOCK_600M;
  94. break;
  95. case 1:
  96. clk = CLOCK_500M;
  97. break;
  98. case 2:
  99. clk = CLOCK_393M;
  100. break;
  101. case 3:
  102. clk = CLOCK_333M;
  103. break;
  104. case 5:
  105. case 6:
  106. clk = CLOCK_196_608M;
  107. break;
  108. case 7:
  109. clk = CLOCK_167M;
  110. break;
  111. case 4:
  112. case 8:
  113. case 9:
  114. clk = CLOCK_125M;
  115. break;
  116. default:
  117. clk = 0;
  118. break;
  119. }
  120. return clk;
  121. }
  122. unsigned long ltq_vr9_fpi_hz(void)
  123. {
  124. unsigned int ocp_sel, cpu_clk;
  125. unsigned long clk;
  126. cpu_clk = ltq_vr9_cpu_hz();
  127. ocp_sel = ltq_cgu_r32(CGU_SYS_XRX) & 0x3;
  128. switch (ocp_sel) {
  129. case 0:
  130. /* OCP ratio 1 */
  131. clk = cpu_clk;
  132. break;
  133. case 2:
  134. /* OCP ratio 2 */
  135. clk = cpu_clk / 2;
  136. break;
  137. case 3:
  138. /* OCP ratio 2.5 */
  139. clk = (cpu_clk * 2) / 5;
  140. break;
  141. case 4:
  142. /* OCP ratio 3 */
  143. clk = cpu_clk / 3;
  144. break;
  145. default:
  146. clk = 0;
  147. break;
  148. }
  149. return clk;
  150. }
  151. unsigned long ltq_vr9_pp32_hz(void)
  152. {
  153. unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 16) & 0x7;
  154. unsigned long clk;
  155. switch (clksys) {
  156. case 0:
  157. clk = CLOCK_500M;
  158. break;
  159. case 1:
  160. clk = CLOCK_432M;
  161. break;
  162. case 2:
  163. clk = CLOCK_288M;
  164. break;
  165. default:
  166. clk = CLOCK_500M;
  167. break;
  168. }
  169. return clk;
  170. }
  171. unsigned long ltq_ar10_cpu_hz(void)
  172. {
  173. unsigned int clksys;
  174. int cpu_fs = (ltq_cgu_r32(CGU_SYS_XRX) >> 8) & 0x1;
  175. int freq_div = (ltq_cgu_r32(CGU_SYS_XRX) >> 4) & 0x7;
  176. switch (cpu_fs) {
  177. case 0:
  178. clksys = CLOCK_500M;
  179. break;
  180. case 1:
  181. clksys = CLOCK_600M;
  182. break;
  183. default:
  184. clksys = CLOCK_500M;
  185. break;
  186. }
  187. switch (freq_div) {
  188. case 0:
  189. return clksys;
  190. case 1:
  191. return clksys >> 1;
  192. case 2:
  193. return clksys >> 2;
  194. default:
  195. return clksys;
  196. }
  197. }
  198. unsigned long ltq_ar10_fpi_hz(void)
  199. {
  200. int freq_fpi = (ltq_cgu_r32(CGU_IF_CLK_AR10) >> 25) & 0xf;
  201. switch (freq_fpi) {
  202. case 1:
  203. return CLOCK_300M;
  204. case 5:
  205. return CLOCK_250M;
  206. case 2:
  207. return CLOCK_150M;
  208. case 6:
  209. return CLOCK_125M;
  210. default:
  211. return CLOCK_125M;
  212. }
  213. }
  214. unsigned long ltq_ar10_pp32_hz(void)
  215. {
  216. unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 16) & 0x7;
  217. unsigned long clk;
  218. switch (clksys) {
  219. case 1:
  220. clk = CLOCK_250M;
  221. break;
  222. case 4:
  223. clk = CLOCK_400M;
  224. break;
  225. default:
  226. clk = CLOCK_250M;
  227. break;
  228. }
  229. return clk;
  230. }
  231. unsigned long ltq_grx390_cpu_hz(void)
  232. {
  233. unsigned int clksys;
  234. int cpu_fs = ((ltq_cgu_r32(CGU_SYS_XRX) >> 9) & 0x3);
  235. int freq_div = ((ltq_cgu_r32(CGU_SYS_XRX) >> 4) & 0x7);
  236. switch (cpu_fs) {
  237. case 0:
  238. clksys = CLOCK_600M;
  239. break;
  240. case 1:
  241. clksys = CLOCK_666M;
  242. break;
  243. case 2:
  244. clksys = CLOCK_720M;
  245. break;
  246. default:
  247. clksys = CLOCK_600M;
  248. break;
  249. }
  250. switch (freq_div) {
  251. case 0:
  252. return clksys;
  253. case 1:
  254. return clksys >> 1;
  255. case 2:
  256. return clksys >> 2;
  257. default:
  258. return clksys;
  259. }
  260. }
  261. unsigned long ltq_grx390_fpi_hz(void)
  262. {
  263. /* fpi clock is derived from ddr_clk */
  264. unsigned int clksys;
  265. int cpu_fs = ((ltq_cgu_r32(CGU_SYS_XRX) >> 9) & 0x3);
  266. int freq_div = ((ltq_cgu_r32(CGU_SYS_XRX)) & 0x7);
  267. switch (cpu_fs) {
  268. case 0:
  269. clksys = CLOCK_600M;
  270. break;
  271. case 1:
  272. clksys = CLOCK_666M;
  273. break;
  274. case 2:
  275. clksys = CLOCK_720M;
  276. break;
  277. default:
  278. clksys = CLOCK_600M;
  279. break;
  280. }
  281. switch (freq_div) {
  282. case 1:
  283. return clksys >> 1;
  284. case 2:
  285. return clksys >> 2;
  286. default:
  287. return clksys >> 1;
  288. }
  289. }
  290. unsigned long ltq_grx390_pp32_hz(void)
  291. {
  292. unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 16) & 0x7;
  293. unsigned long clk;
  294. switch (clksys) {
  295. case 1:
  296. clk = CLOCK_250M;
  297. break;
  298. case 2:
  299. clk = CLOCK_432M;
  300. break;
  301. case 4:
  302. clk = CLOCK_400M;
  303. break;
  304. default:
  305. clk = CLOCK_250M;
  306. break;
  307. }
  308. return clk;
  309. }