Skip to content

Commit f2663f7

Browse files
committed
drm/dp: extract drm_dp_dpcd_poll_act_handled()
SST with 128b/132b channel coding needs this too. Extract to a separate helper, independent of MST. Pass timeout in as a parameter, anticipating that we can reduce the timeout for SST. v2: Clean up kernel-doc a bit Cc: Lyude Paul <[email protected]> Reviewed-by: Imre Deak <[email protected]> Reviewed-by: Lyude Paul <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/459fd3e96a55a8ea8ada8d27d93eaa24c235f9c1.1733238941.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <[email protected]>
1 parent 39b1acf commit f2663f7

File tree

3 files changed

+57
-35
lines changed

3 files changed

+57
-35
lines changed

drivers/gpu/drm/display/drm_dp_helper.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222

2323
#include <linux/backlight.h>
2424
#include <linux/delay.h>
25+
#include <linux/dynamic_debug.h>
2526
#include <linux/errno.h>
2627
#include <linux/i2c.h>
2728
#include <linux/init.h>
29+
#include <linux/iopoll.h>
2830
#include <linux/kernel.h>
2931
#include <linux/module.h>
3032
#include <linux/sched.h>
3133
#include <linux/seq_file.h>
3234
#include <linux/string_helpers.h>
33-
#include <linux/dynamic_debug.h>
3435

3536
#include <drm/display/drm_dp_helper.h>
3637
#include <drm/display/drm_dp_mst_helper.h>
@@ -779,6 +780,57 @@ int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,
779780
}
780781
EXPORT_SYMBOL(drm_dp_dpcd_read_phy_link_status);
781782

783+
static int read_payload_update_status(struct drm_dp_aux *aux)
784+
{
785+
int ret;
786+
u8 status;
787+
788+
ret = drm_dp_dpcd_readb(aux, DP_PAYLOAD_TABLE_UPDATE_STATUS, &status);
789+
if (ret < 0)
790+
return ret;
791+
792+
return status;
793+
}
794+
795+
/**
796+
* drm_dp_dpcd_poll_act_handled() - Poll for ACT handled status
797+
* @aux: DisplayPort AUX channel
798+
* @timeout_ms: Timeout in ms
799+
*
800+
* Try waiting for the sink to finish updating its payload table by polling for
801+
* the ACT handled bit of DP_PAYLOAD_TABLE_UPDATE_STATUS for up to @timeout_ms
802+
* milliseconds, defaulting to 3000 ms if 0.
803+
*
804+
* Returns:
805+
* 0 if the ACT was handled in time, negative error code on failure.
806+
*/
807+
int drm_dp_dpcd_poll_act_handled(struct drm_dp_aux *aux, int timeout_ms)
808+
{
809+
int ret, status;
810+
811+
/* default to 3 seconds, this is arbitrary */
812+
timeout_ms = timeout_ms ?: 3000;
813+
814+
ret = readx_poll_timeout(read_payload_update_status, aux, status,
815+
status & DP_PAYLOAD_ACT_HANDLED || status < 0,
816+
200, timeout_ms * USEC_PER_MSEC);
817+
if (ret < 0 && status >= 0) {
818+
drm_err(aux->drm_dev, "Failed to get ACT after %d ms, last status: %02x\n",
819+
timeout_ms, status);
820+
return -EINVAL;
821+
} else if (status < 0) {
822+
/*
823+
* Failure here isn't unexpected - the hub may have
824+
* just been unplugged
825+
*/
826+
drm_dbg_kms(aux->drm_dev, "Failed to read payload table status: %d\n", status);
827+
return status;
828+
}
829+
830+
return 0;
831+
}
832+
EXPORT_SYMBOL(drm_dp_dpcd_poll_act_handled);
833+
782834
static bool is_edid_digital_input_dp(const struct drm_edid *drm_edid)
783835
{
784836
/* FIXME: get rid of drm_edid_raw() */

drivers/gpu/drm/display/drm_dp_mst_topology.c

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <linux/random.h>
3030
#include <linux/sched.h>
3131
#include <linux/seq_file.h>
32-
#include <linux/iopoll.h>
3332

3433
#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
3534
#include <linux/stacktrace.h>
@@ -4723,18 +4722,6 @@ static int drm_dp_dpcd_write_payload(struct drm_dp_mst_topology_mgr *mgr,
47234722
return ret;
47244723
}
47254724

4726-
static int do_get_act_status(struct drm_dp_aux *aux)
4727-
{
4728-
int ret;
4729-
u8 status;
4730-
4731-
ret = drm_dp_dpcd_readb(aux, DP_PAYLOAD_TABLE_UPDATE_STATUS, &status);
4732-
if (ret < 0)
4733-
return ret;
4734-
4735-
return status;
4736-
}
4737-
47384725
/**
47394726
* drm_dp_check_act_status() - Polls for ACT handled status.
47404727
* @mgr: manager to use
@@ -4752,28 +4739,9 @@ int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr)
47524739
* There doesn't seem to be any recommended retry count or timeout in
47534740
* the MST specification. Since some hubs have been observed to take
47544741
* over 1 second to update their payload allocations under certain
4755-
* conditions, we use a rather large timeout value.
4742+
* conditions, we use a rather large timeout value of 3 seconds.
47564743
*/
4757-
const int timeout_ms = 3000;
4758-
int ret, status;
4759-
4760-
ret = readx_poll_timeout(do_get_act_status, mgr->aux, status,
4761-
status & DP_PAYLOAD_ACT_HANDLED || status < 0,
4762-
200, timeout_ms * USEC_PER_MSEC);
4763-
if (ret < 0 && status >= 0) {
4764-
drm_err(mgr->dev, "Failed to get ACT after %dms, last status: %02x\n",
4765-
timeout_ms, status);
4766-
return -EINVAL;
4767-
} else if (status < 0) {
4768-
/*
4769-
* Failure here isn't unexpected - the hub may have
4770-
* just been unplugged
4771-
*/
4772-
drm_dbg_kms(mgr->dev, "Failed to read payload table status: %d\n", status);
4773-
return status;
4774-
}
4775-
4776-
return 0;
4744+
return drm_dp_dpcd_poll_act_handled(mgr->aux, 3000);
47774745
}
47784746
EXPORT_SYMBOL(drm_dp_check_act_status);
47794747

include/drm/display/drm_dp_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,
567567
enum drm_dp_phy dp_phy,
568568
u8 link_status[DP_LINK_STATUS_SIZE]);
569569

570+
int drm_dp_dpcd_poll_act_handled(struct drm_dp_aux *aux, int timeout_ms);
571+
570572
bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,
571573
u8 real_edid_checksum);
572574

0 commit comments

Comments
 (0)