blob: e263f74e69644423301bb8154c0ac11930d6ffb4 [file] [log] [blame]
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +02001/*
2 * Copyright © 2012-2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
25#ifndef _INTEL_DPLL_MGR_H_
26#define _INTEL_DPLL_MGR_H_
27
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +020028/*FIXME: Move this to a more appropriate place. */
29#define abs_diff(a, b) ({ \
30 typeof(a) __a = (a); \
31 typeof(b) __b = (b); \
32 (void) (&__a == &__b); \
33 __a > __b ? (__a - __b) : (__b - __a); })
34
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020035struct drm_i915_private;
Ander Conselvan de Oliveirac2a9fcd2016-03-08 17:46:20 +020036struct intel_crtc;
37struct intel_crtc_state;
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +020038struct intel_encoder;
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020039
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +020040struct intel_shared_dpll;
Ander Conselvan de Oliveiraf9476a62016-03-08 17:46:22 +020041struct intel_dpll_mgr;
42
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020043enum intel_dpll_id {
44 DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
45 /* real shared dpll ids must be >= 0 */
46 DPLL_ID_PCH_PLL_A = 0,
47 DPLL_ID_PCH_PLL_B = 1,
48 /* hsw/bdw */
49 DPLL_ID_WRPLL1 = 0,
50 DPLL_ID_WRPLL2 = 1,
51 DPLL_ID_SPLL = 2,
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +020052 DPLL_ID_LCPLL_810 = 3,
53 DPLL_ID_LCPLL_1350 = 4,
54 DPLL_ID_LCPLL_2700 = 5,
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020055
56 /* skl */
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +020057 DPLL_ID_SKL_DPLL0 = 0,
58 DPLL_ID_SKL_DPLL1 = 1,
59 DPLL_ID_SKL_DPLL2 = 2,
60 DPLL_ID_SKL_DPLL3 = 3,
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020061};
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +020062#define I915_NUM_PLLS 6
63
64/** Inform the state checker that the DPLL is kept enabled even if not
65 * in use by any crtc.
66 */
67#define INTEL_DPLL_ALWAYS_ON (1 << 0)
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020068
69struct intel_dpll_hw_state {
70 /* i9xx, pch plls */
71 uint32_t dpll;
72 uint32_t dpll_md;
73 uint32_t fp0;
74 uint32_t fp1;
75
76 /* hsw, bdw */
77 uint32_t wrpll;
78 uint32_t spll;
79
80 /* skl */
81 /*
82 * DPLL_CTRL1 has 6 bits for each each this DPLL. We store those in
83 * lower part of ctrl1 and they get shifted into position when writing
84 * the register. This allows us to easily compare the state to share
85 * the DPLL.
86 */
87 uint32_t ctrl1;
88 /* HDMI only, 0 when used for DP */
89 uint32_t cfgcr1, cfgcr2;
90
91 /* bxt */
92 uint32_t ebb0, ebb4, pll0, pll1, pll2, pll3, pll6, pll8, pll9, pll10,
93 pcsdw12;
94};
95
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020096struct intel_shared_dpll_state {
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +020097 unsigned crtc_mask; /* mask of CRTCs sharing this PLL */
98 struct intel_dpll_hw_state hw_state;
99};
100
Ander Conselvan de Oliveira2edd6442016-03-08 17:46:21 +0200101struct intel_shared_dpll_funcs {
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +0200102 /* The mode_set hook is optional and should be used together with the
103 * intel_prepare_shared_dpll function. */
Ander Conselvan de Oliveiraeac61762016-12-29 17:22:10 +0200104 void (*prepare)(struct drm_i915_private *dev_priv,
105 struct intel_shared_dpll *pll);
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +0200106 void (*enable)(struct drm_i915_private *dev_priv,
107 struct intel_shared_dpll *pll);
108 void (*disable)(struct drm_i915_private *dev_priv,
109 struct intel_shared_dpll *pll);
110 bool (*get_hw_state)(struct drm_i915_private *dev_priv,
111 struct intel_shared_dpll *pll,
112 struct intel_dpll_hw_state *hw_state);
113};
114
Ander Conselvan de Oliveira2edd6442016-03-08 17:46:21 +0200115struct intel_shared_dpll {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +0200116 struct intel_shared_dpll_state state;
Ander Conselvan de Oliveira2edd6442016-03-08 17:46:21 +0200117
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +0100118 unsigned active_mask; /* mask of active CRTCs (i.e. DPMS on) */
Ander Conselvan de Oliveira2edd6442016-03-08 17:46:21 +0200119 bool on; /* is the PLL actually active? Disabled during modeset */
120 const char *name;
121 /* should match the index in the dev_priv->shared_dplls array */
122 enum intel_dpll_id id;
123
124 struct intel_shared_dpll_funcs funcs;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +0200125
126 uint32_t flags;
Ander Conselvan de Oliveira2edd6442016-03-08 17:46:21 +0200127};
128
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +0200129#define SKL_DPLL0 0
130#define SKL_DPLL1 1
131#define SKL_DPLL2 2
132#define SKL_DPLL3 3
133
Ander Conselvan de Oliveirac2a9fcd2016-03-08 17:46:20 +0200134/* shared dpll functions */
135struct intel_shared_dpll *
136intel_get_shared_dpll_by_id(struct drm_i915_private *dev_priv,
137 enum intel_dpll_id id);
138enum intel_dpll_id
139intel_get_shared_dpll_id(struct drm_i915_private *dev_priv,
140 struct intel_shared_dpll *pll);
Ander Conselvan de Oliveirac2a9fcd2016-03-08 17:46:20 +0200141void assert_shared_dpll(struct drm_i915_private *dev_priv,
142 struct intel_shared_dpll *pll,
143 bool state);
144#define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true)
145#define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false)
146struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc,
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +0200147 struct intel_crtc_state *state,
148 struct intel_encoder *encoder);
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +0200149void intel_release_shared_dpll(struct intel_shared_dpll *dpll,
150 struct intel_crtc *crtc,
151 struct drm_atomic_state *state);
Ander Conselvan de Oliveirac2a9fcd2016-03-08 17:46:20 +0200152void intel_prepare_shared_dpll(struct intel_crtc *crtc);
153void intel_enable_shared_dpll(struct intel_crtc *crtc);
154void intel_disable_shared_dpll(struct intel_crtc *crtc);
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +0200155void intel_shared_dpll_swap_state(struct drm_atomic_state *state);
Ander Conselvan de Oliveirac2a9fcd2016-03-08 17:46:20 +0200156void intel_shared_dpll_init(struct drm_device *dev);
157
Durgadoss Ra277ca72016-09-01 15:08:09 -0700158/* BXT dpll related functions */
159bool bxt_ddi_dp_set_dpll_hw_state(int clock,
160 struct intel_dpll_hw_state *dpll_hw_state);
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +0200161
Manasi Navare81b9fd82016-09-01 15:08:11 -0700162
Jim Bride9a4edad2016-09-01 15:08:10 -0700163/* SKL dpll related functions */
164bool skl_ddi_dp_set_dpll_hw_state(int clock,
165 struct intel_dpll_hw_state *dpll_hw_state);
Jim Bridef1696602016-09-07 15:47:34 -0700166struct intel_shared_dpll *skl_find_link_pll(struct drm_i915_private *dev_priv,
167 int clock);
Jim Bride9a4edad2016-09-01 15:08:10 -0700168
Manasi Navare81b9fd82016-09-01 15:08:11 -0700169
170/* HSW dpll related functions */
171struct intel_shared_dpll *hsw_ddi_dp_get_dpll(struct intel_encoder *encoder,
172 int clock);
173
Ander Conselvan de Oliveiraac7f11c2016-03-08 17:46:19 +0200174#endif /* _INTEL_DPLL_MGR_H_ */