1 /*
2 * Copyright 2022 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 /* FILE POLICY AND INTENDED USAGE:
27 *
28 * This file implements functions that manage basic HPD components such as gpio.
29 * It also provides wrapper functions to execute HPD related programming. This
30 * file only manages basic HPD functionality. It doesn't manage detection or
31 * feature or signal specific HPD behaviors.
32 */
33 #include "link_hpd.h"
34 #include "gpio_service_interface.h"
35
link_get_hpd_state(struct dc_link * link)36 bool link_get_hpd_state(struct dc_link *link)
37 {
38 if (link->link_enc)
39 return link->link_enc->funcs->get_hpd_state(link->link_enc);
40 else
41 return false;
42 }
43
link_enable_hpd(const struct dc_link * link)44 void link_enable_hpd(const struct dc_link *link)
45 {
46 if (link->link_enc)
47 link->link_enc->funcs->enable_hpd(link->link_enc);
48 }
49
link_disable_hpd(const struct dc_link * link)50 void link_disable_hpd(const struct dc_link *link)
51 {
52 if (link->link_enc)
53 link->link_enc->funcs->disable_hpd(link->link_enc);
54 }
55
link_enable_hpd_filter(struct dc_link * link,bool enable)56 void link_enable_hpd_filter(struct dc_link *link, bool enable)
57 {
58 if (enable) {
59 link->is_hpd_filter_disabled = false;
60 program_hpd_filter(link);
61 } else {
62 link->is_hpd_filter_disabled = true;
63 if (link->link_enc)
64 link->link_enc->funcs->program_hpd_filter(link->link_enc, 0, 0);
65 }
66 }
67
program_hpd_filter(const struct dc_link * link)68 bool program_hpd_filter(const struct dc_link *link)
69 {
70 int delay_on_connect_in_ms = 0;
71 int delay_on_disconnect_in_ms = 0;
72
73 if (link->is_hpd_filter_disabled || !link->link_enc) {
74 ASSERT(link->link_enc);
75 return false;
76 }
77
78 /* Verify feature is supported */
79 switch (link->connector_signal) {
80 case SIGNAL_TYPE_DVI_SINGLE_LINK:
81 case SIGNAL_TYPE_DVI_DUAL_LINK:
82 case SIGNAL_TYPE_HDMI_TYPE_A:
83 /* Program hpd filter */
84 delay_on_connect_in_ms = 500;
85 delay_on_disconnect_in_ms = 100;
86 break;
87 case SIGNAL_TYPE_DISPLAY_PORT:
88 case SIGNAL_TYPE_DISPLAY_PORT_MST:
89 /* Program hpd filter to allow DP signal to settle */
90 /* 500: not able to detect MST <-> SST switch as HPD is low for
91 * only 100ms on DELL U2413
92 * 0: some passive dongle still show aux mode instead of i2c
93 * 20-50: not enough to hide bouncing HPD with passive dongle.
94 * also see intermittent i2c read issues.
95 */
96 delay_on_connect_in_ms = 80;
97 delay_on_disconnect_in_ms = 0;
98 break;
99 case SIGNAL_TYPE_LVDS:
100 case SIGNAL_TYPE_EDP:
101 default:
102 /* Don't program hpd filter */
103 return false;
104 }
105
106 return link->link_enc->funcs->program_hpd_filter(link->link_enc, delay_on_connect_in_ms, delay_on_disconnect_in_ms);
107 }
108
link_get_hpd_gpio(struct dc_bios * dcb,struct graphics_object_id link_id,struct gpio_service * gpio_service)109 struct gpio *link_get_hpd_gpio(struct dc_bios *dcb,
110 struct graphics_object_id link_id,
111 struct gpio_service *gpio_service)
112 {
113 enum bp_result bp_result;
114 struct graphics_object_hpd_info hpd_info;
115 struct gpio_pin_info pin_info;
116
117 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
118 return NULL;
119
120 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
121 hpd_info.hpd_int_gpio_uid, &pin_info);
122
123 if (bp_result != BP_RESULT_OK) {
124 return NULL;
125 }
126
127 return dal_gpio_service_create_irq(gpio_service,
128 pin_info.offset,
129 pin_info.mask);
130 }
131
get_hpd_line(struct dc_link * link)132 enum hpd_source_id get_hpd_line(struct dc_link *link)
133 {
134 struct gpio *hpd;
135 enum hpd_source_id hpd_id;
136
137 hpd_id = HPD_SOURCEID_UNKNOWN;
138
139 /* Use GPIO path where supported, otherwise use hardware encoder path */
140 if (link->ctx && link->ctx->dce_version <= DCN_VERSION_4_01) {
141 hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
142 link->ctx->gpio_service);
143 } else {
144 hpd = NULL;
145 }
146
147 if (hpd) {
148 switch (dal_irq_get_source(hpd)) {
149 case DC_IRQ_SOURCE_HPD1:
150 hpd_id = HPD_SOURCEID1;
151 break;
152 case DC_IRQ_SOURCE_HPD2:
153 hpd_id = HPD_SOURCEID2;
154 break;
155 case DC_IRQ_SOURCE_HPD3:
156 hpd_id = HPD_SOURCEID3;
157 break;
158 case DC_IRQ_SOURCE_HPD4:
159 hpd_id = HPD_SOURCEID4;
160 break;
161 case DC_IRQ_SOURCE_HPD5:
162 hpd_id = HPD_SOURCEID5;
163 break;
164 case DC_IRQ_SOURCE_HPD6:
165 hpd_id = HPD_SOURCEID6;
166 break;
167 default:
168 BREAK_TO_DEBUGGER();
169 break;
170 }
171
172 dal_gpio_destroy_irq(&hpd);
173 }
174
175 return hpd_id;
176 }
177