clk.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #ifndef __TEGRA_CLK_H
  6. #define __TEGRA_CLK_H
  7. #include <linux/clk-provider.h>
  8. #include <linux/clkdev.h>
  9. #include <linux/delay.h>
  10. #define CLK_OUT_ENB_L 0x010
  11. #define CLK_OUT_ENB_H 0x014
  12. #define CLK_OUT_ENB_U 0x018
  13. #define CLK_OUT_ENB_V 0x360
  14. #define CLK_OUT_ENB_W 0x364
  15. #define CLK_OUT_ENB_X 0x280
  16. #define CLK_OUT_ENB_Y 0x298
  17. #define CLK_ENB_PLLP_OUT_CPU BIT(31)
  18. #define CLK_OUT_ENB_SET_L 0x320
  19. #define CLK_OUT_ENB_CLR_L 0x324
  20. #define CLK_OUT_ENB_SET_H 0x328
  21. #define CLK_OUT_ENB_CLR_H 0x32c
  22. #define CLK_OUT_ENB_SET_U 0x330
  23. #define CLK_OUT_ENB_CLR_U 0x334
  24. #define CLK_OUT_ENB_SET_V 0x440
  25. #define CLK_OUT_ENB_CLR_V 0x444
  26. #define CLK_OUT_ENB_SET_W 0x448
  27. #define CLK_OUT_ENB_CLR_W 0x44c
  28. #define CLK_OUT_ENB_SET_X 0x284
  29. #define CLK_OUT_ENB_CLR_X 0x288
  30. #define CLK_OUT_ENB_SET_Y 0x29c
  31. #define CLK_OUT_ENB_CLR_Y 0x2a0
  32. #define RST_DEVICES_L 0x004
  33. #define RST_DEVICES_H 0x008
  34. #define RST_DEVICES_U 0x00C
  35. #define RST_DEVICES_V 0x358
  36. #define RST_DEVICES_W 0x35C
  37. #define RST_DEVICES_X 0x28C
  38. #define RST_DEVICES_Y 0x2a4
  39. #define RST_DEVICES_SET_L 0x300
  40. #define RST_DEVICES_CLR_L 0x304
  41. #define RST_DEVICES_SET_H 0x308
  42. #define RST_DEVICES_CLR_H 0x30c
  43. #define RST_DEVICES_SET_U 0x310
  44. #define RST_DEVICES_CLR_U 0x314
  45. #define RST_DEVICES_SET_V 0x430
  46. #define RST_DEVICES_CLR_V 0x434
  47. #define RST_DEVICES_SET_W 0x438
  48. #define RST_DEVICES_CLR_W 0x43c
  49. #define RST_DEVICES_SET_X 0x290
  50. #define RST_DEVICES_CLR_X 0x294
  51. #define RST_DEVICES_SET_Y 0x2a8
  52. #define RST_DEVICES_CLR_Y 0x2ac
  53. /*
  54. * Tegra CLK_OUT_ENB registers have some undefined bits which are not used and
  55. * any accidental write of 1 to these bits can cause PSLVERR.
  56. * So below are the valid mask defines for each CLK_OUT_ENB register used to
  57. * turn ON only the valid clocks.
  58. */
  59. #define TEGRA210_CLK_ENB_VLD_MSK_L 0xdcd7dff9
  60. #define TEGRA210_CLK_ENB_VLD_MSK_H 0x87d1f3e7
  61. #define TEGRA210_CLK_ENB_VLD_MSK_U 0xf3fed3fa
  62. #define TEGRA210_CLK_ENB_VLD_MSK_V 0xffc18cfb
  63. #define TEGRA210_CLK_ENB_VLD_MSK_W 0x793fb7ff
  64. #define TEGRA210_CLK_ENB_VLD_MSK_X 0x3fe66fff
  65. #define TEGRA210_CLK_ENB_VLD_MSK_Y 0xfc1fc7ff
  66. /**
  67. * struct tegra_clk_sync_source - external clock source from codec
  68. *
  69. * @hw: handle between common and hardware-specific interfaces
  70. * @rate: input frequency from source
  71. * @max_rate: max rate allowed
  72. */
  73. struct tegra_clk_sync_source {
  74. struct clk_hw hw;
  75. unsigned long rate;
  76. unsigned long max_rate;
  77. };
  78. #define to_clk_sync_source(_hw) \
  79. container_of(_hw, struct tegra_clk_sync_source, hw)
  80. extern const struct clk_ops tegra_clk_sync_source_ops;
  81. extern int *periph_clk_enb_refcnt;
  82. struct clk *tegra_clk_register_sync_source(const char *name,
  83. unsigned long max_rate);
  84. /**
  85. * struct tegra_clk_frac_div - fractional divider clock
  86. *
  87. * @hw: handle between common and hardware-specific interfaces
  88. * @reg: register containing divider
  89. * @flags: hardware-specific flags
  90. * @shift: shift to the divider bit field
  91. * @width: width of the divider bit field
  92. * @frac_width: width of the fractional bit field
  93. * @lock: register lock
  94. *
  95. * Flags:
  96. * TEGRA_DIVIDER_ROUND_UP - This flags indicates to round up the divider value.
  97. * TEGRA_DIVIDER_FIXED - Fixed rate PLL dividers has addition override bit, this
  98. * flag indicates that this divider is for fixed rate PLL.
  99. * TEGRA_DIVIDER_INT - Some modules can not cope with the duty cycle when
  100. * fraction bit is set. This flags indicates to calculate divider for which
  101. * fracton bit will be zero.
  102. * TEGRA_DIVIDER_UART - UART module divider has additional enable bit which is
  103. * set when divider value is not 0. This flags indicates that the divider
  104. * is for UART module.
  105. */
  106. struct tegra_clk_frac_div {
  107. struct clk_hw hw;
  108. void __iomem *reg;
  109. u8 flags;
  110. u8 shift;
  111. u8 width;
  112. u8 frac_width;
  113. spinlock_t *lock;
  114. };
  115. #define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
  116. #define TEGRA_DIVIDER_ROUND_UP BIT(0)
  117. #define TEGRA_DIVIDER_FIXED BIT(1)
  118. #define TEGRA_DIVIDER_INT BIT(2)
  119. #define TEGRA_DIVIDER_UART BIT(3)
  120. extern const struct clk_ops tegra_clk_frac_div_ops;
  121. struct clk *tegra_clk_register_divider(const char *name,
  122. const char *parent_name, void __iomem *reg,
  123. unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width,
  124. u8 frac_width, spinlock_t *lock);
  125. struct clk *tegra_clk_register_mc(const char *name, const char *parent_name,
  126. void __iomem *reg, spinlock_t *lock);
  127. /*
  128. * Tegra PLL:
  129. *
  130. * In general, there are 3 requirements for each PLL
  131. * that SW needs to be comply with.
  132. * (1) Input frequency range (REF).
  133. * (2) Comparison frequency range (CF). CF = REF/DIVM.
  134. * (3) VCO frequency range (VCO). VCO = CF * DIVN.
  135. *
  136. * The final PLL output frequency (FO) = VCO >> DIVP.
  137. */
  138. /**
  139. * struct tegra_clk_pll_freq_table - PLL frequecy table
  140. *
  141. * @input_rate: input rate from source
  142. * @output_rate: output rate from PLL for the input rate
  143. * @n: feedback divider
  144. * @m: input divider
  145. * @p: post divider
  146. * @cpcon: charge pump current
  147. * @sdm_data: fraction divider setting (0 = disabled)
  148. */
  149. struct tegra_clk_pll_freq_table {
  150. unsigned long input_rate;
  151. unsigned long output_rate;
  152. u32 n;
  153. u32 m;
  154. u8 p;
  155. u8 cpcon;
  156. u16 sdm_data;
  157. };
  158. /**
  159. * struct pdiv_map - map post divider to hw value
  160. *
  161. * @pdiv: post divider
  162. * @hw_val: value to be written to the PLL hw
  163. */
  164. struct pdiv_map {
  165. u8 pdiv;
  166. u8 hw_val;
  167. };
  168. /**
  169. * struct div_nmp - offset and width of m,n and p fields
  170. *
  171. * @divn_shift: shift to the feedback divider bit field
  172. * @divn_width: width of the feedback divider bit field
  173. * @divm_shift: shift to the input divider bit field
  174. * @divm_width: width of the input divider bit field
  175. * @divp_shift: shift to the post divider bit field
  176. * @divp_width: width of the post divider bit field
  177. * @override_divn_shift: shift to the feedback divider bitfield in override reg
  178. * @override_divm_shift: shift to the input divider bitfield in override reg
  179. * @override_divp_shift: shift to the post divider bitfield in override reg
  180. */
  181. struct div_nmp {
  182. u8 divn_shift;
  183. u8 divn_width;
  184. u8 divm_shift;
  185. u8 divm_width;
  186. u8 divp_shift;
  187. u8 divp_width;
  188. u8 override_divn_shift;
  189. u8 override_divm_shift;
  190. u8 override_divp_shift;
  191. };
  192. #define MAX_PLL_MISC_REG_COUNT 6
  193. struct tegra_clk_pll;
  194. /**
  195. * struct tegra_clk_pll_params - PLL parameters
  196. *
  197. * @input_min: Minimum input frequency
  198. * @input_max: Maximum input frequency
  199. * @cf_min: Minimum comparison frequency
  200. * @cf_max: Maximum comparison frequency
  201. * @vco_min: Minimum VCO frequency
  202. * @vco_max: Maximum VCO frequency
  203. * @base_reg: PLL base reg offset
  204. * @misc_reg: PLL misc reg offset
  205. * @lock_reg: PLL lock reg offset
  206. * @lock_mask: Bitmask for PLL lock status
  207. * @lock_enable_bit_idx: Bit index to enable PLL lock
  208. * @iddq_reg: PLL IDDQ register offset
  209. * @iddq_bit_idx: Bit index to enable PLL IDDQ
  210. * @reset_reg: Register offset of where RESET bit is
  211. * @reset_bit_idx: Shift of reset bit in reset_reg
  212. * @sdm_din_reg: Register offset where SDM settings are
  213. * @sdm_din_mask: Mask of SDM divider bits
  214. * @sdm_ctrl_reg: Register offset where SDM enable is
  215. * @sdm_ctrl_en_mask: Mask of SDM enable bit
  216. * @ssc_ctrl_reg: Register offset where SSC settings are
  217. * @ssc_ctrl_en_mask: Mask of SSC enable bit
  218. * @aux_reg: AUX register offset
  219. * @dyn_ramp_reg: Dynamic ramp control register offset
  220. * @ext_misc_reg: Miscellaneous control register offsets
  221. * @pmc_divnm_reg: n, m divider PMC override register offset (PLLM)
  222. * @pmc_divp_reg: p divider PMC override register offset (PLLM)
  223. * @flags: PLL flags
  224. * @stepa_shift: Dynamic ramp step A field shift
  225. * @stepb_shift: Dynamic ramp step B field shift
  226. * @lock_delay: Delay in us if PLL lock is not used
  227. * @max_p: maximum value for the p divider
  228. * @defaults_set: Boolean signaling all reg defaults for PLL set.
  229. * @pdiv_tohw: mapping of p divider to register values
  230. * @div_nmp: offsets and widths on n, m and p fields
  231. * @freq_table: array of frequencies supported by PLL
  232. * @fixed_rate: PLL rate if it is fixed
  233. * @mdiv_default: Default value for fixed mdiv for this PLL
  234. * @round_p_to_pdiv: Callback used to round p to the closed pdiv
  235. * @set_gain: Callback to adjust N div for SDM enabled
  236. * PLL's based on fractional divider value.
  237. * @calc_rate: Callback used to change how out of table
  238. * rates (dividers and multipler) are calculated.
  239. * @adjust_vco: Callback to adjust the programming range of the
  240. * divider range (if SDM is present)
  241. * @set_defaults: Callback which will try to initialize PLL
  242. * registers to sane default values. This is first
  243. * tried during PLL registration, but if the PLL
  244. * is already enabled, it will be done the first
  245. * time the rate is changed while the PLL is
  246. * disabled.
  247. * @dyn_ramp: Callback which can be used to define a custom
  248. * dynamic ramp function for a given PLL.
  249. * @pre_rate_change: Callback which is invoked just before changing
  250. * PLL's rate.
  251. * @post_rate_change: Callback which is invoked right after changing
  252. * PLL's rate.
  253. *
  254. * Flags:
  255. * TEGRA_PLL_USE_LOCK - This flag indicated to use lock bits for
  256. * PLL locking. If not set it will use lock_delay value to wait.
  257. * TEGRA_PLL_HAS_CPCON - This flag indicates that CPCON value needs
  258. * to be programmed to change output frequency of the PLL.
  259. * TEGRA_PLL_SET_LFCON - This flag indicates that LFCON value needs
  260. * to be programmed to change output frequency of the PLL.
  261. * TEGRA_PLL_SET_DCCON - This flag indicates that DCCON value needs
  262. * to be programmed to change output frequency of the PLL.
  263. * TEGRA_PLLU - PLLU has inverted post divider. This flags indicated
  264. * that it is PLLU and invert post divider value.
  265. * TEGRA_PLLM - PLLM has additional override settings in PMC. This
  266. * flag indicates that it is PLLM and use override settings.
  267. * TEGRA_PLL_FIXED - We are not supposed to change output frequency
  268. * of some plls.
  269. * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling.
  270. * TEGRA_PLL_LOCK_MISC - Lock bit is in the misc register instead of the
  271. * base register.
  272. * TEGRA_PLL_BYPASS - PLL has bypass bit
  273. * TEGRA_PLL_HAS_LOCK_ENABLE - PLL has bit to enable lock monitoring
  274. * TEGRA_MDIV_NEW - Switch to new method for calculating fixed mdiv
  275. * it may be more accurate (especially if SDM present)
  276. * TEGRA_PLLMB - PLLMB has should be treated similar to PLLM. This
  277. * flag indicated that it is PLLMB.
  278. * TEGRA_PLL_VCO_OUT - Used to indicate that the PLL has a VCO output
  279. */
  280. struct tegra_clk_pll_params {
  281. unsigned long input_min;
  282. unsigned long input_max;
  283. unsigned long cf_min;
  284. unsigned long cf_max;
  285. unsigned long vco_min;
  286. unsigned long vco_max;
  287. u32 base_reg;
  288. u32 misc_reg;
  289. u32 lock_reg;
  290. u32 lock_mask;
  291. u32 lock_enable_bit_idx;
  292. u32 iddq_reg;
  293. u32 iddq_bit_idx;
  294. u32 reset_reg;
  295. u32 reset_bit_idx;
  296. u32 sdm_din_reg;
  297. u32 sdm_din_mask;
  298. u32 sdm_ctrl_reg;
  299. u32 sdm_ctrl_en_mask;
  300. u32 ssc_ctrl_reg;
  301. u32 ssc_ctrl_en_mask;
  302. u32 aux_reg;
  303. u32 dyn_ramp_reg;
  304. u32 ext_misc_reg[MAX_PLL_MISC_REG_COUNT];
  305. u32 pmc_divnm_reg;
  306. u32 pmc_divp_reg;
  307. u32 flags;
  308. int stepa_shift;
  309. int stepb_shift;
  310. int lock_delay;
  311. int max_p;
  312. bool defaults_set;
  313. const struct pdiv_map *pdiv_tohw;
  314. struct div_nmp *div_nmp;
  315. struct tegra_clk_pll_freq_table *freq_table;
  316. unsigned long fixed_rate;
  317. u16 mdiv_default;
  318. u32 (*round_p_to_pdiv)(u32 p, u32 *pdiv);
  319. void (*set_gain)(struct tegra_clk_pll_freq_table *cfg);
  320. int (*calc_rate)(struct clk_hw *hw,
  321. struct tegra_clk_pll_freq_table *cfg,
  322. unsigned long rate, unsigned long parent_rate);
  323. unsigned long (*adjust_vco)(struct tegra_clk_pll_params *pll_params,
  324. unsigned long parent_rate);
  325. void (*set_defaults)(struct tegra_clk_pll *pll);
  326. int (*dyn_ramp)(struct tegra_clk_pll *pll,
  327. struct tegra_clk_pll_freq_table *cfg);
  328. int (*pre_rate_change)(void);
  329. void (*post_rate_change)(void);
  330. };
  331. #define TEGRA_PLL_USE_LOCK BIT(0)
  332. #define TEGRA_PLL_HAS_CPCON BIT(1)
  333. #define TEGRA_PLL_SET_LFCON BIT(2)
  334. #define TEGRA_PLL_SET_DCCON BIT(3)
  335. #define TEGRA_PLLU BIT(4)
  336. #define TEGRA_PLLM BIT(5)
  337. #define TEGRA_PLL_FIXED BIT(6)
  338. #define TEGRA_PLLE_CONFIGURE BIT(7)
  339. #define TEGRA_PLL_LOCK_MISC BIT(8)
  340. #define TEGRA_PLL_BYPASS BIT(9)
  341. #define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10)
  342. #define TEGRA_MDIV_NEW BIT(11)
  343. #define TEGRA_PLLMB BIT(12)
  344. #define TEGRA_PLL_VCO_OUT BIT(13)
  345. /**
  346. * struct tegra_clk_pll - Tegra PLL clock
  347. *
  348. * @hw: handle between common and hardware-specifix interfaces
  349. * @clk_base: address of CAR controller
  350. * @pmc: address of PMC, required to read override bits
  351. * @lock: register lock
  352. * @params: PLL parameters
  353. */
  354. struct tegra_clk_pll {
  355. struct clk_hw hw;
  356. void __iomem *clk_base;
  357. void __iomem *pmc;
  358. spinlock_t *lock;
  359. struct tegra_clk_pll_params *params;
  360. };
  361. #define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
  362. /**
  363. * struct tegra_audio_clk_info - Tegra Audio Clk Information
  364. *
  365. * @name: name for the audio pll
  366. * @pll_params: pll_params for audio pll
  367. * @clk_id: clk_ids for the audio pll
  368. * @parent: name of the parent of the audio pll
  369. */
  370. struct tegra_audio_clk_info {
  371. char *name;
  372. struct tegra_clk_pll_params *pll_params;
  373. int clk_id;
  374. char *parent;
  375. };
  376. extern const struct clk_ops tegra_clk_pll_ops;
  377. extern const struct clk_ops tegra_clk_plle_ops;
  378. struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
  379. void __iomem *clk_base, void __iomem *pmc,
  380. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  381. spinlock_t *lock);
  382. struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
  383. void __iomem *clk_base, void __iomem *pmc,
  384. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  385. spinlock_t *lock);
  386. struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
  387. void __iomem *clk_base, void __iomem *pmc,
  388. unsigned long flags,
  389. struct tegra_clk_pll_params *pll_params,
  390. spinlock_t *lock);
  391. struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
  392. void __iomem *clk_base, void __iomem *pmc,
  393. unsigned long flags,
  394. struct tegra_clk_pll_params *pll_params,
  395. spinlock_t *lock);
  396. struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
  397. void __iomem *clk_base, void __iomem *pmc,
  398. unsigned long flags,
  399. struct tegra_clk_pll_params *pll_params,
  400. spinlock_t *lock);
  401. struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
  402. void __iomem *clk_base, void __iomem *pmc,
  403. unsigned long flags,
  404. struct tegra_clk_pll_params *pll_params,
  405. spinlock_t *lock, unsigned long parent_rate);
  406. struct clk *tegra_clk_register_pllre_tegra210(const char *name,
  407. const char *parent_name, void __iomem *clk_base,
  408. void __iomem *pmc, unsigned long flags,
  409. struct tegra_clk_pll_params *pll_params,
  410. spinlock_t *lock, unsigned long parent_rate);
  411. struct clk *tegra_clk_register_plle_tegra114(const char *name,
  412. const char *parent_name,
  413. void __iomem *clk_base, unsigned long flags,
  414. struct tegra_clk_pll_params *pll_params,
  415. spinlock_t *lock);
  416. struct clk *tegra_clk_register_plle_tegra210(const char *name,
  417. const char *parent_name,
  418. void __iomem *clk_base, unsigned long flags,
  419. struct tegra_clk_pll_params *pll_params,
  420. spinlock_t *lock);
  421. struct clk *tegra_clk_register_pllc_tegra210(const char *name,
  422. const char *parent_name, void __iomem *clk_base,
  423. void __iomem *pmc, unsigned long flags,
  424. struct tegra_clk_pll_params *pll_params,
  425. spinlock_t *lock);
  426. struct clk *tegra_clk_register_pllss_tegra210(const char *name,
  427. const char *parent_name, void __iomem *clk_base,
  428. unsigned long flags,
  429. struct tegra_clk_pll_params *pll_params,
  430. spinlock_t *lock);
  431. struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name,
  432. void __iomem *clk_base, unsigned long flags,
  433. struct tegra_clk_pll_params *pll_params,
  434. spinlock_t *lock);
  435. struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name,
  436. void __iomem *clk_base, void __iomem *pmc,
  437. unsigned long flags,
  438. struct tegra_clk_pll_params *pll_params,
  439. spinlock_t *lock);
  440. struct clk *tegra_clk_register_pllu(const char *name, const char *parent_name,
  441. void __iomem *clk_base, unsigned long flags,
  442. struct tegra_clk_pll_params *pll_params,
  443. spinlock_t *lock);
  444. struct clk *tegra_clk_register_pllu_tegra114(const char *name,
  445. const char *parent_name,
  446. void __iomem *clk_base, unsigned long flags,
  447. struct tegra_clk_pll_params *pll_params,
  448. spinlock_t *lock);
  449. struct clk *tegra_clk_register_pllu_tegra210(const char *name,
  450. const char *parent_name,
  451. void __iomem *clk_base, unsigned long flags,
  452. struct tegra_clk_pll_params *pll_params,
  453. spinlock_t *lock);
  454. /**
  455. * struct tegra_clk_pll_out - PLL divider down clock
  456. *
  457. * @hw: handle between common and hardware-specific interfaces
  458. * @reg: register containing the PLL divider
  459. * @enb_bit_idx: bit to enable/disable PLL divider
  460. * @rst_bit_idx: bit to reset PLL divider
  461. * @lock: register lock
  462. * @flags: hardware-specific flags
  463. */
  464. struct tegra_clk_pll_out {
  465. struct clk_hw hw;
  466. void __iomem *reg;
  467. u8 enb_bit_idx;
  468. u8 rst_bit_idx;
  469. spinlock_t *lock;
  470. u8 flags;
  471. };
  472. #define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
  473. extern const struct clk_ops tegra_clk_pll_out_ops;
  474. struct clk *tegra_clk_register_pll_out(const char *name,
  475. const char *parent_name, void __iomem *reg, u8 enb_bit_idx,
  476. u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags,
  477. spinlock_t *lock);
  478. /**
  479. * struct tegra_clk_periph_regs - Registers controlling peripheral clock
  480. *
  481. * @enb_reg: read the enable status
  482. * @enb_set_reg: write 1 to enable clock
  483. * @enb_clr_reg: write 1 to disable clock
  484. * @rst_reg: read the reset status
  485. * @rst_set_reg: write 1 to assert the reset of peripheral
  486. * @rst_clr_reg: write 1 to deassert the reset of peripheral
  487. */
  488. struct tegra_clk_periph_regs {
  489. u32 enb_reg;
  490. u32 enb_set_reg;
  491. u32 enb_clr_reg;
  492. u32 rst_reg;
  493. u32 rst_set_reg;
  494. u32 rst_clr_reg;
  495. };
  496. /**
  497. * struct tegra_clk_periph_gate - peripheral gate clock
  498. *
  499. * @magic: magic number to validate type
  500. * @hw: handle between common and hardware-specific interfaces
  501. * @clk_base: address of CAR controller
  502. * @regs: Registers to control the peripheral
  503. * @flags: hardware-specific flags
  504. * @clk_num: Clock number
  505. * @enable_refcnt: array to maintain reference count of the clock
  506. *
  507. * Flags:
  508. * TEGRA_PERIPH_NO_RESET - This flag indicates that reset is not allowed
  509. * for this module.
  510. * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the
  511. * bus to flush the write operation in apb bus. This flag indicates
  512. * that this peripheral is in apb bus.
  513. * TEGRA_PERIPH_WAR_1005168 - Apply workaround for Tegra114 MSENC bug
  514. */
  515. struct tegra_clk_periph_gate {
  516. u32 magic;
  517. struct clk_hw hw;
  518. void __iomem *clk_base;
  519. u8 flags;
  520. int clk_num;
  521. int *enable_refcnt;
  522. const struct tegra_clk_periph_regs *regs;
  523. };
  524. #define to_clk_periph_gate(_hw) \
  525. container_of(_hw, struct tegra_clk_periph_gate, hw)
  526. #define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309
  527. #define TEGRA_PERIPH_NO_RESET BIT(0)
  528. #define TEGRA_PERIPH_ON_APB BIT(2)
  529. #define TEGRA_PERIPH_WAR_1005168 BIT(3)
  530. #define TEGRA_PERIPH_NO_DIV BIT(4)
  531. #define TEGRA_PERIPH_NO_GATE BIT(5)
  532. extern const struct clk_ops tegra_clk_periph_gate_ops;
  533. struct clk *tegra_clk_register_periph_gate(const char *name,
  534. const char *parent_name, u8 gate_flags, void __iomem *clk_base,
  535. unsigned long flags, int clk_num, int *enable_refcnt);
  536. struct tegra_clk_periph_fixed {
  537. struct clk_hw hw;
  538. void __iomem *base;
  539. const struct tegra_clk_periph_regs *regs;
  540. unsigned int mul;
  541. unsigned int div;
  542. unsigned int num;
  543. };
  544. struct clk *tegra_clk_register_periph_fixed(const char *name,
  545. const char *parent,
  546. unsigned long flags,
  547. void __iomem *base,
  548. unsigned int mul,
  549. unsigned int div,
  550. unsigned int num);
  551. /**
  552. * struct clk-periph - peripheral clock
  553. *
  554. * @magic: magic number to validate type
  555. * @hw: handle between common and hardware-specific interfaces
  556. * @mux: mux clock
  557. * @divider: divider clock
  558. * @gate: gate clock
  559. * @mux_ops: mux clock ops
  560. * @div_ops: divider clock ops
  561. * @gate_ops: gate clock ops
  562. */
  563. struct tegra_clk_periph {
  564. u32 magic;
  565. struct clk_hw hw;
  566. struct clk_mux mux;
  567. struct tegra_clk_frac_div divider;
  568. struct tegra_clk_periph_gate gate;
  569. const struct clk_ops *mux_ops;
  570. const struct clk_ops *div_ops;
  571. const struct clk_ops *gate_ops;
  572. };
  573. #define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
  574. #define TEGRA_CLK_PERIPH_MAGIC 0x18221223
  575. extern const struct clk_ops tegra_clk_periph_ops;
  576. struct clk *tegra_clk_register_periph(const char *name,
  577. const char * const *parent_names, int num_parents,
  578. struct tegra_clk_periph *periph, void __iomem *clk_base,
  579. u32 offset, unsigned long flags);
  580. struct clk *tegra_clk_register_periph_nodiv(const char *name,
  581. const char * const *parent_names, int num_parents,
  582. struct tegra_clk_periph *periph, void __iomem *clk_base,
  583. u32 offset);
  584. #define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags, \
  585. _div_shift, _div_width, _div_frac_width, \
  586. _div_flags, _clk_num,\
  587. _gate_flags, _table, _lock) \
  588. { \
  589. .mux = { \
  590. .flags = _mux_flags, \
  591. .shift = _mux_shift, \
  592. .mask = _mux_mask, \
  593. .table = _table, \
  594. .lock = _lock, \
  595. }, \
  596. .divider = { \
  597. .flags = _div_flags, \
  598. .shift = _div_shift, \
  599. .width = _div_width, \
  600. .frac_width = _div_frac_width, \
  601. .lock = _lock, \
  602. }, \
  603. .gate = { \
  604. .flags = _gate_flags, \
  605. .clk_num = _clk_num, \
  606. }, \
  607. .mux_ops = &clk_mux_ops, \
  608. .div_ops = &tegra_clk_frac_div_ops, \
  609. .gate_ops = &tegra_clk_periph_gate_ops, \
  610. }
  611. struct tegra_periph_init_data {
  612. const char *name;
  613. int clk_id;
  614. union {
  615. const char *const *parent_names;
  616. const char *parent_name;
  617. } p;
  618. int num_parents;
  619. struct tegra_clk_periph periph;
  620. u32 offset;
  621. const char *con_id;
  622. const char *dev_id;
  623. unsigned long flags;
  624. };
  625. #define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
  626. _mux_shift, _mux_mask, _mux_flags, _div_shift, \
  627. _div_width, _div_frac_width, _div_flags, \
  628. _clk_num, _gate_flags, _clk_id, _table, \
  629. _flags, _lock) \
  630. { \
  631. .name = _name, \
  632. .clk_id = _clk_id, \
  633. .p.parent_names = _parent_names, \
  634. .num_parents = ARRAY_SIZE(_parent_names), \
  635. .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, \
  636. _mux_flags, _div_shift, \
  637. _div_width, _div_frac_width, \
  638. _div_flags, _clk_num, \
  639. _gate_flags, _table, _lock), \
  640. .offset = _offset, \
  641. .con_id = _con_id, \
  642. .dev_id = _dev_id, \
  643. .flags = _flags \
  644. }
  645. #define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\
  646. _mux_shift, _mux_width, _mux_flags, _div_shift, \
  647. _div_width, _div_frac_width, _div_flags, \
  648. _clk_num, _gate_flags, _clk_id) \
  649. TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
  650. _mux_shift, BIT(_mux_width) - 1, _mux_flags, \
  651. _div_shift, _div_width, _div_frac_width, _div_flags, \
  652. _clk_num, _gate_flags, _clk_id,\
  653. NULL, 0, NULL)
  654. struct clk *tegra_clk_register_periph_data(void __iomem *clk_base,
  655. struct tegra_periph_init_data *init);
  656. /**
  657. * struct clk_super_mux - super clock
  658. *
  659. * @hw: handle between common and hardware-specific interfaces
  660. * @reg: register controlling multiplexer
  661. * @width: width of the multiplexer bit field
  662. * @flags: hardware-specific flags
  663. * @div2_index: bit controlling divide-by-2
  664. * @pllx_index: PLLX index in the parent list
  665. * @lock: register lock
  666. *
  667. * Flags:
  668. * TEGRA_DIVIDER_2 - LP cluster has additional divider. This flag indicates
  669. * that this is LP cluster clock.
  670. * TEGRA210_CPU_CLK - This flag is used to identify CPU cluster for gen5
  671. * super mux parent using PLLP branches. To use PLLP branches to CPU, need
  672. * to configure additional bit PLLP_OUT_CPU in the clock registers.
  673. * TEGRA20_SUPER_CLK - Tegra20 doesn't have a dedicated divider for Super
  674. * clocks, it only has a clock-skipper.
  675. */
  676. struct tegra_clk_super_mux {
  677. struct clk_hw hw;
  678. void __iomem *reg;
  679. struct tegra_clk_frac_div frac_div;
  680. const struct clk_ops *div_ops;
  681. u8 width;
  682. u8 flags;
  683. u8 div2_index;
  684. u8 pllx_index;
  685. spinlock_t *lock;
  686. };
  687. #define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw)
  688. #define TEGRA_DIVIDER_2 BIT(0)
  689. #define TEGRA210_CPU_CLK BIT(1)
  690. #define TEGRA20_SUPER_CLK BIT(2)
  691. extern const struct clk_ops tegra_clk_super_ops;
  692. struct clk *tegra_clk_register_super_mux(const char *name,
  693. const char **parent_names, u8 num_parents,
  694. unsigned long flags, void __iomem *reg, u8 clk_super_flags,
  695. u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock);
  696. struct clk *tegra_clk_register_super_clk(const char *name,
  697. const char * const *parent_names, u8 num_parents,
  698. unsigned long flags, void __iomem *reg, u8 clk_super_flags,
  699. spinlock_t *lock);
  700. struct clk *tegra_clk_register_super_cclk(const char *name,
  701. const char * const *parent_names, u8 num_parents,
  702. unsigned long flags, void __iomem *reg, u8 clk_super_flags,
  703. spinlock_t *lock);
  704. int tegra_cclk_pre_pllx_rate_change(void);
  705. void tegra_cclk_post_pllx_rate_change(void);
  706. /**
  707. * struct tegra_sdmmc_mux - switch divider with Low Jitter inputs for SDMMC
  708. *
  709. * @hw: handle between common and hardware-specific interfaces
  710. * @reg: register controlling mux and divider
  711. * @flags: hardware-specific flags
  712. * @lock: optional register lock
  713. * @gate: gate clock
  714. * @gate_ops: gate clock ops
  715. */
  716. struct tegra_sdmmc_mux {
  717. struct clk_hw hw;
  718. void __iomem *reg;
  719. spinlock_t *lock;
  720. const struct clk_ops *gate_ops;
  721. struct tegra_clk_periph_gate gate;
  722. u8 div_flags;
  723. };
  724. #define to_clk_sdmmc_mux(_hw) container_of(_hw, struct tegra_sdmmc_mux, hw)
  725. struct clk *tegra_clk_register_sdmmc_mux_div(const char *name,
  726. void __iomem *clk_base, u32 offset, u32 clk_num, u8 div_flags,
  727. unsigned long flags, void *lock);
  728. /**
  729. * struct clk_init_table - clock initialization table
  730. * @clk_id: clock id as mentioned in device tree bindings
  731. * @parent_id: parent clock id as mentioned in device tree bindings
  732. * @rate: rate to set
  733. * @state: enable/disable
  734. */
  735. struct tegra_clk_init_table {
  736. unsigned int clk_id;
  737. unsigned int parent_id;
  738. unsigned long rate;
  739. int state;
  740. };
  741. /**
  742. * struct clk_duplicate - duplicate clocks
  743. * @clk_id: clock id as mentioned in device tree bindings
  744. * @lookup: duplicate lookup entry for the clock
  745. */
  746. struct tegra_clk_duplicate {
  747. int clk_id;
  748. struct clk_lookup lookup;
  749. };
  750. #define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \
  751. { \
  752. .clk_id = _clk_id, \
  753. .lookup = { \
  754. .dev_id = _dev, \
  755. .con_id = _con, \
  756. }, \
  757. }
  758. struct tegra_clk {
  759. int dt_id;
  760. bool present;
  761. };
  762. struct tegra_devclk {
  763. int dt_id;
  764. char *dev_id;
  765. char *con_id;
  766. };
  767. void tegra_init_special_resets(unsigned int num, int (*assert)(unsigned long),
  768. int (*deassert)(unsigned long));
  769. void tegra_init_from_table(struct tegra_clk_init_table *tbl,
  770. struct clk *clks[], int clk_max);
  771. void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
  772. struct clk *clks[], int clk_max);
  773. const struct tegra_clk_periph_regs *get_reg_bank(int clkid);
  774. struct clk **tegra_clk_init(void __iomem *clk_base, int num, int periph_banks);
  775. struct clk **tegra_lookup_dt_id(int clk_id, struct tegra_clk *tegra_clk);
  776. void tegra_add_of_provider(struct device_node *np, void *clk_src_onecell_get);
  777. void tegra_register_devclks(struct tegra_devclk *dev_clks, int num);
  778. void tegra_audio_clk_init(void __iomem *clk_base,
  779. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  780. struct tegra_audio_clk_info *audio_info,
  781. unsigned int num_plls, unsigned long sync_max_rate);
  782. void tegra_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base,
  783. struct tegra_clk *tegra_clks,
  784. struct tegra_clk_pll_params *pll_params);
  785. void tegra_fixed_clk_init(struct tegra_clk *tegra_clks);
  786. int tegra_osc_clk_init(void __iomem *clk_base, struct tegra_clk *clks,
  787. unsigned long *input_freqs, unsigned int num,
  788. unsigned int clk_m_div, unsigned long *osc_freq,
  789. unsigned long *pll_ref_freq);
  790. void tegra_super_clk_gen4_init(void __iomem *clk_base,
  791. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  792. struct tegra_clk_pll_params *pll_params);
  793. void tegra_super_clk_gen5_init(void __iomem *clk_base,
  794. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  795. struct tegra_clk_pll_params *pll_params);
  796. #ifdef CONFIG_TEGRA124_CLK_EMC
  797. struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np,
  798. spinlock_t *lock);
  799. bool tegra124_clk_emc_driver_available(struct clk_hw *emc_hw);
  800. #else
  801. static inline struct clk *
  802. tegra124_clk_register_emc(void __iomem *base, struct device_node *np,
  803. spinlock_t *lock)
  804. {
  805. return NULL;
  806. }
  807. static inline bool tegra124_clk_emc_driver_available(struct clk_hw *emc_hw)
  808. {
  809. return false;
  810. }
  811. #endif
  812. void tegra114_clock_tune_cpu_trimmers_high(void);
  813. void tegra114_clock_tune_cpu_trimmers_low(void);
  814. void tegra114_clock_tune_cpu_trimmers_init(void);
  815. void tegra114_clock_assert_dfll_dvco_reset(void);
  816. void tegra114_clock_deassert_dfll_dvco_reset(void);
  817. typedef void (*tegra_clk_apply_init_table_func)(void);
  818. extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
  819. int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll);
  820. u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate);
  821. int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div);
  822. int div_frac_get(unsigned long rate, unsigned parent_rate, u8 width,
  823. u8 frac_width, u8 flags);
  824. void tegra_clk_osc_resume(void __iomem *clk_base);
  825. void tegra_clk_set_pllp_out_cpu(bool enable);
  826. void tegra_clk_periph_suspend(void);
  827. void tegra_clk_periph_resume(void);
  828. /* Combined read fence with delay */
  829. #define fence_udelay(delay, reg) \
  830. do { \
  831. readl(reg); \
  832. udelay(delay); \
  833. } while (0)
  834. bool tegra20_clk_emc_driver_available(struct clk_hw *emc_hw);
  835. struct clk *tegra20_clk_register_emc(void __iomem *ioaddr, bool low_jitter);
  836. struct clk *tegra210_clk_register_emc(struct device_node *np,
  837. void __iomem *regs);
  838. struct clk *tegra_clk_dev_register(struct clk_hw *hw);
  839. #endif /* TEGRA_CLK_H */