at91sam9rl.c 4.3 KB

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