1
2
3
4
5
6
7
8
9
10
11
12#include <common.h>
13#include <clk.h>
14#include <display.h>
15#include <dm.h>
16#include <errno.h>
17#include <linux/delay.h>
18
19#include "axi.h"
20#include "logicore_dp_dpcd.h"
21#include "logicore_dp_tx.h"
22#include "logicore_dp_tx_regif.h"
23
24
25#define S_AXI_CLK_DEFAULT 100000000
26
27
28#define PHY_CLOCK_SELECT_DEFAULT PHY_CLOCK_SELECT_540GBPS
29
30
31#define MAXIMUM_VS_LEVEL 3
32
33#define MAXIMUM_PE_LEVEL 3
34
35
36#define AUX_MAX_DEFER_COUNT 50
37
38#define AUX_MAX_TIMEOUT_COUNT 50
39
40#define IS_CONNECTED_MAX_TIMEOUT_COUNT 50
41
42
43
44
45
46
47
48
49
50
51
52
53enum link_training_states {
54 TS_CLOCK_RECOVERY,
55 TS_CHANNEL_EQUALIZATION,
56 TS_ADJUST_LINK_RATE,
57 TS_ADJUST_LANE_COUNT,
58 TS_FAILURE,
59 TS_SUCCESS
60};
61
62
63
64
65
66
67
68
69struct aux_transaction {
70 u16 cmd_code;
71 u8 num_bytes;
72 u32 address;
73 u8 *data;
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
121struct main_stream_attributes {
122 u32 pixel_clock_hz;
123 u32 misc_0;
124 u32 misc_1;
125 u32 n_vid;
126
127 u32 user_pixel_width;
128 u32 data_per_lane;
129 u32 avg_bytes_per_tu;
130 u32 transfer_unit_size;
131 u32 init_wait;
132 u32 bits_per_color;
133 u8 component_format;
134 u8 dynamic_range;
135 u8 y_cb_cr_colorimetry;
136 u8 synchronous_clock_mode;
137 u8 override_user_pixel_width;
138 u32 h_start;
139 u16 h_active;
140 u16 h_sync_width;
141 u16 h_total;
142 bool h_sync_polarity;
143 u32 v_start;
144 u16 v_active;
145 u16 v_sync_width;
146 u16 v_total;
147 bool v_sync_polarity;
148};
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165struct link_config {
166 u8 lane_count;
167 u8 link_rate;
168 bool scrambler_en;
169 bool enhanced_framing_mode;
170 u8 max_lane_count;
171 u8 max_link_rate;
172 bool support_enhanced_framing_mode;
173 u8 vs_level;
174 u8 pe_level;
175};
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198struct dp_tx {
199 u32 base;
200 u32 s_axi_clk;
201 bool train_adaptive;
202 u8 max_link_rate;
203 u8 max_lane_count;
204 u8 dpcd_rx_caps[16];
205 u8 lane_status_ajd_reqs[6];
206 struct link_config link_config;
207 struct main_stream_attributes main_stream_attributes;
208};
209
210
211
212
213
214
215
216
217
218
219
220
221static u32 get_reg(struct udevice *dev, u32 reg)
222{
223 struct dp_tx *dp_tx = dev_get_priv(dev);
224 u32 value = 0;
225 int res;
226
227
228 res = axi_read(dev->parent, dp_tx->base + reg, &value, AXI_SIZE_32);
229 if (res < 0)
230 printf("%s() failed; res = %d\n", __func__, res);
231
232 return value;
233}
234
235
236
237
238
239
240
241static void set_reg(struct udevice *dev, u32 reg, u32 value)
242{
243 struct dp_tx *dp_tx = dev_get_priv(dev);
244
245 axi_write(dev->parent, dp_tx->base + reg, &value, AXI_SIZE_32);
246}
247
248
249
250
251
252
253
254
255
256
257static bool is_connected(struct udevice *dev)
258{
259 u8 retries = 0;
260
261 do {
262 int status = get_reg(dev, REG_INTERRUPT_SIG_STATE) &
263 INTERRUPT_SIG_STATE_HPD_STATE_MASK;
264 if (status)
265 return true;
266
267 udelay(1000);
268 } while (retries++ < IS_CONNECTED_MAX_TIMEOUT_COUNT);
269
270 return false;
271}
272
273
274
275
276
277
278
279
280
281static int wait_phy_ready(struct udevice *dev, u32 mask)
282{
283 u16 timeout = 20000;
284 u32 phy_status;
285
286
287 do {
288 phy_status = get_reg(dev, REG_PHY_STATUS) & mask;
289
290
291 if (!timeout--)
292 return -ETIMEDOUT;
293
294 udelay(20);
295 } while (phy_status != mask);
296
297 return 0;
298}
299
300
301
302
303
304
305
306
307
308static int aux_wait_ready(struct udevice *dev)
309{
310 int status;
311 u32 timeout = 100;
312
313
314 do {
315 status = get_reg(dev, REG_INTERRUPT_SIG_STATE);
316
317
318 if (!timeout--)
319 return -ETIMEDOUT;
320 udelay(20);
321 } while (status & REPLY_STATUS_REPLY_IN_PROGRESS_MASK);
322
323 return 0;
324}
325
326
327
328
329
330
331
332
333
334
335static int aux_wait_reply(struct udevice *dev)
336{
337 u32 timeout = 100;
338
339 while (timeout > 0) {
340 int status = get_reg(dev, REG_REPLY_STATUS);
341
342
343 if (status & REPLY_STATUS_REPLY_ERROR_MASK)
344 return -ETIMEDOUT;
345
346
347 if ((status & REPLY_STATUS_REPLY_RECEIVED_MASK) &&
348 !(status &
349 REPLY_STATUS_REQUEST_IN_PROGRESS_MASK) &&
350 !(status &
351 REPLY_STATUS_REPLY_IN_PROGRESS_MASK)) {
352 return 0;
353 }
354
355 timeout--;
356 udelay(20);
357 }
358
359 return -ETIMEDOUT;
360}
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375static int aux_request_send(struct udevice *dev,
376 struct aux_transaction *request)
377{
378 u32 timeout_count;
379 int status;
380 u8 index;
381
382
383 timeout_count = 0;
384 do {
385 status = get_reg(dev, REG_REPLY_STATUS);
386
387 udelay(20);
388 timeout_count++;
389 if (timeout_count >= AUX_MAX_TIMEOUT_COUNT)
390 return -ETIMEDOUT;
391 } while ((status & REPLY_STATUS_REQUEST_IN_PROGRESS_MASK) ||
392 (status & REPLY_STATUS_REPLY_IN_PROGRESS_MASK));
393
394 set_reg(dev, REG_AUX_ADDRESS, request->address);
395
396 if (request->cmd_code == AUX_CMD_WRITE ||
397 request->cmd_code == AUX_CMD_I2C_WRITE ||
398 request->cmd_code == AUX_CMD_I2C_WRITE_MOT) {
399
400 for (index = 0; index < request->num_bytes; index++) {
401 set_reg(dev,
402 REG_AUX_WRITE_FIFO, request->data[index]);
403 }
404 }
405
406
407 set_reg(dev, REG_AUX_CMD,
408 ((request->cmd_code << AUX_CMD_SHIFT) |
409 ((request->num_bytes - 1) &
410 AUX_CMD_NBYTES_TRANSFER_MASK)));
411
412
413 status = aux_wait_reply(dev);
414 if (status)
415
416 return -ETIMEDOUT;
417
418
419 status = get_reg(dev, REG_AUX_REPLY_CODE);
420 if (status == AUX_REPLY_CODE_DEFER ||
421 status == AUX_REPLY_CODE_I2C_DEFER) {
422
423 return -EAGAIN;
424 } else if ((status == AUX_REPLY_CODE_NACK) ||
425 (status == AUX_REPLY_CODE_I2C_NACK)) {
426
427 return -EIO;
428 }
429
430
431
432 if (request->cmd_code == AUX_CMD_READ ||
433 request->cmd_code == AUX_CMD_I2C_READ ||
434 request->cmd_code == AUX_CMD_I2C_READ_MOT) {
435
436 timeout_count = 0;
437 do {
438 status = get_reg(dev, REG_REPLY_DATA_COUNT);
439
440 udelay(100);
441 timeout_count++;
442 if (timeout_count >= AUX_MAX_TIMEOUT_COUNT)
443 return -ETIMEDOUT;
444 } while (status != request->num_bytes);
445
446
447 for (index = 0; index < request->num_bytes; index++)
448 request->data[index] = get_reg(dev, REG_AUX_REPLY_DATA);
449 }
450
451 return 0;
452}
453
454
455
456
457
458
459
460
461
462
463
464
465
466static int aux_request(struct udevice *dev, struct aux_transaction *request)
467{
468 u32 defer_count = 0;
469 u32 timeout_count = 0;
470
471 while ((defer_count < AUX_MAX_DEFER_COUNT) &&
472 (timeout_count < AUX_MAX_TIMEOUT_COUNT)) {
473 int status = aux_wait_ready(dev);
474
475 if (status) {
476
477 timeout_count++;
478 continue;
479 }
480
481 status = aux_request_send(dev, request);
482 if (status == -EAGAIN) {
483
484 defer_count++;
485 } else if (status == -ETIMEDOUT) {
486
487 timeout_count++;
488 } else {
489
490
491
492
493 return status;
494 }
495
496 udelay(100);
497 }
498
499
500 return -ETIMEDOUT;
501}
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518static int aux_common(struct udevice *dev, u32 cmd_type, u32 address,
519 u32 num_bytes, u8 *data)
520{
521 struct aux_transaction request;
522 u32 bytes_left;
523
524
525
526
527
528 request.address = address;
529
530 bytes_left = num_bytes;
531 while (bytes_left) {
532 int status;
533
534 request.cmd_code = cmd_type;
535
536 if (cmd_type == AUX_CMD_READ ||
537 cmd_type == AUX_CMD_WRITE) {
538
539 request.address = address + (num_bytes - bytes_left);
540 }
541
542
543 request.data = &data[num_bytes - bytes_left];
544
545 request.num_bytes = (bytes_left > 16) ? 16 : bytes_left;
546 bytes_left -= request.num_bytes;
547
548 if (cmd_type == AUX_CMD_I2C_READ && bytes_left) {
549
550
551
552
553 request.cmd_code = AUX_CMD_I2C_READ_MOT;
554 } else if ((cmd_type == AUX_CMD_I2C_WRITE) && bytes_left) {
555
556
557
558
559 request.cmd_code = AUX_CMD_I2C_WRITE_MOT;
560 }
561
562 status = aux_request(dev, &request);
563 if (status)
564 return status;
565 }
566
567 return 0;
568}
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584static int aux_read(struct udevice *dev, u32 dpcd_address, u32 bytes_to_read,
585 void *read_data)
586{
587 int status;
588
589 if (!is_connected(dev))
590 return -ENODEV;
591
592
593 status = aux_common(dev, AUX_CMD_READ, dpcd_address,
594 bytes_to_read, (u8 *)read_data);
595
596 return status;
597}
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613static int aux_write(struct udevice *dev, u32 dpcd_address, u32 bytes_to_write,
614 void *write_data)
615{
616 int status;
617
618 if (!is_connected(dev))
619 return -ENODEV;
620
621
622 status = aux_common(dev, AUX_CMD_WRITE, dpcd_address,
623 bytes_to_write, (u8 *)write_data);
624
625 return status;
626}
627
628
629
630
631
632
633
634
635
636static int initialize(struct udevice *dev)
637{
638 struct dp_tx *dp_tx = dev_get_priv(dev);
639 u32 val;
640 u32 phy_config;
641 unsigned int k;
642
643
644 phy_config = get_reg(dev, REG_PHY_CONFIG);
645 set_reg(dev, REG_PHY_CONFIG, phy_config | PHY_CONFIG_GT_ALL_RESET_MASK);
646
647
648 set_reg(dev, REG_SOFT_RESET,
649 SOFT_RESET_VIDEO_STREAM_ALL_MASK |
650 SOFT_RESET_AUX_MASK);
651
652
653 set_reg(dev, REG_ENABLE, 0);
654
655
656 val = get_reg(dev, REG_AUX_CLK_DIVIDER);
657 val &= ~AUX_CLK_DIVIDER_VAL_MASK;
658 val |= dp_tx->s_axi_clk / 1000000;
659 set_reg(dev, REG_AUX_CLK_DIVIDER, val);
660
661
662 set_reg(dev, REG_PHY_CLOCK_SELECT, PHY_CLOCK_SELECT_DEFAULT);
663
664
665 set_reg(dev, REG_PHY_CONFIG,
666 phy_config & ~PHY_CONFIG_GT_ALL_RESET_MASK);
667
668
669 set_reg(dev, REG_ENABLE, 1);
670
671
672 set_reg(dev, REG_INTERRUPT_MASK,
673 ~INTERRUPT_MASK_HPD_PULSE_DETECTED_MASK &
674 ~INTERRUPT_MASK_HPD_EVENT_MASK &
675 ~INTERRUPT_MASK_HPD_IRQ_MASK);
676
677 for (k = 0; k < 4; k++) {
678
679 set_reg(dev, REG_PHY_PRECURSOR_LANE_0 + 4 * k, 0);
680
681
682 set_reg(dev, REG_PHY_VOLTAGE_DIFF_LANE_0 + 4 * k, 0);
683
684
685 set_reg(dev, REG_PHY_POSTCURSOR_LANE_0 + 4 * k, 0);
686 }
687
688 return 0;
689}
690
691
692
693
694
695
696
697
698static bool is_link_rate_valid(struct udevice *dev, u8 link_rate)
699{
700 struct dp_tx *dp_tx = dev_get_priv(dev);
701 bool valid = true;
702
703 if (link_rate != LINK_BW_SET_162GBPS &&
704 link_rate != LINK_BW_SET_270GBPS &&
705 link_rate != LINK_BW_SET_540GBPS)
706 valid = false;
707 else if (link_rate > dp_tx->link_config.max_link_rate)
708 valid = false;
709
710 return valid;
711}
712
713
714
715
716
717
718
719
720static bool is_lane_count_valid(struct udevice *dev, u8 lane_count)
721{
722 struct dp_tx *dp_tx = dev_get_priv(dev);
723 bool valid = true;
724
725 if (lane_count != LANE_COUNT_SET_1 &&
726 lane_count != LANE_COUNT_SET_2 &&
727 lane_count != LANE_COUNT_SET_4)
728 valid = false;
729 else if (lane_count > dp_tx->link_config.max_lane_count)
730 valid = false;
731
732 return valid;
733}
734
735
736
737
738
739
740
741
742
743static int get_rx_capabilities(struct udevice *dev)
744{
745 struct dp_tx *dp_tx = dev_get_priv(dev);
746 int status;
747 u8 rx_max_link_rate;
748 u8 rx_max_lane_count;
749
750 if (!is_connected(dev))
751 return -ENODEV;
752
753 status = aux_read(dev, DPCD_RECEIVER_CAP_FIELD_START, 16,
754 dp_tx->dpcd_rx_caps);
755 if (status)
756 return -EIO;
757
758 rx_max_link_rate = dp_tx->dpcd_rx_caps[DPCD_MAX_LINK_RATE];
759 rx_max_lane_count = dp_tx->dpcd_rx_caps[DPCD_MAX_LANE_COUNT] &
760 DPCD_MAX_LANE_COUNT_MASK;
761
762 dp_tx->link_config.max_link_rate =
763 (rx_max_link_rate > dp_tx->max_link_rate) ?
764 dp_tx->max_link_rate : rx_max_link_rate;
765 if (!is_link_rate_valid(dev, rx_max_link_rate))
766 return -EINVAL;
767
768 dp_tx->link_config.max_lane_count =
769 (rx_max_lane_count > dp_tx->max_lane_count) ?
770 dp_tx->max_lane_count : rx_max_lane_count;
771 if (!is_lane_count_valid(dev, rx_max_lane_count))
772 return -EINVAL;
773
774 dp_tx->link_config.support_enhanced_framing_mode =
775 dp_tx->dpcd_rx_caps[DPCD_MAX_LANE_COUNT] &
776 DPCD_ENHANCED_FRAME_SUPPORT_MASK;
777
778 return 0;
779}
780
781
782
783
784
785static void enable_main_link(struct udevice *dev)
786{
787
788 set_reg(dev, REG_FORCE_SCRAMBLER_RESET, 0x1);
789
790
791 set_reg(dev, REG_ENABLE_MAIN_STREAM, 0x1);
792}
793
794
795
796
797
798static void disable_main_link(struct udevice *dev)
799{
800
801 set_reg(dev, REG_FORCE_SCRAMBLER_RESET, 0x1);
802
803
804 set_reg(dev, REG_ENABLE_MAIN_STREAM, 0x0);
805}
806
807
808
809
810
811
812
813static void reset_dp_phy(struct udevice *dev, u32 reset)
814{
815 struct dp_tx *dp_tx = dev_get_priv(dev);
816 u32 val;
817
818 set_reg(dev, REG_ENABLE, 0x0);
819
820 val = get_reg(dev, REG_PHY_CONFIG);
821
822
823 set_reg(dev, REG_PHY_CONFIG, val | reset);
824
825
826 set_reg(dev, REG_PHY_CONFIG, val);
827
828
829 wait_phy_ready(dev, phy_status_lanes_ready_mask(dp_tx->max_lane_count));
830
831 set_reg(dev, REG_ENABLE, 0x1);
832}
833
834
835
836
837
838
839
840
841
842
843
844
845
846static int set_enhanced_frame_mode(struct udevice *dev, u8 enable)
847{
848 struct dp_tx *dp_tx = dev_get_priv(dev);
849 int status;
850 u8 val;
851
852 if (!is_connected(dev))
853 return -ENODEV;
854
855 if (dp_tx->link_config.support_enhanced_framing_mode)
856 dp_tx->link_config.enhanced_framing_mode = enable;
857 else
858 dp_tx->link_config.enhanced_framing_mode = false;
859
860
861 set_reg(dev, REG_ENHANCED_FRAME_EN,
862 dp_tx->link_config.enhanced_framing_mode);
863
864
865 status = aux_read(dev, DPCD_LANE_COUNT_SET, 0x1, &val);
866 if (status)
867 return -EIO;
868
869 if (dp_tx->link_config.enhanced_framing_mode)
870 val |= DPCD_ENHANCED_FRAME_EN_MASK;
871 else
872 val &= ~DPCD_ENHANCED_FRAME_EN_MASK;
873
874 status = aux_write(dev, DPCD_LANE_COUNT_SET, 0x1, &val);
875 if (status)
876 return -EIO;
877
878 return 0;
879}
880
881
882
883
884
885
886
887
888
889
890
891static int set_lane_count(struct udevice *dev, u8 lane_count)
892{
893 struct dp_tx *dp_tx = dev_get_priv(dev);
894 int status;
895 u8 val;
896
897 if (!is_connected(dev))
898 return -ENODEV;
899
900 printf(" set lane count to %u\n", lane_count);
901
902 dp_tx->link_config.lane_count = lane_count;
903
904
905 set_reg(dev, REG_LANE_COUNT_SET, dp_tx->link_config.lane_count);
906
907
908 status = aux_read(dev, DPCD_LANE_COUNT_SET, 0x1, &val);
909 if (status)
910 return -EIO;
911 val &= ~DPCD_LANE_COUNT_SET_MASK;
912 val |= dp_tx->link_config.lane_count;
913
914 status = aux_write(dev, DPCD_LANE_COUNT_SET, 0x1, &val);
915 if (status)
916 return -EIO;
917
918 return 0;
919}
920
921
922
923
924
925
926
927
928
929
930
931static int set_clk_speed(struct udevice *dev, u32 speed)
932{
933 struct dp_tx *dp_tx = dev_get_priv(dev);
934 int status;
935 u32 val;
936 u32 mask;
937
938
939 val = get_reg(dev, REG_ENABLE);
940 set_reg(dev, REG_ENABLE, 0x0);
941
942
943 set_reg(dev, REG_PHY_CLOCK_SELECT, speed);
944
945
946 if (val)
947 set_reg(dev, REG_ENABLE, 0x1);
948
949
950 mask = phy_status_lanes_ready_mask(dp_tx->max_lane_count);
951 status = wait_phy_ready(dev, mask);
952 if (status)
953 return -EIO;
954
955 return 0;
956}
957
958
959
960
961
962
963
964
965
966
967
968static int set_link_rate(struct udevice *dev, u8 link_rate)
969{
970 struct dp_tx *dp_tx = dev_get_priv(dev);
971 int status;
972
973
974 switch (link_rate) {
975 case LINK_BW_SET_162GBPS:
976 printf(" set link rate to 1.62 Gb/s\n");
977 status = set_clk_speed(dev, PHY_CLOCK_SELECT_162GBPS);
978 break;
979 case LINK_BW_SET_270GBPS:
980 printf(" set link rate to 2.70 Gb/s\n");
981 status = set_clk_speed(dev, PHY_CLOCK_SELECT_270GBPS);
982 break;
983 case LINK_BW_SET_540GBPS:
984 printf(" set link rate to 5.40 Gb/s\n");
985 status = set_clk_speed(dev, PHY_CLOCK_SELECT_540GBPS);
986 break;
987 default:
988 return -EINVAL;
989 }
990 if (status)
991 return -EIO;
992
993 dp_tx->link_config.link_rate = link_rate;
994
995
996 set_reg(dev, REG_LINK_BW_SET, dp_tx->link_config.link_rate);
997
998
999 status = aux_write(dev, DPCD_LINK_BW_SET, 1,
1000 &dp_tx->link_config.link_rate);
1001 if (status)
1002 return -EIO;
1003
1004 return 0;
1005}
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020static int get_training_delay(struct udevice *dev, int training_state)
1021{
1022 struct dp_tx *dp_tx = dev_get_priv(dev);
1023 u16 delay;
1024
1025 switch (dp_tx->dpcd_rx_caps[DPCD_TRAIN_AUX_RD_INTERVAL]) {
1026 case DPCD_TRAIN_AUX_RD_INT_100_400US:
1027 if (training_state == TS_CLOCK_RECOVERY)
1028
1029 delay = 100;
1030 else
1031
1032 delay = 400;
1033 break;
1034 case DPCD_TRAIN_AUX_RD_INT_4MS:
1035 delay = 4000;
1036 break;
1037 case DPCD_TRAIN_AUX_RD_INT_8MS:
1038 delay = 8000;
1039 break;
1040 case DPCD_TRAIN_AUX_RD_INT_12MS:
1041 delay = 12000;
1042 break;
1043 case DPCD_TRAIN_AUX_RD_INT_16MS:
1044 delay = 16000;
1045 break;
1046 default:
1047
1048 delay = 20000;
1049 break;
1050 }
1051
1052 return delay;
1053}
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063static void set_vswing_preemp(struct udevice *dev, u8 *aux_data)
1064{
1065 struct dp_tx *dp_tx = dev_get_priv(dev);
1066 u8 data;
1067 u8 vs_level_rx = dp_tx->link_config.vs_level;
1068 u8 pe_level_rx = dp_tx->link_config.pe_level;
1069
1070
1071 data = (pe_level_rx << DPCD_TRAINING_LANEX_SET_PE_SHIFT) | vs_level_rx;
1072
1073 if (vs_level_rx == MAXIMUM_VS_LEVEL)
1074 data |= DPCD_TRAINING_LANEX_SET_MAX_VS_MASK;
1075
1076
1077 if (pe_level_rx == MAXIMUM_PE_LEVEL)
1078 data |= DPCD_TRAINING_LANEX_SET_MAX_PE_MASK;
1079 memset(aux_data, data, 4);
1080}
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092static int adj_vswing_preemp(struct udevice *dev)
1093{
1094 struct dp_tx *dp_tx = dev_get_priv(dev);
1095 int status;
1096 u8 index;
1097 u8 vs_level_adj_req[4];
1098 u8 pe_level_adj_req[4];
1099 u8 aux_data[4];
1100 u8 *ajd_reqs = &dp_tx->lane_status_ajd_reqs[4];
1101
1102
1103
1104
1105
1106 vs_level_adj_req[0] = ajd_reqs[0] & DPCD_ADJ_REQ_LANE_0_2_VS_MASK;
1107 vs_level_adj_req[1] = (ajd_reqs[0] & DPCD_ADJ_REQ_LANE_1_3_VS_MASK) >>
1108 DPCD_ADJ_REQ_LANE_1_3_VS_SHIFT;
1109 vs_level_adj_req[2] = ajd_reqs[1] & DPCD_ADJ_REQ_LANE_0_2_VS_MASK;
1110 vs_level_adj_req[3] = (ajd_reqs[1] & DPCD_ADJ_REQ_LANE_1_3_VS_MASK) >>
1111 DPCD_ADJ_REQ_LANE_1_3_VS_SHIFT;
1112 pe_level_adj_req[0] = (ajd_reqs[0] & DPCD_ADJ_REQ_LANE_0_2_PE_MASK) >>
1113 DPCD_ADJ_REQ_LANE_0_2_PE_SHIFT;
1114 pe_level_adj_req[1] = (ajd_reqs[0] & DPCD_ADJ_REQ_LANE_1_3_PE_MASK) >>
1115 DPCD_ADJ_REQ_LANE_1_3_PE_SHIFT;
1116 pe_level_adj_req[2] = (ajd_reqs[1] & DPCD_ADJ_REQ_LANE_0_2_PE_MASK) >>
1117 DPCD_ADJ_REQ_LANE_0_2_PE_SHIFT;
1118 pe_level_adj_req[3] = (ajd_reqs[1] & DPCD_ADJ_REQ_LANE_1_3_PE_MASK) >>
1119 DPCD_ADJ_REQ_LANE_1_3_PE_SHIFT;
1120
1121
1122
1123
1124
1125 dp_tx->link_config.vs_level = 0;
1126 dp_tx->link_config.pe_level = 0;
1127 for (index = 0; index < dp_tx->link_config.lane_count; index++) {
1128 if (vs_level_adj_req[index] > dp_tx->link_config.vs_level)
1129 dp_tx->link_config.vs_level = vs_level_adj_req[index];
1130 if (pe_level_adj_req[index] > dp_tx->link_config.pe_level)
1131 dp_tx->link_config.pe_level = pe_level_adj_req[index];
1132 }
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150 if (dp_tx->link_config.pe_level > (3 - dp_tx->link_config.vs_level))
1151 dp_tx->link_config.pe_level = 3 - dp_tx->link_config.vs_level;
1152
1153
1154
1155
1156
1157 set_vswing_preemp(dev, aux_data);
1158
1159
1160
1161
1162 status = aux_write(dev, DPCD_TRAINING_LANE0_SET, 4, aux_data);
1163 if (status)
1164 return -EIO;
1165
1166 return 0;
1167}
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180static int get_lane_status_adj_reqs(struct udevice *dev)
1181{
1182 struct dp_tx *dp_tx = dev_get_priv(dev);
1183 int status;
1184
1185
1186
1187
1188
1189 status = aux_read(dev, DPCD_STATUS_LANE_0_1, 6,
1190 dp_tx->lane_status_ajd_reqs);
1191 if (status)
1192 return -EIO;
1193
1194 return 0;
1195}
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210static int check_clock_recovery(struct udevice *dev, u8 lane_count)
1211{
1212 struct dp_tx *dp_tx = dev_get_priv(dev);
1213 u8 *lane_status = dp_tx->lane_status_ajd_reqs;
1214
1215
1216 switch (lane_count) {
1217 case LANE_COUNT_SET_4:
1218 if (!(lane_status[1] & DPCD_STATUS_LANE_3_CR_DONE_MASK))
1219 goto out_fail;
1220 if (!(lane_status[1] & DPCD_STATUS_LANE_2_CR_DONE_MASK))
1221 goto out_fail;
1222
1223 case LANE_COUNT_SET_2:
1224 if (!(lane_status[0] & DPCD_STATUS_LANE_1_CR_DONE_MASK))
1225 goto out_fail;
1226
1227 case LANE_COUNT_SET_1:
1228 if (!(lane_status[0] & DPCD_STATUS_LANE_0_CR_DONE_MASK))
1229 goto out_fail;
1230 default:
1231
1232 break;
1233 }
1234
1235 return 0;
1236
1237out_fail:
1238 return -EIO;
1239}
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255static int check_channel_equalization(struct udevice *dev, u8 lane_count)
1256{
1257 struct dp_tx *dp_tx = dev_get_priv(dev);
1258 u8 *lane_status = dp_tx->lane_status_ajd_reqs;
1259
1260
1261 switch (lane_count) {
1262 case LANE_COUNT_SET_4:
1263 if (!(lane_status[1] & DPCD_STATUS_LANE_3_CE_DONE_MASK))
1264 goto out_fail;
1265 if (!(lane_status[1] & DPCD_STATUS_LANE_2_CE_DONE_MASK))
1266 goto out_fail;
1267
1268 case LANE_COUNT_SET_2:
1269 if (!(lane_status[0] & DPCD_STATUS_LANE_1_CE_DONE_MASK))
1270 goto out_fail;
1271
1272 case LANE_COUNT_SET_1:
1273 if (!(lane_status[0] & DPCD_STATUS_LANE_0_CE_DONE_MASK))
1274 goto out_fail;
1275 default:
1276
1277 break;
1278 }
1279
1280
1281 switch (lane_count) {
1282 case LANE_COUNT_SET_4:
1283 if (!(lane_status[1] & DPCD_STATUS_LANE_3_SL_DONE_MASK))
1284 goto out_fail;
1285 if (!(lane_status[1] & DPCD_STATUS_LANE_2_SL_DONE_MASK))
1286 goto out_fail;
1287
1288 case LANE_COUNT_SET_2:
1289 if (!(lane_status[0] & DPCD_STATUS_LANE_1_SL_DONE_MASK))
1290 goto out_fail;
1291
1292 case LANE_COUNT_SET_1:
1293 if (!(lane_status[0] & DPCD_STATUS_LANE_0_SL_DONE_MASK))
1294 goto out_fail;
1295 default:
1296
1297 break;
1298 }
1299
1300
1301 if (!(lane_status[2] & DPCD_LANE_ALIGN_STATUS_UPDATED_IA_DONE_MASK))
1302 goto out_fail;
1303
1304 return 0;
1305
1306out_fail:
1307 return -EIO;
1308}
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320static int set_training_pattern(struct udevice *dev, u32 pattern)
1321{
1322 struct dp_tx *dp_tx = dev_get_priv(dev);
1323 int status;
1324 u8 aux_data[5];
1325
1326
1327 set_reg(dev, REG_TRAINING_PATTERN_SET, pattern);
1328
1329 aux_data[0] = pattern;
1330
1331
1332 switch (pattern) {
1333 case TRAINING_PATTERN_SET_OFF:
1334 set_reg(dev, REG_SCRAMBLING_DISABLE, 0);
1335 dp_tx->link_config.scrambler_en = 1;
1336 break;
1337 case TRAINING_PATTERN_SET_TP1:
1338 case TRAINING_PATTERN_SET_TP2:
1339 case TRAINING_PATTERN_SET_TP3:
1340 aux_data[0] |= DPCD_TP_SET_SCRAMB_DIS_MASK;
1341 set_reg(dev, REG_SCRAMBLING_DISABLE, 1);
1342 dp_tx->link_config.scrambler_en = 0;
1343 break;
1344 default:
1345 break;
1346 }
1347
1348
1349
1350
1351
1352 set_vswing_preemp(dev, &aux_data[1]);
1353
1354
1355
1356
1357 if (pattern == TRAINING_PATTERN_SET_OFF)
1358 status = aux_write(dev, DPCD_TP_SET, 1, aux_data);
1359 else
1360 status = aux_write(dev, DPCD_TP_SET, 5, aux_data);
1361 if (status)
1362 return -EIO;
1363
1364 return 0;
1365}
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396static unsigned int training_state_clock_recovery(struct udevice *dev)
1397{
1398 struct dp_tx *dp_tx = dev_get_priv(dev);
1399 int status;
1400 u32 delay_us;
1401 u8 prev_vs_level = 0;
1402 u8 same_vs_level_count = 0;
1403
1404
1405
1406
1407
1408 delay_us = get_training_delay(dev, TS_CLOCK_RECOVERY);
1409
1410
1411
1412
1413
1414
1415 dp_tx->link_config.vs_level = 0;
1416 dp_tx->link_config.pe_level = 0;
1417 status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP1);
1418 if (status)
1419 return TS_FAILURE;
1420
1421 while (1) {
1422
1423 udelay(delay_us);
1424
1425
1426 status = get_lane_status_adj_reqs(dev);
1427 if (status)
1428 return TS_FAILURE;
1429
1430
1431
1432
1433
1434 status = check_clock_recovery(dev,
1435 dp_tx->link_config.lane_count);
1436 if (!status)
1437 return TS_CHANNEL_EQUALIZATION;
1438
1439
1440
1441
1442
1443 if (prev_vs_level == dp_tx->link_config.vs_level) {
1444 same_vs_level_count++;
1445 } else {
1446 same_vs_level_count = 0;
1447 prev_vs_level = dp_tx->link_config.vs_level;
1448 }
1449 if (same_vs_level_count >= 5)
1450 break;
1451
1452
1453 if (dp_tx->link_config.vs_level == MAXIMUM_VS_LEVEL)
1454 break;
1455
1456
1457 status = adj_vswing_preemp(dev);
1458 if (status)
1459
1460 return TS_FAILURE;
1461 }
1462
1463 return TS_ADJUST_LINK_RATE;
1464}
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496static int training_state_channel_equalization(struct udevice *dev)
1497{
1498 struct dp_tx *dp_tx = dev_get_priv(dev);
1499 int status;
1500 u32 delay_us;
1501 u32 iteration_count = 0;
1502
1503
1504
1505
1506
1507 delay_us = get_training_delay(dev, TS_CHANNEL_EQUALIZATION);
1508
1509
1510
1511
1512
1513 if (dp_tx->dpcd_rx_caps[DPCD_MAX_LANE_COUNT] & DPCD_TPS3_SUPPORT_MASK)
1514 status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP3);
1515 else
1516 status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP2);
1517
1518 if (status)
1519 return TS_FAILURE;
1520
1521 while (iteration_count < 5) {
1522
1523 udelay(delay_us);
1524
1525
1526 status = get_lane_status_adj_reqs(dev);
1527 if (status)
1528
1529 return TS_FAILURE;
1530
1531
1532 status = check_clock_recovery(dev,
1533 dp_tx->link_config.lane_count);
1534 if (status)
1535 break;
1536
1537
1538
1539
1540
1541 status =
1542 check_channel_equalization(dev,
1543 dp_tx->link_config.lane_count);
1544 if (!status)
1545 return TS_SUCCESS;
1546
1547
1548 status = adj_vswing_preemp(dev);
1549 if (status)
1550
1551 return TS_FAILURE;
1552
1553 iteration_count++;
1554 }
1555
1556
1557
1558
1559
1560 return TS_ADJUST_LINK_RATE;
1561}
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575static int training_state_adjust_link_rate(struct udevice *dev)
1576{
1577 struct dp_tx *dp_tx = dev_get_priv(dev);
1578 int status;
1579
1580 switch (dp_tx->link_config.link_rate) {
1581 case LINK_BW_SET_540GBPS:
1582 status = set_link_rate(dev, LINK_BW_SET_270GBPS);
1583 if (status) {
1584 status = TS_FAILURE;
1585 break;
1586 }
1587 status = TS_CLOCK_RECOVERY;
1588 break;
1589 case LINK_BW_SET_270GBPS:
1590 status = set_link_rate(dev, LINK_BW_SET_162GBPS);
1591 if (status) {
1592 status = TS_FAILURE;
1593 break;
1594 }
1595 status = TS_CLOCK_RECOVERY;
1596 break;
1597 default:
1598
1599
1600
1601
1602 status = TS_ADJUST_LANE_COUNT;
1603 break;
1604 }
1605
1606 return status;
1607}
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621static int trainig_state_adjust_lane_count(struct udevice *dev)
1622{
1623 struct dp_tx *dp_tx = dev_get_priv(dev);
1624 int status;
1625
1626 switch (dp_tx->link_config.lane_count) {
1627 case LANE_COUNT_SET_4:
1628 status = set_lane_count(dev, LANE_COUNT_SET_2);
1629 if (status) {
1630 status = TS_FAILURE;
1631 break;
1632 }
1633
1634 status = set_link_rate(dev, dp_tx->link_config.max_link_rate);
1635 if (status) {
1636 status = TS_FAILURE;
1637 break;
1638 }
1639 status = TS_CLOCK_RECOVERY;
1640 break;
1641 case LANE_COUNT_SET_2:
1642 status = set_lane_count(dev, LANE_COUNT_SET_1);
1643 if (status) {
1644 status = TS_FAILURE;
1645 break;
1646 }
1647
1648 status = set_link_rate(dev, dp_tx->link_config.max_link_rate);
1649 if (status) {
1650 status = TS_FAILURE;
1651 break;
1652 }
1653 status = TS_CLOCK_RECOVERY;
1654 break;
1655 default:
1656
1657
1658
1659
1660 status = TS_FAILURE;
1661 break;
1662 }
1663
1664 return status;
1665}
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678static int check_link_status(struct udevice *dev, u8 lane_count)
1679{
1680 u8 retry_count = 0;
1681
1682 if (!is_connected(dev))
1683 return -ENODEV;
1684
1685
1686 do {
1687 int status;
1688
1689
1690 status = get_lane_status_adj_reqs(dev);
1691 if (status)
1692 return -EIO;
1693
1694
1695 if ((check_clock_recovery(dev, lane_count) == 0) &&
1696 (check_channel_equalization(dev, lane_count) == 0))
1697 return 0;
1698
1699 retry_count++;
1700 } while (retry_count < 5);
1701
1702 return -EIO;
1703}
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727static int run_training(struct udevice *dev)
1728{
1729 struct dp_tx *dp_tx = dev_get_priv(dev);
1730 int status;
1731 int training_state = TS_CLOCK_RECOVERY;
1732
1733 while (1) {
1734 switch (training_state) {
1735 case TS_CLOCK_RECOVERY:
1736 training_state =
1737 training_state_clock_recovery(dev);
1738 break;
1739 case TS_CHANNEL_EQUALIZATION:
1740 training_state =
1741 training_state_channel_equalization(dev);
1742 break;
1743 case TS_ADJUST_LINK_RATE:
1744 training_state =
1745 training_state_adjust_link_rate(dev);
1746 break;
1747 case TS_ADJUST_LANE_COUNT:
1748 training_state =
1749 trainig_state_adjust_lane_count(dev);
1750 break;
1751 default:
1752 break;
1753 }
1754
1755 if (training_state == TS_SUCCESS)
1756 break;
1757 else if (training_state == TS_FAILURE)
1758 return -EIO;
1759
1760 if (training_state == TS_ADJUST_LINK_RATE ||
1761 training_state == TS_ADJUST_LANE_COUNT) {
1762 if (!dp_tx->train_adaptive)
1763 return -EIO;
1764
1765 status = set_training_pattern(dev,
1766 TRAINING_PATTERN_SET_OFF);
1767 if (status)
1768 return -EIO;
1769 }
1770 }
1771
1772
1773 status = check_link_status(dev, dp_tx->link_config.lane_count);
1774 if (status)
1775 return -EIO;
1776
1777 return 0;
1778}
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791static int cfg_main_link_max(struct udevice *dev)
1792{
1793 struct dp_tx *dp_tx = dev_get_priv(dev);
1794 int status;
1795
1796 if (!is_connected(dev))
1797 return -ENODEV;
1798
1799
1800
1801
1802
1803 status = set_link_rate(dev, dp_tx->link_config.max_link_rate);
1804 if (status)
1805 return status;
1806
1807
1808
1809
1810
1811 status = set_lane_count(dev, dp_tx->link_config.max_lane_count);
1812 if (status)
1813 return status;
1814
1815 return 0;
1816}
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827static int establish_link(struct udevice *dev)
1828{
1829 struct dp_tx *dp_tx = dev_get_priv(dev);
1830 int status;
1831 int status2;
1832 u32 mask;
1833
1834 reset_dp_phy(dev, PHY_CONFIG_PHY_RESET_MASK);
1835
1836
1837 disable_main_link(dev);
1838
1839
1840 mask = phy_status_lanes_ready_mask(dp_tx->max_lane_count);
1841 status = wait_phy_ready(dev, mask);
1842 if (status)
1843 return -EIO;
1844
1845
1846 status = run_training(dev);
1847
1848
1849 status2 = set_training_pattern(dev, TRAINING_PATTERN_SET_OFF);
1850 if (status || status2)
1851 return -EIO;
1852
1853 return 0;
1854}
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887static void cfg_msa_recalculate(struct udevice *dev)
1888{
1889 struct dp_tx *dp_tx = dev_get_priv(dev);
1890 u32 video_bw;
1891 u32 link_bw;
1892 u32 words_per_line;
1893 u8 bits_per_pixel;
1894 struct main_stream_attributes *msa_config;
1895 struct link_config *link_config;
1896
1897 msa_config = &dp_tx->main_stream_attributes;
1898 link_config = &dp_tx->link_config;
1899
1900
1901
1902
1903
1904 if (msa_config->override_user_pixel_width == 0) {
1905 if (msa_config->pixel_clock_hz > 300000000 &&
1906 link_config->lane_count == LANE_COUNT_SET_4) {
1907 msa_config->user_pixel_width = 4;
1908 }
1909
1910
1911
1912 else if ((msa_config->pixel_clock_hz > 150000000) &&
1913 (link_config->lane_count != LANE_COUNT_SET_1)) {
1914 msa_config->user_pixel_width = 2;
1915 } else {
1916 msa_config->user_pixel_width = 1;
1917 }
1918 }
1919
1920
1921 msa_config->n_vid = 27 * 1000 * link_config->link_rate;
1922
1923
1924 if (msa_config->bits_per_color == 6)
1925 msa_config->misc_0 = MAIN_STREAMX_MISC0_BDC_6BPC;
1926 else if (msa_config->bits_per_color == 8)
1927 msa_config->misc_0 = MAIN_STREAMX_MISC0_BDC_8BPC;
1928 else if (msa_config->bits_per_color == 10)
1929 msa_config->misc_0 = MAIN_STREAMX_MISC0_BDC_10BPC;
1930 else if (msa_config->bits_per_color == 12)
1931 msa_config->misc_0 = MAIN_STREAMX_MISC0_BDC_12BPC;
1932 else if (msa_config->bits_per_color == 16)
1933 msa_config->misc_0 = MAIN_STREAMX_MISC0_BDC_16BPC;
1934
1935 msa_config->misc_0 = (msa_config->misc_0 <<
1936 MAIN_STREAMX_MISC0_BDC_SHIFT) |
1937 (msa_config->y_cb_cr_colorimetry <<
1938 MAIN_STREAMX_MISC0_YCBCR_COLORIMETRY_SHIFT) |
1939 (msa_config->dynamic_range <<
1940 MAIN_STREAMX_MISC0_DYNAMIC_RANGE_SHIFT) |
1941 (msa_config->component_format <<
1942 MAIN_STREAMX_MISC0_COMPONENT_FORMAT_SHIFT) |
1943 (msa_config->synchronous_clock_mode);
1944
1945 msa_config->misc_1 = 0;
1946
1947
1948
1949
1950
1951 if (msa_config->component_format ==
1952 MAIN_STREAMX_MISC0_COMPONENT_FORMAT_YCBCR422)
1953
1954 bits_per_pixel = msa_config->bits_per_color * 2;
1955 else
1956
1957 bits_per_pixel = msa_config->bits_per_color * 3;
1958
1959
1960 words_per_line = (msa_config->h_active * bits_per_pixel);
1961 if (words_per_line % 16)
1962 words_per_line += 16;
1963 words_per_line /= 16;
1964
1965 msa_config->data_per_lane = words_per_line - link_config->lane_count;
1966 if (words_per_line % link_config->lane_count)
1967 msa_config->data_per_lane += (words_per_line %
1968 link_config->lane_count);
1969
1970
1971
1972
1973
1974 msa_config->transfer_unit_size = 64;
1975
1976
1977
1978
1979
1980
1981 video_bw = ((msa_config->pixel_clock_hz / 1000) * bits_per_pixel) / 8;
1982 link_bw = (link_config->lane_count * link_config->link_rate * 27);
1983 msa_config->avg_bytes_per_tu = (video_bw *
1984 msa_config->transfer_unit_size) /
1985 link_bw;
1986
1987
1988
1989
1990
1991
1992 if ((msa_config->avg_bytes_per_tu / 1000) <= 4)
1993 msa_config->init_wait = 64;
1994 else
1995 msa_config->init_wait = msa_config->transfer_unit_size -
1996 (msa_config->avg_bytes_per_tu / 1000);
1997}
1998
1999
2000
2001
2002
2003
2004
2005
2006static void set_line_reset(struct udevice *dev)
2007{
2008 struct dp_tx *dp_tx = dev_get_priv(dev);
2009 u32 reg_val;
2010 u16 h_blank;
2011 u16 h_reduced_blank;
2012 struct main_stream_attributes *msa_config =
2013 &dp_tx->main_stream_attributes;
2014
2015 h_blank = msa_config->h_total - msa_config->h_active;
2016
2017 h_reduced_blank = 2 * msa_config->h_total;
2018 if (h_reduced_blank % 10)
2019 h_reduced_blank += 10;
2020 h_reduced_blank /= 10;
2021
2022
2023 reg_val = get_reg(dev, REG_LINE_RESET_DISABLE);
2024 if (h_blank < h_reduced_blank &&
2025 (h_blank == 80 || h_blank == 160)) {
2026 reg_val |= LINE_RESET_DISABLE_MASK;
2027 } else {
2028 reg_val &= ~LINE_RESET_DISABLE_MASK;
2029 }
2030 set_reg(dev, REG_LINE_RESET_DISABLE, reg_val);
2031}
2032
2033
2034
2035
2036
2037
2038
2039static void clear_msa_values(struct udevice *dev)
2040{
2041 set_reg(dev, REG_MAIN_STREAM_HTOTAL, 0);
2042 set_reg(dev, REG_MAIN_STREAM_VTOTAL, 0);
2043 set_reg(dev, REG_MAIN_STREAM_POLARITY, 0);
2044 set_reg(dev, REG_MAIN_STREAM_HSWIDTH, 0);
2045 set_reg(dev, REG_MAIN_STREAM_VSWIDTH, 0);
2046 set_reg(dev, REG_MAIN_STREAM_HRES, 0);
2047 set_reg(dev, REG_MAIN_STREAM_VRES, 0);
2048 set_reg(dev, REG_MAIN_STREAM_HSTART, 0);
2049 set_reg(dev, REG_MAIN_STREAM_VSTART, 0);
2050 set_reg(dev, REG_MAIN_STREAM_MISC0, 0);
2051 set_reg(dev, REG_MAIN_STREAM_MISC1, 0);
2052 set_reg(dev, REG_USER_PIXEL_WIDTH, 0);
2053 set_reg(dev, REG_USER_DATA_COUNT_PER_LANE, 0);
2054 set_reg(dev, REG_M_VID, 0);
2055 set_reg(dev, REG_N_VID, 0);
2056
2057 set_reg(dev, REG_STREAM1, 0);
2058 set_reg(dev, REG_TU_SIZE, 0);
2059 set_reg(dev, REG_MIN_BYTES_PER_TU, 0);
2060 set_reg(dev, REG_FRAC_BYTES_PER_TU, 0);
2061 set_reg(dev, REG_INIT_WAIT, 0);
2062}
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072static void set_msa_values(struct udevice *dev)
2073{
2074 struct dp_tx *dp_tx = dev_get_priv(dev);
2075 struct main_stream_attributes *msa_config =
2076 &dp_tx->main_stream_attributes;
2077
2078 printf(" set MSA %u x %u\n", msa_config->h_active,
2079 msa_config->v_active);
2080
2081 set_reg(dev, REG_MAIN_STREAM_HTOTAL, msa_config->h_total);
2082 set_reg(dev, REG_MAIN_STREAM_VTOTAL, msa_config->v_total);
2083 set_reg(dev, REG_MAIN_STREAM_POLARITY,
2084 msa_config->h_sync_polarity |
2085 (msa_config->v_sync_polarity <<
2086 MAIN_STREAMX_POLARITY_VSYNC_POL_SHIFT));
2087 set_reg(dev, REG_MAIN_STREAM_HSWIDTH, msa_config->h_sync_width);
2088 set_reg(dev, REG_MAIN_STREAM_VSWIDTH, msa_config->v_sync_width);
2089 set_reg(dev, REG_MAIN_STREAM_HRES, msa_config->h_active);
2090 set_reg(dev, REG_MAIN_STREAM_VRES, msa_config->v_active);
2091 set_reg(dev, REG_MAIN_STREAM_HSTART, msa_config->h_start);
2092 set_reg(dev, REG_MAIN_STREAM_VSTART, msa_config->v_start);
2093 set_reg(dev, REG_MAIN_STREAM_MISC0, msa_config->misc_0);
2094 set_reg(dev, REG_MAIN_STREAM_MISC1, msa_config->misc_1);
2095 set_reg(dev, REG_USER_PIXEL_WIDTH, msa_config->user_pixel_width);
2096
2097 set_reg(dev, REG_M_VID, msa_config->pixel_clock_hz / 1000);
2098 set_reg(dev, REG_N_VID, msa_config->n_vid);
2099 set_reg(dev, REG_USER_DATA_COUNT_PER_LANE, msa_config->data_per_lane);
2100
2101 set_line_reset(dev);
2102
2103 set_reg(dev, REG_TU_SIZE, msa_config->transfer_unit_size);
2104 set_reg(dev, REG_MIN_BYTES_PER_TU, msa_config->avg_bytes_per_tu / 1000);
2105 set_reg(dev, REG_FRAC_BYTES_PER_TU,
2106 (msa_config->avg_bytes_per_tu % 1000) * 1024 / 1000);
2107 set_reg(dev, REG_INIT_WAIT, msa_config->init_wait);
2108}
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119static void logicore_dp_tx_set_msa(struct udevice *dev,
2120 struct logicore_dp_tx_msa *msa)
2121{
2122 struct dp_tx *dp_tx = dev_get_priv(dev);
2123
2124 memset(&dp_tx->main_stream_attributes, 0,
2125 sizeof(struct main_stream_attributes));
2126
2127 dp_tx->main_stream_attributes.pixel_clock_hz = msa->pixel_clock_hz;
2128 dp_tx->main_stream_attributes.bits_per_color = msa->bits_per_color;
2129 dp_tx->main_stream_attributes.h_active = msa->h_active;
2130 dp_tx->main_stream_attributes.h_start = msa->h_start;
2131 dp_tx->main_stream_attributes.h_sync_polarity = msa->h_sync_polarity;
2132 dp_tx->main_stream_attributes.h_sync_width = msa->h_sync_width;
2133 dp_tx->main_stream_attributes.h_total = msa->h_total;
2134 dp_tx->main_stream_attributes.v_active = msa->v_active;
2135 dp_tx->main_stream_attributes.v_start = msa->v_start;
2136 dp_tx->main_stream_attributes.v_sync_polarity = msa->v_sync_polarity;
2137 dp_tx->main_stream_attributes.v_sync_width = msa->v_sync_width;
2138 dp_tx->main_stream_attributes.v_total = msa->v_total;
2139 dp_tx->main_stream_attributes.override_user_pixel_width =
2140 msa->override_user_pixel_width;
2141 dp_tx->main_stream_attributes.user_pixel_width = msa->user_pixel_width;
2142 dp_tx->main_stream_attributes.synchronous_clock_mode = 0;
2143}
2144
2145
2146
2147
2148
2149
2150
2151
2152static int logicore_dp_tx_video_enable(struct udevice *dev,
2153 struct logicore_dp_tx_msa *msa)
2154{
2155 struct dp_tx *dp_tx = dev_get_priv(dev);
2156 int res;
2157 u8 power = 0x01;
2158
2159 if (!is_connected(dev)) {
2160 printf(" no DP sink connected\n");
2161 return -EIO;
2162 }
2163
2164 initialize(dev);
2165
2166 disable_main_link(dev);
2167
2168 logicore_dp_tx_set_msa(dev, msa);
2169
2170 get_rx_capabilities(dev);
2171
2172 printf(" DP sink connected\n");
2173 aux_write(dev, DPCD_SET_POWER_DP_PWR_VOLTAGE, 1, &power);
2174 set_enhanced_frame_mode(dev, true);
2175 cfg_main_link_max(dev);
2176 res = establish_link(dev);
2177 printf(" establish_link: %s, vs: %d, pe: %d\n",
2178 res ? "failed" : "ok", dp_tx->link_config.vs_level,
2179 dp_tx->link_config.pe_level);
2180
2181 cfg_msa_recalculate(dev);
2182
2183 clear_msa_values(dev);
2184 set_msa_values(dev);
2185
2186 enable_main_link(dev);
2187
2188 return 0;
2189}
2190
2191
2192
2193
2194
2195static int logicore_dp_tx_enable(struct udevice *dev, int panel_bpp,
2196 const struct display_timing *timing)
2197{
2198 struct clk pixclock;
2199 struct logicore_dp_tx_msa *msa;
2200 struct logicore_dp_tx_msa mode_640_480_60 = {
2201 .pixel_clock_hz = 25175000,
2202 .bits_per_color = 8,
2203 .h_active = 640,
2204 .h_start = 144,
2205 .h_sync_polarity = false,
2206 .h_sync_width = 96,
2207 .h_total = 800,
2208 .v_active = 480,
2209 .v_start = 35,
2210 .v_sync_polarity = false,
2211 .v_sync_width = 2,
2212 .v_total = 525,
2213 .override_user_pixel_width = false,
2214 .user_pixel_width = 0,
2215 };
2216
2217 struct logicore_dp_tx_msa mode_720_400_70 = {
2218 .pixel_clock_hz = 28300000,
2219 .bits_per_color = 8,
2220 .h_active = 720,
2221 .h_start = 162,
2222 .h_sync_polarity = false,
2223 .h_sync_width = 108,
2224 .h_total = 900,
2225 .v_active = 400,
2226 .v_start = 37,
2227 .v_sync_polarity = true,
2228 .v_sync_width = 2,
2229 .v_total = 449,
2230 .override_user_pixel_width = false,
2231 .user_pixel_width = 0,
2232 };
2233
2234 struct logicore_dp_tx_msa mode_1024_768_60 = {
2235 .pixel_clock_hz = 65000000,
2236 .bits_per_color = 8,
2237 .h_active = 1024,
2238 .h_start = 296,
2239 .h_sync_polarity = false,
2240 .h_sync_width = 136,
2241 .h_total = 1344,
2242 .v_active = 768,
2243 .v_start = 35,
2244 .v_sync_polarity = false,
2245 .v_sync_width = 2,
2246 .v_total = 806,
2247 .override_user_pixel_width = false,
2248 .user_pixel_width = 0,
2249 };
2250
2251 if (timing->hactive.typ == 1024 && timing->vactive.typ == 768)
2252 msa = &mode_1024_768_60;
2253 else if (timing->hactive.typ == 720 && timing->vactive.typ == 400)
2254 msa = &mode_720_400_70;
2255 else
2256 msa = &mode_640_480_60;
2257
2258 if (clk_get_by_index(dev, 0, &pixclock)) {
2259 printf("%s: Could not get pixelclock\n", dev->name);
2260 return -1;
2261 }
2262 clk_set_rate(&pixclock, msa->pixel_clock_hz);
2263
2264 return logicore_dp_tx_video_enable(dev, msa);
2265}
2266
2267static int logicore_dp_tx_probe(struct udevice *dev)
2268{
2269 struct dp_tx *dp_tx = dev_get_priv(dev);
2270
2271 dp_tx->s_axi_clk = S_AXI_CLK_DEFAULT;
2272 dp_tx->train_adaptive = false;
2273 dp_tx->max_link_rate = DPCD_MAX_LINK_RATE_540GBPS;
2274 dp_tx->max_lane_count = DPCD_MAX_LANE_COUNT_4;
2275
2276 dp_tx->base = dev_read_u32_default(dev, "reg", -1);
2277
2278 return 0;
2279}
2280
2281static const struct dm_display_ops logicore_dp_tx_ops = {
2282 .enable = logicore_dp_tx_enable,
2283};
2284
2285static const struct udevice_id logicore_dp_tx_ids[] = {
2286 { .compatible = "gdsys,logicore_dp_tx" },
2287 { }
2288};
2289
2290U_BOOT_DRIVER(logicore_dp_tx) = {
2291 .name = "logicore_dp_tx",
2292 .id = UCLASS_DISPLAY,
2293 .of_match = logicore_dp_tx_ids,
2294 .probe = logicore_dp_tx_probe,
2295 .priv_auto_alloc_size = sizeof(struct dp_tx),
2296 .ops = &logicore_dp_tx_ops,
2297};
2298