Skip to content

Commit d567679

Browse files
aford173vinodkoul
authored andcommitted
phy: freescale: fsl-samsung-hdmi: Clean up fld_tg_code calculation
Currently, the calcuation for fld_tg_code is based on a lookup table, but there are gaps in the lookup table, and frequencies in these gaps may not properly use the correct divider. Based on the description of FLD_CK_DIV, the internal PLL frequency should be less than 50 MHz, so directly calcuate the value of FLD_CK_DIV from pixclk. This allow for proper calcuation of any pixel clock and eliminates a few gaps in the LUT. Since the value of the int_pllclk is in Hz, do the fixed-point math in Hz to achieve a more accurate value and reduces the complexity of the caluation to 24MHz * (256 / int_pllclk). Fixes: 6ad082b ("phy: freescale: add Samsung HDMI PHY") Signed-off-by: Adam Ford <[email protected]> Reviewed-by: Frieder Schrempf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 1b9b8b1 commit d567679

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

drivers/phy/freescale/phy-fsl-samsung-hdmi.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,17 @@ fsl_samsung_hdmi_phy_configure_pll_lock_det(struct fsl_samsung_hdmi_phy *phy,
331331
{
332332
u32 pclk = cfg->pixclk;
333333
u32 fld_tg_code;
334-
u32 pclk_khz;
335-
u8 div = 1;
336-
337-
switch (cfg->pixclk) {
338-
case 22250000 ... 47500000:
339-
div = 1;
340-
break;
341-
case 50349650 ... 99000000:
342-
div = 2;
343-
break;
344-
case 100699300 ... 198000000:
345-
div = 4;
346-
break;
347-
case 205000000 ... 297000000:
348-
div = 8;
349-
break;
334+
u32 int_pllclk;
335+
u8 div;
336+
337+
/* Find int_pllclk speed */
338+
for (div = 0; div < 4; div++) {
339+
int_pllclk = pclk / (1 << div);
340+
if (int_pllclk < (50 * MHZ))
341+
break;
350342
}
351343

352-
writeb(FIELD_PREP(REG12_CK_DIV_MASK, ilog2(div)), phy->regs + PHY_REG(12));
344+
writeb(FIELD_PREP(REG12_CK_DIV_MASK, div), phy->regs + PHY_REG(12));
353345

354346
/*
355347
* Calculation for the frequency lock detector target code (fld_tg_code)
@@ -362,10 +354,8 @@ fsl_samsung_hdmi_phy_configure_pll_lock_det(struct fsl_samsung_hdmi_phy *phy,
362354
* settings rounding up always too. TODO: Check if that is
363355
* correct.
364356
*/
365-
pclk /= div;
366-
pclk_khz = pclk / 1000;
367-
fld_tg_code = 256 * 1000 * 1000 / pclk_khz * 24;
368-
fld_tg_code = DIV_ROUND_UP(fld_tg_code, 1000);
357+
358+
fld_tg_code = DIV_ROUND_UP(24 * MHZ * 256, int_pllclk);
369359

370360
/* FLD_TOL and FLD_RP_CODE taken from downstream driver */
371361
writeb(FIELD_PREP(REG13_TG_CODE_LOW_MASK, fld_tg_code),

0 commit comments

Comments
 (0)