Skip to content

Commit

Permalink
drm/bridge: analogix_dp: simplify and correct PLL lock checks
Browse files Browse the repository at this point in the history
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: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Robert Foss <rfoss@kernel.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Robert Foss <rfoss@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240619182200.3752465-12-l.stach@pengutronix.de
  • Loading branch information
Lucas Stach authored and Robert Foss committed Jun 27, 2024
1 parent 917c8d1 commit 0fa5e37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
34 changes: 12 additions & 22 deletions drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
u8 buf[4];
int lane, lane_count, pll_tries, retval;
int lane, lane_count, retval;

lane_count = dp->link_train.lane_count;

Expand All @@ -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*/
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
* the DP inter pair skew issue for at least 10 us
Expand Down Expand Up @@ -270,18 +275,6 @@ static int analogix_dp_link_start(struct analogix_dp_device *dp)
DP_TRAIN_PRE_EMPH_LEVEL_0;
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 */
analogix_dp_set_training_pattern(dp, TRAINING_PTN1);

Expand Down Expand Up @@ -631,9 +624,14 @@ static int analogix_dp_fast_link_train(struct analogix_dp_device *dp)
{
int ret;
u8 link_align, link_status[2];
enum pll_status status;

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
* the DP inter pair skew issue for at least 10 us
Expand All @@ -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_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 */
analogix_dp_set_training_pattern(dp, TRAINING_PTN1);
/* From DP spec, pattern must be on-screen for a minimum 500us */
Expand Down
7 changes: 1 addition & 6 deletions drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ enum dynamic_range {
CEA
};

enum pll_status {
PLL_UNLOCKED,
PLL_LOCKED
};

enum clock_recovery_m_value_type {
CALCULATED_M,
REGISTER_M
Expand Down Expand Up @@ -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_mute_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_analog_power_down(struct analogix_dp_device *dp,
enum analog_power_block block,
Expand Down
12 changes: 5 additions & 7 deletions drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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);
if (reg & PLL_LOCK)
return PLL_LOCKED;
else
return PLL_UNLOCKED;
return readl_poll_timeout(dp->reg_base + ANALOGIX_DP_DEBUG_CTL, val,
val & PLL_LOCK, 120,
120 * DP_TIMEOUT_LOOP_COUNT);
}

void analogix_dp_set_pll_power_down(struct analogix_dp_device *dp, bool enable)
Expand Down

0 comments on commit 0fa5e37

Please sign in to comment.