clk.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. extern int *periph_clk_enb_refcnt;
  36. struct clk *tegra_clk_register_sync_source(const char *name,
  37. unsigned long fixed_rate, unsigned long max_rate);
  38. /**
  39. * struct tegra_clk_frac_div - fractional divider clock
  40. *
  41. * @hw: handle between common and hardware-specific interfaces
  42. * @reg: register containing divider
  43. * @flags: hardware-specific flags
  44. * @shift: shift to the divider bit field
  45. * @width: width of the divider bit field
  46. * @frac_width: width of the fractional bit field
  47. * @lock: register lock
  48. *
  49. * Flags:
  50. * TEGRA_DIVIDER_ROUND_UP - This flags indicates to round up the divider value.
  51. * TEGRA_DIVIDER_FIXED - Fixed rate PLL dividers has addition override bit, this
  52. * flag indicates that this divider is for fixed rate PLL.
  53. * TEGRA_DIVIDER_INT - Some modules can not cope with the duty cycle when
  54. * fraction bit is set. This flags indicates to calculate divider for which
  55. * fracton bit will be zero.
  56. * TEGRA_DIVIDER_UART - UART module divider has additional enable bit which is
  57. * set when divider value is not 0. This flags indicates that the divider
  58. * is for UART module.
  59. */
  60. struct tegra_clk_frac_div {
  61. struct clk_hw hw;
  62. void __iomem *reg;
  63. u8 flags;
  64. u8 shift;
  65. u8 width;
  66. u8 frac_width;
  67. spinlock_t *lock;
  68. };
  69. #define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
  70. #define TEGRA_DIVIDER_ROUND_UP BIT(0)
  71. #define TEGRA_DIVIDER_FIXED BIT(1)
  72. #define TEGRA_DIVIDER_INT BIT(2)
  73. #define TEGRA_DIVIDER_UART BIT(3)
  74. extern const struct clk_ops tegra_clk_frac_div_ops;
  75. struct clk *tegra_clk_register_divider(const char *name,
  76. const char *parent_name, void __iomem *reg,
  77. unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width,
  78. u8 frac_width, spinlock_t *lock);
  79. struct clk *tegra_clk_register_mc(const char *name, const char *parent_name,
  80. void __iomem *reg, spinlock_t *lock);
  81. /*
  82. * Tegra PLL:
  83. *
  84. * In general, there are 3 requirements for each PLL
  85. * that SW needs to be comply with.
  86. * (1) Input frequency range (REF).
  87. * (2) Comparison frequency range (CF). CF = REF/DIVM.
  88. * (3) VCO frequency range (VCO). VCO = CF * DIVN.
  89. *
  90. * The final PLL output frequency (FO) = VCO >> DIVP.
  91. */
  92. /**
  93. * struct tegra_clk_pll_freq_table - PLL frequecy table
  94. *
  95. * @input_rate: input rate from source
  96. * @output_rate: output rate from PLL for the input rate
  97. * @n: feedback divider
  98. * @m: input divider
  99. * @p: post divider
  100. * @cpcon: charge pump current
  101. * @sdm_data: fraction divider setting (0 = disabled)
  102. */
  103. struct tegra_clk_pll_freq_table {
  104. unsigned long input_rate;
  105. unsigned long output_rate;
  106. u32 n;
  107. u16 m;
  108. u8 p;
  109. u8 cpcon;
  110. u16 sdm_data;
  111. };
  112. /**
  113. * struct pdiv_map - map post divider to hw value
  114. *
  115. * @pdiv: post divider
  116. * @hw_val: value to be written to the PLL hw
  117. */
  118. struct pdiv_map {
  119. u8 pdiv;
  120. u8 hw_val;
  121. };
  122. /**
  123. * struct div_nmp - offset and width of m,n and p fields
  124. *
  125. * @divn_shift: shift to the feedback divider bit field
  126. * @divn_width: width of the feedback divider bit field
  127. * @divm_shift: shift to the input divider bit field
  128. * @divm_width: width of the input divider bit field
  129. * @divp_shift: shift to the post divider bit field
  130. * @divp_width: width of the post divider bit field
  131. * @override_divn_shift: shift to the feedback divider bitfield in override reg
  132. * @override_divm_shift: shift to the input divider bitfield in override reg
  133. * @override_divp_shift: shift to the post divider bitfield in override reg
  134. */
  135. struct div_nmp {
  136. u8 divn_shift;
  137. u8 divn_width;
  138. u8 divm_shift;
  139. u8 divm_width;
  140. u8 divp_shift;
  141. u8 divp_width;
  142. u8 override_divn_shift;
  143. u8 override_divm_shift;
  144. u8 override_divp_shift;
  145. };
  146. #define MAX_PLL_MISC_REG_COUNT 6
  147. struct tegra_clk_pll;
  148. /**
  149. * struct tegra_clk_pll_params - PLL parameters
  150. *
  151. * @input_min: Minimum input frequency
  152. * @input_max: Maximum input frequency
  153. * @cf_min: Minimum comparison frequency
  154. * @cf_max: Maximum comparison frequency
  155. * @vco_min: Minimum VCO frequency
  156. * @vco_max: Maximum VCO frequency
  157. * @base_reg: PLL base reg offset
  158. * @misc_reg: PLL misc reg offset
  159. * @lock_reg: PLL lock reg offset
  160. * @lock_mask: Bitmask for PLL lock status
  161. * @lock_enable_bit_idx: Bit index to enable PLL lock
  162. * @iddq_reg: PLL IDDQ register offset
  163. * @iddq_bit_idx: Bit index to enable PLL IDDQ
  164. * @reset_reg: Register offset of where RESET bit is
  165. * @reset_bit_idx: Shift of reset bit in reset_reg
  166. * @sdm_din_reg: Register offset where SDM settings are
  167. * @sdm_din_mask: Mask of SDM divider bits
  168. * @sdm_ctrl_reg: Register offset where SDM enable is
  169. * @sdm_ctrl_en_mask: Mask of SDM enable bit
  170. * @ssc_ctrl_reg: Register offset where SSC settings are
  171. * @ssc_ctrl_en_mask: Mask of SSC enable bit
  172. * @aux_reg: AUX register offset
  173. * @dyn_ramp_reg: Dynamic ramp control register offset
  174. * @ext_misc_reg: Miscellaneous control register offsets
  175. * @pmc_divnm_reg: n, m divider PMC override register offset (PLLM)
  176. * @pmc_divp_reg: p divider PMC override register offset (PLLM)
  177. * @flags: PLL flags
  178. * @stepa_shift: Dynamic ramp step A field shift
  179. * @stepb_shift: Dynamic ramp step B field shift
  180. * @lock_delay: Delay in us if PLL lock is not used
  181. * @max_p: maximum value for the p divider
  182. * @defaults_set: Boolean signaling all reg defaults for PLL set.
  183. * @pdiv_tohw: mapping of p divider to register values
  184. * @div_nmp: offsets and widths on n, m and p fields
  185. * @freq_table: array of frequencies supported by PLL
  186. * @fixed_rate: PLL rate if it is fixed
  187. * @mdiv_default: Default value for fixed mdiv for this PLL
  188. * @round_p_to_pdiv: Callback used to round p to the closed pdiv
  189. * @set_gain: Callback to adjust N div for SDM enabled
  190. * PLL's based on fractional divider value.
  191. * @calc_rate: Callback used to change how out of table
  192. * rates (dividers and multipler) are calculated.
  193. * @adjust_vco: Callback to adjust the programming range of the
  194. * divider range (if SDM is present)
  195. * @set_defaults: Callback which will try to initialize PLL
  196. * registers to sane default values. This is first
  197. * tried during PLL registration, but if the PLL
  198. * is already enabled, it will be done the first
  199. * time the rate is changed while the PLL is
  200. * disabled.
  201. * @dyn_ramp: Callback which can be used to define a custom
  202. * dynamic ramp function for a given PLL.
  203. *
  204. * Flags:
  205. * TEGRA_PLL_USE_LOCK - This flag indicated to use lock bits for
  206. * PLL locking. If not set it will use lock_delay value to wait.
  207. * TEGRA_PLL_HAS_CPCON - This flag indicates that CPCON value needs
  208. * to be programmed to change output frequency of the PLL.
  209. * TEGRA_PLL_SET_LFCON - This flag indicates that LFCON value needs
  210. * to be programmed to change output frequency of the PLL.
  211. * TEGRA_PLL_SET_DCCON - This flag indicates that DCCON value needs
  212. * to be programmed to change output frequency of the PLL.
  213. * TEGRA_PLLU - PLLU has inverted post divider. This flags indicated
  214. * that it is PLLU and invert post divider value.
  215. * TEGRA_PLLM - PLLM has additional override settings in PMC. This
  216. * flag indicates that it is PLLM and use override settings.
  217. * TEGRA_PLL_FIXED - We are not supposed to change output frequency
  218. * of some plls.
  219. * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling.
  220. * TEGRA_PLL_LOCK_MISC - Lock bit is in the misc register instead of the
  221. * base register.
  222. * TEGRA_PLL_BYPASS - PLL has bypass bit
  223. * TEGRA_PLL_HAS_LOCK_ENABLE - PLL has bit to enable lock monitoring
  224. * TEGRA_MDIV_NEW - Switch to new method for calculating fixed mdiv
  225. * it may be more accurate (especially if SDM present)
  226. * TEGRA_PLLMB - PLLMB has should be treated similar to PLLM. This
  227. * flag indicated that it is PLLMB.
  228. * TEGRA_PLL_VCO_OUT - Used to indicate that the PLL has a VCO output
  229. */
  230. struct tegra_clk_pll_params {
  231. unsigned long input_min;
  232. unsigned long input_max;
  233. unsigned long cf_min;
  234. unsigned long cf_max;
  235. unsigned long vco_min;
  236. unsigned long vco_max;
  237. u32 base_reg;
  238. u32 misc_reg;
  239. u32 lock_reg;
  240. u32 lock_mask;
  241. u32 lock_enable_bit_idx;
  242. u32 iddq_reg;
  243. u32 iddq_bit_idx;
  244. u32 reset_reg;
  245. u32 reset_bit_idx;
  246. u32 sdm_din_reg;
  247. u32 sdm_din_mask;
  248. u32 sdm_ctrl_reg;
  249. u32 sdm_ctrl_en_mask;
  250. u32 ssc_ctrl_reg;
  251. u32 ssc_ctrl_en_mask;
  252. u32 aux_reg;
  253. u32 dyn_ramp_reg;
  254. u32 ext_misc_reg[MAX_PLL_MISC_REG_COUNT];
  255. u32 pmc_divnm_reg;
  256. u32 pmc_divp_reg;
  257. u32 flags;
  258. int stepa_shift;
  259. int stepb_shift;
  260. int lock_delay;
  261. int max_p;
  262. bool defaults_set;
  263. const struct pdiv_map *pdiv_tohw;
  264. struct div_nmp *div_nmp;
  265. struct tegra_clk_pll_freq_table *freq_table;
  266. unsigned long fixed_rate;
  267. u16 mdiv_default;
  268. u32 (*round_p_to_pdiv)(u32 p, u32 *pdiv);
  269. void (*set_gain)(struct tegra_clk_pll_freq_table *cfg);
  270. int (*calc_rate)(struct clk_hw *hw,
  271. struct tegra_clk_pll_freq_table *cfg,
  272. unsigned long rate, unsigned long parent_rate);
  273. unsigned long (*adjust_vco)(struct tegra_clk_pll_params *pll_params,
  274. unsigned long parent_rate);
  275. void (*set_defaults)(struct tegra_clk_pll *pll);
  276. int (*dyn_ramp)(struct tegra_clk_pll *pll,
  277. struct tegra_clk_pll_freq_table *cfg);
  278. };
  279. #define TEGRA_PLL_USE_LOCK BIT(0)
  280. #define TEGRA_PLL_HAS_CPCON BIT(1)
  281. #define TEGRA_PLL_SET_LFCON BIT(2)
  282. #define TEGRA_PLL_SET_DCCON BIT(3)
  283. #define TEGRA_PLLU BIT(4)
  284. #define TEGRA_PLLM BIT(5)
  285. #define TEGRA_PLL_FIXED BIT(6)
  286. #define TEGRA_PLLE_CONFIGURE BIT(7)
  287. #define TEGRA_PLL_LOCK_MISC BIT(8)
  288. #define TEGRA_PLL_BYPASS BIT(9)
  289. #define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10)
  290. #define TEGRA_MDIV_NEW BIT(11)
  291. #define TEGRA_PLLMB BIT(12)
  292. #define TEGRA_PLL_VCO_OUT BIT(13)
  293. /**
  294. * struct tegra_clk_pll - Tegra PLL clock
  295. *
  296. * @hw: handle between common and hardware-specifix interfaces
  297. * @clk_base: address of CAR controller
  298. * @pmc: address of PMC, required to read override bits
  299. * @lock: register lock
  300. * @params: PLL parameters
  301. */
  302. struct tegra_clk_pll {
  303. struct clk_hw hw;
  304. void __iomem *clk_base;
  305. void __iomem *pmc;
  306. spinlock_t *lock;
  307. struct tegra_clk_pll_params *params;
  308. };
  309. #define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
  310. /**
  311. * struct tegra_audio_clk_info - Tegra Audio Clk Information
  312. *
  313. * @name: name for the audio pll
  314. * @pll_params: pll_params for audio pll
  315. * @clk_id: clk_ids for the audio pll
  316. * @parent: name of the parent of the audio pll
  317. */
  318. struct tegra_audio_clk_info {
  319. char *name;
  320. struct tegra_clk_pll_params *pll_params;
  321. int clk_id;
  322. char *parent;
  323. };
  324. extern const struct clk_ops tegra_clk_pll_ops;
  325. extern const struct clk_ops tegra_clk_plle_ops;
  326. struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
  327. void __iomem *clk_base, void __iomem *pmc,
  328. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  329. spinlock_t *lock);
  330. struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
  331. void __iomem *clk_base, void __iomem *pmc,
  332. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  333. spinlock_t *lock);
  334. struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
  335. void __iomem *clk_base, void __iomem *pmc,
  336. unsigned long flags,
  337. struct tegra_clk_pll_params *pll_params,
  338. spinlock_t *lock);
  339. struct clk *tegra_clk_register_pllxc_tegra210(const char *name,
  340. const char *parent_name, void __iomem *clk_base,
  341. void __iomem *pmc, unsigned long flags,
  342. struct tegra_clk_pll_params *pll_params,
  343. spinlock_t *lock);
  344. struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
  345. void __iomem *clk_base, void __iomem *pmc,
  346. unsigned long flags,
  347. struct tegra_clk_pll_params *pll_params,
  348. spinlock_t *lock);
  349. struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
  350. void __iomem *clk_base, void __iomem *pmc,
  351. unsigned long flags,
  352. struct tegra_clk_pll_params *pll_params,
  353. spinlock_t *lock);
  354. struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
  355. void __iomem *clk_base, void __iomem *pmc,
  356. unsigned long flags,
  357. struct tegra_clk_pll_params *pll_params,
  358. spinlock_t *lock, unsigned long parent_rate);
  359. struct clk *tegra_clk_register_pllre_tegra210(const char *name,
  360. const char *parent_name, void __iomem *clk_base,
  361. void __iomem *pmc, unsigned long flags,
  362. struct tegra_clk_pll_params *pll_params,
  363. spinlock_t *lock, unsigned long parent_rate);
  364. struct clk *tegra_clk_register_plle_tegra114(const char *name,
  365. const char *parent_name,
  366. void __iomem *clk_base, unsigned long flags,
  367. struct tegra_clk_pll_params *pll_params,
  368. spinlock_t *lock);
  369. struct clk *tegra_clk_register_plle_tegra210(const char *name,
  370. const char *parent_name,
  371. void __iomem *clk_base, unsigned long flags,
  372. struct tegra_clk_pll_params *pll_params,
  373. spinlock_t *lock);
  374. struct clk *tegra_clk_register_pllc_tegra210(const char *name,
  375. const char *parent_name, void __iomem *clk_base,
  376. void __iomem *pmc, unsigned long flags,
  377. struct tegra_clk_pll_params *pll_params,
  378. spinlock_t *lock);
  379. struct clk *tegra_clk_register_pllss_tegra210(const char *name,
  380. const char *parent_name, void __iomem *clk_base,
  381. unsigned long flags,
  382. struct tegra_clk_pll_params *pll_params,
  383. spinlock_t *lock);
  384. struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name,
  385. void __iomem *clk_base, unsigned long flags,
  386. struct tegra_clk_pll_params *pll_params,
  387. spinlock_t *lock);
  388. struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name,
  389. void __iomem *clk_base, void __iomem *pmc,
  390. unsigned long flags,
  391. struct tegra_clk_pll_params *pll_params,
  392. spinlock_t *lock);
  393. struct clk *tegra_clk_register_pllu(const char *name, const char *parent_name,
  394. void __iomem *clk_base, unsigned long flags,
  395. struct tegra_clk_pll_params *pll_params,
  396. spinlock_t *lock);
  397. struct clk *tegra_clk_register_pllu_tegra114(const char *name,
  398. const char *parent_name,
  399. void __iomem *clk_base, unsigned long flags,
  400. struct tegra_clk_pll_params *pll_params,
  401. spinlock_t *lock);
  402. struct clk *tegra_clk_register_pllu_tegra210(const char *name,
  403. const char *parent_name,
  404. void __iomem *clk_base, unsigned long flags,
  405. struct tegra_clk_pll_params *pll_params,
  406. spinlock_t *lock);
  407. /**
  408. * struct tegra_clk_pll_out - PLL divider down clock
  409. *
  410. * @hw: handle between common and hardware-specific interfaces
  411. * @reg: register containing the PLL divider
  412. * @enb_bit_idx: bit to enable/disable PLL divider
  413. * @rst_bit_idx: bit to reset PLL divider
  414. * @lock: register lock
  415. * @flags: hardware-specific flags
  416. */
  417. struct tegra_clk_pll_out {
  418. struct clk_hw hw;
  419. void __iomem *reg;
  420. u8 enb_bit_idx;
  421. u8 rst_bit_idx;
  422. spinlock_t *lock;
  423. u8 flags;
  424. };
  425. #define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
  426. extern const struct clk_ops tegra_clk_pll_out_ops;
  427. struct clk *tegra_clk_register_pll_out(const char *name,
  428. const char *parent_name, void __iomem *reg, u8 enb_bit_idx,
  429. u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags,
  430. spinlock_t *lock);
  431. /**
  432. * struct tegra_clk_periph_regs - Registers controlling peripheral clock
  433. *
  434. * @enb_reg: read the enable status
  435. * @enb_set_reg: write 1 to enable clock
  436. * @enb_clr_reg: write 1 to disable clock
  437. * @rst_reg: read the reset status
  438. * @rst_set_reg: write 1 to assert the reset of peripheral
  439. * @rst_clr_reg: write 1 to deassert the reset of peripheral
  440. */
  441. struct tegra_clk_periph_regs {
  442. u32 enb_reg;
  443. u32 enb_set_reg;
  444. u32 enb_clr_reg;
  445. u32 rst_reg;
  446. u32 rst_set_reg;
  447. u32 rst_clr_reg;
  448. };
  449. /**
  450. * struct tegra_clk_periph_gate - peripheral gate clock
  451. *
  452. * @magic: magic number to validate type
  453. * @hw: handle between common and hardware-specific interfaces
  454. * @clk_base: address of CAR controller
  455. * @regs: Registers to control the peripheral
  456. * @flags: hardware-specific flags
  457. * @clk_num: Clock number
  458. * @enable_refcnt: array to maintain reference count of the clock
  459. *
  460. * Flags:
  461. * TEGRA_PERIPH_NO_RESET - This flag indicates that reset is not allowed
  462. * for this module.
  463. * TEGRA_PERIPH_MANUAL_RESET - This flag indicates not to reset module
  464. * after clock enable and driver for the module is responsible for
  465. * doing reset.
  466. * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the
  467. * bus to flush the write operation in apb bus. This flag indicates
  468. * that this peripheral is in apb bus.
  469. * TEGRA_PERIPH_WAR_1005168 - Apply workaround for Tegra114 MSENC bug
  470. */
  471. struct tegra_clk_periph_gate {
  472. u32 magic;
  473. struct clk_hw hw;
  474. void __iomem *clk_base;
  475. u8 flags;
  476. int clk_num;
  477. int *enable_refcnt;
  478. const struct tegra_clk_periph_regs *regs;
  479. };
  480. #define to_clk_periph_gate(_hw) \
  481. container_of(_hw, struct tegra_clk_periph_gate, hw)
  482. #define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309
  483. #define TEGRA_PERIPH_NO_RESET BIT(0)
  484. #define TEGRA_PERIPH_MANUAL_RESET BIT(1)
  485. #define TEGRA_PERIPH_ON_APB BIT(2)
  486. #define TEGRA_PERIPH_WAR_1005168 BIT(3)
  487. #define TEGRA_PERIPH_NO_DIV BIT(4)
  488. #define TEGRA_PERIPH_NO_GATE BIT(5)
  489. extern const struct clk_ops tegra_clk_periph_gate_ops;
  490. struct clk *tegra_clk_register_periph_gate(const char *name,
  491. const char *parent_name, u8 gate_flags, void __iomem *clk_base,
  492. unsigned long flags, int clk_num, int *enable_refcnt);
  493. struct tegra_clk_periph_fixed {
  494. struct clk_hw hw;
  495. void __iomem *base;
  496. const struct tegra_clk_periph_regs *regs;
  497. unsigned int mul;
  498. unsigned int div;
  499. unsigned int num;
  500. };
  501. struct clk *tegra_clk_register_periph_fixed(const char *name,
  502. const char *parent,
  503. unsigned long flags,
  504. void __iomem *base,
  505. unsigned int mul,
  506. unsigned int div,
  507. unsigned int num);
  508. /**
  509. * struct clk-periph - peripheral clock
  510. *
  511. * @magic: magic number to validate type
  512. * @hw: handle between common and hardware-specific interfaces
  513. * @mux: mux clock
  514. * @divider: divider clock
  515. * @gate: gate clock
  516. * @mux_ops: mux clock ops
  517. * @div_ops: divider clock ops
  518. * @gate_ops: gate clock ops
  519. */
  520. struct tegra_clk_periph {
  521. u32 magic;
  522. struct clk_hw hw;
  523. struct clk_mux mux;
  524. struct tegra_clk_frac_div divider;
  525. struct tegra_clk_periph_gate gate;
  526. const struct clk_ops *mux_ops;
  527. const struct clk_ops *div_ops;
  528. const struct clk_ops *gate_ops;
  529. };
  530. #define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
  531. #define TEGRA_CLK_PERIPH_MAGIC 0x18221223
  532. extern const struct clk_ops tegra_clk_periph_ops;
  533. struct clk *tegra_clk_register_periph(const char *name,
  534. const char **parent_names, int num_parents,
  535. struct tegra_clk_periph *periph, void __iomem *clk_base,
  536. u32 offset, unsigned long flags);
  537. struct clk *tegra_clk_register_periph_nodiv(const char *name,
  538. const char **parent_names, int num_parents,
  539. struct tegra_clk_periph *periph, void __iomem *clk_base,
  540. u32 offset);
  541. #define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags, \
  542. _div_shift, _div_width, _div_frac_width, \
  543. _div_flags, _clk_num,\
  544. _gate_flags, _table, _lock) \
  545. { \
  546. .mux = { \
  547. .flags = _mux_flags, \
  548. .shift = _mux_shift, \
  549. .mask = _mux_mask, \
  550. .table = _table, \
  551. .lock = _lock, \
  552. }, \
  553. .divider = { \
  554. .flags = _div_flags, \
  555. .shift = _div_shift, \
  556. .width = _div_width, \
  557. .frac_width = _div_frac_width, \
  558. .lock = _lock, \
  559. }, \
  560. .gate = { \
  561. .flags = _gate_flags, \
  562. .clk_num = _clk_num, \
  563. }, \
  564. .mux_ops = &clk_mux_ops, \
  565. .div_ops = &tegra_clk_frac_div_ops, \
  566. .gate_ops = &tegra_clk_periph_gate_ops, \
  567. }
  568. struct tegra_periph_init_data {
  569. const char *name;
  570. int clk_id;
  571. union {
  572. const char **parent_names;
  573. const char *parent_name;
  574. } p;
  575. int num_parents;
  576. struct tegra_clk_periph periph;
  577. u32 offset;
  578. const char *con_id;
  579. const char *dev_id;
  580. unsigned long flags;
  581. };
  582. #define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
  583. _mux_shift, _mux_mask, _mux_flags, _div_shift, \
  584. _div_width, _div_frac_width, _div_flags, \
  585. _clk_num, _gate_flags, _clk_id, _table, \
  586. _flags, _lock) \
  587. { \
  588. .name = _name, \
  589. .clk_id = _clk_id, \
  590. .p.parent_names = _parent_names, \
  591. .num_parents = ARRAY_SIZE(_parent_names), \
  592. .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, \
  593. _mux_flags, _div_shift, \
  594. _div_width, _div_frac_width, \
  595. _div_flags, _clk_num, \
  596. _gate_flags, _table, _lock), \
  597. .offset = _offset, \
  598. .con_id = _con_id, \
  599. .dev_id = _dev_id, \
  600. .flags = _flags \
  601. }
  602. #define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\
  603. _mux_shift, _mux_width, _mux_flags, _div_shift, \
  604. _div_width, _div_frac_width, _div_flags, \
  605. _clk_num, _gate_flags, _clk_id) \
  606. TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
  607. _mux_shift, BIT(_mux_width) - 1, _mux_flags, \
  608. _div_shift, _div_width, _div_frac_width, _div_flags, \
  609. _clk_num, _gate_flags, _clk_id,\
  610. NULL, 0, NULL)
  611. /**
  612. * struct clk_super_mux - super clock
  613. *
  614. * @hw: handle between common and hardware-specific interfaces
  615. * @reg: register controlling multiplexer
  616. * @width: width of the multiplexer bit field
  617. * @flags: hardware-specific flags
  618. * @div2_index: bit controlling divide-by-2
  619. * @pllx_index: PLLX index in the parent list
  620. * @lock: register lock
  621. *
  622. * Flags:
  623. * TEGRA_DIVIDER_2 - LP cluster has additional divider. This flag indicates
  624. * that this is LP cluster clock.
  625. */
  626. struct tegra_clk_super_mux {
  627. struct clk_hw hw;
  628. void __iomem *reg;
  629. u8 width;
  630. u8 flags;
  631. u8 div2_index;
  632. u8 pllx_index;
  633. spinlock_t *lock;
  634. };
  635. #define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw)
  636. #define TEGRA_DIVIDER_2 BIT(0)
  637. extern const struct clk_ops tegra_clk_super_ops;
  638. struct clk *tegra_clk_register_super_mux(const char *name,
  639. const char **parent_names, u8 num_parents,
  640. unsigned long flags, void __iomem *reg, u8 clk_super_flags,
  641. u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock);
  642. /**
  643. * struct clk_init_table - clock initialization table
  644. * @clk_id: clock id as mentioned in device tree bindings
  645. * @parent_id: parent clock id as mentioned in device tree bindings
  646. * @rate: rate to set
  647. * @state: enable/disable
  648. */
  649. struct tegra_clk_init_table {
  650. unsigned int clk_id;
  651. unsigned int parent_id;
  652. unsigned long rate;
  653. int state;
  654. };
  655. /**
  656. * struct clk_duplicate - duplicate clocks
  657. * @clk_id: clock id as mentioned in device tree bindings
  658. * @lookup: duplicate lookup entry for the clock
  659. */
  660. struct tegra_clk_duplicate {
  661. int clk_id;
  662. struct clk_lookup lookup;
  663. };
  664. #define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \
  665. { \
  666. .clk_id = _clk_id, \
  667. .lookup = { \
  668. .dev_id = _dev, \
  669. .con_id = _con, \
  670. }, \
  671. }
  672. struct tegra_clk {
  673. int dt_id;
  674. bool present;
  675. };
  676. struct tegra_devclk {
  677. int dt_id;
  678. char *dev_id;
  679. char *con_id;
  680. };
  681. void tegra_init_special_resets(unsigned int num, int (*assert)(unsigned long),
  682. int (*deassert)(unsigned long));
  683. void tegra_init_from_table(struct tegra_clk_init_table *tbl,
  684. struct clk *clks[], int clk_max);
  685. void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
  686. struct clk *clks[], int clk_max);
  687. const struct tegra_clk_periph_regs *get_reg_bank(int clkid);
  688. struct clk **tegra_clk_init(void __iomem *clk_base, int num, int periph_banks);
  689. struct clk **tegra_lookup_dt_id(int clk_id, struct tegra_clk *tegra_clk);
  690. void tegra_add_of_provider(struct device_node *np);
  691. void tegra_register_devclks(struct tegra_devclk *dev_clks, int num);
  692. void tegra_audio_clk_init(void __iomem *clk_base,
  693. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  694. struct tegra_audio_clk_info *audio_info,
  695. unsigned int num_plls);
  696. void tegra_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base,
  697. struct tegra_clk *tegra_clks,
  698. struct tegra_clk_pll_params *pll_params);
  699. void tegra_pmc_clk_init(void __iomem *pmc_base, struct tegra_clk *tegra_clks);
  700. void tegra_fixed_clk_init(struct tegra_clk *tegra_clks);
  701. int tegra_osc_clk_init(void __iomem *clk_base, struct tegra_clk *clks,
  702. unsigned long *input_freqs, unsigned int num,
  703. unsigned int clk_m_div, unsigned long *osc_freq,
  704. unsigned long *pll_ref_freq);
  705. void tegra_super_clk_gen4_init(void __iomem *clk_base,
  706. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  707. struct tegra_clk_pll_params *pll_params);
  708. void tegra_super_clk_gen5_init(void __iomem *clk_base,
  709. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  710. struct tegra_clk_pll_params *pll_params);
  711. #ifdef CONFIG_TEGRA_CLK_EMC
  712. struct clk *tegra_clk_register_emc(void __iomem *base, struct device_node *np,
  713. spinlock_t *lock);
  714. #else
  715. static inline struct clk *tegra_clk_register_emc(void __iomem *base,
  716. struct device_node *np,
  717. spinlock_t *lock)
  718. {
  719. return NULL;
  720. }
  721. #endif
  722. void tegra114_clock_tune_cpu_trimmers_high(void);
  723. void tegra114_clock_tune_cpu_trimmers_low(void);
  724. void tegra114_clock_tune_cpu_trimmers_init(void);
  725. void tegra114_clock_assert_dfll_dvco_reset(void);
  726. void tegra114_clock_deassert_dfll_dvco_reset(void);
  727. typedef void (*tegra_clk_apply_init_table_func)(void);
  728. extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
  729. int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll);
  730. u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate);
  731. int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div);
  732. #endif /* TEGRA_CLK_H */