clk-of-pxa1928.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * pxa1928 clock framework source file
  4. *
  5. * Copyright (C) 2015 Linaro, Ltd.
  6. * Rob Herring <[email protected]>
  7. *
  8. * Based on drivers/clk/mmp/clk-of-mmp2.c:
  9. * Copyright (C) 2012 Marvell
  10. * Chao Xie <[email protected]>
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/io.h>
  14. #include <linux/of_address.h>
  15. #include <linux/slab.h>
  16. #include <linux/spinlock.h>
  17. #include <dt-bindings/clock/marvell,pxa1928.h>
  18. #include "clk.h"
  19. #include "reset.h"
  20. #define MPMU_UART_PLL 0x14
  21. struct pxa1928_clk_unit {
  22. struct mmp_clk_unit unit;
  23. void __iomem *mpmu_base;
  24. void __iomem *apmu_base;
  25. void __iomem *apbc_base;
  26. void __iomem *apbcp_base;
  27. };
  28. static struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
  29. {0, "clk32", NULL, 0, 32768},
  30. {0, "vctcxo", NULL, 0, 26000000},
  31. {0, "pll1_624", NULL, 0, 624000000},
  32. {0, "pll5p", NULL, 0, 832000000},
  33. {0, "pll5", NULL, 0, 1248000000},
  34. {0, "usb_pll", NULL, 0, 480000000},
  35. };
  36. static struct mmp_param_fixed_factor_clk fixed_factor_clks[] = {
  37. {0, "pll1_d2", "pll1_624", 1, 2, 0},
  38. {0, "pll1_d9", "pll1_624", 1, 9, 0},
  39. {0, "pll1_d12", "pll1_624", 1, 12, 0},
  40. {0, "pll1_d16", "pll1_624", 1, 16, 0},
  41. {0, "pll1_d20", "pll1_624", 1, 20, 0},
  42. {0, "pll1_416", "pll1_624", 2, 3, 0},
  43. {0, "vctcxo_d2", "vctcxo", 1, 2, 0},
  44. {0, "vctcxo_d4", "vctcxo", 1, 4, 0},
  45. };
  46. static struct mmp_clk_factor_masks uart_factor_masks = {
  47. .factor = 2,
  48. .num_mask = 0x1fff,
  49. .den_mask = 0x1fff,
  50. .num_shift = 16,
  51. .den_shift = 0,
  52. };
  53. static struct mmp_clk_factor_tbl uart_factor_tbl[] = {
  54. {.num = 832, .den = 234}, /*58.5MHZ */
  55. {.num = 1, .den = 1}, /*26MHZ */
  56. };
  57. static void pxa1928_pll_init(struct pxa1928_clk_unit *pxa_unit)
  58. {
  59. struct mmp_clk_unit *unit = &pxa_unit->unit;
  60. mmp_register_fixed_rate_clks(unit, fixed_rate_clks,
  61. ARRAY_SIZE(fixed_rate_clks));
  62. mmp_register_fixed_factor_clks(unit, fixed_factor_clks,
  63. ARRAY_SIZE(fixed_factor_clks));
  64. mmp_clk_register_factor("uart_pll", "pll1_416",
  65. CLK_SET_RATE_PARENT,
  66. pxa_unit->mpmu_base + MPMU_UART_PLL,
  67. &uart_factor_masks, uart_factor_tbl,
  68. ARRAY_SIZE(uart_factor_tbl), NULL);
  69. }
  70. static DEFINE_SPINLOCK(uart0_lock);
  71. static DEFINE_SPINLOCK(uart1_lock);
  72. static DEFINE_SPINLOCK(uart2_lock);
  73. static DEFINE_SPINLOCK(uart3_lock);
  74. static const char *uart_parent_names[] = {"uart_pll", "vctcxo"};
  75. static DEFINE_SPINLOCK(ssp0_lock);
  76. static DEFINE_SPINLOCK(ssp1_lock);
  77. static const char *ssp_parent_names[] = {"vctcxo_d4", "vctcxo_d2", "vctcxo", "pll1_d12"};
  78. static DEFINE_SPINLOCK(reset_lock);
  79. static struct mmp_param_mux_clk apbc_mux_clks[] = {
  80. {0, "uart0_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_UART0 * 4, 4, 3, 0, &uart0_lock},
  81. {0, "uart1_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_UART1 * 4, 4, 3, 0, &uart1_lock},
  82. {0, "uart2_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_UART2 * 4, 4, 3, 0, &uart2_lock},
  83. {0, "uart3_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_UART3 * 4, 4, 3, 0, &uart3_lock},
  84. {0, "ssp0_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_SSP0 * 4, 4, 3, 0, &ssp0_lock},
  85. {0, "ssp1_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_SSP1 * 4, 4, 3, 0, &ssp1_lock},
  86. };
  87. static struct mmp_param_gate_clk apbc_gate_clks[] = {
  88. {PXA1928_CLK_TWSI0, "twsi0_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI0 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  89. {PXA1928_CLK_TWSI1, "twsi1_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI1 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  90. {PXA1928_CLK_TWSI2, "twsi2_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI2 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  91. {PXA1928_CLK_TWSI3, "twsi3_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI3 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  92. {PXA1928_CLK_TWSI4, "twsi4_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI4 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  93. {PXA1928_CLK_TWSI5, "twsi5_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_TWSI5 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  94. {PXA1928_CLK_GPIO, "gpio_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_GPIO * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  95. {PXA1928_CLK_KPC, "kpc_clk", "clk32", CLK_SET_RATE_PARENT, PXA1928_CLK_KPC * 4, 0x3, 0x3, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
  96. {PXA1928_CLK_RTC, "rtc_clk", "clk32", CLK_SET_RATE_PARENT, PXA1928_CLK_RTC * 4, 0x83, 0x83, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
  97. {PXA1928_CLK_PWM0, "pwm0_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_PWM0 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  98. {PXA1928_CLK_PWM1, "pwm1_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_PWM1 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  99. {PXA1928_CLK_PWM2, "pwm2_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_PWM2 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  100. {PXA1928_CLK_PWM3, "pwm3_clk", "vctcxo", CLK_SET_RATE_PARENT, PXA1928_CLK_PWM3 * 4, 0x3, 0x3, 0x0, 0, &reset_lock},
  101. /* The gate clocks has mux parent. */
  102. {PXA1928_CLK_UART0, "uart0_clk", "uart0_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_UART0 * 4, 0x3, 0x3, 0x0, 0, &uart0_lock},
  103. {PXA1928_CLK_UART1, "uart1_clk", "uart1_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_UART1 * 4, 0x3, 0x3, 0x0, 0, &uart1_lock},
  104. {PXA1928_CLK_UART2, "uart2_clk", "uart2_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_UART2 * 4, 0x3, 0x3, 0x0, 0, &uart2_lock},
  105. {PXA1928_CLK_UART3, "uart3_clk", "uart3_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_UART3 * 4, 0x3, 0x3, 0x0, 0, &uart3_lock},
  106. {PXA1928_CLK_SSP0, "ssp0_clk", "ssp0_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_SSP0 * 4, 0x3, 0x3, 0x0, 0, &ssp0_lock},
  107. {PXA1928_CLK_SSP1, "ssp1_clk", "ssp1_mux", CLK_SET_RATE_PARENT, PXA1928_CLK_SSP1 * 4, 0x3, 0x3, 0x0, 0, &ssp1_lock},
  108. };
  109. static void pxa1928_apb_periph_clk_init(struct pxa1928_clk_unit *pxa_unit)
  110. {
  111. struct mmp_clk_unit *unit = &pxa_unit->unit;
  112. mmp_register_mux_clks(unit, apbc_mux_clks, pxa_unit->apbc_base,
  113. ARRAY_SIZE(apbc_mux_clks));
  114. mmp_register_gate_clks(unit, apbc_gate_clks, pxa_unit->apbc_base,
  115. ARRAY_SIZE(apbc_gate_clks));
  116. }
  117. static DEFINE_SPINLOCK(sdh0_lock);
  118. static DEFINE_SPINLOCK(sdh1_lock);
  119. static DEFINE_SPINLOCK(sdh2_lock);
  120. static DEFINE_SPINLOCK(sdh3_lock);
  121. static DEFINE_SPINLOCK(sdh4_lock);
  122. static const char *sdh_parent_names[] = {"pll1_624", "pll5p", "pll5", "pll1_416"};
  123. static DEFINE_SPINLOCK(usb_lock);
  124. static struct mmp_param_mux_clk apmu_mux_clks[] = {
  125. {0, "sdh_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, PXA1928_CLK_SDH0 * 4, 8, 2, 0, &sdh0_lock},
  126. };
  127. static struct mmp_param_div_clk apmu_div_clks[] = {
  128. {0, "sdh_div", "sdh_mux", 0, PXA1928_CLK_SDH0 * 4, 10, 4, CLK_DIVIDER_ONE_BASED, &sdh0_lock},
  129. };
  130. static struct mmp_param_gate_clk apmu_gate_clks[] = {
  131. {PXA1928_CLK_USB, "usb_clk", "usb_pll", 0, PXA1928_CLK_USB * 4, 0x9, 0x9, 0x0, 0, &usb_lock},
  132. {PXA1928_CLK_HSIC, "hsic_clk", "usb_pll", 0, PXA1928_CLK_HSIC * 4, 0x9, 0x9, 0x0, 0, &usb_lock},
  133. /* The gate clocks has mux parent. */
  134. {PXA1928_CLK_SDH0, "sdh0_clk", "sdh_div", CLK_SET_RATE_PARENT, PXA1928_CLK_SDH0 * 4, 0x1b, 0x1b, 0x0, 0, &sdh0_lock},
  135. {PXA1928_CLK_SDH1, "sdh1_clk", "sdh_div", CLK_SET_RATE_PARENT, PXA1928_CLK_SDH1 * 4, 0x1b, 0x1b, 0x0, 0, &sdh1_lock},
  136. {PXA1928_CLK_SDH2, "sdh2_clk", "sdh_div", CLK_SET_RATE_PARENT, PXA1928_CLK_SDH2 * 4, 0x1b, 0x1b, 0x0, 0, &sdh2_lock},
  137. {PXA1928_CLK_SDH3, "sdh3_clk", "sdh_div", CLK_SET_RATE_PARENT, PXA1928_CLK_SDH3 * 4, 0x1b, 0x1b, 0x0, 0, &sdh3_lock},
  138. {PXA1928_CLK_SDH4, "sdh4_clk", "sdh_div", CLK_SET_RATE_PARENT, PXA1928_CLK_SDH4 * 4, 0x1b, 0x1b, 0x0, 0, &sdh4_lock},
  139. };
  140. static void pxa1928_axi_periph_clk_init(struct pxa1928_clk_unit *pxa_unit)
  141. {
  142. struct mmp_clk_unit *unit = &pxa_unit->unit;
  143. mmp_register_mux_clks(unit, apmu_mux_clks, pxa_unit->apmu_base,
  144. ARRAY_SIZE(apmu_mux_clks));
  145. mmp_register_div_clks(unit, apmu_div_clks, pxa_unit->apmu_base,
  146. ARRAY_SIZE(apmu_div_clks));
  147. mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->apmu_base,
  148. ARRAY_SIZE(apmu_gate_clks));
  149. }
  150. static void pxa1928_clk_reset_init(struct device_node *np,
  151. struct pxa1928_clk_unit *pxa_unit)
  152. {
  153. struct mmp_clk_reset_cell *cells;
  154. int i, base, nr_resets;
  155. nr_resets = ARRAY_SIZE(apbc_gate_clks);
  156. cells = kcalloc(nr_resets, sizeof(*cells), GFP_KERNEL);
  157. if (!cells)
  158. return;
  159. base = 0;
  160. for (i = 0; i < nr_resets; i++) {
  161. cells[base + i].clk_id = apbc_gate_clks[i].id;
  162. cells[base + i].reg =
  163. pxa_unit->apbc_base + apbc_gate_clks[i].offset;
  164. cells[base + i].flags = 0;
  165. cells[base + i].lock = apbc_gate_clks[i].lock;
  166. cells[base + i].bits = 0x4;
  167. }
  168. mmp_clk_reset_register(np, cells, nr_resets);
  169. }
  170. static void __init pxa1928_mpmu_clk_init(struct device_node *np)
  171. {
  172. struct pxa1928_clk_unit *pxa_unit;
  173. pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
  174. if (!pxa_unit)
  175. return;
  176. pxa_unit->mpmu_base = of_iomap(np, 0);
  177. if (!pxa_unit->mpmu_base) {
  178. pr_err("failed to map mpmu registers\n");
  179. kfree(pxa_unit);
  180. return;
  181. }
  182. pxa1928_pll_init(pxa_unit);
  183. }
  184. CLK_OF_DECLARE(pxa1928_mpmu_clk, "marvell,pxa1928-mpmu", pxa1928_mpmu_clk_init);
  185. static void __init pxa1928_apmu_clk_init(struct device_node *np)
  186. {
  187. struct pxa1928_clk_unit *pxa_unit;
  188. pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
  189. if (!pxa_unit)
  190. return;
  191. pxa_unit->apmu_base = of_iomap(np, 0);
  192. if (!pxa_unit->apmu_base) {
  193. pr_err("failed to map apmu registers\n");
  194. kfree(pxa_unit);
  195. return;
  196. }
  197. mmp_clk_init(np, &pxa_unit->unit, PXA1928_APMU_NR_CLKS);
  198. pxa1928_axi_periph_clk_init(pxa_unit);
  199. }
  200. CLK_OF_DECLARE(pxa1928_apmu_clk, "marvell,pxa1928-apmu", pxa1928_apmu_clk_init);
  201. static void __init pxa1928_apbc_clk_init(struct device_node *np)
  202. {
  203. struct pxa1928_clk_unit *pxa_unit;
  204. pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
  205. if (!pxa_unit)
  206. return;
  207. pxa_unit->apbc_base = of_iomap(np, 0);
  208. if (!pxa_unit->apbc_base) {
  209. pr_err("failed to map apbc registers\n");
  210. kfree(pxa_unit);
  211. return;
  212. }
  213. mmp_clk_init(np, &pxa_unit->unit, PXA1928_APBC_NR_CLKS);
  214. pxa1928_apb_periph_clk_init(pxa_unit);
  215. pxa1928_clk_reset_init(np, pxa_unit);
  216. }
  217. CLK_OF_DECLARE(pxa1928_apbc_clk, "marvell,pxa1928-apbc", pxa1928_apbc_clk_init);