1 // SPDX-License-Identifier: MIT
3 * Copyright 2021 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
28 #include "inc/core_status.h"
29 #include "dpcd_defs.h"
31 #include "link_dp_dpia.h"
32 #include "link_hwss.h"
33 #include "dm_helpers.h"
34 #include "dmub/inc/dmub_cmd.h"
35 #include "link_dpcd.h"
36 #include "link_dp_training.h"
37 #include "dc_dmub_srv.h"
42 /** @note Can remove once DP tunneling registers in upstream include/drm/drm_dp_helper.h */
43 /* DPCD DP Tunneling over USB4 */
44 #define DP_TUNNELING_CAPABILITIES_SUPPORT 0xe000d
45 #define DP_IN_ADAPTER_INFO 0xe000e
46 #define DP_USB4_DRIVER_ID 0xe000f
47 #define DP_USB4_ROUTER_TOPOLOGY_ID 0xe001b
49 enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link)
51 enum dc_status status = DC_OK;
52 uint8_t dpcd_dp_tun_data[3] = {0};
53 uint8_t dpcd_topology_data[DPCD_USB4_TOPOLOGY_ID_LEN] = {0};
56 status = core_link_read_dpcd(
58 DP_TUNNELING_CAPABILITIES_SUPPORT,
60 sizeof(dpcd_dp_tun_data));
65 status = core_link_read_dpcd(
67 DP_USB4_ROUTER_TOPOLOGY_ID,
69 sizeof(dpcd_topology_data));
74 link->dpcd_caps.usb4_dp_tun_info.dp_tun_cap.raw =
75 dpcd_dp_tun_data[DP_TUNNELING_CAPABILITIES_SUPPORT - DP_TUNNELING_CAPABILITIES_SUPPORT];
76 link->dpcd_caps.usb4_dp_tun_info.dpia_info.raw =
77 dpcd_dp_tun_data[DP_IN_ADAPTER_INFO - DP_TUNNELING_CAPABILITIES_SUPPORT];
78 link->dpcd_caps.usb4_dp_tun_info.usb4_driver_id =
79 dpcd_dp_tun_data[DP_USB4_DRIVER_ID - DP_TUNNELING_CAPABILITIES_SUPPORT];
81 for (i = 0; i < DPCD_USB4_TOPOLOGY_ID_LEN; i++)
82 link->dpcd_caps.usb4_dp_tun_info.usb4_topology_id[i] = dpcd_topology_data[i];
88 bool dpia_query_hpd_status(struct dc_link *link)
90 union dmub_rb_cmd cmd = {0};
91 struct dc_dmub_srv *dmub_srv = link->ctx->dmub_srv;
93 /* prepare QUERY_HPD command */
94 cmd.query_hpd.header.type = DMUB_CMD__QUERY_HPD_STATE;
95 cmd.query_hpd.data.instance = link->link_id.enum_id - ENUM_ID_1;
96 cmd.query_hpd.data.ch_type = AUX_CHANNEL_DPIA;
98 /* Query dpia hpd status from dmub */
99 if (dc_wake_and_execute_dmub_cmd(dmub_srv->ctx, &cmd,
100 DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY) &&
101 cmd.query_hpd.data.status == AUX_RET_SUCCESS) {
102 DC_LOG_DEBUG("%s: for link(%d) dpia(%d) success, current_hpd_status(%d) new_hpd_status(%d)\n",
105 link->link_id.enum_id - ENUM_ID_1,
107 cmd.query_hpd.data.result);
108 link->hpd_status = cmd.query_hpd.data.result;
110 DC_LOG_ERROR("%s: for link(%d) dpia(%d) failed with status(%d), current_hpd_status(%d) new_hpd_status(0)\n",
113 link->link_id.enum_id - ENUM_ID_1,
114 cmd.query_hpd.data.status,
116 link->hpd_status = false;
119 return link->hpd_status;