1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2021 Advanced Micro Devices, Inc.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
22 *
23 * Authors: AMD
24 *
25 */
26
27 #include "dc.h"
28 #include "inc/core_status.h"
29 #include "dc_link.h"
30 #include "dpcd_defs.h"
31
32 #include "link_dp_dpia.h"
33 #include "link_hwss.h"
34 #include "dm_helpers.h"
35 #include "dmub/inc/dmub_cmd.h"
36 #include "link_dpcd.h"
37 #include "link_dp_training.h"
38 #include "dc_dmub_srv.h"
39
40 #define DC_LOGGER \
41 link->ctx->logger
42
43 /** @note Can remove once DP tunneling registers in upstream include/drm/drm_dp_helper.h */
44 /* DPCD DP Tunneling over USB4 */
45 #define DP_TUNNELING_CAPABILITIES_SUPPORT 0xe000d
46 #define DP_IN_ADAPTER_INFO 0xe000e
47 #define DP_USB4_DRIVER_ID 0xe000f
48 #define DP_USB4_ROUTER_TOPOLOGY_ID 0xe001b
49
dpcd_get_tunneling_device_data(struct dc_link * link)50 enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link)
51 {
52 enum dc_status status = DC_OK;
53 uint8_t dpcd_dp_tun_data[3] = {0};
54 uint8_t dpcd_topology_data[DPCD_USB4_TOPOLOGY_ID_LEN] = {0};
55 uint8_t i = 0;
56
57 status = core_link_read_dpcd(
58 link,
59 DP_TUNNELING_CAPABILITIES_SUPPORT,
60 dpcd_dp_tun_data,
61 sizeof(dpcd_dp_tun_data));
62
63 status = core_link_read_dpcd(
64 link,
65 DP_USB4_ROUTER_TOPOLOGY_ID,
66 dpcd_topology_data,
67 sizeof(dpcd_topology_data));
68
69 link->dpcd_caps.usb4_dp_tun_info.dp_tun_cap.raw =
70 dpcd_dp_tun_data[DP_TUNNELING_CAPABILITIES_SUPPORT - DP_TUNNELING_CAPABILITIES_SUPPORT];
71 link->dpcd_caps.usb4_dp_tun_info.dpia_info.raw =
72 dpcd_dp_tun_data[DP_IN_ADAPTER_INFO - DP_TUNNELING_CAPABILITIES_SUPPORT];
73 link->dpcd_caps.usb4_dp_tun_info.usb4_driver_id =
74 dpcd_dp_tun_data[DP_USB4_DRIVER_ID - DP_TUNNELING_CAPABILITIES_SUPPORT];
75
76 for (i = 0; i < DPCD_USB4_TOPOLOGY_ID_LEN; i++)
77 link->dpcd_caps.usb4_dp_tun_info.usb4_topology_id[i] = dpcd_topology_data[i];
78
79 return status;
80 }
81
dc_link_dpia_query_hpd_status(struct dc_link * link)82 bool dc_link_dpia_query_hpd_status(struct dc_link *link)
83 {
84 union dmub_rb_cmd cmd = {0};
85 struct dc_dmub_srv *dmub_srv = link->ctx->dmub_srv;
86 bool is_hpd_high = false;
87
88 /* prepare QUERY_HPD command */
89 cmd.query_hpd.header.type = DMUB_CMD__QUERY_HPD_STATE;
90 cmd.query_hpd.data.instance = link->link_id.enum_id - ENUM_ID_1;
91 cmd.query_hpd.data.ch_type = AUX_CHANNEL_DPIA;
92
93 /* Return HPD status reported by DMUB if query successfully executed. */
94 if (dc_dmub_srv_cmd_with_reply_data(dmub_srv, &cmd) && cmd.query_hpd.data.status == AUX_RET_SUCCESS)
95 is_hpd_high = cmd.query_hpd.data.result;
96
97 DC_LOG_DEBUG("%s: link(%d) dpia(%d) cmd_status(%d) result(%d)\n",
98 __func__,
99 link->link_index,
100 link->link_id.enum_id - ENUM_ID_1,
101 cmd.query_hpd.data.status,
102 cmd.query_hpd.data.result);
103
104 return is_hpd_high;
105 }
106
107