Skip to content

Commit 8208181

Browse files
aford173abelvesa
authored andcommitted
clk: imx: composite-8m: Add imx8m_divider_determine_rate
Currently, certain clocks are derrived as a divider from their parent clock. For some clocks, even when CLK_SET_RATE_PARENT is set, the parent clock is not properly set which can lead to some relatively inaccurate clock values. Unlike imx/clk-composite-93 and imx/clk-divider-gate, it cannot rely on calling a standard determine_rate function, because the 8m composite clocks have a pre-divider and post-divider. Because of this, a custom determine_rate function is necessary to determine the maximum clock division which is equivalent to pre-divider * the post-divider. With this added, the system can attempt to adjust the parent rate when the proper flags are set which can lead to a more precise clock value. On the imx8mplus, no clock changes are present. On the Mini and Nano, this can help achieve more accurate lcdif clocks. When trying to get a pixel clock of 31.500MHz on an imx8m Nano, the clocks divided the 594MHz down, but left the parent rate untouched which caused a calulation error. Before: video_pll 594000000 video_pll_bypass 594000000 video_pll_out 594000000 disp_pixel 31263158 disp_pixel_clk 31263158 Variance = -236842 Hz After this patch: video_pll 31500000 video_pll_bypass 31500000 video_pll_out 31500000 disp_pixel 31500000 disp_pixel_clk 31500000 Variance = 0 Hz All other clocks rates and parent were the same. Similar results on imx8mm were found. Fixes: 690dccc ("Revert "clk: imx: composite-8m: Add support to determine_rate"") Signed-off-by: Adam Ford <[email protected]> Reviewed-by: Abel Vesa <[email protected]> Tested-by: Fabio Estevam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Abel Vesa <[email protected]>
1 parent 632c60e commit 8208181

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

drivers/clk/imx/clk-composite-8m.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,41 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
119119
return ret;
120120
}
121121

122+
static int imx8m_divider_determine_rate(struct clk_hw *hw,
123+
struct clk_rate_request *req)
124+
{
125+
struct clk_divider *divider = to_clk_divider(hw);
126+
int prediv_value;
127+
int div_value;
128+
129+
/* if read only, just return current value */
130+
if (divider->flags & CLK_DIVIDER_READ_ONLY) {
131+
u32 val;
132+
133+
val = readl(divider->reg);
134+
prediv_value = val >> divider->shift;
135+
prediv_value &= clk_div_mask(divider->width);
136+
prediv_value++;
137+
138+
div_value = val >> PCG_DIV_SHIFT;
139+
div_value &= clk_div_mask(PCG_DIV_WIDTH);
140+
div_value++;
141+
142+
return divider_ro_determine_rate(hw, req, divider->table,
143+
PCG_PREDIV_WIDTH + PCG_DIV_WIDTH,
144+
divider->flags, prediv_value * div_value);
145+
}
146+
147+
return divider_determine_rate(hw, req, divider->table,
148+
PCG_PREDIV_WIDTH + PCG_DIV_WIDTH,
149+
divider->flags);
150+
}
151+
122152
static const struct clk_ops imx8m_clk_composite_divider_ops = {
123153
.recalc_rate = imx8m_clk_composite_divider_recalc_rate,
124154
.round_rate = imx8m_clk_composite_divider_round_rate,
125155
.set_rate = imx8m_clk_composite_divider_set_rate,
156+
.determine_rate = imx8m_divider_determine_rate,
126157
};
127158

128159
static u8 imx8m_clk_composite_mux_get_parent(struct clk_hw *hw)

0 commit comments

Comments
 (0)