interface.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * OMAP interface clock support
  3. *
  4. * Copyright (C) 2013 Texas Instruments, Inc.
  5. *
  6. * Tero Kristo <t-kristo@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  13. * kind, whether express or implied; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk-provider.h>
  18. #include <linux/slab.h>
  19. #include <linux/of.h>
  20. #include <linux/of_address.h>
  21. #include <linux/clk/ti.h>
  22. #include "clock.h"
  23. #undef pr_fmt
  24. #define pr_fmt(fmt) "%s: " fmt, __func__
  25. static const struct clk_ops ti_interface_clk_ops = {
  26. .init = &omap2_init_clk_clkdm,
  27. .enable = &omap2_dflt_clk_enable,
  28. .disable = &omap2_dflt_clk_disable,
  29. .is_enabled = &omap2_dflt_clk_is_enabled,
  30. };
  31. static struct clk *_register_interface(struct device *dev, const char *name,
  32. const char *parent_name,
  33. struct clk_omap_reg *reg, u8 bit_idx,
  34. const struct clk_hw_omap_ops *ops)
  35. {
  36. struct clk_init_data init = { NULL };
  37. struct clk_hw_omap *clk_hw;
  38. struct clk *clk;
  39. clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
  40. if (!clk_hw)
  41. return ERR_PTR(-ENOMEM);
  42. clk_hw->hw.init = &init;
  43. clk_hw->ops = ops;
  44. memcpy(&clk_hw->enable_reg, reg, sizeof(*reg));
  45. clk_hw->enable_bit = bit_idx;
  46. init.name = name;
  47. init.ops = &ti_interface_clk_ops;
  48. init.flags = 0;
  49. init.num_parents = 1;
  50. init.parent_names = &parent_name;
  51. clk = ti_clk_register_omap_hw(NULL, &clk_hw->hw, name);
  52. if (IS_ERR(clk))
  53. kfree(clk_hw);
  54. return clk;
  55. }
  56. static void __init _of_ti_interface_clk_setup(struct device_node *node,
  57. const struct clk_hw_omap_ops *ops)
  58. {
  59. struct clk *clk;
  60. const char *parent_name;
  61. struct clk_omap_reg reg;
  62. u8 enable_bit = 0;
  63. u32 val;
  64. if (ti_clk_get_reg_addr(node, 0, &reg))
  65. return;
  66. if (!of_property_read_u32(node, "ti,bit-shift", &val))
  67. enable_bit = val;
  68. parent_name = of_clk_get_parent_name(node, 0);
  69. if (!parent_name) {
  70. pr_err("%pOFn must have a parent\n", node);
  71. return;
  72. }
  73. clk = _register_interface(NULL, node->name, parent_name, &reg,
  74. enable_bit, ops);
  75. if (!IS_ERR(clk))
  76. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  77. }
  78. static void __init of_ti_interface_clk_setup(struct device_node *node)
  79. {
  80. _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
  81. }
  82. CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
  83. of_ti_interface_clk_setup);
  84. static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
  85. {
  86. _of_ti_interface_clk_setup(node, &clkhwops_iclk);
  87. }
  88. CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
  89. of_ti_no_wait_interface_clk_setup);
  90. #ifdef CONFIG_ARCH_OMAP3
  91. static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
  92. {
  93. _of_ti_interface_clk_setup(node,
  94. &clkhwops_omap3430es2_iclk_hsotgusb_wait);
  95. }
  96. CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
  97. of_ti_hsotgusb_interface_clk_setup);
  98. static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
  99. {
  100. _of_ti_interface_clk_setup(node,
  101. &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
  102. }
  103. CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
  104. of_ti_dss_interface_clk_setup);
  105. static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
  106. {
  107. _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
  108. }
  109. CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
  110. of_ti_ssi_interface_clk_setup);
  111. static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
  112. {
  113. _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
  114. }
  115. CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
  116. of_ti_am35xx_interface_clk_setup);
  117. #endif
  118. #ifdef CONFIG_SOC_OMAP2430
  119. static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
  120. {
  121. _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
  122. }
  123. CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
  124. of_ti_omap2430_interface_clk_setup);
  125. #endif