clk: rockchip: rk3399: add 85.5 MHz rate to PLL rate table
Subsystems (5)
PATCH 1/2 clk: rockchip: rk3399: add 85.5 MHz rate to PLL rate table
85.5 MHz is the pixel clock of the standard DMT 1366x768@60 mode, which is the native mode of many cheap HDMI panels.
Use a 1368 MHz VCO (24 MHz * 57, already used by the existing 1368 MHz entry) with postdiv1 = postdiv2 = 4 to hit 85.5 MHz exactly in integer mode.
--- drivers/clk/rockchip/clk-rk3399.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/rockchip/clk-rk3399.c +1 -0
@@ -98,6 +98,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = {RK3036_PLL_RATE (148500000 ,1 ,99 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (106500000 ,1 ,71 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (96000000 ,1 ,64 ,4 ,4 ,1 ,0 ), +RK3036_PLL_RATE (85500000 ,1 ,57 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (74250000 ,2 ,99 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (65000000 ,1 ,65 ,6 ,4 ,1 ,0 ), RK3036_PLL_RATE( 54000000, 1, 54, 6, 4, 1, 0),
Signature · 1 line
2.55.0
PATCH 2/2 drm/rockchip: vop: don't round the pixel clock when the encoder owns the PLL
On RK3399 the HDMI reference clock is VPLL, a dedicated PLL that is a parent of the VOP dclk. dw_hdmi_rockchip_mode_valid() accepts a mode only if VPLL can produce its pixel clock, and encoder mode_set() then programs VPLL to that rate. However vop_crtc_mode_fixup() ran first, in the check phase, and rounded adjusted_mode->clock through clk_round_rate() on the dclk. At that point VPLL still sits at its previous rate, so the dclk composite picks whichever of VPLL/CPLL/GPLL gets closest at its *current* rate and stores that inexact value.
For 1366x768 (85.5 MHz) this yields GPLL/7 = 84.857 MHz. mode_set() then requests 84.857 MHz from VPLL, which the PLL rate table snaps down to 74.25 MHz, and the VOP ends up on GPLL/7. The panel receives a timing 0.75% slow, which some monitors misdetect (e.g. as 1195x768) and display distorted. Only modes whose clock happens to be an exact GPLL or CPLL fraction (74.25, 148.5, 297 MHz, ...) were unaffected.
Let the encoder tell the CRTC, via a new rockchip_crtc_state flag set in its atomic_check, that it will program a dedicated dclk parent to exactly the requested pixel clock. Move the rounding from mode_fixup to atomic_check, which runs after the encoder's atomic_check as recommended by the DRM documentation, and skip it when the flag is set. With VPLL then set to the exact rate before the VOP enables, clk_set_rate() on the dclk finds an exact match on VPLL.
The flag is only meaningful within the check that sets it and is cleared when the state is duplicated, so it cannot leak into a later modeset on the same CRTC with a different encoder. Behaviour for encoders without a dedicated PLL is unchanged.
--- drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c | 8 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 9 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 25 +++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +7 -1
@@ -300,8 +300,8 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder,struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { - struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); struct rockchip_hdmi *hdmi = to_rockchip_hdmi(encoder); +struct rockchip_crtc_state *s =to_rockchip_crtc_state (crtc_state);union phy_configure_opts opts = {};u32 bus_format;
@@ -327,6 +327,12 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, s->output_type =DRM_MODE_CONNECTOR_HDMIA ; s->bus_format = bus_format; +/* +* The reference clock (e.g. VPLL on RK3399) is a parent of the VOP +* dclk, and mode_set() programs it to the pixel clock, which +* mode_valid() already guaranteed it can produce. +*/ + s->dclk_exact = !!hdmi->ref_clk;if (!hdmi->phy || !conn_state->hdmi.tmds_char_rate)return 0 ;
drivers/gpu/drm/rockchip/rockchip_drm_drv.h +9 -0
@@ -57,6 +57,15 @@ struct rockchip_crtc_state {u32 bus_format;u32 bus_flags;int color_space; +/* +* Set by an encoder's atomic_check when it owns a dedicated PLL that +* feeds the CRTC's dclk and will program it to exactly +* adjusted_mode->clock at mode_set time. The CRTC must then not +* round the pixel clock against the current clock tree, which does +* not reflect that PLL's future rate. Only valid within one check, +* it is cleared when the state is duplicated. +*/ +bool dclk_exact; };#define to_rockchip_crtc_state (s) \ container_of(s, struct rockchip_crtc_state, base)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +18 -7
@@ -1207,11 +1207,9 @@ static enum drm_mode_status vop_crtc_mode_valid(struct drm_crtc *crtc,return MODE_OK ; } -static bool vop_crtc_mode_fixup (struct drm_crtc *crtc, -const struct drm_display_mode *mode, -struct drm_display_mode *adjusted_mode) +static void vop_crtc_adjust_clock (struct vop *vop, +struct drm_display_mode *adjusted_mode) { -struct vop *vop =to_vop (crtc);unsigned long rate;/*
@@ -1245,8 +1243,6 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc, rate =clk_round_rate (vop->dclk, adjusted_mode->clock *1000 +999 ); adjusted_mode->clock =DIV_ROUND_UP (rate,1000 ); - -return true; }static bool vop_dsp_lut_is_enabled (struct vop *vop)
@@ -1558,6 +1554,19 @@ static int vop_crtc_atomic_check(struct drm_crtc *crtc, s =to_rockchip_crtc_state (crtc_state); s->enable_afbc = afbc_planes >0 ; +/* +* Round the pixel clock to what the dclk can really produce, unless +* the encoder will program a dedicated dclk parent PLL to exactly +* this rate at mode_set time. In that case the clock tree seen here +* (with that PLL still at its old rate) would pick a worse, inexact +* source and bake that rate into adjusted_mode, defeating the PLL. +* +* Same condition the atomic helpers use for the mode_fixup callback. +*/ +if ((crtc_state->mode_changed || crtc_state->connectors_changed) && + !s->dclk_exact) +vop_crtc_adjust_clock (vop, &crtc_state->adjusted_mode); +return 0 ; }
@@ -1623,7 +1632,6 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc,static const struct drm_crtc_helper_funcs vop_crtc_helper_funcs = { .mode_valid = vop_crtc_mode_valid, - .mode_fixup = vop_crtc_mode_fixup, .atomic_check = vop_crtc_atomic_check, .atomic_begin = vop_crtc_atomic_begin, .atomic_flush = vop_crtc_atomic_flush,
@@ -1643,6 +1651,9 @@ static struct drm_crtc_state *vop_crtc_duplicate_state(struct drm_crtc *crtc)if (!rockchip_state)return NULL ; +/* Only valid within the check phase that sets it. */ + rockchip_state->dclk_exact = false; +__drm_atomic_helper_crtc_duplicate_state (crtc, &rockchip_state->base);return &rockchip_state->base; }
Signature · 1 line
2.55.0
Re: [PATCH 2/2] drm/rockchip: vop: don't round the pixel clock when the encoder owns the PLL
Hello Vasily,
Quoted 9 lines · Vasily Khoruzhick
On RK3399 the HDMI reference clock is VPLL, a dedicated PLL that is a parent of the VOP dclk.
dw_hdmi_rockchip_mode_valid()accepts a mode only if VPLL can produce its pixel clock, and encodermode_set()then programs VPLL to that rate. Howevervop_crtc_mode_fixup()ran first, in the check phase, and roundedadjusted_mode->clockthroughclk_round_rate()on the dclk. At that point VPLL still sits at its previous rate, so the dclk composite picks whichever of VPLL/CPLL/GPLL gets closest at its *current* rate and stores that inexact value.
Why did vop_crtc_mode_fixup() run first? Within drm_atomic_helper_check_modeset(), mode_valid() is executed before mode_fixup().
Quoted 7 lines
For 1366x768 (85.5 MHz) this yields GPLL/7 = 84.857 MHz.
mode_set()then requests 84.857 MHz from VPLL, which the PLL rate table snaps down to 74.25 MHz, and the VOP ends up on GPLL/7. The panel receives a timing 0.75% slow, which some monitors misdetect (e.g. as 1195x768) and display distorted. Only modes whose clock happens to be an exact GPLL or CPLL fraction (74.25, 148.5, 297 MHz, ...) were unaffected.
Did you designate VPLL as the parent clock of the VOP dclk in the DTS?
Quoted 36 lines
Let the encoder tell the CRTC, via a new
rockchip_crtc_stateflag set in itsatomic_check, that it will program a dedicated dclk parent to exactly the requested pixel clock. Move the rounding frommode_fixuptoatomic_check, which runs after the encoder'satomic_checkas recommended by the DRM documentation, and skip it when the flag is set. With VPLL then set to the exact rate before the VOP enables,clk_set_rate()on the dclk finds an exact match on VPLL.The flag is only meaningful within the check that sets it and is cleared when the state is duplicated, so it cannot leak into a later modeset on the same CRTC with a different encoder. Behaviour for encoders without a dedicated PLL is unchanged.
Assisted-by Claude:claude-fable-5Signed-off-by Vasily Khoruzhick <[email protected]>--- drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c | 8 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 9 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 25 +++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-)drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +1
-1@@ -300,8 +300,8 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder,struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { - struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); struct rockchip_hdmi *hdmi = to_rockchip_hdmi(encoder); +struct rockchip_crtc_state *s =to_rockchip_crtc_state (crtc_state);union phy_configure_opts opts = {};u32 bus_format;
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, · line 336
Quoted 10 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +6
-0@@ -327,6 +327,12 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, s->output_type =DRM_MODE_CONNECTOR_HDMIA ; s->bus_format = bus_format; +/* +* The reference clock (e.g. VPLL on RK3399) is a parent of the VOP +* dclk, and mode_set() programs it to the pixel clock, which +* mode_valid() already guaranteed it can produce. +*/ + s->dclk_exact = !!hdmi->ref_clk;
What about RK3328? It uses hdmi->hdmiphy_clk.
Quoted 59 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +0
-0if (!hdmi->phy || !conn_state->hdmi.tmds_char_rate)return 0 ;drivers/gpu/drm/rockchip/rockchip_drm_drv.h +9
-0@@ -57,6 +57,15 @@ struct rockchip_crtc_state {u32 bus_format;u32 bus_flags;int color_space; +/* +* Set by an encoder's atomic_check when it owns a dedicated PLL that +* feeds the CRTC's dclk and will program it to exactly +* adjusted_mode->clock at mode_set time. The CRTC must then not +* round the pixel clock against the current clock tree, which does +* not reflect that PLL's future rate. Only valid within one check, +* it is cleared when the state is duplicated. +*/ +bool dclk_exact; };#define to_rockchip_crtc_state (s) \ container_of(s, struct rockchip_crtc_state, base)drivers/gpu/drm/rockchip/rockchip_drm_vop.c +8
-6@@ -1207,11 +1207,9 @@ static enum drm_mode_status vop_crtc_mode_valid(struct drm_crtc *crtc,return MODE_OK ; } -static bool vop_crtc_mode_fixup (struct drm_crtc *crtc, -const struct drm_display_mode *mode, -struct drm_display_mode *adjusted_mode) +static void vop_crtc_adjust_clock (struct vop *vop, +struct drm_display_mode *adjusted_mode) { -struct vop *vop =to_vop (crtc);unsigned long rate;/* @@ -1245,8 +1243,6 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc, rate =clk_round_rate (vop->dclk, adjusted_mode->clock *1000 +999 ); adjusted_mode->clock =DIV_ROUND_UP (rate,1000 ); - -return true; }static bool vop_dsp_lut_is_enabled (struct vop *vop)@@ -1558,6 +1554,19 @@ static int vop_crtc_atomic_check(struct drm_crtc *crtc, s =to_rockchip_crtc_state (crtc_state); s->enable_afbc = afbc_planes >0 ; +/* +* Round the pixel clock to what the dclk can really produce, unless +* the encoder will program a dedicated dclk parent PLL to exactly +* this rate at mode_set time. In that case the clock tree seen here +* (with that PLL still at its old rate) would pick a worse, inexact +* source and bake that rate into adjusted_mode, defeating the PLL.
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_crtc_atomic_check(struct drm_crtc *crtc, · line 1572
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +7
-0+* +* Same condition the atomic helpers use for the mode_fixup callback. +*/ +if ((crtc_state->mode_changed || crtc_state->connectors_changed) && + !s->dclk_exact) +vop_crtc_adjust_clock (vop, &crtc_state->adjusted_mode); +return 0 ; }
What about other display interfaces? For example, the .mode_fixup corresponding to cdn-dp will not be called.
Quoted 18 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +3
-1@@ -1623,7 +1632,6 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc,static const struct drm_crtc_helper_funcs vop_crtc_helper_funcs = { .mode_valid = vop_crtc_mode_valid, - .mode_fixup = vop_crtc_mode_fixup, .atomic_check = vop_crtc_atomic_check, .atomic_begin = vop_crtc_atomic_begin, .atomic_flush = vop_crtc_atomic_flush,@@ -1643,6 +1651,9 @@ static struct drm_crtc_state *vop_crtc_duplicate_state(struct drm_crtc *crtc)if (!rockchip_state)return NULL ; +/* Only valid within the check phase that sets it. */ + rockchip_state->dclk_exact = false; +__drm_atomic_helper_crtc_duplicate_state (crtc, &rockchip_state->base);return &rockchip_state->base; }
Signature · 2 lines
Best, Chaoyi
Re: [PATCH 2/2] drm/rockchip: vop: don't round the pixel clock when the encoder owns the PLL
Quoted 2 lines · Chaoyi Chen
Hello Vasily,
Hi Chaoyi,
Quoted 11 lines · Vasily Khoruzhick
Quoted 9 lines
On RK3399 the HDMI reference clock is VPLL, a dedicated PLL that is a parent of the VOP dclk.
dw_hdmi_rockchip_mode_valid()accepts a mode only if VPLL can produce its pixel clock, and encodermode_set()then programs VPLL to that rate. Howevervop_crtc_mode_fixup()ran first, in the check phase, and roundedadjusted_mode->clockthroughclk_round_rate()on the dclk. At that point VPLL still sits at its previous rate, so the dclk composite picks whichever of VPLL/CPLL/GPLL gets closest at its *current* rate and stores that inexact value.
Quoted 2 lines
Why did
vop_crtc_mode_fixup()run first? Withindrm_atomic_helper_check_modeset(),mode_valid()is executed beforemode_fixup().
Sorry, ambiguous wording on my part - "first" meant before the encoder's mode_set() programs the VPLL, not before mode_valid(). The order is as you say, and that's exactly the problem: mode_valid() rounds the pixel clock on the ref clock (the VPLL itself), whose rate table can produce 85.5 MHz, so the mode is accepted. mode_fixup() however rounds on the dclk composite - a different clock - which evaluates its mux parents at their current rates. During check the VPLL still runs at the previous mode's rate, so GPLL/7 = 84.857 MHz wins and gets stored in adjusted_mode->clock. mode_set() then programs the VPLL to that corrupted value in the commit phase. I can reword the commit message to make this clearer.
Quoted 9 lines
Quoted 7 lines
For 1366x768 (85.5 MHz) this yields GPLL/7 = 84.857 MHz.
mode_set()then requests 84.857 MHz from VPLL, which the PLL rate table snaps down to 74.25 MHz, and the VOP ends up on GPLL/7. The panel receives a timing 0.75% slow, which some monitors misdetect (e.g. as 1195x768) and display distorted. Only modes whose clock happens to be an exact GPLL or CPLL fraction (74.25, 148.5, 297 MHz, ...) were unaffected.Did you designate VPLL as the parent clock of the VOP dclk in the DTS?
No, and it isn't needed: in the commit phase the encoder's atomic_mode_set() sets the VPLL to exactly the pixel clock before vop_crtc_atomic_enable() sets the dclk (mode-set runs before enables in the atomic helpers), so by then the dclk composite finds vpll/1 as an exact match and the mux selects VPLL by itself. Verified via clk_summary on the patched kernel: vpll = 85500000 feeding dclk_vop0 = 85500000. Pinning the parent in DT also wouldn't have fixed the bug - without CLK_SET_RATE_PARENT the check-phase clk_round_rate() against the still-stale VPLL would return the same wrong value.
See clk_summary for broken and working cases attached.
Quoted 13 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, · line 336
Quoted 11 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +6
-0@@ -327,6 +327,12 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, s->output_type =DRM_MODE_CONNECTOR_HDMIA ; s->bus_format = bus_format; +/* +* The reference clock (e.g. VPLL on RK3399) is a parent of the VOP +* dclk, and mode_set() programs it to the pixel clock, which +* mode_valid() already guaranteed it can produce. +*/ + s->dclk_exact = !!hdmi->ref_clk;What about RK3328? It uses
hdmi->hdmiphy_clk.
RK3328 clock ownership is the inverse of RK3399's. hdmiphy_clk is only ever consulted (in mode_valid()); the encoder's mode_set() programs just ref_clk, which is NULL on RK3328, so the encoder never sets the PHY PLL - the promise dclk_exact expresses ("the encoder will program this rate itself at mode_set time") wouldn't be true there.
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +11
-0static bool vop_dsp_lut_is_enabled (struct vop *vop)@@ -1558,6 +1554,19 @@ static int vop_crtc_atomic_check(struct drm_crtc *crtc, s =to_rockchip_crtc_state (crtc_state); s->enable_afbc = afbc_planes >0 ; +/* +* Round the pixel clock to what the dclk can really produce, unless +* the encoder will program a dedicated dclk parent PLL to exactly +* this rate at mode_set time. In that case the clock tree seen here +* (with that PLL still at its old rate) would pick a worse, inexact +* source and bake that rate into adjusted_mode, defeating the PLL. +* +* Same condition the atomic helpers use for the mode_fixup callback. +*/ +if ((crtc_state->mode_changed || crtc_state->connectors_changed) && + !s->dclk_exact)
Quoted 8 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_crtc_atomic_check(struct drm_crtc *crtc, · line 1572
Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +2
-0+vop_crtc_adjust_clock (vop, &crtc_state->adjusted_mode); +return 0 ; }What about other display interfaces? For example, the .mode_fixup corresponding to cdn-dp will not be called.
The rounding still runs for cdn-dp and all other interfaces: it moved into vop_crtc_atomic_check(), which is a CRTC callback and is invoked by drm_atomic_helper_check() regardless of the attached encoder - same as the old CRTC-level .mode_fixup was.
Regards,
Vasily
Re: [PATCH 2/2] drm/rockchip: vop: don't round the pixel clock when the encoder owns the PLL
Hello Vasily,
Quoted 20 lines · Vasily Khoruzhick
Quoted 2 lines · Chaoyi Chen
Hello Vasily,
Hi Chaoyi,
Quoted 11 lines · Vasily Khoruzhick
Quoted 9 lines
On RK3399 the HDMI reference clock is VPLL, a dedicated PLL that is a parent of the VOP dclk.
dw_hdmi_rockchip_mode_valid()accepts a mode only if VPLL can produce its pixel clock, and encodermode_set()then programs VPLL to that rate. Howevervop_crtc_mode_fixup()ran first, in the check phase, and roundedadjusted_mode->clockthroughclk_round_rate()on the dclk. At that point VPLL still sits at its previous rate, so the dclk composite picks whichever of VPLL/CPLL/GPLL gets closest at its *current* rate and stores that inexact value.Quoted 2 lines
Why did
vop_crtc_mode_fixup()run first? Withindrm_atomic_helper_check_modeset(),mode_valid()is executed beforemode_fixup().
Quoted 12 lines
Sorry, ambiguous wording on my part - "first" meant before the encoder's
mode_set()programs the VPLL, not beforemode_valid(). The order is as you say, and that's exactly the problem:mode_valid()rounds the pixel clock on the ref clock (the VPLL itself), whose rate table can produce 85.5 MHz, so the mode is accepted.mode_fixup()however rounds on the dclk composite - a different clock - which evaluates its mux parents at their current rates. During check the VPLL still runs at the previous mode's rate, so GPLL/7 = 84.857 MHz wins and gets stored inadjusted_mode->clock.mode_set()then programs the VPLL to that corrupted value in the commit phase. I can reword the commit message to make this clearer.
I think I understand your point now. The encoder's mode_fixup() yields 85.5 MHz, while the CRTC's mode_fixup() yields 84.857 MHz. The patch effectively bypasses the CRTC mode_fixup(), so that both the encoder's mode_set() and the CRTC's atomic_enable() clk_set_rate() end up using 85.5 MHz. I think it's worth mentioning this in the commit message.
Quoted 36 lines
Quoted 9 lines
Quoted 7 lines
For 1366x768 (85.5 MHz) this yields GPLL/7 = 84.857 MHz.
mode_set()then requests 84.857 MHz from VPLL, which the PLL rate table snaps down to 74.25 MHz, and the VOP ends up on GPLL/7. The panel receives a timing 0.75% slow, which some monitors misdetect (e.g. as 1195x768) and display distorted. Only modes whose clock happens to be an exact GPLL or CPLL fraction (74.25, 148.5, 297 MHz, ...) were unaffected.Did you designate VPLL as the parent clock of the VOP dclk in the DTS?
No, and it isn't needed: in the commit phase the encoder's
atomic_mode_set()sets the VPLL to exactly the pixel clock beforevop_crtc_atomic_enable()sets the dclk (mode-set runs before enables in the atomic helpers), so by then the dclk composite finds vpll/1 as an exact match and the mux selects VPLL by itself. Verified viaclk_summaryon the patched kernel: vpll = 85500000 feedingdclk_vop0= 85500000. Pinning the parent in DT also wouldn't have fixed the bug - withoutCLK_SET_RATE_PARENTthe check-phaseclk_round_rate()against the still-stale VPLL would return the same wrong value.See
clk_summaryfor broken and working cases attached.Quoted 13 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, · line 336
Quoted 11 lines
drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +6
-0@@ -327,6 +327,12 @@ dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder, s->output_type =DRM_MODE_CONNECTOR_HDMIA ; s->bus_format = bus_format; +/* +* The reference clock (e.g. VPLL on RK3399) is a parent of the VOP +* dclk, and mode_set() programs it to the pixel clock, which +* mode_valid() already guaranteed it can produce. +*/ + s->dclk_exact = !!hdmi->ref_clk;What about RK3328? It uses
hdmi->hdmiphy_clk.
Quoted 6 lines
RK3328 clock ownership is the inverse of RK3399's.
hdmiphy_clkis only ever consulted (inmode_valid()); the encoder'smode_set()programs justref_clk, which is NULL on RK3328, so the encoder never sets the PHY PLL - the promisedclk_exactexpresses ("the encoder will program this rate itself atmode_settime") wouldn't be true there.
Given the complexity of clock trees across different platforms, I think a better approach would be to implement functions like rockchip_drm_dclk_round_rate() and rockchip_drm_dclk_set_rate(), which properly configure the parent clock to meet the frequency requirements. Of course, the current approach is okay for me. :)
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +11
-0static bool vop_dsp_lut_is_enabled (struct vop *vop)@@ -1558,6 +1554,19 @@ static int vop_crtc_atomic_check(struct drm_crtc *crtc, s =to_rockchip_crtc_state (crtc_state); s->enable_afbc = afbc_planes >0 ; +/* +* Round the pixel clock to what the dclk can really produce, unless +* the encoder will program a dedicated dclk parent PLL to exactly +* this rate at mode_set time. In that case the clock tree seen here +* (with that PLL still at its old rate) would pick a worse, inexact +* source and bake that rate into adjusted_mode, defeating the PLL. +* +* Same condition the atomic helpers use for the mode_fixup callback. +*/ +if ((crtc_state->mode_changed || crtc_state->connectors_changed) && + !s->dclk_exact)Quoted 8 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_crtc_atomic_check(struct drm_crtc *crtc, · line 1572
Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +2
-0+vop_crtc_adjust_clock (vop, &crtc_state->adjusted_mode); +return 0 ; }What about other display interfaces? For example, the .mode_fixup corresponding to cdn-dp will not be called.
Quoted 5 lines
The rounding still runs for cdn-dp and all other interfaces: it moved into
vop_crtc_atomic_check(), which is a CRTC callback and is invoked bydrm_atomic_helper_check()regardless of the attached encoder - same as the old CRTC-level .mode_fixup was.
I still don't quite understand why we need to move this to CRTC atomic_check(). What's wrong with checking !s->dclk_exact in CRTC mode_fixup()? Thanks.
Quoted 2 lines
Regards,
Vasily
Signature · 2 lines
Best, Chaoyi
Hi Vasily,
Quoted 19 lines · Vasily Khoruzhick
85.5 MHz is the pixel clock of the standard DMT 1366x768@60 mode, which is the native mode of many cheap HDMI panels.
Use a 1368 MHz VCO (24 MHz * 57, already used by the existing 1368 MHz entry) with postdiv1 = postdiv2 = 4 to hit 85.5 MHz exactly in integer mode.
Assisted-by Claude:claude-fable-5Signed-off-by Vasily Khoruzhick <[email protected]>--- drivers/clk/rockchip/clk-rk3399.c | 1 + 1 file changed, 1 insertion(+)drivers/clk/rockchip/clk-rk3399.c +0
-0
drivers/clk/rockchip/clk-rk3399.c static struct rockchip_pll_rate_table rk3399_pll_rates[] = { · line 101
Quoted 4 lines
drivers/clk/rockchip/clk-rk3399.c +1
-0@@ -98,6 +98,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = {RK3036_PLL_RATE (148500000 ,1 ,99 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (106500000 ,1 ,71 ,4 ,4 ,1 ,0 ),RK3036_PLL_RATE (96000000 ,1 ,64 ,4 ,4 ,1 ,0 ), + RK3036_PLL_RATE( 85500000, 1, 57, 4, 4, 1, 0),
There is already an entry for 1368000000, which is 16x your rate, and the 16x divisor should fit comfortably into the downstream clock's 8-bit divisor field. Do you really need a separate PLL rate? Have you checked what the hardware arrives at with the unmodified PLL table - e.g. via /sys/kernel/debug/clk/clk_summary?
Best regards,
Alexey
Quoted 2 lines · Alexey Charkov
Hi Vasily,
Hey Alexey,
Quoted 7 lines
Quoted 7 lines
drivers/clk/rockchip/clk-rk3399.c +0
-0@@ -98,6 +98,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = {RK3036_PLL_RATE (148500000 ,1 ,99 ,4 ,4 ,1 ,0 ), RK3036_PLL_RATE( 106500000, 1, 71, 4, 4, 1, 0),
Quoted 8 lines
drivers/clk/rockchip/clk-rk3399.c static struct rockchip_pll_rate_table rk3399_pll_rates[] = { · line 101
Quoted 2 lines
drivers/clk/rockchip/clk-rk3399.c +1
-0RK3036_PLL_RATE (96000000 ,1 ,64 ,4 ,4 ,1 ,0 ), + RK3036_PLL_RATE( 85500000, 1, 57, 4, 4, 1, 0),There is already an entry for 1368000000, which is 16x your rate, and the 16x divisor should fit comfortably into the downstream clock's 8-bit divisor field. Do you really need a separate PLL rate? Have you checked what the hardware arrives at with the unmodified PLL table - e.g. via
/sys/kernel/debug/clk/clk_summary?
See arch/arm64/boot/dts/rockchip/rk3399-base.dtsi, hdmi ref clock is wired directly to VPLL, and dw_hdmi-rockchip calls clk_set_rate() with pixel clock for ref clock, see dw_hdmi_rockchip_encoder_atomic_mode_set(). So at least in the rk3399 case VPLL is supposed to support the required pixel clock. Without the first patch 1366x768 mode with 85.5MHz pixel clock is just rejected.
Please see clk_summary attached for 1280x800 (no patches applied), broken 1366x768 (just the first patch applied), and working 1366x768 (both patches applied)
Regards,
Vasily
Quoted 23 lines · Vasily Khoruzhick
Quoted 2 lines · Alexey Charkov
Hi Vasily,
Hey Alexey,
Quoted 7 lines
Quoted 7 lines
drivers/clk/rockchip/clk-rk3399.c +0
-0@@ -98,6 +98,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = {RK3036_PLL_RATE (148500000 ,1 ,99 ,4 ,4 ,1 ,0 ), RK3036_PLL_RATE( 106500000, 1, 71, 4, 4, 1, 0),Quoted 8 lines
drivers/clk/rockchip/clk-rk3399.c static struct rockchip_pll_rate_table rk3399_pll_rates[] = { · line 101
Quoted 2 lines
drivers/clk/rockchip/clk-rk3399.c +1
-0RK3036_PLL_RATE (96000000 ,1 ,64 ,4 ,4 ,1 ,0 ), + RK3036_PLL_RATE( 85500000, 1, 57, 4, 4, 1, 0),There is already an entry for 1368000000, which is 16x your rate, and the 16x divisor should fit comfortably into the downstream clock's 8-bit divisor field. Do you really need a separate PLL rate? Have you checked what the hardware arrives at with the unmodified PLL table - e.g. via
/sys/kernel/debug/clk/clk_summary?
Quoted 6 lines
See
arch/arm64/boot/dts/rockchip/rk3399-base.dtsi, hdmi ref clock is wired directly to VPLL, and dw_hdmi-rockchip callsclk_set_rate()with pixel clock for ref clock, seedw_hdmi_rockchip_encoder_atomic_mode_set(). So at least in the rk3399 case VPLL is supposed to support the required pixel clock. Without the first patch 1366x768 mode with 85.5MHz pixel clock is just rejected.
I strongly suspect that the dtsi doesn't describe the real clock usage here. The TRM for RK3399 doesn't show any "ref" clock for HDMI, and no TRM-documented VPLL users look like anything that could connect directly to the HDMI controller.
I believe something is hardcoding the divisor (or leaving it at the power-on default) in the actual DCLK of a VOP which the HDMI controller uses, instead of modelling it properly as a mux (frac/div) feeding off VPLL via another mux - both perfectly representable in the clock framework and already envisaged in the clock driver, making the PLL table patching unnecessary.
Can you please try re-pointing the "ref" clock at DCLK_VOP0 (or 1, depending on which one your HDMI controller uses)? Your clock summary already shows that something is assigning its parent to DCLK_VOPx_DIV and the latter's parent to PLL_VPLL, so rate changes the current driver code does on VPLL propagate to the muxed and divided downstream consumer as a side-effect rather than as an actual rate request.
Best regards,
Alexey
Quoted 11 lines · Alexey Charkov
Quoted 6 lines
See
arch/arm64/boot/dts/rockchip/rk3399-base.dtsi, hdmi ref clock is wired directly to VPLL, and dw_hdmi-rockchip callsclk_set_rate()with pixel clock for ref clock, seedw_hdmi_rockchip_encoder_atomic_mode_set(). So at least in the rk3399 case VPLL is supposed to support the required pixel clock. Without the first patch 1366x768 mode with 85.5MHz pixel clock is just rejected.I strongly suspect that the dtsi doesn't describe the real clock usage here. The TRM for RK3399 doesn't show any "ref" clock for HDMI, and no TRM-documented VPLL users look like anything that could connect directly to the HDMI controller.
See "1.1.11 HDMI Interface", it explicitly mentions 13.5–600MHz input reference clock
Quoted 7 lines
I believe something is hardcoding the divisor (or leaving it at the power-on default) in the actual DCLK of a VOP which the HDMI controller uses, instead of modelling it properly as a mux (frac/div) feeding off VPLL via another mux - both perfectly representable in the clock framework and already envisaged in the clock driver, making the PLL table patching unnecessary.
Quoted 6 lines
Can you please try re-pointing the "ref" clock at
DCLK_VOP0(or 1, depending on which one your HDMI controller uses)? Your clock summary already shows that something is assigning its parent toDCLK_VOPx_DIVand the latter's parent toPLL_VPLL, so rate changes the current driver code does on VPLL propagate to the muxed and divided downstream consumer as a side-effect rather than as an actual rate request.
I don't think it is a reasonable ask. Wrong clock for the HDMI encoder would just result in non-working HDMI output and no feasible way for me to debug what is wrong.
Regards,
Vasily
Quoted 10 lines · Vasily Khoruzhick
Quoted 7 lines · Alexey Charkov
Quoted 6 lines
See
arch/arm64/boot/dts/rockchip/rk3399-base.dtsi, hdmi ref clock is wired directly to VPLL, and dw_hdmi-rockchip callsclk_set_rate()with pixel clock for ref clock, seedw_hdmi_rockchip_encoder_atomic_mode_set(). So at least in the rk3399 case VPLL is supposed to support the required pixel clock. Without the first patch 1366x768 mode with 85.5MHz pixel clock is just rejected.
Quoted 7 lines
Quoted 4 lines
I strongly suspect that the dtsi doesn't describe the real clock usage here. The TRM for RK3399 doesn't show any "ref" clock for HDMI, and no TRM-documented VPLL users look like anything that could connect directly to the HDMI controller.
See "1.1.11 HDMI Interface", it explicitly mentions 13.5–600MHz input reference clock
Which matches the pixel clock (dclk) range for HDMI 2.0, so nothing is disproven yet
Quoted 14 lines
Quoted 7 lines
I believe something is hardcoding the divisor (or leaving it at the power-on default) in the actual DCLK of a VOP which the HDMI controller uses, instead of modelling it properly as a mux (frac/div) feeding off VPLL via another mux - both perfectly representable in the clock framework and already envisaged in the clock driver, making the PLL table patching unnecessary.
Quoted 6 lines
Can you please try re-pointing the "ref" clock at
DCLK_VOP0(or 1, depending on which one your HDMI controller uses)? Your clock summary already shows that something is assigning its parent toDCLK_VOPx_DIVand the latter's parent toPLL_VPLL, so rate changes the current driver code does on VPLL propagate to the muxed and divided downstream consumer as a side-effect rather than as an actual rate request.
Quoted 3 lines
I don't think it is a reasonable ask. Wrong clock for the HDMI encoder would just result in non-working HDMI output and no feasible way for me to debug what is wrong.
Hope you have a serial console or ssh connection to the board. If it doesn't work you'll know soon enough.
What I'm pointing out is that the clock setup implied by the current dtsi doesn't make much sense: VOP's dclk is driven off VPLL via a mux and divisor. If the encoder's pixel clock is truly driven directly off VPLL then Rockchip designed the muxes and dividers for nothing, as they will always be no-ops. This doesn't square, so something must be wrong, and I believe it's the dtsi.
I'll be happy to be proven wrong here.
Best regards,
Alexey
Quoted 21 lines · Alexey Charkov
Quoted 14 lines
Quoted 7 lines
I believe something is hardcoding the divisor (or leaving it at the power-on default) in the actual DCLK of a VOP which the HDMI controller uses, instead of modelling it properly as a mux (frac/div) feeding off VPLL via another mux - both perfectly representable in the clock framework and already envisaged in the clock driver, making the PLL table patching unnecessary.
Quoted 6 lines
Can you please try re-pointing the "ref" clock at
DCLK_VOP0(or 1, depending on which one your HDMI controller uses)? Your clock summary already shows that something is assigning its parent toDCLK_VOPx_DIVand the latter's parent toPLL_VPLL, so rate changes the current driver code does on VPLL propagate to the muxed and divided downstream consumer as a side-effect rather than as an actual rate request.Quoted 3 lines
I don't think it is a reasonable ask. Wrong clock for the HDMI encoder would just result in non-working HDMI output and no feasible way for me to debug what is wrong.
Hope you have a serial console or ssh connection to the board. If it doesn't work you'll know soon enough.
Quoted 8 lines
What I'm pointing out is that the clock setup implied by the current dtsi doesn't make much sense: VOP's dclk is driven off VPLL via a mux and divisor. If the encoder's pixel clock is truly driven directly off VPLL then Rockchip designed the muxes and dividers for nothing, as they will always be no-ops. This doesn't square, so something must be wrong, and I believe it's the dtsi.
I'll be happy to be proven wrong here.
Hey Alexey,
Sorry for the long delay - NVMe in my laptop died and I had to wait for a warranty replacement to arrive. I would have bought a new one if the price wasn't ridiculous :)
The dtsi describes the hardware correctly. The HDMI PHY's reference clock input (TRM Part 1, 1.1.11: "13.5-600MHz input reference clock") is wired to VPLL with no mux or divider in between; it is not one of the CRU clocks in the TRM's clock tree at all.
That's exactly what the commit that introduced the "vpll" clock says, from Rockchip's own engineers, see 5e3bc6d1ab48 ("drm/rockchip:dw_hdmi: introduce the VPLL clock setting")
This bug report itself is a solid proof of this wiring. With VPLL left at 74.25 MHz and the VOP on GPLL/7 = 84.857 MHz, the monitor reported the mode as 1195x768. 74.25/84.857 = 0.875, and 1366 * 0.875 = 1195. The TMDS clock came from VPLL while the sync timing came from the VOP. If the PHY were clocked from the dclk mux output, that mismatch could not exist.
The mux and dividers are not for nothing: there is one VPLL and two VOPs, and each VOP can also drive eDP, MIPI DSI and DP, whose PHYs have their own PLLs. When VOPB drives HDMI from VPLL/1, VOPL has to run from CPLL or GPLL through the divider, and the fractional divider exists for DSI panels with odd pixel clocks. For HDMI the divider is legitimately 1.
This is also why the PLL table patch is needed under any scheme: the RK3399 PLL driver is table-only (rockchip_pll_determine_rate() snaps to the nearest lower table entry), and the PHY reference has to be 85.5 MHz exactly because nothing between VPLL and the PHY can divide it.
And the VOP patch doesn't hardcode a divisor. The VOP still makes a real clk_set_rate() on its dclk at enable time. The bug was ordering:mode_fixup() rounded the pixel clock through the dclk while VPLL was still at its old rate, so the composite chose GPLL/7 and the encoder then asked VPLL for 84.857 MHz, which the table snapped to 74.25 MHz. With VPLL programmed first, the composite picks VPLL with divider 1 because it is the exact match.
Regards,
Vasily
Alexey Charkov
Reviewed-byHi Vasily,
Quoted 34 lines · Vasily Khoruzhick
Quoted 21 lines · Alexey Charkov
Quoted 14 lines
Quoted 7 lines
I believe something is hardcoding the divisor (or leaving it at the power-on default) in the actual DCLK of a VOP which the HDMI controller uses, instead of modelling it properly as a mux (frac/div) feeding off VPLL via another mux - both perfectly representable in the clock framework and already envisaged in the clock driver, making the PLL table patching unnecessary.
Quoted 6 lines
Can you please try re-pointing the "ref" clock at
DCLK_VOP0(or 1, depending on which one your HDMI controller uses)? Your clock summary already shows that something is assigning its parent toDCLK_VOPx_DIVand the latter's parent toPLL_VPLL, so rate changes the current driver code does on VPLL propagate to the muxed and divided downstream consumer as a side-effect rather than as an actual rate request.Quoted 3 lines
I don't think it is a reasonable ask. Wrong clock for the HDMI encoder would just result in non-working HDMI output and no feasible way for me to debug what is wrong.
Hope you have a serial console or ssh connection to the board. If it doesn't work you'll know soon enough.
Quoted 8 lines
What I'm pointing out is that the clock setup implied by the current dtsi doesn't make much sense: VOP's dclk is driven off VPLL via a mux and divisor. If the encoder's pixel clock is truly driven directly off VPLL then Rockchip designed the muxes and dividers for nothing, as they will always be no-ops. This doesn't square, so something must be wrong, and I believe it's the dtsi.
I'll be happy to be proven wrong here.
Hey Alexey,
Quoted 8 lines
Sorry for the long delay - NVMe in my laptop died and I had to wait for a warranty replacement to arrive. I would have bought a new one if the price wasn't ridiculous :)
The dtsi describes the hardware correctly. The HDMI PHY's reference clock input (TRM Part 1, 1.1.11: "13.5-600MHz input reference clock") is wired to VPLL with no mux or divider in between; it is not one of the CRU clocks in the TRM's clock tree at all.
The TRM unfortunately only says there is an input reference clock but gives no detail on how it's wired.
Quoted 3 lines
That's exactly what the commit that introduced the "vpll" clock says, from Rockchip's own engineers, see
5e3bc6d1ab48("drm/rockchip:dw_hdmi: introduce the VPLL clock setting")
That commit indeed mentions that there is no divider between the VPLL and HDMI PHY. Looks like it's our only evidence, but I believe we should trust the information in Mark Yao's commit message, given his Rockchip sign-off line.
Quoted 6 lines
This bug report itself is a solid proof of this wiring. With VPLL left at 74.25 MHz and the VOP on GPLL/7 = 84.857 MHz, the monitor reported the mode as 1195x768. 74.25/84.857 = 0.875, and 1366 * 0.875 = 1195. The TMDS clock came from VPLL while the sync timing came from the VOP. If the PHY were clocked from the dclk mux output, that mismatch could not exist.
Fair enough.
Quoted 13 lines
The mux and dividers are not for nothing: there is one VPLL and two VOPs, and each VOP can also drive eDP, MIPI DSI and DP, whose PHYs have their own PLLs. When VOPB drives HDMI from VPLL/1, VOPL has to run from CPLL or GPLL through the divider, and the fractional divider exists for DSI panels with odd pixel clocks. For HDMI the divider is legitimately 1.
This is also why the PLL table patch is needed under any scheme: the RK3399 PLL driver is table-only (
rockchip_pll_determine_rate()snaps to the nearest lower table entry), and the PHY reference has to be 85.5 MHz exactly because nothing between VPLL and the PHY can divide it.
Quoted 7 lines
And the VOP patch doesn't hardcode a divisor. The VOP still makes a real
clk_set_rate()on its dclk at enable time. The bug was ordering:mode_fixup()rounded the pixel clock through the dclk while VPLL was still at its old rate, so the composite chose GPLL/7 and the encoder then asked VPLL for 84.857 MHz, which the table snapped to 74.25 MHz. With VPLL programmed first, the composite picks VPLL with divider 1 because it is the exact match.
Ack. Thanks a lot for double-checking all of these - it's great to have your explanations recorded on the mailing list for posterity!
Back to the patch itself. The new rate you're defining is consistent with the existing entry for RK3036_PLL_RATE(1368000000, 1, 57, 1, 1, 1, 0), and the parameters are within spec (VCO rate of 1368000000 falls within the documented range of 800 MHz to 3.2 GHz). Feel free to include my:
On the existing 1368000000 entry, I'm pretty sure it would produce less jitter as RK3036_PLL_RATE(1368000000, 1, 114, 2, 1, 1, 0), by the virtue of FVCO=2736MHz falling into the higher end of the allowed band. This won't apply to your 85.5MHz rate though, because the required divisors won't fit in two 3-bit registers.
Best regards,
Alexey