clock-cpg.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include <linux/clk.h>
  2. #include <linux/compiler.h>
  3. #include <linux/bootmem.h>
  4. #include <linux/io.h>
  5. #include <asm/clock.h>
  6. static int sh_clk_mstp32_enable(struct clk *clk)
  7. {
  8. __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
  9. clk->enable_reg);
  10. return 0;
  11. }
  12. static void sh_clk_mstp32_disable(struct clk *clk)
  13. {
  14. __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
  15. clk->enable_reg);
  16. }
  17. static struct clk_ops sh_clk_mstp32_clk_ops = {
  18. .enable = sh_clk_mstp32_enable,
  19. .disable = sh_clk_mstp32_disable,
  20. .recalc = followparent_recalc,
  21. };
  22. int __init sh_clk_mstp32_register(struct clk *clks, int nr)
  23. {
  24. struct clk *clkp;
  25. int ret = 0;
  26. int k;
  27. for (k = 0; !ret && (k < nr); k++) {
  28. clkp = clks + k;
  29. clkp->ops = &sh_clk_mstp32_clk_ops;
  30. ret |= clk_register(clkp);
  31. }
  32. return ret;
  33. }
  34. static unsigned long sh_clk_div4_recalc(struct clk *clk)
  35. {
  36. struct clk_div_mult_table *table = clk->priv;
  37. unsigned int idx;
  38. clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
  39. table, &clk->arch_flags);
  40. idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
  41. return clk->freq_table[idx].frequency;
  42. }
  43. static long sh_clk_div4_round_rate(struct clk *clk, unsigned long rate)
  44. {
  45. return clk_rate_table_round(clk, clk->freq_table, rate);
  46. }
  47. static struct clk_ops sh_clk_div4_clk_ops = {
  48. .recalc = sh_clk_div4_recalc,
  49. .round_rate = sh_clk_div4_round_rate,
  50. };
  51. int __init sh_clk_div4_register(struct clk *clks, int nr,
  52. struct clk_div_mult_table *table)
  53. {
  54. struct clk *clkp;
  55. void *freq_table;
  56. int nr_divs = table->nr_divisors;
  57. int freq_table_size = sizeof(struct cpufreq_frequency_table);
  58. int ret = 0;
  59. int k;
  60. freq_table_size *= (nr_divs + 1);
  61. freq_table = alloc_bootmem(freq_table_size * nr);
  62. if (!freq_table)
  63. return -ENOMEM;
  64. for (k = 0; !ret && (k < nr); k++) {
  65. clkp = clks + k;
  66. clkp->ops = &sh_clk_div4_clk_ops;
  67. clkp->id = -1;
  68. clkp->priv = table;
  69. clkp->freq_table = freq_table + (k * freq_table_size);
  70. clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
  71. ret = clk_register(clkp);
  72. }
  73. return ret;
  74. }
  75. #ifdef CONFIG_SH_CLK_CPG_LEGACY
  76. static struct clk master_clk = {
  77. .name = "master_clk",
  78. .flags = CLK_ENABLE_ON_INIT,
  79. .rate = CONFIG_SH_PCLK_FREQ,
  80. };
  81. static struct clk peripheral_clk = {
  82. .name = "peripheral_clk",
  83. .parent = &master_clk,
  84. .flags = CLK_ENABLE_ON_INIT,
  85. };
  86. static struct clk bus_clk = {
  87. .name = "bus_clk",
  88. .parent = &master_clk,
  89. .flags = CLK_ENABLE_ON_INIT,
  90. };
  91. static struct clk cpu_clk = {
  92. .name = "cpu_clk",
  93. .parent = &master_clk,
  94. .flags = CLK_ENABLE_ON_INIT,
  95. };
  96. /*
  97. * The ordering of these clocks matters, do not change it.
  98. */
  99. static struct clk *onchip_clocks[] = {
  100. &master_clk,
  101. &peripheral_clk,
  102. &bus_clk,
  103. &cpu_clk,
  104. };
  105. int __init __deprecated cpg_clk_init(void)
  106. {
  107. int i, ret = 0;
  108. for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
  109. struct clk *clk = onchip_clocks[i];
  110. arch_init_clk_ops(&clk->ops, i);
  111. if (clk->ops)
  112. ret |= clk_register(clk);
  113. }
  114. return ret;
  115. }
  116. /*
  117. * Placeholder for compatability, until the lazy CPUs do this
  118. * on their own.
  119. */
  120. int __init __weak arch_clk_init(void)
  121. {
  122. return cpg_clk_init();
  123. }
  124. #endif /* CONFIG_SH_CPG_CLK_LEGACY */