1c349dbc7Sjsg /* 2c349dbc7Sjsg * Copyright © 2012-2016 Intel Corporation 3c349dbc7Sjsg * 4c349dbc7Sjsg * Permission is hereby granted, free of charge, to any person obtaining a 5c349dbc7Sjsg * copy of this software and associated documentation files (the "Software"), 6c349dbc7Sjsg * to deal in the Software without restriction, including without limitation 7c349dbc7Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c349dbc7Sjsg * and/or sell copies of the Software, and to permit persons to whom the 9c349dbc7Sjsg * Software is furnished to do so, subject to the following conditions: 10c349dbc7Sjsg * 11c349dbc7Sjsg * The above copyright notice and this permission notice (including the next 12c349dbc7Sjsg * paragraph) shall be included in all copies or substantial portions of the 13c349dbc7Sjsg * Software. 14c349dbc7Sjsg * 15c349dbc7Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16c349dbc7Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17c349dbc7Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18c349dbc7Sjsg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19c349dbc7Sjsg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20c349dbc7Sjsg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21c349dbc7Sjsg * IN THE SOFTWARE. 22c349dbc7Sjsg * 23c349dbc7Sjsg */ 24c349dbc7Sjsg 25c349dbc7Sjsg #ifndef _INTEL_DPLL_MGR_H_ 26c349dbc7Sjsg #define _INTEL_DPLL_MGR_H_ 27c349dbc7Sjsg 28c349dbc7Sjsg #include <linux/types.h> 29c349dbc7Sjsg 30c349dbc7Sjsg #include "intel_wakeref.h" 31c349dbc7Sjsg 32c349dbc7Sjsg /*FIXME: Move this to a more appropriate place. */ 33c349dbc7Sjsg #define abs_diff(a, b) ({ \ 34c349dbc7Sjsg typeof(a) __a = (a); \ 35c349dbc7Sjsg typeof(b) __b = (b); \ 36c349dbc7Sjsg (void) (&__a == &__b); \ 37c349dbc7Sjsg __a > __b ? (__a - __b) : (__b - __a); }) 38c349dbc7Sjsg 391bb76ff1Sjsg enum tc_port; 40c349dbc7Sjsg struct drm_i915_private; 41c349dbc7Sjsg struct intel_atomic_state; 42c349dbc7Sjsg struct intel_crtc; 43c349dbc7Sjsg struct intel_crtc_state; 44c349dbc7Sjsg struct intel_encoder; 45c349dbc7Sjsg struct intel_shared_dpll; 461bb76ff1Sjsg struct intel_shared_dpll_funcs; 47c349dbc7Sjsg 48c349dbc7Sjsg /** 49c349dbc7Sjsg * enum intel_dpll_id - possible DPLL ids 50c349dbc7Sjsg * 51c349dbc7Sjsg * Enumeration of possible IDs for a DPLL. Real shared dpll ids must be >= 0. 52c349dbc7Sjsg */ 53c349dbc7Sjsg enum intel_dpll_id { 54c349dbc7Sjsg /** 55c349dbc7Sjsg * @DPLL_ID_PRIVATE: non-shared dpll in use 56c349dbc7Sjsg */ 57c349dbc7Sjsg DPLL_ID_PRIVATE = -1, 58c349dbc7Sjsg 59c349dbc7Sjsg /** 60c349dbc7Sjsg * @DPLL_ID_PCH_PLL_A: DPLL A in ILK, SNB and IVB 61c349dbc7Sjsg */ 62c349dbc7Sjsg DPLL_ID_PCH_PLL_A = 0, 63c349dbc7Sjsg /** 64c349dbc7Sjsg * @DPLL_ID_PCH_PLL_B: DPLL B in ILK, SNB and IVB 65c349dbc7Sjsg */ 66c349dbc7Sjsg DPLL_ID_PCH_PLL_B = 1, 67c349dbc7Sjsg 68c349dbc7Sjsg 69c349dbc7Sjsg /** 70c349dbc7Sjsg * @DPLL_ID_WRPLL1: HSW and BDW WRPLL1 71c349dbc7Sjsg */ 72c349dbc7Sjsg DPLL_ID_WRPLL1 = 0, 73c349dbc7Sjsg /** 74c349dbc7Sjsg * @DPLL_ID_WRPLL2: HSW and BDW WRPLL2 75c349dbc7Sjsg */ 76c349dbc7Sjsg DPLL_ID_WRPLL2 = 1, 77c349dbc7Sjsg /** 78c349dbc7Sjsg * @DPLL_ID_SPLL: HSW and BDW SPLL 79c349dbc7Sjsg */ 80c349dbc7Sjsg DPLL_ID_SPLL = 2, 81c349dbc7Sjsg /** 82c349dbc7Sjsg * @DPLL_ID_LCPLL_810: HSW and BDW 0.81 GHz LCPLL 83c349dbc7Sjsg */ 84c349dbc7Sjsg DPLL_ID_LCPLL_810 = 3, 85c349dbc7Sjsg /** 86c349dbc7Sjsg * @DPLL_ID_LCPLL_1350: HSW and BDW 1.35 GHz LCPLL 87c349dbc7Sjsg */ 88c349dbc7Sjsg DPLL_ID_LCPLL_1350 = 4, 89c349dbc7Sjsg /** 90c349dbc7Sjsg * @DPLL_ID_LCPLL_2700: HSW and BDW 2.7 GHz LCPLL 91c349dbc7Sjsg */ 92c349dbc7Sjsg DPLL_ID_LCPLL_2700 = 5, 93c349dbc7Sjsg 94c349dbc7Sjsg 95c349dbc7Sjsg /** 96c349dbc7Sjsg * @DPLL_ID_SKL_DPLL0: SKL and later DPLL0 97c349dbc7Sjsg */ 98c349dbc7Sjsg DPLL_ID_SKL_DPLL0 = 0, 99c349dbc7Sjsg /** 100c349dbc7Sjsg * @DPLL_ID_SKL_DPLL1: SKL and later DPLL1 101c349dbc7Sjsg */ 102c349dbc7Sjsg DPLL_ID_SKL_DPLL1 = 1, 103c349dbc7Sjsg /** 104c349dbc7Sjsg * @DPLL_ID_SKL_DPLL2: SKL and later DPLL2 105c349dbc7Sjsg */ 106c349dbc7Sjsg DPLL_ID_SKL_DPLL2 = 2, 107c349dbc7Sjsg /** 108c349dbc7Sjsg * @DPLL_ID_SKL_DPLL3: SKL and later DPLL3 109c349dbc7Sjsg */ 110c349dbc7Sjsg DPLL_ID_SKL_DPLL3 = 3, 111c349dbc7Sjsg 112c349dbc7Sjsg 113c349dbc7Sjsg /** 114c349dbc7Sjsg * @DPLL_ID_ICL_DPLL0: ICL/TGL combo PHY DPLL0 115c349dbc7Sjsg */ 116c349dbc7Sjsg DPLL_ID_ICL_DPLL0 = 0, 117c349dbc7Sjsg /** 118c349dbc7Sjsg * @DPLL_ID_ICL_DPLL1: ICL/TGL combo PHY DPLL1 119c349dbc7Sjsg */ 120c349dbc7Sjsg DPLL_ID_ICL_DPLL1 = 1, 121c349dbc7Sjsg /** 122c349dbc7Sjsg * @DPLL_ID_EHL_DPLL4: EHL combo PHY DPLL4 123c349dbc7Sjsg */ 124c349dbc7Sjsg DPLL_ID_EHL_DPLL4 = 2, 125c349dbc7Sjsg /** 126c349dbc7Sjsg * @DPLL_ID_ICL_TBTPLL: ICL/TGL TBT PLL 127c349dbc7Sjsg */ 128c349dbc7Sjsg DPLL_ID_ICL_TBTPLL = 2, 129c349dbc7Sjsg /** 130c349dbc7Sjsg * @DPLL_ID_ICL_MGPLL1: ICL MG PLL 1 port 1 (C), 131c349dbc7Sjsg * TGL TC PLL 1 port 1 (TC1) 132c349dbc7Sjsg */ 133c349dbc7Sjsg DPLL_ID_ICL_MGPLL1 = 3, 134c349dbc7Sjsg /** 135c349dbc7Sjsg * @DPLL_ID_ICL_MGPLL2: ICL MG PLL 1 port 2 (D) 136c349dbc7Sjsg * TGL TC PLL 1 port 2 (TC2) 137c349dbc7Sjsg */ 138c349dbc7Sjsg DPLL_ID_ICL_MGPLL2 = 4, 139c349dbc7Sjsg /** 140c349dbc7Sjsg * @DPLL_ID_ICL_MGPLL3: ICL MG PLL 1 port 3 (E) 141c349dbc7Sjsg * TGL TC PLL 1 port 3 (TC3) 142c349dbc7Sjsg */ 143c349dbc7Sjsg DPLL_ID_ICL_MGPLL3 = 5, 144c349dbc7Sjsg /** 145c349dbc7Sjsg * @DPLL_ID_ICL_MGPLL4: ICL MG PLL 1 port 4 (F) 146c349dbc7Sjsg * TGL TC PLL 1 port 4 (TC4) 147c349dbc7Sjsg */ 148c349dbc7Sjsg DPLL_ID_ICL_MGPLL4 = 6, 149c349dbc7Sjsg /** 150c349dbc7Sjsg * @DPLL_ID_TGL_MGPLL5: TGL TC PLL port 5 (TC5) 151c349dbc7Sjsg */ 152c349dbc7Sjsg DPLL_ID_TGL_MGPLL5 = 7, 153c349dbc7Sjsg /** 154c349dbc7Sjsg * @DPLL_ID_TGL_MGPLL6: TGL TC PLL port 6 (TC6) 155c349dbc7Sjsg */ 156c349dbc7Sjsg DPLL_ID_TGL_MGPLL6 = 8, 1575ca02815Sjsg 1585ca02815Sjsg /** 1595ca02815Sjsg * @DPLL_ID_DG1_DPLL0: DG1 combo PHY DPLL0 1605ca02815Sjsg */ 1615ca02815Sjsg DPLL_ID_DG1_DPLL0 = 0, 1625ca02815Sjsg /** 1635ca02815Sjsg * @DPLL_ID_DG1_DPLL1: DG1 combo PHY DPLL1 1645ca02815Sjsg */ 1655ca02815Sjsg DPLL_ID_DG1_DPLL1 = 1, 1665ca02815Sjsg /** 1675ca02815Sjsg * @DPLL_ID_DG1_DPLL2: DG1 combo PHY DPLL2 1685ca02815Sjsg */ 1695ca02815Sjsg DPLL_ID_DG1_DPLL2 = 2, 1705ca02815Sjsg /** 1715ca02815Sjsg * @DPLL_ID_DG1_DPLL3: DG1 combo PHY DPLL3 1725ca02815Sjsg */ 1735ca02815Sjsg DPLL_ID_DG1_DPLL3 = 3, 174c349dbc7Sjsg }; 175c349dbc7Sjsg 176c349dbc7Sjsg #define I915_NUM_PLLS 9 177c349dbc7Sjsg 178c349dbc7Sjsg enum icl_port_dpll_id { 179c349dbc7Sjsg ICL_PORT_DPLL_DEFAULT, 180c349dbc7Sjsg ICL_PORT_DPLL_MG_PHY, 181c349dbc7Sjsg 182c349dbc7Sjsg ICL_PORT_DPLL_COUNT, 183c349dbc7Sjsg }; 184c349dbc7Sjsg 185c349dbc7Sjsg struct intel_dpll_hw_state { 186c349dbc7Sjsg /* i9xx, pch plls */ 187c349dbc7Sjsg u32 dpll; 188c349dbc7Sjsg u32 dpll_md; 189c349dbc7Sjsg u32 fp0; 190c349dbc7Sjsg u32 fp1; 191c349dbc7Sjsg 192c349dbc7Sjsg /* hsw, bdw */ 193c349dbc7Sjsg u32 wrpll; 194c349dbc7Sjsg u32 spll; 195c349dbc7Sjsg 196c349dbc7Sjsg /* skl */ 197c349dbc7Sjsg /* 198c349dbc7Sjsg * DPLL_CTRL1 has 6 bits for each each this DPLL. We store those in 199c349dbc7Sjsg * lower part of ctrl1 and they get shifted into position when writing 200c349dbc7Sjsg * the register. This allows us to easily compare the state to share 201c349dbc7Sjsg * the DPLL. 202c349dbc7Sjsg */ 203c349dbc7Sjsg u32 ctrl1; 204c349dbc7Sjsg /* HDMI only, 0 when used for DP */ 205c349dbc7Sjsg u32 cfgcr1, cfgcr2; 206c349dbc7Sjsg 2075ca02815Sjsg /* icl */ 208c349dbc7Sjsg u32 cfgcr0; 209c349dbc7Sjsg 2101bb76ff1Sjsg /* tgl */ 2111bb76ff1Sjsg u32 div0; 2121bb76ff1Sjsg 213c349dbc7Sjsg /* bxt */ 214c349dbc7Sjsg u32 ebb0, ebb4, pll0, pll1, pll2, pll3, pll6, pll8, pll9, pll10, pcsdw12; 215c349dbc7Sjsg 216c349dbc7Sjsg /* 217c349dbc7Sjsg * ICL uses the following, already defined: 218c349dbc7Sjsg * u32 cfgcr0, cfgcr1; 219c349dbc7Sjsg */ 220c349dbc7Sjsg u32 mg_refclkin_ctl; 221c349dbc7Sjsg u32 mg_clktop2_coreclkctl1; 222c349dbc7Sjsg u32 mg_clktop2_hsclkctl; 223c349dbc7Sjsg u32 mg_pll_div0; 224c349dbc7Sjsg u32 mg_pll_div1; 225c349dbc7Sjsg u32 mg_pll_lf; 226c349dbc7Sjsg u32 mg_pll_frac_lock; 227c349dbc7Sjsg u32 mg_pll_ssc; 228c349dbc7Sjsg u32 mg_pll_bias; 229c349dbc7Sjsg u32 mg_pll_tdc_coldst_bias; 230c349dbc7Sjsg u32 mg_pll_bias_mask; 231c349dbc7Sjsg u32 mg_pll_tdc_coldst_bias_mask; 232c349dbc7Sjsg }; 233c349dbc7Sjsg 234c349dbc7Sjsg /** 235c349dbc7Sjsg * struct intel_shared_dpll_state - hold the DPLL atomic state 236c349dbc7Sjsg * 237c349dbc7Sjsg * This structure holds an atomic state for the DPLL, that can represent 238c349dbc7Sjsg * either its current state (in struct &intel_shared_dpll) or a desired 239c349dbc7Sjsg * future state which would be applied by an atomic mode set (stored in 240c349dbc7Sjsg * a struct &intel_atomic_state). 241c349dbc7Sjsg * 242c349dbc7Sjsg * See also intel_reserve_shared_dplls() and intel_release_shared_dplls(). 243c349dbc7Sjsg */ 244c349dbc7Sjsg struct intel_shared_dpll_state { 245c349dbc7Sjsg /** 2465ca02815Sjsg * @pipe_mask: mask of pipes using this DPLL, active or not 247c349dbc7Sjsg */ 2485ca02815Sjsg u8 pipe_mask; 249c349dbc7Sjsg 250c349dbc7Sjsg /** 251c349dbc7Sjsg * @hw_state: hardware configuration for the DPLL stored in 252c349dbc7Sjsg * struct &intel_dpll_hw_state. 253c349dbc7Sjsg */ 254c349dbc7Sjsg struct intel_dpll_hw_state hw_state; 255c349dbc7Sjsg }; 256c349dbc7Sjsg 257c349dbc7Sjsg /** 258c349dbc7Sjsg * struct dpll_info - display PLL platform specific info 259c349dbc7Sjsg */ 260c349dbc7Sjsg struct dpll_info { 261c349dbc7Sjsg /** 262c349dbc7Sjsg * @name: DPLL name; used for logging 263c349dbc7Sjsg */ 264c349dbc7Sjsg const char *name; 265c349dbc7Sjsg 266c349dbc7Sjsg /** 267c349dbc7Sjsg * @funcs: platform specific hooks 268c349dbc7Sjsg */ 269c349dbc7Sjsg const struct intel_shared_dpll_funcs *funcs; 270c349dbc7Sjsg 271c349dbc7Sjsg /** 272c349dbc7Sjsg * @id: unique indentifier for this DPLL; should match the index in the 273c349dbc7Sjsg * dev_priv->shared_dplls array 274c349dbc7Sjsg */ 275c349dbc7Sjsg enum intel_dpll_id id; 276c349dbc7Sjsg 277c349dbc7Sjsg #define INTEL_DPLL_ALWAYS_ON (1 << 0) 278c349dbc7Sjsg /** 279c349dbc7Sjsg * @flags: 280c349dbc7Sjsg * 281c349dbc7Sjsg * INTEL_DPLL_ALWAYS_ON 282c349dbc7Sjsg * Inform the state checker that the DPLL is kept enabled even if 283c349dbc7Sjsg * not in use by any CRTC. 284c349dbc7Sjsg */ 285c349dbc7Sjsg u32 flags; 286c349dbc7Sjsg }; 287c349dbc7Sjsg 288c349dbc7Sjsg /** 289c349dbc7Sjsg * struct intel_shared_dpll - display PLL with tracked state and users 290c349dbc7Sjsg */ 291c349dbc7Sjsg struct intel_shared_dpll { 292c349dbc7Sjsg /** 293c349dbc7Sjsg * @state: 294c349dbc7Sjsg * 295c349dbc7Sjsg * Store the state for the pll, including its hw state 296c349dbc7Sjsg * and CRTCs using it. 297c349dbc7Sjsg */ 298c349dbc7Sjsg struct intel_shared_dpll_state state; 299c349dbc7Sjsg 300c349dbc7Sjsg /** 3015ca02815Sjsg * @active_mask: mask of active pipes (i.e. DPMS on) using this DPLL 302c349dbc7Sjsg */ 3035ca02815Sjsg u8 active_mask; 304c349dbc7Sjsg 305c349dbc7Sjsg /** 306c349dbc7Sjsg * @on: is the PLL actually active? Disabled during modeset 307c349dbc7Sjsg */ 308c349dbc7Sjsg bool on; 309c349dbc7Sjsg 310c349dbc7Sjsg /** 311c349dbc7Sjsg * @info: platform specific info 312c349dbc7Sjsg */ 313c349dbc7Sjsg const struct dpll_info *info; 314c349dbc7Sjsg 315c349dbc7Sjsg /** 316c349dbc7Sjsg * @wakeref: In some platforms a device-level runtime pm reference may 317c349dbc7Sjsg * need to be grabbed to disable DC states while this DPLL is enabled 318c349dbc7Sjsg */ 319c349dbc7Sjsg intel_wakeref_t wakeref; 320c349dbc7Sjsg }; 321c349dbc7Sjsg 322c349dbc7Sjsg #define SKL_DPLL0 0 323c349dbc7Sjsg #define SKL_DPLL1 1 324c349dbc7Sjsg #define SKL_DPLL2 2 325c349dbc7Sjsg #define SKL_DPLL3 3 326c349dbc7Sjsg 327c349dbc7Sjsg /* shared dpll functions */ 328c349dbc7Sjsg struct intel_shared_dpll * 329c349dbc7Sjsg intel_get_shared_dpll_by_id(struct drm_i915_private *dev_priv, 330c349dbc7Sjsg enum intel_dpll_id id); 331c349dbc7Sjsg void assert_shared_dpll(struct drm_i915_private *dev_priv, 332c349dbc7Sjsg struct intel_shared_dpll *pll, 333c349dbc7Sjsg bool state); 334c349dbc7Sjsg #define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true) 335c349dbc7Sjsg #define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false) 3361bb76ff1Sjsg int intel_compute_shared_dplls(struct intel_atomic_state *state, 3371bb76ff1Sjsg struct intel_crtc *crtc, 3381bb76ff1Sjsg struct intel_encoder *encoder); 3391bb76ff1Sjsg int intel_reserve_shared_dplls(struct intel_atomic_state *state, 340c349dbc7Sjsg struct intel_crtc *crtc, 341c349dbc7Sjsg struct intel_encoder *encoder); 342c349dbc7Sjsg void intel_release_shared_dplls(struct intel_atomic_state *state, 343c349dbc7Sjsg struct intel_crtc *crtc); 344*f005ef32Sjsg void intel_unreference_shared_dpll_crtc(const struct intel_crtc *crtc, 345*f005ef32Sjsg const struct intel_shared_dpll *pll, 346*f005ef32Sjsg struct intel_shared_dpll_state *shared_dpll_state); 347c349dbc7Sjsg void icl_set_active_port_dpll(struct intel_crtc_state *crtc_state, 348c349dbc7Sjsg enum icl_port_dpll_id port_dpll_id); 349c349dbc7Sjsg void intel_update_active_dpll(struct intel_atomic_state *state, 350c349dbc7Sjsg struct intel_crtc *crtc, 351c349dbc7Sjsg struct intel_encoder *encoder); 352c349dbc7Sjsg int intel_dpll_get_freq(struct drm_i915_private *i915, 3535ca02815Sjsg const struct intel_shared_dpll *pll, 3545ca02815Sjsg const struct intel_dpll_hw_state *pll_state); 3555ca02815Sjsg bool intel_dpll_get_hw_state(struct drm_i915_private *i915, 3565ca02815Sjsg struct intel_shared_dpll *pll, 3575ca02815Sjsg struct intel_dpll_hw_state *hw_state); 358c349dbc7Sjsg void intel_enable_shared_dpll(const struct intel_crtc_state *crtc_state); 359c349dbc7Sjsg void intel_disable_shared_dpll(const struct intel_crtc_state *crtc_state); 360c349dbc7Sjsg void intel_shared_dpll_swap_state(struct intel_atomic_state *state); 3611bb76ff1Sjsg void intel_shared_dpll_init(struct drm_i915_private *dev_priv); 3625ca02815Sjsg void intel_dpll_update_ref_clks(struct drm_i915_private *dev_priv); 363c349dbc7Sjsg void intel_dpll_readout_hw_state(struct drm_i915_private *dev_priv); 364c349dbc7Sjsg void intel_dpll_sanitize_state(struct drm_i915_private *dev_priv); 365c349dbc7Sjsg 366c349dbc7Sjsg void intel_dpll_dump_hw_state(struct drm_i915_private *dev_priv, 367c349dbc7Sjsg const struct intel_dpll_hw_state *hw_state); 368c349dbc7Sjsg enum intel_dpll_id icl_tc_port_to_pll_id(enum tc_port tc_port); 369c349dbc7Sjsg bool intel_dpll_is_combophy(enum intel_dpll_id id); 370c349dbc7Sjsg 3711bb76ff1Sjsg void intel_shared_dpll_state_verify(struct intel_crtc *crtc, 3721bb76ff1Sjsg struct intel_crtc_state *old_crtc_state, 3731bb76ff1Sjsg struct intel_crtc_state *new_crtc_state); 3741bb76ff1Sjsg void intel_shared_dpll_verify_disabled(struct drm_i915_private *i915); 3751bb76ff1Sjsg 376c349dbc7Sjsg #endif /* _INTEL_DPLL_MGR_H_ */ 377