clock-sh7763.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7763.c
  3. *
  4. * SH7763 support for the clock framework
  5. *
  6. * Copyright (C) 2005 Paul Mundt
  7. * Copyright (C) 2007 Yoshihiro Shimoda
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/io.h>
  16. #include <linux/clkdev.h>
  17. #include <asm/clock.h>
  18. #include <asm/freq.h>
  19. #include <asm/io.h>
  20. static int bfc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  21. static int p0fc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
  22. static int cfc_divisors[] = { 1, 1, 4, 1, 1, 1, 1, 1 };
  23. static void master_clk_init(struct clk *clk)
  24. {
  25. clk->rate *= p0fc_divisors[(__raw_readl(FRQCR) >> 4) & 0x07];
  26. }
  27. static struct sh_clk_ops sh7763_master_clk_ops = {
  28. .init = master_clk_init,
  29. };
  30. static unsigned long module_clk_recalc(struct clk *clk)
  31. {
  32. int idx = ((__raw_readl(FRQCR) >> 4) & 0x07);
  33. return clk->parent->rate / p0fc_divisors[idx];
  34. }
  35. static struct sh_clk_ops sh7763_module_clk_ops = {
  36. .recalc = module_clk_recalc,
  37. };
  38. static unsigned long bus_clk_recalc(struct clk *clk)
  39. {
  40. int idx = ((__raw_readl(FRQCR) >> 16) & 0x07);
  41. return clk->parent->rate / bfc_divisors[idx];
  42. }
  43. static struct sh_clk_ops sh7763_bus_clk_ops = {
  44. .recalc = bus_clk_recalc,
  45. };
  46. static struct sh_clk_ops sh7763_cpu_clk_ops = {
  47. .recalc = followparent_recalc,
  48. };
  49. static struct sh_clk_ops *sh7763_clk_ops[] = {
  50. &sh7763_master_clk_ops,
  51. &sh7763_module_clk_ops,
  52. &sh7763_bus_clk_ops,
  53. &sh7763_cpu_clk_ops,
  54. };
  55. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  56. {
  57. if (idx < ARRAY_SIZE(sh7763_clk_ops))
  58. *ops = sh7763_clk_ops[idx];
  59. }
  60. static unsigned long shyway_clk_recalc(struct clk *clk)
  61. {
  62. int idx = ((__raw_readl(FRQCR) >> 20) & 0x07);
  63. return clk->parent->rate / cfc_divisors[idx];
  64. }
  65. static struct sh_clk_ops sh7763_shyway_clk_ops = {
  66. .recalc = shyway_clk_recalc,
  67. };
  68. static struct clk sh7763_shyway_clk = {
  69. .flags = CLK_ENABLE_ON_INIT,
  70. .ops = &sh7763_shyway_clk_ops,
  71. };
  72. /*
  73. * Additional SH7763-specific on-chip clocks that aren't already part of the
  74. * clock framework
  75. */
  76. static struct clk *sh7763_onchip_clocks[] = {
  77. &sh7763_shyway_clk,
  78. };
  79. static struct clk_lookup lookups[] = {
  80. /* main clocks */
  81. CLKDEV_CON_ID("shyway_clk", &sh7763_shyway_clk),
  82. };
  83. int __init arch_clk_init(void)
  84. {
  85. struct clk *clk;
  86. int i, ret = 0;
  87. cpg_clk_init();
  88. clk = clk_get(NULL, "master_clk");
  89. for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
  90. struct clk *clkp = sh7763_onchip_clocks[i];
  91. clkp->parent = clk;
  92. ret |= clk_register(clkp);
  93. }
  94. clk_put(clk);
  95. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  96. return ret;
  97. }