clock-sh5.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * arch/sh/kernel/cpu/sh5/clock-sh5.c
  3. *
  4. * SH-5 support for the clock framework
  5. *
  6. * Copyright (C) 2008 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <asm/clock.h>
  15. #include <asm/io.h>
  16. static int ifc_table[] = { 2, 4, 6, 8, 10, 12, 16, 24 };
  17. /* Clock, Power and Reset Controller */
  18. #define CPRC_BLOCK_OFF 0x01010000
  19. #define CPRC_BASE (PHYS_PERIPHERAL_BLOCK + CPRC_BLOCK_OFF)
  20. static unsigned long cprc_base;
  21. static void master_clk_init(struct clk *clk)
  22. {
  23. int idx = (__raw_readl(cprc_base + 0x00) >> 6) & 0x0007;
  24. clk->rate *= ifc_table[idx];
  25. }
  26. static struct sh_clk_ops sh5_master_clk_ops = {
  27. .init = master_clk_init,
  28. };
  29. static unsigned long module_clk_recalc(struct clk *clk)
  30. {
  31. int idx = (__raw_readw(cprc_base) >> 12) & 0x0007;
  32. return clk->parent->rate / ifc_table[idx];
  33. }
  34. static struct sh_clk_ops sh5_module_clk_ops = {
  35. .recalc = module_clk_recalc,
  36. };
  37. static unsigned long bus_clk_recalc(struct clk *clk)
  38. {
  39. int idx = (__raw_readw(cprc_base) >> 3) & 0x0007;
  40. return clk->parent->rate / ifc_table[idx];
  41. }
  42. static struct sh_clk_ops sh5_bus_clk_ops = {
  43. .recalc = bus_clk_recalc,
  44. };
  45. static unsigned long cpu_clk_recalc(struct clk *clk)
  46. {
  47. int idx = (__raw_readw(cprc_base) & 0x0007);
  48. return clk->parent->rate / ifc_table[idx];
  49. }
  50. static struct sh_clk_ops sh5_cpu_clk_ops = {
  51. .recalc = cpu_clk_recalc,
  52. };
  53. static struct sh_clk_ops *sh5_clk_ops[] = {
  54. &sh5_master_clk_ops,
  55. &sh5_module_clk_ops,
  56. &sh5_bus_clk_ops,
  57. &sh5_cpu_clk_ops,
  58. };
  59. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  60. {
  61. cprc_base = (unsigned long)ioremap_nocache(CPRC_BASE, 1024);
  62. BUG_ON(!cprc_base);
  63. if (idx < ARRAY_SIZE(sh5_clk_ops))
  64. *ops = sh5_clk_ops[idx];
  65. }