clk-integrator.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Clock driver for the ARM Integrator/AP and Integrator/CP 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-provider.h>
  10. #include <linux/clk.h>
  11. #include <linux/clkdev.h>
  12. #include <linux/err.h>
  13. #include <linux/io.h>
  14. #include <mach/hardware.h>
  15. #include <mach/platform.h>
  16. #include "clk-icst.h"
  17. /*
  18. * Implementation of the ARM Integrator/AP and Integrator/CP clock tree.
  19. * Inspired by portions of:
  20. * plat-versatile/clock.c and plat-versatile/include/plat/clock.h
  21. */
  22. #define CM_LOCK (__io_address(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
  23. #define CM_AUXOSC (__io_address(INTEGRATOR_HDR_BASE)+0x1c)
  24. /**
  25. * cp_auxvco_get() - get ICST VCO settings for the Integrator/CP
  26. * @vco: ICST VCO parameters to update with hardware status
  27. */
  28. static struct icst_vco cp_auxvco_get(void)
  29. {
  30. u32 val;
  31. struct icst_vco vco;
  32. val = readl(CM_AUXOSC);
  33. vco.v = val & 0x1ff;
  34. vco.r = (val >> 9) & 0x7f;
  35. vco.s = (val >> 16) & 03;
  36. return vco;
  37. }
  38. /**
  39. * cp_auxvco_set() - commit changes to Integrator/CP ICST VCO
  40. * @vco: ICST VCO parameters to commit
  41. */
  42. static void cp_auxvco_set(struct icst_vco vco)
  43. {
  44. u32 val;
  45. val = readl(CM_AUXOSC) & ~0x7ffff;
  46. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  47. /* This magic unlocks the CM VCO so it can be controlled */
  48. writel(0xa05f, CM_LOCK);
  49. writel(val, CM_AUXOSC);
  50. /* This locks the CM again */
  51. writel(0, CM_LOCK);
  52. }
  53. static const struct icst_params cp_auxvco_params = {
  54. .ref = 24000000,
  55. .vco_max = ICST525_VCO_MAX_5V,
  56. .vco_min = ICST525_VCO_MIN,
  57. .vd_min = 8,
  58. .vd_max = 263,
  59. .rd_min = 3,
  60. .rd_max = 65,
  61. .s2div = icst525_s2div,
  62. .idx2s = icst525_idx2s,
  63. };
  64. static const struct clk_icst_desc __initdata cp_icst_desc = {
  65. .params = &cp_auxvco_params,
  66. .getvco = cp_auxvco_get,
  67. .setvco = cp_auxvco_set,
  68. };
  69. /*
  70. * integrator_clk_init() - set up the integrator clock tree
  71. * @is_cp: pass true if it's the Integrator/CP else AP is assumed
  72. */
  73. void __init integrator_clk_init(bool is_cp)
  74. {
  75. struct clk *clk;
  76. /* APB clock dummy */
  77. clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0);
  78. clk_register_clkdev(clk, "apb_pclk", NULL);
  79. /* UART reference clock */
  80. clk = clk_register_fixed_rate(NULL, "uartclk", NULL, CLK_IS_ROOT,
  81. 14745600);
  82. clk_register_clkdev(clk, NULL, "uart0");
  83. clk_register_clkdev(clk, NULL, "uart1");
  84. if (is_cp)
  85. clk_register_clkdev(clk, NULL, "mmci");
  86. /* 24 MHz clock */
  87. clk = clk_register_fixed_rate(NULL, "clk24mhz", NULL, CLK_IS_ROOT,
  88. 24000000);
  89. clk_register_clkdev(clk, NULL, "kmi0");
  90. clk_register_clkdev(clk, NULL, "kmi1");
  91. if (!is_cp)
  92. clk_register_clkdev(clk, NULL, "ap_timer");
  93. if (!is_cp)
  94. return;
  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 used on the Integrator/CP CLCD */
  100. clk = icst_clk_register(NULL, &cp_icst_desc);
  101. clk_register_clkdev(clk, NULL, "clcd");
  102. }