clk.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. #include <linux/kernel.h>
  14. struct device;
  15. /*
  16. * The base API.
  17. */
  18. /*
  19. * struct clk - an machine class defined object / cookie.
  20. */
  21. struct clk;
  22. /**
  23. * clk_get - lookup and obtain a reference to a clock producer.
  24. * @dev: device for clock "consumer"
  25. * @id: clock comsumer ID
  26. *
  27. * Returns a struct clk corresponding to the clock producer, or
  28. * valid IS_ERR() condition containing errno. The implementation
  29. * uses @dev and @id to determine the clock consumer, and thereby
  30. * the clock producer. (IOW, @id may be identical strings, but
  31. * clk_get may return different clock producers depending on @dev.)
  32. *
  33. * Drivers must assume that the clock source is not enabled.
  34. *
  35. * clk_get should not be called from within interrupt context.
  36. */
  37. struct clk *clk_get(struct device *dev, const char *id);
  38. /**
  39. * clk_prepare - prepare a clock source
  40. * @clk: clock source
  41. *
  42. * This prepares the clock source for use.
  43. *
  44. * Must not be called from within atomic context.
  45. */
  46. #ifdef CONFIG_HAVE_CLK_PREPARE
  47. int clk_prepare(struct clk *clk);
  48. #else
  49. static inline int clk_prepare(struct clk *clk)
  50. {
  51. might_sleep();
  52. return 0;
  53. }
  54. #endif
  55. /**
  56. * clk_enable - inform the system when the clock source should be running.
  57. * @clk: clock source
  58. *
  59. * If the clock can not be enabled/disabled, this should return success.
  60. *
  61. * May be called from atomic contexts.
  62. *
  63. * Returns success (0) or negative errno.
  64. */
  65. int clk_enable(struct clk *clk);
  66. /**
  67. * clk_disable - inform the system when the clock source is no longer required.
  68. * @clk: clock source
  69. *
  70. * Inform the system that a clock source is no longer required by
  71. * a driver and may be shut down.
  72. *
  73. * May be called from atomic contexts.
  74. *
  75. * Implementation detail: if the clock source is shared between
  76. * multiple drivers, clk_enable() calls must be balanced by the
  77. * same number of clk_disable() calls for the clock source to be
  78. * disabled.
  79. */
  80. void clk_disable(struct clk *clk);
  81. /**
  82. * clk_unprepare - undo preparation of a clock source
  83. * @clk: clock source
  84. *
  85. * This undoes a previously prepared clock. The caller must balance
  86. * the number of prepare and unprepare calls.
  87. *
  88. * Must not be called from within atomic context.
  89. */
  90. #ifdef CONFIG_HAVE_CLK_PREPARE
  91. void clk_unprepare(struct clk *clk);
  92. #else
  93. static inline void clk_unprepare(struct clk *clk)
  94. {
  95. might_sleep();
  96. }
  97. #endif
  98. /**
  99. * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  100. * This is only valid once the clock source has been enabled.
  101. * @clk: clock source
  102. */
  103. unsigned long clk_get_rate(struct clk *clk);
  104. /**
  105. * clk_put - "free" the clock source
  106. * @clk: clock source
  107. *
  108. * Note: drivers must ensure that all clk_enable calls made on this
  109. * clock source are balanced by clk_disable calls prior to calling
  110. * this function.
  111. *
  112. * clk_put should not be called from within interrupt context.
  113. */
  114. void clk_put(struct clk *clk);
  115. /*
  116. * The remaining APIs are optional for machine class support.
  117. */
  118. /**
  119. * clk_round_rate - adjust a rate to the exact rate a clock can provide
  120. * @clk: clock source
  121. * @rate: desired clock rate in Hz
  122. *
  123. * Returns rounded clock rate in Hz, or negative errno.
  124. */
  125. long clk_round_rate(struct clk *clk, unsigned long rate);
  126. /**
  127. * clk_set_rate - set the clock rate for a clock source
  128. * @clk: clock source
  129. * @rate: desired clock rate in Hz
  130. *
  131. * Returns success (0) or negative errno.
  132. */
  133. int clk_set_rate(struct clk *clk, unsigned long rate);
  134. /**
  135. * clk_set_parent - set the parent clock source for this clock
  136. * @clk: clock source
  137. * @parent: parent clock source
  138. *
  139. * Returns success (0) or negative errno.
  140. */
  141. int clk_set_parent(struct clk *clk, struct clk *parent);
  142. /**
  143. * clk_get_parent - get the parent clock source for this clock
  144. * @clk: clock source
  145. *
  146. * Returns struct clk corresponding to parent clock source, or
  147. * valid IS_ERR() condition containing errno.
  148. */
  149. struct clk *clk_get_parent(struct clk *clk);
  150. /**
  151. * clk_get_sys - get a clock based upon the device name
  152. * @dev_id: device name
  153. * @con_id: connection ID
  154. *
  155. * Returns a struct clk corresponding to the clock producer, or
  156. * valid IS_ERR() condition containing errno. The implementation
  157. * uses @dev_id and @con_id to determine the clock consumer, and
  158. * thereby the clock producer. In contrast to clk_get() this function
  159. * takes the device name instead of the device itself for identification.
  160. *
  161. * Drivers must assume that the clock source is not enabled.
  162. *
  163. * clk_get_sys should not be called from within interrupt context.
  164. */
  165. struct clk *clk_get_sys(const char *dev_id, const char *con_id);
  166. /**
  167. * clk_add_alias - add a new clock alias
  168. * @alias: name for clock alias
  169. * @alias_dev_name: device name
  170. * @id: platform specific clock name
  171. * @dev: device
  172. *
  173. * Allows using generic clock names for drivers by adding a new alias.
  174. * Assumes clkdev, see clkdev.h for more info.
  175. */
  176. int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
  177. struct device *dev);
  178. #endif