interface.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <[email protected]>
  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(sizeof(*clk_hw), GFP_KERNEL);
  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. u32 val;
  58. if (ti_clk_get_reg_addr(node, 0, &reg))
  59. return;
  60. if (!of_property_read_u32(node, "ti,bit-shift", &val))
  61. enable_bit = val;
  62. parent_name = of_clk_get_parent_name(node, 0);
  63. if (!parent_name) {
  64. pr_err("%pOFn must have a parent\n", node);
  65. return;
  66. }
  67. name = ti_dt_clk_name(node);
  68. clk = _register_interface(node, name, parent_name, &reg,
  69. enable_bit, ops);
  70. if (!IS_ERR(clk))
  71. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  72. }
  73. static void __init of_ti_interface_clk_setup(struct device_node *node)
  74. {
  75. _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
  76. }
  77. CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
  78. of_ti_interface_clk_setup);
  79. static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
  80. {
  81. _of_ti_interface_clk_setup(node, &clkhwops_iclk);
  82. }
  83. CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
  84. of_ti_no_wait_interface_clk_setup);
  85. #ifdef CONFIG_ARCH_OMAP3
  86. static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
  87. {
  88. _of_ti_interface_clk_setup(node,
  89. &clkhwops_omap3430es2_iclk_hsotgusb_wait);
  90. }
  91. CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
  92. of_ti_hsotgusb_interface_clk_setup);
  93. static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
  94. {
  95. _of_ti_interface_clk_setup(node,
  96. &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
  97. }
  98. CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
  99. of_ti_dss_interface_clk_setup);
  100. static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
  101. {
  102. _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
  103. }
  104. CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
  105. of_ti_ssi_interface_clk_setup);
  106. static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
  107. {
  108. _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
  109. }
  110. CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
  111. of_ti_am35xx_interface_clk_setup);
  112. #endif
  113. #ifdef CONFIG_SOC_OMAP2430
  114. static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
  115. {
  116. _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
  117. }
  118. CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
  119. of_ti_omap2430_interface_clk_setup);
  120. #endif