drm/msm/dp: Drop the HPD state machine
v2 cover drm/msm/dp: Drop the HPD state machine
Currently, all HPD interrupt handling must go through the HPD state machine.
This has caused many issues where the DRM framework assumes that DP is in one state while the state machine is stuck in another state.
As discussed here [1], this series:
- Removes the state machine
- Moves link training to atomic_enable()
- Changes the detect() behavior to return true if a display is physically plugged in (as opposed to if the DP link is ready).
- Remove event queue and move internal HPD handling to hpd_notify()
This has been validated on x1e80100-crd and sa8775p-ride. Any help testing on other platforms/use-cases would be appreciated!
[1] https://patchwork.freedesktop.org/patch/656312/?series=142010&rev=2#comment_1201738
---
Changes in v2:
- Dropped event queue (Dmitry)
- Moved internal HPD handling to use hpd_notify() (Dmitry)
- Reworked bridge detect() to read DPCP and sink count (Dmitry)
- Moved setting of link_trained to plug/unplugged handling
- Dropped msm_dp::connected (Dmitry)
- Squashed all hpd state related patches (Dmitry)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Abhinav Kumar (1):
drm/msm/dp: remove redundant checks related to ST_DISPLAY_OFF in plug handler
Jessica Zhang (11):
drm/msm/dp: fix HPD state status bit shift value drm/msm/dp: Fix the ISR_* enum values
drm/msm/dp: Read DPCD and sink count in bridge detect() drm/msm/dp: Move link training to atomic_enable() drm/msm/dp: Drop EV_USER_NOTIFICATION
drm/msm/dp: Use drm_bridge_hpd_notify()
drm/msm/dp: Handle internal HPD IRQ in hpd_notify() drm/msm/dp: Drop event waitqueue
drm/msm/dp: Return early from atomic_enable() if cable is not connected drm/msm/dp: drop the entire HPD state machine
drm/msm/dp: Add sink_count and link_ready to debug logs
drivers/gpu/drm/msm/dp/dp_ctrl.c | 22 -- drivers/gpu/drm/msm/dp/dp_ctrl.h | 1 - drivers/gpu/drm/msm/dp/dp_display.c | 580 +++++++++++------------------------- drivers/gpu/drm/msm/dp/dp_display.h | 1 + drivers/gpu/drm/msm/dp/dp_drm.c | 20 +- drivers/gpu/drm/msm/dp/dp_drm.h | 1 + drivers/gpu/drm/msm/dp/dp_reg.h | 2 +- 7 files changed, 187 insertions(+), 440 deletions(-)
---
base-commit: 8290d37ad2b087bbcfe65fa5bcaf260e184b250a
change-id: 20250523-hpd-refactor-74e25b55620a
Best regards,
Signature · 1 line
Jessica Zhang <[email protected]>
PATCH v2 1/12 drm/msm/dp: fix HPD state status bit shift value
The HPD state status is the last 3 bits, not 4 bits of the HPD_INT_STATUS register.
Fix the bit shift macro so that the correct bits are returned in msm_dp_aux_is_link_connected().
--- drivers/gpu/drm/msm/dp/dp_reg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dp/dp_reg.h +1 -1
@@ -69,7 +69,7 @@#define DP_DP_HPD_REPLUG_INT_ACK (0x00000004)#define DP_DP_HPD_UNPLUG_INT_ACK (0x00000008)#define DP_DP_HPD_STATE_STATUS_BITS_MASK (0x0000000F) -#define DP_DP_HPD_STATE_STATUS_BITS_SHIFT (0x1C) +#define DP_DP_HPD_STATE_STATUS_BITS_SHIFT (0x1D)#define REG_DP_DP_HPD_INT_MASK (0x0000000C)#define DP_DP_HPD_PLUG_INT_MASK (0x00000001)
Signature · 1 line
2.50.1
Re: [PATCH v2 01/12] drm/msm/dp: fix HPD state status bit shift value
Quoted 2 lines · Jessica Zhang
The HPD state status is the last 3 bits, not 4 bits of the
HPD_INT_STATUSregister.
Then the mask is incorrect too. Also, I'd suggest using 'most significant' instead of 'last'. The latter one might be confusing.
Quoted 24 lines
Fix the bit shift macro so that the correct bits are returned in
msm_dp_aux_is_link_connected().Fixes 19e52bcb27c2 ("drm/msm/dp: return correct connection status after suspend")Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_reg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/dp/dp_reg.h +1
-1@@ -69,7 +69,7 @@#define DP_DP_HPD_REPLUG_INT_ACK (0x00000004)#define DP_DP_HPD_UNPLUG_INT_ACK (0x00000008)#define DP_DP_HPD_STATE_STATUS_BITS_MASK (0x0000000F) -#define DP_DP_HPD_STATE_STATUS_BITS_SHIFT (0x1C) +#define DP_DP_HPD_STATE_STATUS_BITS_SHIFT (0x1D)#define REG_DP_DP_HPD_INT_MASK (0x0000000C)#define DP_DP_HPD_PLUG_INT_MASK (0x00000001)
Signature · 2 lines
With best wishes Dmitry
PATCH v2 2/12 drm/msm/dp: Fix the ISR_* enum values
In reply to Jessica ZhangISR_HPD_IO_GLITCH_COUNT and ISR_HPD_REPLUG_COUNT are not in the correct order. Swap them so that the ISR_* enum will have the correct values.
Also, correct the spelling for ISR_HPD_REPLUG_COUNT.
--- drivers/gpu/drm/msm/dp/dp_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +2 -2
@@ -38,9 +38,9 @@ enum {ISR_DISCONNECTED ,ISR_CONNECT_PENDING ,ISR_CONNECTED , -ISR_HPD_REPLUG_COUNT , +ISR_HPD_IO_GLITCH_COUNT ,ISR_IRQ_HPD_PULSE_COUNT , - ISR_HPD_LO_GLITH_COUNT, + ISR_HPD_REPLUG_COUNT, };/* event thread connection state */
Signature · 1 line
2.50.1
PATCH v2 3/12 drm/msm/dp: Read DPCD and sink count in bridge detect()
In reply to Jessica ZhangInstead of relying on the link_ready flag to specify if DP is connected, read the DPCD bits and get the sink count to accurately detect if DP is connected.
--- drivers/gpu/drm/msm/dp/dp_display.c | 54 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/msm/dp/dp_drm.c | 18 ------------- drivers/gpu/drm/msm/dp/dp_drm.h | 1 + 3 files changed, 55 insertions(+), 18 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +54 -0
@@ -1142,6 +1142,60 @@ static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_preturn 0 ; } +/** +* msm_dp_bridge_detect - callback to determine if connector is connected +* @bridge: Pointer to drm bridge structure +* Returns: Bridge's 'is connected' status +*/ +enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge) +{ +struct msm_dp_bridge *msm_dp_bridge =to_dp_bridge (bridge); +struct msm_dp *dp = msm_dp_bridge->msm_dp_display; +struct msm_dp_display_private *priv; +int ret =0 , sink_count =0 ; +int status = connector_status_disconnected; +u8 dpcd[DP_RECEIVER_CAP_SIZE ]; + + dp =to_dp_bridge (bridge)->msm_dp_display; + + priv = container_of(dp, struct msm_dp_display_private, msm_dp_display); + +if (!dp->link_ready) +return status; + +msm_dp_aux_enable_xfers (priv->aux, true); + + ret =pm_runtime_resume_and_get (&dp->pdev->dev); +if (ret) { +DRM_ERROR ("failed to pm_runtime_resume\n" ); +msm_dp_aux_enable_xfers (priv->aux, false); +return status; + } + + ret =msm_dp_aux_is_link_connected (priv->aux); +if (dp->internal_hpd && !ret) + goto end; + + ret =drm_dp_read_dpcd_caps (priv->aux, dpcd); +if (ret) + goto end; + + sink_count =drm_dp_read_sink_count (priv->aux); + +drm_dbg_dp (dp->drm_dev,"is_branch = %s, sink_count = %d\n" , +str_true_false (drm_dp_is_branch (dpcd)), + sink_count); + +if (drm_dp_is_branch (dpcd) && sink_count ==0 ) + status = connector_status_disconnected; +else + status = connector_status_connected; + +end: +pm_runtime_put_sync (&dp->pdev->dev); +return status; +} +static irqreturn_t msm_dp_display_irq_handler (int irq,void *dev_id) {struct msm_dp_display_private *dp = dev_id;
drivers/gpu/drm/msm/dp/dp_drm.c +0 -18
@@ -15,24 +15,6 @@#include "dp_audio.h" #include "dp_drm.h" -/** -* msm_dp_bridge_detect - callback to determine if connector is connected -* @bridge: Pointer to drm bridge structure -* Returns: Bridge's 'is connected' status -*/ -static enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge) -{ -struct msm_dp *dp; - - dp =to_dp_bridge (bridge)->msm_dp_display; - -drm_dbg_dp (dp->drm_dev,"link_ready = %s\n" , -str_true_false (dp->link_ready)); - -return (dp->link_ready) ? connector_status_connected : - connector_status_disconnected; -} - static int msm_dp_bridge_atomic_check(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state,
drivers/gpu/drm/msm/dp/dp_drm.h +1 -0
@@ -25,6 +25,7 @@ int msm_dp_bridge_init(struct msm_dp *msm_dp_display, struct drm_device *dev,struct drm_encoder *encoder, bool yuv_supported); +enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge);void msm_dp_bridge_atomic_enable (struct drm_bridge *drm_bridge,struct drm_atomic_state *state); void msm_dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
Signature · 1 line
2.50.1
Re: [PATCH v2 03/12] drm/msm/dp: Read DPCD and sink count in bridge detect()
Quoted 48 lines · Jessica Zhang
Instead of relying on the
link_readyflag to specify if DP is connected, read the DPCD bits and get the sink count to accurately detect if DP is connected.Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 54 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/msm/dp/dp_drm.c | 18 ------------- drivers/gpu/drm/msm/dp/dp_drm.h | 1 + 3 files changed, 55 insertions(+), 18 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +29
-0@@ -1142,6 +1142,60 @@ static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_preturn 0 ; } +/** +* msm_dp_bridge_detect - callback to determine if connector is connected +* @bridge: Pointer to drm bridge structure +* Returns: Bridge's 'is connected' status +*/ +enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge) +{ +struct msm_dp_bridge *msm_dp_bridge =to_dp_bridge (bridge); +struct msm_dp *dp = msm_dp_bridge->msm_dp_display; +struct msm_dp_display_private *priv; +int ret =0 , sink_count =0 ; +int status = connector_status_disconnected; +u8 dpcd[DP_RECEIVER_CAP_SIZE ]; + + dp =to_dp_bridge (bridge)->msm_dp_display; + + priv = container_of(dp, struct msm_dp_display_private, msm_dp_display); + +if (!dp->link_ready) +return status; + +msm_dp_aux_enable_xfers (priv->aux, true); + + ret =pm_runtime_resume_and_get (&dp->pdev->dev); +if (ret) { +DRM_ERROR ("failed to pm_runtime_resume\n" ); +msm_dp_aux_enable_xfers (priv->aux, false); +return status; + }
drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_hpd_event_thread_start(struct msm_dp_display_private *msm_dp_p · line 1183
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +10
-0+ + ret =msm_dp_aux_is_link_connected (priv->aux); +if (dp->internal_hpd && !ret) + goto end; + + ret =drm_dp_read_dpcd_caps (priv->aux, dpcd); +if (ret) + goto end; + + sink_count =drm_dp_read_sink_count (priv->aux);
Should be guarded by drm_dp_read_sink_count_cap()
Quoted 60 lines
drivers/gpu/drm/msm/dp/dp_display.c +15
-0+ +drm_dbg_dp (dp->drm_dev,"is_branch = %s, sink_count = %d\n" , +str_true_false (drm_dp_is_branch (dpcd)), + sink_count); + +if (drm_dp_is_branch (dpcd) && sink_count ==0 ) + status = connector_status_disconnected; +else + status = connector_status_connected; + +end: +pm_runtime_put_sync (&dp->pdev->dev); +return status; +} +static irqreturn_t msm_dp_display_irq_handler (int irq,void *dev_id) {struct msm_dp_display_private *dp = dev_id;drivers/gpu/drm/msm/dp/dp_drm.c +0
-18@@ -15,24 +15,6 @@#include "dp_audio.h" #include "dp_drm.h" -/** -* msm_dp_bridge_detect - callback to determine if connector is connected -* @bridge: Pointer to drm bridge structure -* Returns: Bridge's 'is connected' status -*/ -static enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge) -{ -struct msm_dp *dp; - - dp =to_dp_bridge (bridge)->msm_dp_display; - -drm_dbg_dp (dp->drm_dev,"link_ready = %s\n" , -str_true_false (dp->link_ready)); - -return (dp->link_ready) ? connector_status_connected : - connector_status_disconnected; -} - static int msm_dp_bridge_atomic_check(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state,drivers/gpu/drm/msm/dp/dp_drm.h +1
-0@@ -25,6 +25,7 @@ int msm_dp_bridge_init(struct msm_dp *msm_dp_display, struct drm_device *dev,struct drm_encoder *encoder, bool yuv_supported); +enum drm_connector_status msm_dp_bridge_detect (struct drm_bridge *bridge);void msm_dp_bridge_atomic_enable (struct drm_bridge *drm_bridge,struct drm_atomic_state *state); void msm_dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
Signature · 2 lines
With best wishes Dmitry
PATCH v2 4/12 drm/msm/dp: Move link training to atomic_enable()
In reply to Jessica ZhangCurrently, the DP link training is being done during HPD. Move link training to atomic_enable() in accordance with the atomic_enable() documentation.
Link disabling is already done in atomic_post_disable() (as part of the dp_ctrl_off_link_stream() helper).
Finally, call the plug/unplug handlers directly in hpd_notify() instead of queueing them in the event thread so that they aren't preempted by other events.
--- drivers/gpu/drm/msm/dp/dp_display.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +8 -7
@@ -427,11 +427,6 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_psm_config (dp->link, &dp->panel->link_info, false);msm_dp_link_reset_phy_params_vx_px (dp->link); - rc =msm_dp_ctrl_on_link (dp->ctrl); -if (rc) { -DRM_ERROR ("failed to complete DP link training\n" ); - goto end; - }msm_dp_add_event (dp,EV_USER_NOTIFICATION , true,0 );
@@ -1680,6 +1675,12 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, force_link_train = true; } + rc =msm_dp_ctrl_on_link (msm_dp_display->ctrl); +if (rc) { +DRM_ERROR ("Failed link training (rc=%d)\n" , rc); + dp->connector->state->link_status =DRM_LINK_STATUS_BAD ; + } +msm_dp_display_enable (msm_dp_display, force_link_train); rc =msm_dp_display_post_enable (dp);
@@ -1839,7 +1840,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,return ;if (!msm_dp_display->link_ready && status == connector_status_connected) -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,0 ); +msm_dp_hpd_plug_handle (dp,0 );else if (msm_dp_display->link_ready && status == connector_status_disconnected) -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); +msm_dp_hpd_unplug_handle (dp,0 ); }
Signature · 1 line
2.50.1
Re: [PATCH v2 04/12] drm/msm/dp: Move link training to atomic_enable()
Quoted 10 lines · Jessica Zhang
Currently, the DP link training is being done during HPD. Move link training to
atomic_enable()in accordance with theatomic_enable()documentation.Link disabling is already done in
atomic_post_disable()(as part of thedp_ctrl_off_link_stream()helper).Finally, call the plug/unplug handlers directly in
hpd_notify()instead of queueing them in the event thread so that they aren't preempted by other events.
This feels like two unrelated changes.
Quoted 46 lines
Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +8
-7@@ -427,11 +427,6 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_psm_config (dp->link, &dp->panel->link_info, false);msm_dp_link_reset_phy_params_vx_px (dp->link); - rc =msm_dp_ctrl_on_link (dp->ctrl); -if (rc) { -DRM_ERROR ("failed to complete DP link training\n" ); - goto end; - }msm_dp_add_event (dp,EV_USER_NOTIFICATION , true,0 );@@ -1680,6 +1675,12 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, force_link_train = true; } + rc =msm_dp_ctrl_on_link (msm_dp_display->ctrl); +if (rc) { +DRM_ERROR ("Failed link training (rc=%d)\n" , rc); + dp->connector->state->link_status =DRM_LINK_STATUS_BAD ; + } +msm_dp_display_enable (msm_dp_display, force_link_train); rc =msm_dp_display_post_enable (dp);@@ -1839,7 +1840,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,return ;if (!msm_dp_display->link_ready && status == connector_status_connected) -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,0 ); +msm_dp_hpd_plug_handle (dp,0 );else if (msm_dp_display->link_ready && status == connector_status_disconnected) -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); +msm_dp_hpd_unplug_handle (dp,0 ); }
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v2 04/12] drm/msm/dp: Move link training to atomic_enable()
Quoted 5 lines · Dmitry Baryshkov
Quoted 4 lines · Jessica Zhang
Currently, the DP link training is being done during HPD. Move link training to
atomic_enable()in accordance with theatomic_enable()documentation.
Quoted 8 lines
Quoted 6 lines
Link disabling is already done in
atomic_post_disable()(as part of thedp_ctrl_off_link_stream()helper).Finally, call the plug/unplug handlers directly in
hpd_notify()instead of queueing them in the event thread so that they aren't preempted by other events.This feels like two unrelated changes.
Hi Dmitry,
Ack. Would it make more sense to squash the hpd_notify part with the IRQ thread change?
Thanks,
Jessica Zhang
Quoted 46 lines
Quoted 44 lines
Signed-off-by Jessica Zhang <[email protected]>---
drivers/gpu/drm/msm/dp/dp_display.c| 15 ++++++++-------1 file changed, 8 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +8
-7@@ -427,11 +427,6 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) msm_dp_link_psm_config(dp->link, &dp->panel->link_info, false); msm_dp_link_reset_phy_params_vx_px(dp->link); - rc = msm_dp_ctrl_on_link(dp->ctrl); - if (rc) { - DRM_ERROR("failed to complete DP link training\n"); - goto end; - } msm_dp_add_event(dp, EV_USER_NOTIFICATION, true, 0);@@ -1680,6 +1675,12 @@ void msm_dp_bridge_atomic_enable(structdrm_bridge *drm_bridge, force_link_train = true; } + rc = msm_dp_ctrl_on_link(msm_dp_display->ctrl); + if (rc) { + DRM_ERROR("Failed link training (rc=%d)\n", rc); + dp->connector->state->link_status = DRM_LINK_STATUS_BAD; + } + msm_dp_display_enable(msm_dp_display, force_link_train); rc = msm_dp_display_post_enable(dp);@@ -1839,7 +1840,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge, return; if (!msm_dp_display->link_ready && status == connector_status_connected) - msm_dp_add_event(dp, EV_HPD_PLUG_INT, 0, 0); + msm_dp_hpd_plug_handle(dp, 0); else if (msm_dp_display->link_ready && status == connector_status_disconnected) - msm_dp_add_event(dp, EV_HPD_UNPLUG_INT, 0, 0); + msm_dp_hpd_unplug_handle(dp, 0); }
Re: [PATCH v2 04/12] drm/msm/dp: Move link training to atomic_enable()
In reply to Jessica ZhangQuoted 21 lines · Jessica Zhang
Currently, the DP link training is being done during HPD. Move link training to
atomic_enable()in accordance with theatomic_enable()documentation.Link disabling is already done in
atomic_post_disable()(as part of thedp_ctrl_off_link_stream()helper).Finally, call the plug/unplug handlers directly in
hpd_notify()instead of queueing them in the event thread so that they aren't preempted by other events.Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +0
-0
drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) · line 431
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +0
-5@@ -427,11 +427,6 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_psm_config (dp->link, &dp->panel->link_info, false);msm_dp_link_reset_phy_params_vx_px (dp->link); - rc =msm_dp_ctrl_on_link (dp->ctrl); -if (rc) { -DRM_ERROR ("failed to complete DP link training\n" ); - goto end; - }msm_dp_add_event (dp,EV_USER_NOTIFICATION , true,0 );
Also at this point we enqueue event, which will set link_ready to true (which is obviously incorrect).
drivers/gpu/drm/msm/dp/dp_display.c void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, · line 1681
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +4
-0@@ -1680,6 +1675,12 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, force_link_train = true; } + rc =msm_dp_ctrl_on_link (msm_dp_display->ctrl); +if (rc) { +DRM_ERROR ("Failed link training (rc=%d)\n" , rc); + dp->connector->state->link_status =DRM_LINK_STATUS_BAD ;
Add a comment why it's set directly rather than through drm_connector_set_link_status_property().
Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_display.c +4
-2+ } +msm_dp_display_enable (msm_dp_display, force_link_train); rc =msm_dp_display_post_enable (dp);@@ -1839,7 +1840,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,return ;if (!msm_dp_display->link_ready && status == connector_status_connected) -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,0 ); +msm_dp_hpd_plug_handle (dp,0 );else if (msm_dp_display->link_ready && status == connector_status_disconnected) -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); +msm_dp_hpd_unplug_handle (dp,0 ); }
Signature · 2 lines
With best wishes Dmitry
PATCH v2 5/12 drm/msm/dp: Drop EV_USER_NOTIFICATION
In reply to Jessica ZhangCurrently, we queue an event for signalling HPD connect/disconnect. This can mean a delay in plug/unplug handling and notifying DRM core when a hotplug happens.
Drop EV_USER_NOTIFICATION and signal the IRQ event as part of hotplug handling.
--- drivers/gpu/drm/msm/dp/dp_display.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +3 -8
@@ -58,7 +58,6 @@ enum {EV_HPD_PLUG_INT ,EV_IRQ_HPD_INT , EV_HPD_UNPLUG_INT, - EV_USER_NOTIFICATION, };#define EVENT_TIMEOUT (HZ/10)/* 100ms */
@@ -428,7 +427,7 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_reset_phy_params_vx_px (dp->link); -msm_dp_add_event (dp,EV_USER_NOTIFICATION , true,0 ); +msm_dp_display_send_hpd_notification (dp, true); end:return rc;
@@ -497,7 +496,7 @@ static int msm_dp_display_notify_disconnect(struct device *dev) {struct msm_dp_display_private *dp =dev_get_dp_display_private (dev); -msm_dp_add_event (dp,EV_USER_NOTIFICATION , false,0 ); +msm_dp_display_send_hpd_notification (dp, false);return 0 ; }
@@ -518,7 +517,7 @@ static int msm_dp_display_handle_port_status_changed(struct msm_dp_display_privadrm_dbg_dp (dp->drm_dev,"sink count is zero, nothing to do\n" );if (dp->hpd_state !=ST_DISCONNECTED ) { dp->hpd_state =ST_DISCONNECT_PENDING ; -msm_dp_add_event (dp,EV_USER_NOTIFICATION , false,0 ); +msm_dp_display_send_hpd_notification (dp, false); } }else {if (dp->hpd_state ==ST_DISCONNECTED ) {
@@ -1112,10 +1111,6 @@ static int hpd_event_thread(void *data)case EV_IRQ_HPD_INT :msm_dp_irq_hpd_handle (msm_dp_priv, todo->data);break ; -case EV_USER_NOTIFICATION : -msm_dp_display_send_hpd_notification (msm_dp_priv, - todo->data); -break ;default :break ; }
Signature · 1 line
2.50.1
Re: [PATCH v2 05/12] drm/msm/dp: Drop EV_USER_NOTIFICATION
Quoted 4 lines · Jessica Zhang
Currently, we queue an event for signalling HPD connect/disconnect. This can mean a delay in plug/unplug handling and notifying DRM core when a hotplug happens.
Quoted 8 lines
Drop
EV_USER_NOTIFICATIONand signal the IRQ event as part of hotplug handling.Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
This removes serialisation around msm_dp_display_send_hpd_notification(). This means that it can be called this function can be called in parallel, so we need to add locking around .link_ready access.
Signature · 2 lines
With best wishes Dmitry
PATCH v2 6/12 drm/msm/dp: Use drm_bridge_hpd_notify()
In reply to Jessica ZhangCall drm_bridge_hpd_notify() instead of drm_helper_hpd_irq_event(). This way, we can directly call hpd_notify() via the bridge connector.
--- drivers/gpu/drm/msm/dp/dp_display.c | 17 +++++------------ drivers/gpu/drm/msm/dp/dp_display.h | 1 + drivers/gpu/drm/msm/dp/dp_drm.c | 2 ++ 3 files changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +5 -12
@@ -333,17 +333,6 @@ static const struct component_ops msm_dp_display_comp_ops = { .unbind = msm_dp_display_unbind, }; -static void msm_dp_display_send_hpd_event (struct msm_dp *msm_dp_display) -{ -struct msm_dp_display_private *dp; -struct drm_connector *connector; - - dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); - - connector = dp->msm_dp_display.connector; -drm_helper_hpd_irq_event (connector->dev); -} -static int msm_dp_display_send_hpd_notification (struct msm_dp_display_private *dp,bool hpd) {
@@ -367,7 +356,11 @@ static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *ddrm_dbg_dp (dp->drm_dev,"type=%d hpd=%d\n" , dp->msm_dp_display.connector_type, hpd); -msm_dp_display_send_hpd_event (&dp->msm_dp_display); + +drm_bridge_hpd_notify (dp->msm_dp_display.bridge, + hpd ? + connector_status_connected : + connector_status_disconnected);return 0 ; }
drivers/gpu/drm/msm/dp/dp_display.h +1 -0
@@ -16,6 +16,7 @@ struct msm_dp {struct platform_device *pdev;struct drm_connector *connector;struct drm_bridge *next_bridge; +struct drm_bridge *bridge;bool link_ready;bool audio_enabled;bool power_on;
drivers/gpu/drm/msm/dp/dp_drm.c +2 -0
@@ -340,6 +340,8 @@ int msm_dp_bridge_init(struct msm_dp *msm_dp_display, struct drm_device *dev, } } + msm_dp_display->bridge = bridge; +return 0 ; }
Signature · 1 line
2.50.1
Re: [PATCH v2 06/12] drm/msm/dp: Use drm_bridge_hpd_notify()
Quoted 2 lines · Jessica Zhang
Call
drm_bridge_hpd_notify()instead ofdrm_helper_hpd_irq_event(). This way, we can directly callhpd_notify()via the bridge connector.
I can't understand the sentence.
Please start by describing the problem and why do you want to perform the change.
Quoted 31 lines
Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 17 +++++------------ drivers/gpu/drm/msm/dp/dp_display.h | 1 + drivers/gpu/drm/msm/dp/dp_drm.c | 2 ++ 3 files changed, 8 insertions(+), 12 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +0
-11@@ -333,17 +333,6 @@ static const struct component_ops msm_dp_display_comp_ops = { .unbind = msm_dp_display_unbind, }; -static void msm_dp_display_send_hpd_event (struct msm_dp *msm_dp_display) -{ -struct msm_dp_display_private *dp; -struct drm_connector *connector; - - dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); - - connector = dp->msm_dp_display.connector; -drm_helper_hpd_irq_event (connector->dev); -} -static int msm_dp_display_send_hpd_notification (struct msm_dp_display_private *dp,bool hpd) {
drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *d · line 363
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +5
-1@@ -367,7 +356,11 @@ static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *ddrm_dbg_dp (dp->drm_dev,"type=%d hpd=%d\n" , dp->msm_dp_display.connector_type, hpd); -msm_dp_display_send_hpd_event (&dp->msm_dp_display); + +drm_bridge_hpd_notify (dp->msm_dp_display.bridge, + hpd ? + connector_status_connected : + connector_status_disconnected);
I'd really prefer that at the end drm_bridge_hpd_notify() is called directly without extra wrappers.
Quoted 32 lines
drivers/gpu/drm/msm/dp/dp_display.c +0
-0return 0 ; }drivers/gpu/drm/msm/dp/dp_display.h +1
-0@@ -16,6 +16,7 @@ struct msm_dp {struct platform_device *pdev;struct drm_connector *connector;struct drm_bridge *next_bridge; +struct drm_bridge *bridge;bool link_ready;bool audio_enabled;bool power_on;drivers/gpu/drm/msm/dp/dp_drm.c +2
-0@@ -340,6 +340,8 @@ int msm_dp_bridge_init(struct msm_dp *msm_dp_display, struct drm_device *dev, } } + msm_dp_display->bridge = bridge; +return 0 ; }Signature · 2 lines
-- 2.50.1
Signature · 2 lines
With best wishes Dmitry
PATCH v2 7/12 drm/msm/dp: Handle internal HPD IRQ in hpd_notify()
In reply to Jessica ZhangSwitch to using a threaded IRQ to handle HPD IRQ events and moving handling of internal HPD IRQ events to hpd_notify().
This will simplify the handling of HPD events by unifying the handling of both external and internal HPD events in hpd_notify(). Also, having internal HPD IRQ use the DRM framework calls removes the need for msm_dp to track the HPD state internally.
Note: The setting of linked ready is moved out of *_send_hpd_notification() as it should only be set after the plug/unplug handling has been completed.
--- drivers/gpu/drm/msm/dp/dp_display.c | 127 +++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 37 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +90 -37
@@ -96,6 +96,10 @@ struct msm_dp_display_private {/* wait for audio signaling */ struct completion audio_comp; +/* HPD IRQ handling */ +spinlock_t irq_thread_lock; +u32 hpd_isr_status; +/* event related only access by event thread */ struct mutex event_mutex;wait_queue_head_t event_q;
@@ -345,14 +349,8 @@ static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *d/* reset video pattern flag on disconnect */ if (!hpd) { dp->panel->video_test = false; -if (!dp->msm_dp_display.is_edp) -drm_dp_set_subconnector_property (dp->msm_dp_display.connector, - connector_status_disconnected, - dp->panel->dpcd, - dp->panel->downstream_ports); } - dp->msm_dp_display.link_ready = hpd;drm_dbg_dp (dp->drm_dev,"type=%d hpd=%d\n" , dp->msm_dp_display.connector_type, hpd);
@@ -407,6 +405,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) dp->panel->dpcd, dp->panel->downstream_ports); + dp->msm_dp_display.link_ready = true; + dp->msm_dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled; dp->audio_supported = info->has_audio;
@@ -420,7 +420,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_reset_phy_params_vx_px (dp->link); -msm_dp_display_send_hpd_notification (dp, true); +if (!dp->msm_dp_display.internal_hpd) +msm_dp_display_send_hpd_notification (dp, true); end:return rc;
@@ -489,7 +490,16 @@ static int msm_dp_display_notify_disconnect(struct device *dev) {struct msm_dp_display_private *dp =dev_get_dp_display_private (dev); -msm_dp_display_send_hpd_notification (dp, false); +if (!dp->msm_dp_display.is_edp) +drm_dp_set_subconnector_property (dp->msm_dp_display.connector, + connector_status_disconnected, + dp->panel->dpcd, + dp->panel->downstream_ports); + + dp->msm_dp_display.link_ready = false; + +if (!dp->msm_dp_display.internal_hpd) +msm_dp_display_send_hpd_notification (dp, false);return 0 ; }
@@ -1182,40 +1192,56 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge)static irqreturn_t msm_dp_display_irq_handler (int irq,void *dev_id) {struct msm_dp_display_private *dp = dev_id; -irqreturn_t ret =IRQ_NONE ;u32 hpd_isr_status; - -if (!dp) { -DRM_ERROR ("invalid data\n" ); -return IRQ_NONE ; - } +unsigned long flags; +irqreturn_t ret =IRQ_HANDLED ; hpd_isr_status =msm_dp_aux_get_hpd_intr_status (dp->aux);if (hpd_isr_status &0x0F ) {drm_dbg_dp (dp->drm_dev,"type=%d isr=0x%x\n" , dp->msm_dp_display.connector_type, hpd_isr_status); -/* hpd related interrupts */ -if (hpd_isr_status &DP_DP_HPD_PLUG_INT_MASK ) -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,0 ); -if (hpd_isr_status &DP_DP_IRQ_HPD_INT_MASK ) { -msm_dp_add_event (dp,EV_IRQ_HPD_INT ,0 ,0 ); - } +spin_lock_irqsave (&dp->irq_thread_lock, flags); + dp->hpd_isr_status |= hpd_isr_status; + ret =IRQ_WAKE_THREAD ; +spin_unlock_irqrestore (&dp->irq_thread_lock, flags); + } -if (hpd_isr_status &DP_DP_HPD_REPLUG_INT_MASK ) { -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,3 ); - } +/* DP controller isr */ + ret |=msm_dp_ctrl_isr (dp->ctrl); -if (hpd_isr_status &DP_DP_HPD_UNPLUG_INT_MASK ) -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); +return ret; +} - ret =IRQ_HANDLED ; +static irqreturn_t msm_dp_display_irq_thread (int irq,void *dev_id) +{ +struct msm_dp_display_private *dp = dev_id; +irqreturn_t ret =IRQ_NONE ; +unsigned long flags; +u32 hpd_isr_status; + +if (!dp) { +DRM_ERROR ("invalid data\n" ); +return IRQ_NONE ; } -/* DP controller isr */ - ret |=msm_dp_ctrl_isr (dp->ctrl); +spin_lock_irqsave (&dp->irq_thread_lock, flags); + hpd_isr_status = dp->hpd_isr_status; + dp->hpd_isr_status =0 ; +spin_unlock_irqrestore (&dp->irq_thread_lock, flags); + +/* hpd related interrupts */ +if (hpd_isr_status &DP_DP_HPD_PLUG_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, true); + +if (hpd_isr_status &DP_DP_HPD_UNPLUG_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, false); + +if (hpd_isr_status &DP_DP_IRQ_HPD_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, true); + + ret =IRQ_HANDLED ;return ret; }
@@ -1231,9 +1257,13 @@ static int msm_dp_display_request_irq(struct msm_dp_display_private *dp)return dp->irq; } - rc =devm_request_irq (&pdev->dev, dp->irq, msm_dp_display_irq_handler, -IRQF_TRIGGER_HIGH |IRQF_NO_AUTOEN , -"dp_display_isr" , dp); +spin_lock_init (&dp->irq_thread_lock); +irq_set_status_flags (dp->irq,IRQ_NOAUTOEN ); + rc =devm_request_threaded_irq (&pdev->dev, dp->irq, + msm_dp_display_irq_handler, + msm_dp_display_irq_thread, +IRQ_TYPE_LEVEL_HIGH , +"dp_display_isr" , dp);if (rc <0 ) { DRM_ERROR("failed to request IRQ%u: %d\n",
@@ -1413,6 +1443,7 @@ static int msm_dp_display_probe(struct platform_device *pdev) dp->wide_bus_supported = desc->wide_bus_supported; dp->msm_dp_display.is_edp = (dp->msm_dp_display.connector_type == DRM_MODE_CONNECTOR_eDP); + dp->hpd_isr_status =0 ; rc =msm_dp_display_get_io (dp);if (rc)
@@ -1822,13 +1853,35 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,struct msm_dp_bridge *msm_dp_bridge =to_dp_bridge (bridge);struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display; struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); +u32 hpd_link_status =0 ; -/* Without next_bridge interrupts are handled by the DP core directly */ -if (msm_dp_display->internal_hpd) -return ; +if (msm_dp_display->internal_hpd) { +if (pm_runtime_resume_and_get (&msm_dp_display->pdev->dev)) { +DRM_ERROR ("failed to pm_runtime_resume\n" ); +return ; + } + + hpd_link_status =msm_dp_aux_is_link_connected (dp->aux); + } -if (!msm_dp_display->link_ready && status == connector_status_connected) +drm_dbg_dp (dp->drm_dev,"type=%d link connected=0x%x, link_ready=%d, status=%d\n" , + msm_dp_display->connector_type, hpd_link_status, + msm_dp_display->link_ready, status); + +if ((!msm_dp_display->internal_hpd || hpd_link_status ==ISR_CONNECTED ) && + status == connector_status_connected) +msm_dp_hpd_plug_handle (dp,0 ); +else if ((hpd_link_status ==ISR_IRQ_HPD_PULSE_COUNT ) && + status == connector_status_connected) +msm_dp_irq_hpd_handle (dp,0 ); +else if (hpd_link_status ==ISR_HPD_REPLUG_COUNT ) {msm_dp_hpd_plug_handle (dp,0 ); -else if (msm_dp_display->link_ready && status == connector_status_disconnected)msm_dp_hpd_unplug_handle (dp,0 ); + }else if ((!msm_dp_display->internal_hpd || + hpd_link_status ==ISR_DISCONNECTED ) && + status == connector_status_disconnected) +msm_dp_hpd_unplug_handle (dp,0 ); + +if (msm_dp_display->internal_hpd) +pm_runtime_put_sync (&msm_dp_display->pdev->dev); }
Signature · 1 line
2.50.1
Re: [PATCH v2 07/12] drm/msm/dp: Handle internal HPD IRQ in hpd_notify()
Quoted 7 lines · Jessica Zhang
Switch to using a threaded IRQ to handle HPD IRQ events and moving handling of internal HPD IRQ events to
hpd_notify().This will simplify the handling of HPD events by unifying the handling of both external and internal HPD events in
hpd_notify(). Also, having internal HPD IRQ use the DRM framework calls removes the need formsm_dpto track the HPD state internally.
You should describe, why are you splitting the handler into two parts rather than just moving existing handler to be a threaded handler.
Quoted 4 lines
Note: The setting of linked ready is moved out of
*_send_hpd_notification()as it should only be set after the plug/unplug handling has been completed.
Unrelated
Quoted 46 lines
Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 127 +++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 37 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +6
-6@@ -96,6 +96,10 @@ struct msm_dp_display_private {/* wait for audio signaling */ struct completion audio_comp; +/* HPD IRQ handling */ +spinlock_t irq_thread_lock; +u32 hpd_isr_status; +/* event related only access by event thread */ struct mutex event_mutex;wait_queue_head_t event_q;@@ -345,14 +349,8 @@ static int msm_dp_display_send_hpd_notification(struct msm_dp_display_private *d/* reset video pattern flag on disconnect */ if (!hpd) { dp->panel->video_test = false; -if (!dp->msm_dp_display.is_edp) -drm_dp_set_subconnector_property (dp->msm_dp_display.connector, - connector_status_disconnected, - dp->panel->dpcd, - dp->panel->downstream_ports); } - dp->msm_dp_display.link_ready = hpd;drm_dbg_dp (dp->drm_dev,"type=%d hpd=%d\n" , dp->msm_dp_display.connector_type, hpd);@@ -407,6 +405,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) dp->panel->dpcd, dp->panel->downstream_ports); + dp->msm_dp_display.link_ready = true; + dp->msm_dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled; dp->audio_supported = info->has_audio;
drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) · line 423
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +1
-1@@ -420,7 +420,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)msm_dp_link_reset_phy_params_vx_px (dp->link); -msm_dp_display_send_hpd_notification (dp, true); +if (!dp->msm_dp_display.internal_hpd)
Why?
Quoted 72 lines
drivers/gpu/drm/msm/dp/dp_display.c +27
-20+msm_dp_display_send_hpd_notification (dp, true); end:return rc;@@ -489,7 +490,16 @@ static int msm_dp_display_notify_disconnect(struct device *dev) {struct msm_dp_display_private *dp =dev_get_dp_display_private (dev); -msm_dp_display_send_hpd_notification (dp, false); +if (!dp->msm_dp_display.is_edp) +drm_dp_set_subconnector_property (dp->msm_dp_display.connector, + connector_status_disconnected, + dp->panel->dpcd, + dp->panel->downstream_ports); + + dp->msm_dp_display.link_ready = false; + +if (!dp->msm_dp_display.internal_hpd) +msm_dp_display_send_hpd_notification (dp, false);return 0 ; }@@ -1182,40 +1192,56 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge)static irqreturn_t msm_dp_display_irq_handler (int irq,void *dev_id) {struct msm_dp_display_private *dp = dev_id; -irqreturn_t ret =IRQ_NONE ;u32 hpd_isr_status; - -if (!dp) { -DRM_ERROR ("invalid data\n" ); -return IRQ_NONE ; - } +unsigned long flags; +irqreturn_t ret =IRQ_HANDLED ; hpd_isr_status =msm_dp_aux_get_hpd_intr_status (dp->aux);if (hpd_isr_status &0x0F ) {drm_dbg_dp (dp->drm_dev,"type=%d isr=0x%x\n" , dp->msm_dp_display.connector_type, hpd_isr_status); -/* hpd related interrupts */ -if (hpd_isr_status &DP_DP_HPD_PLUG_INT_MASK ) -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,0 ); -if (hpd_isr_status &DP_DP_IRQ_HPD_INT_MASK ) { -msm_dp_add_event (dp,EV_IRQ_HPD_INT ,0 ,0 ); - } +spin_lock_irqsave (&dp->irq_thread_lock, flags); + dp->hpd_isr_status |= hpd_isr_status; + ret =IRQ_WAKE_THREAD ; +spin_unlock_irqrestore (&dp->irq_thread_lock, flags); + } -if (hpd_isr_status &DP_DP_HPD_REPLUG_INT_MASK ) { -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,3 ); - } +/* DP controller isr */ + ret |=msm_dp_ctrl_isr (dp->ctrl); -if (hpd_isr_status &DP_DP_HPD_UNPLUG_INT_MASK ) -msm_dp_add_event (dp,EV_HPD_UNPLUG_INT ,0 ,0 ); +return ret; +} - ret =IRQ_HANDLED ; +static irqreturn_t msm_dp_display_irq_thread (int irq,void *dev_id) +{ +struct msm_dp_display_private *dp = dev_id; +irqreturn_t ret =IRQ_NONE ; +unsigned long flags;
drivers/gpu/drm/msm/dp/dp_display.c enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge) · line 1229
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +6
-2+u32 hpd_isr_status; + +if (!dp) { +DRM_ERROR ("invalid data\n" ); +return IRQ_NONE ; } -/* DP controller isr */ - ret |=msm_dp_ctrl_isr (dp->ctrl); +spin_lock_irqsave (&dp->irq_thread_lock, flags);
You don't need to save/restore flags in the IRQ handler.
Quoted 44 lines
drivers/gpu/drm/msm/dp/dp_display.c +23
-3+ hpd_isr_status = dp->hpd_isr_status; + dp->hpd_isr_status =0 ; +spin_unlock_irqrestore (&dp->irq_thread_lock, flags); + +/* hpd related interrupts */ +if (hpd_isr_status &DP_DP_HPD_PLUG_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, true); + +if (hpd_isr_status &DP_DP_HPD_UNPLUG_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, false); + +if (hpd_isr_status &DP_DP_IRQ_HPD_INT_MASK ) +msm_dp_display_send_hpd_notification (dp, true); + + ret =IRQ_HANDLED ;return ret; }@@ -1231,9 +1257,13 @@ static int msm_dp_display_request_irq(struct msm_dp_display_private *dp)return dp->irq; } - rc =devm_request_irq (&pdev->dev, dp->irq, msm_dp_display_irq_handler, -IRQF_TRIGGER_HIGH |IRQF_NO_AUTOEN , -"dp_display_isr" , dp); +spin_lock_init (&dp->irq_thread_lock); +irq_set_status_flags (dp->irq,IRQ_NOAUTOEN ); + rc =devm_request_threaded_irq (&pdev->dev, dp->irq, + msm_dp_display_irq_handler, + msm_dp_display_irq_thread, +IRQ_TYPE_LEVEL_HIGH , +"dp_display_isr" , dp);if (rc <0 ) { DRM_ERROR("failed to request IRQ%u: %d\n",@@ -1413,6 +1443,7 @@ static int msm_dp_display_probe(struct platform_device *pdev) dp->wide_bus_supported = desc->wide_bus_supported; dp->msm_dp_display.is_edp = (dp->msm_dp_display.connector_type == DRM_MODE_CONNECTOR_eDP); + dp->hpd_isr_status =0 ; rc =msm_dp_display_get_io (dp);if (rc)
drivers/gpu/drm/msm/dp/dp_display.c void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge, · line 1858
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +2
-3@@ -1822,13 +1853,35 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,struct msm_dp_bridge *msm_dp_bridge =to_dp_bridge (bridge);struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display; struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); +u32 hpd_link_status =0 ; -/* Without next_bridge interrupts are handled by the DP core directly */ -if (msm_dp_display->internal_hpd) -return ; +if (msm_dp_display->internal_hpd) {
Why? The .internal_hpd should be gone completely, there should be no difference between those two paths.
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_display.c +7
-0+if (pm_runtime_resume_and_get (&msm_dp_display->pdev->dev)) { +DRM_ERROR ("failed to pm_runtime_resume\n" ); +return ; + } + + hpd_link_status =msm_dp_aux_is_link_connected (dp->aux); + }
drivers/gpu/drm/msm/dp/dp_display.c void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge, · line 1875
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +9
-1-if (!msm_dp_display->link_ready && status == connector_status_connected) +drm_dbg_dp (dp->drm_dev,"type=%d link connected=0x%x, link_ready=%d, status=%d\n" , + msm_dp_display->connector_type, hpd_link_status, + msm_dp_display->link_ready, status); + +if ((!msm_dp_display->internal_hpd || hpd_link_status ==ISR_CONNECTED ) && + status == connector_status_connected) +msm_dp_hpd_plug_handle (dp,0 ); +else if ((hpd_link_status ==ISR_IRQ_HPD_PULSE_COUNT ) && + status == connector_status_connected)
wrong indentation
Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_display.c +9
-1+msm_dp_irq_hpd_handle (dp,0 ); + else if (hpd_link_status == ISR_HPD_REPLUG_COUNT) {msm_dp_hpd_plug_handle (dp,0 ); - else if (msm_dp_display->link_ready && status == connector_status_disconnected)msm_dp_hpd_unplug_handle (dp,0 ); + } else if ((!msm_dp_display->internal_hpd || + hpd_link_status == ISR_DISCONNECTED) && + status == connector_status_disconnected) +msm_dp_hpd_unplug_handle (dp,0 ); + +if (msm_dp_display->internal_hpd) +pm_runtime_put_sync (&msm_dp_display->pdev->dev); }Signature · 2 lines
-- 2.50.1
Signature · 2 lines
With best wishes Dmitry
PATCH v2 8/12 drm/msm/dp: Drop event waitqueue
In reply to Jessica ZhangSince the HPD IRQ handler directly notifies DRM core for hotplug events, there is no need to maintain a separate event waitqueue.
Drop the event waitqueue and all related structs and helpers.
--- drivers/gpu/drm/msm/dp/dp_display.c | 255 +----------------------------------- 1 file changed, 7 insertions(+), 248 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +7 -248
@@ -52,27 +52,6 @@ enum { ST_DISPLAY_OFF, }; -enum { -EV_NO_EVENT , -/* hpd events */ -EV_HPD_PLUG_INT , -EV_IRQ_HPD_INT , -EV_HPD_UNPLUG_INT , -}; - -#define EVENT_TIMEOUT (HZ/10)/* 100ms */ -#define DP_EVENT_Q_MAX 8 - -#define DP_TIMEOUT_NONE 0 - -#define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2) - -struct msm_dp_event { -u32 event_id; -u32 data; -u32 delay; -}; -struct msm_dp_display_private {int irq;
@@ -100,16 +79,7 @@ struct msm_dp_display_private {spinlock_t irq_thread_lock;u32 hpd_isr_status; -/* event related only access by event thread */ -struct mutex event_mutex; -wait_queue_head_t event_q;u32 hpd_state; -u32 event_pndx; -u32 event_gndx; -struct task_struct *ev_tsk; -struct msm_dp_event event_list[DP_EVENT_Q_MAX ]; -spinlock_t event_lock; -bool wide_bus_supported;struct msm_dp_audio *audio;
@@ -212,60 +182,6 @@ static struct msm_dp_display_private *dev_get_dp_display_private(struct device * return container_of(dp, struct msm_dp_display_private, msm_dp_display); } -static int msm_dp_add_event (struct msm_dp_display_private *msm_dp_priv,u32 event, -u32 data,u32 delay) -{ -unsigned long flag; -struct msm_dp_event *todo; -int pndx; - -spin_lock_irqsave (&msm_dp_priv->event_lock, flag); - pndx = msm_dp_priv->event_pndx +1 ; - pndx %=DP_EVENT_Q_MAX ; -if (pndx == msm_dp_priv->event_gndx) { -pr_err ("event_q is full: pndx=%d gndx=%d\n" , - msm_dp_priv->event_pndx, msm_dp_priv->event_gndx); -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -return -EPERM ; - } - todo = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++]; - msm_dp_priv->event_pndx %=DP_EVENT_Q_MAX ; - todo->event_id = event; - todo->data = data; - todo->delay = delay; -wake_up (&msm_dp_priv->event_q); -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); - -return 0 ; -} - -static int msm_dp_del_event (struct msm_dp_display_private *msm_dp_priv,u32 event) -{ -unsigned long flag; -struct msm_dp_event *todo; -u32 gndx; - -spin_lock_irqsave (&msm_dp_priv->event_lock, flag); -if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) { -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -return -ENOENT ; - } - - gndx = msm_dp_priv->event_gndx; -while (msm_dp_priv->event_pndx != gndx) { - todo = &msm_dp_priv->event_list[gndx]; -if (todo->event_id == event) { - todo->event_id =EV_NO_EVENT ;/* deleted */ - todo->delay =0 ; - } - gndx++; - gndx %=DP_EVENT_Q_MAX ; - } -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); - -return 0 ; -} -void msm_dp_display_signal_audio_start (struct msm_dp *msm_dp_display) {struct msm_dp_display_private *dp;
@@ -284,8 +200,6 @@ void msm_dp_display_signal_audio_complete(struct msm_dp *msm_dp_display)complete_all (&dp->audio_comp); } -static int msm_dp_hpd_event_thread_start (struct msm_dp_display_private *msm_dp_priv); -static int msm_dp_display_bind (struct device *dev,struct device *master,void *data) {
@@ -305,12 +219,6 @@ static int msm_dp_display_bind(struct device *dev, struct device *master, goto end; } - rc =msm_dp_hpd_event_thread_start (dp); -if (rc) { -DRM_ERROR ("Event thread create failed\n" ); - goto end; - } -return 0 ; end:return rc;
@@ -322,8 +230,6 @@ static void msm_dp_display_unbind(struct device *dev, struct device *master,struct msm_dp_display_private *dp =dev_get_dp_display_private (dev);struct msm_drm_private *priv =dev_get_drvdata (master); -kthread_stop (dp->ev_tsk); -of_dp_aux_depopulate_bus (dp->aux);msm_dp_aux_unregister (dp->aux);
@@ -585,33 +491,22 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)msm_dp_aux_enable_xfers (dp->aux, true); -mutex_lock (&dp->event_mutex); - state = dp->hpd_state;drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -if (state ==ST_DISPLAY_OFF ) { -mutex_unlock (&dp->event_mutex); +if (state ==ST_DISPLAY_OFF )return 0 ; - } -if (state ==ST_MAINLINK_READY || state ==ST_CONNECTED ) { -mutex_unlock (&dp->event_mutex); +if (state ==ST_MAINLINK_READY || state ==ST_CONNECTED )return 0 ; - } -if (state ==ST_DISCONNECT_PENDING ) { -/* wait until ST_DISCONNECTED */ -msm_dp_add_event (dp,EV_HPD_PLUG_INT ,0 ,1 );/* delay = 1 */ -mutex_unlock (&dp->event_mutex); +if (state ==ST_DISCONNECT_PENDING )return 0 ; - } ret =pm_runtime_resume_and_get (&pdev->dev);if (ret) {DRM_ERROR ("failed to pm_runtime_resume\n" ); -mutex_unlock (&dp->event_mutex);return ret; }
@@ -625,7 +520,6 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)drm_dbg_dp (dp->drm_dev,"After, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -mutex_unlock (&dp->event_mutex);/* uevent will complete connection part */ return 0 ;
@@ -652,26 +546,19 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)msm_dp_aux_enable_xfers (dp->aux, false); -mutex_lock (&dp->event_mutex); - state = dp->hpd_state;drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -/* unplugged, no more irq_hpd handle */ -msm_dp_del_event (dp,EV_IRQ_HPD_INT ); -if (state ==ST_DISCONNECTED ) {/* triggered by irq_hdp with sink_count = 0 */ if (dp->link->sink_count ==0 ) {msm_dp_display_host_phy_exit (dp); }msm_dp_display_notify_disconnect (&dp->msm_dp_display.pdev->dev); -mutex_unlock (&dp->event_mutex);return 0 ; }else if (state ==ST_DISCONNECT_PENDING ) { -mutex_unlock (&dp->event_mutex);return 0 ; }else if (state ==ST_MAINLINK_READY ) {msm_dp_ctrl_off_link (dp->ctrl);
@@ -679,7 +566,6 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data) dp->hpd_state =ST_DISCONNECTED ;msm_dp_display_notify_disconnect (&dp->msm_dp_display.pdev->dev);pm_runtime_put_sync (&pdev->dev); -mutex_unlock (&dp->event_mutex);return 0 ; }
@@ -703,7 +589,6 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)/* uevent will complete disconnection part */ pm_runtime_put_sync (&pdev->dev); -mutex_unlock (&dp->event_mutex);return 0 ; }
@@ -711,32 +596,22 @@ static int msm_dp_irq_hpd_handle(struct msm_dp_display_private *dp, u32 data) {u32 state; -mutex_lock (&dp->event_mutex); -/* irq_hpd can happen at either connected or disconnected state */ state = dp->hpd_state;drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -if (state ==ST_DISPLAY_OFF ) { -mutex_unlock (&dp->event_mutex); +if (state ==ST_DISPLAY_OFF )return 0 ; - } -if (state ==ST_MAINLINK_READY || state ==ST_DISCONNECT_PENDING ) { -/* wait until ST_CONNECTED */ -msm_dp_add_event (dp,EV_IRQ_HPD_INT ,0 ,1 );/* delay = 1 */ -mutex_unlock (&dp->event_mutex); +if (state ==ST_MAINLINK_READY || state ==ST_DISCONNECT_PENDING )return 0 ; - }msm_dp_display_usbpd_attention_cb (&dp->msm_dp_display.pdev->dev);drm_dbg_dp (dp->drm_dev,"After, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -mutex_unlock (&dp->event_mutex); -return 0 ; }
@@ -1013,12 +888,8 @@ void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp)* power_on status before dumping DP registers to avoid crash due * to unclocked access */ -mutex_lock (&msm_dp_display->event_mutex); - -if (!dp->power_on) { -mutex_unlock (&msm_dp_display->event_mutex); +if (!dp->power_on)return ; - }msm_disp_snapshot_add_block (disp_state, msm_dp_display->ahb_len, msm_dp_display->ahb_base,"dp_ahb" );
@@ -1028,8 +899,6 @@ void msm_dp_snapshot(struct msm_disp_state *disp_state, struct msm_dp *dp) msm_dp_display->link_base, "dp_link");msm_disp_snapshot_add_block (disp_state, msm_dp_display->p0_len, msm_dp_display->p0_base,"dp_p0" ); - -mutex_unlock (&msm_dp_display->event_mutex); }void msm_dp_display_set_psr (struct msm_dp *msm_dp_display,bool enter)
@@ -1045,96 +914,6 @@ void msm_dp_display_set_psr(struct msm_dp *msm_dp_display, bool enter)msm_dp_ctrl_set_psr (dp->ctrl, enter); } -static int hpd_event_thread (void *data) -{ -struct msm_dp_display_private *msm_dp_priv; -unsigned long flag; -struct msm_dp_event *todo; -int timeout_mode =0 ; - - msm_dp_priv = (struct msm_dp_display_private *)data; - -while (1 ) { -if (timeout_mode) { -wait_event_timeout (msm_dp_priv->event_q, - (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) || -kthread_should_stop (),EVENT_TIMEOUT ); - }else { -wait_event_interruptible (msm_dp_priv->event_q, - (msm_dp_priv->event_pndx != msm_dp_priv->event_gndx) || -kthread_should_stop ()); - } - -if (kthread_should_stop ()) -break ; - -spin_lock_irqsave (&msm_dp_priv->event_lock, flag); - todo = &msm_dp_priv->event_list[msm_dp_priv->event_gndx]; -if (todo->delay) { -struct msm_dp_event *todo_next; - - msm_dp_priv->event_gndx++; - msm_dp_priv->event_gndx %=DP_EVENT_Q_MAX ; - -/* re enter delay event into q */ - todo_next = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++]; - msm_dp_priv->event_pndx %=DP_EVENT_Q_MAX ; - todo_next->event_id = todo->event_id; - todo_next->data = todo->data; - todo_next->delay = todo->delay -1 ; - -/* clean up older event */ - todo->event_id =EV_NO_EVENT ; - todo->delay =0 ; - -/* switch to timeout mode */ - timeout_mode =1 ; -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -continue ; - } - -/* timeout with no events in q */ -if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) { -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -continue ; - } - - msm_dp_priv->event_gndx++; - msm_dp_priv->event_gndx %=DP_EVENT_Q_MAX ; - timeout_mode =0 ; -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); - -switch (todo->event_id) { -case EV_HPD_PLUG_INT : -msm_dp_hpd_plug_handle (msm_dp_priv, todo->data); -break ; -case EV_HPD_UNPLUG_INT : -msm_dp_hpd_unplug_handle (msm_dp_priv, todo->data); -break ; -case EV_IRQ_HPD_INT : -msm_dp_irq_hpd_handle (msm_dp_priv, todo->data); -break ; -default : -break ; - } - } - -return 0 ; -} - -static int msm_dp_hpd_event_thread_start (struct msm_dp_display_private *msm_dp_priv) -{ -/* set event q to empty */ - msm_dp_priv->event_gndx =0 ; - msm_dp_priv->event_pndx =0 ; - - msm_dp_priv->ev_tsk =kthread_run (hpd_event_thread, msm_dp_priv,"dp_hpd_handler" ); -if (IS_ERR (msm_dp_priv->ev_tsk)) -return PTR_ERR (msm_dp_priv->ev_tsk); - -return 0 ; -} -/** * msm_dp_bridge_detect - callback to determine if connector is connected * @bridge: Pointer to drm bridge structure
@@ -1455,11 +1234,6 @@ static int msm_dp_display_probe(struct platform_device *pdev)return -EPROBE_DEFER ; } -/* setup event q */ -mutex_init (&dp->event_mutex); -init_waitqueue_head (&dp->event_q); -spin_lock_init (&dp->event_lock); -/* Store DP audio handle inside DP display */ dp->msm_dp_display.msm_dp_audio = dp->audio;
@@ -1667,23 +1441,18 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge,if (dp->is_edp)msm_dp_hpd_plug_handle (msm_dp_display,0 ); -mutex_lock (&msm_dp_display->event_mutex);if (pm_runtime_resume_and_get (&dp->pdev->dev)) {DRM_ERROR ("failed to pm_runtime_resume\n" ); -mutex_unlock (&msm_dp_display->event_mutex);return ; } hpd_state = msm_dp_display->hpd_state; -if (hpd_state !=ST_DISPLAY_OFF && hpd_state !=ST_MAINLINK_READY ) { -mutex_unlock (&msm_dp_display->event_mutex); +if (hpd_state !=ST_DISPLAY_OFF && hpd_state !=ST_MAINLINK_READY )return ; - } rc =msm_dp_display_set_mode (dp, &msm_dp_display->msm_dp_mode);if (rc) {DRM_ERROR ("Failed to perform a mode set, rc=%d\n" , rc); -mutex_unlock (&msm_dp_display->event_mutex);return ; }
@@ -1712,7 +1481,6 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, msm_dp_display->hpd_state =ST_CONNECTED ;drm_dbg_dp (dp->drm_dev,"type=%d Done\n" , dp->connector_type); -mutex_unlock (&msm_dp_display->event_mutex); } void msm_dp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
@@ -1740,8 +1508,6 @@ void msm_dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,if (dp->is_edp)msm_dp_hpd_unplug_handle (msm_dp_display,0 ); -mutex_lock (&msm_dp_display->event_mutex); - hpd_state = msm_dp_display->hpd_state;if (hpd_state !=ST_DISCONNECT_PENDING && hpd_state !=ST_CONNECTED ) drm_dbg_dp(dp->drm_dev, "type=%d wrong hpd_state=%d\n",
@@ -1760,7 +1526,6 @@ void msm_dp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,drm_dbg_dp (dp->drm_dev,"type=%d Done\n" , dp->connector_type);pm_runtime_put_sync (&dp->pdev->dev); -mutex_unlock (&msm_dp_display->event_mutex); } void msm_dp_bridge_mode_set(struct drm_bridge *drm_bridge,
@@ -1816,10 +1581,8 @@ void msm_dp_bridge_hpd_enable(struct drm_bridge *bridge)* step-4: DP PHY is initialized at plugin handler before link training * */ -mutex_lock (&dp->event_mutex);if (pm_runtime_resume_and_get (&msm_dp_display->pdev->dev)) {DRM_ERROR ("failed to resume power\n" ); -mutex_unlock (&dp->event_mutex);return ; }
@@ -1827,7 +1590,6 @@ void msm_dp_bridge_hpd_enable(struct drm_bridge *bridge)msm_dp_aux_hpd_intr_enable (dp->aux); msm_dp_display->internal_hpd = true; -mutex_unlock (&dp->event_mutex); }void msm_dp_bridge_hpd_disable (struct drm_bridge *bridge)
@@ -1836,15 +1598,12 @@ void msm_dp_bridge_hpd_disable(struct drm_bridge *bridge)struct msm_dp *msm_dp_display = msm_dp_bridge->msm_dp_display; struct msm_dp_display_private *dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); -mutex_lock (&dp->event_mutex); -msm_dp_aux_hpd_intr_disable (dp->aux);msm_dp_aux_hpd_disable (dp->aux); msm_dp_display->internal_hpd = false;pm_runtime_put_sync (&msm_dp_display->pdev->dev); -mutex_unlock (&dp->event_mutex); } void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
Signature · 1 line
2.50.1
Re: [PATCH v2 08/12] drm/msm/dp: Drop event waitqueue
Quoted 152 lines · Jessica Zhang
Since the HPD IRQ handler directly notifies DRM core for hotplug events, there is no need to maintain a separate event waitqueue.
Drop the event waitqueue and all related structs and helpers.
Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_display.c | 255 +----------------------------------- 1 file changed, 7 insertions(+), 248 deletions(-)drivers/gpu/drm/msm/dp/dp_display.c +0
-94@@ -52,27 +52,6 @@ enum { ST_DISPLAY_OFF, }; -enum { -EV_NO_EVENT , -/* hpd events */ -EV_HPD_PLUG_INT , -EV_IRQ_HPD_INT , -EV_HPD_UNPLUG_INT , -}; - -#define EVENT_TIMEOUT (HZ/10)/* 100ms */ -#define DP_EVENT_Q_MAX 8 - -#define DP_TIMEOUT_NONE 0 - -#define WAIT_FOR_RESUME_TIMEOUT_JIFFIES (HZ / 2) - -struct msm_dp_event { -u32 event_id; -u32 data; -u32 delay; -}; -struct msm_dp_display_private {int irq;@@ -100,16 +79,7 @@ struct msm_dp_display_private {spinlock_t irq_thread_lock;u32 hpd_isr_status; -/* event related only access by event thread */ -struct mutex event_mutex; -wait_queue_head_t event_q;u32 hpd_state; -u32 event_pndx; -u32 event_gndx; -struct task_struct *ev_tsk; -struct msm_dp_event event_list[DP_EVENT_Q_MAX ]; -spinlock_t event_lock; -bool wide_bus_supported;struct msm_dp_audio *audio;@@ -212,60 +182,6 @@ static struct msm_dp_display_private *dev_get_dp_display_private(struct device * return container_of(dp, struct msm_dp_display_private, msm_dp_display); } -static int msm_dp_add_event (struct msm_dp_display_private *msm_dp_priv,u32 event, -u32 data,u32 delay) -{ -unsigned long flag; -struct msm_dp_event *todo; -int pndx; - -spin_lock_irqsave (&msm_dp_priv->event_lock, flag); - pndx = msm_dp_priv->event_pndx +1 ; - pndx %=DP_EVENT_Q_MAX ; -if (pndx == msm_dp_priv->event_gndx) { -pr_err ("event_q is full: pndx=%d gndx=%d\n" , - msm_dp_priv->event_pndx, msm_dp_priv->event_gndx); -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -return -EPERM ; - } - todo = &msm_dp_priv->event_list[msm_dp_priv->event_pndx++]; - msm_dp_priv->event_pndx %=DP_EVENT_Q_MAX ; - todo->event_id = event; - todo->data = data; - todo->delay = delay; -wake_up (&msm_dp_priv->event_q); -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); - -return 0 ; -} - -static int msm_dp_del_event (struct msm_dp_display_private *msm_dp_priv,u32 event) -{ -unsigned long flag; -struct msm_dp_event *todo; -u32 gndx; - -spin_lock_irqsave (&msm_dp_priv->event_lock, flag); -if (msm_dp_priv->event_pndx == msm_dp_priv->event_gndx) { -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); -return -ENOENT ; - } - - gndx = msm_dp_priv->event_gndx; -while (msm_dp_priv->event_pndx != gndx) { - todo = &msm_dp_priv->event_list[gndx]; -if (todo->event_id == event) { - todo->event_id =EV_NO_EVENT ;/* deleted */ - todo->delay =0 ; - } - gndx++; - gndx %=DP_EVENT_Q_MAX ; - } -spin_unlock_irqrestore (&msm_dp_priv->event_lock, flag); - -return 0 ; -} -void msm_dp_display_signal_audio_start (struct msm_dp *msm_dp_display) {struct msm_dp_display_private *dp;@@ -284,8 +200,6 @@ void msm_dp_display_signal_audio_complete(struct msm_dp *msm_dp_display)complete_all (&dp->audio_comp); } -static int msm_dp_hpd_event_thread_start (struct msm_dp_display_private *msm_dp_priv); -static int msm_dp_display_bind (struct device *dev,struct device *master,void *data) {@@ -305,12 +219,6 @@ static int msm_dp_display_bind(struct device *dev, struct device *master, goto end; } - rc =msm_dp_hpd_event_thread_start (dp); -if (rc) { -DRM_ERROR ("Event thread create failed\n" ); - goto end; - } -return 0 ; end:return rc;@@ -322,8 +230,6 @@ static void msm_dp_display_unbind(struct device *dev, struct device *master,struct msm_dp_display_private *dp =dev_get_dp_display_private (dev);struct msm_drm_private *priv =dev_get_drvdata (master); -kthread_stop (dp->ev_tsk); -of_dp_aux_depopulate_bus (dp->aux);msm_dp_aux_unregister (dp->aux);
drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data) · line 588
Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_display.c +0
-1@@ -585,33 +491,22 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)msm_dp_aux_enable_xfers (dp->aux, true); -mutex_lock (&dp->event_mutex);
I think the event_mutex should be kept as is. Otherwise we don't have protection against delivering the next event while we still process the previous one.
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +0
-1- state = dp->hpd_state;drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state);
Signature · 2 lines
With best wishes Dmitry
PATCH v2 9/12 drm/msm/dp: remove redundant checks related to ST_DISPLAY_OFF in plug handler
In reply to Jessica ZhangFrom: Abhinav Kumar <[email protected]>
In commit 8ede2ecc3e5ee ("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets"), checks were introduced to avoid handling any plug event in ST_DISPLAY_OFF state.
Even if we do get hpd events, after the bridge was disabled, it should get handled. Moreover, its unclear under what circumstances these events will fire because ST_DISPLAY_OFF means that the link was still connected but only the bridge was disabled. If the link was untouched, then interrupts shouldn't fire.
Even in the case of the DP compliance equipment, it should be raising these interrupts during the start of the test which is usually accompanied with either a HPD pulse or a IRQ HPD but after the bridge is disabled it should be fine to handle these anyway. In the absence of a better reason to keep these checks, drop these and if any other issues do arise, it should be handled in a different way.
---
Note: Taken from https://patchwork.freedesktop.org/series/142010/
--- drivers/gpu/drm/msm/dp/dp_display.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +0 -3
@@ -495,9 +495,6 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -if (state ==ST_DISPLAY_OFF ) -return 0 ; -if (state ==ST_MAINLINK_READY || state ==ST_CONNECTED )return 0 ;
Signature · 1 line
2.50.1
Re: [PATCH v2 09/12] drm/msm/dp: remove redundant checks related to ST_DISPLAY_OFF in plug handler
Quoted 19 lines · Jessica Zhang
From: Abhinav Kumar <[email protected]>
In commit
8ede2ecc3e5ee("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets"), checks were introduced to avoid handling any plug event inST_DISPLAY_OFFstate.Even if we do get hpd events, after the bridge was disabled, it should get handled. Moreover, its unclear under what circumstances these events will fire because
ST_DISPLAY_OFFmeans that the link was still connected but only the bridge was disabled. If the link was untouched, then interrupts shouldn't fire.Even in the case of the DP compliance equipment, it should be raising these interrupts during the start of the test which is usually accompanied with either a HPD pulse or a IRQ HPD but after the bridge is disabled it should be fine to handle these anyway. In the absence of a better reason to keep these checks, drop these and if any other issues do arise, it should be handled in a different way.
Quoted 7 lines
Signed-off-by Abhinav Kumar <[email protected]>Signed-off-by Jessica Zhang <[email protected]>---
Note: Taken from https://patchwork.freedesktop.org/series/142010/--- drivers/gpu/drm/msm/dp/dp_display.c | 3 --- 1 file changed, 3 deletions(-)
I think this patch and the next one should be folded into the 'drop the HPD state machine' patch. It would be easier to review.
Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_display.c +0
-3@@ -495,9 +495,6 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)drm_dbg_dp (dp->drm_dev,"Before, type=%d hpd_state=%d\n" , dp->msm_dp_display.connector_type, state); -if (state ==ST_DISPLAY_OFF ) -return 0 ; -if (state ==ST_MAINLINK_READY || state ==ST_CONNECTED )return 0 ;Signature · 2 lines
-- 2.50.1
Signature · 2 lines
With best wishes Dmitry
PATCH v2 10/12 drm/msm/dp: Return early from atomic_enable() if cable is not connected
In reply to Jessica ZhangReplace the ST_MAINLINK_READY check here with a check for sink count.
Since atomic_check() fails if the link isn't ready, we technically don't need a check against ST_MAINLINK_READY. The hpd_state should also never really hit ST_DISPLAY_OFF since atomic_enable() shouldn't be called twice in a row without an atomic_disable() in between.
That being said, it is possible for the cable to be disconnected after atomic_check() but before atomic_enable(). So let's change this check to guard against sink_count instead.
--- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dp/dp_display.c +1 -1
@@ -1444,7 +1444,7 @@ void msm_dp_bridge_atomic_enable(struct drm_bridge *drm_bridge, } hpd_state = msm_dp_display->hpd_state; -if (hpd_state !=ST_DISPLAY_OFF && hpd_state !=ST_MAINLINK_READY ) +if (msm_dp_display->link->sink_count ==0 )return ; rc =msm_dp_display_set_mode (dp, &msm_dp_display->msm_dp_mode);
Signature · 1 line
2.50.1
PATCH v2 11/12 drm/msm/dp: drop the entire HPD state machine
In reply to Jessica ZhangSince internal HPD IRQ event handling has been moved to being handled by the DRM framework detect() and hpd_notify() callbacks, there is no need for the MSM driver to track the HPD state separately.
Drop all references to the HPD state machine and replace existing checks with checks for link_ready or sink_count.
--- drivers/gpu/drm/msm/dp/dp_ctrl.c | 22 ------ drivers/gpu/drm/msm/dp/dp_ctrl.h | 1 - drivers/gpu/drm/msm/dp/dp_display.c | 148 +++++++++--------------------------- 3 files changed, 34 insertions(+), 137 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +0 -22
@@ -2567,28 +2567,6 @@ void msm_dp_ctrl_off_link_stream(struct msm_dp_ctrl *msm_dp_ctrl) phy, phy->init_count, phy->power_count); } -void msm_dp_ctrl_off_link (struct msm_dp_ctrl *msm_dp_ctrl) -{ -struct msm_dp_ctrl_private *ctrl; -struct phy *phy; - - ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl); - phy = ctrl->phy; - -msm_dp_ctrl_mainlink_disable (ctrl); - -dev_pm_opp_set_rate (ctrl->dev,0 ); -msm_dp_ctrl_link_clk_disable (&ctrl->msm_dp_ctrl); - -DRM_DEBUG_DP ("Before, phy=%p init_count=%d power_on=%d\n" , - phy, phy->init_count, phy->power_count); - -phy_power_off (phy); - -DRM_DEBUG_DP ("After, phy=%p init_count=%d power_on=%d\n" , - phy, phy->init_count, phy->power_count); -} -void msm_dp_ctrl_off (struct msm_dp_ctrl *msm_dp_ctrl) {struct msm_dp_ctrl_private *ctrl;
drivers/gpu/drm/msm/dp/dp_ctrl.h +0 -1
@@ -19,7 +19,6 @@ struct phy;int msm_dp_ctrl_on_link (struct msm_dp_ctrl *msm_dp_ctrl);int msm_dp_ctrl_on_stream (struct msm_dp_ctrl *msm_dp_ctrl,bool force_link_train);void msm_dp_ctrl_off_link_stream (struct msm_dp_ctrl *msm_dp_ctrl); -void msm_dp_ctrl_off_link (struct msm_dp_ctrl *msm_dp_ctrl);void msm_dp_ctrl_off (struct msm_dp_ctrl *msm_dp_ctrl);void msm_dp_ctrl_push_idle (struct msm_dp_ctrl *msm_dp_ctrl);irqreturn_t msm_dp_ctrl_isr (struct msm_dp_ctrl *msm_dp_ctrl);
drivers/gpu/drm/msm/dp/dp_display.c +34 -114
280 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH v2 11/12] drm/msm/dp: drop the entire HPD state machine
Quoted 6 lines · Jessica Zhang
Since internal HPD IRQ event handling has been moved to being handled by the DRM framework
detect()andhpd_notify()callbacks, there is no need for the MSM driver to track the HPD state separately.Drop all references to the HPD state machine and replace existing checks with checks for
link_readyorsink_count.
After this patch there should no more difference between 'internal_hpd' and 'external_hpd' cases. However, the code still tries to make the difference for some reason. There are several places where the driver calls msm_dp_display_send_hpd_notification(), e.g. msm_dp_hpd_unplug_handle(), msm_dp_display_process_hpd_high(), etc. These functions are called from msm_dp_bridge_hpd_notify(), which means that we can end up with the lock ups because of the event loops.
Quoted 8 lines
Signed-off-by Jessica Zhang <[email protected]>--- drivers/gpu/drm/msm/dp/dp_ctrl.c | 22 ------ drivers/gpu/drm/msm/dp/dp_ctrl.h | 1 - drivers/gpu/drm/msm/dp/dp_display.c | 148 +++++++++--------------------------- 3 files changed, 34 insertions(+), 137 deletions(-)
Signature · 2 lines
With best wishes Dmitry
PATCH v2 12/12 drm/msm/dp: Add sink_count and link_ready to debug logs
In reply to Jessica ZhangAdd sink count and link_ready to the debug logs for [un]plug and HPD IRQ handling.
--- drivers/gpu/drm/msm/dp/dp_display.c | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +25 -13
@@ -455,8 +455,10 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)msm_dp_aux_enable_xfers (dp->aux, true); -drm_dbg_dp (dp->drm_dev,"Before, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"Before, type=%d sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);if (dp->msm_dp_display.link_ready)return 0 ;
@@ -473,8 +475,10 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp, u32 data)pm_runtime_put_sync (&pdev->dev); } -drm_dbg_dp (dp->drm_dev,"After, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"After, type=%d sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);/* uevent will complete connection part */ return 0 ;
@@ -500,8 +504,10 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)msm_dp_aux_enable_xfers (dp->aux, false); -drm_dbg_dp (dp->drm_dev,"Before, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"Before, type=%d sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);if (!dp->msm_dp_display.link_ready)return 0 ;
@@ -528,8 +534,10 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)/* signal the disconnect event early to ensure proper teardown */ msm_dp_display_handle_plugged_change (&dp->msm_dp_display, false); -drm_dbg_dp (dp->drm_dev,"After, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"After, type=%d, sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);/* uevent will complete disconnection part */ pm_runtime_put_sync (&pdev->dev);
@@ -539,13 +547,17 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp, u32 data)static int msm_dp_irq_hpd_handle (struct msm_dp_display_private *dp,u32 data) {/* irq_hpd can happen at either connected or disconnected state */ -drm_dbg_dp (dp->drm_dev,"Before, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"Before, type=%d, sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);msm_dp_display_usbpd_attention_cb (&dp->msm_dp_display.pdev->dev); -drm_dbg_dp (dp->drm_dev,"After, type=%d\n" , - dp->msm_dp_display.connector_type); +drm_dbg_dp (dp->drm_dev,"After, type=%d, sink_count=%d, link_ready=%d\n" , + dp->msm_dp_display.connector_type, + dp->link->sink_count, + dp->msm_dp_display.link_ready);return 0 ; }
@@ -1540,7 +1552,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge, hpd_link_status =msm_dp_aux_is_link_connected (dp->aux); } -drm_dbg_dp (dp->drm_dev,"type=%d link connected=0x%x, link_ready=%d, status=%d\n" , +drm_dbg_dp (dp->drm_dev,"type=%d link hpd_link_status=0x%x, link_ready=%d, status=%d\n" , msm_dp_display->connector_type, hpd_link_status, msm_dp_display->link_ready, status);
Signature · 1 line
2.50.1