clk-of-pxa168.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/io.h>
  15. #include <linux/delay.h>
  16. #include <linux/err.h>
  17. #include <linux/of_address.h>
  18. #include <dt-bindings/clock/marvell,pxa168.h>
  19. #include "clk.h"
  20. #include "reset.h"
  21. #define APBC_RTC 0x28
  22. #define APBC_TWSI0 0x2c
  23. #define APBC_KPC 0x30
  24. #define APBC_UART0 0x0
  25. #define APBC_UART1 0x4
  26. #define APBC_GPIO 0x8
  27. #define APBC_PWM0 0xc
  28. #define APBC_PWM1 0x10
  29. #define APBC_PWM2 0x14
  30. #define APBC_PWM3 0x18
  31. #define APBC_TIMER 0x34
  32. #define APBC_SSP0 0x81c
  33. #define APBC_SSP1 0x820
  34. #define APBC_SSP2 0x84c
  35. #define APBC_SSP3 0x858
  36. #define APBC_SSP4 0x85c
  37. #define APBC_TWSI1 0x6c
  38. #define APBC_UART2 0x70
  39. #define APMU_SDH0 0x54
  40. #define APMU_SDH1 0x58
  41. #define APMU_USB 0x5c
  42. #define APMU_DISP0 0x4c
  43. #define APMU_CCIC0 0x50
  44. #define APMU_DFC 0x60
  45. #define MPMU_UART_PLL 0x14
  46. struct pxa168_clk_unit {
  47. struct mmp_clk_unit unit;
  48. void __iomem *mpmu_base;
  49. void __iomem *apmu_base;
  50. void __iomem *apbc_base;
  51. };
  52. static struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
  53. {PXA168_CLK_CLK32, "clk32", NULL, CLK_IS_ROOT, 32768},
  54. {PXA168_CLK_VCTCXO, "vctcxo", NULL, CLK_IS_ROOT, 26000000},
  55. {PXA168_CLK_PLL1, "pll1", NULL, CLK_IS_ROOT, 624000000},
  56. {PXA168_CLK_USB_PLL, "usb_pll", NULL, CLK_IS_ROOT, 480000000},
  57. };
  58. static struct mmp_param_fixed_factor_clk fixed_factor_clks[] = {
  59. {PXA168_CLK_PLL1_2, "pll1_2", "pll1", 1, 2, 0},
  60. {PXA168_CLK_PLL1_4, "pll1_4", "pll1_2", 1, 2, 0},
  61. {PXA168_CLK_PLL1_8, "pll1_8", "pll1_4", 1, 2, 0},
  62. {PXA168_CLK_PLL1_16, "pll1_16", "pll1_8", 1, 2, 0},
  63. {PXA168_CLK_PLL1_6, "pll1_6", "pll1_2", 1, 3, 0},
  64. {PXA168_CLK_PLL1_12, "pll1_12", "pll1_6", 1, 2, 0},
  65. {PXA168_CLK_PLL1_24, "pll1_24", "pll1_12", 1, 2, 0},
  66. {PXA168_CLK_PLL1_48, "pll1_48", "pll1_24", 1, 2, 0},
  67. {PXA168_CLK_PLL1_96, "pll1_96", "pll1_48", 1, 2, 0},
  68. {PXA168_CLK_PLL1_192, "pll1_192", "pll1_96", 1, 2, 0},
  69. {PXA168_CLK_PLL1_13, "pll1_13", "pll1", 1, 13, 0},
  70. {PXA168_CLK_PLL1_13_1_5, "pll1_13_1_5", "pll1_13", 2, 3, 0},
  71. {PXA168_CLK_PLL1_2_1_5, "pll1_2_1_5", "pll1_2", 2, 3, 0},
  72. {PXA168_CLK_PLL1_3_16, "pll1_3_16", "pll1", 3, 16, 0},
  73. };
  74. static struct mmp_clk_factor_masks uart_factor_masks = {
  75. .factor = 2,
  76. .num_mask = 0x1fff,
  77. .den_mask = 0x1fff,
  78. .num_shift = 16,
  79. .den_shift = 0,
  80. };
  81. static struct mmp_clk_factor_tbl uart_factor_tbl[] = {
  82. {.num = 8125, .den = 1536}, /*14.745MHZ */
  83. };
  84. static void pxa168_pll_init(struct pxa168_clk_unit *pxa_unit)
  85. {
  86. struct clk *clk;
  87. struct mmp_clk_unit *unit = &pxa_unit->unit;
  88. mmp_register_fixed_rate_clks(unit, fixed_rate_clks,
  89. ARRAY_SIZE(fixed_rate_clks));
  90. mmp_register_fixed_factor_clks(unit, fixed_factor_clks,
  91. ARRAY_SIZE(fixed_factor_clks));
  92. clk = mmp_clk_register_factor("uart_pll", "pll1_4",
  93. CLK_SET_RATE_PARENT,
  94. pxa_unit->mpmu_base + MPMU_UART_PLL,
  95. &uart_factor_masks, uart_factor_tbl,
  96. ARRAY_SIZE(uart_factor_tbl), NULL);
  97. mmp_clk_add(unit, PXA168_CLK_UART_PLL, clk);
  98. }
  99. static DEFINE_SPINLOCK(uart0_lock);
  100. static DEFINE_SPINLOCK(uart1_lock);
  101. static DEFINE_SPINLOCK(uart2_lock);
  102. static const char *uart_parent_names[] = {"pll1_3_16", "uart_pll"};
  103. static DEFINE_SPINLOCK(ssp0_lock);
  104. static DEFINE_SPINLOCK(ssp1_lock);
  105. static DEFINE_SPINLOCK(ssp2_lock);
  106. static DEFINE_SPINLOCK(ssp3_lock);
  107. static DEFINE_SPINLOCK(ssp4_lock);
  108. static const char *ssp_parent_names[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
  109. static DEFINE_SPINLOCK(timer_lock);
  110. static const char *timer_parent_names[] = {"pll1_48", "clk32", "pll1_96", "pll1_192"};
  111. static DEFINE_SPINLOCK(reset_lock);
  112. static struct mmp_param_mux_clk apbc_mux_clks[] = {
  113. {0, "uart0_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART0, 4, 3, 0, &uart0_lock},
  114. {0, "uart1_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART1, 4, 3, 0, &uart1_lock},
  115. {0, "uart2_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART2, 4, 3, 0, &uart2_lock},
  116. {0, "ssp0_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP0, 4, 3, 0, &ssp0_lock},
  117. {0, "ssp1_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP1, 4, 3, 0, &ssp1_lock},
  118. {0, "ssp2_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP2, 4, 3, 0, &ssp2_lock},
  119. {0, "ssp3_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP3, 4, 3, 0, &ssp3_lock},
  120. {0, "ssp4_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP4, 4, 3, 0, &ssp4_lock},
  121. {0, "timer_mux", timer_parent_names, ARRAY_SIZE(timer_parent_names), CLK_SET_RATE_PARENT, APBC_TIMER, 4, 3, 0, &timer_lock},
  122. };
  123. static struct mmp_param_gate_clk apbc_gate_clks[] = {
  124. {PXA168_CLK_TWSI0, "twsi0_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI0, 0x3, 0x3, 0x0, 0, &reset_lock},
  125. {PXA168_CLK_TWSI1, "twsi1_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI1, 0x3, 0x3, 0x0, 0, &reset_lock},
  126. {PXA168_CLK_GPIO, "gpio_clk", "vctcxo", CLK_SET_RATE_PARENT, APBC_GPIO, 0x3, 0x3, 0x0, 0, &reset_lock},
  127. {PXA168_CLK_KPC, "kpc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_KPC, 0x3, 0x3, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
  128. {PXA168_CLK_RTC, "rtc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_RTC, 0x83, 0x83, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
  129. {PXA168_CLK_PWM0, "pwm0_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM0, 0x3, 0x3, 0x0, 0, &reset_lock},
  130. {PXA168_CLK_PWM1, "pwm1_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM1, 0x3, 0x3, 0x0, 0, &reset_lock},
  131. {PXA168_CLK_PWM2, "pwm2_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM2, 0x3, 0x3, 0x0, 0, &reset_lock},
  132. {PXA168_CLK_PWM3, "pwm3_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM3, 0x3, 0x3, 0x0, 0, &reset_lock},
  133. /* The gate clocks has mux parent. */
  134. {PXA168_CLK_UART0, "uart0_clk", "uart0_mux", CLK_SET_RATE_PARENT, APBC_UART0, 0x3, 0x3, 0x0, 0, &uart0_lock},
  135. {PXA168_CLK_UART1, "uart1_clk", "uart1_mux", CLK_SET_RATE_PARENT, APBC_UART1, 0x3, 0x3, 0x0, 0, &uart1_lock},
  136. {PXA168_CLK_UART2, "uart2_clk", "uart2_mux", CLK_SET_RATE_PARENT, APBC_UART2, 0x3, 0x3, 0x0, 0, &uart2_lock},
  137. {PXA168_CLK_SSP0, "ssp0_clk", "ssp0_mux", CLK_SET_RATE_PARENT, APBC_SSP0, 0x3, 0x3, 0x0, 0, &ssp0_lock},
  138. {PXA168_CLK_SSP1, "ssp1_clk", "ssp1_mux", CLK_SET_RATE_PARENT, APBC_SSP1, 0x3, 0x3, 0x0, 0, &ssp1_lock},
  139. {PXA168_CLK_SSP2, "ssp2_clk", "ssp2_mux", CLK_SET_RATE_PARENT, APBC_SSP2, 0x3, 0x3, 0x0, 0, &ssp2_lock},
  140. {PXA168_CLK_SSP3, "ssp3_clk", "ssp3_mux", CLK_SET_RATE_PARENT, APBC_SSP3, 0x3, 0x3, 0x0, 0, &ssp3_lock},
  141. {PXA168_CLK_SSP4, "ssp4_clk", "ssp4_mux", CLK_SET_RATE_PARENT, APBC_SSP4, 0x3, 0x3, 0x0, 0, &ssp4_lock},
  142. {PXA168_CLK_TIMER, "timer_clk", "timer_mux", CLK_SET_RATE_PARENT, APBC_TIMER, 0x3, 0x3, 0x0, 0, &timer_lock},
  143. };
  144. static void pxa168_apb_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
  145. {
  146. struct mmp_clk_unit *unit = &pxa_unit->unit;
  147. mmp_register_mux_clks(unit, apbc_mux_clks, pxa_unit->apbc_base,
  148. ARRAY_SIZE(apbc_mux_clks));
  149. mmp_register_gate_clks(unit, apbc_gate_clks, pxa_unit->apbc_base,
  150. ARRAY_SIZE(apbc_gate_clks));
  151. }
  152. static DEFINE_SPINLOCK(sdh0_lock);
  153. static DEFINE_SPINLOCK(sdh1_lock);
  154. static const char *sdh_parent_names[] = {"pll1_12", "pll1_13"};
  155. static DEFINE_SPINLOCK(usb_lock);
  156. static DEFINE_SPINLOCK(disp0_lock);
  157. static const char *disp_parent_names[] = {"pll1_2", "pll1_12"};
  158. static DEFINE_SPINLOCK(ccic0_lock);
  159. static const char *ccic_parent_names[] = {"pll1_2", "pll1_12"};
  160. static const char *ccic_phy_parent_names[] = {"pll1_6", "pll1_12"};
  161. static struct mmp_param_mux_clk apmu_mux_clks[] = {
  162. {0, "sdh0_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH0, 6, 1, 0, &sdh0_lock},
  163. {0, "sdh1_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH1, 6, 1, 0, &sdh1_lock},
  164. {0, "disp0_mux", disp_parent_names, ARRAY_SIZE(disp_parent_names), CLK_SET_RATE_PARENT, APMU_DISP0, 6, 1, 0, &disp0_lock},
  165. {0, "ccic0_mux", ccic_parent_names, ARRAY_SIZE(ccic_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 6, 1, 0, &ccic0_lock},
  166. {0, "ccic0_phy_mux", ccic_phy_parent_names, ARRAY_SIZE(ccic_phy_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 7, 1, 0, &ccic0_lock},
  167. };
  168. static struct mmp_param_div_clk apmu_div_clks[] = {
  169. {0, "ccic0_sphy_div", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 10, 5, 0, &ccic0_lock},
  170. };
  171. static struct mmp_param_gate_clk apmu_gate_clks[] = {
  172. {PXA168_CLK_DFC, "dfc_clk", "pll1_4", CLK_SET_RATE_PARENT, APMU_DFC, 0x19b, 0x19b, 0x0, 0, NULL},
  173. {PXA168_CLK_USB, "usb_clk", "usb_pll", 0, APMU_USB, 0x9, 0x9, 0x0, 0, &usb_lock},
  174. {PXA168_CLK_SPH, "sph_clk", "usb_pll", 0, APMU_USB, 0x12, 0x12, 0x0, 0, &usb_lock},
  175. /* The gate clocks has mux parent. */
  176. {PXA168_CLK_SDH0, "sdh0_clk", "sdh0_mux", CLK_SET_RATE_PARENT, APMU_SDH0, 0x1b, 0x1b, 0x0, 0, &sdh0_lock},
  177. {PXA168_CLK_SDH1, "sdh1_clk", "sdh1_mux", CLK_SET_RATE_PARENT, APMU_SDH1, 0x1b, 0x1b, 0x0, 0, &sdh1_lock},
  178. {PXA168_CLK_DISP0, "disp0_clk", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1b, 0x1b, 0x0, 0, &disp0_lock},
  179. {PXA168_CLK_CCIC0, "ccic0_clk", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x1b, 0x1b, 0x0, 0, &ccic0_lock},
  180. {PXA168_CLK_CCIC0_PHY, "ccic0_phy_clk", "ccic0_phy_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x24, 0x24, 0x0, 0, &ccic0_lock},
  181. {PXA168_CLK_CCIC0_SPHY, "ccic0_sphy_clk", "ccic0_sphy_div", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x300, 0x300, 0x0, 0, &ccic0_lock},
  182. };
  183. static void pxa168_axi_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
  184. {
  185. struct mmp_clk_unit *unit = &pxa_unit->unit;
  186. mmp_register_mux_clks(unit, apmu_mux_clks, pxa_unit->apmu_base,
  187. ARRAY_SIZE(apmu_mux_clks));
  188. mmp_register_div_clks(unit, apmu_div_clks, pxa_unit->apmu_base,
  189. ARRAY_SIZE(apmu_div_clks));
  190. mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->apmu_base,
  191. ARRAY_SIZE(apmu_gate_clks));
  192. }
  193. static void pxa168_clk_reset_init(struct device_node *np,
  194. struct pxa168_clk_unit *pxa_unit)
  195. {
  196. struct mmp_clk_reset_cell *cells;
  197. int i, nr_resets;
  198. nr_resets = ARRAY_SIZE(apbc_gate_clks);
  199. cells = kcalloc(nr_resets, sizeof(*cells), GFP_KERNEL);
  200. if (!cells)
  201. return;
  202. for (i = 0; i < nr_resets; i++) {
  203. cells[i].clk_id = apbc_gate_clks[i].id;
  204. cells[i].reg = pxa_unit->apbc_base + apbc_gate_clks[i].offset;
  205. cells[i].flags = 0;
  206. cells[i].lock = apbc_gate_clks[i].lock;
  207. cells[i].bits = 0x4;
  208. }
  209. mmp_clk_reset_register(np, cells, nr_resets);
  210. }
  211. static void __init pxa168_clk_init(struct device_node *np)
  212. {
  213. struct pxa168_clk_unit *pxa_unit;
  214. pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
  215. if (!pxa_unit)
  216. return;
  217. pxa_unit->mpmu_base = of_iomap(np, 0);
  218. if (!pxa_unit->mpmu_base) {
  219. pr_err("failed to map mpmu registers\n");
  220. return;
  221. }
  222. pxa_unit->apmu_base = of_iomap(np, 1);
  223. if (!pxa_unit->apmu_base) {
  224. pr_err("failed to map apmu registers\n");
  225. return;
  226. }
  227. pxa_unit->apbc_base = of_iomap(np, 2);
  228. if (!pxa_unit->apbc_base) {
  229. pr_err("failed to map apbc registers\n");
  230. return;
  231. }
  232. mmp_clk_init(np, &pxa_unit->unit, PXA168_NR_CLKS);
  233. pxa168_pll_init(pxa_unit);
  234. pxa168_apb_periph_clk_init(pxa_unit);
  235. pxa168_axi_periph_clk_init(pxa_unit);
  236. pxa168_clk_reset_init(np, pxa_unit);
  237. }
  238. CLK_OF_DECLARE(pxa168_clk, "marvell,pxa168-clock", pxa168_clk_init);