at91sam9rl.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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(sam9rl_mck_lock);
  8. static const struct clk_master_characteristics sam9rl_mck_characteristics = {
  9. .output = { .min = 0, .max = 94000000 },
  10. .divisors = { 1, 2, 4, 0 },
  11. };
  12. static u8 sam9rl_plla_out[] = { 0, 2 };
  13. static const struct clk_range sam9rl_plla_outputs[] = {
  14. { .min = 80000000, .max = 200000000 },
  15. { .min = 190000000, .max = 240000000 },
  16. };
  17. static const struct clk_pll_characteristics sam9rl_plla_characteristics = {
  18. .input = { .min = 1000000, .max = 32000000 },
  19. .num_output = ARRAY_SIZE(sam9rl_plla_outputs),
  20. .output = sam9rl_plla_outputs,
  21. .out = sam9rl_plla_out,
  22. };
  23. static const struct {
  24. char *n;
  25. char *p;
  26. u8 id;
  27. } at91sam9rl_systemck[] = {
  28. { .n = "pck0", .p = "prog0", .id = 8 },
  29. { .n = "pck1", .p = "prog1", .id = 9 },
  30. };
  31. static const struct {
  32. char *n;
  33. u8 id;
  34. } at91sam9rl_periphck[] = {
  35. { .n = "pioA_clk", .id = 2, },
  36. { .n = "pioB_clk", .id = 3, },
  37. { .n = "pioC_clk", .id = 4, },
  38. { .n = "pioD_clk", .id = 5, },
  39. { .n = "usart0_clk", .id = 6, },
  40. { .n = "usart1_clk", .id = 7, },
  41. { .n = "usart2_clk", .id = 8, },
  42. { .n = "usart3_clk", .id = 9, },
  43. { .n = "mci0_clk", .id = 10, },
  44. { .n = "twi0_clk", .id = 11, },
  45. { .n = "twi1_clk", .id = 12, },
  46. { .n = "spi0_clk", .id = 13, },
  47. { .n = "ssc0_clk", .id = 14, },
  48. { .n = "ssc1_clk", .id = 15, },
  49. { .n = "tc0_clk", .id = 16, },
  50. { .n = "tc1_clk", .id = 17, },
  51. { .n = "tc2_clk", .id = 18, },
  52. { .n = "pwm_clk", .id = 19, },
  53. { .n = "adc_clk", .id = 20, },
  54. { .n = "dma0_clk", .id = 21, },
  55. { .n = "udphs_clk", .id = 22, },
  56. { .n = "lcd_clk", .id = 23, },
  57. };
  58. static void __init at91sam9rl_pmc_setup(struct device_node *np)
  59. {
  60. const char *slck_name, *mainxtal_name;
  61. struct pmc_data *at91sam9rl_pmc;
  62. const char *parent_names[6];
  63. struct regmap *regmap;
  64. struct clk_hw *hw;
  65. int i;
  66. i = of_property_match_string(np, "clock-names", "slow_clk");
  67. if (i < 0)
  68. return;
  69. slck_name = of_clk_get_parent_name(np, i);
  70. i = of_property_match_string(np, "clock-names", "main_xtal");
  71. if (i < 0)
  72. return;
  73. mainxtal_name = of_clk_get_parent_name(np, i);
  74. regmap = device_node_to_regmap(np);
  75. if (IS_ERR(regmap))
  76. return;
  77. at91sam9rl_pmc = pmc_data_allocate(PMC_PLLACK + 1,
  78. nck(at91sam9rl_systemck),
  79. nck(at91sam9rl_periphck), 0, 2);
  80. if (!at91sam9rl_pmc)
  81. return;
  82. hw = at91_clk_register_rm9200_main(regmap, "mainck", mainxtal_name);
  83. if (IS_ERR(hw))
  84. goto err_free;
  85. at91sam9rl_pmc->chws[PMC_MAIN] = hw;
  86. hw = at91_clk_register_pll(regmap, "pllack", "mainck", 0,
  87. &at91rm9200_pll_layout,
  88. &sam9rl_plla_characteristics);
  89. if (IS_ERR(hw))
  90. goto err_free;
  91. at91sam9rl_pmc->chws[PMC_PLLACK] = hw;
  92. hw = at91_clk_register_utmi(regmap, NULL, "utmick", "mainck");
  93. if (IS_ERR(hw))
  94. goto err_free;
  95. at91sam9rl_pmc->chws[PMC_UTMI] = hw;
  96. parent_names[0] = slck_name;
  97. parent_names[1] = "mainck";
  98. parent_names[2] = "pllack";
  99. parent_names[3] = "utmick";
  100. hw = at91_clk_register_master_pres(regmap, "masterck_pres", 4,
  101. parent_names,
  102. &at91rm9200_master_layout,
  103. &sam9rl_mck_characteristics,
  104. &sam9rl_mck_lock);
  105. if (IS_ERR(hw))
  106. goto err_free;
  107. hw = at91_clk_register_master_div(regmap, "masterck_div",
  108. "masterck_pres",
  109. &at91rm9200_master_layout,
  110. &sam9rl_mck_characteristics,
  111. &sam9rl_mck_lock, CLK_SET_RATE_GATE, 0);
  112. if (IS_ERR(hw))
  113. goto err_free;
  114. at91sam9rl_pmc->chws[PMC_MCK] = hw;
  115. parent_names[0] = slck_name;
  116. parent_names[1] = "mainck";
  117. parent_names[2] = "pllack";
  118. parent_names[3] = "utmick";
  119. parent_names[4] = "masterck_div";
  120. for (i = 0; i < 2; i++) {
  121. char name[6];
  122. snprintf(name, sizeof(name), "prog%d", i);
  123. hw = at91_clk_register_programmable(regmap, name,
  124. parent_names, 5, i,
  125. &at91rm9200_programmable_layout,
  126. NULL);
  127. if (IS_ERR(hw))
  128. goto err_free;
  129. at91sam9rl_pmc->pchws[i] = hw;
  130. }
  131. for (i = 0; i < ARRAY_SIZE(at91sam9rl_systemck); i++) {
  132. hw = at91_clk_register_system(regmap, at91sam9rl_systemck[i].n,
  133. at91sam9rl_systemck[i].p,
  134. at91sam9rl_systemck[i].id);
  135. if (IS_ERR(hw))
  136. goto err_free;
  137. at91sam9rl_pmc->shws[at91sam9rl_systemck[i].id] = hw;
  138. }
  139. for (i = 0; i < ARRAY_SIZE(at91sam9rl_periphck); i++) {
  140. hw = at91_clk_register_peripheral(regmap,
  141. at91sam9rl_periphck[i].n,
  142. "masterck_div",
  143. at91sam9rl_periphck[i].id);
  144. if (IS_ERR(hw))
  145. goto err_free;
  146. at91sam9rl_pmc->phws[at91sam9rl_periphck[i].id] = hw;
  147. }
  148. of_clk_add_hw_provider(np, of_clk_hw_pmc_get, at91sam9rl_pmc);
  149. return;
  150. err_free:
  151. kfree(at91sam9rl_pmc);
  152. }
  153. CLK_OF_DECLARE(at91sam9rl_pmc, "atmel,at91sam9rl-pmc", at91sam9rl_pmc_setup);