Skip to content

Commit f23fe4d

Browse files
committed
drm/i915/cdclk: Rewrite cdclk->voltage_level selection to use tables
The cdclk->voltage_level if ladders are hard to read, especially as they're written the other way around compared to how bspec lists the limits. Let's rewrite them to use simple arrays that gives us the max cdclk for each voltage level. v2: Bump the jsl/ehl max cdclk in the table to 652.8 MHz to accommodate JSL machines in CI that boot with high cdclk Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20231211221759.29725-1-ville.syrjala@linux.intel.com
1 parent e1a914a commit f23fe4d

1 file changed

Lines changed: 57 additions & 30 deletions

File tree

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

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,50 +1446,77 @@ static u8 bxt_calc_voltage_level(int cdclk)
14461446
return DIV_ROUND_UP(cdclk, 25000);
14471447
}
14481448

1449+
static u8 calc_voltage_level(int cdclk, int num_voltage_levels,
1450+
const int voltage_level_max_cdclk[])
1451+
{
1452+
int voltage_level;
1453+
1454+
for (voltage_level = 0; voltage_level < num_voltage_levels; voltage_level++) {
1455+
if (cdclk <= voltage_level_max_cdclk[voltage_level])
1456+
return voltage_level;
1457+
}
1458+
1459+
MISSING_CASE(cdclk);
1460+
return num_voltage_levels - 1;
1461+
}
1462+
14491463
static u8 icl_calc_voltage_level(int cdclk)
14501464
{
1451-
if (cdclk > 556800)
1452-
return 2;
1453-
else if (cdclk > 312000)
1454-
return 1;
1455-
else
1456-
return 0;
1465+
static const int icl_voltage_level_max_cdclk[] = {
1466+
[0] = 312000,
1467+
[1] = 556800,
1468+
[2] = 652800,
1469+
};
1470+
1471+
return calc_voltage_level(cdclk,
1472+
ARRAY_SIZE(icl_voltage_level_max_cdclk),
1473+
icl_voltage_level_max_cdclk);
14571474
}
14581475

14591476
static u8 ehl_calc_voltage_level(int cdclk)
14601477
{
1461-
if (cdclk > 326400)
1462-
return 3;
1463-
else if (cdclk > 312000)
1464-
return 2;
1465-
else if (cdclk > 180000)
1466-
return 1;
1467-
else
1468-
return 0;
1478+
static const int ehl_voltage_level_max_cdclk[] = {
1479+
[0] = 180000,
1480+
[1] = 312000,
1481+
[2] = 326400,
1482+
/*
1483+
* Bspec lists the limit as 556.8 MHz, but some JSL
1484+
* development boards (at least) boot with 652.8 MHz
1485+
*/
1486+
[3] = 652800,
1487+
};
1488+
1489+
return calc_voltage_level(cdclk,
1490+
ARRAY_SIZE(ehl_voltage_level_max_cdclk),
1491+
ehl_voltage_level_max_cdclk);
14691492
}
14701493

14711494
static u8 tgl_calc_voltage_level(int cdclk)
14721495
{
1473-
if (cdclk > 556800)
1474-
return 3;
1475-
else if (cdclk > 326400)
1476-
return 2;
1477-
else if (cdclk > 312000)
1478-
return 1;
1479-
else
1480-
return 0;
1496+
static const int tgl_voltage_level_max_cdclk[] = {
1497+
[0] = 312000,
1498+
[1] = 326400,
1499+
[2] = 556800,
1500+
[3] = 652800,
1501+
};
1502+
1503+
return calc_voltage_level(cdclk,
1504+
ARRAY_SIZE(tgl_voltage_level_max_cdclk),
1505+
tgl_voltage_level_max_cdclk);
14811506
}
14821507

14831508
static u8 rplu_calc_voltage_level(int cdclk)
14841509
{
1485-
if (cdclk > 556800)
1486-
return 3;
1487-
else if (cdclk > 480000)
1488-
return 2;
1489-
else if (cdclk > 312000)
1490-
return 1;
1491-
else
1492-
return 0;
1510+
static const int rplu_voltage_level_max_cdclk[] = {
1511+
[0] = 312000,
1512+
[1] = 480000,
1513+
[2] = 556800,
1514+
[3] = 652800,
1515+
};
1516+
1517+
return calc_voltage_level(cdclk,
1518+
ARRAY_SIZE(rplu_voltage_level_max_cdclk),
1519+
rplu_voltage_level_max_cdclk);
14931520
}
14941521

14951522
static void icl_readout_refclk(struct drm_i915_private *dev_priv,

0 commit comments

Comments
 (0)