• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012-15 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 #include <linux/slab.h>
27 
28 #include "dm_services.h"
29 #include "dm_helpers.h"
30 #include "gpio_service_interface.h"
31 #include "include/ddc_service_types.h"
32 #include "include/grph_object_id.h"
33 #include "include/dpcd_defs.h"
34 #include "include/logger_interface.h"
35 #include "include/vector.h"
36 #include "core_types.h"
37 #include "dc_link_ddc.h"
38 #include "dce/dce_aux.h"
39 
40 #define AUX_POWER_UP_WA_DELAY 500
41 #define I2C_OVER_AUX_DEFER_WA_DELAY 70
42 
43 /* CV smart dongle slave address for retrieving supported HDTV modes*/
44 #define CV_SMART_DONGLE_ADDRESS 0x20
45 /* DVI-HDMI dongle slave address for retrieving dongle signature*/
46 #define DVI_HDMI_DONGLE_ADDRESS 0x68
47 struct dvi_hdmi_dongle_signature_data {
48 	int8_t vendor[3];/* "AMD" */
49 	uint8_t version[2];
50 	uint8_t size;
51 	int8_t id[11];/* "6140063500G"*/
52 };
53 /* DP-HDMI dongle slave address for retrieving dongle signature*/
54 #define DP_HDMI_DONGLE_ADDRESS 0x40
55 static const uint8_t dp_hdmi_dongle_signature_str[] = "DP-HDMI ADAPTOR";
56 #define DP_HDMI_DONGLE_SIGNATURE_EOT 0x04
57 
58 struct dp_hdmi_dongle_signature_data {
59 	int8_t id[15];/* "DP-HDMI ADAPTOR"*/
60 	uint8_t eot;/* end of transmition '\x4' */
61 };
62 
63 /* SCDC Address defines (HDMI 2.0)*/
64 #define HDMI_SCDC_WRITE_UPDATE_0_ARRAY 3
65 #define HDMI_SCDC_ADDRESS  0x54
66 #define HDMI_SCDC_SINK_VERSION 0x01
67 #define HDMI_SCDC_SOURCE_VERSION 0x02
68 #define HDMI_SCDC_UPDATE_0 0x10
69 #define HDMI_SCDC_TMDS_CONFIG 0x20
70 #define HDMI_SCDC_SCRAMBLER_STATUS 0x21
71 #define HDMI_SCDC_CONFIG_0 0x30
72 #define HDMI_SCDC_STATUS_FLAGS 0x40
73 #define HDMI_SCDC_ERR_DETECT 0x50
74 #define HDMI_SCDC_TEST_CONFIG 0xC0
75 
76 union hdmi_scdc_update_read_data {
77 	uint8_t byte[2];
78 	struct {
79 		uint8_t STATUS_UPDATE:1;
80 		uint8_t CED_UPDATE:1;
81 		uint8_t RR_TEST:1;
82 		uint8_t RESERVED:5;
83 		uint8_t RESERVED2:8;
84 	} fields;
85 };
86 
87 union hdmi_scdc_status_flags_data {
88 	uint8_t byte[2];
89 	struct {
90 		uint8_t CLOCK_DETECTED:1;
91 		uint8_t CH0_LOCKED:1;
92 		uint8_t CH1_LOCKED:1;
93 		uint8_t CH2_LOCKED:1;
94 		uint8_t RESERVED:4;
95 		uint8_t RESERVED2:8;
96 		uint8_t RESERVED3:8;
97 
98 	} fields;
99 };
100 
101 union hdmi_scdc_ced_data {
102 	uint8_t byte[7];
103 	struct {
104 		uint8_t CH0_8LOW:8;
105 		uint8_t CH0_7HIGH:7;
106 		uint8_t CH0_VALID:1;
107 		uint8_t CH1_8LOW:8;
108 		uint8_t CH1_7HIGH:7;
109 		uint8_t CH1_VALID:1;
110 		uint8_t CH2_8LOW:8;
111 		uint8_t CH2_7HIGH:7;
112 		uint8_t CH2_VALID:1;
113 		uint8_t CHECKSUM:8;
114 		uint8_t RESERVED:8;
115 		uint8_t RESERVED2:8;
116 		uint8_t RESERVED3:8;
117 		uint8_t RESERVED4:4;
118 	} fields;
119 };
120 
121 struct i2c_payloads {
122 	struct vector payloads;
123 };
124 
125 struct aux_payloads {
126 	struct vector payloads;
127 };
128 
dal_ddc_i2c_payloads_create(struct dc_context * ctx,struct i2c_payloads * payloads,uint32_t count)129 static bool dal_ddc_i2c_payloads_create(
130 		struct dc_context *ctx,
131 		struct i2c_payloads *payloads,
132 		uint32_t count)
133 {
134 	if (dal_vector_construct(
135 		&payloads->payloads, ctx, count, sizeof(struct i2c_payload)))
136 		return true;
137 
138 	return false;
139 }
140 
dal_ddc_i2c_payloads_get(struct i2c_payloads * p)141 static struct i2c_payload *dal_ddc_i2c_payloads_get(struct i2c_payloads *p)
142 {
143 	return (struct i2c_payload *)p->payloads.container;
144 }
145 
dal_ddc_i2c_payloads_get_count(struct i2c_payloads * p)146 static uint32_t dal_ddc_i2c_payloads_get_count(struct i2c_payloads *p)
147 {
148 	return p->payloads.count;
149 }
150 
151 #define DDC_MIN(a, b) (((a) < (b)) ? (a) : (b))
152 
dal_ddc_i2c_payloads_add(struct i2c_payloads * payloads,uint32_t address,uint32_t len,uint8_t * data,bool write)153 void dal_ddc_i2c_payloads_add(
154 	struct i2c_payloads *payloads,
155 	uint32_t address,
156 	uint32_t len,
157 	uint8_t *data,
158 	bool write)
159 {
160 	uint32_t payload_size = EDID_SEGMENT_SIZE;
161 	uint32_t pos;
162 
163 	for (pos = 0; pos < len; pos += payload_size) {
164 		struct i2c_payload payload = {
165 			.write = write,
166 			.address = address,
167 			.length = DDC_MIN(payload_size, len - pos),
168 			.data = data + pos };
169 		dal_vector_append(&payloads->payloads, &payload);
170 	}
171 
172 }
173 
ddc_service_construct(struct ddc_service * ddc_service,struct ddc_service_init_data * init_data)174 static void ddc_service_construct(
175 	struct ddc_service *ddc_service,
176 	struct ddc_service_init_data *init_data)
177 {
178 	enum connector_id connector_id =
179 		dal_graphics_object_id_get_connector_id(init_data->id);
180 
181 	struct gpio_service *gpio_service = init_data->ctx->gpio_service;
182 	struct graphics_object_i2c_info i2c_info;
183 	struct gpio_ddc_hw_info hw_info;
184 	struct dc_bios *dcb = init_data->ctx->dc_bios;
185 
186 	ddc_service->link = init_data->link;
187 	ddc_service->ctx = init_data->ctx;
188 
189 	if (BP_RESULT_OK != dcb->funcs->get_i2c_info(dcb, init_data->id, &i2c_info)) {
190 		ddc_service->ddc_pin = NULL;
191 	} else {
192 		hw_info.ddc_channel = i2c_info.i2c_line;
193 		if (ddc_service->link != NULL)
194 			hw_info.hw_supported = i2c_info.i2c_hw_assist;
195 		else
196 			hw_info.hw_supported = false;
197 
198 		ddc_service->ddc_pin = dal_gpio_create_ddc(
199 			gpio_service,
200 			i2c_info.gpio_info.clk_a_register_index,
201 			1 << i2c_info.gpio_info.clk_a_shift,
202 			&hw_info);
203 	}
204 
205 	ddc_service->flags.EDID_QUERY_DONE_ONCE = false;
206 	ddc_service->flags.FORCE_READ_REPEATED_START = false;
207 	ddc_service->flags.EDID_STRESS_READ = false;
208 
209 	ddc_service->flags.IS_INTERNAL_DISPLAY =
210 		connector_id == CONNECTOR_ID_EDP ||
211 		connector_id == CONNECTOR_ID_LVDS;
212 
213 	ddc_service->wa.raw = 0;
214 }
215 
dal_ddc_service_create(struct ddc_service_init_data * init_data)216 struct ddc_service *dal_ddc_service_create(
217 	struct ddc_service_init_data *init_data)
218 {
219 	struct ddc_service *ddc_service;
220 
221 	ddc_service = kzalloc(sizeof(struct ddc_service), GFP_KERNEL);
222 
223 	if (!ddc_service)
224 		return NULL;
225 
226 	ddc_service_construct(ddc_service, init_data);
227 	return ddc_service;
228 }
229 
ddc_service_destruct(struct ddc_service * ddc)230 static void ddc_service_destruct(struct ddc_service *ddc)
231 {
232 	if (ddc->ddc_pin)
233 		dal_gpio_destroy_ddc(&ddc->ddc_pin);
234 }
235 
dal_ddc_service_destroy(struct ddc_service ** ddc)236 void dal_ddc_service_destroy(struct ddc_service **ddc)
237 {
238 	if (!ddc || !*ddc) {
239 		BREAK_TO_DEBUGGER();
240 		return;
241 	}
242 	ddc_service_destruct(*ddc);
243 	kfree(*ddc);
244 	*ddc = NULL;
245 }
246 
dal_ddc_service_get_type(struct ddc_service * ddc)247 enum ddc_service_type dal_ddc_service_get_type(struct ddc_service *ddc)
248 {
249 	return DDC_SERVICE_TYPE_CONNECTOR;
250 }
251 
dal_ddc_service_set_transaction_type(struct ddc_service * ddc,enum ddc_transaction_type type)252 void dal_ddc_service_set_transaction_type(
253 	struct ddc_service *ddc,
254 	enum ddc_transaction_type type)
255 {
256 	ddc->transaction_type = type;
257 }
258 
dal_ddc_service_is_in_aux_transaction_mode(struct ddc_service * ddc)259 bool dal_ddc_service_is_in_aux_transaction_mode(struct ddc_service *ddc)
260 {
261 	switch (ddc->transaction_type) {
262 	case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
263 	case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
264 	case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_RETRY_DEFER:
265 		return true;
266 	default:
267 		break;
268 	}
269 	return false;
270 }
271 
ddc_service_set_dongle_type(struct ddc_service * ddc,enum display_dongle_type dongle_type)272 void ddc_service_set_dongle_type(struct ddc_service *ddc,
273 		enum display_dongle_type dongle_type)
274 {
275 	ddc->dongle_type = dongle_type;
276 }
277 
defer_delay_converter_wa(struct ddc_service * ddc,uint32_t defer_delay)278 static uint32_t defer_delay_converter_wa(
279 	struct ddc_service *ddc,
280 	uint32_t defer_delay)
281 {
282 	struct dc_link *link = ddc->link;
283 
284 	if (link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_0080E1 &&
285 		!memcmp(link->dpcd_caps.branch_dev_name,
286 			DP_DVI_CONVERTER_ID_4,
287 			sizeof(link->dpcd_caps.branch_dev_name)))
288 		return defer_delay > I2C_OVER_AUX_DEFER_WA_DELAY ?
289 			defer_delay : I2C_OVER_AUX_DEFER_WA_DELAY;
290 
291 	return defer_delay;
292 }
293 
294 #define DP_TRANSLATOR_DELAY 5
295 
get_defer_delay(struct ddc_service * ddc)296 uint32_t get_defer_delay(struct ddc_service *ddc)
297 {
298 	uint32_t defer_delay = 0;
299 
300 	switch (ddc->transaction_type) {
301 	case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
302 		if ((DISPLAY_DONGLE_DP_VGA_CONVERTER == ddc->dongle_type) ||
303 			(DISPLAY_DONGLE_DP_DVI_CONVERTER == ddc->dongle_type) ||
304 			(DISPLAY_DONGLE_DP_HDMI_CONVERTER ==
305 				ddc->dongle_type)) {
306 
307 			defer_delay = DP_TRANSLATOR_DELAY;
308 
309 			defer_delay =
310 				defer_delay_converter_wa(ddc, defer_delay);
311 
312 		} else /*sink has a delay different from an Active Converter*/
313 			defer_delay = 0;
314 		break;
315 	case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
316 		defer_delay = DP_TRANSLATOR_DELAY;
317 		break;
318 	default:
319 		break;
320 	}
321 	return defer_delay;
322 }
323 
i2c_read(struct ddc_service * ddc,uint32_t address,uint8_t * buffer,uint32_t len)324 static bool i2c_read(
325 	struct ddc_service *ddc,
326 	uint32_t address,
327 	uint8_t *buffer,
328 	uint32_t len)
329 {
330 	uint8_t offs_data = 0;
331 	struct i2c_payload payloads[2] = {
332 		{
333 		.write = true,
334 		.address = address,
335 		.length = 1,
336 		.data = &offs_data },
337 		{
338 		.write = false,
339 		.address = address,
340 		.length = len,
341 		.data = buffer } };
342 
343 	struct i2c_command command = {
344 		.payloads = payloads,
345 		.number_of_payloads = 2,
346 		.engine = DDC_I2C_COMMAND_ENGINE,
347 		.speed = ddc->ctx->dc->caps.i2c_speed_in_khz };
348 
349 	return dm_helpers_submit_i2c(
350 			ddc->ctx,
351 			ddc->link,
352 			&command);
353 }
354 
dal_ddc_service_i2c_query_dp_dual_mode_adaptor(struct ddc_service * ddc,struct display_sink_capability * sink_cap)355 void dal_ddc_service_i2c_query_dp_dual_mode_adaptor(
356 	struct ddc_service *ddc,
357 	struct display_sink_capability *sink_cap)
358 {
359 	uint8_t i;
360 	bool is_valid_hdmi_signature;
361 	enum display_dongle_type *dongle = &sink_cap->dongle_type;
362 	uint8_t type2_dongle_buf[DP_ADAPTOR_TYPE2_SIZE];
363 	bool is_type2_dongle = false;
364 	int retry_count = 2;
365 	struct dp_hdmi_dongle_signature_data *dongle_signature;
366 
367 	/* Assume we have no valid DP passive dongle connected */
368 	*dongle = DISPLAY_DONGLE_NONE;
369 	sink_cap->max_hdmi_pixel_clock = DP_ADAPTOR_HDMI_SAFE_MAX_TMDS_CLK;
370 
371 	/* Read DP-HDMI dongle I2c (no response interpreted as DP-DVI dongle)*/
372 	if (!i2c_read(
373 		ddc,
374 		DP_HDMI_DONGLE_ADDRESS,
375 		type2_dongle_buf,
376 		sizeof(type2_dongle_buf))) {
377 		/* Passive HDMI dongles can sometimes fail here without retrying*/
378 		while (retry_count > 0) {
379 			if (i2c_read(ddc,
380 				DP_HDMI_DONGLE_ADDRESS,
381 				type2_dongle_buf,
382 				sizeof(type2_dongle_buf)))
383 				break;
384 			retry_count--;
385 		}
386 		if (retry_count == 0) {
387 			*dongle = DISPLAY_DONGLE_DP_DVI_DONGLE;
388 			sink_cap->max_hdmi_pixel_clock = DP_ADAPTOR_DVI_MAX_TMDS_CLK;
389 
390 			CONN_DATA_DETECT(ddc->link, type2_dongle_buf, sizeof(type2_dongle_buf),
391 					"DP-DVI passive dongle %dMhz: ",
392 					DP_ADAPTOR_DVI_MAX_TMDS_CLK / 1000);
393 			return;
394 		}
395 	}
396 
397 	/* Check if Type 2 dongle.*/
398 	if (type2_dongle_buf[DP_ADAPTOR_TYPE2_REG_ID] == DP_ADAPTOR_TYPE2_ID)
399 		is_type2_dongle = true;
400 
401 	dongle_signature =
402 		(struct dp_hdmi_dongle_signature_data *)type2_dongle_buf;
403 
404 	is_valid_hdmi_signature = true;
405 
406 	/* Check EOT */
407 	if (dongle_signature->eot != DP_HDMI_DONGLE_SIGNATURE_EOT) {
408 		is_valid_hdmi_signature = false;
409 	}
410 
411 	/* Check signature */
412 	for (i = 0; i < sizeof(dongle_signature->id); ++i) {
413 		/* If its not the right signature,
414 		 * skip mismatch in subversion byte.*/
415 		if (dongle_signature->id[i] !=
416 			dp_hdmi_dongle_signature_str[i] && i != 3) {
417 
418 			if (is_type2_dongle) {
419 				is_valid_hdmi_signature = false;
420 				break;
421 			}
422 
423 		}
424 	}
425 
426 	if (is_type2_dongle) {
427 		uint32_t max_tmds_clk =
428 			type2_dongle_buf[DP_ADAPTOR_TYPE2_REG_MAX_TMDS_CLK];
429 
430 		max_tmds_clk = max_tmds_clk * 2 + max_tmds_clk / 2;
431 
432 		if (0 == max_tmds_clk ||
433 				max_tmds_clk < DP_ADAPTOR_TYPE2_MIN_TMDS_CLK ||
434 				max_tmds_clk > DP_ADAPTOR_TYPE2_MAX_TMDS_CLK) {
435 			*dongle = DISPLAY_DONGLE_DP_DVI_DONGLE;
436 
437 			CONN_DATA_DETECT(ddc->link, type2_dongle_buf,
438 					sizeof(type2_dongle_buf),
439 					"DP-DVI passive dongle %dMhz: ",
440 					DP_ADAPTOR_DVI_MAX_TMDS_CLK / 1000);
441 		} else {
442 			if (is_valid_hdmi_signature == true) {
443 				*dongle = DISPLAY_DONGLE_DP_HDMI_DONGLE;
444 
445 				CONN_DATA_DETECT(ddc->link, type2_dongle_buf,
446 						sizeof(type2_dongle_buf),
447 						"Type 2 DP-HDMI passive dongle %dMhz: ",
448 						max_tmds_clk);
449 			} else {
450 				*dongle = DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE;
451 
452 				CONN_DATA_DETECT(ddc->link, type2_dongle_buf,
453 						sizeof(type2_dongle_buf),
454 						"Type 2 DP-HDMI passive dongle (no signature) %dMhz: ",
455 						max_tmds_clk);
456 
457 			}
458 
459 			/* Multiply by 1000 to convert to kHz. */
460 			sink_cap->max_hdmi_pixel_clock =
461 				max_tmds_clk * 1000;
462 		}
463 
464 	} else {
465 		if (is_valid_hdmi_signature == true) {
466 			*dongle = DISPLAY_DONGLE_DP_HDMI_DONGLE;
467 
468 			CONN_DATA_DETECT(ddc->link, type2_dongle_buf,
469 					sizeof(type2_dongle_buf),
470 					"Type 1 DP-HDMI passive dongle %dMhz: ",
471 					sink_cap->max_hdmi_pixel_clock / 1000);
472 		} else {
473 			*dongle = DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE;
474 
475 			CONN_DATA_DETECT(ddc->link, type2_dongle_buf,
476 					sizeof(type2_dongle_buf),
477 					"Type 1 DP-HDMI passive dongle (no signature) %dMhz: ",
478 					sink_cap->max_hdmi_pixel_clock / 1000);
479 		}
480 	}
481 
482 	return;
483 }
484 
485 enum {
486 	DP_SINK_CAP_SIZE =
487 		DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV + 1
488 };
489 
dal_ddc_service_query_ddc_data(struct ddc_service * ddc,uint32_t address,uint8_t * write_buf,uint32_t write_size,uint8_t * read_buf,uint32_t read_size)490 bool dal_ddc_service_query_ddc_data(
491 	struct ddc_service *ddc,
492 	uint32_t address,
493 	uint8_t *write_buf,
494 	uint32_t write_size,
495 	uint8_t *read_buf,
496 	uint32_t read_size)
497 {
498 	bool success = true;
499 	uint32_t payload_size =
500 		dal_ddc_service_is_in_aux_transaction_mode(ddc) ?
501 			DEFAULT_AUX_MAX_DATA_SIZE : EDID_SEGMENT_SIZE;
502 
503 	uint32_t write_payloads =
504 		(write_size + payload_size - 1) / payload_size;
505 
506 	uint32_t read_payloads =
507 		(read_size + payload_size - 1) / payload_size;
508 
509 	uint32_t payloads_num = write_payloads + read_payloads;
510 
511 
512 	if (write_size > EDID_SEGMENT_SIZE || read_size > EDID_SEGMENT_SIZE)
513 		return false;
514 
515 	if (!payloads_num)
516 		return false;
517 
518 	/*TODO: len of payload data for i2c and aux is uint8!!!!,
519 	 *  but we want to read 256 over i2c!!!!*/
520 	if (dal_ddc_service_is_in_aux_transaction_mode(ddc)) {
521 		struct aux_payload payload;
522 
523 		payload.i2c_over_aux = true;
524 		payload.address = address;
525 		payload.reply = NULL;
526 		payload.defer_delay = get_defer_delay(ddc);
527 
528 		if (write_size != 0) {
529 			payload.write = true;
530 			/* should not set mot (middle of transaction) to 0
531 			 * if there are pending read payloads
532 			 */
533 			payload.mot = read_size == 0 ? false : true;
534 			payload.length = write_size;
535 			payload.data = write_buf;
536 
537 			success = dal_ddc_submit_aux_command(ddc, &payload);
538 		}
539 
540 		if (read_size != 0 && success) {
541 			payload.write = false;
542 			/* should set mot (middle of transaction) to 0
543 			 * since it is the last payload to send
544 			 */
545 			payload.mot = false;
546 			payload.length = read_size;
547 			payload.data = read_buf;
548 
549 			success = dal_ddc_submit_aux_command(ddc, &payload);
550 		}
551 	} else {
552 		struct i2c_command command = {0};
553 		struct i2c_payloads payloads;
554 
555 		if (!dal_ddc_i2c_payloads_create(ddc->ctx, &payloads, payloads_num))
556 			return false;
557 
558 		command.payloads = dal_ddc_i2c_payloads_get(&payloads);
559 		command.number_of_payloads = 0;
560 		command.engine = DDC_I2C_COMMAND_ENGINE;
561 		command.speed = ddc->ctx->dc->caps.i2c_speed_in_khz;
562 
563 		dal_ddc_i2c_payloads_add(
564 			&payloads, address, write_size, write_buf, true);
565 
566 		dal_ddc_i2c_payloads_add(
567 			&payloads, address, read_size, read_buf, false);
568 
569 		command.number_of_payloads =
570 			dal_ddc_i2c_payloads_get_count(&payloads);
571 
572 		success = dm_helpers_submit_i2c(
573 				ddc->ctx,
574 				ddc->link,
575 				&command);
576 
577 		dal_vector_destruct(&payloads.payloads);
578 	}
579 
580 	return success;
581 }
582 
dal_ddc_submit_aux_command(struct ddc_service * ddc,struct aux_payload * payload)583 bool dal_ddc_submit_aux_command(struct ddc_service *ddc,
584 		struct aux_payload *payload)
585 {
586 	uint32_t retrieved = 0;
587 	bool ret = false;
588 
589 	if (!ddc)
590 		return false;
591 
592 	if (!payload)
593 		return false;
594 
595 	do {
596 		struct aux_payload current_payload;
597 		bool is_end_of_payload = (retrieved + DEFAULT_AUX_MAX_DATA_SIZE) >=
598 			payload->length;
599 
600 		current_payload.address = payload->address;
601 		current_payload.data = &payload->data[retrieved];
602 		current_payload.defer_delay = payload->defer_delay;
603 		current_payload.i2c_over_aux = payload->i2c_over_aux;
604 		current_payload.length = is_end_of_payload ?
605 			payload->length - retrieved : DEFAULT_AUX_MAX_DATA_SIZE;
606 		/* set mot (middle of transaction) to false
607 		 * if it is the last payload
608 		 */
609 		current_payload.mot = is_end_of_payload ? payload->mot:true;
610 		current_payload.reply = payload->reply;
611 		current_payload.write = payload->write;
612 
613 		ret = dc_link_aux_transfer_with_retries(ddc, &current_payload);
614 
615 		retrieved += current_payload.length;
616 	} while (retrieved < payload->length && ret == true);
617 
618 	return ret;
619 }
620 
621 /* dc_link_aux_transfer_raw() - Attempt to transfer
622  * the given aux payload.  This function does not perform
623  * retries or handle error states.  The reply is returned
624  * in the payload->reply and the result through
625  * *operation_result.  Returns the number of bytes transferred,
626  * or -1 on a failure.
627  */
dc_link_aux_transfer_raw(struct ddc_service * ddc,struct aux_payload * payload,enum aux_channel_operation_result * operation_result)628 int dc_link_aux_transfer_raw(struct ddc_service *ddc,
629 		struct aux_payload *payload,
630 		enum aux_channel_operation_result *operation_result)
631 {
632 	return dce_aux_transfer_raw(ddc, payload, operation_result);
633 }
634 
635 /* dc_link_aux_transfer_with_retries() - Attempt to submit an
636  * aux payload, retrying on timeouts, defers, and busy states
637  * as outlined in the DP spec.  Returns true if the request
638  * was successful.
639  *
640  * Unless you want to implement your own retry semantics, this
641  * is probably the one you want.
642  */
dc_link_aux_transfer_with_retries(struct ddc_service * ddc,struct aux_payload * payload)643 bool dc_link_aux_transfer_with_retries(struct ddc_service *ddc,
644 		struct aux_payload *payload)
645 {
646 	return dce_aux_transfer_with_retries(ddc, payload);
647 }
648 
649 
dc_link_aux_try_to_configure_timeout(struct ddc_service * ddc,uint32_t timeout)650 bool dc_link_aux_try_to_configure_timeout(struct ddc_service *ddc,
651 		uint32_t timeout)
652 {
653 	bool result = false;
654 	struct ddc *ddc_pin = ddc->ddc_pin;
655 
656 	if (ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout) {
657 		ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout(ddc, timeout);
658 		result = true;
659 	}
660 	return result;
661 }
662 
663 /*test only function*/
dal_ddc_service_set_ddc_pin(struct ddc_service * ddc_service,struct ddc * ddc)664 void dal_ddc_service_set_ddc_pin(
665 	struct ddc_service *ddc_service,
666 	struct ddc *ddc)
667 {
668 	ddc_service->ddc_pin = ddc;
669 }
670 
dal_ddc_service_get_ddc_pin(struct ddc_service * ddc_service)671 struct ddc *dal_ddc_service_get_ddc_pin(struct ddc_service *ddc_service)
672 {
673 	return ddc_service->ddc_pin;
674 }
675 
dal_ddc_service_write_scdc_data(struct ddc_service * ddc_service,uint32_t pix_clk,bool lte_340_scramble)676 void dal_ddc_service_write_scdc_data(struct ddc_service *ddc_service,
677 		uint32_t pix_clk,
678 		bool lte_340_scramble)
679 {
680 	bool over_340_mhz = pix_clk > 340000 ? 1 : 0;
681 	uint8_t slave_address = HDMI_SCDC_ADDRESS;
682 	uint8_t offset = HDMI_SCDC_SINK_VERSION;
683 	uint8_t sink_version = 0;
684 	uint8_t write_buffer[2] = {0};
685 	/*Lower than 340 Scramble bit from SCDC caps*/
686 
687 	if (ddc_service->link->local_sink &&
688 		ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
689 		return;
690 
691 	dal_ddc_service_query_ddc_data(ddc_service, slave_address, &offset,
692 			sizeof(offset), &sink_version, sizeof(sink_version));
693 	if (sink_version == 1) {
694 		/*Source Version = 1*/
695 		write_buffer[0] = HDMI_SCDC_SOURCE_VERSION;
696 		write_buffer[1] = 1;
697 		dal_ddc_service_query_ddc_data(ddc_service, slave_address,
698 				write_buffer, sizeof(write_buffer), NULL, 0);
699 		/*Read Request from SCDC caps*/
700 	}
701 	write_buffer[0] = HDMI_SCDC_TMDS_CONFIG;
702 
703 	if (over_340_mhz) {
704 		write_buffer[1] = 3;
705 	} else if (lte_340_scramble) {
706 		write_buffer[1] = 1;
707 	} else {
708 		write_buffer[1] = 0;
709 	}
710 	dal_ddc_service_query_ddc_data(ddc_service, slave_address, write_buffer,
711 			sizeof(write_buffer), NULL, 0);
712 }
713 
dal_ddc_service_read_scdc_data(struct ddc_service * ddc_service)714 void dal_ddc_service_read_scdc_data(struct ddc_service *ddc_service)
715 {
716 	uint8_t slave_address = HDMI_SCDC_ADDRESS;
717 	uint8_t offset = HDMI_SCDC_TMDS_CONFIG;
718 	uint8_t tmds_config = 0;
719 
720 	if (ddc_service->link->local_sink &&
721 		ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
722 		return;
723 
724 	dal_ddc_service_query_ddc_data(ddc_service, slave_address, &offset,
725 			sizeof(offset), &tmds_config, sizeof(tmds_config));
726 	if (tmds_config & 0x1) {
727 		union hdmi_scdc_status_flags_data status_data = { {0} };
728 		uint8_t scramble_status = 0;
729 
730 		offset = HDMI_SCDC_SCRAMBLER_STATUS;
731 		dal_ddc_service_query_ddc_data(ddc_service, slave_address,
732 				&offset, sizeof(offset), &scramble_status,
733 				sizeof(scramble_status));
734 		offset = HDMI_SCDC_STATUS_FLAGS;
735 		dal_ddc_service_query_ddc_data(ddc_service, slave_address,
736 				&offset, sizeof(offset), status_data.byte,
737 				sizeof(status_data.byte));
738 	}
739 }
740 
741