clk.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __TEGRA_CLK_H
  17. #define __TEGRA_CLK_H
  18. #include <linux/clk-provider.h>
  19. #include <linux/clkdev.h>
  20. /**
  21. * struct tegra_clk_sync_source - external clock source from codec
  22. *
  23. * @hw: handle between common and hardware-specific interfaces
  24. * @rate: input frequency from source
  25. * @max_rate: max rate allowed
  26. */
  27. struct tegra_clk_sync_source {
  28. struct clk_hw hw;
  29. unsigned long rate;
  30. unsigned long max_rate;
  31. };
  32. #define to_clk_sync_source(_hw) \
  33. container_of(_hw, struct tegra_clk_sync_source, hw)
  34. extern const struct clk_ops tegra_clk_sync_source_ops;
  35. struct clk *tegra_clk_register_sync_source(const char *name,
  36. unsigned long fixed_rate, unsigned long max_rate);
  37. /**
  38. * struct tegra_clk_frac_div - fractional divider clock
  39. *
  40. * @hw: handle between common and hardware-specific interfaces
  41. * @reg: register containing divider
  42. * @flags: hardware-specific flags
  43. * @shift: shift to the divider bit field
  44. * @width: width of the divider bit field
  45. * @frac_width: width of the fractional bit field
  46. * @lock: register lock
  47. *
  48. * Flags:
  49. * TEGRA_DIVIDER_ROUND_UP - This flags indicates to round up the divider value.
  50. * TEGRA_DIVIDER_FIXED - Fixed rate PLL dividers has addition override bit, this
  51. * flag indicates that this divider is for fixed rate PLL.
  52. * TEGRA_DIVIDER_INT - Some modules can not cope with the duty cycle when
  53. * fraction bit is set. This flags indicates to calculate divider for which
  54. * fracton bit will be zero.
  55. * TEGRA_DIVIDER_UART - UART module divider has additional enable bit which is
  56. * set when divider value is not 0. This flags indicates that the divider
  57. * is for UART module.
  58. */
  59. struct tegra_clk_frac_div {
  60. struct clk_hw hw;
  61. void __iomem *reg;
  62. u8 flags;
  63. u8 shift;
  64. u8 width;
  65. u8 frac_width;
  66. spinlock_t *lock;
  67. };
  68. #define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
  69. #define TEGRA_DIVIDER_ROUND_UP BIT(0)
  70. #define TEGRA_DIVIDER_FIXED BIT(1)
  71. #define TEGRA_DIVIDER_INT BIT(2)
  72. #define TEGRA_DIVIDER_UART BIT(3)
  73. extern const struct clk_ops tegra_clk_frac_div_ops;
  74. struct clk *tegra_clk_register_divider(const char *name,
  75. const char *parent_name, void __iomem *reg,
  76. unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width,
  77. u8 frac_width, spinlock_t *lock);
  78. /*
  79. * Tegra PLL:
  80. *
  81. * In general, there are 3 requirements for each PLL
  82. * that SW needs to be comply with.
  83. * (1) Input frequency range (REF).
  84. * (2) Comparison frequency range (CF). CF = REF/DIVM.
  85. * (3) VCO frequency range (VCO). VCO = CF * DIVN.
  86. *
  87. * The final PLL output frequency (FO) = VCO >> DIVP.
  88. */
  89. /**
  90. * struct tegra_clk_pll_freq_table - PLL frequecy table
  91. *
  92. * @input_rate: input rate from source
  93. * @output_rate: output rate from PLL for the input rate
  94. * @n: feedback divider
  95. * @m: input divider
  96. * @p: post divider
  97. * @cpcon: charge pump current
  98. */
  99. struct tegra_clk_pll_freq_table {
  100. unsigned long input_rate;
  101. unsigned long output_rate;
  102. u16 n;
  103. u16 m;
  104. u8 p;
  105. u8 cpcon;
  106. };
  107. /**
  108. * struct clk_pll_params - PLL parameters
  109. *
  110. * @input_min: Minimum input frequency
  111. * @input_max: Maximum input frequency
  112. * @cf_min: Minimum comparison frequency
  113. * @cf_max: Maximum comparison frequency
  114. * @vco_min: Minimum VCO frequency
  115. * @vco_max: Maximum VCO frequency
  116. * @base_reg: PLL base reg offset
  117. * @misc_reg: PLL misc reg offset
  118. * @lock_reg: PLL lock reg offset
  119. * @lock_bit_idx: Bit index for PLL lock status
  120. * @lock_enable_bit_idx: Bit index to enable PLL lock
  121. * @lock_delay: Delay in us if PLL lock is not used
  122. */
  123. struct tegra_clk_pll_params {
  124. unsigned long input_min;
  125. unsigned long input_max;
  126. unsigned long cf_min;
  127. unsigned long cf_max;
  128. unsigned long vco_min;
  129. unsigned long vco_max;
  130. u32 base_reg;
  131. u32 misc_reg;
  132. u32 lock_reg;
  133. u32 lock_bit_idx;
  134. u32 lock_enable_bit_idx;
  135. int lock_delay;
  136. };
  137. /**
  138. * struct tegra_clk_pll - Tegra PLL clock
  139. *
  140. * @hw: handle between common and hardware-specifix interfaces
  141. * @clk_base: address of CAR controller
  142. * @pmc: address of PMC, required to read override bits
  143. * @freq_table: array of frequencies supported by PLL
  144. * @params: PLL parameters
  145. * @flags: PLL flags
  146. * @fixed_rate: PLL rate if it is fixed
  147. * @lock: register lock
  148. * @divn_shift: shift to the feedback divider bit field
  149. * @divn_width: width of the feedback divider bit field
  150. * @divm_shift: shift to the input divider bit field
  151. * @divm_width: width of the input divider bit field
  152. * @divp_shift: shift to the post divider bit field
  153. * @divp_width: width of the post divider bit field
  154. *
  155. * Flags:
  156. * TEGRA_PLL_USE_LOCK - This flag indicated to use lock bits for
  157. * PLL locking. If not set it will use lock_delay value to wait.
  158. * TEGRA_PLL_HAS_CPCON - This flag indicates that CPCON value needs
  159. * to be programmed to change output frequency of the PLL.
  160. * TEGRA_PLL_SET_LFCON - This flag indicates that LFCON value needs
  161. * to be programmed to change output frequency of the PLL.
  162. * TEGRA_PLL_SET_DCCON - This flag indicates that DCCON value needs
  163. * to be programmed to change output frequency of the PLL.
  164. * TEGRA_PLLU - PLLU has inverted post divider. This flags indicated
  165. * that it is PLLU and invert post divider value.
  166. * TEGRA_PLLM - PLLM has additional override settings in PMC. This
  167. * flag indicates that it is PLLM and use override settings.
  168. * TEGRA_PLL_FIXED - We are not supposed to change output frequency
  169. * of some plls.
  170. * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling.
  171. */
  172. struct tegra_clk_pll {
  173. struct clk_hw hw;
  174. void __iomem *clk_base;
  175. void __iomem *pmc;
  176. u8 flags;
  177. unsigned long fixed_rate;
  178. spinlock_t *lock;
  179. u8 divn_shift;
  180. u8 divn_width;
  181. u8 divm_shift;
  182. u8 divm_width;
  183. u8 divp_shift;
  184. u8 divp_width;
  185. struct tegra_clk_pll_freq_table *freq_table;
  186. struct tegra_clk_pll_params *params;
  187. };
  188. #define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
  189. #define TEGRA_PLL_USE_LOCK BIT(0)
  190. #define TEGRA_PLL_HAS_CPCON BIT(1)
  191. #define TEGRA_PLL_SET_LFCON BIT(2)
  192. #define TEGRA_PLL_SET_DCCON BIT(3)
  193. #define TEGRA_PLLU BIT(4)
  194. #define TEGRA_PLLM BIT(5)
  195. #define TEGRA_PLL_FIXED BIT(6)
  196. #define TEGRA_PLLE_CONFIGURE BIT(7)
  197. extern const struct clk_ops tegra_clk_pll_ops;
  198. extern const struct clk_ops tegra_clk_plle_ops;
  199. struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
  200. void __iomem *clk_base, void __iomem *pmc,
  201. unsigned long flags, unsigned long fixed_rate,
  202. struct tegra_clk_pll_params *pll_params, u8 pll_flags,
  203. struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
  204. struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
  205. void __iomem *clk_base, void __iomem *pmc,
  206. unsigned long flags, unsigned long fixed_rate,
  207. struct tegra_clk_pll_params *pll_params, u8 pll_flags,
  208. struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
  209. /**
  210. * struct tegra_clk_pll_out - PLL divider down clock
  211. *
  212. * @hw: handle between common and hardware-specific interfaces
  213. * @reg: register containing the PLL divider
  214. * @enb_bit_idx: bit to enable/disable PLL divider
  215. * @rst_bit_idx: bit to reset PLL divider
  216. * @lock: register lock
  217. * @flags: hardware-specific flags
  218. */
  219. struct tegra_clk_pll_out {
  220. struct clk_hw hw;
  221. void __iomem *reg;
  222. u8 enb_bit_idx;
  223. u8 rst_bit_idx;
  224. spinlock_t *lock;
  225. u8 flags;
  226. };
  227. #define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
  228. extern const struct clk_ops tegra_clk_pll_out_ops;
  229. struct clk *tegra_clk_register_pll_out(const char *name,
  230. const char *parent_name, void __iomem *reg, u8 enb_bit_idx,
  231. u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags,
  232. spinlock_t *lock);
  233. /**
  234. * struct tegra_clk_periph_regs - Registers controlling peripheral clock
  235. *
  236. * @enb_reg: read the enable status
  237. * @enb_set_reg: write 1 to enable clock
  238. * @enb_clr_reg: write 1 to disable clock
  239. * @rst_reg: read the reset status
  240. * @rst_set_reg: write 1 to assert the reset of peripheral
  241. * @rst_clr_reg: write 1 to deassert the reset of peripheral
  242. */
  243. struct tegra_clk_periph_regs {
  244. u32 enb_reg;
  245. u32 enb_set_reg;
  246. u32 enb_clr_reg;
  247. u32 rst_reg;
  248. u32 rst_set_reg;
  249. u32 rst_clr_reg;
  250. };
  251. /**
  252. * struct tegra_clk_periph_gate - peripheral gate clock
  253. *
  254. * @magic: magic number to validate type
  255. * @hw: handle between common and hardware-specific interfaces
  256. * @clk_base: address of CAR controller
  257. * @regs: Registers to control the peripheral
  258. * @flags: hardware-specific flags
  259. * @clk_num: Clock number
  260. * @enable_refcnt: array to maintain reference count of the clock
  261. *
  262. * Flags:
  263. * TEGRA_PERIPH_NO_RESET - This flag indicates that reset is not allowed
  264. * for this module.
  265. * TEGRA_PERIPH_MANUAL_RESET - This flag indicates not to reset module
  266. * after clock enable and driver for the module is responsible for
  267. * doing reset.
  268. * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the
  269. * bus to flush the write operation in apb bus. This flag indicates
  270. * that this peripheral is in apb bus.
  271. */
  272. struct tegra_clk_periph_gate {
  273. u32 magic;
  274. struct clk_hw hw;
  275. void __iomem *clk_base;
  276. u8 flags;
  277. int clk_num;
  278. int *enable_refcnt;
  279. struct tegra_clk_periph_regs *regs;
  280. };
  281. #define to_clk_periph_gate(_hw) \
  282. container_of(_hw, struct tegra_clk_periph_gate, hw)
  283. #define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309
  284. #define TEGRA_PERIPH_NO_RESET BIT(0)
  285. #define TEGRA_PERIPH_MANUAL_RESET BIT(1)
  286. #define TEGRA_PERIPH_ON_APB BIT(2)
  287. void tegra_periph_reset(struct tegra_clk_periph_gate *gate, bool assert);
  288. extern const struct clk_ops tegra_clk_periph_gate_ops;
  289. struct clk *tegra_clk_register_periph_gate(const char *name,
  290. const char *parent_name, u8 gate_flags, void __iomem *clk_base,
  291. unsigned long flags, int clk_num,
  292. struct tegra_clk_periph_regs *pregs, int *enable_refcnt);
  293. /**
  294. * struct clk-periph - peripheral clock
  295. *
  296. * @magic: magic number to validate type
  297. * @hw: handle between common and hardware-specific interfaces
  298. * @mux: mux clock
  299. * @divider: divider clock
  300. * @gate: gate clock
  301. * @mux_ops: mux clock ops
  302. * @div_ops: divider clock ops
  303. * @gate_ops: gate clock ops
  304. */
  305. struct tegra_clk_periph {
  306. u32 magic;
  307. struct clk_hw hw;
  308. struct clk_mux mux;
  309. struct tegra_clk_frac_div divider;
  310. struct tegra_clk_periph_gate gate;
  311. const struct clk_ops *mux_ops;
  312. const struct clk_ops *div_ops;
  313. const struct clk_ops *gate_ops;
  314. };
  315. #define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
  316. #define TEGRA_CLK_PERIPH_MAGIC 0x18221223
  317. extern const struct clk_ops tegra_clk_periph_ops;
  318. struct clk *tegra_clk_register_periph(const char *name,
  319. const char **parent_names, int num_parents,
  320. struct tegra_clk_periph *periph, void __iomem *clk_base,
  321. u32 offset);
  322. struct clk *tegra_clk_register_periph_nodiv(const char *name,
  323. const char **parent_names, int num_parents,
  324. struct tegra_clk_periph *periph, void __iomem *clk_base,
  325. u32 offset);
  326. #define TEGRA_CLK_PERIPH(_mux_shift, _mux_width, _mux_flags, \
  327. _div_shift, _div_width, _div_frac_width, \
  328. _div_flags, _clk_num, _enb_refcnt, _regs, \
  329. _gate_flags) \
  330. { \
  331. .mux = { \
  332. .flags = _mux_flags, \
  333. .shift = _mux_shift, \
  334. .width = _mux_width, \
  335. }, \
  336. .divider = { \
  337. .flags = _div_flags, \
  338. .shift = _div_shift, \
  339. .width = _div_width, \
  340. .frac_width = _div_frac_width, \
  341. }, \
  342. .gate = { \
  343. .flags = _gate_flags, \
  344. .clk_num = _clk_num, \
  345. .enable_refcnt = _enb_refcnt, \
  346. .regs = _regs, \
  347. }, \
  348. .mux_ops = &clk_mux_ops, \
  349. .div_ops = &tegra_clk_frac_div_ops, \
  350. .gate_ops = &tegra_clk_periph_gate_ops, \
  351. }
  352. struct tegra_periph_init_data {
  353. const char *name;
  354. int clk_id;
  355. const char **parent_names;
  356. int num_parents;
  357. struct tegra_clk_periph periph;
  358. u32 offset;
  359. const char *con_id;
  360. const char *dev_id;
  361. };
  362. #define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset, \
  363. _mux_shift, _mux_width, _mux_flags, _div_shift, \
  364. _div_width, _div_frac_width, _div_flags, _regs, \
  365. _clk_num, _enb_refcnt, _gate_flags, _clk_id) \
  366. { \
  367. .name = _name, \
  368. .clk_id = _clk_id, \
  369. .parent_names = _parent_names, \
  370. .num_parents = ARRAY_SIZE(_parent_names), \
  371. .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_width, \
  372. _mux_flags, _div_shift, \
  373. _div_width, _div_frac_width, \
  374. _div_flags, _clk_num, \
  375. _enb_refcnt, _regs, \
  376. _gate_flags), \
  377. .offset = _offset, \
  378. .con_id = _con_id, \
  379. .dev_id = _dev_id, \
  380. }
  381. /**
  382. * struct clk_super_mux - super clock
  383. *
  384. * @hw: handle between common and hardware-specific interfaces
  385. * @reg: register controlling multiplexer
  386. * @width: width of the multiplexer bit field
  387. * @flags: hardware-specific flags
  388. * @div2_index: bit controlling divide-by-2
  389. * @pllx_index: PLLX index in the parent list
  390. * @lock: register lock
  391. *
  392. * Flags:
  393. * TEGRA_DIVIDER_2 - LP cluster has additional divider. This flag indicates
  394. * that this is LP cluster clock.
  395. */
  396. struct tegra_clk_super_mux {
  397. struct clk_hw hw;
  398. void __iomem *reg;
  399. u8 width;
  400. u8 flags;
  401. u8 div2_index;
  402. u8 pllx_index;
  403. spinlock_t *lock;
  404. };
  405. #define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw)
  406. #define TEGRA_DIVIDER_2 BIT(0)
  407. extern const struct clk_ops tegra_clk_super_ops;
  408. struct clk *tegra_clk_register_super_mux(const char *name,
  409. const char **parent_names, u8 num_parents,
  410. unsigned long flags, void __iomem *reg, u8 clk_super_flags,
  411. u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock);
  412. /**
  413. * struct clk_init_tabel - clock initialization table
  414. * @clk_id: clock id as mentioned in device tree bindings
  415. * @parent_id: parent clock id as mentioned in device tree bindings
  416. * @rate: rate to set
  417. * @state: enable/disable
  418. */
  419. struct tegra_clk_init_table {
  420. unsigned int clk_id;
  421. unsigned int parent_id;
  422. unsigned long rate;
  423. int state;
  424. };
  425. /**
  426. * struct clk_duplicate - duplicate clocks
  427. * @clk_id: clock id as mentioned in device tree bindings
  428. * @lookup: duplicate lookup entry for the clock
  429. */
  430. struct tegra_clk_duplicate {
  431. int clk_id;
  432. struct clk_lookup lookup;
  433. };
  434. #define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \
  435. { \
  436. .clk_id = _clk_id, \
  437. .lookup = { \
  438. .dev_id = _dev, \
  439. .con_id = _con, \
  440. }, \
  441. }
  442. void tegra_init_from_table(struct tegra_clk_init_table *tbl,
  443. struct clk *clks[], int clk_max);
  444. void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
  445. struct clk *clks[], int clk_max);
  446. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  447. void tegra20_clock_init(struct device_node *np);
  448. #else
  449. static inline void tegra20_clock_init(struct device_node *np) {}
  450. #endif /* CONFIG_ARCH_TEGRA_2x_SOC */
  451. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  452. void tegra30_clock_init(struct device_node *np);
  453. #else
  454. static inline void tegra30_clock_init(struct device_node *np) {}
  455. #endif /* CONFIG_ARCH_TEGRA_3x_SOC */
  456. #endif /* TEGRA_CLK_H */