Skip to content

Commit 46a8726

Browse files
aford173vinodkoul
authored andcommitted
phy: freescale: fsl-samsung-hdmi: Improve LUT search for best clock
Searching the look-up-table runs so long as the frequency in the table is at or below the desired rate. This works well in most cases, but the next entry in the LUT might be closer to the nominal value than the lower one. Add some logic to check the higer value is any closer to the nominal value and use it. Signed-off-by: Adam Ford <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 41db462 commit 46a8726

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,14 @@ static const struct phy_config *fsl_samsung_hdmi_phy_lookup_rate(unsigned long r
510510
if (phy_pll_cfg[i].pixclk <= rate)
511511
break;
512512

513-
return &phy_pll_cfg[i];
513+
/* If there is an exact match, or the array has been searched, return the value*/
514+
if (phy_pll_cfg[i].pixclk == rate || i + 1 > ARRAY_SIZE(phy_pll_cfg) - 1)
515+
return &phy_pll_cfg[i];
516+
517+
/* See if the next entry is closer to nominal than this one */
518+
return (abs((long) rate - (long) phy_pll_cfg[i].pixclk) <
519+
abs((long) rate - (long) phy_pll_cfg[i+1].pixclk) ?
520+
&phy_pll_cfg[i] : &phy_pll_cfg[i+1]);
514521
}
515522

516523
static void fsl_samsung_hdmi_calculate_phy(struct phy_config *cal_phy, unsigned long rate,

0 commit comments

Comments
 (0)