clk-uclass.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. * Copyright (c) 2016, NVIDIA CORPORATION.
  6. */
  7. #ifndef _CLK_UCLASS_H
  8. #define _CLK_UCLASS_H
  9. /* See clk.h for background documentation. */
  10. #include <clk.h>
  11. struct ofnode_phandle_args;
  12. /**
  13. * struct clk_ops - The functions that a clock driver must implement.
  14. * @of_xlate: Translate a client's device-tree (OF) clock specifier.
  15. * @request: Request a translated clock.
  16. * @rfree: Free a previously requested clock.
  17. * @round_rate: Adjust a rate to the exact rate a clock can provide.
  18. * @get_rate: Get current clock rate.
  19. * @set_rate: Set current clock rate.
  20. * @set_parent: Set current clock parent
  21. * @enable: Enable a clock.
  22. * @disable: Disable a clock.
  23. *
  24. * The individual methods are described more fully below.
  25. */
  26. struct clk_ops {
  27. int (*of_xlate)(struct clk *clock,
  28. struct ofnode_phandle_args *args);
  29. int (*request)(struct clk *clock);
  30. void (*rfree)(struct clk *clock);
  31. ulong (*round_rate)(struct clk *clk, ulong rate);
  32. ulong (*get_rate)(struct clk *clk);
  33. ulong (*set_rate)(struct clk *clk, ulong rate);
  34. int (*set_parent)(struct clk *clk, struct clk *parent);
  35. int (*enable)(struct clk *clk);
  36. int (*disable)(struct clk *clk);
  37. };
  38. #if 0 /* For documentation only */
  39. /**
  40. * of_xlate() - Translate a client's device-tree (OF) clock specifier.
  41. * @clock: The clock struct to hold the translation result.
  42. * @args: The clock specifier values from device tree.
  43. *
  44. * The clock core calls this function as the first step in implementing
  45. * a client's clk_get_by_*() call.
  46. *
  47. * If this function pointer is set to NULL, the clock core will use a
  48. * default implementation, which assumes #clock-cells = <1>, and that
  49. * the DT cell contains a simple integer clock ID.
  50. *
  51. * At present, the clock API solely supports device-tree. If this
  52. * changes, other xxx_xlate() functions may be added to support those
  53. * other mechanisms.
  54. *
  55. * Return: 0 if OK, or a negative error code.
  56. */
  57. int of_xlate(struct clk *clock, struct ofnode_phandle_args *args);
  58. /**
  59. * request() - Request a translated clock.
  60. * @clock: The clock struct to request; this has been filled in by
  61. * a previoux xxx_xlate() function call, or by the caller
  62. * of clk_request().
  63. *
  64. * The clock core calls this function as the second step in
  65. * implementing a client's clk_get_by_*() call, following a successful
  66. * xxx_xlate() call, or as the only step in implementing a client's
  67. * clk_request() call.
  68. *
  69. * Return: 0 if OK, or a negative error code.
  70. */
  71. int request(struct clk *clock);
  72. /**
  73. * rfree() - Free a previously requested clock.
  74. * @clock: The clock to free.
  75. *
  76. * Free any resources allocated in request().
  77. */
  78. void rfree(struct clk *clock);
  79. /**
  80. * round_rate() - Adjust a rate to the exact rate a clock can provide.
  81. * @clk: The clock to manipulate.
  82. * @rate: Desidered clock rate in Hz.
  83. *
  84. * Return: rounded rate in Hz, or -ve error code.
  85. */
  86. ulong round_rate(struct clk *clk, ulong rate);
  87. /**
  88. * get_rate() - Get current clock rate.
  89. * @clk: The clock to query.
  90. *
  91. * Return: clock rate in Hz, or -ve error code
  92. */
  93. ulong get_rate(struct clk *clk);
  94. /**
  95. * set_rate() - Set current clock rate.
  96. * @clk: The clock to manipulate.
  97. * @rate: New clock rate in Hz.
  98. *
  99. * Return: new rate, or -ve error code.
  100. */
  101. ulong set_rate(struct clk *clk, ulong rate);
  102. /**
  103. * set_parent() - Set current clock parent
  104. * @clk: The clock to manipulate.
  105. * @parent: New clock parent.
  106. *
  107. * Return: zero on success, or -ve error code.
  108. */
  109. int set_parent(struct clk *clk, struct clk *parent);
  110. /**
  111. * enable() - Enable a clock.
  112. * @clk: The clock to manipulate.
  113. *
  114. * Return: zero on success, or -ve error code.
  115. */
  116. int enable(struct clk *clk);
  117. /**
  118. * disable() - Disable a clock.
  119. * @clk: The clock to manipulate.
  120. *
  121. * Return: zero on success, or -ve error code.
  122. */
  123. int disable(struct clk *clk);
  124. #endif
  125. #endif