Commit 0fa5e37f authored by Lucas Stach's avatar Lucas Stach Committed by Robert Foss

drm/bridge: analogix_dp: simplify and correct PLL lock checks

Move the wait loop into its own function, so it doesn't need to be
replicated in multiple locations. Also move the PLL lock checks between
setting the link bandwidth, which may cause the PLL to unlock, and the
MACRO_RST which needs the PLL to be locked.
Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
Reviewed-by: default avatarRobert Foss <rfoss@kernel.org>
Tested-by: default avatarHeiko Stuebner <heiko@sntech.de>
Signed-off-by: default avatarRobert Foss <rfoss@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240619182200.3752465-12-l.stach@pengutronix.de
parent 917c8d19
...@@ -231,7 +231,7 @@ static int analogix_dp_training_pattern_dis(struct analogix_dp_device *dp) ...@@ -231,7 +231,7 @@ static int analogix_dp_training_pattern_dis(struct analogix_dp_device *dp)
static int analogix_dp_link_start(struct analogix_dp_device *dp) static int analogix_dp_link_start(struct analogix_dp_device *dp)
{ {
u8 buf[4]; u8 buf[4];
int lane, lane_count, pll_tries, retval; int lane, lane_count, retval;
lane_count = dp->link_train.lane_count; lane_count = dp->link_train.lane_count;
...@@ -243,6 +243,11 @@ static int analogix_dp_link_start(struct analogix_dp_device *dp) ...@@ -243,6 +243,11 @@ static int analogix_dp_link_start(struct analogix_dp_device *dp)
/* Set link rate and count as you want to establish*/ /* Set link rate and count as you want to establish*/
analogix_dp_set_link_bandwidth(dp, dp->link_train.link_rate); analogix_dp_set_link_bandwidth(dp, dp->link_train.link_rate);
retval = analogix_dp_wait_pll_locked(dp);
if (retval) {
DRM_DEV_ERROR(dp->dev, "Wait for pll lock failed %d\n", retval);
return retval;
}
/* /*
* MACRO_RST must be applied after the PLL_LOCK to avoid * MACRO_RST must be applied after the PLL_LOCK to avoid
* the DP inter pair skew issue for at least 10 us * the DP inter pair skew issue for at least 10 us
...@@ -270,18 +275,6 @@ static int analogix_dp_link_start(struct analogix_dp_device *dp) ...@@ -270,18 +275,6 @@ static int analogix_dp_link_start(struct analogix_dp_device *dp)
DP_TRAIN_PRE_EMPH_LEVEL_0; DP_TRAIN_PRE_EMPH_LEVEL_0;
analogix_dp_set_lane_link_training(dp); analogix_dp_set_lane_link_training(dp);
/* Wait for PLL lock */
pll_tries = 0;
while (analogix_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) {
if (pll_tries == DP_TIMEOUT_LOOP_COUNT) {
dev_err(dp->dev, "Wait for PLL lock timed out\n");
return -ETIMEDOUT;
}
pll_tries++;
usleep_range(90, 120);
}
/* Set training pattern 1 */ /* Set training pattern 1 */
analogix_dp_set_training_pattern(dp, TRAINING_PTN1); analogix_dp_set_training_pattern(dp, TRAINING_PTN1);
...@@ -631,9 +624,14 @@ static int analogix_dp_fast_link_train(struct analogix_dp_device *dp) ...@@ -631,9 +624,14 @@ static int analogix_dp_fast_link_train(struct analogix_dp_device *dp)
{ {
int ret; int ret;
u8 link_align, link_status[2]; u8 link_align, link_status[2];
enum pll_status status;
analogix_dp_set_link_bandwidth(dp, dp->link_train.link_rate); analogix_dp_set_link_bandwidth(dp, dp->link_train.link_rate);
ret = analogix_dp_wait_pll_locked(dp);
if (ret) {
DRM_DEV_ERROR(dp->dev, "Wait for pll lock failed %d\n", ret);
return ret;
}
/* /*
* MACRO_RST must be applied after the PLL_LOCK to avoid * MACRO_RST must be applied after the PLL_LOCK to avoid
* the DP inter pair skew issue for at least 10 us * the DP inter pair skew issue for at least 10 us
...@@ -642,14 +640,6 @@ static int analogix_dp_fast_link_train(struct analogix_dp_device *dp) ...@@ -642,14 +640,6 @@ static int analogix_dp_fast_link_train(struct analogix_dp_device *dp)
analogix_dp_set_lane_count(dp, dp->link_train.lane_count); analogix_dp_set_lane_count(dp, dp->link_train.lane_count);
analogix_dp_set_lane_link_training(dp); analogix_dp_set_lane_link_training(dp);
ret = readx_poll_timeout(analogix_dp_get_pll_lock_status, dp, status,
status != PLL_UNLOCKED, 120,
120 * DP_TIMEOUT_LOOP_COUNT);
if (ret) {
DRM_DEV_ERROR(dp->dev, "Wait for pll lock failed %d\n", ret);
return ret;
}
/* source Set training pattern 1 */ /* source Set training pattern 1 */
analogix_dp_set_training_pattern(dp, TRAINING_PTN1); analogix_dp_set_training_pattern(dp, TRAINING_PTN1);
/* From DP spec, pattern must be on-screen for a minimum 500us */ /* From DP spec, pattern must be on-screen for a minimum 500us */
......
...@@ -95,11 +95,6 @@ enum dynamic_range { ...@@ -95,11 +95,6 @@ enum dynamic_range {
CEA CEA
}; };
enum pll_status {
PLL_UNLOCKED,
PLL_LOCKED
};
enum clock_recovery_m_value_type { enum clock_recovery_m_value_type {
CALCULATED_M, CALCULATED_M,
REGISTER_M REGISTER_M
...@@ -191,7 +186,7 @@ void analogix_dp_swreset(struct analogix_dp_device *dp); ...@@ -191,7 +186,7 @@ void analogix_dp_swreset(struct analogix_dp_device *dp);
void analogix_dp_config_interrupt(struct analogix_dp_device *dp); void analogix_dp_config_interrupt(struct analogix_dp_device *dp);
void analogix_dp_mute_hpd_interrupt(struct analogix_dp_device *dp); void analogix_dp_mute_hpd_interrupt(struct analogix_dp_device *dp);
void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device *dp); void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device *dp);
enum pll_status analogix_dp_get_pll_lock_status(struct analogix_dp_device *dp); int analogix_dp_wait_pll_locked(struct analogix_dp_device *dp);
void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable); void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable);
void analogix_dp_set_analog_power_down(struct analogix_dp_device *dp, void analogix_dp_set_analog_power_down(struct analogix_dp_device *dp,
enum analog_power_block block, enum analog_power_block block,
......
...@@ -217,15 +217,13 @@ void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device *dp) ...@@ -217,15 +217,13 @@ void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device *dp)
writel(reg, dp->reg_base + ANALOGIX_DP_INT_STA_MASK); writel(reg, dp->reg_base + ANALOGIX_DP_INT_STA_MASK);
} }
enum pll_status analogix_dp_get_pll_lock_status(struct analogix_dp_device *dp) int analogix_dp_wait_pll_locked(struct analogix_dp_device *dp)
{ {
u32 reg; u32 val;
reg = readl(dp->reg_base + ANALOGIX_DP_DEBUG_CTL); return readl_poll_timeout(dp->reg_base + ANALOGIX_DP_DEBUG_CTL, val,
if (reg & PLL_LOCK) val & PLL_LOCK, 120,
return PLL_LOCKED; 120 * DP_TIMEOUT_LOOP_COUNT);
else
return PLL_UNLOCKED;
} }
void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable) void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment