clock.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * arch/arm/mach-tegra/include/mach/clock.h
  3. *
  4. * Copyright (C) 2010 Google, Inc.
  5. * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved.
  6. *
  7. * Author:
  8. * Colin Cross <ccross@google.com>
  9. *
  10. * This software is licensed under the terms of the GNU General Public
  11. * License version 2, as published by the Free Software Foundation, and
  12. * may be copied, distributed, and modified under those terms.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #ifndef __MACH_TEGRA_CLOCK_H
  21. #define __MACH_TEGRA_CLOCK_H
  22. #include <linux/clk-provider.h>
  23. #include <linux/clkdev.h>
  24. #include <linux/list.h>
  25. #include <linux/spinlock.h>
  26. #include <mach/clk.h>
  27. #define DIV_BUS (1 << 0)
  28. #define DIV_U71 (1 << 1)
  29. #define DIV_U71_FIXED (1 << 2)
  30. #define DIV_2 (1 << 3)
  31. #define DIV_U16 (1 << 4)
  32. #define PLL_FIXED (1 << 5)
  33. #define PLL_HAS_CPCON (1 << 6)
  34. #define MUX (1 << 7)
  35. #define PLLD (1 << 8)
  36. #define PERIPH_NO_RESET (1 << 9)
  37. #define PERIPH_NO_ENB (1 << 10)
  38. #define PERIPH_EMC_ENB (1 << 11)
  39. #define PERIPH_MANUAL_RESET (1 << 12)
  40. #define PLL_ALT_MISC_REG (1 << 13)
  41. #define PLLU (1 << 14)
  42. #define PLLX (1 << 15)
  43. #define MUX_PWM (1 << 16)
  44. #define MUX8 (1 << 17)
  45. #define DIV_U71_UART (1 << 18)
  46. #define MUX_CLK_OUT (1 << 19)
  47. #define PLLM (1 << 20)
  48. #define DIV_U71_INT (1 << 21)
  49. #define DIV_U71_IDLE (1 << 22)
  50. #define ENABLE_ON_INIT (1 << 28)
  51. #define PERIPH_ON_APB (1 << 29)
  52. struct clk;
  53. #ifdef CONFIG_COMMON_CLK
  54. struct clk_tegra;
  55. #define to_clk_tegra(_hw) container_of(_hw, struct clk_tegra, hw)
  56. #endif
  57. struct clk_mux_sel {
  58. struct clk *input;
  59. u32 value;
  60. };
  61. struct clk_pll_freq_table {
  62. unsigned long input_rate;
  63. unsigned long output_rate;
  64. u16 n;
  65. u16 m;
  66. u8 p;
  67. u8 cpcon;
  68. };
  69. enum clk_state {
  70. UNINITIALIZED = 0,
  71. ON,
  72. OFF,
  73. };
  74. #ifndef CONFIG_COMMON_CLK
  75. struct clk_ops {
  76. void (*init)(struct clk *);
  77. int (*enable)(struct clk *);
  78. void (*disable)(struct clk *);
  79. int (*set_parent)(struct clk *, struct clk *);
  80. int (*set_rate)(struct clk *, unsigned long);
  81. long (*round_rate)(struct clk *, unsigned long);
  82. void (*reset)(struct clk *, bool);
  83. int (*clk_cfg_ex)(struct clk *,
  84. enum tegra_clk_ex_param, u32);
  85. };
  86. struct clk {
  87. /* node for master clocks list */
  88. struct list_head node; /* node for list of all clocks */
  89. struct clk_lookup lookup;
  90. #ifdef CONFIG_DEBUG_FS
  91. struct dentry *dent;
  92. #endif
  93. bool set;
  94. struct clk_ops *ops;
  95. unsigned long rate;
  96. unsigned long max_rate;
  97. unsigned long min_rate;
  98. u32 flags;
  99. const char *name;
  100. u32 refcnt;
  101. enum clk_state state;
  102. struct clk *parent;
  103. u32 div;
  104. u32 mul;
  105. const struct clk_mux_sel *inputs;
  106. u32 reg;
  107. u32 reg_shift;
  108. struct list_head shared_bus_list;
  109. union {
  110. struct {
  111. unsigned int clk_num;
  112. } periph;
  113. struct {
  114. unsigned long input_min;
  115. unsigned long input_max;
  116. unsigned long cf_min;
  117. unsigned long cf_max;
  118. unsigned long vco_min;
  119. unsigned long vco_max;
  120. const struct clk_pll_freq_table *freq_table;
  121. int lock_delay;
  122. unsigned long fixed_rate;
  123. } pll;
  124. struct {
  125. u32 sel;
  126. u32 reg_mask;
  127. } mux;
  128. struct {
  129. struct clk *main;
  130. struct clk *backup;
  131. } cpu;
  132. struct {
  133. struct list_head node;
  134. bool enabled;
  135. unsigned long rate;
  136. } shared_bus_user;
  137. } u;
  138. spinlock_t spinlock;
  139. };
  140. #else
  141. struct clk_tegra {
  142. /* node for master clocks list */
  143. struct list_head node; /* node for list of all clocks */
  144. struct clk_lookup lookup;
  145. struct clk_hw hw;
  146. bool set;
  147. unsigned long fixed_rate;
  148. unsigned long max_rate;
  149. unsigned long min_rate;
  150. u32 flags;
  151. const char *name;
  152. enum clk_state state;
  153. u32 div;
  154. u32 mul;
  155. u32 reg;
  156. u32 reg_shift;
  157. struct list_head shared_bus_list;
  158. union {
  159. struct {
  160. unsigned int clk_num;
  161. } periph;
  162. struct {
  163. unsigned long input_min;
  164. unsigned long input_max;
  165. unsigned long cf_min;
  166. unsigned long cf_max;
  167. unsigned long vco_min;
  168. unsigned long vco_max;
  169. const struct clk_pll_freq_table *freq_table;
  170. int lock_delay;
  171. unsigned long fixed_rate;
  172. } pll;
  173. struct {
  174. u32 sel;
  175. u32 reg_mask;
  176. } mux;
  177. struct {
  178. struct clk *main;
  179. struct clk *backup;
  180. } cpu;
  181. struct {
  182. struct list_head node;
  183. bool enabled;
  184. unsigned long rate;
  185. } shared_bus_user;
  186. } u;
  187. void (*reset)(struct clk_hw *, bool);
  188. int (*clk_cfg_ex)(struct clk_hw *, enum tegra_clk_ex_param, u32);
  189. };
  190. #endif /* !CONFIG_COMMON_CLK */
  191. struct clk_duplicate {
  192. const char *name;
  193. struct clk_lookup lookup;
  194. };
  195. struct tegra_clk_init_table {
  196. const char *name;
  197. const char *parent;
  198. unsigned long rate;
  199. bool enabled;
  200. };
  201. #ifndef CONFIG_COMMON_CLK
  202. void clk_init(struct clk *clk);
  203. unsigned long clk_get_rate_locked(struct clk *c);
  204. int clk_set_rate_locked(struct clk *c, unsigned long rate);
  205. int clk_reparent(struct clk *c, struct clk *parent);
  206. #endif /* !CONFIG_COMMON_CLK */
  207. void tegra2_init_clocks(void);
  208. void tegra30_init_clocks(void);
  209. struct clk *tegra_get_clock_by_name(const char *name);
  210. void tegra_clk_init_from_table(struct tegra_clk_init_table *table);
  211. #endif