drm/bridge: tc358767: Split tc_pxl_pll_en() into parameter calculation and enablement
Subsystems (3)
PATCH v4 1/5 drm/bridge: tc358767: Split tc_pxl_pll_en() into parameter calculation and enablement
Split tc_pxl_pll_en() into tc_pxl_pll_calc() which does only Pixel PLL parameter calculation and tc_pxl_pll_en() which calls tc_pxl_pll_calc() and then configures the Pixel PLL register.
This is a preparatory patch for further rework, where tc_pxl_pll_calc() will also be used to find out the exact clock frequency generated by the Pixel PLL. This frequency will be used as adjusted_mode clock frequency and passed down the display pipeline to obtain exactly this frequency on input into this bridge.
The precise input frequency that matches the Pixel PLL frequency is important for this bridge, as if the frequencies do not match, the bridge does suffer VFIFO overruns or underruns.
---
Cc: Andrzej Hajda <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: No change
V3: No change
V4: - Fix another rebase mishap
- Add RB from Alexander
--- drivers/gpu/drm/bridge/tc358767.c | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +25 -7
@@ -585,9 +585,9 @@ static u32 div64_round_up(u64 v, u32 d)return div_u64 (v + d -1 , d); } -static int tc_pxl_pll_en (struct tc_data *tc,u32 refclk,u32 pixelclock) +static int tc_pxl_pll_calc (struct tc_data *tc,u32 refclk,u32 pixelclock, +int *out_best_pixelclock,u32 *out_pxl_pllparam) { -int ret;int i_pre, best_pre =1 ;int i_post, best_post =1 ;int div, best_div =1 ;
@@ -683,11 +683,6 @@ static int tc_pxl_pll_en(struct tc_data *tc, u32 refclk, u32 pixelclock)if (best_mul ==128 ) best_mul =0 ; -/* Power up PLL and switch to bypass */ - ret =regmap_write (tc->regmap,PXL_PLLCTRL ,PLLBYP |PLLEN ); -if (ret) -return ret; - pxl_pllparam = vco_hi <<24 ;/* For PLL VCO >= 300 MHz = 1 */ pxl_pllparam |= ext_div[best_pre] <<20 ;/* External Pre-divider */ pxl_pllparam |= ext_div[best_post] <<16 ;/* External Post-divider */
@@ -695,6 +690,29 @@ static int tc_pxl_pll_en(struct tc_data *tc, u32 refclk, u32 pixelclock) pxl_pllparam |= best_div <<8 ;/* Divider for PLL RefClk */ pxl_pllparam |= best_mul;/* Multiplier for PLL */ +if (out_best_pixelclock) + *out_best_pixelclock = best_pixelclock; + +if (out_pxl_pllparam) + *out_pxl_pllparam = pxl_pllparam; + +return 0 ; +} + +static int tc_pxl_pll_en (struct tc_data *tc,u32 refclk,u32 pixelclock) +{ +u32 pxl_pllparam =0 ; +int ret; + + ret =tc_pxl_pll_calc (tc, refclk, pixelclock,NULL , &pxl_pllparam); +if (ret) +return ret; + +/* Power up PLL and switch to bypass */ + ret =regmap_write (tc->regmap,PXL_PLLCTRL ,PLLBYP |PLLEN ); +if (ret) +return ret; + ret =regmap_write (tc->regmap,PXL_PLLPARAM , pxl_pllparam);if (ret)return ret;
Signature · 1 line
2.43.0
PATCH v4 2/5 drm/bridge: tc358767: Use tc_pxl_pll_calc() to correct adjusted_mode clock
Use tc_pxl_pll_calc() to find out the exact clock frequency generated by the Pixel PLL. Use the Pixel PLL frequency as adjusted_mode clock frequency and pass it down the display pipeline to obtain exactly this frequency on input into this bridge.
The precise input frequency that matches the Pixel PLL frequency is important for this bridge, as if the frequencies do not match, the bridge does suffer VFIFO overruns or underruns.
---
Cc: Andrzej Hajda <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: - Use mode clock as input into tc_pxl_pll_calc() to avoid
accumulating rounding error
V3: No change
V4: - Add RB from Alexander
--- drivers/gpu/drm/bridge/tc358767.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/drm/bridge/tc358767.c +24 -0
@@ -1624,6 +1624,18 @@ static int tc_dpi_atomic_check(struct drm_bridge *bridge,struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { + struct tc_data *tc = bridge_to_tc(bridge); +int adjusted_clock =0 ; +int ret; + + ret =tc_pxl_pll_calc (tc,clk_get_rate (tc->refclk), + crtc_state->mode.clock *1000 , + &adjusted_clock,NULL ); +if (ret) +return ret; + + crtc_state->adjusted_mode.clock = adjusted_clock /1000 ; +/* DSI->DPI interface clock limitation: upto 100 MHz */ if (crtc_state->adjusted_mode.clock >100000 )return -EINVAL ;
@@ -1636,6 +1648,18 @@ static int tc_edp_atomic_check(struct drm_bridge *bridge,struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { + struct tc_data *tc = bridge_to_tc(bridge); +int adjusted_clock =0 ; +int ret; + + ret =tc_pxl_pll_calc (tc,clk_get_rate (tc->refclk), + crtc_state->mode.clock *1000 , + &adjusted_clock,NULL ); +if (ret) +return ret; + + crtc_state->adjusted_mode.clock = adjusted_clock /1000 ; +/* DPI->(e)DP interface clock limitation: upto 154 MHz */ if (crtc_state->adjusted_mode.clock >154000 )return -EINVAL ;
Signature · 1 line
2.43.0
PATCH v4 3/5 drm/bridge: tc358767: Drop line_pixel_subtract
In reply to Marek VasutThis line_pixel_subtract is no longer needed now that the bridge can request and obtain specific pixel clock on input to the bridge, with clock frequency that matches the Pixel PLL frequency.
The line_pixel_subtract is now always 0, so drop it entirely.
The line_pixel_subtract was not reliable as it never worked when the Pixel PLL and input clock were off just so that the required amount of pixels to subtract would not be whole integer.
---
Cc: Andrzej Hajda <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: No change
V3: Fix up rebase artifact
V4: - Fix another rebase mishap
- Add RB from Alexander
--- drivers/gpu/drm/bridge/tc358767.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +1 -20
@@ -382,9 +382,6 @@ struct tc_data {/* HPD pin number (0 or 1) or -ENODEV */ int hpd_pin; - -/* Number of pixels to subtract from a line due to pixel clock delta */ -u32 line_pixel_subtract; };static inline struct tc_data *aux_to_tc (struct drm_dp_aux *a)
@@ -580,11 +577,6 @@ static int tc_pllupdate(struct tc_data *tc, unsigned int pllctrl)return 0 ; } -static u32 div64_round_up (u64 v,u32 d) -{ -return div_u64 (v + d -1 , d); -} -static int tc_pxl_pll_calc (struct tc_data *tc,u32 refclk,u32 pixelclock,int *out_best_pixelclock,u32 *out_pxl_pllparam) {
@@ -666,11 +658,7 @@ static int tc_pxl_pll_calc(struct tc_data *tc, u32 refclk, u32 pixelclock,return -EINVAL ; } - tc->line_pixel_subtract = tc->mode.htotal - -div64_round_up (tc->mode.htotal * (u64 )best_pixelclock, pixelclock); - -dev_dbg (tc->dev,"PLL: got %d, delta %d (subtract %d px)\n" , best_pixelclock, - best_delta, tc->line_pixel_subtract); +dev_dbg (tc->dev,"PLL: got %d, delta %d\n" , best_pixelclock, best_delta);dev_dbg (tc->dev,"PLL: %d / %d / %d * %d / %d\n" , refclk, ext_div[best_pre], best_div, best_mul, ext_div[best_post]);
@@ -914,13 +902,6 @@ static int tc_set_common_video_mode(struct tc_data *tc, upper_margin, lower_margin, vsync_len);dev_dbg (tc->dev,"total: %dx%d\n" , mode->htotal, mode->vtotal); -if (right_margin > tc->line_pixel_subtract) { - right_margin -= tc->line_pixel_subtract; - }else { -dev_err (tc->dev,"Bridge pixel clock too slow for mode\n" ); - right_margin =0 ; - } -/* * LCD Ctl Frame Size * datasheet is not clear of vsdelay in case of DPI
Signature · 1 line
2.43.0
PATCH v4 4/5 drm/bridge: tc358767: Set LSCLK divider for SYSCLK to 1
In reply to Marek VasutThe only information in the datasheet regarding this divider is a note in SYS_PLLPARAM register documentation which states that when LSCLK is 270 MHz, LSCLK_DIV should be 1. What should LSCLK_DIV be set to when LSCLK is 162 MHz (for DP 1.62G mode) is unclear, but empirical test confirms using LSCLK_DIV 1 has no adverse effects either. In the worst case, the internal TC358767 clock would run faster.
---
Cc: Andrzej Hajda <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: No change
V3: No change
V4: - Add RB from Alexander
--- drivers/gpu/drm/bridge/tc358767.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/tc358767.c +1 -1
@@ -738,7 +738,7 @@ static int tc_stream_clock_calc(struct tc_data *tc)static int tc_set_syspllparam (struct tc_data *tc) {unsigned long rate; -u32 pllparam =SYSCLK_SEL_LSCLK |LSCLK_DIV_2 ; +u32 pllparam =SYSCLK_SEL_LSCLK |LSCLK_DIV_1 ; rate =clk_get_rate (tc->refclk);switch (rate) {
Signature · 1 line
2.43.0
PATCH v4 5/5 Revert "drm/bridge: tc358767: Set default CLRSIPO count"
In reply to Marek VasutThis reverts commit 01338bb82fed40a6a234c2b36a92367c8671adf0.
With clock improvements in place, this seems to be no longer necessary. Set the CLRSIPO to default setting recommended by manufacturer.
---
Cc: Andrzej Hajda <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: No change
V3: No change
V4: - Add RB from Alexander
--- drivers/gpu/drm/bridge/tc358767.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +4 -4
@@ -1356,10 +1356,10 @@ static int tc_dsi_rx_enable(struct tc_data *tc)u32 value;int ret; -regmap_write (tc->regmap,PPI_D0S_CLRSIPOCOUNT ,25 ); -regmap_write (tc->regmap,PPI_D1S_CLRSIPOCOUNT ,25 ); -regmap_write (tc->regmap,PPI_D2S_CLRSIPOCOUNT ,25 ); -regmap_write (tc->regmap,PPI_D3S_CLRSIPOCOUNT ,25 ); +regmap_write (tc->regmap,PPI_D0S_CLRSIPOCOUNT ,5 ); +regmap_write (tc->regmap,PPI_D1S_CLRSIPOCOUNT ,5 ); +regmap_write (tc->regmap,PPI_D2S_CLRSIPOCOUNT ,5 ); +regmap_write (tc->regmap,PPI_D3S_CLRSIPOCOUNT ,5 );regmap_write (tc->regmap,PPI_D0S_ATMR ,0 );regmap_write (tc->regmap,PPI_D1S_ATMR ,0 );regmap_write (tc->regmap,PPI_TX_RX_TA ,TTA_GET |TTA_SURE );
Signature · 1 line
2.43.0
Quoted 11 lines · Marek Vasut
Split
tc_pxl_pll_en()intotc_pxl_pll_calc()which does only Pixel PLL parameter calculation andtc_pxl_pll_en()which callstc_pxl_pll_calc()and then configures the Pixel PLL register.This is a preparatory patch for further rework, where
tc_pxl_pll_calc()will also be used to find out the exact clock frequency generated by the Pixel PLL. This frequency will be used asadjusted_modeclock frequency and passed down the display pipeline to obtain exactly this frequency on input into this bridge.[...]
Applied, thanks!
[1/5] drm/bridge: tc358767: Split tc_pxl_pll_en() into parameter calculation and enablement
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=84708c2d180c [2/5] drm/bridge: tc358767: Use tc_pxl_pll_calc() to correct adjusted_mode clock https://cgit.freedesktop.org/drm/drm-misc/commit/?id=a723d434009e [3/5] drm/bridge: tc358767: Drop line_pixel_subtract https://cgit.freedesktop.org/drm/drm-misc/commit/?id=3f13e53bcf30 [4/5] drm/bridge: tc358767: Set LSCLK divider for SYSCLK to 1 https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9c433c87e81c [5/5] Revert "drm/bridge: tc358767: Set default CLRSIPO count" https://cgit.freedesktop.org/drm/drm-misc/commit/?id=86b0e0c1ad47
Rob