clock-cpg.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <linux/clk.h>
  2. #include <linux/compiler.h>
  3. #include <linux/io.h>
  4. #include <asm/clock.h>
  5. static int sh_clk_mstp32_enable(struct clk *clk)
  6. {
  7. __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
  8. clk->enable_reg);
  9. return 0;
  10. }
  11. static void sh_clk_mstp32_disable(struct clk *clk)
  12. {
  13. __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
  14. clk->enable_reg);
  15. }
  16. static struct clk_ops sh_clk_mstp32_clk_ops = {
  17. .enable = sh_clk_mstp32_enable,
  18. .disable = sh_clk_mstp32_disable,
  19. .recalc = followparent_recalc,
  20. };
  21. int __init sh_clk_mstp32_register(struct clk *clks, int nr)
  22. {
  23. struct clk *clkp;
  24. int ret = 0;
  25. int k;
  26. for (k = 0; !ret && (k < nr); k++) {
  27. clkp = clks + k;
  28. clkp->ops = &sh_clk_mstp32_clk_ops;
  29. ret |= clk_register(clkp);
  30. }
  31. return ret;
  32. }
  33. #ifdef CONFIG_SH_CLK_CPG_LEGACY
  34. static struct clk master_clk = {
  35. .name = "master_clk",
  36. .flags = CLK_ENABLE_ON_INIT,
  37. .rate = CONFIG_SH_PCLK_FREQ,
  38. };
  39. static struct clk peripheral_clk = {
  40. .name = "peripheral_clk",
  41. .parent = &master_clk,
  42. .flags = CLK_ENABLE_ON_INIT,
  43. };
  44. static struct clk bus_clk = {
  45. .name = "bus_clk",
  46. .parent = &master_clk,
  47. .flags = CLK_ENABLE_ON_INIT,
  48. };
  49. static struct clk cpu_clk = {
  50. .name = "cpu_clk",
  51. .parent = &master_clk,
  52. .flags = CLK_ENABLE_ON_INIT,
  53. };
  54. /*
  55. * The ordering of these clocks matters, do not change it.
  56. */
  57. static struct clk *onchip_clocks[] = {
  58. &master_clk,
  59. &peripheral_clk,
  60. &bus_clk,
  61. &cpu_clk,
  62. };
  63. int __init __deprecated cpg_clk_init(void)
  64. {
  65. int i, ret = 0;
  66. for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
  67. struct clk *clk = onchip_clocks[i];
  68. arch_init_clk_ops(&clk->ops, i);
  69. if (clk->ops)
  70. ret |= clk_register(clk);
  71. }
  72. return ret;
  73. }
  74. /*
  75. * Placeholder for compatability, until the lazy CPUs do this
  76. * on their own.
  77. */
  78. int __init __weak arch_clk_init(void)
  79. {
  80. return cpg_clk_init();
  81. }
  82. #endif /* CONFIG_SH_CPG_CLK_LEGACY */