clk-impd1.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Clock driver for the ARM Integrator/IM-PD1 board
  3. * Copyright (C) 2012-2013 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 <linux/platform_data/clk-integrator.h>
  15. #include <mach/impd1.h>
  16. #include "clk-icst.h"
  17. struct impd1_clk {
  18. char *vco1name;
  19. struct clk *vco1clk;
  20. char *vco2name;
  21. struct clk *vco2clk;
  22. struct clk *mmciclk;
  23. char *uartname;
  24. struct clk *uartclk;
  25. char *spiname;
  26. struct clk *spiclk;
  27. char *scname;
  28. struct clk *scclk;
  29. struct clk_lookup *clks[6];
  30. };
  31. /* One entry for each connected IM-PD1 LM */
  32. static struct impd1_clk impd1_clks[4];
  33. /*
  34. * There are two VCO's on the IM-PD1
  35. */
  36. static const struct icst_params impd1_vco1_params = {
  37. .ref = 24000000, /* 24 MHz */
  38. .vco_max = ICST525_VCO_MAX_3V,
  39. .vco_min = ICST525_VCO_MIN,
  40. .vd_min = 12,
  41. .vd_max = 519,
  42. .rd_min = 3,
  43. .rd_max = 120,
  44. .s2div = icst525_s2div,
  45. .idx2s = icst525_idx2s,
  46. };
  47. static const struct clk_icst_desc impd1_icst1_desc = {
  48. .params = &impd1_vco1_params,
  49. .vco_offset = IMPD1_OSC1,
  50. .lock_offset = IMPD1_LOCK,
  51. };
  52. static const struct icst_params impd1_vco2_params = {
  53. .ref = 24000000, /* 24 MHz */
  54. .vco_max = ICST525_VCO_MAX_3V,
  55. .vco_min = ICST525_VCO_MIN,
  56. .vd_min = 12,
  57. .vd_max = 519,
  58. .rd_min = 3,
  59. .rd_max = 120,
  60. .s2div = icst525_s2div,
  61. .idx2s = icst525_idx2s,
  62. };
  63. static const struct clk_icst_desc impd1_icst2_desc = {
  64. .params = &impd1_vco2_params,
  65. .vco_offset = IMPD1_OSC2,
  66. .lock_offset = IMPD1_LOCK,
  67. };
  68. /**
  69. * integrator_impd1_clk_init() - set up the integrator clock tree
  70. * @base: base address of the logic module (LM)
  71. * @id: the ID of this LM
  72. */
  73. void integrator_impd1_clk_init(void __iomem *base, unsigned int id)
  74. {
  75. struct impd1_clk *imc;
  76. struct clk *clk;
  77. int i;
  78. if (id > 3) {
  79. pr_crit("no more than 4 LMs can be attached\n");
  80. return;
  81. }
  82. imc = &impd1_clks[id];
  83. imc->vco1name = kasprintf(GFP_KERNEL, "lm%x-vco1", id);
  84. clk = icst_clk_register(NULL, &impd1_icst1_desc, imc->vco1name, base);
  85. imc->vco1clk = clk;
  86. imc->clks[0] = clkdev_alloc(clk, NULL, "lm%x:01000", id);
  87. /* VCO2 is also called "CLK2" */
  88. imc->vco2name = kasprintf(GFP_KERNEL, "lm%x-vco2", id);
  89. clk = icst_clk_register(NULL, &impd1_icst2_desc, imc->vco2name, base);
  90. imc->vco2clk = clk;
  91. /* MMCI uses CLK2 right off */
  92. imc->clks[1] = clkdev_alloc(clk, NULL, "lm%x:00700", id);
  93. /* UART reference clock divides CLK2 by a fixed factor 4 */
  94. imc->uartname = kasprintf(GFP_KERNEL, "lm%x-uartclk", id);
  95. clk = clk_register_fixed_factor(NULL, imc->uartname, imc->vco2name,
  96. CLK_IGNORE_UNUSED, 1, 4);
  97. imc->uartclk = clk;
  98. imc->clks[2] = clkdev_alloc(clk, NULL, "lm%x:00100", id);
  99. imc->clks[3] = clkdev_alloc(clk, NULL, "lm%x:00200", id);
  100. /* SPI PL022 clock divides CLK2 by a fixed factor 64 */
  101. imc->spiname = kasprintf(GFP_KERNEL, "lm%x-spiclk", id);
  102. clk = clk_register_fixed_factor(NULL, imc->spiname, imc->vco2name,
  103. CLK_IGNORE_UNUSED, 1, 64);
  104. imc->clks[4] = clkdev_alloc(clk, NULL, "lm%x:00300", id);
  105. /* Smart Card clock divides CLK2 by a fixed factor 4 */
  106. imc->scname = kasprintf(GFP_KERNEL, "lm%x-scclk", id);
  107. clk = clk_register_fixed_factor(NULL, imc->scname, imc->vco2name,
  108. CLK_IGNORE_UNUSED, 1, 4);
  109. imc->scclk = clk;
  110. imc->clks[5] = clkdev_alloc(clk, NULL, "lm%x:00600", id);
  111. for (i = 0; i < ARRAY_SIZE(imc->clks); i++)
  112. clkdev_add(imc->clks[i]);
  113. }
  114. void integrator_impd1_clk_exit(unsigned int id)
  115. {
  116. int i;
  117. struct impd1_clk *imc;
  118. if (id > 3)
  119. return;
  120. imc = &impd1_clks[id];
  121. for (i = 0; i < ARRAY_SIZE(imc->clks); i++)
  122. clkdev_drop(imc->clks[i]);
  123. clk_unregister(imc->spiclk);
  124. clk_unregister(imc->uartclk);
  125. clk_unregister(imc->vco2clk);
  126. clk_unregister(imc->vco1clk);
  127. kfree(imc->scname);
  128. kfree(imc->spiname);
  129. kfree(imc->uartname);
  130. kfree(imc->vco2name);
  131. kfree(imc->vco1name);
  132. }