diff options
author | Thierry Reding <treding@nvidia.com> | 2013-12-09 11:47:55 +0100 |
---|---|---|
committer | Thierry Reding <treding@nvidia.com> | 2014-01-10 10:15:22 +0100 |
commit | 8797d68b9faa2300144ff4374961f5fc759f28e4 (patch) | |
tree | 7fe20d3c249e96f3f7f3b3c845f615b160a8fd1f | |
parent | 962b70e2334340dbe6718692f6953e8910dbb4ad (diff) |
drm/dp: Add DisplayPort link helpers
Add a helper to probe a DP link (reading out the maximum rate, link
count and capabilities) as well as configuring it accordingly.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
Changes in v3:
- remove duplicate kerneldoc
-rw-r--r-- | drivers/gpu/drm/drm_dp_helper.c | 77 | ||||
-rw-r--r-- | include/drm/drm_dp_helper.h | 15 |
2 files changed, 92 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index 572637456713..7c27c2015d4c 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -472,3 +472,80 @@ int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, DP_LINK_STATUS_SIZE); } EXPORT_SYMBOL(drm_dp_dpcd_read_link_status); + +/** + * drm_dp_link_probe() - probe a DisplayPort link for capabilities + * @aux: DisplayPort AUX channel + * @link: pointer to structure in which to return link capabilities + * + * The structure filled in by this function can usually be passed directly + * into drm_dp_link_power_up() configure the link based on the link's + * capabilities. + * + * Returns 0 on success or a negative error code on failure. + */ +int drm_dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link) +{ + u8 value; + int err; + + memset(link, 0, sizeof(*link)); + + err = drm_dp_dpcd_readb(aux, DP_MAX_LINK_RATE, &value); + if (err < 0) + return err; + + link->rate = drm_dp_bw_code_to_link_rate(value); + + err = drm_dp_dpcd_readb(aux, DP_MAX_LANE_COUNT, &value); + if (err < 0) + return err; + + link->num_lanes = value & DP_MAX_LANE_COUNT_MASK; + + if (value & DP_ENHANCED_FRAME_CAP) + link->capabilities |= DP_LINK_CAP_ENHANCED_FRAMING; + + return 0; +} + +/** + * drm_dp_link_power_up() - power up and configure a DisplayPort link + * @aux: DisplayPort AUX channel + * @link: pointer to a structure containing the link configuration + * + * Returns 0 on success or a negative error code on failure. + */ +int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link) +{ + u8 value; + int err; + + err = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value); + if (err < 0) + return err; + + value &= ~DP_SET_POWER_MASK; + value |= DP_SET_POWER_D0; + + err = drm_dp_dpcd_writeb(aux, value, DP_SET_POWER); + if (err < 0) + return err; + + value = drm_dp_link_rate_to_bw_code(link->rate); + + err = drm_dp_dpcd_writeb(aux, value, DP_LINK_BW_SET); + if (err < 0) + return err; + + value = link->num_lanes; + + if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING) + value |= DP_LANE_COUNT_ENHANCED_FRAME_EN; + + err = drm_dp_dpcd_writeb(aux, value, DP_LANE_COUNT_SET); + if (err < 0) + return err; + + return 0; +} diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index f6c61f3178f8..05055c05db2b 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -291,6 +291,7 @@ #define DP_SET_POWER 0x600 # define DP_SET_POWER_D0 0x1 # define DP_SET_POWER_D3 0x2 +# define DP_SET_POWER_MASK 0x3 #define DP_PSR_ERROR_STATUS 0x2006 /* XXX 1.2? */ # define DP_PSR_LINK_CRC_ERROR (1 << 0) @@ -468,4 +469,18 @@ static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux, u8 value, int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, u8 status[DP_LINK_STATUS_SIZE]); +/* + * DisplayPort link + */ +#define DP_LINK_CAP_ENHANCED_FRAMING (1 << 0) + +struct drm_dp_link { + unsigned int rate; + unsigned int num_lanes; + unsigned long capabilities; +}; + +int drm_dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link); +int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link); + #endif /* _DRM_DP_HELPER_H_ */ |