]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/display/dc/link/link_factory.c
Merge tag 'linux-watchdog-6.14-rc1' of git://www.linux-watchdog.org/linux-watchdog
[linux.git] / drivers / gpu / drm / amd / display / dc / link / link_factory.c
1 /*
2  * Copyright 2023 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  * This file owns the creation/destruction of link structure.
28  */
29 #include "link_factory.h"
30 #include "link_detection.h"
31 #include "link_resource.h"
32 #include "link_validation.h"
33 #include "link_dpms.h"
34 #include "accessories/link_dp_cts.h"
35 #include "accessories/link_dp_trace.h"
36 #include "protocols/link_ddc.h"
37 #include "protocols/link_dp_capability.h"
38 #include "protocols/link_dp_dpia_bw.h"
39 #include "protocols/link_dp_dpia.h"
40 #include "protocols/link_dp_irq_handler.h"
41 #include "protocols/link_dp_phy.h"
42 #include "protocols/link_dp_training.h"
43 #include "protocols/link_edp_panel_control.h"
44 #include "protocols/link_hpd.h"
45 #include "gpio_service_interface.h"
46 #include "atomfirmware.h"
47
48 #define DC_LOGGER \
49         dc_ctx->logger
50 #define DC_LOGGER_INIT(logger)
51
52 #define LINK_INFO(...) \
53         DC_LOG_HW_HOTPLUG(  \
54                 __VA_ARGS__)
55
56 /* link factory owns the creation/destruction of link structures. */
57 static void construct_link_service_factory(struct link_service *link_srv)
58 {
59
60         link_srv->create_link = link_create;
61         link_srv->destroy_link = link_destroy;
62 }
63
64 /* link_detection manages link detection states and receiver states by using
65  * various link protocols. It also provides helper functions to interpret
66  * certain capabilities or status based on the states it manages or retrieve
67  * them directly from connected receivers.
68  */
69 static void construct_link_service_detection(struct link_service *link_srv)
70 {
71         link_srv->detect_link = link_detect;
72         link_srv->detect_connection_type = link_detect_connection_type;
73         link_srv->add_remote_sink = link_add_remote_sink;
74         link_srv->remove_remote_sink = link_remove_remote_sink;
75         link_srv->get_hpd_state = link_get_hpd_state;
76         link_srv->get_hpd_gpio = link_get_hpd_gpio;
77         link_srv->enable_hpd = link_enable_hpd;
78         link_srv->disable_hpd = link_disable_hpd;
79         link_srv->enable_hpd_filter = link_enable_hpd_filter;
80         link_srv->reset_cur_dp_mst_topology = link_reset_cur_dp_mst_topology;
81         link_srv->get_status = link_get_status;
82         link_srv->is_hdcp1x_supported = link_is_hdcp14;
83         link_srv->is_hdcp2x_supported = link_is_hdcp22;
84         link_srv->clear_dprx_states = link_clear_dprx_states;
85 }
86
87 /* link resource implements accessors to link resource. */
88 static void construct_link_service_resource(struct link_service *link_srv)
89 {
90         link_srv->get_cur_res_map = link_get_cur_res_map;
91         link_srv->restore_res_map = link_restore_res_map;
92         link_srv->get_cur_link_res = link_get_cur_link_res;
93 }
94
95 /* link validation owns timing validation against various link limitations. (ex.
96  * link bandwidth, receiver capability or our hardware capability) It also
97  * provides helper functions exposing bandwidth formulas used in validation.
98  */
99 static void construct_link_service_validation(struct link_service *link_srv)
100 {
101         link_srv->validate_mode_timing = link_validate_mode_timing;
102         link_srv->dp_link_bandwidth_kbps = dp_link_bandwidth_kbps;
103         link_srv->validate_dpia_bandwidth = link_validate_dpia_bandwidth;
104         link_srv->dp_required_hblank_size_bytes = dp_required_hblank_size_bytes;
105 }
106
107 /* link dpms owns the programming sequence of stream's dpms state associated
108  * with the link and link's enable/disable sequences as result of the stream's
109  * dpms state change.
110  */
111 static void construct_link_service_dpms(struct link_service *link_srv)
112 {
113         link_srv->set_dpms_on = link_set_dpms_on;
114         link_srv->set_dpms_off = link_set_dpms_off;
115         link_srv->resume = link_resume;
116         link_srv->blank_all_dp_displays = link_blank_all_dp_displays;
117         link_srv->blank_all_edp_displays = link_blank_all_edp_displays;
118         link_srv->blank_dp_stream = link_blank_dp_stream;
119         link_srv->increase_mst_payload = link_increase_mst_payload;
120         link_srv->reduce_mst_payload = link_reduce_mst_payload;
121         link_srv->set_dsc_on_stream = link_set_dsc_on_stream;
122         link_srv->set_dsc_enable = link_set_dsc_enable;
123         link_srv->update_dsc_config = link_update_dsc_config;
124 }
125
126 /* link ddc implements generic display communication protocols such as i2c, aux
127  * and scdc. It should not contain any specific applications of these
128  * protocols such as display capability query, detection, or handshaking such as
129  * link training.
130  */
131 static void construct_link_service_ddc(struct link_service *link_srv)
132 {
133         link_srv->create_ddc_service = link_create_ddc_service;
134         link_srv->destroy_ddc_service = link_destroy_ddc_service;
135         link_srv->query_ddc_data = link_query_ddc_data;
136         link_srv->aux_transfer_raw = link_aux_transfer_raw;
137         link_srv->configure_fixed_vs_pe_retimer = link_configure_fixed_vs_pe_retimer;
138         link_srv->aux_transfer_with_retries_no_mutex =
139                         link_aux_transfer_with_retries_no_mutex;
140         link_srv->is_in_aux_transaction_mode = link_is_in_aux_transaction_mode;
141         link_srv->get_aux_defer_delay = link_get_aux_defer_delay;
142 }
143
144 /* link dp capability implements dp specific link capability retrieval sequence.
145  * It is responsible for retrieving, parsing, overriding, deciding capability
146  * obtained from dp link. Link capability consists of encoders, DPRXs, cables,
147  * retimers, usb and all other possible backend capabilities.
148  */
149 static void construct_link_service_dp_capability(struct link_service *link_srv)
150 {
151         link_srv->dp_is_sink_present = dp_is_sink_present;
152         link_srv->dp_is_fec_supported = dp_is_fec_supported;
153         link_srv->dp_is_128b_132b_signal = dp_is_128b_132b_signal;
154         link_srv->dp_get_max_link_enc_cap = dp_get_max_link_enc_cap;
155         link_srv->dp_get_verified_link_cap = dp_get_verified_link_cap;
156         link_srv->dp_get_encoding_format = link_dp_get_encoding_format;
157         link_srv->dp_should_enable_fec = dp_should_enable_fec;
158         link_srv->dp_decide_link_settings = link_decide_link_settings;
159         link_srv->mst_decide_link_encoding_format =
160                         mst_decide_link_encoding_format;
161         link_srv->edp_decide_link_settings = edp_decide_link_settings;
162         link_srv->bw_kbps_from_raw_frl_link_rate_data =
163                         link_bw_kbps_from_raw_frl_link_rate_data;
164         link_srv->dp_overwrite_extended_receiver_cap =
165                         dp_overwrite_extended_receiver_cap;
166         link_srv->dp_decide_lttpr_mode = dp_decide_lttpr_mode;
167 }
168
169 /* link dp phy/dpia implements basic dp phy/dpia functionality such as
170  * enable/disable output and set lane/drive settings. It is responsible for
171  * maintaining and update software state representing current phy/dpia status
172  * such as current link settings.
173  */
174 static void construct_link_service_dp_phy_or_dpia(struct link_service *link_srv)
175 {
176         link_srv->dpia_handle_usb4_bandwidth_allocation_for_link =
177                         dpia_handle_usb4_bandwidth_allocation_for_link;
178         link_srv->dpia_handle_bw_alloc_response = dpia_handle_bw_alloc_response;
179         link_srv->dp_set_drive_settings = dp_set_drive_settings;
180         link_srv->dpcd_write_rx_power_ctrl = dpcd_write_rx_power_ctrl;
181 }
182
183 /* link dp irq handler implements DP HPD short pulse handling sequence according
184  * to DP specifications
185  */
186 static void construct_link_service_dp_irq_handler(struct link_service *link_srv)
187 {
188         link_srv->dp_parse_link_loss_status = dp_parse_link_loss_status;
189         link_srv->dp_should_allow_hpd_rx_irq = dp_should_allow_hpd_rx_irq;
190         link_srv->dp_handle_link_loss = dp_handle_link_loss;
191         link_srv->dp_read_hpd_rx_irq_data = dp_read_hpd_rx_irq_data;
192         link_srv->dp_handle_hpd_rx_irq = dp_handle_hpd_rx_irq;
193 }
194
195 /* link edp panel control implements retrieval and configuration of eDP panel
196  * features such as PSR and ABM and it also manages specs defined eDP panel
197  * power sequences.
198  */
199 static void construct_link_service_edp_panel_control(struct link_service *link_srv)
200 {
201         link_srv->edp_panel_backlight_power_on = edp_panel_backlight_power_on;
202         link_srv->edp_get_backlight_level = edp_get_backlight_level;
203         link_srv->edp_get_backlight_level_nits = edp_get_backlight_level_nits;
204         link_srv->edp_set_backlight_level = edp_set_backlight_level;
205         link_srv->edp_set_backlight_level_nits = edp_set_backlight_level_nits;
206         link_srv->edp_get_target_backlight_pwm = edp_get_target_backlight_pwm;
207         link_srv->edp_get_psr_state = edp_get_psr_state;
208         link_srv->edp_set_psr_allow_active = edp_set_psr_allow_active;
209         link_srv->edp_setup_psr = edp_setup_psr;
210         link_srv->edp_set_sink_vtotal_in_psr_active =
211                         edp_set_sink_vtotal_in_psr_active;
212         link_srv->edp_get_psr_residency = edp_get_psr_residency;
213
214         link_srv->edp_get_replay_state = edp_get_replay_state;
215         link_srv->edp_set_replay_allow_active = edp_set_replay_allow_active;
216         link_srv->edp_setup_replay = edp_setup_replay;
217         link_srv->edp_send_replay_cmd = edp_send_replay_cmd;
218         link_srv->edp_set_coasting_vtotal = edp_set_coasting_vtotal;
219         link_srv->edp_replay_residency = edp_replay_residency;
220         link_srv->edp_set_replay_power_opt_and_coasting_vtotal = edp_set_replay_power_opt_and_coasting_vtotal;
221
222         link_srv->edp_wait_for_t12 = edp_wait_for_t12;
223         link_srv->edp_is_ilr_optimization_required =
224                         edp_is_ilr_optimization_required;
225         link_srv->edp_backlight_enable_aux = edp_backlight_enable_aux;
226         link_srv->edp_add_delay_for_T9 = edp_add_delay_for_T9;
227         link_srv->edp_receiver_ready_T9 = edp_receiver_ready_T9;
228         link_srv->edp_receiver_ready_T7 = edp_receiver_ready_T7;
229         link_srv->edp_power_alpm_dpcd_enable = edp_power_alpm_dpcd_enable;
230         link_srv->edp_set_panel_power = edp_set_panel_power;
231 }
232
233 /* link dp cts implements dp compliance test automation protocols and manual
234  * testing interfaces for debugging and certification purpose.
235  */
236 static void construct_link_service_dp_cts(struct link_service *link_srv)
237 {
238         link_srv->dp_handle_automated_test = dp_handle_automated_test;
239         link_srv->dp_set_test_pattern = dp_set_test_pattern;
240         link_srv->dp_set_preferred_link_settings =
241                         dp_set_preferred_link_settings;
242         link_srv->dp_set_preferred_training_settings =
243                         dp_set_preferred_training_settings;
244 }
245
246 /* link dp trace implements tracing interfaces for tracking major dp sequences
247  * including execution status and timestamps
248  */
249 static void construct_link_service_dp_trace(struct link_service *link_srv)
250 {
251         link_srv->dp_trace_is_initialized = dp_trace_is_initialized;
252         link_srv->dp_trace_set_is_logged_flag = dp_trace_set_is_logged_flag;
253         link_srv->dp_trace_is_logged = dp_trace_is_logged;
254         link_srv->dp_trace_get_lt_end_timestamp = dp_trace_get_lt_end_timestamp;
255         link_srv->dp_trace_get_lt_counts = dp_trace_get_lt_counts;
256         link_srv->dp_trace_get_link_loss_count = dp_trace_get_link_loss_count;
257         link_srv->dp_trace_set_edp_power_timestamp =
258                         dp_trace_set_edp_power_timestamp;
259         link_srv->dp_trace_get_edp_poweron_timestamp =
260                         dp_trace_get_edp_poweron_timestamp;
261         link_srv->dp_trace_get_edp_poweroff_timestamp =
262                         dp_trace_get_edp_poweroff_timestamp;
263         link_srv->dp_trace_source_sequence = dp_trace_source_sequence;
264 }
265
266 static void construct_link_service(struct link_service *link_srv)
267 {
268         /* All link service functions should fall under some sub categories.
269          * If a new function doesn't perfectly fall under an existing sub
270          * category, it must be that you are either adding a whole new aspect of
271          * responsibility to link service or something doesn't belong to link
272          * service. In that case please contact the arch owner to arrange a
273          * design review meeting.
274          */
275         construct_link_service_factory(link_srv);
276         construct_link_service_detection(link_srv);
277         construct_link_service_resource(link_srv);
278         construct_link_service_validation(link_srv);
279         construct_link_service_dpms(link_srv);
280         construct_link_service_ddc(link_srv);
281         construct_link_service_dp_capability(link_srv);
282         construct_link_service_dp_phy_or_dpia(link_srv);
283         construct_link_service_dp_irq_handler(link_srv);
284         construct_link_service_edp_panel_control(link_srv);
285         construct_link_service_dp_cts(link_srv);
286         construct_link_service_dp_trace(link_srv);
287 }
288
289 struct link_service *link_create_link_service(void)
290 {
291         struct link_service *link_srv = kzalloc(sizeof(*link_srv), GFP_KERNEL);
292
293         if (link_srv == NULL)
294                 goto fail;
295
296         construct_link_service(link_srv);
297
298         return link_srv;
299 fail:
300         return NULL;
301 }
302
303 void link_destroy_link_service(struct link_service **link_srv)
304 {
305         kfree(*link_srv);
306         *link_srv = NULL;
307 }
308
309 static enum transmitter translate_encoder_to_transmitter(
310                 struct graphics_object_id encoder)
311 {
312         switch (encoder.id) {
313         case ENCODER_ID_INTERNAL_UNIPHY:
314                 switch (encoder.enum_id) {
315                 case ENUM_ID_1:
316                         return TRANSMITTER_UNIPHY_A;
317                 case ENUM_ID_2:
318                         return TRANSMITTER_UNIPHY_B;
319                 default:
320                         return TRANSMITTER_UNKNOWN;
321                 }
322         break;
323         case ENCODER_ID_INTERNAL_UNIPHY1:
324                 switch (encoder.enum_id) {
325                 case ENUM_ID_1:
326                         return TRANSMITTER_UNIPHY_C;
327                 case ENUM_ID_2:
328                         return TRANSMITTER_UNIPHY_D;
329                 default:
330                         return TRANSMITTER_UNKNOWN;
331                 }
332         break;
333         case ENCODER_ID_INTERNAL_UNIPHY2:
334                 switch (encoder.enum_id) {
335                 case ENUM_ID_1:
336                         return TRANSMITTER_UNIPHY_E;
337                 case ENUM_ID_2:
338                         return TRANSMITTER_UNIPHY_F;
339                 default:
340                         return TRANSMITTER_UNKNOWN;
341                 }
342         break;
343         case ENCODER_ID_INTERNAL_UNIPHY3:
344                 switch (encoder.enum_id) {
345                 case ENUM_ID_1:
346                         return TRANSMITTER_UNIPHY_G;
347                 default:
348                         return TRANSMITTER_UNKNOWN;
349                 }
350         break;
351         case ENCODER_ID_EXTERNAL_NUTMEG:
352                 switch (encoder.enum_id) {
353                 case ENUM_ID_1:
354                         return TRANSMITTER_NUTMEG_CRT;
355                 default:
356                         return TRANSMITTER_UNKNOWN;
357                 }
358         break;
359         case ENCODER_ID_EXTERNAL_TRAVIS:
360                 switch (encoder.enum_id) {
361                 case ENUM_ID_1:
362                         return TRANSMITTER_TRAVIS_CRT;
363                 case ENUM_ID_2:
364                         return TRANSMITTER_TRAVIS_LCD;
365                 default:
366                         return TRANSMITTER_UNKNOWN;
367                 }
368         break;
369         default:
370                 return TRANSMITTER_UNKNOWN;
371         }
372 }
373
374 static void link_destruct(struct dc_link *link)
375 {
376         int i;
377
378         if (link->hpd_gpio) {
379                 dal_gpio_destroy_irq(&link->hpd_gpio);
380                 link->hpd_gpio = NULL;
381         }
382
383         if (link->ddc)
384                 link_destroy_ddc_service(&link->ddc);
385
386         if (link->panel_cntl)
387                 link->panel_cntl->funcs->destroy(&link->panel_cntl);
388
389         if (link->link_enc && !link->is_dig_mapping_flexible) {
390                 /* Update link encoder resource tracking variables. These are used for
391                  * the dynamic assignment of link encoders to streams. Virtual links
392                  * are not assigned encoder resources on creation.
393                  */
394                 if (link->link_id.id != CONNECTOR_ID_VIRTUAL && link->eng_id != ENGINE_ID_UNKNOWN) {
395                         link->dc->res_pool->link_encoders[link->eng_id - ENGINE_ID_DIGA] = NULL;
396                         link->dc->res_pool->dig_link_enc_count--;
397                 }
398                 link->link_enc->funcs->destroy(&link->link_enc);
399         }
400
401         if (link->local_sink)
402                 dc_sink_release(link->local_sink);
403
404         for (i = 0; i < link->sink_count; ++i)
405                 dc_sink_release(link->remote_sinks[i]);
406 }
407
408 static enum channel_id get_ddc_line(struct dc_link *link)
409 {
410         struct ddc *ddc;
411         enum channel_id channel;
412
413         channel = CHANNEL_ID_UNKNOWN;
414
415         ddc = get_ddc_pin(link->ddc);
416
417         if (ddc) {
418                 switch (dal_ddc_get_line(ddc)) {
419                 case GPIO_DDC_LINE_DDC1:
420                         channel = CHANNEL_ID_DDC1;
421                         break;
422                 case GPIO_DDC_LINE_DDC2:
423                         channel = CHANNEL_ID_DDC2;
424                         break;
425                 case GPIO_DDC_LINE_DDC3:
426                         channel = CHANNEL_ID_DDC3;
427                         break;
428                 case GPIO_DDC_LINE_DDC4:
429                         channel = CHANNEL_ID_DDC4;
430                         break;
431                 case GPIO_DDC_LINE_DDC5:
432                         channel = CHANNEL_ID_DDC5;
433                         break;
434                 case GPIO_DDC_LINE_DDC6:
435                         channel = CHANNEL_ID_DDC6;
436                         break;
437                 case GPIO_DDC_LINE_DDC_VGA:
438                         channel = CHANNEL_ID_DDC_VGA;
439                         break;
440                 case GPIO_DDC_LINE_I2C_PAD:
441                         channel = CHANNEL_ID_I2C_PAD;
442                         break;
443                 default:
444                         BREAK_TO_DEBUGGER();
445                         break;
446                 }
447         }
448
449         return channel;
450 }
451
452 static bool construct_phy(struct dc_link *link,
453                               const struct link_init_data *init_params)
454 {
455         uint8_t i;
456         struct ddc_service_init_data ddc_service_init_data = { 0 };
457         struct dc_context *dc_ctx = init_params->ctx;
458         struct encoder_init_data enc_init_data = { 0 };
459         struct panel_cntl_init_data panel_cntl_init_data = { 0 };
460         struct dc_bios *bios = init_params->dc->ctx->dc_bios;
461         const struct dc_vbios_funcs *bp_funcs = bios->funcs;
462         struct bp_disp_connector_caps_info disp_connect_caps_info = { 0 };
463
464         DC_LOGGER_INIT(dc_ctx->logger);
465
466         link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
467         link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
468         link->link_status.dpcd_caps = &link->dpcd_caps;
469
470         link->dc = init_params->dc;
471         link->ctx = dc_ctx;
472         link->link_index = init_params->link_index;
473
474         memset(&link->preferred_training_settings, 0,
475                sizeof(struct dc_link_training_overrides));
476         memset(&link->preferred_link_setting, 0,
477                sizeof(struct dc_link_settings));
478
479         link->link_id =
480                 bios->funcs->get_connector_id(bios, init_params->connector_index);
481
482         link->ep_type = DISPLAY_ENDPOINT_PHY;
483
484         DC_LOG_DC("BIOS object table - link_id: %d", link->link_id.id);
485
486         if (bios->funcs->get_disp_connector_caps_info) {
487                 bios->funcs->get_disp_connector_caps_info(bios, link->link_id, &disp_connect_caps_info);
488                 link->is_internal_display = disp_connect_caps_info.INTERNAL_DISPLAY;
489                 DC_LOG_DC("BIOS object table - is_internal_display: %d", link->is_internal_display);
490         }
491
492         if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
493                 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
494                                      __func__, init_params->connector_index,
495                                      link->link_id.type, OBJECT_TYPE_CONNECTOR);
496                 goto create_fail;
497         }
498
499         if (link->dc->res_pool->funcs->link_init)
500                 link->dc->res_pool->funcs->link_init(link);
501
502         link->hpd_gpio = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
503                                       link->ctx->gpio_service);
504
505         if (link->hpd_gpio) {
506                 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
507                 dal_gpio_unlock_pin(link->hpd_gpio);
508                 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
509
510                 DC_LOG_DC("BIOS object table - hpd_gpio id: %d", link->hpd_gpio->id);
511                 DC_LOG_DC("BIOS object table - hpd_gpio en: %d", link->hpd_gpio->en);
512         }
513
514         switch (link->link_id.id) {
515         case CONNECTOR_ID_HDMI_TYPE_A:
516                 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
517
518                 break;
519         case CONNECTOR_ID_SINGLE_LINK_DVID:
520         case CONNECTOR_ID_SINGLE_LINK_DVII:
521                 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
522                 break;
523         case CONNECTOR_ID_DUAL_LINK_DVID:
524         case CONNECTOR_ID_DUAL_LINK_DVII:
525                 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
526                 break;
527         case CONNECTOR_ID_DISPLAY_PORT:
528         case CONNECTOR_ID_MXM:
529         case CONNECTOR_ID_USBC:
530                 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
531
532                 if (link->hpd_gpio)
533                         link->irq_source_hpd_rx =
534                                         dal_irq_get_rx_source(link->hpd_gpio);
535
536                 break;
537         case CONNECTOR_ID_EDP:
538                 link->connector_signal = SIGNAL_TYPE_EDP;
539
540                 if (link->hpd_gpio) {
541                         if (!link->dc->config.allow_edp_hotplug_detection)
542                                 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
543
544                         switch (link->dc->config.allow_edp_hotplug_detection) {
545                         case HPD_EN_FOR_ALL_EDP:
546                                 link->irq_source_hpd_rx =
547                                                 dal_irq_get_rx_source(link->hpd_gpio);
548                                 break;
549                         case HPD_EN_FOR_PRIMARY_EDP_ONLY:
550                                 if (link->link_index == 0)
551                                         link->irq_source_hpd_rx =
552                                                 dal_irq_get_rx_source(link->hpd_gpio);
553                                 else
554                                         link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
555                                 break;
556                         case HPD_EN_FOR_SECONDARY_EDP_ONLY:
557                                 if (link->link_index == 1)
558                                         link->irq_source_hpd_rx =
559                                                 dal_irq_get_rx_source(link->hpd_gpio);
560                                 else
561                                         link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
562                                 break;
563                         default:
564                                 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
565                                 break;
566                         }
567                 }
568
569                 break;
570         case CONNECTOR_ID_LVDS:
571                 link->connector_signal = SIGNAL_TYPE_LVDS;
572                 break;
573         default:
574                 DC_LOG_WARNING("Unsupported Connector type:%d!\n",
575                                link->link_id.id);
576                 goto create_fail;
577         }
578
579         LINK_INFO("Connector[%d] description: signal: %s\n",
580                   init_params->connector_index,
581                   signal_type_to_string(link->connector_signal));
582
583         ddc_service_init_data.ctx = link->ctx;
584         ddc_service_init_data.id = link->link_id;
585         ddc_service_init_data.link = link;
586         link->ddc = link_create_ddc_service(&ddc_service_init_data);
587
588         if (!link->ddc) {
589                 DC_ERROR("Failed to create ddc_service!\n");
590                 goto ddc_create_fail;
591         }
592
593         if (!link->ddc->ddc_pin) {
594                 DC_ERROR("Failed to get I2C info for connector!\n");
595                 goto ddc_create_fail;
596         }
597
598         link->ddc_hw_inst =
599                 dal_ddc_get_line(get_ddc_pin(link->ddc));
600
601         enc_init_data.ctx = dc_ctx;
602         bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
603                               &enc_init_data.encoder);
604         enc_init_data.connector = link->link_id;
605         enc_init_data.channel = get_ddc_line(link);
606         enc_init_data.hpd_source = get_hpd_line(link);
607
608         link->hpd_src = enc_init_data.hpd_source;
609
610         enc_init_data.transmitter =
611                 translate_encoder_to_transmitter(enc_init_data.encoder);
612         link->link_enc =
613                 link->dc->res_pool->funcs->link_enc_create(dc_ctx, &enc_init_data);
614
615         if (!link->link_enc) {
616                 DC_ERROR("Failed to create link encoder!\n");
617                 goto link_enc_create_fail;
618         }
619
620         DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
621         DC_LOG_DC("BIOS object table - IS_DP2_CAPABLE: %d", link->link_enc->features.flags.bits.IS_DP2_CAPABLE);
622
623         /* Update link encoder tracking variables. These are used for the dynamic
624          * assignment of link encoders to streams.
625          */
626         link->eng_id = link->link_enc->preferred_engine;
627         link->dc->res_pool->link_encoders[link->eng_id - ENGINE_ID_DIGA] = link->link_enc;
628         link->dc->res_pool->dig_link_enc_count++;
629
630         link->link_enc_hw_inst = link->link_enc->transmitter;
631
632         if (link->dc->res_pool->funcs->panel_cntl_create &&
633                 (link->link_id.id == CONNECTOR_ID_EDP ||
634                         link->link_id.id == CONNECTOR_ID_LVDS)) {
635                 panel_cntl_init_data.ctx = dc_ctx;
636                 panel_cntl_init_data.inst = panel_cntl_init_data.ctx->dc_edp_id_count;
637                 panel_cntl_init_data.eng_id = link->eng_id;
638                 link->panel_cntl =
639                         link->dc->res_pool->funcs->panel_cntl_create(
640                                                                 &panel_cntl_init_data);
641                 panel_cntl_init_data.ctx->dc_edp_id_count++;
642
643                 if (link->panel_cntl == NULL) {
644                         DC_ERROR("Failed to create link panel_cntl!\n");
645                         goto panel_cntl_create_fail;
646                 }
647         }
648         for (i = 0; i < 4; i++) {
649                 if (bp_funcs->get_device_tag(dc_ctx->dc_bios,
650                                              link->link_id, i,
651                                              &link->device_tag) != BP_RESULT_OK) {
652                         DC_ERROR("Failed to find device tag!\n");
653                         goto device_tag_fail;
654                 }
655
656                 /* Look for device tag that matches connector signal,
657                  * CRT for rgb, LCD for other supported signal tyes
658                  */
659                 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios,
660                                                       link->device_tag.dev_id))
661                         continue;
662                 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT &&
663                     link->connector_signal != SIGNAL_TYPE_RGB)
664                         continue;
665                 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD &&
666                     link->connector_signal == SIGNAL_TYPE_RGB)
667                         continue;
668
669                 DC_LOG_DC("BIOS object table - device_tag.acpi_device: %d", link->device_tag.acpi_device);
670                 DC_LOG_DC("BIOS object table - device_tag.dev_id.device_type: %d", link->device_tag.dev_id.device_type);
671                 DC_LOG_DC("BIOS object table - device_tag.dev_id.enum_id: %d", link->device_tag.dev_id.enum_id);
672                 break;
673         }
674
675         if (bios->integrated_info) {
676                 /* Look for channel mapping corresponding to connector and device tag */
677                 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
678                         struct external_display_path *path =
679                                 &bios->integrated_info->ext_disp_conn_info.path[i];
680
681                         if (path->device_connector_id.enum_id == link->link_id.enum_id &&
682                             path->device_connector_id.id == link->link_id.id &&
683                             path->device_connector_id.type == link->link_id.type) {
684                                 if (link->device_tag.acpi_device != 0 &&
685                                     path->device_acpi_enum == link->device_tag.acpi_device) {
686                                         link->ddi_channel_mapping = path->channel_mapping;
687                                         link->chip_caps = path->caps;
688                                         DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X",
689                                                   link->ddi_channel_mapping.raw);
690                                         DC_LOG_DC("BIOS object table - chip_caps: %d",
691                                                   link->chip_caps);
692                                 } else if (path->device_tag ==
693                                            link->device_tag.dev_id.raw_device_tag) {
694                                         link->ddi_channel_mapping = path->channel_mapping;
695                                         link->chip_caps = path->caps;
696                                         DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X",
697                                                   link->ddi_channel_mapping.raw);
698                                         DC_LOG_DC("BIOS object table - chip_caps: %d",
699                                                   link->chip_caps);
700                                 }
701
702                                 if ((link->chip_caps & AMD_EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK) == AMD_EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) {
703                                         link->bios_forced_drive_settings.VOLTAGE_SWING =
704                                                 (bios->integrated_info->ext_disp_conn_info.fixdpvoltageswing & 0x3);
705                                         link->bios_forced_drive_settings.PRE_EMPHASIS =
706                                                 ((bios->integrated_info->ext_disp_conn_info.fixdpvoltageswing >> 2) & 0x3);
707                                 }
708
709                                 break;
710                         }
711                 }
712         }
713         if (bios->funcs->get_atom_dc_golden_table)
714                 bios->funcs->get_atom_dc_golden_table(bios);
715
716         /*
717          * TODO check if GPIO programmed correctly
718          *
719          * If GPIO isn't programmed correctly HPD might not rise or drain
720          * fast enough, leading to bounces.
721          */
722         program_hpd_filter(link);
723
724         link->psr_settings.psr_vtotal_control_support = false;
725         link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
726
727         DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
728         return true;
729 device_tag_fail:
730         link->link_enc->funcs->destroy(&link->link_enc);
731 link_enc_create_fail:
732         if (link->panel_cntl != NULL)
733                 link->panel_cntl->funcs->destroy(&link->panel_cntl);
734 panel_cntl_create_fail:
735         link_destroy_ddc_service(&link->ddc);
736 ddc_create_fail:
737 create_fail:
738
739         if (link->hpd_gpio) {
740                 dal_gpio_destroy_irq(&link->hpd_gpio);
741                 link->hpd_gpio = NULL;
742         }
743
744         DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
745         return false;
746 }
747
748 static bool construct_dpia(struct dc_link *link,
749                               const struct link_init_data *init_params)
750 {
751         struct ddc_service_init_data ddc_service_init_data = { 0 };
752         struct dc_context *dc_ctx = init_params->ctx;
753
754         DC_LOGGER_INIT(dc_ctx->logger);
755
756         /* Initialized irq source for hpd and hpd rx */
757         link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
758         link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
759         link->link_status.dpcd_caps = &link->dpcd_caps;
760
761         link->dc = init_params->dc;
762         link->ctx = dc_ctx;
763         link->link_index = init_params->link_index;
764
765         memset(&link->preferred_training_settings, 0,
766                sizeof(struct dc_link_training_overrides));
767         memset(&link->preferred_link_setting, 0,
768                sizeof(struct dc_link_settings));
769
770         /* Dummy Init for linkid */
771         link->link_id.type = OBJECT_TYPE_CONNECTOR;
772         link->link_id.id = CONNECTOR_ID_DISPLAY_PORT;
773         link->link_id.enum_id = ENUM_ID_1 + init_params->connector_index;
774         link->is_internal_display = false;
775         link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
776         LINK_INFO("Connector[%d] description:signal %d\n",
777                   init_params->connector_index,
778                   link->connector_signal);
779
780         link->ep_type = DISPLAY_ENDPOINT_USB4_DPIA;
781         link->is_dig_mapping_flexible = true;
782
783         /* TODO: Initialize link : funcs->link_init */
784
785         ddc_service_init_data.ctx = link->ctx;
786         ddc_service_init_data.id = link->link_id;
787         ddc_service_init_data.link = link;
788         /* Set indicator for dpia link so that ddc wont be created */
789         ddc_service_init_data.is_dpia_link = true;
790
791         link->ddc = link_create_ddc_service(&ddc_service_init_data);
792         if (!link->ddc) {
793                 DC_ERROR("Failed to create ddc_service!\n");
794                 goto ddc_create_fail;
795         }
796
797         /* Set dpia port index : 0 to number of dpia ports */
798         link->ddc_hw_inst = init_params->connector_index;
799
800         // Assign Dpia preferred eng_id
801         if (link->dc->res_pool->funcs->get_preferred_eng_id_dpia)
802                 link->dpia_preferred_eng_id = link->dc->res_pool->funcs->get_preferred_eng_id_dpia(link->ddc_hw_inst);
803
804         /* TODO: Create link encoder */
805
806         link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
807
808         /* Some docks seem to NAK I2C writes to segment pointer with mot=0. */
809         link->wa_flags.dp_mot_reset_segment = true;
810
811         return true;
812
813 ddc_create_fail:
814         return false;
815 }
816
817 static bool link_construct(struct dc_link *link,
818                               const struct link_init_data *init_params)
819 {
820         /* Handle dpia case */
821         if (init_params->is_dpia_link == true)
822                 return construct_dpia(link, init_params);
823         else
824                 return construct_phy(link, init_params);
825 }
826
827 struct dc_link *link_create(const struct link_init_data *init_params)
828 {
829         struct dc_link *link =
830                         kzalloc(sizeof(*link), GFP_KERNEL);
831
832         if (NULL == link)
833                 goto alloc_fail;
834
835         if (false == link_construct(link, init_params))
836                 goto construct_fail;
837
838         return link;
839
840 construct_fail:
841         kfree(link);
842
843 alloc_fail:
844         return NULL;
845 }
846
847 void link_destroy(struct dc_link **link)
848 {
849         link_destruct(*link);
850         kfree(*link);
851         *link = NULL;
852 }
This page took 0.086915 seconds and 4 git commands to generate.