clk-realview.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Clock driver for the ARM RealView boards
  3. * Copyright (C) 2012 Linus Walleij
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/clkdev.h>
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/clk-provider.h>
  14. #include <mach/hardware.h>
  15. #include <mach/platform.h>
  16. #include "clk-icst.h"
  17. /*
  18. * Implementation of the ARM RealView clock trees.
  19. */
  20. static void __iomem *sys_lock;
  21. static void __iomem *sys_vcoreg;
  22. /**
  23. * realview_oscvco_get() - get ICST OSC settings for the RealView
  24. */
  25. static struct icst_vco realview_oscvco_get(void)
  26. {
  27. u32 val;
  28. struct icst_vco vco;
  29. val = readl(sys_vcoreg);
  30. vco.v = val & 0x1ff;
  31. vco.r = (val >> 9) & 0x7f;
  32. vco.s = (val >> 16) & 03;
  33. return vco;
  34. }
  35. static void realview_oscvco_set(struct icst_vco vco)
  36. {
  37. u32 val;
  38. val = readl(sys_vcoreg) & ~0x7ffff;
  39. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  40. /* This magic unlocks the CM VCO so it can be controlled */
  41. writel(0xa05f, sys_lock);
  42. writel(val, sys_vcoreg);
  43. /* This locks the CM again */
  44. writel(0, sys_lock);
  45. }
  46. static const struct icst_params realview_oscvco_params = {
  47. .ref = 24000000,
  48. .vco_max = ICST307_VCO_MAX,
  49. .vco_min = ICST307_VCO_MIN,
  50. .vd_min = 4 + 8,
  51. .vd_max = 511 + 8,
  52. .rd_min = 1 + 2,
  53. .rd_max = 127 + 2,
  54. .s2div = icst307_s2div,
  55. .idx2s = icst307_idx2s,
  56. };
  57. static const struct clk_icst_desc __initdata realview_icst_desc = {
  58. .params = &realview_oscvco_params,
  59. .getvco = realview_oscvco_get,
  60. .setvco = realview_oscvco_set,
  61. };
  62. /*
  63. * realview_clk_init() - set up the RealView clock tree
  64. */
  65. void __init realview_clk_init(void __iomem *sysbase, bool is_pb1176)
  66. {
  67. struct clk *clk;
  68. sys_lock = sysbase + REALVIEW_SYS_LOCK_OFFSET;
  69. if (is_pb1176)
  70. sys_vcoreg = sysbase + REALVIEW_SYS_OSC0_OFFSET;
  71. else
  72. sys_vcoreg = sysbase + REALVIEW_SYS_OSC4_OFFSET;
  73. /* APB clock dummy */
  74. clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
  75. clk_register_clkdev(clk, "apb_pclk", NULL);
  76. /* 24 MHz clock */
  77. clk = clk_register_fixed_rate(NULL, "clk24mhz", NULL, CLK_IS_ROOT,
  78. 24000000);
  79. clk_register_clkdev(clk, NULL, "dev:uart0");
  80. clk_register_clkdev(clk, NULL, "dev:uart1");
  81. clk_register_clkdev(clk, NULL, "dev:uart2");
  82. clk_register_clkdev(clk, NULL, "fpga:kmi0");
  83. clk_register_clkdev(clk, NULL, "fpga:kmi1");
  84. clk_register_clkdev(clk, NULL, "fpga:mmc0");
  85. clk_register_clkdev(clk, NULL, "dev:ssp0");
  86. if (is_pb1176) {
  87. /*
  88. * UART3 is on the dev chip in PB1176
  89. * UART4 only exists in PB1176
  90. */
  91. clk_register_clkdev(clk, NULL, "dev:uart3");
  92. clk_register_clkdev(clk, NULL, "dev:uart4");
  93. } else
  94. clk_register_clkdev(clk, NULL, "fpga:uart3");
  95. /* 1 MHz clock */
  96. clk = clk_register_fixed_rate(NULL, "clk1mhz", NULL, CLK_IS_ROOT,
  97. 1000000);
  98. clk_register_clkdev(clk, NULL, "sp804");
  99. /* ICST VCO clock */
  100. clk = icst_clk_register(NULL, &realview_icst_desc);
  101. clk_register_clkdev(clk, NULL, "dev:clcd");
  102. clk_register_clkdev(clk, NULL, "issp:clcd");
  103. }