tegra.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2020, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #ifndef __LINUX_CLK_TEGRA_H_
  6. #define __LINUX_CLK_TEGRA_H_
  7. #include <linux/types.h>
  8. #include <linux/bug.h>
  9. /*
  10. * Tegra CPU clock and reset control ops
  11. *
  12. * wait_for_reset:
  13. * keep waiting until the CPU in reset state
  14. * put_in_reset:
  15. * put the CPU in reset state
  16. * out_of_reset:
  17. * release the CPU from reset state
  18. * enable_clock:
  19. * CPU clock un-gate
  20. * disable_clock:
  21. * CPU clock gate
  22. * rail_off_ready:
  23. * CPU is ready for rail off
  24. * suspend:
  25. * save the clock settings when CPU go into low-power state
  26. * resume:
  27. * restore the clock settings when CPU exit low-power state
  28. */
  29. struct tegra_cpu_car_ops {
  30. void (*wait_for_reset)(u32 cpu);
  31. void (*put_in_reset)(u32 cpu);
  32. void (*out_of_reset)(u32 cpu);
  33. void (*enable_clock)(u32 cpu);
  34. void (*disable_clock)(u32 cpu);
  35. #ifdef CONFIG_PM_SLEEP
  36. bool (*rail_off_ready)(void);
  37. void (*suspend)(void);
  38. void (*resume)(void);
  39. #endif
  40. };
  41. #ifdef CONFIG_ARCH_TEGRA
  42. extern struct tegra_cpu_car_ops *tegra_cpu_car_ops;
  43. static inline void tegra_wait_cpu_in_reset(u32 cpu)
  44. {
  45. if (WARN_ON(!tegra_cpu_car_ops->wait_for_reset))
  46. return;
  47. tegra_cpu_car_ops->wait_for_reset(cpu);
  48. }
  49. static inline void tegra_put_cpu_in_reset(u32 cpu)
  50. {
  51. if (WARN_ON(!tegra_cpu_car_ops->put_in_reset))
  52. return;
  53. tegra_cpu_car_ops->put_in_reset(cpu);
  54. }
  55. static inline void tegra_cpu_out_of_reset(u32 cpu)
  56. {
  57. if (WARN_ON(!tegra_cpu_car_ops->out_of_reset))
  58. return;
  59. tegra_cpu_car_ops->out_of_reset(cpu);
  60. }
  61. static inline void tegra_enable_cpu_clock(u32 cpu)
  62. {
  63. if (WARN_ON(!tegra_cpu_car_ops->enable_clock))
  64. return;
  65. tegra_cpu_car_ops->enable_clock(cpu);
  66. }
  67. static inline void tegra_disable_cpu_clock(u32 cpu)
  68. {
  69. if (WARN_ON(!tegra_cpu_car_ops->disable_clock))
  70. return;
  71. tegra_cpu_car_ops->disable_clock(cpu);
  72. }
  73. #else
  74. static inline void tegra_wait_cpu_in_reset(u32 cpu)
  75. {
  76. }
  77. static inline void tegra_put_cpu_in_reset(u32 cpu)
  78. {
  79. }
  80. static inline void tegra_cpu_out_of_reset(u32 cpu)
  81. {
  82. }
  83. static inline void tegra_enable_cpu_clock(u32 cpu)
  84. {
  85. }
  86. static inline void tegra_disable_cpu_clock(u32 cpu)
  87. {
  88. }
  89. #endif
  90. #if defined(CONFIG_ARCH_TEGRA) && defined(CONFIG_PM_SLEEP)
  91. static inline bool tegra_cpu_rail_off_ready(void)
  92. {
  93. if (WARN_ON(!tegra_cpu_car_ops->rail_off_ready))
  94. return false;
  95. return tegra_cpu_car_ops->rail_off_ready();
  96. }
  97. static inline void tegra_cpu_clock_suspend(void)
  98. {
  99. if (WARN_ON(!tegra_cpu_car_ops->suspend))
  100. return;
  101. tegra_cpu_car_ops->suspend();
  102. }
  103. static inline void tegra_cpu_clock_resume(void)
  104. {
  105. if (WARN_ON(!tegra_cpu_car_ops->resume))
  106. return;
  107. tegra_cpu_car_ops->resume();
  108. }
  109. #else
  110. static inline bool tegra_cpu_rail_off_ready(void)
  111. {
  112. return false;
  113. }
  114. static inline void tegra_cpu_clock_suspend(void)
  115. {
  116. }
  117. static inline void tegra_cpu_clock_resume(void)
  118. {
  119. }
  120. #endif
  121. struct clk;
  122. struct tegra_emc;
  123. typedef long (tegra20_clk_emc_round_cb)(unsigned long rate,
  124. unsigned long min_rate,
  125. unsigned long max_rate,
  126. void *arg);
  127. typedef int (tegra124_emc_prepare_timing_change_cb)(struct tegra_emc *emc,
  128. unsigned long rate);
  129. typedef void (tegra124_emc_complete_timing_change_cb)(struct tegra_emc *emc,
  130. unsigned long rate);
  131. struct tegra210_clk_emc_config {
  132. unsigned long rate;
  133. bool same_freq;
  134. u32 value;
  135. unsigned long parent_rate;
  136. u8 parent;
  137. };
  138. struct tegra210_clk_emc_provider {
  139. struct module *owner;
  140. struct device *dev;
  141. struct tegra210_clk_emc_config *configs;
  142. unsigned int num_configs;
  143. int (*set_rate)(struct device *dev,
  144. const struct tegra210_clk_emc_config *config);
  145. };
  146. #if defined(CONFIG_ARCH_TEGRA_2x_SOC) || defined(CONFIG_ARCH_TEGRA_3x_SOC)
  147. void tegra20_clk_set_emc_round_callback(tegra20_clk_emc_round_cb *round_cb,
  148. void *cb_arg);
  149. int tegra20_clk_prepare_emc_mc_same_freq(struct clk *emc_clk, bool same);
  150. #else
  151. static inline void
  152. tegra20_clk_set_emc_round_callback(tegra20_clk_emc_round_cb *round_cb,
  153. void *cb_arg)
  154. {
  155. }
  156. static inline int
  157. tegra20_clk_prepare_emc_mc_same_freq(struct clk *emc_clk, bool same)
  158. {
  159. return 0;
  160. }
  161. #endif
  162. #ifdef CONFIG_TEGRA124_CLK_EMC
  163. void tegra124_clk_set_emc_callbacks(tegra124_emc_prepare_timing_change_cb *prep_cb,
  164. tegra124_emc_complete_timing_change_cb *complete_cb);
  165. #else
  166. static inline void
  167. tegra124_clk_set_emc_callbacks(tegra124_emc_prepare_timing_change_cb *prep_cb,
  168. tegra124_emc_complete_timing_change_cb *complete_cb)
  169. {
  170. }
  171. #endif
  172. #ifdef CONFIG_ARCH_TEGRA_210_SOC
  173. int tegra210_plle_hw_sequence_start(void);
  174. bool tegra210_plle_hw_sequence_is_enabled(void);
  175. void tegra210_xusb_pll_hw_control_enable(void);
  176. void tegra210_xusb_pll_hw_sequence_start(void);
  177. void tegra210_sata_pll_hw_control_enable(void);
  178. void tegra210_sata_pll_hw_sequence_start(void);
  179. void tegra210_set_sata_pll_seq_sw(bool state);
  180. void tegra210_put_utmipll_in_iddq(void);
  181. void tegra210_put_utmipll_out_iddq(void);
  182. int tegra210_clk_handle_mbist_war(unsigned int id);
  183. void tegra210_clk_emc_dll_enable(bool flag);
  184. void tegra210_clk_emc_dll_update_setting(u32 emc_dll_src_value);
  185. void tegra210_clk_emc_update_setting(u32 emc_src_value);
  186. int tegra210_clk_emc_attach(struct clk *clk,
  187. struct tegra210_clk_emc_provider *provider);
  188. void tegra210_clk_emc_detach(struct clk *clk);
  189. #else
  190. static inline int tegra210_plle_hw_sequence_start(void)
  191. {
  192. return 0;
  193. }
  194. static inline bool tegra210_plle_hw_sequence_is_enabled(void)
  195. {
  196. return false;
  197. }
  198. static inline int tegra210_clk_handle_mbist_war(unsigned int id)
  199. {
  200. return 0;
  201. }
  202. static inline int
  203. tegra210_clk_emc_attach(struct clk *clk,
  204. struct tegra210_clk_emc_provider *provider)
  205. {
  206. return 0;
  207. }
  208. static inline void tegra210_xusb_pll_hw_control_enable(void) {}
  209. static inline void tegra210_xusb_pll_hw_sequence_start(void) {}
  210. static inline void tegra210_sata_pll_hw_control_enable(void) {}
  211. static inline void tegra210_sata_pll_hw_sequence_start(void) {}
  212. static inline void tegra210_set_sata_pll_seq_sw(bool state) {}
  213. static inline void tegra210_put_utmipll_in_iddq(void) {}
  214. static inline void tegra210_put_utmipll_out_iddq(void) {}
  215. static inline void tegra210_clk_emc_dll_enable(bool flag) {}
  216. static inline void tegra210_clk_emc_dll_update_setting(u32 emc_dll_src_value) {}
  217. static inline void tegra210_clk_emc_update_setting(u32 emc_src_value) {}
  218. static inline void tegra210_clk_emc_detach(struct clk *clk) {}
  219. #endif
  220. #endif /* __LINUX_CLK_TEGRA_H_ */