clk-pxa910.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * pxa910 clock framework source file
  3. *
  4. * Copyright (C) 2012 Marvell
  5. * Chao Xie <[email protected]>
  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 "clk.h"
  19. #define APBC_RTC 0x28
  20. #define APBC_TWSI0 0x2c
  21. #define APBC_KPC 0x18
  22. #define APBC_UART0 0x0
  23. #define APBC_UART1 0x4
  24. #define APBC_GPIO 0x8
  25. #define APBC_PWM0 0xc
  26. #define APBC_PWM1 0x10
  27. #define APBC_PWM2 0x14
  28. #define APBC_PWM3 0x18
  29. #define APBC_SSP0 0x1c
  30. #define APBC_SSP1 0x20
  31. #define APBC_SSP2 0x4c
  32. #define APBCP_TWSI1 0x28
  33. #define APBCP_UART2 0x1c
  34. #define APMU_SDH0 0x54
  35. #define APMU_SDH1 0x58
  36. #define APMU_USB 0x5c
  37. #define APMU_DISP0 0x4c
  38. #define APMU_CCIC0 0x50
  39. #define APMU_DFC 0x60
  40. #define MPMU_UART_PLL 0x14
  41. static DEFINE_SPINLOCK(clk_lock);
  42. static struct mmp_clk_factor_masks uart_factor_masks = {
  43. .factor = 2,
  44. .num_mask = 0x1fff,
  45. .den_mask = 0x1fff,
  46. .num_shift = 16,
  47. .den_shift = 0,
  48. };
  49. static struct mmp_clk_factor_tbl uart_factor_tbl[] = {
  50. {.num = 8125, .den = 1536}, /*14.745MHZ */
  51. };
  52. static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
  53. static const char *ssp_parent[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
  54. static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
  55. static const char *disp_parent[] = {"pll1_2", "pll1_12"};
  56. static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
  57. static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
  58. void __init pxa910_clk_init(phys_addr_t mpmu_phys, phys_addr_t apmu_phys,
  59. phys_addr_t apbc_phys, phys_addr_t apbcp_phys)
  60. {
  61. struct clk *clk;
  62. struct clk *uart_pll;
  63. void __iomem *mpmu_base;
  64. void __iomem *apmu_base;
  65. void __iomem *apbcp_base;
  66. void __iomem *apbc_base;
  67. mpmu_base = ioremap(mpmu_phys, SZ_4K);
  68. if (mpmu_base == NULL) {
  69. pr_err("error to ioremap MPMU base\n");
  70. return;
  71. }
  72. apmu_base = ioremap(apmu_phys, SZ_4K);
  73. if (apmu_base == NULL) {
  74. pr_err("error to ioremap APMU base\n");
  75. return;
  76. }
  77. apbcp_base = ioremap(apbcp_phys, SZ_4K);
  78. if (apbcp_base == NULL) {
  79. pr_err("error to ioremap APBC extension base\n");
  80. return;
  81. }
  82. apbc_base = ioremap(apbc_phys, SZ_4K);
  83. if (apbc_base == NULL) {
  84. pr_err("error to ioremap APBC base\n");
  85. return;
  86. }
  87. clk = clk_register_fixed_rate(NULL, "clk32", NULL, 0, 3200);
  88. clk_register_clkdev(clk, "clk32", NULL);
  89. clk = clk_register_fixed_rate(NULL, "vctcxo", NULL, 0, 26000000);
  90. clk_register_clkdev(clk, "vctcxo", NULL);
  91. clk = clk_register_fixed_rate(NULL, "pll1", NULL, 0, 624000000);
  92. clk_register_clkdev(clk, "pll1", NULL);
  93. clk = clk_register_fixed_factor(NULL, "pll1_2", "pll1",
  94. CLK_SET_RATE_PARENT, 1, 2);
  95. clk_register_clkdev(clk, "pll1_2", NULL);
  96. clk = clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
  97. CLK_SET_RATE_PARENT, 1, 2);
  98. clk_register_clkdev(clk, "pll1_4", NULL);
  99. clk = clk_register_fixed_factor(NULL, "pll1_8", "pll1_4",
  100. CLK_SET_RATE_PARENT, 1, 2);
  101. clk_register_clkdev(clk, "pll1_8", NULL);
  102. clk = clk_register_fixed_factor(NULL, "pll1_16", "pll1_8",
  103. CLK_SET_RATE_PARENT, 1, 2);
  104. clk_register_clkdev(clk, "pll1_16", NULL);
  105. clk = clk_register_fixed_factor(NULL, "pll1_6", "pll1_2",
  106. CLK_SET_RATE_PARENT, 1, 3);
  107. clk_register_clkdev(clk, "pll1_6", NULL);
  108. clk = clk_register_fixed_factor(NULL, "pll1_12", "pll1_6",
  109. CLK_SET_RATE_PARENT, 1, 2);
  110. clk_register_clkdev(clk, "pll1_12", NULL);
  111. clk = clk_register_fixed_factor(NULL, "pll1_24", "pll1_12",
  112. CLK_SET_RATE_PARENT, 1, 2);
  113. clk_register_clkdev(clk, "pll1_24", NULL);
  114. clk = clk_register_fixed_factor(NULL, "pll1_48", "pll1_24",
  115. CLK_SET_RATE_PARENT, 1, 2);
  116. clk_register_clkdev(clk, "pll1_48", NULL);
  117. clk = clk_register_fixed_factor(NULL, "pll1_96", "pll1_48",
  118. CLK_SET_RATE_PARENT, 1, 2);
  119. clk_register_clkdev(clk, "pll1_96", NULL);
  120. clk = clk_register_fixed_factor(NULL, "pll1_13", "pll1",
  121. CLK_SET_RATE_PARENT, 1, 13);
  122. clk_register_clkdev(clk, "pll1_13", NULL);
  123. clk = clk_register_fixed_factor(NULL, "pll1_13_1_5", "pll1",
  124. CLK_SET_RATE_PARENT, 2, 3);
  125. clk_register_clkdev(clk, "pll1_13_1_5", NULL);
  126. clk = clk_register_fixed_factor(NULL, "pll1_2_1_5", "pll1",
  127. CLK_SET_RATE_PARENT, 2, 3);
  128. clk_register_clkdev(clk, "pll1_2_1_5", NULL);
  129. clk = clk_register_fixed_factor(NULL, "pll1_3_16", "pll1",
  130. CLK_SET_RATE_PARENT, 3, 16);
  131. clk_register_clkdev(clk, "pll1_3_16", NULL);
  132. uart_pll = mmp_clk_register_factor("uart_pll", "pll1_4", 0,
  133. mpmu_base + MPMU_UART_PLL,
  134. &uart_factor_masks, uart_factor_tbl,
  135. ARRAY_SIZE(uart_factor_tbl), &clk_lock);
  136. clk_set_rate(uart_pll, 14745600);
  137. clk_register_clkdev(uart_pll, "uart_pll", NULL);
  138. clk = mmp_clk_register_apbc("twsi0", "pll1_13_1_5",
  139. apbc_base + APBC_TWSI0, 10, 0, &clk_lock);
  140. clk_register_clkdev(clk, NULL, "pxa2xx-i2c.0");
  141. clk = mmp_clk_register_apbc("twsi1", "pll1_13_1_5",
  142. apbcp_base + APBCP_TWSI1, 10, 0, &clk_lock);
  143. clk_register_clkdev(clk, NULL, "pxa2xx-i2c.1");
  144. clk = mmp_clk_register_apbc("gpio", "vctcxo",
  145. apbc_base + APBC_GPIO, 10, 0, &clk_lock);
  146. clk_register_clkdev(clk, NULL, "mmp-gpio");
  147. clk = mmp_clk_register_apbc("kpc", "clk32",
  148. apbc_base + APBC_KPC, 10, 0, &clk_lock);
  149. clk_register_clkdev(clk, NULL, "pxa27x-keypad");
  150. clk = mmp_clk_register_apbc("rtc", "clk32",
  151. apbc_base + APBC_RTC, 10, 0, &clk_lock);
  152. clk_register_clkdev(clk, NULL, "sa1100-rtc");
  153. clk = mmp_clk_register_apbc("pwm0", "pll1_48",
  154. apbc_base + APBC_PWM0, 10, 0, &clk_lock);
  155. clk_register_clkdev(clk, NULL, "pxa910-pwm.0");
  156. clk = mmp_clk_register_apbc("pwm1", "pll1_48",
  157. apbc_base + APBC_PWM1, 10, 0, &clk_lock);
  158. clk_register_clkdev(clk, NULL, "pxa910-pwm.1");
  159. clk = mmp_clk_register_apbc("pwm2", "pll1_48",
  160. apbc_base + APBC_PWM2, 10, 0, &clk_lock);
  161. clk_register_clkdev(clk, NULL, "pxa910-pwm.2");
  162. clk = mmp_clk_register_apbc("pwm3", "pll1_48",
  163. apbc_base + APBC_PWM3, 10, 0, &clk_lock);
  164. clk_register_clkdev(clk, NULL, "pxa910-pwm.3");
  165. clk = clk_register_mux(NULL, "uart0_mux", uart_parent,
  166. ARRAY_SIZE(uart_parent),
  167. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  168. apbc_base + APBC_UART0, 4, 3, 0, &clk_lock);
  169. clk_set_parent(clk, uart_pll);
  170. clk_register_clkdev(clk, "uart_mux.0", NULL);
  171. clk = mmp_clk_register_apbc("uart0", "uart0_mux",
  172. apbc_base + APBC_UART0, 10, 0, &clk_lock);
  173. clk_register_clkdev(clk, NULL, "pxa2xx-uart.0");
  174. clk = clk_register_mux(NULL, "uart1_mux", uart_parent,
  175. ARRAY_SIZE(uart_parent),
  176. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  177. apbc_base + APBC_UART1, 4, 3, 0, &clk_lock);
  178. clk_set_parent(clk, uart_pll);
  179. clk_register_clkdev(clk, "uart_mux.1", NULL);
  180. clk = mmp_clk_register_apbc("uart1", "uart1_mux",
  181. apbc_base + APBC_UART1, 10, 0, &clk_lock);
  182. clk_register_clkdev(clk, NULL, "pxa2xx-uart.1");
  183. clk = clk_register_mux(NULL, "uart2_mux", uart_parent,
  184. ARRAY_SIZE(uart_parent),
  185. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  186. apbcp_base + APBCP_UART2, 4, 3, 0, &clk_lock);
  187. clk_set_parent(clk, uart_pll);
  188. clk_register_clkdev(clk, "uart_mux.2", NULL);
  189. clk = mmp_clk_register_apbc("uart2", "uart2_mux",
  190. apbcp_base + APBCP_UART2, 10, 0, &clk_lock);
  191. clk_register_clkdev(clk, NULL, "pxa2xx-uart.2");
  192. clk = clk_register_mux(NULL, "ssp0_mux", ssp_parent,
  193. ARRAY_SIZE(ssp_parent),
  194. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  195. apbc_base + APBC_SSP0, 4, 3, 0, &clk_lock);
  196. clk_register_clkdev(clk, "uart_mux.0", NULL);
  197. clk = mmp_clk_register_apbc("ssp0", "ssp0_mux",
  198. apbc_base + APBC_SSP0, 10, 0, &clk_lock);
  199. clk_register_clkdev(clk, NULL, "mmp-ssp.0");
  200. clk = clk_register_mux(NULL, "ssp1_mux", ssp_parent,
  201. ARRAY_SIZE(ssp_parent),
  202. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  203. apbc_base + APBC_SSP1, 4, 3, 0, &clk_lock);
  204. clk_register_clkdev(clk, "ssp_mux.1", NULL);
  205. clk = mmp_clk_register_apbc("ssp1", "ssp1_mux",
  206. apbc_base + APBC_SSP1, 10, 0, &clk_lock);
  207. clk_register_clkdev(clk, NULL, "mmp-ssp.1");
  208. clk = mmp_clk_register_apmu("dfc", "pll1_4",
  209. apmu_base + APMU_DFC, 0x19b, &clk_lock);
  210. clk_register_clkdev(clk, NULL, "pxa3xx-nand.0");
  211. clk = clk_register_mux(NULL, "sdh0_mux", sdh_parent,
  212. ARRAY_SIZE(sdh_parent),
  213. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  214. apmu_base + APMU_SDH0, 6, 1, 0, &clk_lock);
  215. clk_register_clkdev(clk, "sdh0_mux", NULL);
  216. clk = mmp_clk_register_apmu("sdh0", "sdh_mux",
  217. apmu_base + APMU_SDH0, 0x1b, &clk_lock);
  218. clk_register_clkdev(clk, NULL, "sdhci-pxa.0");
  219. clk = clk_register_mux(NULL, "sdh1_mux", sdh_parent,
  220. ARRAY_SIZE(sdh_parent),
  221. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  222. apmu_base + APMU_SDH1, 6, 1, 0, &clk_lock);
  223. clk_register_clkdev(clk, "sdh1_mux", NULL);
  224. clk = mmp_clk_register_apmu("sdh1", "sdh1_mux",
  225. apmu_base + APMU_SDH1, 0x1b, &clk_lock);
  226. clk_register_clkdev(clk, NULL, "sdhci-pxa.1");
  227. clk = mmp_clk_register_apmu("usb", "usb_pll",
  228. apmu_base + APMU_USB, 0x9, &clk_lock);
  229. clk_register_clkdev(clk, "usb_clk", NULL);
  230. clk = mmp_clk_register_apmu("sph", "usb_pll",
  231. apmu_base + APMU_USB, 0x12, &clk_lock);
  232. clk_register_clkdev(clk, "sph_clk", NULL);
  233. clk = clk_register_mux(NULL, "disp0_mux", disp_parent,
  234. ARRAY_SIZE(disp_parent),
  235. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  236. apmu_base + APMU_DISP0, 6, 1, 0, &clk_lock);
  237. clk_register_clkdev(clk, "disp_mux.0", NULL);
  238. clk = mmp_clk_register_apmu("disp0", "disp0_mux",
  239. apmu_base + APMU_DISP0, 0x1b, &clk_lock);
  240. clk_register_clkdev(clk, NULL, "mmp-disp.0");
  241. clk = clk_register_mux(NULL, "ccic0_mux", ccic_parent,
  242. ARRAY_SIZE(ccic_parent),
  243. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  244. apmu_base + APMU_CCIC0, 6, 1, 0, &clk_lock);
  245. clk_register_clkdev(clk, "ccic_mux.0", NULL);
  246. clk = mmp_clk_register_apmu("ccic0", "ccic0_mux",
  247. apmu_base + APMU_CCIC0, 0x1b, &clk_lock);
  248. clk_register_clkdev(clk, "fnclk", "mmp-ccic.0");
  249. clk = clk_register_mux(NULL, "ccic0_phy_mux", ccic_phy_parent,
  250. ARRAY_SIZE(ccic_phy_parent),
  251. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT,
  252. apmu_base + APMU_CCIC0, 7, 1, 0, &clk_lock);
  253. clk_register_clkdev(clk, "ccic_phy_mux.0", NULL);
  254. clk = mmp_clk_register_apmu("ccic0_phy", "ccic0_phy_mux",
  255. apmu_base + APMU_CCIC0, 0x24, &clk_lock);
  256. clk_register_clkdev(clk, "phyclk", "mmp-ccic.0");
  257. clk = clk_register_divider(NULL, "ccic0_sphy_div", "ccic0_mux",
  258. CLK_SET_RATE_PARENT, apmu_base + APMU_CCIC0,
  259. 10, 5, 0, &clk_lock);
  260. clk_register_clkdev(clk, "sphyclk_div", NULL);
  261. clk = mmp_clk_register_apmu("ccic0_sphy", "ccic0_sphy_div",
  262. apmu_base + APMU_CCIC0, 0x300, &clk_lock);
  263. clk_register_clkdev(clk, "sphyclk", "mmp-ccic.0");
  264. }