clk-versatile.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Clock driver for the ARM Integrator/AP, Integrator/CP, Versatile AB and
  3. * Versatile PB boards.
  4. * Copyright (C) 2012 Linus Walleij
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/clk-provider.h>
  11. #include <linux/err.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include "icst.h"
  15. #include "clk-icst.h"
  16. #define INTEGRATOR_HDR_LOCK_OFFSET 0x14
  17. #define VERSATILE_SYS_OSCCLCD_OFFSET 0x1c
  18. #define VERSATILE_SYS_LOCK_OFFSET 0x20
  19. /* Base offset for the core module */
  20. static void __iomem *cm_base;
  21. static const struct icst_params cp_auxosc_params = {
  22. .vco_max = ICST525_VCO_MAX_5V,
  23. .vco_min = ICST525_VCO_MIN,
  24. .vd_min = 8,
  25. .vd_max = 263,
  26. .rd_min = 3,
  27. .rd_max = 65,
  28. .s2div = icst525_s2div,
  29. .idx2s = icst525_idx2s,
  30. };
  31. static const struct clk_icst_desc cm_auxosc_desc __initconst = {
  32. .params = &cp_auxosc_params,
  33. .vco_offset = 0x1c,
  34. .lock_offset = INTEGRATOR_HDR_LOCK_OFFSET,
  35. };
  36. static const struct icst_params versatile_auxosc_params = {
  37. .vco_max = ICST307_VCO_MAX,
  38. .vco_min = ICST307_VCO_MIN,
  39. .vd_min = 4 + 8,
  40. .vd_max = 511 + 8,
  41. .rd_min = 1 + 2,
  42. .rd_max = 127 + 2,
  43. .s2div = icst307_s2div,
  44. .idx2s = icst307_idx2s,
  45. };
  46. static const struct clk_icst_desc versatile_auxosc_desc __initconst = {
  47. .params = &versatile_auxosc_params,
  48. .vco_offset = VERSATILE_SYS_OSCCLCD_OFFSET,
  49. .lock_offset = VERSATILE_SYS_LOCK_OFFSET,
  50. };
  51. static void __init cm_osc_setup(struct device_node *np,
  52. const struct clk_icst_desc *desc)
  53. {
  54. struct clk *clk = ERR_PTR(-EINVAL);
  55. const char *clk_name = np->name;
  56. const char *parent_name;
  57. if (!cm_base) {
  58. /* Remap the core module base if not done yet */
  59. struct device_node *parent;
  60. parent = of_get_parent(np);
  61. if (!parent) {
  62. pr_err("no parent on core module clock\n");
  63. return;
  64. }
  65. cm_base = of_iomap(parent, 0);
  66. if (!cm_base) {
  67. pr_err("could not remap core module base\n");
  68. return;
  69. }
  70. }
  71. parent_name = of_clk_get_parent_name(np, 0);
  72. clk = icst_clk_register(NULL, desc, clk_name, parent_name, cm_base);
  73. if (!IS_ERR(clk))
  74. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  75. }
  76. static void __init of_integrator_cm_osc_setup(struct device_node *np)
  77. {
  78. cm_osc_setup(np, &cm_auxosc_desc);
  79. }
  80. CLK_OF_DECLARE(integrator_cm_auxosc_clk,
  81. "arm,integrator-cm-auxosc", of_integrator_cm_osc_setup);
  82. static void __init of_versatile_cm_osc_setup(struct device_node *np)
  83. {
  84. cm_osc_setup(np, &versatile_auxosc_desc);
  85. }
  86. CLK_OF_DECLARE(versatile_cm_auxosc_clk,
  87. "arm,versatile-cm-auxosc", of_versatile_cm_osc_setup);