1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
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
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
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
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
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
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 - 2022, Xilinx Inc.
* Copyright (C) 2022 - 2023, Advanced Micro Devices, Inc.
*
* Xilinx displayport(DP) Tx Subsytem driver
*/
#include <common.h>
#include <clk.h>
#include <cpu_func.h>
#include <dm.h>
#include <errno.h>
#include <generic-phy.h>
#include <stdlib.h>
#include <video.h>
#include <wait_bit.h>
#include <dm/device_compat.h>
#include <asm/io.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <dm/device_compat.h>
#include <asm/global_data.h>
#include "zynqmp_dpsub.h"
DECLARE_GLOBAL_DATA_PTR;
/* Maximum supported resolution */
#define WIDTH 1024
#define HEIGHT 768
static struct dp_dma dp_dma;
static struct dp_dma_descriptor cur_desc __aligned(256);
static void dma_init_video_descriptor(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct dp_dma_frame_buffer *frame_buffer = &dp_sub->frame_buffer;
cur_desc.control = DPDMA_DESC_PREAMBLE | DPDMA_DESC_IGNR_DONE |
DPDMA_DESC_LAST_FRAME;
cur_desc.dscr_id = 0;
cur_desc.xfer_size = frame_buffer->size;
cur_desc.line_size_stride = ((frame_buffer->stride >> 4) <<
DPDMA_DESCRIPTOR_LINE_SIZE_STRIDE_SHIFT) |
(frame_buffer->line_size);
cur_desc.addr_ext = (((u32)(frame_buffer->address >>
DPDMA_DESCRIPTOR_SRC_ADDR_WIDTH) <<
DPDMA_DESCRIPTOR_ADDR_EXT_SRC_ADDR_EXT_SHIFT) |
(upper_32_bits((u64)&cur_desc)));
cur_desc.next_desr = lower_32_bits((u64)&cur_desc);
cur_desc.src_addr = lower_32_bits((u64)gd->fb_base);
}
static void dma_set_descriptor_address(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
flush_dcache_range((u64)&cur_desc,
ALIGN(((u64)&cur_desc + sizeof(cur_desc)),
CONFIG_SYS_CACHELINE_SIZE));
writel(upper_32_bits((u64)&cur_desc), dp_sub->dp_dma->base_addr +
DPDMA_CH3_DSCR_STRT_ADDRE);
writel(lower_32_bits((u64)&cur_desc), dp_sub->dp_dma->base_addr +
DPDMA_CH3_DSCR_STRT_ADDR);
}
static void dma_setup_channel(struct udevice *dev)
{
dma_init_video_descriptor(dev);
dma_set_descriptor_address(dev);
}
static void dma_set_channel_state(struct udevice *dev)
{
u32 mask = 0, regval = 0;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
mask = DPDMA_CH_CNTL_EN_MASK | DPDMA_CH_CNTL_PAUSE_MASK;
regval = DPDMA_CH_CNTL_EN_MASK;
clrsetbits_le32(dp_sub->dp_dma->base_addr + DPDMA_CH3_CNTL,
mask, regval);
}
static void dma_trigger(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 trigger;
trigger = DPDMA_GBL_TRG_CH3_MASK;
dp_sub->dp_dma->gfx.trigger_status = DPDMA_TRIGGER_DONE;
writel(trigger, dp_sub->dp_dma->base_addr + DPDMA_GBL);
}
static void dma_vsync_intr_handler(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
dma_setup_channel(dev);
dma_set_channel_state(dev);
dma_trigger(dev);
/* Clear VSync Interrupt */
writel(DPDMA_ISR_VSYNC_INT_MASK, dp_sub->dp_dma->base_addr + DPDMA_ISR);
}
/**
* wait_phy_ready() - Wait for the DisplayPort PHY to come out of reset
* @dev: The DP device
*
* Return: 0 if wait succeeded, -ve if error occurred
*/
static int wait_phy_ready(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 timeout = 100, phy_status;
u8 phy_ready_mask = DP_PHY_STATUS_RESET_LANE_0_DONE_MASK |
DP_PHY_STATUS_GT_PLL_LOCK_MASK;
/* Wait until the PHY is ready. */
do {
udelay(20);
phy_status = readl(dp_sub->base_addr + DP_PHY_STATUS);
phy_status &= phy_ready_mask;
/* Protect against an infinite loop. */
if (!timeout--)
return -ETIMEDOUT;
} while (phy_status != phy_ready_mask);
return 0;
}
static int init_dp_tx(struct udevice *dev)
{
u32 status, phyval, regval, rate;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
phyval = readl(dp_sub->base_addr + DP_PHY_CONFIG);
writel(DP_SOFT_RESET_EN, dp_sub->base_addr + DP_SOFT_RESET);
status = readl(dp_sub->base_addr + DP_SOFT_RESET);
writel(DP_DISABLE, dp_sub->base_addr + DP_ENABLE);
regval = (readl(dp_sub->base_addr + DP_AUX_CLK_DIVIDER) &
~DP_AUX_CLK_DIVIDER_VAL_MASK) |
(60 << 8) |
(dp_sub->clock / 1000000);
writel(regval, dp_sub->base_addr + DP_AUX_CLK_DIVIDER);
writel(DP_PHY_CLOCK_SELECT_540GBPS, dp_sub->base_addr + DP_PHY_CLOCK_SELECT);
regval = phyval & ~DP_PHY_CONFIG_GT_ALL_RESET_MASK;
writel(regval, dp_sub->base_addr + DP_PHY_CONFIG);
status = wait_phy_ready(dev);
if (status)
return -EINVAL;
writel(DP_ENABLE, dp_sub->base_addr + DP_ENABLE);
rate = ~DP_INTR_HPD_PULSE_DETECTED_MASK & ~DP_INTR_HPD_EVENT_MASK
& ~DP_INTR_HPD_IRQ_MASK;
writel(rate, dp_sub->base_addr + DP_INTR_MASK);
return 0;
}
static int set_nonlive_gfx_format(struct udevice *dev, enum av_buf_video_format format)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct av_buf_vid_attribute *ptr = (struct av_buf_vid_attribute *)avbuf_supported_formats;
while (1) {
dev_dbg(dev, "Format %d\n", ptr->video_format);
if (!ptr->video_format)
return -EINVAL;
if (ptr->video_format == format) {
dp_sub->non_live_graphics = ptr;
break;
}
ptr++;
}
dev_dbg(dev, "Video format found. BPP %d\n", dp_sub->non_live_graphics->bpp);
return 0;
}
/* DP dma setup */
static void set_qos(struct udevice *dev, u8 qos)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 index;
u32 regval = 0, mask;
regval = (((u32)qos << DPDMA_CH_CNTL_QOS_DATA_RD_SHIFT) |
((u32)qos << DPDMA_CH_CNTL_QOS_DSCR_RD_SHIFT) |
((u32)qos << DPDMA_CH_CNTL_QOS_DSCR_WR_SHIFT));
mask = DPDMA_CH_CNTL_QOS_DATA_RD_MASK |
DPDMA_CH_CNTL_QOS_DSCR_RD_MASK |
DPDMA_CH_CNTL_QOS_DSCR_WR_MASK;
for (index = 0; index <= DPDMA_AUDIO_CHANNEL1; index++) {
clrsetbits_le32(dp_sub->dp_dma->base_addr +
DPDMA_CH0_CNTL +
(DPDMA_CH_OFFSET * (u32)index),
mask, regval);
}
}
static void enable_gfx_buffers(struct udevice *dev, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 regval = 0;
regval = (0xF << AVBUF_CHBUF3_BURST_LEN_SHIFT) |
AVBUF_CHBUF3_FLUSH_MASK;
writel(regval, dp_sub->base_addr + AVBUF_CHBUF3);
if (enable) {
regval = (0xF << AVBUF_CHBUF3_BURST_LEN_SHIFT) |
AVBUF_CHBUF0_EN_MASK;
writel(regval, dp_sub->base_addr + AVBUF_CHBUF3);
}
}
static void avbuf_video_select(struct udevice *dev, enum av_buf_video_stream vid_stream,
enum av_buf_gfx_stream gfx_stream)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
dp_sub->av_mode.video_src = vid_stream;
dp_sub->av_mode.gfx_src = gfx_stream;
clrsetbits_le32(dp_sub->base_addr +
AVBUF_BUF_OUTPUT_AUD_VID_SELECT,
AVBUF_BUF_OUTPUT_AUD_VID_SELECT_VID_STREAM2_SEL_MASK |
AVBUF_BUF_OUTPUT_AUD_VID_SELECT_VID_STREAM1_SEL_MASK,
vid_stream | gfx_stream);
}
static void config_gfx_pipeline(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u16 *csc_matrix, *offset_matrix;
u32 regval = 0, index = 0, *scaling_factors = NULL;
u16 rgb_coeffs[] = { 0x1000, 0x0000, 0x0000,
0x0000, 0x1000, 0x0000,
0x0000, 0x0000, 0x1000 };
u16 rgb_offset[] = { 0x0000, 0x0000, 0x0000 };
struct av_buf_vid_attribute *video = dp_sub->non_live_graphics;
scaling_factors = video->sf;
clrsetbits_le32(dp_sub->base_addr + AVBUF_BUF_FORMAT,
AVBUF_BUF_FORMAT_NL_GRAPHX_FORMAT_MASK,
(video->value) << AVBUF_BUF_FORMAT_NL_GRAPHX_FORMAT_SHIFT);
for (index = 0; index < 3; index++) {
writel(scaling_factors[index], dp_sub->base_addr +
AVBUF_BUF_GRAPHICS_COMP0_SCALE_FACTOR + (index * 4));
}
regval = (video->is_rgb << AVBUF_V_BLEND_LAYER0_CONTROL_RGB_MODE_SHIFT) |
video->sampling_en;
writel(regval, dp_sub->base_addr + AVBUF_V_BLEND_LAYER1_CONTROL);
if (video->is_rgb) {
csc_matrix = rgb_coeffs;
offset_matrix = rgb_offset;
}
/* Program Colorspace conversion coefficients */
for (index = 9; index < 12; index++) {
writel(offset_matrix[index - 9], dp_sub->base_addr +
AVBUF_V_BLEND_IN2CSC_COEFF0 + (index * 4));
}
/* Program Colorspace conversion matrix */
for (index = 0; index < 9; index++) {
writel(csc_matrix[index], dp_sub->base_addr +
AVBUF_V_BLEND_IN2CSC_COEFF0 + (index * 4));
}
}
static void set_blender_alpha(struct udevice *dev, u8 alpha, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 regval;
regval = enable;
regval |= alpha << AVBUF_V_BLEND_SET_GLOBAL_ALPHA_REG_VALUE_SHIFT;
writel(regval, dp_sub->base_addr +
AVBUF_V_BLEND_SET_GLOBAL_ALPHA_REG);
}
static void config_output_video(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 regval = 0, index;
u16 rgb_coeffs[] = { 0x1000, 0x0000, 0x0000,
0x0000, 0x1000, 0x0000,
0x0000, 0x0000, 0x1000 };
u16 rgb_offset[] = { 0x0000, 0x0000, 0x0000 };
u16 *matrix_coeff = rgb_coeffs, *matrix_offset = rgb_offset;
struct av_buf_vid_attribute *output_video = dp_sub->non_live_graphics;
regval |= output_video->sampling_en <<
AVBUF_V_BLEND_OUTPUT_VID_FORMAT_EN_DOWNSAMPLE_SHIFT;
regval |= output_video->value;
writel(regval, dp_sub->base_addr + AVBUF_V_BLEND_OUTPUT_VID_FORMAT);
for (index = 0; index < 9; index++) {
writel(matrix_coeff[index], dp_sub->base_addr +
AVBUF_V_BLEND_RGB2YCBCR_COEFF0 + (index * 4));
}
for (index = 0; index < 3; index++) {
writel((matrix_offset[index] <<
AVBUF_V_BLEND_LUMA_IN1CSC_OFFSET_POST_OFFSET_SHIFT),
dp_sub->base_addr +
AVBUF_V_BLEND_LUMA_OUTCSC_OFFSET
+ (index * 4));
}
set_blender_alpha(dev, 0, 0);
}
static void config_msa_sync_clk_mode(struct udevice *dev, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct main_stream_attributes *msa_config;
msa_config = &dp_sub->msa_config;
msa_config->synchronous_clock_mode = enable;
if (enable == 1) {
msa_config->misc0 |= (1 <<
DP_MAIN_STREAM_MISC0_COMPONENT_FORMAT_SHIFT);
} else {
msa_config->misc0 &= ~(1 <<
DP_MAIN_STREAM_MISC0_COMPONENT_FORMAT_SHIFT);
}
}
static void av_buf_soft_reset(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
writel(AVBUF_BUF_SRST_REG_VID_RST_MASK,
dp_sub->base_addr + AVBUF_BUF_SRST_REG);
writel(0, dp_sub->base_addr + AVBUF_BUF_SRST_REG);
}
static void set_video_clk_source(struct udevice *dev, u8 video_clk, u8 audio_clk)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 regval = 0;
if (dp_sub->av_mode.video_src != AVBUF_VIDSTREAM1_LIVE &&
dp_sub->av_mode.gfx_src != AVBUF_VIDSTREAM2_LIVE_GFX) {
regval = 1 << AVBUF_BUF_AUD_VID_CLK_SOURCE_VID_TIMING_SRC_SHIFT;
} else if (dp_sub->av_mode.video_src == AVBUF_VIDSTREAM1_LIVE ||
dp_sub->av_mode.gfx_src == AVBUF_VIDSTREAM2_LIVE_GFX) {
video_clk = AVBUF_PL_CLK;
}
regval |= (video_clk << AVBUF_BUF_AUD_VID_CLK_SOURCE_VID_CLK_SRC_SHIFT) |
(audio_clk << AVBUF_BUF_AUD_VID_CLK_SOURCE_AUD_CLK_SRC_SHIFT);
writel(regval, dp_sub->base_addr + AVBUF_BUF_AUD_VID_CLK_SOURCE);
av_buf_soft_reset(dev);
}
static int init_dpdma_subsys(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
dp_sub->dp_dma->base_addr = DPDMA_BASE_ADDRESS;
dp_sub->dp_dma->gfx.channel.cur = NULL;
dp_sub->dp_dma->gfx.trigger_status = DPDMA_TRIGGER_DONE;
set_qos(dev, 11);
return 0;
}
/**
* is_dp_connected() - Check if there is a connected RX device
* @dev: The DP device
*
*
* Return: true if a connected RX device was detected, false otherwise
*/
static bool is_dp_connected(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
u8 retries = 0;
do {
status = readl(dp_sub->base_addr +
DP_INTERRUPT_SIG_STATE)
& DP_INTERRUPT_SIG_STATE_HPD_STATE_MASK;
if (retries > DP_IS_CONNECTED_MAX_TIMEOUT_COUNT)
return 0;
retries++;
udelay(1000);
} while (status == 0);
return 1;
}
/**
* aux_wait_ready() - Wait until another request is no longer in progress
* @dev: The DP device
*
* Return: 0 if wait succeeded, -ve if error occurred
*/
static int aux_wait_ready(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status, timeout = 100;
do {
status = readl(dp_sub->base_addr +
DP_INTERRUPT_SIG_STATE);
if (!timeout--)
return -ETIMEDOUT;
udelay(20);
} while (status & DP_REPLY_STATUS_REPLY_IN_PROGRESS_MASK);
return 0;
}
/**
* aux_wait_reply() - Wait for reply on AUX channel
* @dev: The DP device
*
* Wait for a reply indicating that the most recent AUX request
* has been received by the RX device.
*
* Return: 0 if wait succeeded, -ve if error occurred
*/
static int aux_wait_reply(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 timeout = DP_AUX_MAX_WAIT, status;
while (timeout > 0) {
status = readl(dp_sub->base_addr + DP_REPLY_STATUS);
if (status & DP_REPLY_STATUS_REPLY_ERROR_MASK)
return -ETIMEDOUT;
if ((status & DP_REPLY_STATUS_REPLY_RECEIVED_MASK) &&
!(status & DP_REPLY_STATUS_REQUEST_IN_PROGRESS_MASK) &&
!(status & DP_REPLY_STATUS_REPLY_IN_PROGRESS_MASK)) {
return 0;
}
timeout--;
udelay(20);
}
return -ETIMEDOUT;
}
/**
* aux_request_send() - Send request on the AUX channel
* @dev: The DP device
* @request: The request to send
*
* Submit the supplied AUX request to the RX device over the AUX
* channel by writing the command, the destination address, (the write buffer
* for write commands), and the data size to the DisplayPort TX core.
*
* This is the lower-level sending routine, which is called by aux_request().
*
* Return: 0 if request was sent successfully, -ve on error
*/
static int aux_request_send(struct udevice *dev, struct aux_transaction *request)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 timeout_count = 0, status;
u8 index;
do {
status = readl(dp_sub->base_addr +
DP_REPLY_STATUS);
udelay(20);
timeout_count++;
if (timeout_count >= DP_AUX_MAX_TIMEOUT_COUNT)
return -ETIMEDOUT;
} while ((status & DP_REPLY_STATUS_REQUEST_IN_PROGRESS_MASK) ||
(status & DP_REPLY_STATUS_REPLY_IN_PROGRESS_MASK));
/* Set the address for the request. */
writel(request->address, dp_sub->base_addr + DP_AUX_ADDRESS);
if (request->cmd_code == DP_AUX_CMD_WRITE ||
request->cmd_code == DP_AUX_CMD_I2C_WRITE ||
request->cmd_code == DP_AUX_CMD_I2C_WRITE_MOT) {
/* Feed write data into the DisplayPort TX core's write FIFO. */
for (index = 0; index < request->num_bytes; index++) {
writel(request->data[index],
dp_sub->base_addr +
DP_AUX_WRITE_FIFO);
}
}
status = ((request->cmd_code << DP_AUX_CMD_SHIFT) |
((request->num_bytes - 1) &
DP_AUX_CMD_NBYTES_TRANSFER_MASK));
/* Submit the command and the data size. */
writel(((request->cmd_code << DP_AUX_CMD_SHIFT) |
((request->num_bytes - 1) & DP_AUX_CMD_NBYTES_TRANSFER_MASK)),
dp_sub->base_addr + DP_AUX_CMD);
/* Check for a reply from the RX device to the submitted request. */
status = aux_wait_reply(dev);
if (status)
/* Waiting for a reply timed out. */
return -ETIMEDOUT;
/* Analyze the reply. */
status = readl(dp_sub->base_addr + DP_AUX_REPLY_CODE);
if (status == DP_AUX_REPLY_CODE_DEFER ||
status == DP_AUX_REPLY_CODE_I2C_DEFER) {
/* The request was deferred. */
return -EAGAIN;
} else if (status == DP_AUX_REPLY_CODE_NACK ||
status == DP_AUX_REPLY_CODE_I2C_NACK) {
/* The request was not acknowledged. */
return -EIO;
}
/* The request was acknowledged. */
if (request->cmd_code == DP_AUX_CMD_READ ||
request->cmd_code == DP_AUX_CMD_I2C_READ ||
request->cmd_code == DP_AUX_CMD_I2C_READ_MOT) {
/* Wait until all data has been received. */
timeout_count = 0;
do {
status = readl(dp_sub->base_addr +
DP_REPLY_DATA_COUNT);
udelay(100);
timeout_count++;
if (timeout_count >= DP_AUX_MAX_TIMEOUT_COUNT)
return -ETIMEDOUT;
} while (status != request->num_bytes);
/* Obtain the read data from the reply FIFO. */
for (index = 0; index < request->num_bytes; index++) {
request->data[index] = readl(dp_sub->base_addr +
DP_AUX_REPLY_DATA);
}
}
return 0;
}
/**
* aux_request() - Submit request on the AUX channel
* @dev: The DP device
* @request: The request to submit
*
* Submit the supplied AUX request to the RX device over the AUX
* channel. If waiting for a reply times out, or if the DisplayPort TX core
* indicates that the request was deferred, the request is sent again (up to a
* maximum specified by DP_AUX_MAX_DEFER_COUNT|DP_AUX_MAX_TIMEOUT_COUNT).
*
* Return: 0 if request was submitted successfully, -ve on error
*/
static int aux_request(struct udevice *dev, struct aux_transaction *request)
{
u32 status, defer_count = 0, timeout_count = 0;
do {
status = aux_wait_ready(dev);
if (status) {
/* The RX device isn't ready yet. */
timeout_count++;
continue;
}
/* Send the request. */
status = aux_request_send(dev, request);
if (status == -EAGAIN) {
/* The request was deferred. */
defer_count++;
} else if (status == -ETIMEDOUT) {
/* Waiting for a reply timed out. */
timeout_count++;
} else {
return status;
}
udelay(100);
} while ((defer_count < DP_AUX_MAX_DEFER_COUNT) &&
(timeout_count < DP_AUX_MAX_TIMEOUT_COUNT));
/* The request was not successfully received by the RX device. */
return -ETIMEDOUT;
}
/**
* aux_common() - Common (read/write) AUX communication transmission
* @dev: The DP device
* @cmd_type: Command code of the transaction
* @address: The DPCD address of the transaction
* @num_bytes: Number of bytes in the payload data
* @data: The payload data of the AUX command
*
* Common sequence of submitting an AUX command for AUX read, AUX write,
* I2C-over-AUX read, and I2C-over-AUX write transactions. If required, the
* reads and writes are split into multiple requests, each acting on a maximum
* of 16 bytes.
*
* Return: 0 if OK, -ve on error
*/
static int aux_common(struct udevice *dev, u32 cmd_type, u32 address,
u32 num_bytes, u8 *data)
{
u32 status, bytes_left;
struct aux_transaction request;
if (!is_dp_connected(dev))
return -ENODEV;
/*
* Set the start address for AUX transactions. For I2C transactions,
* this is the address of the I2C bus.
*/
request.address = address;
bytes_left = num_bytes;
while (bytes_left > 0) {
request.cmd_code = cmd_type;
if (cmd_type == DP_AUX_CMD_READ ||
cmd_type == DP_AUX_CMD_WRITE) {
/* Increment address for normal AUX transactions. */
request.address = address + (num_bytes - bytes_left);
}
/* Increment the pointer to the supplied data buffer. */
request.data = &data[num_bytes - bytes_left];
if (bytes_left > 16)
request.num_bytes = 16;
else
request.num_bytes = bytes_left;
bytes_left -= request.num_bytes;
if (cmd_type == DP_AUX_CMD_I2C_READ && bytes_left > 0) {
/*
* Middle of a transaction I2C read request. Override
* the command code that was set to CmdType.
*/
request.cmd_code = DP_AUX_CMD_I2C_READ_MOT;
} else if (cmd_type == DP_AUX_CMD_I2C_WRITE && bytes_left > 0) {
/*
* Middle of a transaction I2C write request. Override
* the command code that was set to CmdType.
*/
request.cmd_code = DP_AUX_CMD_I2C_WRITE_MOT;
}
status = aux_request(dev, &request);
if (status)
return status;
}
return 0;
}
/**
* aux_write() - Issue AUX write request
* @dev: The DP device
* @dpcd_address: The DPCD address to write to
* @bytes_to_write: Number of bytes to write
* @write_data: Buffer containig data to be written
*
* Issue a write request over the AUX channel that will write to
* the RX device's DisplayPort Configuration data (DPCD) address space. The
* write message will be divided into multiple transactions which write a
* maximum of 16 bytes each.
*
* Return: 0 if write operation was successful, -ve on error
*/
static int aux_write(struct udevice *dev, u32 dpcd_address, u32 bytes_to_write,
void *write_data)
{
return aux_common(dev, DP_AUX_CMD_WRITE, dpcd_address,
bytes_to_write, (u8 *)write_data);
}
/**
* aux_read() - Issue AUX read request
* @dev: The DP device
* @dpcd_address: The DPCD address to read from
* @bytes_to_read: Number of bytes to read
* @read_data: Buffer to receive the read data
*
* Issue a read request over the AUX channel that will read from the RX
* device's DisplayPort Configuration data (DPCD) address space. The read
* message will be divided into multiple transactions which read a maximum of
* 16 bytes each.
*
* Return: 0 if read operation was successful, -ve on error
*/
static int aux_read(struct udevice *dev, u32 dpcd_address, u32 bytes_to_read, void *read_data)
{
return aux_common(dev, DP_AUX_CMD_READ, dpcd_address,
bytes_to_read, (u8 *)read_data);
}
static int dp_tx_wakeup(struct udevice *dev)
{
u32 status;
u8 aux_data;
aux_data = 0x1;
status = aux_write(dev, DP_DPCD_SET_POWER_DP_PWR_VOLTAGE, 1, &aux_data);
if (status)
debug("! 1st power wake-up - AUX write failed.\n");
status = aux_write(dev, DP_DPCD_SET_POWER_DP_PWR_VOLTAGE, 1, &aux_data);
if (status)
debug("! 2nd power wake-up - AUX write failed.\n");
return status;
}
/**
* enable_main_link() - Switch on main link for a device
* @dev: The DP device
*/
static void enable_main_link(struct udevice *dev, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
/* Reset the scrambler. */
writel(1, dp_sub->base_addr + DP_FORCE_SCRAMBLER_RESET);
/* Enable the main stream. */
writel(enable, dp_sub->base_addr + DP_ENABLE_MAIN_STREAM);
}
/**
* get_rx_capabilities() - Check if capabilities of RX device are valid for TX
* device
* @dev: The DP device
*
* Return: 0 if the capabilities of the RX device are valid for the TX device,
* -ve if not, of an error occurred during capability determination
*/
static int get_rx_capabilities(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 rx_max_link_rate, rx_max_lane_count, *dpcd = NULL;
u32 status;
struct link_config *link_config = NULL;
dpcd = dp_sub->dpcd_rx_caps;
link_config = &dp_sub->link_config;
status = aux_read(dev, DP_DPCD_RECEIVER_CAP_FIELD_START, 16, dpcd);
if (status)
return status;
rx_max_link_rate = dpcd[DP_DPCD_MAX_LINK_RATE];
rx_max_lane_count = dpcd[DP_DPCD_MAX_LANE_COUNT] & DP_DPCD_MAX_LANE_COUNT_MASK;
link_config->max_link_rate = (rx_max_link_rate > DP_0_LINK_RATE) ?
DP_0_LINK_RATE : rx_max_link_rate;
link_config->max_lane_count = (rx_max_lane_count > DP_0_LANE_COUNT) ?
DP_0_LANE_COUNT : rx_max_lane_count;
link_config->support_enhanced_framing_mode = dpcd[DP_DPCD_MAX_LANE_COUNT] &
DP_DPCD_ENHANCED_FRAME_SUPPORT_MASK;
link_config->support_downspread_control = dpcd[DP_DPCD_MAX_DOWNSPREAD] &
DP_DPCD_MAX_DOWNSPREAD_MASK;
return 0;
}
/**
* set_enhanced_frame_mode() - Enable/Disable enhanced frame mode
* @dev: The DP device
* @enable: Flag to determine whether to enable (1) or disable (0) the enhanced
* frame mode
*
* Enable or disable the enhanced framing symbol sequence for
* both the DisplayPort TX core and the RX device.
*
* Return: 0 if enabling/disabling the enhanced frame mode was successful, -ve
* on error
*/
static int set_enhanced_frame_mode(struct udevice *dev, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
u8 regval;
dp_sub->link_config.enhanced_framing_mode = enable;
/* Write enhanced frame mode enable to the DisplayPort TX core. */
writel(dp_sub->link_config.enhanced_framing_mode,
dp_sub->base_addr + DP_ENHANCED_FRAME_EN);
/* Preserve the current RX device settings. */
status = aux_read(dev, DP_DPCD_LANE_COUNT_SET, 0x1, ®val);
if (status)
return status;
if (dp_sub->link_config.enhanced_framing_mode)
regval |= DP_DPCD_ENHANCED_FRAME_EN_MASK;
else
regval &= ~DP_DPCD_ENHANCED_FRAME_EN_MASK;
/* Write enhanced frame mode enable to the RX device. */
return aux_write(dev, DP_DPCD_LANE_COUNT_SET, 0x1, ®val);
}
/**
* set_lane_count() - Set the lane count
* @dev: The DP device
* @lane_count: Lane count to set
*
* Set the number of lanes to be used by the main link for both
* the DisplayPort TX core and the RX device.
*
* Return: 0 if setting the lane count was successful, -ve on error
*/
static int set_lane_count(struct udevice *dev, u8 lane_count)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
u8 regval;
dp_sub->link_config.lane_count = lane_count;
/* Write the new lane count to the DisplayPort TX core. */
writel(dp_sub->link_config.lane_count,
dp_sub->base_addr + DP_LANE_COUNT_SET);
/* Preserve the current RX device settings. */
status = aux_read(dev, DP_DPCD_LANE_COUNT_SET, 0x1, ®val);
if (status)
return status;
regval &= ~DP_DPCD_LANE_COUNT_SET_MASK;
regval |= dp_sub->link_config.lane_count;
/* Write the new lane count to the RX device. */
return aux_write(dev, DP_DPCD_LANE_COUNT_SET, 0x1, ®val);
}
/**
* set_clk_speed() - Set DP phy clock speed
* @dev: The DP device
* @speed: The clock frquency to set (one of PHY_CLOCK_SELECT_*)
*
* Set the clock frequency for the DisplayPort PHY corresponding to a desired
* data rate.
*
* Return: 0 if setting the DP phy clock speed was successful, -ve on error
*/
static int set_clk_speed(struct udevice *dev, u32 speed)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 regval;
/* Disable the DisplayPort TX core first. */
regval = readl(dp_sub->base_addr + DP_ENABLE);
writel(0, dp_sub->base_addr + DP_ENABLE);
/* Change speed of the feedback clock. */
writel(speed, dp_sub->base_addr + DP_PHY_CLOCK_SELECT);
/* Re-enable the DisplayPort TX core if it was previously enabled. */
if (regval)
writel(regval, dp_sub->base_addr + DP_ENABLE);
/* Wait until the PHY is ready. */
return wait_phy_ready(dev);
}
/**
* set_link_rate() - Set the link rate
* @dev: The DP device
* @link_rate: The link rate to set (one of LINK_BW_SET_*)
*
* Set the data rate to be used by the main link for both the DisplayPort TX
* core and the RX device.
*
* Return: 0 if setting the link rate was successful, -ve on error
*/
static int set_link_rate(struct udevice *dev, u8 link_rate)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
/* Write a corresponding clock frequency to the DisplayPort TX core. */
switch (link_rate) {
case DP_LINK_BW_SET_162GBPS:
status = set_clk_speed(dev, DP_PHY_CLOCK_SELECT_162GBPS);
break;
case DP_LINK_BW_SET_270GBPS:
status = set_clk_speed(dev, DP_PHY_CLOCK_SELECT_270GBPS);
break;
case DP_LINK_BW_SET_540GBPS:
status = set_clk_speed(dev, DP_PHY_CLOCK_SELECT_540GBPS);
break;
default:
status = -EINVAL;
break;
}
if (status)
return status;
dp_sub->link_config.link_rate = link_rate;
/* Write new link rate to the DisplayPort TX core. */
writel(dp_sub->link_config.link_rate,
dp_sub->base_addr +
DP_LINK_BW_SET);
/* Write new link rate to the RX device. */
return aux_write(dev, DP_DPCD_LINK_BW_SET, 0x1,
&dp_sub->link_config.link_rate);
}
static int set_downspread(struct udevice *dev, u8 enable)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
u8 regval;
dp_sub->link_config.support_downspread_control = enable;
/* Write downspread enable to the DisplayPort TX core. */
writel(dp_sub->link_config.support_downspread_control,
dp_sub->base_addr + DP_DOWNSPREAD_CTRL);
/* Preserve the current RX device settings. */
status = aux_read(dev, DP_DPCD_DOWNSPREAD_CTRL, 0x1, ®val);
if (status)
return status;
if (dp_sub->link_config.support_downspread_control)
regval |= DP_DPCD_SPREAD_AMP_MASK;
else
regval &= ~DP_DPCD_SPREAD_AMP_MASK;
/* Write downspread enable to the RX device. */
return aux_write(dev, DP_DPCD_DOWNSPREAD_CTRL, 0x1, ®val);
}
static void set_serdes_vswing_preemp(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 index;
u8 vs_level_rx = dp_sub->link_config.vs_level;
u8 pe_level_rx = dp_sub->link_config.pe_level;
for (index = 0; index < dp_sub->link_config.lane_count; index++) {
/* Write new voltage swing levels to the TX registers. */
writel(vs[pe_level_rx][vs_level_rx], (ulong)SERDES_BASEADDR +
SERDES_L0_TX_MARGININGF + index * SERDES_LANE_OFFSET);
/* Write new pre-emphasis levels to the TX registers. */
writel(pe[pe_level_rx][vs_level_rx], (ulong)SERDES_BASEADDR +
SERDES_L0_TX_DEEMPHASIS + index * SERDES_LANE_OFFSET);
}
}
/**
* set_vswing_preemp() - Build AUX data to set voltage swing and pre-emphasis
* @dev: The DP device
* @aux_data: Buffer to receive the built AUX data
*
* Build AUX data to set current voltage swing and pre-emphasis level settings;
* the necessary data is taken from the link_config structure.
*/
static void set_vswing_preemp(struct udevice *dev, u8 *aux_data)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 data = 0;
u8 vs_level_rx = dp_sub->link_config.vs_level;
u8 pe_level_rx = dp_sub->link_config.pe_level;
if (vs_level_rx >= DP_MAXIMUM_VS_LEVEL)
data |= DP_DPCD_TRAINING_LANEX_SET_MAX_VS_MASK;
/* The maximum pre-emphasis level has been reached. */
if (pe_level_rx >= DP_MAXIMUM_PE_LEVEL)
data |= DP_DPCD_TRAINING_LANEX_SET_MAX_PE_MASK;
/* Set up the data buffer for writing to the RX device. */
data |= (pe_level_rx << DP_DPCD_TRAINING_LANEX_SET_PE_SHIFT) |
vs_level_rx;
memset(aux_data, data, 4);
set_serdes_vswing_preemp(dev);
}
static int set_training_pattern(struct udevice *dev, u32 pattern)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 aux_data[5];
writel(pattern, dp_sub->base_addr + TRAINING_PATTERN_SET);
aux_data[0] = pattern;
switch (pattern) {
case TRAINING_PATTERN_SET_OFF:
writel(0, dp_sub->base_addr + SCRAMBLING_DISABLE);
dp_sub->link_config.scrambler_en = 1;
break;
case TRAINING_PATTERN_SET_TP1:
case TRAINING_PATTERN_SET_TP2:
case TRAINING_PATTERN_SET_TP3:
aux_data[0] |= DP_DPCD_TP_SET_SCRAMB_DIS_MASK;
writel(1, dp_sub->base_addr + SCRAMBLING_DISABLE);
dp_sub->link_config.scrambler_en = 0;
break;
default:
break;
}
/*
* Make the adjustments to both the DisplayPort TX core and the RX
* device.
*/
set_vswing_preemp(dev, &aux_data[1]);
/*
* Write the voltage swing and pre-emphasis levels for each lane to the
* RX device.
*/
if (pattern == TRAINING_PATTERN_SET_OFF)
return aux_write(dev, DP_DPCD_TP_SET, 1, aux_data);
else
return aux_write(dev, DP_DPCD_TP_SET, 5, aux_data);
}
static int get_lane_status_adj_reqs(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
u8 aux_data[8];
status = aux_read(dev, DP_DPCD_SINK_COUNT, 8, aux_data);
if (status)
return status;
/* Save XDPPSU_DPCD_SINK_COUNT contents. */
dp_sub->sink_count =
((aux_data[0] & DP_DPCD_SINK_COUNT_HIGH_MASK) >>
DP_DPCD_SINK_COUNT_HIGH_LOW_SHIFT) |
(aux_data[0] & DP_DPCD_SINK_COUNT_LOW_MASK);
memcpy(dp_sub->lane_status_ajd_reqs, &aux_data[2], 6);
return 0;
}
/**
* check_clock_recovery() - Check clock recovery success
* @dev: The LogiCore DP TX device in question
* @lane_count: The number of lanes for which to check clock recovery success
*
* Check if the RX device's DisplayPort Configuration data (DPCD) indicates
* that the clock recovery sequence during link training was successful - the
* RX device's link clock and data recovery unit has realized and maintained
* the frequency lock for all lanes currently in use.
*
* Return: 0 if clock recovery was successful on all lanes in question, -ve if
* not
*/
static int check_clock_recovery(struct udevice *dev, u8 lane_count)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 *lane_status = dp_sub->lane_status_ajd_reqs;
switch (lane_count) {
case DP_LANE_COUNT_SET_2:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_1_CR_DONE_MASK))
return -EINVAL;
case DP_LANE_COUNT_SET_1:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_0_CR_DONE_MASK))
return -EINVAL;
default:
/* All (LaneCount) lanes have achieved clock recovery. */
break;
}
return 0;
}
/**
* adj_vswing_preemp() - Adjust voltage swing and pre-emphasis
* @dev: The DP device
*
* Set new voltage swing and pre-emphasis levels using the
* adjustment requests obtained from the RX device.
*
* Return: 0 if voltage swing and pre-emphasis could be adjusted successfully,
* -ve on error
*/
static int adj_vswing_preemp(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 index, vs_level_adj_req[4], pe_level_adj_req[4];
u8 aux_data[4];
u8 *adj_reqs = &dp_sub->lane_status_ajd_reqs[4];
/*
* Analyze the adjustment requests for changes in voltage swing and
* pre-emphasis levels.
*/
vs_level_adj_req[0] = adj_reqs[0] & DP_DPCD_ADJ_REQ_LANE_0_2_VS_MASK;
vs_level_adj_req[1] = (adj_reqs[0] & DP_DPCD_ADJ_REQ_LANE_1_3_VS_MASK) >>
DP_DPCD_ADJ_REQ_LANE_1_3_VS_SHIFT;
pe_level_adj_req[0] = (adj_reqs[0] & DP_DPCD_ADJ_REQ_LANE_0_2_PE_MASK) >>
DP_DPCD_ADJ_REQ_LANE_0_2_PE_SHIFT;
pe_level_adj_req[1] = (adj_reqs[0] & DP_DPCD_ADJ_REQ_LANE_1_3_PE_MASK) >>
DP_DPCD_ADJ_REQ_LANE_1_3_PE_SHIFT;
/*
* Change the drive settings to match the adjustment requests. Use the
* greatest level requested.
*/
dp_sub->link_config.vs_level = 0;
dp_sub->link_config.pe_level = 0;
for (index = 0; index < dp_sub->link_config.lane_count; index++) {
if (vs_level_adj_req[index] > dp_sub->link_config.vs_level)
dp_sub->link_config.vs_level = vs_level_adj_req[index];
if (pe_level_adj_req[index] > dp_sub->link_config.pe_level)
dp_sub->link_config.pe_level = pe_level_adj_req[index];
}
if (dp_sub->link_config.pe_level > DP_MAXIMUM_PE_LEVEL)
dp_sub->link_config.pe_level = DP_MAXIMUM_PE_LEVEL;
if (dp_sub->link_config.vs_level > DP_MAXIMUM_VS_LEVEL)
dp_sub->link_config.vs_level = DP_MAXIMUM_VS_LEVEL;
if (dp_sub->link_config.pe_level >
(4 - dp_sub->link_config.vs_level)) {
dp_sub->link_config.pe_level =
4 - dp_sub->link_config.vs_level;
}
/*
* Make the adjustments to both the DisplayPort TX core and the RX
* device.
*/
set_vswing_preemp(dev, aux_data);
/*
* Write the voltage swing and pre-emphasis levels for each lane to the
* RX device.
*/
return aux_write(dev, DP_DPCD_TRAINING_LANE0_SET, 2, aux_data);
}
/**
* get_training_delay() - Get training delay
* @dev: The DP device
* @training_state: The training state for which the required training delay
* should be queried
*
* Determine what the RX device's required training delay is for
* link training.
*
* Return: The training delay in us
*/
static u32 get_training_delay(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 *dpcd = dp_sub->dpcd_rx_caps;
if (dpcd[DP_DPCD_TRAIN_AUX_RD_INTERVAL])
return 400 * dpcd[DP_DPCD_TRAIN_AUX_RD_INTERVAL] * 10;
return 400;
}
/**
* training_state_clock_recovery() - Run clock recovery part of link training
* @dev: The DP device
*
* Run the clock recovery sequence as part of link training. The
* sequence is as follows:
*
* 0) Start signaling at the minimum voltage swing, pre-emphasis, and
* post- cursor levels.
* 1) Transmit training pattern 1 over the main link with symbol
* scrambling disabled.
* 2) The clock recovery loop. If clock recovery is unsuccessful after
* MaxIterations loop iterations, return.
* 2a) Wait for at least the period of time specified in the RX device's
* DisplayPort Configuration data (DPCD) register,
* TRAINING_AUX_RD_INTERVAL.
* 2b) Check if all lanes have achieved clock recovery lock. If so,
* return.
* 2c) Check if the same voltage swing level has been used 5 consecutive
* times or if the maximum level has been reached. If so, return.
* 2d) Adjust the voltage swing, pre-emphasis, and post-cursor levels as
* requested by the RX device.
* 2e) Loop back to 2a.
*
* For a more detailed description of the clock recovery sequence, see section
* 3.5.1.2.1 of the DisplayPort 1.2a specification document.
*
* Return: The next state machine state to advance to
*/
static enum link_training_states training_state_clock_recovery(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status, delay_us;
u8 prev_vs_level = 0, same_vs_level_count = 0;
struct link_config *link_config = &dp_sub->link_config;
delay_us = get_training_delay(dev);
/* Start CRLock. */
/* Start from minimal voltage swing and pre-emphasis levels. */
dp_sub->link_config.vs_level = 0;
dp_sub->link_config.pe_level = 0;
/* Transmit training pattern 1. */
status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP1);
if (status)
return TS_FAILURE;
while (1) {
/* Wait delay specified in TRAINING_AUX_RD_INTERVAL. */
udelay(delay_us);
/* Get lane and adjustment requests. */
status = get_lane_status_adj_reqs(dev);
if (status)
/* The AUX read failed. */
return TS_FAILURE;
/*
* Check if all lanes have realized and maintained the frequency
* lock and get adjustment requests.
*/
status = check_clock_recovery(dev, dp_sub->link_config.lane_count);
if (status == 0)
return TS_CHANNEL_EQUALIZATION;
/*
* Check if the same voltage swing for each lane has been used 5
* consecutive times.
*/
if (prev_vs_level == link_config->vs_level) {
same_vs_level_count++;
} else {
same_vs_level_count = 0;
prev_vs_level = link_config->vs_level;
}
if (same_vs_level_count >= 5)
break;
/* Only try maximum voltage swing once. */
if (link_config->vs_level == DP_MAXIMUM_VS_LEVEL)
break;
/* Adjust the drive settings as requested by the RX device. */
status = adj_vswing_preemp(dev);
if (status)
/* The AUX write failed. */
return TS_FAILURE;
}
return TS_ADJUST_LINK_RATE;
}
/**
* check_channel_equalization() - Check channel equalization success
* @dev: The DP device
* @lane_count: The number of lanes for which to check channel equalization
* success
*
* Check if the RX device's DisplayPort Configuration data (DPCD) indicates
* that the channel equalization sequence during link training was successful -
* the RX device has achieved channel equalization, symbol lock, and interlane
* alignment for all lanes currently in use.
*
* Return: 0 if channel equalization was successful on all lanes in question,
* -ve if not
*/
static int check_channel_equalization(struct udevice *dev, u8 lane_count)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 *lane_status = dp_sub->lane_status_ajd_reqs;
/* Check that all LANEx_CHANNEL_EQ_DONE bits are set. */
switch (lane_count) {
case DP_LANE_COUNT_SET_2:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_1_CE_DONE_MASK))
return -EINVAL;
case DP_LANE_COUNT_SET_1:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_0_CE_DONE_MASK))
return -EINVAL;
default:
/* All (LaneCount) lanes have achieved channel equalization. */
break;
}
/* Check that all LANEx_SYMBOL_LOCKED bits are set. */
switch (lane_count) {
case DP_LANE_COUNT_SET_2:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_1_SL_DONE_MASK))
return -EINVAL;
case DP_LANE_COUNT_SET_1:
if (!(lane_status[0] & DP_DPCD_STATUS_LANE_0_SL_DONE_MASK))
return -EINVAL;
default:
/* All (LaneCount) lanes have achieved symbol lock. */
break;
}
/* Check that interlane alignment is done. */
if (!(lane_status[2] & DP_DPCD_LANE_ALIGN_STATUS_UPDATED_IA_DONE_MASK))
return -EINVAL;
return 0;
}
/**
* training_state_channel_equalization() - Run channel equalization part of
* link training
* @dev: The DP device
*
* Run the channel equalization sequence as part of link
* training. The sequence is as follows:
*
* 0) Start signaling with the same drive settings used at the end of the
* clock recovery sequence.
* 1) Transmit training pattern 2 (or 3) over the main link with symbol
* scrambling disabled.
* 2) The channel equalization loop. If channel equalization is
* unsuccessful after 5 loop iterations, return.
* 2a) Wait for at least the period of time specified in the RX device's
* DisplayPort Configuration data (DPCD) register,
* TRAINING_AUX_RD_INTERVAL.
* 2b) Check if all lanes have achieved channel equalization, symbol lock,
* and interlane alignment. If so, return.
* 2c) Check if the same voltage swing level has been used 5 consecutive
* times or if the maximum level has been reached. If so, return.
* 2d) Adjust the voltage swing, pre-emphasis, and post-cursor levels as
* requested by the RX device.
* 2e) Loop back to 2a.
*
* For a more detailed description of the channel equalization sequence, see
* section 3.5.1.2.2 of the DisplayPort 1.2a specification document.
*
* Return: The next state machine state to advance to
*/
static enum link_training_states training_state_channel_equalization(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status, delay_us = 400, iteration_count = 0;
/* Write the current drive settings. */
/* Transmit training pattern 2/3. */
if (dp_sub->dpcd_rx_caps[DP_DPCD_MAX_LANE_COUNT] &
DP_DPCD_TPS3_SUPPORT_MASK)
status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP3);
else
status = set_training_pattern(dev, TRAINING_PATTERN_SET_TP2);
if (status)
return TS_FAILURE;
while (iteration_count < 5) {
/* Wait delay specified in TRAINING_AUX_RD_INTERVAL. */
udelay(delay_us);
/* Get lane and adjustment requests. */
status = get_lane_status_adj_reqs(dev);
if (status)
/* The AUX read failed. */
return TS_FAILURE;
/* Adjust the drive settings as requested by the RX device. */
status = adj_vswing_preemp(dev);
if (status)
/* The AUX write failed. */
return TS_FAILURE;
/* Check that all lanes still have their clocks locked. */
status = check_clock_recovery(dev, dp_sub->link_config.lane_count);
if (status)
break;
/*
* Check that all lanes have accomplished channel
* equalization, symbol lock, and interlane alignment.
*/
status = check_channel_equalization(dev, dp_sub->link_config.lane_count);
if (status == 0)
return TS_SUCCESS;
iteration_count++;
}
/*
* Tried 5 times with no success. Try a reduced bitrate first, then
* reduce the number of lanes.
*/
return TS_ADJUST_LINK_RATE;
}
static int check_lane_align(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u8 *lane_status = dp_sub->lane_status_ajd_reqs;
if (!(lane_status[2] & DP_DPCD_LANE_ALIGN_STATUS_UPDATED_IA_DONE_MASK))
return -EINVAL;
return 0;
}
/**
* check_link_status() - Check status of link
* @dev: The DP device
* @lane_count: The lane count to use for the check
*
* Check if the receiver's DisplayPort Configuration data (DPCD) indicates the
* receiver has achieved and maintained clock recovery, channel equalization,
* symbol lock, and interlane alignment for all lanes currently in use.
*
* Return: 0 if the link status is OK, -ve if a error occurred during checking
*/
static int check_link_status(struct udevice *dev, u8 lane_count)
{
u32 status;
status = get_lane_status_adj_reqs(dev);
if (status)
/* The AUX read failed. */
return status;
/* Check if the link needs training. */
if ((check_clock_recovery(dev, lane_count) == 0) &&
(check_channel_equalization(dev, lane_count) == 0) &&
(check_lane_align(dev) == 0)) {
return 0;
}
return -EINVAL;
}
/**
* run_training() - Run link training
* @dev: The DP device
*
* Run the link training process. It is implemented as a state machine, with
* each state returning the next state. First, the clock recovery sequence will
* be run; if successful, the channel equalization sequence will run. If either
* the clock recovery or channel equalization sequence failed, the link rate or
* the number of lanes used will be reduced and training will be re-attempted.
* If training fails at the minimal data rate, 1.62 Gbps with a single lane,
* training will no longer re-attempt and fail.
*
* There are undocumented timeout constraints in the link training process. In
* DP v1.2a spec, Chapter 3.5.1.2.2 a 10ms limit for the complete training
* process is mentioned. Which individual timeouts are derived and implemented
* by sink manufacturers is unknown. So each step should be as short as
* possible and link training should start as soon as possible after HPD.
*
* Return: 0 if the training sequence ran successfully, -ve if a error occurred
* or the training failed
*/
static int run_training(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status;
enum link_training_states training_state = TS_CLOCK_RECOVERY;
while (1) {
switch (training_state) {
case TS_CLOCK_RECOVERY:
training_state = training_state_clock_recovery(dev);
break;
case TS_CHANNEL_EQUALIZATION:
training_state = training_state_channel_equalization(dev);
break;
default:
break;
}
if (training_state == TS_SUCCESS)
break;
else if (training_state == TS_FAILURE)
return -EINVAL;
if (training_state == TS_ADJUST_LANE_COUNT ||
training_state == TS_ADJUST_LINK_RATE) {
status = set_training_pattern(dev, TRAINING_PATTERN_SET_OFF);
if (status)
return -EINVAL;
}
}
/* Final status check. */
return check_link_status(dev, dp_sub->link_config.lane_count);
}
void reset_dp_phy(struct udevice *dev, u32 reset)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 phyval, regval;
writel(0, dp_sub->base_addr + DP_ENABLE);
phyval = readl(dp_sub->base_addr + DP_PHY_CONFIG);
regval = phyval | reset;
writel(regval, dp_sub->base_addr + DP_PHY_CONFIG);
/* Remove the reset. */
writel(phyval, dp_sub->base_addr + DP_PHY_CONFIG);
/* Wait for the PHY to be ready. */
wait_phy_ready(dev);
writel(1, dp_sub->base_addr + DP_ENABLE);
}
/**
* establish_link() - Establish a link
* @dev: The DP device
*
* Check if the link needs training and run the training sequence if training
* is required.
*
* Return: 0 if the link was established successfully, -ve on error
*/
static int establish_link(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 status, re_enable_main_link;
reset_dp_phy(dev, DP_PHY_CONFIG_TX_PHY_8B10BEN_MASK |
DP_PHY_CONFIG_PHY_RESET_MASK);
re_enable_main_link = readl(dp_sub->base_addr + DP_ENABLE_MAIN_STREAM);
if (re_enable_main_link)
enable_main_link(dev, 0);
status = run_training(dev);
if (status)
return status;
status = set_training_pattern(dev, TRAINING_PATTERN_SET_OFF);
if (status)
return status;
if (re_enable_main_link)
enable_main_link(dev, 1);
return check_link_status(dev, dp_sub->link_config.lane_count);
}
static int dp_hpd_train(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct link_config *link_config = &dp_sub->link_config;
u32 status;
status = get_rx_capabilities(dev);
if (status) {
debug("! Error getting RX caps.\n");
return status;
}
status = set_enhanced_frame_mode(dev, link_config->support_enhanced_framing_mode ? 1 : 0);
if (status) {
debug("! EFM set failed.\n");
return status;
}
status = set_lane_count(dev, (dp_sub->use_max_lane_count) ?
link_config->max_lane_count : dp_sub->lane_count);
if (status) {
debug("! Lane count set failed.\n");
return status;
}
status = set_link_rate(dev, (dp_sub->use_max_link_rate) ?
link_config->max_link_rate : dp_sub->link_rate);
if (status) {
debug("! Link rate set failed.\n");
return status;
}
status = set_downspread(dev, link_config->support_downspread_control);
if (status) {
debug("! Setting downspread failed.\n");
return status;
}
debug("Lane count =%d\n", dp_sub->link_config.lane_count);
debug("Link rate =%d\n", dp_sub->link_config.link_rate);
debug("Starting Training...\n");
status = establish_link(dev);
if (status == 0)
debug("! Training succeeded.\n");
else
debug("! Training failed.\n");
return status;
}
static void display_gfx_frame_buffer(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
if (!dp_sub->dp_dma->gfx.channel.cur)
dp_sub->dp_dma->gfx.trigger_status = DPDMA_TRIGGER_EN;
}
static void set_color_encode(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct main_stream_attributes *msa_config = &dp_sub->msa_config;
msa_config->y_cb_cr_colorimetry = 0;
msa_config->dynamic_range = 0;
msa_config->component_format = 0;
msa_config->misc0 = 0;
msa_config->misc1 = 0;
msa_config->component_format = DP_MAIN_STREAM_MISC0_COMPONENT_FORMAT_RGB;
}
static void config_msa_recalculate(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
u32 video_bw, link_bw, words_per_line;
u8 bits_per_pixel;
struct main_stream_attributes *msa_config;
struct link_config *link_config;
msa_config = &dp_sub->msa_config;
link_config = &dp_sub->link_config;
msa_config->user_pixel_width = 1;
/* Compute the rest of the MSA values. */
msa_config->n_vid = 27 * 1000 * link_config->link_rate;
msa_config->h_start = msa_config->vid_timing_mode.video_timing.h_sync_width +
msa_config->vid_timing_mode.video_timing.h_back_porch;
msa_config->v_start = msa_config->vid_timing_mode.video_timing.f0_pv_sync_width +
msa_config->vid_timing_mode.video_timing.f0_pv_back_porch;
/* Miscellaneous attributes. */
if (msa_config->bits_per_color == 6)
msa_config->misc0 = DP_MAIN_STREAM_MISC0_BDC_6BPC;
else if (msa_config->bits_per_color == 8)
msa_config->misc0 = DP_MAIN_STREAM_MISC0_BDC_8BPC;
else if (msa_config->bits_per_color == 10)
msa_config->misc0 = DP_MAIN_STREAM_MISC0_BDC_10BPC;
else if (msa_config->bits_per_color == 12)
msa_config->misc0 = DP_MAIN_STREAM_MISC0_BDC_12BPC;
else if (msa_config->bits_per_color == 16)
msa_config->misc0 = DP_MAIN_STREAM_MISC0_BDC_16BPC;
msa_config->misc0 <<= DP_MAIN_STREAM_MISC0_BDC_SHIFT;
/* Need to set this. */
msa_config->misc0 |= msa_config->component_format <<
DP_MAIN_STREAM_MISC0_COMPONENT_FORMAT_SHIFT;
msa_config->misc0 |= msa_config->dynamic_range <<
DP_MAIN_STREAM_MISC0_DYNAMIC_RANGE_SHIFT;
msa_config->misc0 |= msa_config->y_cb_cr_colorimetry <<
DP_MAIN_STREAM_MISC0_YCBCR_COLORIMETRY_SHIFT;
msa_config->misc0 |= msa_config->synchronous_clock_mode;
/*
* Determine the number of bits per pixel for the specified color
* component format.
*/
if (msa_config->misc1 == DP_MAIN_STREAM_MISC1_Y_ONLY_EN_MASK)
bits_per_pixel = msa_config->bits_per_color;
else if (msa_config->component_format ==
DP_MAIN_STREAM_MISC0_COMPONENT_FORMAT_YCBCR422)
/* YCbCr422 color component format. */
bits_per_pixel = msa_config->bits_per_color * 2;
else
/* RGB or YCbCr 4:4:4 color component format. */
bits_per_pixel = msa_config->bits_per_color * 3;
/* Calculate the data per lane. */
words_per_line = msa_config->vid_timing_mode.video_timing.h_active * bits_per_pixel;
if (words_per_line % 16)
words_per_line += 16;
words_per_line /= 16;
msa_config->data_per_lane = words_per_line - link_config->lane_count;
if (words_per_line % link_config->lane_count)
msa_config->data_per_lane += (words_per_line % link_config->lane_count);
/* Allocate a fixed size for single-stream transport (SST) operation. */
msa_config->transfer_unit_size = 64;
/*
* Calculate the average number of bytes per transfer unit.
* Note: Both the integer and the fractional part is stored in
* AvgBytesPerTU.
*/
video_bw = ((msa_config->pixel_clock_hz / 1000) * bits_per_pixel) / 8;
link_bw = (link_config->lane_count * link_config->link_rate * 27);
msa_config->avg_bytes_per_tu = ((10 *
(video_bw * msa_config->transfer_unit_size)
/ link_bw) + 5) / 10;
/*
* The number of initial wait cycles at the start of a new line by the
* framing logic. This allows enough data to be buffered in the input
* FIFO before video is sent.
*/
if ((msa_config->avg_bytes_per_tu / 1000) <= 4)
msa_config->init_wait = 64;
else
msa_config->init_wait = msa_config->transfer_unit_size -
(msa_config->avg_bytes_per_tu / 1000);
}
static void set_msa_bpc(struct udevice *dev, u8 bits_per_color)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
dp_sub->msa_config.bits_per_color = bits_per_color;
/* Calculate the rest of the MSA values. */
config_msa_recalculate(dev);
}
const struct video_timing_mode *get_video_mode_data(enum video_mode vm_id)
{
if (vm_id < VIDC_VM_NUM_SUPPORTED)
return &vidc_video_timing_modes[vm_id];
return NULL;
}
static u64 get_pixelclk_by_vmid(enum video_mode vm_id)
{
const struct video_timing_mode *vm;
u64 clk_hz;
vm = get_video_mode_data(vm_id);
/* For progressive mode, use only frame 0 vertical total. */
clk_hz = vm->video_timing.f0_pv_total;
/* Multiply the number of pixels by the frame rate. */
clk_hz *= vm->frame_rate;
/*
* Multiply the vertical total by the horizontal total for number of
* pixels.
*/
clk_hz *= vm->video_timing.h_total;
return clk_hz;
}
/**
* config_msa_video_mode() - Enable video output
* @dev: The DP device
* @msa: The MSA values to set for the device
*
* Return: 0 if the video was enabled successfully, -ve on error
*/
static void config_msa_video_mode(struct udevice *dev, enum video_mode videomode)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct main_stream_attributes *msa_config;
msa_config = &dp_sub->msa_config;
/* Configure the MSA values from the display monitor DMT table. */
msa_config->vid_timing_mode.vid_mode = vidc_video_timing_modes[videomode].vid_mode;
msa_config->vid_timing_mode.frame_rate = vidc_video_timing_modes[videomode].frame_rate;
msa_config->vid_timing_mode.video_timing.h_active =
vidc_video_timing_modes[videomode].video_timing.h_active;
msa_config->vid_timing_mode.video_timing.h_front_porch =
vidc_video_timing_modes[videomode].video_timing.h_front_porch;
msa_config->vid_timing_mode.video_timing.h_sync_width =
vidc_video_timing_modes[videomode].video_timing.h_sync_width;
msa_config->vid_timing_mode.video_timing.h_back_porch =
vidc_video_timing_modes[videomode].video_timing.h_back_porch;
msa_config->vid_timing_mode.video_timing.h_total =
vidc_video_timing_modes[videomode].video_timing.h_total;
msa_config->vid_timing_mode.video_timing.h_sync_polarity =
vidc_video_timing_modes[videomode].video_timing.h_sync_polarity;
msa_config->vid_timing_mode.video_timing.v_active =
vidc_video_timing_modes[videomode].video_timing.v_active;
msa_config->vid_timing_mode.video_timing.f0_pv_front_porch =
vidc_video_timing_modes[videomode].video_timing.f0_pv_front_porch;
msa_config->vid_timing_mode.video_timing.f0_pv_sync_width =
vidc_video_timing_modes[videomode].video_timing.f0_pv_sync_width;
msa_config->vid_timing_mode.video_timing.f0_pv_back_porch =
vidc_video_timing_modes[videomode].video_timing.f0_pv_back_porch;
msa_config->vid_timing_mode.video_timing.f0_pv_total =
vidc_video_timing_modes[videomode].video_timing.f0_pv_total;
msa_config->vid_timing_mode.video_timing.f1_v_front_porch =
vidc_video_timing_modes[videomode].video_timing.f1_v_front_porch;
msa_config->vid_timing_mode.video_timing.f1_v_sync_width =
vidc_video_timing_modes[videomode].video_timing.f1_v_sync_width;
msa_config->vid_timing_mode.video_timing.f1_v_back_porch =
vidc_video_timing_modes[videomode].video_timing.f1_v_back_porch;
msa_config->vid_timing_mode.video_timing.f1_v_total =
vidc_video_timing_modes[videomode].video_timing.f1_v_total;
msa_config->vid_timing_mode.video_timing.v_sync_polarity =
vidc_video_timing_modes[videomode].video_timing.v_sync_polarity;
msa_config->pixel_clock_hz = get_pixelclk_by_vmid(msa_config->vid_timing_mode.vid_mode);
/* Calculate the rest of the MSA values. */
config_msa_recalculate(dev);
}
static void set_pixel_clock(u64 freq_hz)
{
u64 ext_divider, vco, vco_int_frac;
u32 pll_assigned, frac_int_fb_div, fraction, regpll = 0;
u8 pll;
pll_assigned = readl(CLK_FPD_BASEADDR + VIDEO_REF_CTRL) & VIDEO_REF_CTRL_SRCSEL_MASK;
if (pll_assigned)
pll = VPLL;
ext_divider = PLL_OUT_FREQ / freq_hz;
vco = freq_hz * ext_divider * 2;
vco_int_frac = (vco * INPUT_FREQ_PRECISION * SHIFT_DECIMAL) /
AVBUF_INPUT_REF_CLK;
frac_int_fb_div = vco_int_frac >> PRECISION;
fraction = vco_int_frac & AVBUF_DECIMAL;
regpll |= ENABLE_BIT << PLL_CTRL_BYPASS_SHIFT;
regpll |= frac_int_fb_div << PLL_CTRL_FBDIV_SHIFT;
regpll |= (1 << PLL_CTRL_DIV2_SHIFT);
regpll |= (PSS_REF_CLK << PLL_CTRL_PRE_SRC_SHIFT);
writel(regpll, CLK_FPD_BASEADDR + VPLL_CTRL);
regpll = 0;
regpll |= VPLL_CFG_CP << PLL_CFG_CP_SHIFT;
regpll |= VPLL_CFG_RES << PLL_CFG_RES_SHIFT;
regpll |= VPLL_CFG_LFHF << PLL_CFG_LFHF_SHIFT;
regpll |= VPLL_CFG_LOCK_DLY << PLL_CFG_LOCK_DLY_SHIFT;
regpll |= VPLL_CFG_LOCK_CNT << PLL_CFG_LOCK_CNT_SHIFT;
writel(regpll, CLK_FPD_BASEADDR + VPLL_CFG);
regpll = (1U << PLL_FRAC_CFG_ENABLED_SHIFT) |
(fraction << PLL_FRAC_CFG_DATA_SHIFT);
writel(regpll, CLK_FPD_BASEADDR + VPLL_FRAC_CFG);
clrsetbits_le32(CLK_FPD_BASEADDR + VPLL_CTRL,
PLL_CTRL_RESET_MASK,
(ENABLE_BIT << PLL_CTRL_RESET_SHIFT));
/* Deassert reset to the PLL. */
clrsetbits_le32(CLK_FPD_BASEADDR + VPLL_CTRL,
PLL_CTRL_RESET_MASK,
(DISABLE_BIT << PLL_CTRL_RESET_SHIFT));
while (!(readl(CLK_FPD_BASEADDR + PLL_STATUS) &
(1 << PLL_STATUS_VPLL_LOCK)))
;
/* Deassert Bypass. */
clrsetbits_le32(CLK_FPD_BASEADDR + VPLL_CTRL,
PLL_CTRL_BYPASS_MASK,
(DISABLE_BIT << PLL_CTRL_BYPASS_SHIFT));
udelay(1);
clrsetbits_le32(CLK_FPD_BASEADDR + VIDEO_REF_CTRL,
VIDEO_REF_CTRL_CLKACT_MASK,
(DISABLE_BIT << VIDEO_REF_CTRL_CLKACT_SHIFT));
clrsetbits_le32(CLK_FPD_BASEADDR + VIDEO_REF_CTRL,
VIDEO_REF_CTRL_DIVISOR1_MASK,
(ENABLE_BIT << VIDEO_REF_CTRL_DIVISOR1_SHIFT));
clrsetbits_le32(CLK_FPD_BASEADDR + VIDEO_REF_CTRL,
VIDEO_REF_CTRL_DIVISOR0_MASK,
(ext_divider << VIDEO_REF_CTRL_DIVISOR0_SHIFT));
clrsetbits_le32(CLK_FPD_BASEADDR + VIDEO_REF_CTRL,
VIDEO_REF_CTRL_CLKACT_MASK,
(ENABLE_BIT << VIDEO_REF_CTRL_CLKACT_SHIFT));
}
/**
* set_msa_values() - Set MSA values
* @dev: The DP device
*
* Set the main stream attributes registers of the DisplayPort TX
* core with the values specified in the main stream attributes configuration
* structure.
*/
static void set_msa_values(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct main_stream_attributes *msa_config;
msa_config = &dp_sub->msa_config;
/*
* Set the main stream attributes to the associated DisplayPort TX core
* registers.
*/
writel(msa_config->vid_timing_mode.video_timing.h_total,
dp_sub->base_addr + DP_MAIN_STREAM_HTOTAL);
writel(msa_config->vid_timing_mode.video_timing.f0_pv_total,
dp_sub->base_addr + DP_MAIN_STREAM_VTOTAL);
writel(msa_config->vid_timing_mode.video_timing.h_sync_polarity |
(msa_config->vid_timing_mode.video_timing.v_sync_polarity
<< DP_MAIN_STREAM_POLARITY_VSYNC_POL_SHIFT),
dp_sub->base_addr + DP_MAIN_STREAM_POLARITY);
writel(msa_config->vid_timing_mode.video_timing.h_sync_width,
dp_sub->base_addr + DP_MAIN_STREAM_HSWIDTH);
writel(msa_config->vid_timing_mode.video_timing.f0_pv_sync_width,
dp_sub->base_addr + DP_MAIN_STREAM_VSWIDTH);
writel(msa_config->vid_timing_mode.video_timing.h_active,
dp_sub->base_addr + DP_MAIN_STREAM_HRES);
writel(msa_config->vid_timing_mode.video_timing.v_active,
dp_sub->base_addr + DP_MAIN_STREAM_VRES);
writel(msa_config->h_start, dp_sub->base_addr + DP_MAIN_STREAM_HSTART);
writel(msa_config->v_start, dp_sub->base_addr + DP_MAIN_STREAM_VSTART);
writel(msa_config->misc0, dp_sub->base_addr + DP_MAIN_STREAM_MISC0);
writel(msa_config->misc1, dp_sub->base_addr + DP_MAIN_STREAM_MISC1);
writel(msa_config->pixel_clock_hz / 1000, dp_sub->base_addr + DP_M_VID);
writel(msa_config->n_vid, dp_sub->base_addr + DP_N_VID);
writel(msa_config->user_pixel_width, dp_sub->base_addr + DP_USER_PIXEL_WIDTH);
writel(msa_config->data_per_lane, dp_sub->base_addr + DP_USER_DATA_COUNT_PER_LANE);
/*
* Set the transfer unit values to the associated DisplayPort TX core
* registers.
*/
writel(msa_config->transfer_unit_size, dp_sub->base_addr + DP_TU_SIZE);
writel(msa_config->avg_bytes_per_tu / 1000,
dp_sub->base_addr + DP_MIN_BYTES_PER_TU);
writel((msa_config->avg_bytes_per_tu % 1000) * 1000,
dp_sub->base_addr + DP_FRAC_BYTES_PER_TU);
writel(msa_config->init_wait, dp_sub->base_addr + DP_INIT_WAIT);
}
static void setup_video_stream(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
struct main_stream_attributes *msa_config = &dp_sub->msa_config;
set_color_encode(dev);
set_msa_bpc(dev, dp_sub->bpc);
config_msa_video_mode(dev, dp_sub->video_mode);
/* Set pixel clock. */
dp_sub->pix_clk = msa_config->pixel_clock_hz;
set_pixel_clock(dp_sub->pix_clk);
/* Reset the transmitter. */
writel(1, dp_sub->base_addr + DP_SOFT_RESET);
udelay(10);
writel(0, dp_sub->base_addr + DP_SOFT_RESET);
set_msa_values(dev);
/* Issuing a soft-reset (AV_BUF_SRST_REG). */
writel(3, dp_sub->base_addr + AVBUF_BUF_SRST_REG); // Assert reset.
udelay(10);
writel(0, dp_sub->base_addr + AVBUF_BUF_SRST_REG); // De-ssert reset.
enable_main_link(dev, 1);
debug("DONE!\n");
}
static int dp_tx_start_link_training(struct udevice *dev)
{
u32 status;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
enable_main_link(dev, 0);
if (!is_dp_connected(dev)) {
debug("! Disconnected.\n");
return -ENODEV;
}
status = dp_tx_wakeup(dev);
if (status) {
debug("! Wakeup failed.\n");
return -EIO;
}
do {
mdelay(100);
status = dp_hpd_train(dev);
if (status == -EINVAL) {
debug("Lost connection\n\r");
return -EIO;
} else if (status) {
continue;
}
display_gfx_frame_buffer(dev);
setup_video_stream(dev);
status = check_link_status(dev, dp_sub->link_config.lane_count);
if (status == -EINVAL)
return -EIO;
} while (status != 0);
return 0;
}
static void init_run_config(struct udevice *dev)
{
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
dp_sub->dp_dma = &dp_dma;
dp_sub->video_mode = VIDC_VM_1024x768_60_P;
dp_sub->bpc = VIDC_BPC_8;
dp_sub->color_encode = DP_CENC_RGB;
dp_sub->use_max_cfg_caps = 1;
dp_sub->lane_count = LANE_COUNT_1;
dp_sub->link_rate = LINK_RATE_540GBPS;
dp_sub->en_sync_clk_mode = 0;
dp_sub->use_max_lane_count = 1;
dp_sub->use_max_link_rate = 1;
}
static int dpdma_setup(struct udevice *dev)
{
int status;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
writel(DPDMA_ISR_VSYNC_INT_MASK, dp_sub->dp_dma->base_addr + DPDMA_IEN);
status = wait_for_bit_le32((u32 *)dp_sub->dp_dma->base_addr + DPDMA_ISR,
DPDMA_ISR_VSYNC_INT_MASK, false, 1000, false);
if (status) {
debug("%s: INTR TIMEDOUT\n", __func__);
return status;
}
debug("INTR dma_vsync_intr_handler called...\n");
dma_vsync_intr_handler(dev);
return 0;
}
static int zynqmp_dpsub_init(struct udevice *dev)
{
int status;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
/* Initialize the dpdma configuration */
status = init_dpdma_subsys(dev);
if (status)
return -EINVAL;
config_msa_sync_clk_mode(dev, dp_sub->en_sync_clk_mode);
set_video_clk_source(dev, AVBUF_PS_CLK, AVBUF_PS_CLK);
return 0;
}
static int dp_tx_run(struct udevice *dev)
{
u32 interrupt_signal_state, interrupt_status, hpd_state, hpd_event;
u32 hpd_pulse_detected, hpd_duration, status;
int attempts = 0;
struct zynqmp_dpsub_priv *dp_sub = dev_get_priv(dev);
/* Continuously poll for HPD events. */
while (attempts < 5) {
/* Read interrupt registers. */
interrupt_signal_state = readl(dp_sub->base_addr + DP_INTERRUPT_SIG_STATE);
interrupt_status = readl(dp_sub->base_addr + DP_INTR_STATUS);
/* Check for HPD events. */
hpd_state = interrupt_signal_state & DP_INTERRUPT_SIG_STATE_HPD_STATE_MASK;
hpd_event = interrupt_status & DP_INTR_HPD_EVENT_MASK;
hpd_pulse_detected = interrupt_status & DP_INTR_HPD_PULSE_DETECTED_MASK;
if (hpd_pulse_detected)
hpd_duration = readl(dp_sub->base_addr + DP_HPD_DURATION);
else
attempts++;
/* HPD event handling. */
if (hpd_state && hpd_event) {
debug("+===> HPD connection event detected.\n");
/* Initiate link training. */
status = dp_tx_start_link_training(dev);
if (status) {
debug("Link training failed\n");
return status;
}
return 0;
} else if (hpd_state && hpd_pulse_detected && (hpd_duration >= 250)) {
debug("===> HPD pulse detected.\n");
/* Re-train if needed. */
status = dp_tx_start_link_training(dev);
if (status) {
debug("HPD pulse detection failed\n");
return status;
}
return 0;
} else if (!hpd_state && hpd_event) {
debug("+===> HPD disconnection event detected.\n\n");
/* Disable main link. */
enable_main_link(dev, 0);
break;
}
}
return -EINVAL;
}
static int zynqmp_dpsub_probe(struct udevice *dev)
{
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
struct zynqmp_dpsub_priv *priv = dev_get_priv(dev);
struct clk clk;
int ret;
int mode = RGBA8888;
ret = clk_get_by_name(dev, "dp_apb_clk", &clk);
if (ret < 0) {
dev_err(dev, "failed to get clock\n");
return ret;
}
priv->clock = clk_get_rate(&clk);
if (IS_ERR_VALUE(priv->clock)) {
dev_err(dev, "failed to get rate\n");
return priv->clock;
}
ret = clk_enable(&clk);
if (ret) {
dev_err(dev, "failed to enable clock\n");
return ret;
}
dev_dbg(dev, "Base addr 0x%x, clock %d\n", (u32)priv->base_addr,
priv->clock);
/* Initialize the DisplayPort TX core. */
ret = init_dp_tx(dev);
if (ret)
return -EINVAL;
/* Initialize the runtime configuration */
init_run_config(dev);
/* Set the format graphics frame for Video Pipeline */
ret = set_nonlive_gfx_format(dev, mode);
if (ret)
return ret;
uc_priv->bpix = ffs(priv->non_live_graphics->bpp) - 1;
dev_dbg(dev, "BPP in bits %d, bpix %d\n",
priv->non_live_graphics->bpp, uc_priv->bpix);
uc_priv->fb = (void *)gd->fb_base;
uc_priv->xsize = vidc_video_timing_modes[priv->video_mode].video_timing.h_active;
uc_priv->ysize = vidc_video_timing_modes[priv->video_mode].video_timing.v_active;
/* Calculated by core but need it for my own setup */
uc_priv->line_length = uc_priv->xsize * VNBYTES(uc_priv->bpix);
/* Will be calculated again in video_post_probe() but I need that value now */
uc_priv->fb_size = uc_priv->line_length * uc_priv->ysize;
switch (mode) {
case RGBA8888:
uc_priv->format = VIDEO_RGBA8888;
break;
default:
debug("Unsupported mode\n");
return -EINVAL;
}
video_set_flush_dcache(dev, true);
debug("Video: WIDTH[%d]xHEIGHT[%d]xBPP[%d/%d] -- line length %d\n", uc_priv->xsize,
uc_priv->ysize, uc_priv->bpix, VNBYTES(uc_priv->bpix), uc_priv->line_length);
enable_gfx_buffers(dev, 1);
avbuf_video_select(dev, AVBUF_VIDSTREAM1_NONE, AVBUF_VIDSTREAM2_NONLIVE_GFX);
config_gfx_pipeline(dev);
config_output_video(dev);
ret = zynqmp_dpsub_init(dev);
if (ret)
return ret;
/* Populate the FrameBuffer structure with the frame attributes */
priv->frame_buffer.stride = uc_priv->line_length;
priv->frame_buffer.line_size = priv->frame_buffer.stride;
priv->frame_buffer.size = priv->frame_buffer.line_size * uc_priv->ysize;
ret = dp_tx_run(dev);
if (ret)
return ret;
return dpdma_setup(dev);
}
static int zynqmp_dpsub_bind(struct udevice *dev)
{
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
/* This is maximum size to allocate - it depends on BPP setting */
plat->size = WIDTH * HEIGHT * 4;
/* plat->align is not defined that's why 1MB alignment is used */
/*
* plat->base can be used for allocating own location for FB
* if not defined then it is allocated by u-boot itself
*/
return 0;
}
static int zynqmp_dpsub_of_to_plat(struct udevice *dev)
{
struct zynqmp_dpsub_priv *priv = dev_get_priv(dev);
struct resource res;
int ret;
ret = dev_read_resource_byname(dev, "dp", &res);
if (ret)
return ret;
priv->base_addr = res.start;
return 0;
}
static const struct udevice_id zynqmp_dpsub_ids[] = {
{ .compatible = "xlnx,zynqmp-dpsub-1.7" },
{ }
};
U_BOOT_DRIVER(zynqmp_dpsub_video) = {
.name = "zynqmp_dpsub_video",
.id = UCLASS_VIDEO,
.of_match = zynqmp_dpsub_ids,
.plat_auto = sizeof(struct video_uc_plat),
.bind = zynqmp_dpsub_bind,
.probe = zynqmp_dpsub_probe,
.priv_auto = sizeof(struct zynqmp_dpsub_priv),
.of_to_plat = zynqmp_dpsub_of_to_plat,
};
|