drm/amd/display: move dp irq handler functions from dc_link_dp to link_dp_irq_handler
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / display / dc / link / protocols / link_dp_dpia.c
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 "dc_link_dp.h"
31 #include "dpcd_defs.h"
32
33 #include "link_dp_dpia.h"
34 #include "link_hwss.h"
35 #include "dm_helpers.h"
36 #include "dmub/inc/dmub_cmd.h"
37 #include "link_dpcd.h"
38 #include "link_dp_training.h"
39 #include "dc_dmub_srv.h"
40
41 #define DC_LOGGER \
42         link->ctx->logger
43
44 /** @note Can remove once DP tunneling registers in upstream include/drm/drm_dp_helper.h */
45 /* DPCD DP Tunneling over USB4 */
46 #define DP_TUNNELING_CAPABILITIES_SUPPORT 0xe000d
47 #define DP_IN_ADAPTER_INFO                0xe000e
48 #define DP_USB4_DRIVER_ID                 0xe000f
49 #define DP_USB4_ROUTER_TOPOLOGY_ID        0xe001b
50
51 enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link)
52 {
53         enum dc_status status = DC_OK;
54         uint8_t dpcd_dp_tun_data[3] = {0};
55         uint8_t dpcd_topology_data[DPCD_USB4_TOPOLOGY_ID_LEN] = {0};
56         uint8_t i = 0;
57
58         status = core_link_read_dpcd(
59                         link,
60                         DP_TUNNELING_CAPABILITIES_SUPPORT,
61                         dpcd_dp_tun_data,
62                         sizeof(dpcd_dp_tun_data));
63
64         status = core_link_read_dpcd(
65                         link,
66                         DP_USB4_ROUTER_TOPOLOGY_ID,
67                         dpcd_topology_data,
68                         sizeof(dpcd_topology_data));
69
70         link->dpcd_caps.usb4_dp_tun_info.dp_tun_cap.raw =
71                         dpcd_dp_tun_data[DP_TUNNELING_CAPABILITIES_SUPPORT - DP_TUNNELING_CAPABILITIES_SUPPORT];
72         link->dpcd_caps.usb4_dp_tun_info.dpia_info.raw =
73                         dpcd_dp_tun_data[DP_IN_ADAPTER_INFO - DP_TUNNELING_CAPABILITIES_SUPPORT];
74         link->dpcd_caps.usb4_dp_tun_info.usb4_driver_id =
75                         dpcd_dp_tun_data[DP_USB4_DRIVER_ID - DP_TUNNELING_CAPABILITIES_SUPPORT];
76
77         for (i = 0; i < DPCD_USB4_TOPOLOGY_ID_LEN; i++)
78                 link->dpcd_caps.usb4_dp_tun_info.usb4_topology_id[i] = dpcd_topology_data[i];
79
80         return status;
81 }
82
83 bool dc_link_dpia_query_hpd_status(struct dc_link *link)
84 {
85         union dmub_rb_cmd cmd = {0};
86         struct dc_dmub_srv *dmub_srv = link->ctx->dmub_srv;
87         bool is_hpd_high = false;
88
89         /* prepare QUERY_HPD command */
90         cmd.query_hpd.header.type = DMUB_CMD__QUERY_HPD_STATE;
91         cmd.query_hpd.data.instance = link->link_id.enum_id - ENUM_ID_1;
92         cmd.query_hpd.data.ch_type = AUX_CHANNEL_DPIA;
93
94         /* Return HPD status reported by DMUB if query successfully executed. */
95         if (dc_dmub_srv_cmd_with_reply_data(dmub_srv, &cmd) && cmd.query_hpd.data.status == AUX_RET_SUCCESS)
96                 is_hpd_high = cmd.query_hpd.data.result;
97
98         DC_LOG_DEBUG("%s: link(%d) dpia(%d) cmd_status(%d) result(%d)\n",
99                 __func__,
100                 link->link_index,
101                 link->link_id.enum_id - ENUM_ID_1,
102                 cmd.query_hpd.data.status,
103                 cmd.query_hpd.data.result);
104
105         return is_hpd_high;
106 }