clk.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * linux/include/linux/clk.h
  3. *
  4. * Copyright (C) 2004 ARM Limited.
  5. * Written by Deep Blue Solutions Limited.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_CLK_H
  12. #define __LINUX_CLK_H
  13. struct device;
  14. /*
  15. * The base API.
  16. */
  17. /*
  18. * struct clk - an machine class defined object / cookie.
  19. */
  20. struct clk;
  21. /**
  22. * clk_get - lookup and obtain a reference to a clock producer.
  23. * @dev: device for clock "consumer"
  24. * @id: clock comsumer ID
  25. *
  26. * Returns a struct clk corresponding to the clock producer, or
  27. * valid IS_ERR() condition containing errno. The implementation
  28. * uses @dev and @id to determine the clock consumer, and thereby
  29. * the clock producer. (IOW, @id may be identical strings, but
  30. * clk_get may return different clock producers depending on @dev.)
  31. *
  32. * Drivers must assume that the clock source is not enabled.
  33. *
  34. * clk_get should not be called from within interrupt context.
  35. */
  36. struct clk *clk_get(struct device *dev, const char *id);
  37. /**
  38. * clk_enable - inform the system when the clock source should be running.
  39. * @clk: clock source
  40. *
  41. * If the clock can not be enabled/disabled, this should return success.
  42. *
  43. * Returns success (0) or negative errno.
  44. */
  45. int clk_enable(struct clk *clk);
  46. /**
  47. * clk_disable - inform the system when the clock source is no longer required.
  48. * @clk: clock source
  49. *
  50. * Inform the system that a clock source is no longer required by
  51. * a driver and may be shut down.
  52. *
  53. * Implementation detail: if the clock source is shared between
  54. * multiple drivers, clk_enable() calls must be balanced by the
  55. * same number of clk_disable() calls for the clock source to be
  56. * disabled.
  57. */
  58. void clk_disable(struct clk *clk);
  59. /**
  60. * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  61. * This is only valid once the clock source has been enabled.
  62. * @clk: clock source
  63. */
  64. unsigned long clk_get_rate(struct clk *clk);
  65. /**
  66. * clk_put - "free" the clock source
  67. * @clk: clock source
  68. *
  69. * Note: drivers must ensure that all clk_enable calls made on this
  70. * clock source are balanced by clk_disable calls prior to calling
  71. * this function.
  72. *
  73. * clk_put should not be called from within interrupt context.
  74. */
  75. void clk_put(struct clk *clk);
  76. /*
  77. * The remaining APIs are optional for machine class support.
  78. */
  79. /**
  80. * clk_round_rate - adjust a rate to the exact rate a clock can provide
  81. * @clk: clock source
  82. * @rate: desired clock rate in Hz
  83. *
  84. * Returns rounded clock rate in Hz, or negative errno.
  85. */
  86. long clk_round_rate(struct clk *clk, unsigned long rate);
  87. /**
  88. * clk_set_rate - set the clock rate for a clock source
  89. * @clk: clock source
  90. * @rate: desired clock rate in Hz
  91. *
  92. * Returns success (0) or negative errno.
  93. */
  94. int clk_set_rate(struct clk *clk, unsigned long rate);
  95. /**
  96. * clk_set_parent - set the parent clock source for this clock
  97. * @clk: clock source
  98. * @parent: parent clock source
  99. *
  100. * Returns success (0) or negative errno.
  101. */
  102. int clk_set_parent(struct clk *clk, struct clk *parent);
  103. /**
  104. * clk_get_parent - get the parent clock source for this clock
  105. * @clk: clock source
  106. *
  107. * Returns struct clk corresponding to parent clock source, or
  108. * valid IS_ERR() condition containing errno.
  109. */
  110. struct clk *clk_get_parent(struct clk *clk);
  111. /**
  112. * clk_get_sys - get a clock based upon the device name
  113. * @dev_id: device name
  114. * @con_id: connection ID
  115. *
  116. * Returns a struct clk corresponding to the clock producer, or
  117. * valid IS_ERR() condition containing errno. The implementation
  118. * uses @dev_id and @con_id to determine the clock consumer, and
  119. * thereby the clock producer. In contrast to clk_get() this function
  120. * takes the device name instead of the device itself for identification.
  121. *
  122. * Drivers must assume that the clock source is not enabled.
  123. *
  124. * clk_get_sys should not be called from within interrupt context.
  125. */
  126. struct clk *clk_get_sys(const char *dev_id, const char *con_id);
  127. #endif