interface.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP interface clock support
  4. *
  5. * Copyright (C) 2013 Texas Instruments, Inc.
  6. *
  7. * Tero Kristo <t-kristo@ti.com>
  8. */
  9. #include <linux/clk-provider.h>
  10. #include <linux/slab.h>
  11. #include <linux/of.h>
  12. #include <linux/of_address.h>
  13. #include <linux/clk/ti.h>
  14. #include "clock.h"
  15. #undef pr_fmt
  16. #define pr_fmt(fmt) "%s: " fmt, __func__
  17. static const struct clk_ops ti_interface_clk_ops = {
  18. .init = &omap2_init_clk_clkdm,
  19. .enable = &omap2_dflt_clk_enable,
  20. .disable = &omap2_dflt_clk_disable,
  21. .is_enabled = &omap2_dflt_clk_is_enabled,
  22. };
  23. static struct clk *_register_interface(struct device_node *node,
  24. const char *name,
  25. const char *parent_name,
  26. struct clk_omap_reg *reg, u8 bit_idx,
  27. const struct clk_hw_omap_ops *ops)
  28. {
  29. struct clk_init_data init = { NULL };
  30. struct clk_hw_omap *clk_hw;
  31. struct clk *clk;
  32. clk_hw = kzalloc_obj(*clk_hw);
  33. if (!clk_hw)
  34. return ERR_PTR(-ENOMEM);
  35. clk_hw->hw.init = &init;
  36. clk_hw->ops = ops;
  37. memcpy(&clk_hw->enable_reg, reg, sizeof(*reg));
  38. clk_hw->enable_bit = bit_idx;
  39. init.name = name;
  40. init.ops = &ti_interface_clk_ops;
  41. init.flags = 0;
  42. init.num_parents = 1;
  43. init.parent_names = &parent_name;
  44. clk = of_ti_clk_register_omap_hw(node, &clk_hw->hw, name);
  45. if (IS_ERR(clk))
  46. kfree(clk_hw);
  47. return clk;
  48. }
  49. static void __init _of_ti_interface_clk_setup(struct device_node *node,
  50. const struct clk_hw_omap_ops *ops)
  51. {
  52. struct clk *clk;
  53. const char *parent_name;
  54. struct clk_omap_reg reg;
  55. u8 enable_bit = 0;
  56. const char *name;
  57. if (ti_clk_get_reg_addr(node, 0, &reg))
  58. return;
  59. enable_bit = reg.bit;
  60. parent_name = of_clk_get_parent_name(node, 0);
  61. if (!parent_name) {
  62. pr_err("%pOFn must have a parent\n", node);
  63. return;
  64. }
  65. name = ti_dt_clk_name(node);
  66. clk = _register_interface(node, name, parent_name, &reg,
  67. enable_bit, ops);
  68. if (!IS_ERR(clk))
  69. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  70. }
  71. static void __init of_ti_interface_clk_setup(struct device_node *node)
  72. {
  73. _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
  74. }
  75. CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
  76. of_ti_interface_clk_setup);
  77. static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
  78. {
  79. _of_ti_interface_clk_setup(node, &clkhwops_iclk);
  80. }
  81. CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
  82. of_ti_no_wait_interface_clk_setup);
  83. #ifdef CONFIG_ARCH_OMAP3
  84. static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
  85. {
  86. _of_ti_interface_clk_setup(node,
  87. &clkhwops_omap3430es2_iclk_hsotgusb_wait);
  88. }
  89. CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
  90. of_ti_hsotgusb_interface_clk_setup);
  91. static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
  92. {
  93. _of_ti_interface_clk_setup(node,
  94. &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
  95. }
  96. CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
  97. of_ti_dss_interface_clk_setup);
  98. static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
  99. {
  100. _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
  101. }
  102. CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
  103. of_ti_ssi_interface_clk_setup);
  104. static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
  105. {
  106. _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
  107. }
  108. CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
  109. of_ti_am35xx_interface_clk_setup);
  110. #endif
  111. #ifdef CONFIG_SOC_OMAP2430
  112. static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
  113. {
  114. _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
  115. }
  116. CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
  117. of_ti_omap2430_interface_clk_setup);
  118. #endif