clk-pxa168.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * pxa168 clock framework source file
  3. *
  4. * Copyright (C) 2012 Marvell
  5. * Chao Xie <xiechao.mail@gmail.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/io.h>
  16. #include <linux/delay.h>
  17. #include <linux/err.h>
  18. #include <mach/addr-map.h>
  19. #include "clk.h"
  20. #define APBC_RTC 0x28
  21. #define APBC_TWSI0 0x2c
  22. #define APBC_KPC 0x30
  23. #define APBC_UART0 0x0
  24. #define APBC_UART1 0x4
  25. #define APBC_GPIO 0x8
  26. #define APBC_PWM0 0xc
  27. #define APBC_PWM1 0x10
  28. #define APBC_PWM2 0x14
  29. #define APBC_PWM3 0x18
  30. #define APBC_SSP0 0x81c
  31. #define APBC_SSP1 0x820
  32. #define APBC_SSP2 0x84c
  33. #define APBC_SSP3 0x858
  34. #define APBC_SSP4 0x85c
  35. #define APBC_TWSI1 0x6c
  36. #define APBC_UART2 0x70
  37. #define APMU_SDH0 0x54
  38. #define APMU_SDH1 0x58
  39. #define APMU_USB 0x5c
  40. #define APMU_DISP0 0x4c
  41. #define APMU_CCIC0 0x50
  42. #define APMU_DFC 0x60
  43. #define MPMU_UART_PLL 0x14
  44. static DEFINE_SPINLOCK(clk_lock);
  45. static struct mmp_clk_factor_masks uart_factor_masks = {
  46. .factor = 2,
  47. .num_mask = 0x1fff,
  48. .den_mask = 0x1fff,
  49. .num_shift = 16,
  50. .den_shift = 0,
  51. };
  52. static struct mmp_clk_factor_tbl uart_factor_tbl[] = {
  53. {.num = 8125, .den = 1536}, /*14.745MHZ */
  54. };
  55. static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
  56. static const char *ssp_parent[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
  57. static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
  58. static const char *disp_parent[] = {"pll1_2", "pll1_12"};
  59. static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
  60. static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
  61. void __init pxa168_clk_init(void)
  62. {
  63. struct clk *clk;
  64. struct clk *uart_pll;
  65. void __iomem *mpmu_base;
  66. void __iomem *apmu_base;
  67. void __iomem *apbc_base;
  68. mpmu_base = ioremap(APB_PHYS_BASE + 0x50000, SZ_4K);
  69. if (mpmu_base == NULL) {
  70. pr_err("error to ioremap MPMU base\n");
  71. return;
  72. }
  73. apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
  74. if (apmu_base == NULL) {
  75. pr_err("error to ioremap APMU base\n");
  76. return;
  77. }
  78. apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
  79. if (apbc_base == NULL) {
  80. pr_err("error to ioremap APBC base\n");
  81. return;
  82. }
  83. clk = clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
  84. clk_register_clkdev(clk, "clk32", NULL);
  85. clk = clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
  86. 26000000);
  87. clk_register_clkdev(clk, "vctcxo", NULL);
  88. clk = clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT,
  89. 624000000);
  90. clk_register_clkdev(clk, "pll1", NULL);
  91. clk = clk_register_fixed_factor(NULL, "pll1_2", "pll1",
  92. CLK_SET_RATE_PARENT, 1, 2);
  93. clk_register_clkdev(clk, "pll1_2", NULL);
  94. clk = clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
  95. CLK_SET_RATE_PARENT, 1, 2);
  96. clk_register_clkdev(clk, "pll1_4", NULL);
  97. clk = clk_register_fixed_factor(NULL, "pll1_8", "pll1_4",
  98. CLK_SET_RATE_PARENT, 1, 2);
  99. clk_register_clkdev(clk, "pll1_8", NULL);
  100. clk = clk_register_fixed_factor(NULL, "pll1_16", "pll1_8",
  101. CLK_SET_RATE_PARENT, 1, 2);
  102. clk_register_clkdev(clk, "pll1_16", NULL);
  103. clk = clk_register_fixed_factor(NULL, "pll1_6", "pll1_2",
  104. CLK_SET_RATE_PARENT, 1, 3);
  105. clk_register_clkdev(clk, "pll1_6", NULL);
  106. clk = clk_register_fixed_factor(NULL, "pll1_12", "pll1_6",
  107. CLK_SET_RATE_PARENT, 1, 2);
  108. clk_register_clkdev(clk, "pll1_12", NULL);
  109. clk = clk_register_fixed_factor(NULL, "pll1_24", "pll1_12",
  110. CLK_SET_RATE_PARENT, 1, 2);
  111. clk_register_clkdev(clk, "pll1_24", NULL);
  112. clk = clk_register_fixed_factor(NULL, "pll1_48", "pll1_24",
  113. CLK_SET_RATE_PARENT, 1, 2);
  114. clk_register_clkdev(clk, "pll1_48", NULL);
  115. clk = clk_register_fixed_factor(NULL, "pll1_96", "pll1_48",
  116. CLK_SET_RATE_PARENT, 1, 2);
  117. clk_register_clkdev(clk, "pll1_96", NULL);
  118. clk = clk_register_fixed_factor(NULL, "pll1_13", "pll1",
  119. CLK_SET_RATE_PARENT, 1, 13);
  120. clk_register_clkdev(clk, "pll1_13", NULL);
  121. clk = clk_register_fixed_factor(NULL, "pll1_13_1_5", "pll1",
  122. CLK_SET_RATE_PARENT, 2, 3);
  123. clk_register_clkdev(clk, "pll1_13_1_5", NULL);
  124. clk = clk_register_fixed_factor(NULL, "pll1_2_1_5", "pll1",
  125. CLK_SET_RATE_PARENT, 2, 3);
  126. clk_register_clkdev(clk, "pll1_2_1_5", NULL);
  127. clk = clk_register_fixed_factor(NULL, "pll1_3_16", "pll1",
  128. CLK_SET_RATE_PARENT, 3, 16);
  129. clk_register_clkdev(clk, "pll1_3_16", NULL);
  130. uart_pll = mmp_clk_register_factor("uart_pll", "pll1_4", 0,
  131. mpmu_base + MPMU_UART_PLL,
  132. &uart_factor_masks, uart_factor_tbl,
  133. ARRAY_SIZE(uart_factor_tbl), &clk_lock);
  134. clk_set_rate(uart_pll, 14745600);
  135. clk_register_clkdev(uart_pll, "uart_pll", NULL);
  136. clk = mmp_clk_register_apbc("twsi0", "pll1_13_1_5",
  137. apbc_base + APBC_TWSI0, 10, 0, &clk_lock);
  138. clk_register_clkdev(clk, NULL, "pxa2xx-i2c.0");
  139. clk = mmp_clk_register_apbc("twsi1", "pll1_13_1_5",
  140. apbc_base + APBC_TWSI1, 10, 0, &clk_lock);
  141. clk_register_clkdev(clk, NULL, "pxa2xx-i2c.1");
  142. clk = mmp_clk_register_apbc("gpio", "vctcxo",
  143. apbc_base + APBC_GPIO, 10, 0, &clk_lock);
  144. clk_register_clkdev(clk, NULL, "mmp-gpio");
  145. clk = mmp_clk_register_apbc("kpc", "clk32",
  146. apbc_base + APBC_KPC, 10, 0, &clk_lock);
  147. clk_register_clkdev(clk, NULL, "pxa27x-keypad");
  148. clk = mmp_clk_register_apbc("rtc", "clk32",
  149. apbc_base + APBC_RTC, 10, 0, &clk_lock);
  150. clk_register_clkdev(clk, NULL, "sa1100-rtc");
  151. clk = mmp_clk_register_apbc("pwm0", "pll1_48",
  152. apbc_base + APBC_PWM0, 10, 0, &clk_lock);
  153. clk_register_clkdev(clk, NULL, "pxa168-pwm.0");
  154. clk = mmp_clk_register_apbc("pwm1", "pll1_48",
  155. apbc_base + APBC_PWM1, 10, 0, &clk_lock);
  156. clk_register_clkdev(clk, NULL, "pxa168-pwm.1");
  157. clk = mmp_clk_register_apbc("pwm2", "pll1_48",
  158. apbc_base + APBC_PWM2, 10, 0, &clk_lock);
  159. clk_register_clkdev(clk, NULL, "pxa168-pwm.2");
  160. clk = mmp_clk_register_apbc("pwm3", "pll1_48",
  161. apbc_base + APBC_PWM3, 10, 0, &clk_lock);
  162. clk_register_clkdev(clk, NULL, "pxa168-pwm.3");
  163. clk = clk_register_mux(NULL, "uart0_mux", uart_parent,
  164. ARRAY_SIZE(uart_parent),
  165. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  166. apbc_base + APBC_UART0, 4, 3, 0, &clk_lock);
  167. clk_set_parent(clk, uart_pll);
  168. clk_register_clkdev(clk, "uart_mux.0", NULL);
  169. clk = mmp_clk_register_apbc("uart0", "uart0_mux",
  170. apbc_base + APBC_UART0, 10, 0, &clk_lock);
  171. clk_register_clkdev(clk, NULL, "pxa2xx-uart.0");
  172. clk = clk_register_mux(NULL, "uart1_mux", uart_parent,
  173. ARRAY_SIZE(uart_parent),
  174. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  175. apbc_base + APBC_UART1, 4, 3, 0, &clk_lock);
  176. clk_set_parent(clk, uart_pll);
  177. clk_register_clkdev(clk, "uart_mux.1", NULL);
  178. clk = mmp_clk_register_apbc("uart1", "uart1_mux",
  179. apbc_base + APBC_UART1, 10, 0, &clk_lock);
  180. clk_register_clkdev(clk, NULL, "pxa2xx-uart.1");
  181. clk = clk_register_mux(NULL, "uart2_mux", uart_parent,
  182. ARRAY_SIZE(uart_parent),
  183. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  184. apbc_base + APBC_UART2, 4, 3, 0, &clk_lock);
  185. clk_set_parent(clk, uart_pll);
  186. clk_register_clkdev(clk, "uart_mux.2", NULL);
  187. clk = mmp_clk_register_apbc("uart2", "uart2_mux",
  188. apbc_base + APBC_UART2, 10, 0, &clk_lock);
  189. clk_register_clkdev(clk, NULL, "pxa2xx-uart.2");
  190. clk = clk_register_mux(NULL, "ssp0_mux", ssp_parent,
  191. ARRAY_SIZE(ssp_parent),
  192. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  193. apbc_base + APBC_SSP0, 4, 3, 0, &clk_lock);
  194. clk_register_clkdev(clk, "uart_mux.0", NULL);
  195. clk = mmp_clk_register_apbc("ssp0", "ssp0_mux", apbc_base + APBC_SSP0,
  196. 10, 0, &clk_lock);
  197. clk_register_clkdev(clk, NULL, "mmp-ssp.0");
  198. clk = clk_register_mux(NULL, "ssp1_mux", ssp_parent,
  199. ARRAY_SIZE(ssp_parent),
  200. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  201. apbc_base + APBC_SSP1, 4, 3, 0, &clk_lock);
  202. clk_register_clkdev(clk, "ssp_mux.1", NULL);
  203. clk = mmp_clk_register_apbc("ssp1", "ssp1_mux", apbc_base + APBC_SSP1,
  204. 10, 0, &clk_lock);
  205. clk_register_clkdev(clk, NULL, "mmp-ssp.1");
  206. clk = clk_register_mux(NULL, "ssp2_mux", ssp_parent,
  207. ARRAY_SIZE(ssp_parent),
  208. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  209. apbc_base + APBC_SSP2, 4, 3, 0, &clk_lock);
  210. clk_register_clkdev(clk, "ssp_mux.2", NULL);
  211. clk = mmp_clk_register_apbc("ssp2", "ssp1_mux", apbc_base + APBC_SSP2,
  212. 10, 0, &clk_lock);
  213. clk_register_clkdev(clk, NULL, "mmp-ssp.2");
  214. clk = clk_register_mux(NULL, "ssp3_mux", ssp_parent,
  215. ARRAY_SIZE(ssp_parent),
  216. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  217. apbc_base + APBC_SSP3, 4, 3, 0, &clk_lock);
  218. clk_register_clkdev(clk, "ssp_mux.3", NULL);
  219. clk = mmp_clk_register_apbc("ssp3", "ssp1_mux", apbc_base + APBC_SSP3,
  220. 10, 0, &clk_lock);
  221. clk_register_clkdev(clk, NULL, "mmp-ssp.3");
  222. clk = clk_register_mux(NULL, "ssp4_mux", ssp_parent,
  223. ARRAY_SIZE(ssp_parent),
  224. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  225. apbc_base + APBC_SSP4, 4, 3, 0, &clk_lock);
  226. clk_register_clkdev(clk, "ssp_mux.4", NULL);
  227. clk = mmp_clk_register_apbc("ssp4", "ssp1_mux", apbc_base + APBC_SSP4,
  228. 10, 0, &clk_lock);
  229. clk_register_clkdev(clk, NULL, "mmp-ssp.4");
  230. clk = mmp_clk_register_apmu("dfc", "pll1_4", apmu_base + APMU_DFC,
  231. 0x19b, &clk_lock);
  232. clk_register_clkdev(clk, NULL, "pxa3xx-nand.0");
  233. clk = clk_register_mux(NULL, "sdh0_mux", sdh_parent,
  234. ARRAY_SIZE(sdh_parent),
  235. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  236. apmu_base + APMU_SDH0, 6, 1, 0, &clk_lock);
  237. clk_register_clkdev(clk, "sdh0_mux", NULL);
  238. clk = mmp_clk_register_apmu("sdh0", "sdh_mux", apmu_base + APMU_SDH0,
  239. 0x1b, &clk_lock);
  240. clk_register_clkdev(clk, NULL, "sdhci-pxa.0");
  241. clk = clk_register_mux(NULL, "sdh1_mux", sdh_parent,
  242. ARRAY_SIZE(sdh_parent),
  243. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  244. apmu_base + APMU_SDH1, 6, 1, 0, &clk_lock);
  245. clk_register_clkdev(clk, "sdh1_mux", NULL);
  246. clk = mmp_clk_register_apmu("sdh1", "sdh1_mux", apmu_base + APMU_SDH1,
  247. 0x1b, &clk_lock);
  248. clk_register_clkdev(clk, NULL, "sdhci-pxa.1");
  249. clk = mmp_clk_register_apmu("usb", "usb_pll", apmu_base + APMU_USB,
  250. 0x9, &clk_lock);
  251. clk_register_clkdev(clk, "usb_clk", NULL);
  252. clk = mmp_clk_register_apmu("sph", "usb_pll", apmu_base + APMU_USB,
  253. 0x12, &clk_lock);
  254. clk_register_clkdev(clk, "sph_clk", NULL);
  255. clk = clk_register_mux(NULL, "disp0_mux", disp_parent,
  256. ARRAY_SIZE(disp_parent),
  257. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  258. apmu_base + APMU_DISP0, 6, 1, 0, &clk_lock);
  259. clk_register_clkdev(clk, "disp_mux.0", NULL);
  260. clk = mmp_clk_register_apmu("disp0", "disp0_mux",
  261. apmu_base + APMU_DISP0, 0x1b, &clk_lock);
  262. clk_register_clkdev(clk, "fnclk", "mmp-disp.0");
  263. clk = mmp_clk_register_apmu("disp0_hclk", "disp0_mux",
  264. apmu_base + APMU_DISP0, 0x24, &clk_lock);
  265. clk_register_clkdev(clk, "hclk", "mmp-disp.0");
  266. clk = clk_register_mux(NULL, "ccic0_mux", ccic_parent,
  267. ARRAY_SIZE(ccic_parent),
  268. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  269. apmu_base + APMU_CCIC0, 6, 1, 0, &clk_lock);
  270. clk_register_clkdev(clk, "ccic_mux.0", NULL);
  271. clk = mmp_clk_register_apmu("ccic0", "ccic0_mux",
  272. apmu_base + APMU_CCIC0, 0x1b, &clk_lock);
  273. clk_register_clkdev(clk, "fnclk", "mmp-ccic.0");
  274. clk = clk_register_mux(NULL, "ccic0_phy_mux", ccic_phy_parent,
  275. ARRAY_SIZE(ccic_phy_parent),
  276. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  277. apmu_base + APMU_CCIC0, 7, 1, 0, &clk_lock);
  278. clk_register_clkdev(clk, "ccic_phy_mux.0", NULL);
  279. clk = mmp_clk_register_apmu("ccic0_phy", "ccic0_phy_mux",
  280. apmu_base + APMU_CCIC0, 0x24, &clk_lock);
  281. clk_register_clkdev(clk, "phyclk", "mmp-ccic.0");
  282. clk = clk_register_divider(NULL, "ccic0_sphy_div", "ccic0_mux",
  283. CLK_SET_RATE_PARENT, apmu_base + APMU_CCIC0,
  284. 10, 5, 0, &clk_lock);
  285. clk_register_clkdev(clk, "sphyclk_div", NULL);
  286. clk = mmp_clk_register_apmu("ccic0_sphy", "ccic0_sphy_div",
  287. apmu_base + APMU_CCIC0, 0x300, &clk_lock);
  288. clk_register_clkdev(clk, "sphyclk", "mmp-ccic.0");
  289. }