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