sama5d4.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/clk-provider.h>
  3. #include <linux/mfd/syscon.h>
  4. #include <linux/slab.h>
  5. #include <dt-bindings/clock/at91.h>
  6. #include "pmc.h"
  7. static DEFINE_SPINLOCK(mck_lock);
  8. static const struct clk_master_characteristics mck_characteristics = {
  9. .output = { .min = 125000000, .max = 200000000 },
  10. .divisors = { 1, 2, 4, 3 },
  11. };
  12. static u8 plla_out[] = { 0 };
  13. static u16 plla_icpll[] = { 0 };
  14. static const struct clk_range plla_outputs[] = {
  15. { .min = 600000000, .max = 1200000000 },
  16. };
  17. static const struct clk_pll_characteristics plla_characteristics = {
  18. .input = { .min = 12000000, .max = 12000000 },
  19. .num_output = ARRAY_SIZE(plla_outputs),
  20. .output = plla_outputs,
  21. .icpll = plla_icpll,
  22. .out = plla_out,
  23. };
  24. static const struct clk_pcr_layout sama5d4_pcr_layout = {
  25. .offset = 0x10c,
  26. .cmd = BIT(12),
  27. .pid_mask = GENMASK(6, 0),
  28. };
  29. static const struct {
  30. char *n;
  31. char *p;
  32. u8 id;
  33. } sama5d4_systemck[] = {
  34. { .n = "ddrck", .p = "masterck_div", .id = 2 },
  35. { .n = "lcdck", .p = "masterck_div", .id = 3 },
  36. { .n = "smdck", .p = "smdclk", .id = 4 },
  37. { .n = "uhpck", .p = "usbck", .id = 6 },
  38. { .n = "udpck", .p = "usbck", .id = 7 },
  39. { .n = "pck0", .p = "prog0", .id = 8 },
  40. { .n = "pck1", .p = "prog1", .id = 9 },
  41. { .n = "pck2", .p = "prog2", .id = 10 },
  42. };
  43. static const struct {
  44. char *n;
  45. u8 id;
  46. } sama5d4_periph32ck[] = {
  47. { .n = "pioD_clk", .id = 5 },
  48. { .n = "usart0_clk", .id = 6 },
  49. { .n = "usart1_clk", .id = 7 },
  50. { .n = "icm_clk", .id = 9 },
  51. { .n = "aes_clk", .id = 12 },
  52. { .n = "tdes_clk", .id = 14 },
  53. { .n = "sha_clk", .id = 15 },
  54. { .n = "matrix1_clk", .id = 17 },
  55. { .n = "hsmc_clk", .id = 22 },
  56. { .n = "pioA_clk", .id = 23 },
  57. { .n = "pioB_clk", .id = 24 },
  58. { .n = "pioC_clk", .id = 25 },
  59. { .n = "pioE_clk", .id = 26 },
  60. { .n = "uart0_clk", .id = 27 },
  61. { .n = "uart1_clk", .id = 28 },
  62. { .n = "usart2_clk", .id = 29 },
  63. { .n = "usart3_clk", .id = 30 },
  64. { .n = "usart4_clk", .id = 31 },
  65. { .n = "twi0_clk", .id = 32 },
  66. { .n = "twi1_clk", .id = 33 },
  67. { .n = "twi2_clk", .id = 34 },
  68. { .n = "mci0_clk", .id = 35 },
  69. { .n = "mci1_clk", .id = 36 },
  70. { .n = "spi0_clk", .id = 37 },
  71. { .n = "spi1_clk", .id = 38 },
  72. { .n = "spi2_clk", .id = 39 },
  73. { .n = "tcb0_clk", .id = 40 },
  74. { .n = "tcb1_clk", .id = 41 },
  75. { .n = "tcb2_clk", .id = 42 },
  76. { .n = "pwm_clk", .id = 43 },
  77. { .n = "adc_clk", .id = 44 },
  78. { .n = "dbgu_clk", .id = 45 },
  79. { .n = "uhphs_clk", .id = 46 },
  80. { .n = "udphs_clk", .id = 47 },
  81. { .n = "ssc0_clk", .id = 48 },
  82. { .n = "ssc1_clk", .id = 49 },
  83. { .n = "trng_clk", .id = 53 },
  84. { .n = "macb0_clk", .id = 54 },
  85. { .n = "macb1_clk", .id = 55 },
  86. { .n = "fuse_clk", .id = 57 },
  87. { .n = "securam_clk", .id = 59 },
  88. { .n = "smd_clk", .id = 61 },
  89. { .n = "twi3_clk", .id = 62 },
  90. { .n = "catb_clk", .id = 63 },
  91. };
  92. static const struct {
  93. char *n;
  94. u8 id;
  95. } sama5d4_periphck[] = {
  96. { .n = "dma0_clk", .id = 8 },
  97. { .n = "cpkcc_clk", .id = 10 },
  98. { .n = "aesb_clk", .id = 13 },
  99. { .n = "mpddr_clk", .id = 16 },
  100. { .n = "matrix0_clk", .id = 18 },
  101. { .n = "vdec_clk", .id = 19 },
  102. { .n = "dma1_clk", .id = 50 },
  103. { .n = "lcdc_clk", .id = 51 },
  104. { .n = "isi_clk", .id = 52 },
  105. };
  106. static void __init sama5d4_pmc_setup(struct device_node *np)
  107. {
  108. struct clk_range range = CLK_RANGE(0, 0);
  109. const char *slck_name, *mainxtal_name;
  110. struct pmc_data *sama5d4_pmc;
  111. const char *parent_names[5];
  112. struct regmap *regmap;
  113. struct clk_hw *hw;
  114. int i;
  115. bool bypass;
  116. i = of_property_match_string(np, "clock-names", "slow_clk");
  117. if (i < 0)
  118. return;
  119. slck_name = of_clk_get_parent_name(np, i);
  120. i = of_property_match_string(np, "clock-names", "main_xtal");
  121. if (i < 0)
  122. return;
  123. mainxtal_name = of_clk_get_parent_name(np, i);
  124. regmap = device_node_to_regmap(np);
  125. if (IS_ERR(regmap))
  126. return;
  127. sama5d4_pmc = pmc_data_allocate(PMC_PLLACK + 1,
  128. nck(sama5d4_systemck),
  129. nck(sama5d4_periph32ck), 0, 3);
  130. if (!sama5d4_pmc)
  131. return;
  132. hw = at91_clk_register_main_rc_osc(regmap, "main_rc_osc", 12000000,
  133. 100000000);
  134. if (IS_ERR(hw))
  135. goto err_free;
  136. bypass = of_property_read_bool(np, "atmel,osc-bypass");
  137. hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
  138. bypass);
  139. if (IS_ERR(hw))
  140. goto err_free;
  141. parent_names[0] = "main_rc_osc";
  142. parent_names[1] = "main_osc";
  143. hw = at91_clk_register_sam9x5_main(regmap, "mainck", parent_names, 2);
  144. if (IS_ERR(hw))
  145. goto err_free;
  146. hw = at91_clk_register_pll(regmap, "pllack", "mainck", 0,
  147. &sama5d3_pll_layout, &plla_characteristics);
  148. if (IS_ERR(hw))
  149. goto err_free;
  150. hw = at91_clk_register_plldiv(regmap, "plladivck", "pllack");
  151. if (IS_ERR(hw))
  152. goto err_free;
  153. sama5d4_pmc->chws[PMC_PLLACK] = hw;
  154. hw = at91_clk_register_utmi(regmap, NULL, "utmick", "mainck");
  155. if (IS_ERR(hw))
  156. goto err_free;
  157. sama5d4_pmc->chws[PMC_UTMI] = hw;
  158. parent_names[0] = slck_name;
  159. parent_names[1] = "mainck";
  160. parent_names[2] = "plladivck";
  161. parent_names[3] = "utmick";
  162. hw = at91_clk_register_master_pres(regmap, "masterck_pres", 4,
  163. parent_names,
  164. &at91sam9x5_master_layout,
  165. &mck_characteristics, &mck_lock);
  166. if (IS_ERR(hw))
  167. goto err_free;
  168. hw = at91_clk_register_master_div(regmap, "masterck_div",
  169. "masterck_pres",
  170. &at91sam9x5_master_layout,
  171. &mck_characteristics, &mck_lock,
  172. CLK_SET_RATE_GATE, 0);
  173. if (IS_ERR(hw))
  174. goto err_free;
  175. sama5d4_pmc->chws[PMC_MCK] = hw;
  176. hw = at91_clk_register_h32mx(regmap, "h32mxck", "masterck_div");
  177. if (IS_ERR(hw))
  178. goto err_free;
  179. sama5d4_pmc->chws[PMC_MCK2] = hw;
  180. parent_names[0] = "plladivck";
  181. parent_names[1] = "utmick";
  182. hw = at91sam9x5_clk_register_usb(regmap, "usbck", parent_names, 2);
  183. if (IS_ERR(hw))
  184. goto err_free;
  185. parent_names[0] = "plladivck";
  186. parent_names[1] = "utmick";
  187. hw = at91sam9x5_clk_register_smd(regmap, "smdclk", parent_names, 2);
  188. if (IS_ERR(hw))
  189. goto err_free;
  190. parent_names[0] = slck_name;
  191. parent_names[1] = "mainck";
  192. parent_names[2] = "plladivck";
  193. parent_names[3] = "utmick";
  194. parent_names[4] = "masterck_div";
  195. for (i = 0; i < 3; i++) {
  196. char name[6];
  197. snprintf(name, sizeof(name), "prog%d", i);
  198. hw = at91_clk_register_programmable(regmap, name,
  199. parent_names, 5, i,
  200. &at91sam9x5_programmable_layout,
  201. NULL);
  202. if (IS_ERR(hw))
  203. goto err_free;
  204. sama5d4_pmc->pchws[i] = hw;
  205. }
  206. for (i = 0; i < ARRAY_SIZE(sama5d4_systemck); i++) {
  207. hw = at91_clk_register_system(regmap, sama5d4_systemck[i].n,
  208. sama5d4_systemck[i].p,
  209. sama5d4_systemck[i].id);
  210. if (IS_ERR(hw))
  211. goto err_free;
  212. sama5d4_pmc->shws[sama5d4_systemck[i].id] = hw;
  213. }
  214. for (i = 0; i < ARRAY_SIZE(sama5d4_periphck); i++) {
  215. hw = at91_clk_register_sam9x5_peripheral(regmap, &pmc_pcr_lock,
  216. &sama5d4_pcr_layout,
  217. sama5d4_periphck[i].n,
  218. "masterck_div",
  219. sama5d4_periphck[i].id,
  220. &range, INT_MIN);
  221. if (IS_ERR(hw))
  222. goto err_free;
  223. sama5d4_pmc->phws[sama5d4_periphck[i].id] = hw;
  224. }
  225. for (i = 0; i < ARRAY_SIZE(sama5d4_periph32ck); i++) {
  226. hw = at91_clk_register_sam9x5_peripheral(regmap, &pmc_pcr_lock,
  227. &sama5d4_pcr_layout,
  228. sama5d4_periph32ck[i].n,
  229. "h32mxck",
  230. sama5d4_periph32ck[i].id,
  231. &range, INT_MIN);
  232. if (IS_ERR(hw))
  233. goto err_free;
  234. sama5d4_pmc->phws[sama5d4_periph32ck[i].id] = hw;
  235. }
  236. of_clk_add_hw_provider(np, of_clk_hw_pmc_get, sama5d4_pmc);
  237. return;
  238. err_free:
  239. kfree(sama5d4_pmc);
  240. }
  241. CLK_OF_DECLARE(sama5d4_pmc, "atmel,sama5d4-pmc", sama5d4_pmc_setup);