1 // SPDX-License-Identifier: MIT
3 * Copyright (C) 2013-2019 NVIDIA Corporation
4 * Copyright (C) 2015 Rob Clark
7 #include <drm/drm_dp_helper.h>
12 * drm_dp_link_probe() - probe a DisplayPort link for capabilities
13 * @aux: DisplayPort AUX channel
14 * @link: pointer to structure in which to return link capabilities
16 * The structure filled in by this function can usually be passed directly
17 * into drm_dp_link_power_up() and drm_dp_link_configure() to power up and
18 * configure the link based on the link's capabilities.
20 * Returns 0 on success or a negative error code on failure.
22 int drm_dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link)
27 memset(link, 0, sizeof(*link));
29 err = drm_dp_dpcd_read(aux, DP_DPCD_REV, values, sizeof(values));
33 link->revision = values[0];
34 link->rate = drm_dp_bw_code_to_link_rate(values[1]);
35 link->num_lanes = values[2] & DP_MAX_LANE_COUNT_MASK;
37 if (values[2] & DP_ENHANCED_FRAME_CAP)
38 link->capabilities |= DP_LINK_CAP_ENHANCED_FRAMING;
44 * drm_dp_link_power_up() - power up a DisplayPort link
45 * @aux: DisplayPort AUX channel
46 * @link: pointer to a structure containing the link configuration
48 * Returns 0 on success or a negative error code on failure.
50 int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link)
55 /* DP_SET_POWER register is only available on DPCD v1.1 and later */
56 if (link->revision < 0x11)
59 err = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value);
63 value &= ~DP_SET_POWER_MASK;
64 value |= DP_SET_POWER_D0;
66 err = drm_dp_dpcd_writeb(aux, DP_SET_POWER, value);
71 * According to the DP 1.1 specification, a "Sink Device must exit the
72 * power saving state within 1 ms" (Section 2.5.3.1, Table 5-52, "Sink
73 * Control Field" (register 0x600).
75 usleep_range(1000, 2000);
81 * drm_dp_link_power_down() - power down a DisplayPort link
82 * @aux: DisplayPort AUX channel
83 * @link: pointer to a structure containing the link configuration
85 * Returns 0 on success or a negative error code on failure.
87 int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link)
92 /* DP_SET_POWER register is only available on DPCD v1.1 and later */
93 if (link->revision < 0x11)
96 err = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value);
100 value &= ~DP_SET_POWER_MASK;
101 value |= DP_SET_POWER_D3;
103 err = drm_dp_dpcd_writeb(aux, DP_SET_POWER, value);
111 * drm_dp_link_configure() - configure a DisplayPort link
112 * @aux: DisplayPort AUX channel
113 * @link: pointer to a structure containing the link configuration
115 * Returns 0 on success or a negative error code on failure.
117 int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link)
122 values[0] = drm_dp_link_rate_to_bw_code(link->rate);
123 values[1] = link->num_lanes;
125 if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
126 values[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
128 err = drm_dp_dpcd_write(aux, DP_LINK_BW_SET, values, sizeof(values));