Skip to content

Commit e06f1c6

Browse files
committed
drm/i915/dsi: Extract {vlv,bxt}_get_pclk()
Extract the state->freq computation for VLV/BXT DSI PLL into small helpers. We want to use these during the state computation as well. Reviewed-by: Mika Kahola <mika.kahola@intel.com> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220907091057.11572-5-ville.syrjala@linux.intel.com
1 parent 9988db5 commit e06f1c6

File tree

1 file changed

+68
-53
lines changed

1 file changed

+68
-53
lines changed

drivers/gpu/drm/i915/display/vlv_dsi_pll.c

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,61 @@ static int dsi_calc_mnp(struct drm_i915_private *dev_priv,
113113
return 0;
114114
}
115115

116+
static int vlv_dsi_pclk(struct intel_encoder *encoder,
117+
struct intel_crtc_state *config)
118+
{
119+
struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
120+
struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
121+
int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
122+
u32 dsi_clock;
123+
u32 pll_ctl, pll_div;
124+
u32 m = 0, p = 0, n;
125+
int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
126+
int i;
127+
128+
pll_ctl = config->dsi_pll.ctrl;
129+
pll_div = config->dsi_pll.div;
130+
131+
/* mask out other bits and extract the P1 divisor */
132+
pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
133+
pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
134+
135+
/* N1 divisor */
136+
n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
137+
n = 1 << n; /* register has log2(N1) */
138+
139+
/* mask out the other bits and extract the M1 divisor */
140+
pll_div &= DSI_PLL_M1_DIV_MASK;
141+
pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
142+
143+
while (pll_ctl) {
144+
pll_ctl = pll_ctl >> 1;
145+
p++;
146+
}
147+
p--;
148+
149+
if (!p) {
150+
drm_err(&dev_priv->drm, "wrong P1 divisor\n");
151+
return 0;
152+
}
153+
154+
for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
155+
if (lfsr_converts[i] == pll_div)
156+
break;
157+
}
158+
159+
if (i == ARRAY_SIZE(lfsr_converts)) {
160+
drm_err(&dev_priv->drm, "wrong m_seed programmed\n");
161+
return 0;
162+
}
163+
164+
m = i + 62;
165+
166+
dsi_clock = (m * refclk) / (p * n);
167+
168+
return DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, bpp);
169+
}
170+
116171
/*
117172
* XXX: The muxing and gating is hard coded for now. Need to add support for
118173
* sharing PLLs with two DSI outputs.
@@ -262,13 +317,7 @@ u32 vlv_dsi_get_pclk(struct intel_encoder *encoder,
262317
struct intel_crtc_state *config)
263318
{
264319
struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
265-
struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
266-
int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
267-
u32 dsi_clock, pclk;
268320
u32 pll_ctl, pll_div;
269-
u32 m = 0, p = 0, n;
270-
int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
271-
int i;
272321

273322
drm_dbg_kms(&dev_priv->drm, "\n");
274323

@@ -280,65 +329,31 @@ u32 vlv_dsi_get_pclk(struct intel_encoder *encoder,
280329
config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK;
281330
config->dsi_pll.div = pll_div;
282331

283-
/* mask out other bits and extract the P1 divisor */
284-
pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
285-
pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
286-
287-
/* N1 divisor */
288-
n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
289-
n = 1 << n; /* register has log2(N1) */
290-
291-
/* mask out the other bits and extract the M1 divisor */
292-
pll_div &= DSI_PLL_M1_DIV_MASK;
293-
pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
294-
295-
while (pll_ctl) {
296-
pll_ctl = pll_ctl >> 1;
297-
p++;
298-
}
299-
p--;
300-
301-
if (!p) {
302-
drm_err(&dev_priv->drm, "wrong P1 divisor\n");
303-
return 0;
304-
}
305-
306-
for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
307-
if (lfsr_converts[i] == pll_div)
308-
break;
309-
}
310-
311-
if (i == ARRAY_SIZE(lfsr_converts)) {
312-
drm_err(&dev_priv->drm, "wrong m_seed programmed\n");
313-
return 0;
314-
}
315-
316-
m = i + 62;
332+
return vlv_dsi_pclk(encoder, config);
333+
}
317334

318-
dsi_clock = (m * refclk) / (p * n);
335+
static int bxt_dsi_pclk(struct intel_encoder *encoder,
336+
const struct intel_crtc_state *config)
337+
{
338+
struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
339+
int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
340+
u32 dsi_ratio, dsi_clk;
319341

320-
pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, bpp);
342+
dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
343+
dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
321344

322-
return pclk;
345+
return DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, bpp);
323346
}
324347

325348
u32 bxt_dsi_get_pclk(struct intel_encoder *encoder,
326349
struct intel_crtc_state *config)
327350
{
328-
u32 pclk;
329-
u32 dsi_clk;
330-
u32 dsi_ratio;
331-
struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
332351
struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
333-
int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
352+
u32 pclk;
334353

335354
config->dsi_pll.ctrl = intel_de_read(dev_priv, BXT_DSI_PLL_CTL);
336355

337-
dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
338-
339-
dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
340-
341-
pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, bpp);
356+
pclk = bxt_dsi_pclk(encoder, config);
342357

343358
drm_dbg(&dev_priv->drm, "Calculated pclk=%u\n", pclk);
344359
return pclk;

0 commit comments

Comments
 (0)