interface.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #undef pr_fmt
  23. #define pr_fmt(fmt) "%s: " fmt, __func__
  24. static const struct clk_ops ti_interface_clk_ops = {
  25. .init = &omap2_init_clk_clkdm,
  26. .enable = &omap2_dflt_clk_enable,
  27. .disable = &omap2_dflt_clk_disable,
  28. .is_enabled = &omap2_dflt_clk_is_enabled,
  29. };
  30. static void __init _of_ti_interface_clk_setup(struct device_node *node,
  31. const struct clk_hw_omap_ops *ops)
  32. {
  33. struct clk *clk;
  34. struct clk_init_data init = { NULL };
  35. struct clk_hw_omap *clk_hw;
  36. const char *parent_name;
  37. u32 val;
  38. clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
  39. if (!clk_hw)
  40. return;
  41. clk_hw->hw.init = &init;
  42. clk_hw->ops = ops;
  43. clk_hw->flags = MEMMAP_ADDRESSING;
  44. clk_hw->enable_reg = ti_clk_get_reg_addr(node, 0);
  45. if (!clk_hw->enable_reg)
  46. goto cleanup;
  47. if (!of_property_read_u32(node, "ti,bit-shift", &val))
  48. clk_hw->enable_bit = val;
  49. init.name = node->name;
  50. init.ops = &ti_interface_clk_ops;
  51. init.flags = 0;
  52. parent_name = of_clk_get_parent_name(node, 0);
  53. if (!parent_name) {
  54. pr_err("%s must have a parent\n", node->name);
  55. goto cleanup;
  56. }
  57. init.num_parents = 1;
  58. init.parent_names = &parent_name;
  59. clk = clk_register(NULL, &clk_hw->hw);
  60. if (!IS_ERR(clk)) {
  61. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  62. omap2_init_clk_hw_omap_clocks(clk);
  63. return;
  64. }
  65. cleanup:
  66. kfree(clk_hw);
  67. }
  68. static void __init of_ti_interface_clk_setup(struct device_node *node)
  69. {
  70. _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
  71. }
  72. CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
  73. of_ti_interface_clk_setup);
  74. static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
  75. {
  76. _of_ti_interface_clk_setup(node, &clkhwops_iclk);
  77. }
  78. CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
  79. of_ti_no_wait_interface_clk_setup);
  80. #ifdef CONFIG_ARCH_OMAP3
  81. static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
  82. {
  83. _of_ti_interface_clk_setup(node,
  84. &clkhwops_omap3430es2_iclk_hsotgusb_wait);
  85. }
  86. CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
  87. of_ti_hsotgusb_interface_clk_setup);
  88. static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
  89. {
  90. _of_ti_interface_clk_setup(node,
  91. &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
  92. }
  93. CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
  94. of_ti_dss_interface_clk_setup);
  95. static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
  96. {
  97. _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
  98. }
  99. CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
  100. of_ti_ssi_interface_clk_setup);
  101. static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
  102. {
  103. _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
  104. }
  105. CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
  106. of_ti_am35xx_interface_clk_setup);
  107. #endif
  108. #ifdef CONFIG_SOC_OMAP2430
  109. static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
  110. {
  111. _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
  112. }
  113. CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
  114. of_ti_omap2430_interface_clk_setup);
  115. #endif