Ubuntu Pastebin

Paste from ogra at Wed, 21 Jun 2017 12:39:50 +0000

Download as text
   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
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
diff --git a/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts b/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
index b7ca916..ea88d1c 100644
--- a/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
+++ b/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
@@ -58,6 +58,7 @@
 	aliases {
 		serial0 = &uart0;
 		/* ethernet0 is the H3 emac, defined in sun8i-h3.dtsi */
+		ethernet0 = &emac;
 		ethernet1 = &xr819;
 	};
 
@@ -100,6 +101,17 @@
 	status = "okay";
 };
 
+&emac {
+		phy = <&phy1>;
+		phy-mode = "mii";
+		allwinner,use-internal-phy;
+		allwinner,leds-active-low;
+		status = "okay";
+		phy1: ethernet-phy@1 {
+			reg = <1>;
+		};
+};
+
 &mmc0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&mmc0_pins_a>;
diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 27780b9..dd4c697 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -140,6 +140,30 @@
 		#size-cells = <1>;
 		ranges;
 
+		emac: ethernet@1c30000 {
+			compatible = "allwinner,sun8i-h3-emac";
+			syscon = <&syscon>;
+			reg = <0x01c30000 0x104>;
+			interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
+			resets = <&ccu RST_BUS_EMAC>;
+			reset-names = "ahb";
+			clocks = <&ccu CLK_BUS_EMAC>;
+			clock-names = "ahb";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+
+			mdio: mdio {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				int_mii_phy: ethernet-phy@1 {
+					reg = <1>;
+					clocks = <&ccu CLK_BUS_EPHY>;
+					resets = <&ccu RST_BUS_EPHY>;
+				};
+			};
+		};
+
 		dma: dma-controller@01c02000 {
 			compatible = "allwinner,sun8i-h3-dma";
 			reg = <0x01c02000 0x1000>;
@@ -328,6 +352,16 @@
 			interrupt-controller;
 			#interrupt-cells = <3>;
 
+			emac_rgmii_pins: emac0@0 {
+				pins = "PD0", "PD1", "PD2", "PD3",
+				       "PD4", "PD5", "PD7",
+				       "PD8", "PD9", "PD10",
+				       "PD12", "PD13", "PD15",
+				       "PD16", "PD17";
+				function = "emac";
+				drive-strength = <40>;
+			};
+
 			i2c0_pins: i2c0 {
 				pins = "PA11", "PA12";
 				function = "i2c0";
@@ -456,6 +490,12 @@
 			#size-cells = <0>;
 		};
 
+		syscon: syscon@01c00000 {
+			compatible = "syscon",
+				     "allwinner,sun8i-h3-system-controller";
+			reg = <0x01c00000 0x1000>;
+		};
+
 		wdt0: watchdog@01c20ca0 {
 			compatible = "allwinner,sun6i-a31-wdt";
 			reg = <0x01c20ca0 0x20>;
diff --git a/debian.master/config/amd64/config.common.amd64 b/debian.master/config/amd64/config.common.amd64
index ec9b516..a8a95ad 100644
--- a/debian.master/config/amd64/config.common.amd64
+++ b/debian.master/config/amd64/config.common.amd64
@@ -71,6 +71,7 @@ CONFIG_CMA=y
 CONFIG_CMDLINE_PARTITION=y
 CONFIG_CONFIGFS_FS=m
 CONFIG_CRAMFS=m
+CONFIG_CRYPTO_DES=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is not set
 # CONFIG_CXL_AFU_DRIVER_OPS is not set
 # CONFIG_CXL_BASE is not set
@@ -267,6 +268,7 @@ CONFIG_NET_VENDOR_WIZNET=y
 CONFIG_NEW_LEDS=y
 CONFIG_NFC=m
 CONFIG_NFP=m
+CONFIG_NLS_ISO8859_1=m
 CONFIG_NODES_SHIFT=10
 CONFIG_NOP_USB_XCEIV=m
 CONFIG_NOZOMI=m
@@ -335,6 +337,7 @@ CONFIG_REISERFS_FS=m
 # CONFIG_RESET_BERLIN is not set
 CONFIG_RESET_CONTROLLER=y
 # CONFIG_RESET_MESON is not set
+# CONFIG_RESET_SUNXI is not set
 CONFIG_RFKILL=y
 CONFIG_ROMFS_FS=m
 CONFIG_RTC_DRV_CMOS=y
@@ -433,6 +436,7 @@ CONFIG_SRAM=y
 CONFIG_SSB=m
 CONFIG_STAGING=y
 # CONFIG_STANDALONE is not set
+# CONFIG_SUNXI_SRAM is not set
 CONFIG_SUN_PARTITION=y
 CONFIG_SYSV68_PARTITION=y
 CONFIG_SYSV_FS=m
diff --git a/debian.master/config/arm64/config.common.arm64 b/debian.master/config/arm64/config.common.arm64
index cac69d8..c3c0ac0 100644
--- a/debian.master/config/arm64/config.common.arm64
+++ b/debian.master/config/arm64/config.common.arm64
@@ -32,6 +32,7 @@ CONFIG_ARCH_PHYS_ADDR_T_64BIT=y
 # CONFIG_ARCH_ROCKCHIP is not set
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_SPARSEMEM_DEFAULT=y
+# CONFIG_ARCH_SUNXI is not set
 # CONFIG_ARCH_TEGRA is not set
 # CONFIG_ARCH_UNIPHIER is not set
 # CONFIG_ARCH_WANTS_UBSAN_NO_NULL is not set
@@ -80,6 +81,7 @@ CONFIG_CMDLINE_PARTITION=y
 CONFIG_CONFIGFS_FS=m
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_CRAMFS=m
+CONFIG_CRYPTO_DES=m
 CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_IMX is not set
 # CONFIG_CXL_AFU_DRIVER_OPS is not set
@@ -286,6 +288,7 @@ CONFIG_NET_VENDOR_WIZNET=y
 CONFIG_NEW_LEDS=y
 CONFIG_NFC=m
 CONFIG_NFP=m
+CONFIG_NLS_ISO8859_1=m
 CONFIG_NODES_SHIFT=6
 CONFIG_NOP_USB_XCEIV=m
 CONFIG_NOZOMI=m
@@ -354,6 +357,7 @@ CONFIG_REISERFS_FS=m
 CONFIG_RESET_BERLIN=y
 CONFIG_RESET_CONTROLLER=y
 # CONFIG_RESET_MESON is not set
+# CONFIG_RESET_SUNXI is not set
 CONFIG_RFKILL=y
 CONFIG_ROMFS_FS=m
 CONFIG_RTC_DRV_PCF8523=m
@@ -453,6 +457,7 @@ CONFIG_SRAM=y
 CONFIG_SSB=m
 CONFIG_STAGING=y
 CONFIG_STANDALONE=y
+# CONFIG_SUNXI_SRAM is not set
 CONFIG_SUN_PARTITION=y
 CONFIG_SYSV68_PARTITION=y
 CONFIG_SYSV_FS=m
diff --git a/debian.master/config/armhf/config.common.armhf b/debian.master/config/armhf/config.common.armhf
index ac58566..4ecdfcf 100644
--- a/debian.master/config/armhf/config.common.armhf
+++ b/debian.master/config/armhf/config.common.armhf
@@ -275,7 +275,6 @@ CONFIG_NOZOMI=m
 CONFIG_NR_CPUS=4
 CONFIG_NTB=m
 # CONFIG_NTFS_RW is not set
-CONFIG_NVMEM=m
 CONFIG_N_GSM=m
 CONFIG_OF=y
 CONFIG_OMFS_FS=m
@@ -384,7 +383,6 @@ CONFIG_SCSI_WD719X=m
 CONFIG_SECURITY_SELINUX_BOOTPARAM=y
 CONFIG_SENSORS_SCH56XX_COMMON=m
 CONFIG_SERIAL_8250=y
-CONFIG_SERIAL_8250_DW=m
 # CONFIG_SERIAL_8250_FINTEK is not set
 CONFIG_SERIAL_8250_FSL=y
 CONFIG_SERIAL_ALTERA_JTAGUART=m
diff --git a/debian.master/config/armhf/config.flavour.generic b/debian.master/config/armhf/config.flavour.generic
index 37309d3..11f7f0a 100644
--- a/debian.master/config/armhf/config.flavour.generic
+++ b/debian.master/config/armhf/config.flavour.generic
@@ -5,21 +5,27 @@ CONFIG_ARCH_MXC=y
 CONFIG_ARCH_OMAP3=y
 CONFIG_ARCH_OMAP4=y
 # CONFIG_ARCH_PHYS_ADDR_T_64BIT is not set
+CONFIG_ARCH_SUNXI=y
 CONFIG_ARCH_TEGRA=y
 CONFIG_ARM_ATAG_DTB_COMPAT=y
 # CONFIG_ARM_HIGHBANK_CPUIDLE is not set
 # CONFIG_ARM_LPAE is not set
+CONFIG_CRYPTO_DES=y
 CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC=m
 CONFIG_FB_CFB_REV_PIXELS_IN_BYTE=y
 CONFIG_FORCE_MAX_ZONEORDER=12
 # CONFIG_HUGETLB_PAGE is not set
 # CONFIG_IOMMU_IO_PGTABLE_LPAE is not set
+CONFIG_NLS_ISO8859_1=y
+CONFIG_NVMEM=y
 CONFIG_PGTABLE_LEVELS=2
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_PWM_TIECAP=m
 CONFIG_PWM_TIEHRPWM=m
 CONFIG_REGULATOR_TWL4030=y
+CONFIG_RESET_SUNXI=y
 CONFIG_RTC_DRV_PCF8523=y
+CONFIG_SERIAL_8250_DW=y
 CONFIG_SERIAL_MCTRL_GPIO=y
 CONFIG_SND_EDMA_SOC=m
 # CONFIG_SND_EMU10K1_SEQ is not set
@@ -28,3 +34,4 @@ CONFIG_SND_SOC_IMX_AUDMUX=y
 CONFIG_SND_SOC_RT5677_SPI=m
 CONFIG_SND_SOC_SGTL5000=y
 CONFIG_SOC_AM33XX=y
+CONFIG_SUNXI_SRAM=y
diff --git a/debian.master/config/armhf/config.flavour.generic-lpae b/debian.master/config/armhf/config.flavour.generic-lpae
index e8d2408..c48605b 100644
--- a/debian.master/config/armhf/config.flavour.generic-lpae
+++ b/debian.master/config/armhf/config.flavour.generic-lpae
@@ -5,21 +5,27 @@
 # CONFIG_ARCH_OMAP3 is not set
 # CONFIG_ARCH_OMAP4 is not set
 CONFIG_ARCH_PHYS_ADDR_T_64BIT=y
+# CONFIG_ARCH_SUNXI is not set
 # CONFIG_ARCH_TEGRA is not set
 # CONFIG_ARM_ATAG_DTB_COMPAT is not set
 CONFIG_ARM_HIGHBANK_CPUIDLE=y
 CONFIG_ARM_LPAE=y
+CONFIG_CRYPTO_DES=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is not set
 # CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
 CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_HUGETLB_PAGE=y
 CONFIG_IOMMU_IO_PGTABLE_LPAE=y
+CONFIG_NLS_ISO8859_1=m
+CONFIG_NVMEM=m
 CONFIG_PGTABLE_LEVELS=3
 CONFIG_PHYS_ADDR_T_64BIT=y
 # CONFIG_PWM_TIECAP is not set
 # CONFIG_PWM_TIEHRPWM is not set
 CONFIG_REGULATOR_TWL4030=m
+# CONFIG_RESET_SUNXI is not set
 CONFIG_RTC_DRV_PCF8523=m
+CONFIG_SERIAL_8250_DW=m
 CONFIG_SERIAL_MCTRL_GPIO=m
 # CONFIG_SND_EDMA_SOC is not set
 CONFIG_SND_EMU10K1_SEQ=m
@@ -28,3 +34,4 @@ CONFIG_SND_SOC_IMX_AUDMUX=m
 # CONFIG_SND_SOC_RT5677_SPI is not set
 CONFIG_SND_SOC_SGTL5000=m
 # CONFIG_SOC_AM33XX is not set
+# CONFIG_SUNXI_SRAM is not set
diff --git a/debian.master/config/config.common.ubuntu b/debian.master/config/config.common.ubuntu
index 9831fa8..720865ba 100644
--- a/debian.master/config/config.common.ubuntu
+++ b/debian.master/config/config.common.ubuntu
@@ -212,6 +212,7 @@ CONFIG_AHCI_CEVA=m
 CONFIG_AHCI_IMX=y
 CONFIG_AHCI_MVEBU=m
 CONFIG_AHCI_QORIQ=m
+CONFIG_AHCI_SUNXI=y
 CONFIG_AHCI_TEGRA=m
 CONFIG_AHCI_XGENE=m
 CONFIG_AIC79XX_CMDS_PER_DEVICE=32
@@ -444,7 +445,6 @@ CONFIG_ARCH_SPARSEMEM_ENABLE=y
 CONFIG_ARCH_SPRD=y
 # CONFIG_ARCH_STI is not set
 CONFIG_ARCH_STRATIX10=y
-# CONFIG_ARCH_SUNXI is not set
 CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=y
 CONFIG_ARCH_SUPPORTS_BIG_ENDIAN=y
 CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
@@ -1168,6 +1168,7 @@ CONFIG_CAN_SJA1000_PLATFORM=m
 CONFIG_CAN_SLCAN=m
 CONFIG_CAN_SOFTING=m
 CONFIG_CAN_SOFTING_CS=m
+CONFIG_CAN_SUN4I=m
 CONFIG_CAN_TI_HECC=m
 CONFIG_CAN_TSCAN1=m
 CONFIG_CAN_VCAN=m
@@ -1687,7 +1688,6 @@ CONFIG_CRYPTO_CRYPTD=m
 CONFIG_CRYPTO_CTR=y
 CONFIG_CRYPTO_CTS=y
 CONFIG_CRYPTO_DEFLATE=m
-CONFIG_CRYPTO_DES=m
 CONFIG_CRYPTO_DES3_EDE_X86_64=m
 CONFIG_CRYPTO_DES_S390=m
 CONFIG_CRYPTO_DEV_BCM_SPU=m
@@ -1736,6 +1736,7 @@ CONFIG_CRYPTO_DEV_QCE=m
 # CONFIG_CRYPTO_DEV_ROCKCHIP is not set
 CONFIG_CRYPTO_DEV_S5P=m
 CONFIG_CRYPTO_DEV_SAHARA=m
+CONFIG_CRYPTO_DEV_SUN4I_SS=y
 CONFIG_CRYPTO_DEV_VIRTIO=m
 CONFIG_CRYPTO_DEV_VMX=y
 CONFIG_CRYPTO_DEV_VMX_ENCRYPT=m
@@ -2033,6 +2034,8 @@ CONFIG_DMA_ENGINE_RAID=y
 CONFIG_DMA_OF=y
 CONFIG_DMA_OMAP=y
 CONFIG_DMA_SHARED_BUFFER=y
+CONFIG_DMA_SUN4I=y
+CONFIG_DMA_SUN6I=y
 CONFIG_DMA_VIRT_OPS=y
 CONFIG_DMI=y
 CONFIG_DMIID=y
@@ -2195,6 +2198,7 @@ CONFIG_DRM_SHMOBILE=m
 CONFIG_DRM_SII902X=m
 CONFIG_DRM_SIL_SII8620=m
 # CONFIG_DRM_STI is not set
+CONFIG_DRM_SUN4I=m
 CONFIG_DRM_TEGRA=m
 # CONFIG_DRM_TEGRA_DEBUG is not set
 CONFIG_DRM_TEGRA_STAGING=y
@@ -2416,6 +2420,7 @@ CONFIG_DWMAC_GENERIC=m
 CONFIG_DWMAC_IPQ806X=m
 CONFIG_DWMAC_MESON=m
 CONFIG_DWMAC_ROCKCHIP=m
+CONFIG_DWMAC_SUNXI=m
 CONFIG_DW_APB_ICTL=y
 CONFIG_DW_APB_TIMER=y
 CONFIG_DW_APB_TIMER_OF=y
@@ -3592,6 +3597,7 @@ CONFIG_I2C_SIS96X=m
 CONFIG_I2C_SLAVE_EEPROM=m
 CONFIG_I2C_SMBUS=m
 CONFIG_I2C_STUB=m
+CONFIG_I2C_SUN6I_P2WI=y
 CONFIG_I2C_TAOS_EVM=m
 CONFIG_I2C_TEGRA=m
 CONFIG_I2C_THUNDERX=m
@@ -4185,6 +4191,7 @@ CONFIG_IR_SHARP_DECODER=m
 CONFIG_IR_SONY_DECODER=m
 CONFIG_IR_SPI=m
 CONFIG_IR_STREAMZAP=m
+CONFIG_IR_SUNXI=m
 CONFIG_IR_TTUSBIR=m
 CONFIG_IR_WINBOND_CIR=m
 CONFIG_IR_XMP_DECODER=m
@@ -4373,6 +4380,7 @@ CONFIG_KEYBOARD_SH_KEYSC=m
 CONFIG_KEYBOARD_SNVS_PWRKEY=m
 CONFIG_KEYBOARD_STMPE=m
 CONFIG_KEYBOARD_STOWAWAY=m
+CONFIG_KEYBOARD_SUN4I_LRADC=y
 CONFIG_KEYBOARD_SUNKBD=m
 CONFIG_KEYBOARD_TC3589X=m
 CONFIG_KEYBOARD_TCA6416=m
@@ -4669,6 +4677,12 @@ CONFIG_MACH_MVEBU_V7=y
 # CONFIG_MACH_OMAP3517EVM is not set
 CONFIG_MACH_OMAP3_PANDORA=y
 CONFIG_MACH_OMAP_GENERIC=y
+CONFIG_MACH_SUN4I=y
+CONFIG_MACH_SUN5I=y
+CONFIG_MACH_SUN6I=y
+CONFIG_MACH_SUN7I=y
+CONFIG_MACH_SUN8I=y
+CONFIG_MACH_SUN9I=y
 CONFIG_MACINTOSH_DRIVERS=y
 CONFIG_MACSEC=m
 CONFIG_MACVLAN=m
@@ -4744,6 +4758,7 @@ CONFIG_MDIO_CAVIUM=m
 CONFIG_MDIO_GPIO=m
 CONFIG_MDIO_HISI_FEMAC=m
 CONFIG_MDIO_OCTEON=m
+CONFIG_MDIO_SUN4I=y
 CONFIG_MDIO_THUNDER=m
 CONFIG_MDIO_XGENE=m
 CONFIG_MDM_GCC_9615=m
@@ -4849,6 +4864,7 @@ CONFIG_MFD_88PM800=m
 CONFIG_MFD_88PM805=m
 CONFIG_MFD_88PM860X=y
 CONFIG_MFD_AAT2870_CORE=y
+# CONFIG_MFD_AC100 is not set
 CONFIG_MFD_ACT8945A=m
 CONFIG_MFD_ARIZONA=y
 CONFIG_MFD_ARIZONA_I2C=m
@@ -4860,6 +4876,7 @@ CONFIG_MFD_ATMEL_FLEXCOM=m
 CONFIG_MFD_ATMEL_HLCDC=m
 CONFIG_MFD_AXP20X=m
 CONFIG_MFD_AXP20X_I2C=m
+# CONFIG_MFD_AXP20X_RSB is not set
 CONFIG_MFD_BCM590XX=m
 CONFIG_MFD_CPCAP=m
 CONFIG_MFD_CROS_EC=m
@@ -4918,6 +4935,7 @@ CONFIG_MFD_SM501_GPIO=y
 CONFIG_MFD_SMSC=y
 CONFIG_MFD_SPMI_PMIC=m
 CONFIG_MFD_STMPE=y
+CONFIG_MFD_SUN6I_PRCM=y
 CONFIG_MFD_T7L66XB=y
 CONFIG_MFD_TC3589X=y
 CONFIG_MFD_TC6387XB=y
@@ -5060,6 +5078,7 @@ CONFIG_MMC_SDHI=m
 CONFIG_MMC_SDRICOH_CS=m
 CONFIG_MMC_SH_MMCIF=m
 CONFIG_MMC_SPI=m
+CONFIG_MMC_SUNXI=y
 # CONFIG_MMC_TEST is not set
 CONFIG_MMC_TIFM_SD=m
 CONFIG_MMC_TMIO=m
@@ -5249,6 +5268,7 @@ CONFIG_MTD_NAND_PLATFORM=m
 CONFIG_MTD_NAND_PXA3xx=m
 CONFIG_MTD_NAND_QCOM=m
 CONFIG_MTD_NAND_RICOH=m
+# CONFIG_MTD_NAND_SUNXI is not set
 CONFIG_MTD_NAND_TANGO=m
 CONFIG_MTD_NAND_TMIO=m
 # CONFIG_MTD_NAND_VF610_NFC is not set
@@ -5600,6 +5620,7 @@ CONFIG_NET_TULIP=y
 CONFIG_NET_UDP_TUNNEL=m
 CONFIG_NET_VENDOR_8390=y
 CONFIG_NET_VENDOR_ALACRITECH=y
+CONFIG_NET_VENDOR_ALLWINNER=y
 CONFIG_NET_VENDOR_AMAZON=y
 CONFIG_NET_VENDOR_AQUANTIA=y
 CONFIG_NET_VENDOR_AURORA=y
@@ -5831,7 +5852,6 @@ CONFIG_NLS_CODEPAGE_936=m
 CONFIG_NLS_CODEPAGE_949=m
 CONFIG_NLS_CODEPAGE_950=m
 CONFIG_NLS_DEFAULT="utf8"
-CONFIG_NLS_ISO8859_1=m
 CONFIG_NLS_ISO8859_13=m
 CONFIG_NLS_ISO8859_14=m
 CONFIG_NLS_ISO8859_15=m
@@ -5896,6 +5916,7 @@ CONFIG_NVEC_POWER=m
 CONFIG_NVM=y
 CONFIG_NVMEM_BCM_OCOTP=m
 CONFIG_NVMEM_IMX_OCOTP=m
+CONFIG_NVMEM_SUNXI_SID=y
 # CONFIG_NVMEM_VF610_OCOTP is not set
 CONFIG_NVME_CORE=m
 CONFIG_NVME_FABRICS=m
@@ -6248,6 +6269,8 @@ CONFIG_PHY_ROCKCHIP_PCIE=m
 CONFIG_PHY_ROCKCHIP_TYPEC=m
 CONFIG_PHY_ROCKCHIP_USB=m
 CONFIG_PHY_SAMSUNG_USB2=m
+CONFIG_PHY_SUN4I_USB=y
+CONFIG_PHY_SUN9I_USB=y
 CONFIG_PHY_TEGRA_XUSB=m
 CONFIG_PHY_TUSB1210=m
 CONFIG_PHY_XGENE=y
@@ -6326,7 +6349,22 @@ CONFIG_PINCTRL_SAMSUNG=y
 CONFIG_PINCTRL_SH_PFC=y
 CONFIG_PINCTRL_SH_PFC_GPIO=y
 CONFIG_PINCTRL_SINGLE=y
+CONFIG_PINCTRL_SUN4I_A10=y
+CONFIG_PINCTRL_SUN5I=y
+CONFIG_PINCTRL_SUN6I_A31=y
+CONFIG_PINCTRL_SUN6I_A31_R=y
+CONFIG_PINCTRL_SUN7I_A20=y
+CONFIG_PINCTRL_SUN8I_A23=y
+CONFIG_PINCTRL_SUN8I_A23_R=y
+CONFIG_PINCTRL_SUN8I_A33=y
+CONFIG_PINCTRL_SUN8I_A83T=y
+CONFIG_PINCTRL_SUN8I_H3=y
+CONFIG_PINCTRL_SUN8I_H3_R=y
+CONFIG_PINCTRL_SUN8I_V3S=y
+CONFIG_PINCTRL_SUN9I_A80=y
+CONFIG_PINCTRL_SUN9I_A80_R=y
 CONFIG_PINCTRL_SUNRISEPOINT=m
+CONFIG_PINCTRL_SUNXI=y
 CONFIG_PINCTRL_SX150X=y
 CONFIG_PINCTRL_TEGRA=y
 CONFIG_PINCTRL_TEGRA114=y
@@ -6572,6 +6610,7 @@ CONFIG_PWM_RENESAS_TPU=m
 CONFIG_PWM_ROCKCHIP=m
 CONFIG_PWM_SAMSUNG=m
 CONFIG_PWM_STMPE=y
+CONFIG_PWM_SUN4I=y
 CONFIG_PWM_SYSFS=y
 CONFIG_PWM_TEGRA=m
 CONFIG_PWM_TIPWMSS=y
@@ -6875,7 +6914,6 @@ CONFIG_RESET_HISI=y
 # CONFIG_RESET_PISTACHIO is not set
 # CONFIG_RESET_SOCFPGA is not set
 # CONFIG_RESET_STM32 is not set
-# CONFIG_RESET_SUNXI is not set
 # CONFIG_RESET_TEGRA_BPMP is not set
 CONFIG_RESET_UNIPHIER=m
 # CONFIG_RESET_ZYNQ is not set
@@ -7069,6 +7107,8 @@ CONFIG_RTC_DRV_S3C=y
 CONFIG_RTC_DRV_S5M=m
 CONFIG_RTC_DRV_SNVS=m
 CONFIG_RTC_DRV_STK17TA8=m
+CONFIG_RTC_DRV_SUN6I=y
+CONFIG_RTC_DRV_SUNXI=y
 CONFIG_RTC_DRV_TEGRA=m
 # CONFIG_RTC_DRV_TEST is not set
 CONFIG_RTC_DRV_TPS6586X=m
@@ -7612,6 +7652,7 @@ CONFIG_SERIO_PCIPS2=m
 CONFIG_SERIO_PS2MULT=m
 CONFIG_SERIO_RAW=m
 CONFIG_SERIO_SERPORT=m
+# CONFIG_SERIO_SUN4I_PS2 is not set
 CONFIG_SERIO_XILINX_XPS_PS2=m
 CONFIG_SFC_FALCON_MTD=y
 CONFIG_SFC_MCDI_LOGGING=y
@@ -8112,6 +8153,11 @@ CONFIG_SND_SST_ATOM_HIFI2_PLATFORM=m
 CONFIG_SND_SST_IPC=m
 CONFIG_SND_SST_IPC_ACPI=m
 CONFIG_SND_SST_IPC_PCI=m
+CONFIG_SND_SUN4I_CODEC=m
+CONFIG_SND_SUN4I_I2S=m
+CONFIG_SND_SUN4I_SPDIF=m
+CONFIG_SND_SUN8I_CODEC=m
+CONFIG_SND_SUN8I_CODEC_ANALOG=m
 CONFIG_SND_SUPPORT_OLD_API=y
 CONFIG_SND_TRIDENT=m
 CONFIG_SND_USB=y
@@ -8267,6 +8313,8 @@ CONFIG_SPI_SC18IS602=m
 CONFIG_SPI_SH_HSPI=m
 CONFIG_SPI_SH_MSIOF=m
 CONFIG_SPI_SPIDEV=m
+CONFIG_SPI_SUN4I=y
+CONFIG_SPI_SUN6I=y
 CONFIG_SPI_TEGRA114=m
 CONFIG_SPI_TEGRA20_SFLASH=m
 CONFIG_SPI_TEGRA20_SLINK=m
@@ -8347,6 +8395,18 @@ CONFIG_STRICT_MODULE_RWX=y
 CONFIG_STUB_CLK_HI6220=y
 CONFIG_STX104=m
 CONFIG_SUDMAC=m
+CONFIG_SUN4I_EMAC=m
+CONFIG_SUN4I_TIMER=y
+# CONFIG_SUN50I_A64_CCU is not set
+CONFIG_SUN5I_CCU=y
+CONFIG_SUN5I_HSTIMER=y
+CONFIG_SUN6I_A31_CCU=y
+CONFIG_SUN8I_A23_CCU=y
+CONFIG_SUN8I_A33_CCU=y
+CONFIG_SUN8I_EMAC=m
+CONFIG_SUN8I_H3_CCU=y
+CONFIG_SUN8I_V3S_CCU=y
+CONFIG_SUN9I_A80_CCU=y
 CONFIG_SUNDANCE=m
 # CONFIG_SUNDANCE_MMIO is not set
 CONFIG_SUNGEM=m
@@ -8357,7 +8417,20 @@ CONFIG_SUNRPC_DEBUG=y
 CONFIG_SUNRPC_GSS=m
 CONFIG_SUNRPC_SWAP=y
 CONFIG_SUNRPC_XPRT_RDMA=m
-# CONFIG_SUNXI_SRAM is not set
+CONFIG_SUNXI_CCU=y
+CONFIG_SUNXI_CCU_DIV=y
+CONFIG_SUNXI_CCU_FRAC=y
+CONFIG_SUNXI_CCU_GATE=y
+CONFIG_SUNXI_CCU_MP=y
+CONFIG_SUNXI_CCU_MULT=y
+CONFIG_SUNXI_CCU_MUX=y
+CONFIG_SUNXI_CCU_NK=y
+CONFIG_SUNXI_CCU_NKM=y
+CONFIG_SUNXI_CCU_NKMP=y
+CONFIG_SUNXI_CCU_NM=y
+CONFIG_SUNXI_CCU_PHASE=y
+CONFIG_SUNXI_RSB=y
+CONFIG_SUNXI_WATCHDOG=y
 CONFIG_SURFACE3_WMI=m
 CONFIG_SURFACE_3_BUTTON=m
 CONFIG_SURFACE_PRO3_BUTTON=m
@@ -8648,6 +8721,7 @@ CONFIG_TOUCHSCREEN_SILEAD=m
 CONFIG_TOUCHSCREEN_SIS_I2C=m
 CONFIG_TOUCHSCREEN_ST1232=m
 CONFIG_TOUCHSCREEN_STMPE=m
+CONFIG_TOUCHSCREEN_SUN4I=y
 CONFIG_TOUCHSCREEN_SUR40=m
 CONFIG_TOUCHSCREEN_SURFACE3_SPI=m
 CONFIG_TOUCHSCREEN_SX8654=m
@@ -9050,6 +9124,7 @@ CONFIG_USB_MUSB_DUAL_ROLE=y
 # CONFIG_USB_MUSB_GADGET is not set
 # CONFIG_USB_MUSB_HOST is not set
 CONFIG_USB_MUSB_OMAP2PLUS=m
+# CONFIG_USB_MUSB_SUNXI is not set
 CONFIG_USB_MUSB_TUSB6010=m
 CONFIG_USB_MV_U3D=m
 CONFIG_USB_MV_UDC=m
diff --git a/debian.master/config/i386/config.common.i386 b/debian.master/config/i386/config.common.i386
index fde23de..37adbe4 100644
--- a/debian.master/config/i386/config.common.i386
+++ b/debian.master/config/i386/config.common.i386
@@ -68,6 +68,7 @@ CONFIG_CMA=y
 CONFIG_CMDLINE_PARTITION=y
 CONFIG_CONFIGFS_FS=m
 CONFIG_CRAMFS=m
+CONFIG_CRYPTO_DES=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is not set
 # CONFIG_CXL_AFU_DRIVER_OPS is not set
 # CONFIG_CXL_BASE is not set
@@ -263,6 +264,7 @@ CONFIG_NET_VENDOR_WIZNET=y
 CONFIG_NEW_LEDS=y
 CONFIG_NFC=m
 CONFIG_NFP=m
+CONFIG_NLS_ISO8859_1=m
 CONFIG_NOP_USB_XCEIV=m
 CONFIG_NOZOMI=m
 CONFIG_NR_CPUS=8
@@ -329,6 +331,7 @@ CONFIG_REISERFS_FS=m
 # CONFIG_RESET_BERLIN is not set
 CONFIG_RESET_CONTROLLER=y
 # CONFIG_RESET_MESON is not set
+# CONFIG_RESET_SUNXI is not set
 CONFIG_RFKILL=y
 CONFIG_ROMFS_FS=m
 CONFIG_RTC_DRV_CMOS=y
@@ -427,6 +430,7 @@ CONFIG_SRAM=y
 CONFIG_SSB=m
 CONFIG_STAGING=y
 # CONFIG_STANDALONE is not set
+# CONFIG_SUNXI_SRAM is not set
 CONFIG_SUN_PARTITION=y
 CONFIG_SYSV68_PARTITION=y
 CONFIG_SYSV_FS=m
diff --git a/debian.master/config/ppc64el/config.common.ppc64el b/debian.master/config/ppc64el/config.common.ppc64el
index 8aedb32..e68a207 100644
--- a/debian.master/config/ppc64el/config.common.ppc64el
+++ b/debian.master/config/ppc64el/config.common.ppc64el
@@ -68,6 +68,7 @@ CONFIG_CMM=m
 CONFIG_CONFIGFS_FS=m
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_CRAMFS=m
+CONFIG_CRYPTO_DES=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is not set
 CONFIG_CXL_AFU_DRIVER_OPS=y
 CONFIG_CXL_BASE=y
@@ -269,6 +270,7 @@ CONFIG_NET_VENDOR_WIZNET=y
 CONFIG_NEW_LEDS=y
 CONFIG_NFC=m
 CONFIG_NFP=m
+CONFIG_NLS_ISO8859_1=m
 CONFIG_NODES_SHIFT=8
 CONFIG_NOP_USB_XCEIV=m
 CONFIG_NOZOMI=m
@@ -333,6 +335,7 @@ CONFIG_REISERFS_FS=m
 # CONFIG_RESET_BERLIN is not set
 CONFIG_RESET_CONTROLLER=y
 # CONFIG_RESET_MESON is not set
+# CONFIG_RESET_SUNXI is not set
 CONFIG_RFKILL=y
 CONFIG_ROMFS_FS=m
 CONFIG_RTC_DRV_CMOS=m
@@ -430,6 +433,7 @@ CONFIG_SRAM=y
 CONFIG_SSB=m
 CONFIG_STAGING=y
 CONFIG_STANDALONE=y
+# CONFIG_SUNXI_SRAM is not set
 CONFIG_SUN_PARTITION=y
 CONFIG_SYSV68_PARTITION=y
 CONFIG_SYSV_FS=m
diff --git a/debian.master/config/s390x/config.common.s390x b/debian.master/config/s390x/config.common.s390x
index 39f4e8a..f6d9e7a 100644
--- a/debian.master/config/s390x/config.common.s390x
+++ b/debian.master/config/s390x/config.common.s390x
@@ -61,6 +61,7 @@ CONFIG_CMM=y
 CONFIG_CONFIGFS_FS=y
 CONFIG_CPU_BIG_ENDIAN=y
 # CONFIG_CRAMFS is not set
+CONFIG_CRYPTO_DES=m
 # CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC is not set
 # CONFIG_CXL_AFU_DRIVER_OPS is not set
 # CONFIG_CXL_BASE is not set
@@ -234,6 +235,7 @@ CONFIG_MFD_CORE=m
 # CONFIG_NEW_LEDS is not set
 # CONFIG_NFC is not set
 # CONFIG_NFP is not set
+CONFIG_NLS_ISO8859_1=m
 CONFIG_NODES_SHIFT=4
 # CONFIG_NOZOMI is not set
 CONFIG_NR_CPUS=256
@@ -362,6 +364,7 @@ CONFIG_SERIAL_CORE=m
 # CONFIG_SSB is not set
 # CONFIG_STAGING is not set
 CONFIG_STANDALONE=y
+# CONFIG_SUNXI_SRAM is not set
 # CONFIG_SUN_PARTITION is not set
 # CONFIG_SYSV68_PARTITION is not set
 # CONFIG_SYSV_FS is not set
diff --git a/drivers/net/ethernet/allwinner/Kconfig b/drivers/net/ethernet/allwinner/Kconfig
index 47da7e7..060569c 100644
--- a/drivers/net/ethernet/allwinner/Kconfig
+++ b/drivers/net/ethernet/allwinner/Kconfig
@@ -33,4 +33,17 @@ config SUN4I_EMAC
           To compile this driver as a module, choose M here.  The module
           will be called sun4i-emac.
 
+config SUN8I_EMAC
+	tristate "Allwinner sun8i EMAC support"
+	depends on ARCH_SUNXI || COMPILE_TEST
+	depends on OF
+	select MII
+	select PHYLIB
+        ---help---
+	  This driver support the sun8i EMAC ethernet driver present on
+	  H3/A83T/A64 Allwinner SoCs.
+
+          To compile this driver as a module, choose M here.  The module
+          will be called sun8i-emac.
+
 endif # NET_VENDOR_ALLWINNER
diff --git a/drivers/net/ethernet/allwinner/Makefile b/drivers/net/ethernet/allwinner/Makefile
index 03129f7..8bd1693c 100644
--- a/drivers/net/ethernet/allwinner/Makefile
+++ b/drivers/net/ethernet/allwinner/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_SUN4I_EMAC) += sun4i-emac.o
+obj-$(CONFIG_SUN8I_EMAC) += sun8i-emac.o
diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c b/drivers/net/ethernet/allwinner/sun8i-emac.c
new file mode 100644
index 0000000..1163fee
--- /dev/null
+++ b/drivers/net/ethernet/allwinner/sun8i-emac.c
@@ -0,0 +1,2349 @@
+/*
+ * sun8i-emac driver
+ *
+ * Copyright (C) 2015-2016 Corentin LABBE <clabbe.montjoie@gmail.com>
+ *
+ * This is the driver for Allwinner Ethernet MAC found in H3/A83T/A64 SoC
+ *
+ * TODO:
+ * - MAC filtering
+ * - Jumbo frame
+ * - features rx-all (NETIF_F_RXALL_BIT)
+ * - PM runtime
+ */
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/mii.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/of_device.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/phy.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/reset.h>
+#include <linux/scatterlist.h>
+#include <linux/skbuff.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+
+#define EMAC_BASIC_CTL0	0x00
+#define EMAC_BASIC_CTL1	0x04
+#define EMAC_INT_STA	0x08
+#define EMAC_INT_EN	0x0C
+#define EMAC_TX_CTL0	0x10
+#define EMAC_TX_CTL1	0x14
+#define EMAC_TX_FLOW_CTL	0x1C
+#define EMAC_RX_CTL0	0x24
+#define EMAC_RX_CTL1	0x28
+#define EMAC_RX_FRM_FLT	0x38
+#define EMAC_MDIO_CMD	0x48
+#define EMAC_MDIO_DATA	0x4C
+#define EMAC_TX_DMA_STA	0xB0
+#define EMAC_TX_CUR_DESC	0xB4
+#define EMAC_TX_CUR_BUF	0xB8
+#define EMAC_RX_DMA_STA	0xC0
+
+#define MDIO_CMD_MII_BUSY	BIT(0)
+#define MDIO_CMD_MII_WRITE	BIT(1)
+#define MDIO_CMD_MII_PHY_REG_ADDR_MASK	GENMASK(8, 4)
+#define MDIO_CMD_MII_PHY_REG_ADDR_SHIFT	4
+#define MDIO_CMD_MII_PHY_ADDR_MASK	GENMASK(16, 12)
+#define MDIO_CMD_MII_PHY_ADDR_SHIFT	12
+
+#define EMAC_MACADDR_HI	0x50
+#define EMAC_MACADDR_LO	0x54
+
+#define EMAC_RX_DESC_LIST 0x34
+#define EMAC_TX_DESC_LIST 0x20
+
+#define EMAC_RX_DO_CRC BIT(27)
+#define EMAC_RX_STRIP_FCS BIT(28)
+
+#define LE32_BIT(x) (cpu_to_le32(BIT(x)))
+
+#define EMAC_COULD_BE_USED_BY_DMA LE32_BIT(31)
+
+/* Used in RX_CTL1*/
+#define EMAC_RX_MD		BIT(1)
+#define EMAC_RX_DMA_EN	BIT(30)
+#define EMAC_RX_DMA_START	BIT(31)
+
+/* Used in TX_CTL1*/
+#define EMAC_TX_MD		BIT(1)
+#define EMAC_TX_NEXT_FRM	BIT(2)
+#define EMAC_TX_DMA_EN	BIT(30)
+#define EMAC_TX_DMA_START	BIT(31)
+
+/* Used in RX_CTL0 */
+#define EMAC_RX_RECEIVER_EN		BIT(31)
+#define EMAC_RX_FLOW_CTL_EN		BIT(16)
+/* Used in TX_CTL0 */
+#define EMAC_TX_TRANSMITTER_EN	BIT(31)
+
+/* Used in EMAC_TX_FLOW_CTL */
+#define EMAC_TX_FLOW_CTL_EN		BIT(0)
+
+/* Used in EMAC_RX_FRM_FLT */
+#define EMAC_FRM_FLT_RXALL		BIT(0)
+#define EMAC_FRM_FLT_CTL		BIT(13)
+#define EMAC_FRM_FLT_MULTICAST		BIT(16)
+
+/* Mac address */
+#define EMAC_MAX_MACADDR		8
+#define MAC_ADDR_TYPE_DST BIT(31)
+
+/* Used in BASIC_CTL0 */
+#define EMAC_BCTL0_FD			BIT(0)
+#define EMAC_BCTL0_LOOPBACK		BIT(1)
+#define EMAC_BCTL0_SPEED_10		2
+#define EMAC_BCTL0_SPEED_100		3
+#define EMAC_BCTL0_SPEED_MASK	GENMASK(3, 2)
+#define EMAC_BCTL0_SPEED_SHIFT	2
+
+#define EMAC_FLOW_RX 1
+#define EMAC_FLOW_TX 2
+
+#define EMAC_TX_INT		BIT(0)
+#define EMAC_TX_DMA_STOP_INT	BIT(1)
+#define EMAC_TX_BUF_UA_INT	BIT(2)
+#define EMAC_TX_TIMEOUT_INT	BIT(3)
+#define EMAC_TX_UNDERFLOW_INT	BIT(4)
+#define EMAC_TX_EARLY_INT	BIT(5)
+#define EMAC_RX_INT		BIT(8)
+#define EMAC_RX_BUF_UA_INT	BIT(9)
+#define EMAC_RX_DMA_STOP_INT	BIT(10)
+#define EMAC_RX_TIMEOUT_INT	BIT(11)
+#define EMAC_RX_OVERFLOW_INT	BIT(12)
+#define EMAC_RX_EARLY_INT	BIT(13)
+#define EMAC_RGMII_STA_INT	BIT(16)
+
+/* Bits used in frame RX status */
+#define EMAC_DSC_RX_PAYLOAD_ERR		BIT(0)
+#define EMAC_DSC_RX_CRC_ERR		BIT(1)
+#define EMAC_DSC_RX_PHY_ERR		BIT(3)
+#define EMAC_DSC_RX_LENGTH_ERR		BIT(4)
+#define EMAC_DSC_RX_COL_ERR		BIT(6)
+#define EMAC_DSC_RX_HEADER_ERR		BIT(7)
+#define EMAC_DSC_RX_LAST		BIT(8)
+#define EMAC_DSC_RX_FIRST		BIT(9)
+#define EMAC_DSC_RX_OVERFLOW_ERR	BIT(11)
+#define EMAC_DSC_RX_SAF_FAIL		BIT(13)
+#define EMAC_DSC_RX_NO_ENOUGTH_BUF_ERR	BIT(14)
+#define EMAC_DSC_RX_DAF_FAIL		BIT(30)
+
+/* Bits used in frame TX ctl */
+#define EMAC_MAGIC_TX_BIT		LE32_BIT(24)
+#define EMAC_TX_DO_CRC		(LE32_BIT(27) | LE32_BIT(28))
+#define EMAC_DSC_TX_FIRST		LE32_BIT(29)
+#define EMAC_DSC_TX_LAST		LE32_BIT(30)
+#define EMAC_WANT_INT			LE32_BIT(31)
+/* Bits used in frame TX status */
+#define EMAC_DSC_TX_UNDERFLOW_ERR	BIT(1)
+#define EMAC_DSC_TX_DEFER_ERR		BIT(2)
+#define EMAC_DSC_TX_COL_NB		GENMASK(6, 3)
+#define EMAC_DSC_TX_COL_ERR_1		BIT(8)
+#define EMAC_DSC_TX_COL_ERR_0		BIT(9)
+#define EMAC_DSC_TX_CRS_ERR		BIT(10)
+#define EMAC_DSC_TX_PAYLOAD_ERR		BIT(12)
+#define EMAC_DSC_TX_LENGTH_ERR		BIT(14)
+#define EMAC_DSC_TX_HEADER_ERR		BIT(16)
+
+/* struct emac_variant - Describe an emac variant of sun8i-emac
+ * @default_syscon_value: Default value of the syscon EMAC register
+ * The default_syscon_value is also used for powering down the PHY
+ * @internal_phy:	which PHY type is internal
+ * @support_mii:	Does the SoC support MII
+ * @support_rmii:	Does the SoC support RMII
+ * @support_rgmii:	Does the SoC support RGMII
+ */
+struct emac_variant {
+	u32 default_syscon_value;
+	int internal_phy;
+	bool support_mii;
+	bool support_rmii;
+	bool support_rgmii;
+};
+
+static const struct emac_variant emac_variant_h3 = {
+	.default_syscon_value = 0x58000,
+	.internal_phy = PHY_INTERFACE_MODE_MII,
+	.support_mii = true,
+	.support_rmii = true,
+	.support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a83t = {
+	.default_syscon_value = 0,
+	.internal_phy = 0,
+	.support_mii = true,
+	.support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a64 = {
+	.default_syscon_value = 0,
+	.internal_phy = 0,
+	.support_mii = true,
+	.support_rmii = true,
+	.support_rgmii = true
+};
+
+static char const estats_str[][ETH_GSTRING_LEN] = {
+	/* errors */
+	"rx_payload_error",
+	"rx_CRC_error",
+	"rx_phy_error",
+	"rx_length_error",
+	"rx_col_error",
+	"rx_header_error",
+	"rx_overflow_error",
+	"rx_saf_error",
+	"rx_daf_error",
+	"rx_buf_error",
+	"rx_invalid_error",
+	"tx_timeout",
+	/* misc infos */
+	"tx_stop_queue",
+	"rx_dma_ua",
+	"rx_dma_stop",
+	"tx_dma_ua",
+	"tx_dma_stop",
+	"rx_hw_csum",
+	"tx_hw_csum",
+	/* interrupts */
+	"rx_int",
+	"tx_int",
+	"tx_early_int",
+	"tx_underflow_int",
+	"tx_timeout_int",
+	"rx_early_int",
+	"rx_overflow_int",
+	"rx_timeout_int",
+	"rgmii_state_int",
+	/* debug */
+	"tx_used_desc",
+	"napi_schedule",
+	"napi_underflow",
+};
+
+struct sun8i_emac_stats {
+	u64 rx_payload_error;
+	u64 rx_crc_error;
+	u64 rx_phy_error;
+	u64 rx_length_error;
+	u64 rx_col_error;
+	u64 rx_header_error;
+	u64 rx_overflow_error;
+	u64 rx_saf_fail;
+	u64 rx_daf_fail;
+	u64 rx_buf_error;
+	u64 rx_invalid_error;
+	u64 tx_timeout;
+
+	u64 tx_stop_queue;
+	u64 rx_dma_ua;
+	u64 rx_dma_stop;
+	u64 tx_dma_ua;
+	u64 tx_dma_stop;
+	u64 rx_hw_csum;
+	u64 tx_hw_csum;
+
+	u64 rx_int;
+	u64 tx_int;
+	u64 tx_early_int;
+	u64 tx_underflow_int;
+	u64 tx_timeout_int;
+	u64 rx_early_int;
+	u64 rx_overflow_int;
+	u64 rx_timeout_int;
+	u64 rgmii_state_int;
+
+	u64 tx_used_desc;
+	u64 napi_schedule;
+	u64 napi_underflow;
+};
+
+/* The datasheet said that each descriptor can transfer up to 4096bytes
+ * But latter, a register documentation reduce that value to 2048
+ * Anyway using 2048 cause strange behaviours and even BSP driver use 2047
+ */
+#define DESC_BUF_MAX 2044
+
+/* MAGIC value for knowing if a TX descriptor is available or not */
+#define DCLEAN cpu_to_le32(EMAC_DSC_TX_HEADER_ERR | EMAC_DSC_TX_LENGTH_ERR |\
+	EMAC_DSC_TX_PAYLOAD_ERR | EMAC_DSC_TX_CRS_ERR | EMAC_DSC_TX_COL_ERR_0)
+
+/* struct dma_desc - Structure of DMA descriptor used by the hardware
+ * @status:	Status of the frame written by HW, so RO for the
+ *		driver (except for BIT(31) which is R/W)
+ * @ctl:	Information on the frame written by the driver (INT, len,...)
+ * @buf_addr:	physical address of the frame data
+ * @next:	physical address of next dma_desc
+ */
+struct dma_desc {
+	__le32 status;
+	__le32 ctl;
+	__le32 buf_addr;
+	__le32 next;
+};
+
+/* Describe how data from skb are DMA mapped (used in txinfo map member) */
+#define MAP_SINGLE 1
+#define MAP_PAGE 2
+
+/* Structure for storing information about data in TX ring buffer */
+struct txinfo {
+	struct sk_buff *skb;
+	int map;
+};
+
+struct sun8i_emac_priv {
+	void __iomem *base;
+	struct regmap *regmap;
+	int irq;
+	struct device *dev;
+	struct net_device *ndev;
+	struct mii_bus *mdio;
+	struct napi_struct napi;
+	spinlock_t tx_lock;/* control the access of transmit descriptors */
+	int duplex;
+	int speed;
+	int link;
+	int phy_interface;
+	const struct emac_variant *variant;
+	struct device_node *phy_node;
+	struct device_node *mdio_node;
+	struct clk *ahb_clk;
+	struct clk *ephy_clk;
+	struct regulator *regulator;
+	bool use_internal_phy;
+
+	struct reset_control *rst_mac;
+	struct reset_control *rst_ephy;
+
+	struct dma_desc *dd_rx;
+	dma_addr_t dd_rx_phy;
+	struct dma_desc *dd_tx;
+	dma_addr_t dd_tx_phy;
+	struct sk_buff **rx_skb;
+	struct txinfo *txl;
+
+	int nbdesc_tx;
+	int nbdesc_rx;
+	int tx_slot;
+	int tx_dirty;
+	int rx_dirty;
+	struct sun8i_emac_stats estats;
+	u32 msg_enable;
+	int flow_ctrl;
+	int pause;
+};
+
+static irqreturn_t sun8i_emac_dma_interrupt(int irq, void *dev_id);
+
+static void rb_inc(int *p, const int max)
+{
+	(*p)++;
+	(*p) %= max;
+}
+
+/* Locking strategy:
+ * RX queue does not need any lock since only sun8i_emac_poll() access it.
+ * (All other RX modifiers (ringparam/ndo_stop) disable NAPI and so
+ * sun8i_emac_poll())
+ * TX queue is handled by sun8i_emac_xmit(), sun8i_emac_complete_xmit() and
+ * sun8i_emac_tx_timeout()
+ * (All other RX modifiers (ringparam/ndo_stop) disable NAPI and stop queue)
+ *
+ * sun8i_emac_xmit() could fire only once (netif_tx_lock)
+ * sun8i_emac_complete_xmit() could fire only once (called from NAPI)
+ * sun8i_emac_tx_timeout() could fire only once (netif_tx_lock) and could not
+ * race with sun8i_emac_xmit (due to netif_tx_lock) and with
+ * sun8i_emac_complete_xmit which disable NAPI.
+ *
+ * So only sun8i_emac_xmit and sun8i_emac_complete_xmit could fire at the same
+ * time.
+ * But they never could modify the same descriptors:
+ * - sun8i_emac_complete_xmit() will modify only descriptors with empty status
+ * - sun8i_emac_xmit() will modify only descriptors set to DCLEAN
+ * Proper memory barriers ensure that descriptor set to DCLEAN could not be
+ * modified latter by sun8i_emac_complete_xmit().
+ */
+
+/* Return the number of contiguous free descriptors
+ * starting from tx_slot
+ */
+static int rb_tx_numfreedesc(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	if (priv->tx_slot < priv->tx_dirty)
+		return priv->tx_dirty - priv->tx_slot;
+
+	return (priv->nbdesc_tx - priv->tx_slot) + priv->tx_dirty;
+}
+
+/* sun8i_emac_rx_skb - Allocate a skb in a DMA descriptor
+ *
+ * @ndev:	The net_device for this interface
+ * @i:		index of slot to fill
+ *
+ * Refill a DMA descriptor with a fresh skb and map it for DMA.
+ */
+static int sun8i_emac_rx_skb(struct net_device *ndev, int i)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct dma_desc *ddesc;
+	struct sk_buff *skb;
+
+	ddesc = priv->dd_rx + i;
+
+	ddesc->ctl = 0;
+
+	skb = netdev_alloc_skb_ip_align(ndev, DESC_BUF_MAX);
+	if (!skb)
+		return -ENOMEM;
+
+	/* should not happen */
+	if (unlikely(priv->rx_skb[i]))
+		dev_warn(priv->dev, "BUG: Leaking a skbuff\n");
+
+	priv->rx_skb[i] = skb;
+
+	ddesc->buf_addr = dma_map_single(priv->dev, skb->data,
+					 DESC_BUF_MAX, DMA_FROM_DEVICE);
+	if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+		dev_err(priv->dev, "ERROR: Cannot map RX buffer for DMA\n");
+		dev_kfree_skb(skb);
+		return -EFAULT;
+	}
+	/* We cannot direcly use cpu_to_le32() after dma_map_single
+	 * since dma_mapping_error use it
+	 */
+	ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+	ddesc->ctl |= cpu_to_le32(DESC_BUF_MAX);
+	/* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+	dma_wmb();
+	ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+
+	return 0;
+}
+
+static void sun8i_emac_stop_tx(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v;
+
+	netif_stop_queue(ndev);
+
+	v = readl(priv->base + EMAC_TX_CTL0);
+	/* Disable transmitter after current reception */
+	v &= ~EMAC_TX_TRANSMITTER_EN;
+	writel(v, priv->base + EMAC_TX_CTL0);
+
+	v = readl(priv->base + EMAC_TX_CTL1);
+	/* Stop TX DMA */
+	v &= ~EMAC_TX_DMA_EN;
+	writel(v, priv->base + EMAC_TX_CTL1);
+
+	/* We must be sure that all is stopped before leaving this function */
+	dma_wmb();
+}
+
+static void sun8i_emac_stop_rx(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v;
+
+	v = readl(priv->base + EMAC_RX_CTL0);
+	/* Disable receiver after current reception */
+	v &= ~EMAC_RX_RECEIVER_EN;
+	writel(v, priv->base + EMAC_RX_CTL0);
+
+	v = readl(priv->base + EMAC_RX_CTL1);
+	/* Stop RX DMA */
+	v &= ~EMAC_RX_DMA_EN;
+	writel(v, priv->base + EMAC_RX_CTL1);
+
+	/* We must be sure that all is stopped before leaving this function */
+	dma_wmb();
+}
+
+static void sun8i_emac_start_rx(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v;
+
+	v = readl(priv->base + EMAC_RX_CTL0);
+	/* Enable receiver */
+	v |= EMAC_RX_RECEIVER_EN;
+	writel(v, priv->base + EMAC_RX_CTL0);
+
+	v = readl(priv->base + EMAC_RX_CTL1);
+	v |= EMAC_RX_DMA_START;
+	v |= EMAC_RX_DMA_EN;
+	writel(v, priv->base + EMAC_RX_CTL1);
+}
+
+static void sun8i_emac_start_tx(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v;
+
+	v = readl(priv->base + EMAC_TX_CTL0);
+	v |= EMAC_TX_TRANSMITTER_EN;
+	writel(v, priv->base + EMAC_TX_CTL0);
+
+	v = readl(priv->base + EMAC_TX_CTL1);
+	v |= EMAC_TX_DMA_START;
+	v |= EMAC_TX_DMA_EN;
+	writel(v, priv->base + EMAC_TX_CTL1);
+}
+
+/* sun8i_emac_set_macaddr - Set MAC address for slot index
+ *
+ * @addr: the MAC address to set
+ * @index: The index of slot where to set address.
+ *
+ * The slot 0 is the main MAC address
+ */
+static void sun8i_emac_set_macaddr(struct sun8i_emac_priv *priv,
+				   const u8 *addr, int index)
+{
+	u32 v;
+
+	if (index > 7) {
+		dev_err(priv->dev, "Too many MAC addr\n");
+		return;
+	}
+
+	dev_info(priv->dev, "device MAC address slot %d %pM", index, addr);
+
+	v = (addr[5] << 8) | addr[4];
+	if (index > 0)
+		v |= MAC_ADDR_TYPE_DST;
+	writel(v, priv->base + EMAC_MACADDR_HI + index * 8);
+
+	v = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
+	writel(v, priv->base + EMAC_MACADDR_LO + index * 8);
+}
+
+static void sun8i_emac_set_link_mode(struct sun8i_emac_priv *priv)
+{
+	u32 v;
+
+	v = readl(priv->base + EMAC_BASIC_CTL0);
+
+	if (priv->duplex)
+		v |= EMAC_BCTL0_FD;
+	else
+		v &= ~EMAC_BCTL0_FD;
+
+	v &= ~EMAC_BCTL0_SPEED_MASK;
+
+	switch (priv->speed) {
+	case 1000:
+		break;
+	case 100:
+		v |= EMAC_BCTL0_SPEED_100 << EMAC_BCTL0_SPEED_SHIFT;
+		break;
+	case 10:
+		v |= EMAC_BCTL0_SPEED_10 << EMAC_BCTL0_SPEED_SHIFT;
+		break;
+	default:
+		dev_err(priv->dev, "Unsupported speed %d\n", priv->speed);
+		return;
+	}
+
+	writel(v, priv->base + EMAC_BASIC_CTL0);
+}
+
+static void sun8i_emac_flow_ctrl(struct sun8i_emac_priv *priv, int duplex,
+				 int fc)
+{
+	u32 flow = 0;
+
+	flow = readl(priv->base + EMAC_RX_CTL0);
+	if (fc & EMAC_FLOW_RX)
+		flow |= EMAC_RX_FLOW_CTL_EN;
+	else
+		flow &= ~EMAC_RX_FLOW_CTL_EN;
+	writel(flow, priv->base + EMAC_RX_CTL0);
+
+	flow = readl(priv->base + EMAC_TX_FLOW_CTL);
+	if (fc & EMAC_FLOW_TX)
+		flow |= EMAC_TX_FLOW_CTL_EN;
+	else
+		flow &= ~EMAC_TX_FLOW_CTL_EN;
+	writel(flow, priv->base + EMAC_TX_FLOW_CTL);
+}
+
+/* Grab a frame into a skb from descriptor number i */
+static int sun8i_emac_rx_from_ddesc(struct net_device *ndev, int i)
+{
+	struct sk_buff *skb;
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct dma_desc *ddesc = priv->dd_rx + i;
+	int frame_len;
+	int rxcsum_done = 0;
+	u32 dstatus = le32_to_cpu(ddesc->status);
+
+	if (ndev->features & NETIF_F_RXCSUM)
+		rxcsum_done = 1;
+
+	/* bit0/bit7 work only on IPv4/IPv6 TCP traffic,
+	 * (not on ARP for example) so we do not raise rx_errors/discard frame
+	 */
+	/* the checksum or length of received frame's payload is wrong*/
+	if (dstatus & EMAC_DSC_RX_PAYLOAD_ERR) {
+		priv->estats.rx_payload_error++;
+		rxcsum_done = 0;
+	}
+
+	if (dstatus & EMAC_DSC_RX_CRC_ERR) {
+		priv->ndev->stats.rx_errors++;
+		priv->ndev->stats.rx_crc_errors++;
+		priv->estats.rx_crc_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_PHY_ERR)) {
+		priv->ndev->stats.rx_errors++;
+		priv->estats.rx_phy_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_LENGTH_ERR)) {
+		priv->ndev->stats.rx_errors++;
+		priv->ndev->stats.rx_length_errors++;
+		priv->estats.rx_length_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_COL_ERR)) {
+		priv->ndev->stats.rx_errors++;
+		priv->estats.rx_col_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_HEADER_ERR)) {
+		priv->estats.rx_header_error++;
+		rxcsum_done = 0;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_OVERFLOW_ERR)) {
+		priv->ndev->stats.rx_over_errors++;
+		priv->estats.rx_overflow_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_SAF_FAIL))
+		priv->estats.rx_saf_fail++;
+
+	if ((dstatus & EMAC_DSC_RX_NO_ENOUGTH_BUF_ERR)) {
+		priv->ndev->stats.rx_errors++;
+		priv->estats.rx_buf_error++;
+		goto discard_frame;
+	}
+
+	if ((dstatus & EMAC_DSC_RX_DAF_FAIL))
+		priv->estats.rx_daf_fail++;
+
+	/* EMAC_DSC_RX_FIRST is for the first frame, not having it is bad
+	 * since we do not handle Jumbo frame
+	 */
+	if ((dstatus & EMAC_DSC_RX_FIRST) == 0) {
+		priv->ndev->stats.rx_errors++;
+		priv->estats.rx_invalid_error++;
+		goto discard_frame;
+	}
+
+	/* this frame is not the last */
+	if ((dstatus & EMAC_DSC_RX_LAST) == 0) {
+		priv->ndev->stats.rx_errors++;
+		priv->estats.rx_invalid_error++;
+		goto discard_frame;
+	}
+
+	frame_len = (dstatus >> 16) & 0x3FFF;
+	if (!(ndev->features & NETIF_F_RXFCS))
+		frame_len -= ETH_FCS_LEN;
+
+	skb = priv->rx_skb[i];
+
+	netif_dbg(priv, rx_status, priv->ndev,
+		  "%s from %02d %pad len=%d status=%x st=%x\n",
+		  __func__, i, &ddesc, frame_len, dstatus,
+		  cpu_to_le32(ddesc->ctl));
+
+	skb_put(skb, frame_len);
+
+	dma_unmap_single(priv->dev, le32_to_cpu(ddesc->buf_addr), DESC_BUF_MAX,
+			 DMA_FROM_DEVICE);
+	skb->protocol = eth_type_trans(skb, priv->ndev);
+	if (rxcsum_done) {
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+		priv->estats.rx_hw_csum++;
+	} else {
+		skb->ip_summed = CHECKSUM_PARTIAL;
+	}
+
+	priv->ndev->stats.rx_packets++;
+	priv->ndev->stats.rx_bytes += frame_len;
+	priv->rx_skb[i] = NULL;
+
+	sun8i_emac_rx_skb(ndev, i);
+	napi_gro_receive(&priv->napi, skb);
+
+	return 0;
+	/* If the frame need to be dropped, we simply reuse the buffer */
+discard_frame:
+	ddesc->ctl = cpu_to_le32(DESC_BUF_MAX);
+	/* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+	dma_wmb();
+	ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+	return 0;
+}
+
+/* Iterate over dma_desc for finding completed xmit.
+ *
+ * The problem is: how to know that a descriptor is sent and not just in
+ * preparation.
+ * Need to have status=0 and st set but this is the state of first frame just
+ * before setting the own-by-DMA bit.
+ * The solution is to used the artificial value DCLEAN.
+ */
+static int sun8i_emac_complete_xmit(struct net_device *ndev, int budget)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct dma_desc *ddesc;
+	int frame_len;
+	int work = 0;
+	unsigned int bytes_compl = 0, pkts_compl = 0;
+	u32 dstatus;
+
+	do {
+		ddesc = priv->dd_tx + priv->tx_dirty;
+
+		if (ddesc->status & EMAC_COULD_BE_USED_BY_DMA)
+			goto xmit_end;
+
+		if (ddesc->status == DCLEAN)
+			goto xmit_end;
+
+		dstatus = cpu_to_le32(ddesc->status);
+
+		if (ddesc->status == 0 && !ddesc->ctl) {
+			dev_err(priv->dev, "BUG: reached the void %d %d\n",
+				priv->tx_dirty, priv->tx_slot);
+			goto xmit_end;
+		}
+
+		if (dstatus & EMAC_DSC_TX_UNDERFLOW_ERR)
+			priv->ndev->stats.tx_errors++;
+		if (dstatus & EMAC_DSC_TX_DEFER_ERR)
+			priv->ndev->stats.tx_errors++;
+		/* BIT 6:3 numbers of collisions */
+		if (dstatus & EMAC_DSC_TX_COL_NB)
+			priv->ndev->stats.collisions +=
+				(dstatus & EMAC_DSC_TX_COL_NB) >> 3;
+		if (dstatus & EMAC_DSC_TX_COL_ERR_1)
+			priv->ndev->stats.tx_errors++;
+		if (dstatus & EMAC_DSC_TX_COL_ERR_0)
+			priv->ndev->stats.tx_errors++;
+		if (dstatus & EMAC_DSC_TX_CRS_ERR)
+			priv->ndev->stats.tx_carrier_errors++;
+		if (dstatus & EMAC_DSC_TX_PAYLOAD_ERR)
+			priv->ndev->stats.tx_errors++;
+		if (dstatus & EMAC_DSC_TX_LENGTH_ERR)
+			priv->ndev->stats.tx_errors++;
+		if (dstatus & EMAC_DSC_TX_HEADER_ERR)
+			priv->ndev->stats.tx_errors++;
+
+		frame_len = le32_to_cpu(ddesc->ctl) & 0x3FFF;
+		bytes_compl += frame_len;
+
+		if (priv->txl[priv->tx_dirty].map == MAP_SINGLE)
+			dma_unmap_single(priv->dev,
+					 le32_to_cpu(ddesc->buf_addr),
+					 frame_len, DMA_TO_DEVICE);
+		else
+			dma_unmap_page(priv->dev,
+				       le32_to_cpu(ddesc->buf_addr),
+				       frame_len, DMA_TO_DEVICE);
+		/* we can free skb only on last frame */
+		if (priv->txl[priv->tx_dirty].skb &&
+		    (ddesc->ctl & EMAC_DSC_TX_LAST)) {
+			dev_kfree_skb_irq(priv->txl[priv->tx_dirty].skb);
+			pkts_compl++;
+		}
+
+		priv->txl[priv->tx_dirty].skb = NULL;
+		priv->txl[priv->tx_dirty].map = 0;
+		ddesc->ctl = 0;
+		/* setting status to DCLEAN is the last value to be set */
+		dma_wmb();
+		ddesc->status = DCLEAN;
+		work++;
+
+		rb_inc(&priv->tx_dirty, priv->nbdesc_tx);
+		ddesc = priv->dd_tx + priv->tx_dirty;
+	} while (ddesc->ctl &&
+		 !(ddesc->status & EMAC_COULD_BE_USED_BY_DMA) &&
+		 work < budget);
+
+xmit_end:
+	netdev_completed_queue(ndev, pkts_compl, bytes_compl);
+
+	/* if we don't have handled all packets */
+	if (work < budget)
+		work = 0;
+
+	if (netif_queue_stopped(ndev) &&
+	    rb_tx_numfreedesc(ndev) > MAX_SKB_FRAGS + 1)
+		netif_wake_queue(ndev);
+	return work;
+}
+
+static int sun8i_emac_poll(struct napi_struct *napi, int budget)
+{
+	struct sun8i_emac_priv *priv =
+		container_of(napi, struct sun8i_emac_priv, napi);
+	struct net_device *ndev = priv->ndev;
+	int worked;
+	struct dma_desc *ddesc;
+
+	priv->estats.napi_schedule++;
+	worked = sun8i_emac_complete_xmit(ndev, budget);
+
+	ddesc = priv->dd_rx + priv->rx_dirty;
+	while (!(ddesc->status & EMAC_COULD_BE_USED_BY_DMA) &&
+	       worked < budget) {
+		sun8i_emac_rx_from_ddesc(ndev, priv->rx_dirty);
+		worked++;
+		rb_inc(&priv->rx_dirty, priv->nbdesc_rx);
+		ddesc = priv->dd_rx + priv->rx_dirty;
+	};
+	if (worked < budget) {
+		priv->estats.napi_underflow++;
+		napi_complete(&priv->napi);
+		writel(EMAC_RX_INT | EMAC_TX_INT, priv->base + EMAC_INT_EN);
+	}
+	return worked;
+}
+
+static int sun8i_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
+{
+	struct net_device *ndev = bus->priv;
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int err;
+	u32 reg;
+
+	err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+				 !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+	if (err) {
+		dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+		return err;
+	}
+
+	reg &= ~MDIO_CMD_MII_WRITE;
+	reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+	reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
+		MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+
+	reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
+
+	reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
+		MDIO_CMD_MII_PHY_ADDR_MASK;
+
+	reg |= MDIO_CMD_MII_BUSY;
+
+	writel(reg, priv->base + EMAC_MDIO_CMD);
+
+	err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+				 !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+
+	if (err) {
+		dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+		return err;
+	}
+
+	return readl(priv->base + EMAC_MDIO_DATA);
+}
+
+static int sun8i_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg,
+			    u16 data)
+{
+	struct net_device *ndev = bus->priv;
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 reg;
+	int err;
+
+	err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+				 !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+	if (err) {
+		dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+		return err;
+	}
+
+	reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+	reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
+		MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+
+	reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
+	reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
+		MDIO_CMD_MII_PHY_ADDR_MASK;
+
+	reg |= MDIO_CMD_MII_WRITE;
+	reg |= MDIO_CMD_MII_BUSY;
+
+	writel(data, priv->base + EMAC_MDIO_DATA);
+	writel(reg, priv->base + EMAC_MDIO_CMD);
+
+	err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+				 !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+	if (err) {
+		dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+		return err;
+	}
+
+	return 0;
+}
+
+static int sun8i_emac_mdio_register(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct mii_bus *bus;
+	int ret;
+
+	bus = mdiobus_alloc();
+	if (!bus) {
+		netdev_err(ndev, "Failed to allocate a new mdio bus\n");
+		return -ENOMEM;
+	}
+
+	bus->name = dev_name(priv->dev);
+	bus->read = &sun8i_mdio_read;
+	bus->write = &sun8i_mdio_write;
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%x", bus->name, priv->dev->id);
+
+	bus->parent = priv->dev;
+	bus->priv = ndev;
+
+	ret = of_mdiobus_register(bus, priv->mdio_node);
+	if (ret) {
+		netdev_err(ndev, "Could not register a MDIO bus: %d\n", ret);
+		mdiobus_free(bus);
+		return ret;
+	}
+
+	priv->mdio = bus;
+
+	return 0;
+}
+
+static void sun8i_emac_mdio_unregister(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	mdiobus_unregister(priv->mdio);
+	mdiobus_free(priv->mdio);
+}
+
+/* Run within phydev->lock */
+static void sun8i_emac_adjust_link(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct phy_device *phydev = ndev->phydev;
+	int new_state = 0;
+
+	netif_dbg(priv, link, priv->ndev,
+		  "%s link=%x duplex=%x speed=%x\n", __func__,
+		  phydev->link, phydev->duplex, phydev->speed);
+	if (!phydev)
+		return;
+
+	if (phydev->link) {
+		if (phydev->duplex != priv->duplex) {
+			new_state = 1;
+			priv->duplex = phydev->duplex;
+		}
+		if (phydev->pause)
+			sun8i_emac_flow_ctrl(priv, phydev->duplex,
+					     priv->flow_ctrl);
+
+		if (phydev->speed != priv->speed) {
+			new_state = 1;
+			priv->speed = phydev->speed;
+		}
+
+		if (priv->link == 0) {
+			new_state = 1;
+			priv->link = phydev->link;
+		}
+
+		netif_dbg(priv, link, priv->ndev,
+			  "%s new=%d link=%d pause=%d\n",
+			  __func__, new_state, priv->link, phydev->pause);
+		if (new_state)
+			sun8i_emac_set_link_mode(priv);
+	} else if (priv->link != phydev->link) {
+		new_state = 1;
+		priv->link = 0;
+		priv->speed = 0;
+		priv->duplex = -1;
+	}
+
+	if (new_state)
+		phy_print_status(phydev);
+}
+
+/* H3 specific bits for EPHY */
+#define H3_EPHY_ADDR_SHIFT	20
+#define H3_EPHY_LED_POL		BIT(17) /* 1: active low, 0: active high */
+#define H3_EPHY_SHUTDOWN	BIT(16) /* 1: shutdown, 0: power up */
+#define H3_EPHY_SELECT		BIT(15) /* 1: internal PHY, 0: external PHY */
+
+/* H3/A64 specific bits */
+#define SYSCON_RMII_EN		BIT(13) /* 1: enable RMII (overrides EPIT) */
+
+/* Generic system control EMAC_CLK bits */
+#define SYSCON_ETXDC_MASK		GENMASK(2, 0)
+#define SYSCON_ETXDC_SHIFT		10
+#define SYSCON_ERXDC_MASK		GENMASK(4, 0)
+#define SYSCON_ERXDC_SHIFT		5
+/* EMAC PHY Interface Type */
+#define SYSCON_EPIT			BIT(2) /* 1: RGMII, 0: MII */
+#define SYSCON_ETCS_MASK		GENMASK(1, 0)
+#define SYSCON_ETCS_MII		0x0
+#define SYSCON_ETCS_EXT_GMII	0x1
+#define SYSCON_ETCS_INT_GMII	0x2
+#define SYSCON_EMAC_REG		0x30
+
+static int sun8i_emac_set_syscon(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct device_node *node = priv->dev->of_node;
+	int ret;
+	u32 reg, val;
+
+	reg = priv->variant->default_syscon_value;
+
+	if (priv->variant->internal_phy) {
+		if (!priv->use_internal_phy) {
+			/* switch to external PHY interface */
+			reg &= ~H3_EPHY_SELECT;
+		} else {
+			reg |= H3_EPHY_SELECT;
+			reg &= ~H3_EPHY_SHUTDOWN;
+
+			if (of_property_read_bool(priv->phy_node,
+						  "allwinner,leds-active-low"))
+				reg |= H3_EPHY_LED_POL;
+			else
+				reg &= ~H3_EPHY_LED_POL;
+
+			ret = of_mdio_parse_addr(priv->dev, priv->phy_node);
+			if (ret < 0) {
+				netdev_err(ndev, "Could not parse MDIO addr\n");
+				return ret;
+			}
+			/* of_mdio_parse_addr returns a valid (0 ~ 31) PHY
+			 * address. No need to mask it again.
+			 */
+			reg |= ret << H3_EPHY_ADDR_SHIFT;
+		}
+	}
+
+	if (!of_property_read_u32(node, "allwinner,tx-delay", &val)) {
+		if (val <= SYSCON_ETXDC_MASK) {
+			reg &= ~(SYSCON_ETXDC_MASK << SYSCON_ETXDC_SHIFT);
+			reg |= (val << SYSCON_ETXDC_SHIFT);
+		} else {
+			netdev_warn(ndev, "Invalid TX clock delay: %d\n", val);
+		}
+	}
+
+	if (!of_property_read_u32(node, "allwinner,rx-delay", &val)) {
+		if (val <= SYSCON_ERXDC_MASK) {
+			reg &= ~(SYSCON_ERXDC_MASK << SYSCON_ERXDC_SHIFT);
+			reg |= (val << SYSCON_ERXDC_SHIFT);
+		} else {
+			netdev_warn(ndev, "Invalid RX clock delay: %d\n", val);
+		}
+	}
+
+	/* Clear interface mode bits */
+	reg &= ~(SYSCON_ETCS_MASK | SYSCON_EPIT);
+	if (priv->variant->support_rmii)
+		reg &= ~SYSCON_RMII_EN;
+
+	switch (priv->phy_interface) {
+	case PHY_INTERFACE_MODE_MII:
+		/* default */
+		break;
+	case PHY_INTERFACE_MODE_RGMII:
+		reg |= SYSCON_EPIT | SYSCON_ETCS_INT_GMII;
+		break;
+	case PHY_INTERFACE_MODE_RMII:
+		reg |= SYSCON_RMII_EN | SYSCON_ETCS_EXT_GMII;
+		break;
+	default:
+		netdev_err(ndev, "Unsupported interface mode: %s",
+			   phy_modes(priv->phy_interface));
+		return -EINVAL;
+	}
+
+	regmap_write(priv->regmap, SYSCON_EMAC_REG, reg);
+
+	return 0;
+}
+
+static void sun8i_emac_unset_syscon(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 reg = priv->variant->default_syscon_value;
+
+	regmap_write(priv->regmap, SYSCON_EMAC_REG, reg);
+}
+
+/* Set Management Data Clock, must be call after device reset */
+static void sun8i_emac_set_mdc(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	unsigned long rate;
+	u32 reg;
+
+	rate = clk_get_rate(priv->ahb_clk);
+	if (rate > 160000000)
+		reg = 0x3 << 20; /* AHB / 128 */
+	else if (rate > 80000000)
+		reg = 0x2 << 20; /* AHB / 64 */
+	else if (rate > 40000000)
+		reg = 0x1 << 20; /* AHB / 32 */
+	else
+		reg = 0x0 << 20; /* AHB / 16 */
+	netif_dbg(priv, link, ndev, "MDC auto : %x\n", reg);
+	writel(reg, priv->base + EMAC_MDIO_CMD);
+}
+
+/* "power" the device, by enabling clk/reset/regulators */
+static int sun8i_emac_power(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int ret;
+
+	ret = clk_prepare_enable(priv->ahb_clk);
+	if (ret) {
+		netdev_err(ndev, "Could not enable AHB clock\n");
+		return ret;
+	}
+
+	if (priv->rst_mac) {
+		ret = reset_control_deassert(priv->rst_mac);
+		if (ret) {
+			netdev_err(ndev, "Could not deassert reset\n");
+			goto err_reset;
+		}
+	}
+
+	if (priv->ephy_clk) {
+		ret = clk_prepare_enable(priv->ephy_clk);
+		if (ret) {
+			netdev_err(ndev, "Could not enable EPHY clock\n");
+			goto err_ephy_clk;
+		}
+	}
+
+	if (priv->rst_ephy) {
+		ret = reset_control_deassert(priv->rst_ephy);
+		if (ret) {
+			netdev_err(ndev, "Could not deassert EPHY reset\n");
+			goto err_ephy_reset;
+		}
+	}
+
+	if (priv->regulator) {
+		ret = regulator_enable(priv->regulator);
+		if (ret)
+			goto err_regulator;
+	}
+
+	return 0;
+
+err_regulator:
+	if (priv->rst_ephy)
+		reset_control_assert(priv->rst_ephy);
+err_ephy_reset:
+	if (priv->ephy_clk)
+		clk_disable_unprepare(priv->ephy_clk);
+err_ephy_clk:
+	if (priv->rst_mac)
+		reset_control_assert(priv->rst_mac);
+err_reset:
+	clk_disable_unprepare(priv->ahb_clk);
+	return ret;
+}
+
+/* "Unpower" the device, disabling clocks and regulators, asserting reset */
+static void sun8i_emac_unpower(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	if (priv->regulator)
+		regulator_disable(priv->regulator);
+
+	if (priv->rst_ephy)
+		reset_control_assert(priv->rst_ephy);
+
+	if (priv->ephy_clk)
+		clk_disable_unprepare(priv->ephy_clk);
+
+	if (priv->rst_mac)
+		reset_control_assert(priv->rst_mac);
+
+	clk_disable_unprepare(priv->ahb_clk);
+}
+
+static int sun8i_emac_init(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct device_node *node = priv->dev->of_node;
+	const u8 *addr;
+
+	/* Try to get MAC address from DT, or assign a random one */
+	addr = of_get_mac_address(node);
+	if (addr)
+		ether_addr_copy(ndev->dev_addr, addr);
+	else
+		eth_hw_addr_random(ndev);
+
+	return 0;
+}
+
+static int sun8i_emac_mdio_probe(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct phy_device *phydev = NULL;
+
+	phydev = of_phy_connect(ndev, priv->phy_node, &sun8i_emac_adjust_link,
+				0, priv->phy_interface);
+
+	if (!phydev) {
+		netdev_err(ndev, "Could not attach to PHY\n");
+		return -ENODEV;
+	}
+
+	phy_attached_info(phydev);
+
+	/* mask with MAC supported features */
+	phydev->supported &= PHY_GBIT_FEATURES;
+	phydev->advertising = phydev->supported;
+
+	priv->link = 0;
+	priv->speed = 0;
+	priv->duplex = -1;
+
+	return 0;
+}
+
+/* Allocate both RX and TX ring buffer and init them
+ * This function also write the startbase of thoses ring in the device.
+ * All structures that help managing thoses rings are also handled
+ * by this functions (rx_skb/txl)
+ */
+static int sun8i_emac_alloc_rings(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct dma_desc *ddesc;
+	int err, i;
+
+	priv->rx_skb = kcalloc(priv->nbdesc_rx, sizeof(struct sk_buff *),
+			      GFP_KERNEL);
+	if (!priv->rx_skb) {
+		err = -ENOMEM;
+		goto rx_skb_error;
+	}
+	priv->txl = kcalloc(priv->nbdesc_tx, sizeof(struct txinfo), GFP_KERNEL);
+	if (!priv->txl) {
+		err = -ENOMEM;
+		goto tx_error;
+	}
+
+	/* allocate/init RX ring */
+	priv->dd_rx = dma_zalloc_coherent(priv->dev,
+			priv->nbdesc_rx * sizeof(struct dma_desc),
+			&priv->dd_rx_phy, GFP_KERNEL);
+	if (!priv->dd_rx) {
+		dev_err(priv->dev, "ERROR: cannot allocate DMA RX buffer");
+		err = -ENOMEM;
+		goto dma_rx_error;
+	}
+	ddesc = priv->dd_rx;
+	for (i = 0; i < priv->nbdesc_rx; i++) {
+		sun8i_emac_rx_skb(ndev, i);
+		ddesc->next = cpu_to_le32(priv->dd_rx_phy + (i + 1)
+			* sizeof(struct dma_desc));
+		ddesc++;
+	}
+	/* last descriptor point back to first one */
+	ddesc--;
+	ddesc->next = cpu_to_le32(priv->dd_rx_phy);
+
+	/* allocate/init TX ring */
+	priv->dd_tx = dma_zalloc_coherent(priv->dev,
+			priv->nbdesc_tx * sizeof(struct dma_desc),
+			&priv->dd_tx_phy, GFP_KERNEL);
+	if (!priv->dd_tx) {
+		dev_err(priv->dev, "ERROR: cannot allocate DMA TX buffer");
+		err = -ENOMEM;
+		goto dma_tx_error;
+	}
+	ddesc = priv->dd_tx;
+	for (i = 0; i < priv->nbdesc_tx; i++) {
+		ddesc->status = DCLEAN;
+		ddesc->ctl = 0;
+		ddesc->next = cpu_to_le32(priv->dd_tx_phy + (i + 1)
+			* sizeof(struct dma_desc));
+		ddesc++;
+	}
+	/* last descriptor point back to first one */
+	ddesc--;
+	ddesc->next = cpu_to_le32(priv->dd_tx_phy);
+	i--;
+
+	priv->tx_slot = 0;
+	priv->tx_dirty = 0;
+	priv->rx_dirty = 0;
+
+	/* write start of RX ring descriptor */
+	writel(priv->dd_rx_phy, priv->base + EMAC_RX_DESC_LIST);
+	/* write start of TX ring descriptor */
+	writel(priv->dd_tx_phy, priv->base + EMAC_TX_DESC_LIST);
+
+	return 0;
+dma_tx_error:
+	dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+			  priv->dd_rx, priv->dd_rx_phy);
+dma_rx_error:
+	kfree(priv->txl);
+tx_error:
+	kfree(priv->rx_skb);
+rx_skb_error:
+	return err;
+}
+
+static int sun8i_emac_open(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int err;
+	u32 v;
+
+	err = sun8i_emac_power(ndev);
+	if (err)
+		return err;
+
+	err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0,
+			  dev_name(priv->dev), ndev);
+	if (err) {
+		dev_err(priv->dev, "Cannot request IRQ: %d\n", err);
+		goto err_power;
+	}
+
+	/* Set interface mode (and configure internal PHY on H3) */
+	err = sun8i_emac_set_syscon(ndev);
+	if (err)
+		goto err_irq;
+
+	/* Do SOFT RST */
+	v = readl(priv->base + EMAC_BASIC_CTL1);
+	writel(v | 0x01, priv->base + EMAC_BASIC_CTL1);
+
+	err = readl_poll_timeout(priv->base + EMAC_BASIC_CTL1, v,
+				 !(v & 0x01), 100, 10000);
+	if (err) {
+		dev_err(priv->dev, "EMAC reset timeout\n");
+		err = -EFAULT;
+		goto err_syscon;
+	}
+
+	sun8i_emac_set_mdc(ndev);
+
+	err = sun8i_emac_mdio_register(ndev);
+	if (err)
+		goto err_syscon;
+
+	err = sun8i_emac_mdio_probe(ndev);
+	if (err)
+		goto err_syscon;
+
+	/* DMA */
+	v = (8 << 24);/* burst len */
+	writel(v, priv->base + EMAC_BASIC_CTL1);
+
+	writel(EMAC_RX_INT | EMAC_TX_INT, priv->base + EMAC_INT_EN);
+
+	v = readl(priv->base + EMAC_RX_CTL0);
+	/* CHECK_CRC */
+	if (ndev->features & NETIF_F_RXCSUM)
+		v |= EMAC_RX_DO_CRC;
+	else
+		v &= ~EMAC_RX_DO_CRC;
+	/* STRIP_FCS */
+	if (ndev->features & NETIF_F_RXFCS)
+		v &= ~EMAC_RX_STRIP_FCS;
+	else
+		v |= EMAC_RX_STRIP_FCS;
+	writel(v, priv->base + EMAC_RX_CTL0);
+
+	v = readl(priv->base + EMAC_TX_CTL1);
+	/* TX_MD Transmission starts after a full frame located in TX DMA FIFO*/
+	v |= EMAC_TX_MD;
+	/* Undocumented bit (called TX_NEXT_FRM in BSP), the original comment is
+	 * "Operating on second frame increase the performance
+	 * especially when transmit store-and-forward is used."
+	 */
+	v |= EMAC_TX_NEXT_FRM;
+	writel(v, priv->base + EMAC_TX_CTL1);
+
+	v = readl(priv->base + EMAC_RX_CTL1);
+	/* RX_MD RX DMA reads data from RX DMA FIFO to host memory after a
+	 * complete frame has been written to RX DMA FIFO
+	 */
+	v |= EMAC_RX_MD;
+	writel(v, priv->base + EMAC_RX_CTL1);
+
+	sun8i_emac_set_macaddr(priv, ndev->dev_addr, 0);
+
+	err = sun8i_emac_alloc_rings(ndev);
+	if (err) {
+		netdev_err(ndev, "Fail to allocate rings\n");
+		goto err_mdio;
+	}
+
+	phy_start(ndev->phydev);
+
+	sun8i_emac_start_rx(ndev);
+	sun8i_emac_start_tx(ndev);
+
+	netif_napi_add(ndev, &priv->napi, sun8i_emac_poll, 64);
+	napi_enable(&priv->napi);
+	netif_start_queue(ndev);
+
+	return 0;
+err_mdio:
+	phy_disconnect(ndev->phydev);
+err_syscon:
+	sun8i_emac_unset_syscon(ndev);
+err_irq:
+	free_irq(priv->irq, ndev);
+err_power:
+	sun8i_emac_unpower(ndev);
+	return err;
+}
+
+/* Clean the TX ring of any accepted skb for xmit */
+static void sun8i_emac_tx_clean(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int i;
+	struct dma_desc *ddesc;
+	int frame_len;
+
+	for (i = 0; i < priv->nbdesc_tx; i++) {
+		if (priv->txl[i].skb) {
+			ddesc = priv->dd_tx + i;
+			frame_len = le32_to_cpu(ddesc->ctl) & 0x3FFF;
+			switch (priv->txl[i].map) {
+			case MAP_SINGLE:
+				dma_unmap_single(priv->dev,
+						 le32_to_cpu(ddesc->buf_addr),
+						 frame_len, DMA_TO_DEVICE);
+				break;
+			case MAP_PAGE:
+				dma_unmap_page(priv->dev,
+					       le32_to_cpu(ddesc->buf_addr),
+					       frame_len, DMA_TO_DEVICE);
+				break;
+			default:
+				dev_err(priv->dev, "Trying to free an empty slot\n");
+				continue;
+			}
+			dev_kfree_skb_any(priv->txl[i].skb);
+			priv->txl[i].skb = NULL;
+			ddesc->ctl = 0;
+			ddesc->status = DCLEAN;
+		}
+	}
+	priv->tx_slot = 0;
+	priv->tx_dirty = 0;
+}
+
+/* Clean the RX ring */
+static void sun8i_emac_rx_clean(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int i;
+	struct dma_desc *ddesc;
+
+	/* clean RX ring */
+	for (i = 0; i < priv->nbdesc_rx; i++)
+		if (priv->rx_skb[i]) {
+			ddesc = priv->dd_rx + i;
+			dma_unmap_single(priv->dev,
+					 le32_to_cpu(ddesc->buf_addr),
+					 DESC_BUF_MAX, DMA_FROM_DEVICE);
+			dev_kfree_skb_any(priv->rx_skb[i]);
+			priv->rx_skb[i] = NULL;
+		}
+}
+
+static int sun8i_emac_stop(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	napi_disable(&priv->napi);
+
+	sun8i_emac_stop_tx(ndev);
+	sun8i_emac_stop_rx(ndev);
+
+	phy_stop(ndev->phydev);
+	phy_disconnect(ndev->phydev);
+
+	sun8i_emac_mdio_unregister(ndev);
+
+	sun8i_emac_unset_syscon(ndev);
+
+	free_irq(priv->irq, ndev);
+
+	sun8i_emac_rx_clean(ndev);
+	sun8i_emac_tx_clean(ndev);
+
+	kfree(priv->rx_skb);
+	kfree(priv->txl);
+
+	dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+			  priv->dd_rx, priv->dd_rx_phy);
+	dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc),
+			  priv->dd_tx, priv->dd_tx_phy);
+
+	sun8i_emac_unpower(ndev);
+
+	return 0;
+}
+
+static netdev_tx_t sun8i_emac_xmit(struct sk_buff *skb, struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct dma_desc *ddesc;
+	struct dma_desc *first;
+	int i = 0, rbd_first;
+	unsigned int len, fraglen, tlen;
+	u32 v;
+	int n;
+	int nf;
+	const skb_frag_t *frag;
+	int do_csum = 0;
+
+	if (skb_put_padto(skb, ETH_ZLEN))
+		return NETDEV_TX_OK;
+	len = skb_headlen(skb);
+
+	n = skb_shinfo(skb)->nr_frags;
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		do_csum = 1;
+		priv->estats.tx_hw_csum++;
+	}
+	netif_dbg(priv, tx_queued, ndev, "%s len=%u skblen=%u %x\n", __func__,
+		  len, skb->len,
+		  (skb->ip_summed == CHECKSUM_PARTIAL));
+
+	/* check for contigous space
+	 * We need at least 1(skb->data) + n(numfrags) + 1(one clean slot)
+	 */
+	if (rb_tx_numfreedesc(ndev) < n + 2) {
+		dev_err_ratelimited(priv->dev, "BUG!: TX is full %d %d\n",
+				    priv->tx_dirty, priv->tx_slot);
+		netif_stop_queue(ndev);
+		return NETDEV_TX_BUSY;
+	}
+	i = priv->tx_slot;
+
+	ddesc = priv->dd_tx + i;
+	first = priv->dd_tx + i;
+	rbd_first = i;
+
+	ddesc->buf_addr = dma_map_single(priv->dev, skb->data, len,
+					 DMA_TO_DEVICE);
+	if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+		dev_err(priv->dev, "ERROR: Cannot map buffer for DMA\n");
+		goto xmit_error;
+	}
+	/* We cannot direcly use cpu_to_le32() after dma_map_single
+	 * since dma_mapping_error use it
+	 */
+	ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+	priv->txl[i].map = MAP_SINGLE;
+	priv->txl[i].skb = skb;
+
+	tlen = len;
+	ddesc->ctl = le32_to_cpu(len);
+	/* Undocumented bit that make it works
+	 * Without it, packets never be sent on H3 SoC
+	 */
+	ddesc->ctl |= EMAC_MAGIC_TX_BIT;
+	if (do_csum)
+		ddesc->ctl |= EMAC_TX_DO_CRC;
+
+	/* handle fragmented skb, one descriptor per fragment  */
+	for (nf = 0; nf < n; nf++) {
+		frag = &skb_shinfo(skb)->frags[nf];
+		rb_inc(&i, priv->nbdesc_tx);
+		priv->txl[i].skb = skb;
+		ddesc = priv->dd_tx + i;
+		fraglen = skb_frag_size(frag);
+		ddesc->ctl = le32_to_cpu(fraglen);
+		tlen += fraglen,
+		ddesc->ctl |= EMAC_MAGIC_TX_BIT;
+		if (do_csum)
+			ddesc->ctl |= EMAC_TX_DO_CRC;
+
+		ddesc->buf_addr = skb_frag_dma_map(priv->dev, frag, 0,
+				fraglen, DMA_TO_DEVICE);
+		if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+			dev_err(priv->dev, "Cannot map buffer for DMA\n");
+			goto xmit_error;
+		}
+		/* Cannot directly use cpu_to_le32() after skb_frag_dma_map
+		 * since dma_mapping_error use it
+		 */
+		ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+		priv->txl[i].map = MAP_PAGE;
+		ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+	}
+
+	/* frame end */
+	ddesc->ctl |= EMAC_DSC_TX_LAST;
+	/* We want an interrupt after transmission */
+	ddesc->ctl |= EMAC_WANT_INT;
+
+	rb_inc(&i, priv->nbdesc_tx);
+
+	/* This line was previously after DMA start, but with that we hit a
+	 * small race with complete_xmit() where we complete more data than
+	 * sent.
+	 * The packet is sent just after EMAC_COULD_BE_USED_BY_DMA flag set and
+	 * complete_xmit fire just after before netdev_sent_queue().
+	 * This race could be observed only when overflowing a gigabit line.
+	 */
+	netdev_sent_queue(ndev, skb->len);
+
+	/* frame begin */
+	first->ctl |= EMAC_DSC_TX_FIRST;
+	dma_wmb();/* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+	first->status = EMAC_COULD_BE_USED_BY_DMA;
+	priv->tx_slot = i;
+
+	/* Trying to optimize this (recording DMA start/stop) seems
+	 * to lead to errors. So we always start DMA.
+	 */
+	v = readl(priv->base + EMAC_TX_CTL1);
+	v |= EMAC_TX_DMA_START;
+	v |= EMAC_TX_DMA_EN;
+	writel_relaxed(v, priv->base + EMAC_TX_CTL1);
+
+	if (rb_tx_numfreedesc(ndev) < MAX_SKB_FRAGS + 1) {
+		netif_stop_queue(ndev);
+		priv->estats.tx_stop_queue++;
+	}
+	priv->estats.tx_used_desc = rb_tx_numfreedesc(ndev);
+	priv->ndev->stats.tx_packets++;
+	priv->ndev->stats.tx_bytes += tlen;
+
+	return NETDEV_TX_OK;
+
+xmit_error:
+	/* destroy skb and return TX OK Documentation/DMA-API-HOWTO.txt */
+	/* clean descritors from rbd_first to i */
+	ddesc->ctl = 0;
+	/* setting status to DCLEAN is the last value to be set */
+	dma_wmb();
+	ddesc->status = DCLEAN;
+	do {
+		ddesc = priv->dd_tx + rbd_first;
+		ddesc->ctl = 0;
+		/* setting status to DCLEAN is the last value to be set */
+		dma_wmb();
+		ddesc->status = DCLEAN;
+		rb_inc(&rbd_first, priv->nbdesc_tx);
+	} while (rbd_first != i);
+	dev_kfree_skb_any(skb);
+	return NETDEV_TX_OK;
+}
+
+static int sun8i_emac_change_mtu(struct net_device *ndev, int new_mtu)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int max_mtu;
+
+	dev_info(priv->dev, "%s set MTU to %d\n", __func__, new_mtu);
+
+	if (netif_running(ndev)) {
+		dev_err(priv->dev, "%s: must be stopped to change its MTU\n",
+			ndev->name);
+		return -EBUSY;
+	}
+
+	max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
+
+	if ((new_mtu < 68) || (new_mtu > max_mtu)) {
+		dev_err(priv->dev, "%s: invalid MTU, max MTU is: %d\n",
+			ndev->name, max_mtu);
+		return -EINVAL;
+	}
+
+	ndev->mtu = new_mtu;
+	netdev_update_features(ndev);
+	return 0;
+}
+
+static int sun8i_emac_set_features(struct net_device *ndev,
+				   netdev_features_t features)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v;
+
+	v = readl(priv->base + EMAC_BASIC_CTL0);
+	if (features & NETIF_F_LOOPBACK && netif_running(ndev)) {
+		netif_info(priv, hw, ndev, "Set loopback features");
+		v |= EMAC_BCTL0_LOOPBACK;
+	} else {
+		netif_info(priv, hw, ndev, "Unset loopback features");
+		v &= ~EMAC_BCTL0_LOOPBACK;
+	}
+	writel(v, priv->base + EMAC_BASIC_CTL0);
+
+	v = readl(priv->base + EMAC_RX_CTL0);
+	if (features & NETIF_F_RXCSUM) {
+		v |= EMAC_RX_DO_CRC;
+		netif_info(priv, hw, ndev, "Doing RX CRC check by hardware");
+	} else {
+		v &= ~EMAC_RX_DO_CRC;
+		netif_info(priv, hw, ndev, "No RX CRC check by hardware");
+	}
+	if (features & NETIF_F_RXFCS) {
+		v &= ~EMAC_RX_STRIP_FCS;
+		netif_info(priv, hw, ndev, "Keep FCS");
+	} else {
+		v |= EMAC_RX_STRIP_FCS;
+		netif_info(priv, hw, ndev, "Strip FCS");
+	}
+	writel(v, priv->base + EMAC_RX_CTL0);
+
+	netif_dbg(priv, drv, ndev, "%s %llx %x\n", __func__, features, v);
+
+	return 0;
+}
+
+static void sun8i_emac_set_rx_mode(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v = 0;
+	int i = 0;
+	struct netdev_hw_addr *ha;
+	int macaddrs = netdev_uc_count(ndev) + netdev_mc_count(ndev) + 1;
+
+	/* Receive all control frames */
+	v |= EMAC_FRM_FLT_CTL;
+
+        if (ndev->flags & IFF_PROMISC) {
+                v = EMAC_FRM_FLT_RXALL;
+        } else if (ndev->flags & IFF_ALLMULTI) {
+                v |= EMAC_FRM_FLT_MULTICAST;
+        } else if (macaddrs <= EMAC_MAX_MACADDR) {
+		if (!netdev_mc_empty(ndev)) {
+			netdev_for_each_mc_addr(ha, ndev) {
+				i++;
+				sun8i_emac_set_macaddr(priv, ha->addr, i);
+			}
+		}
+		if (!netdev_uc_empty(ndev)) {
+			netdev_for_each_uc_addr(ha, ndev) {
+				i++;
+				sun8i_emac_set_macaddr(priv, ha->addr, i);
+			}
+		}
+	} else {
+		netdev_info(ndev, "Too many address, switching to promiscuous\n");
+		v = EMAC_FRM_FLT_RXALL;
+	}
+
+	writel(v, priv->base + EMAC_RX_FRM_FLT);
+}
+
+static void sun8i_emac_tx_timeout(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	netdev_err(ndev, "%s\n", __func__);
+
+	sun8i_emac_stop_tx(ndev);
+
+	sun8i_emac_tx_clean(ndev);
+
+	/* write start of the new TX ring descriptor */
+	writel(priv->dd_tx_phy, priv->base + EMAC_TX_DESC_LIST);
+
+	sun8i_emac_start_tx(ndev);
+
+	netdev_reset_queue(ndev);
+
+	priv->estats.tx_timeout++;
+	ndev->stats.tx_errors++;
+	netif_wake_queue(ndev);
+}
+
+static int sun8i_emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
+{
+	struct phy_device *phydev = ndev->phydev;
+
+	if (!netif_running(ndev))
+		return -EINVAL;
+
+	if (!phydev)
+		return -ENODEV;
+
+	return phy_mii_ioctl(phydev, rq, cmd);
+}
+
+static int sun8i_emac_check_if_running(struct net_device *ndev)
+{
+	if (!netif_running(ndev))
+		return -EINVAL;
+	return 0;
+}
+
+static int sun8i_emac_get_sset_count(struct net_device *ndev, int sset)
+{
+	switch (sset) {
+	case ETH_SS_STATS:
+		return ARRAY_SIZE(estats_str);
+	}
+	return -EOPNOTSUPP;
+}
+
+static int sun8i_emac_ethtool_get_settings(struct net_device *ndev,
+					   struct ethtool_cmd *cmd)
+{
+	struct phy_device *phy = ndev->phydev;
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	if (!phy) {
+		netdev_err(ndev, "%s: %s: PHY is not registered\n",
+			   __func__, ndev->name);
+		return -ENODEV;
+	}
+
+	if (!netif_running(ndev)) {
+		dev_err(priv->dev, "interface disabled: we cannot track link speed / duplex setting\n");
+		return -EBUSY;
+	}
+
+	return phy_ethtool_gset(phy, cmd);
+}
+
+static int sun8i_emac_ethtool_set_settings(struct net_device *ndev,
+					   struct ethtool_cmd *cmd)
+{
+	struct phy_device *phy = ndev->phydev;
+
+	return phy_ethtool_sset(phy, cmd);
+}
+
+static void sun8i_emac_ethtool_getdrvinfo(struct net_device *ndev,
+					  struct ethtool_drvinfo *info)
+{
+	strlcpy(info->driver, "sun8i_emac", sizeof(info->driver));
+	strcpy(info->version, "00");
+	info->fw_version[0] = '\0';
+}
+
+static void sun8i_emac_ethtool_stats(struct net_device *ndev,
+				     struct ethtool_stats *dummy, u64 *data)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	memcpy(data, &priv->estats,
+	       sun8i_emac_get_sset_count(ndev, ETH_SS_STATS) * sizeof(u64));
+}
+
+static void sun8i_emac_ethtool_strings(struct net_device *dev, u32 stringset,
+				       u8 *buffer)
+{
+	switch (stringset) {
+	case ETH_SS_STATS:
+		memcpy(buffer, &estats_str, sizeof(estats_str));
+		break;
+	}
+}
+
+static u32 sun8i_emac_ethtool_getmsglevel(struct net_device *ndev)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	return priv->msg_enable;
+}
+
+static void sun8i_emac_ethtool_setmsglevel(struct net_device *ndev, u32 level)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	priv->msg_enable = level;
+}
+
+static void sun8i_emac_get_pauseparam(struct net_device *ndev,
+				      struct ethtool_pauseparam *pause)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	pause->rx_pause = 0;
+	pause->tx_pause = 0;
+	pause->autoneg = ndev->phydev->autoneg;
+
+	if (priv->flow_ctrl & EMAC_FLOW_RX)
+		pause->rx_pause = 1;
+	if (priv->flow_ctrl & EMAC_FLOW_TX)
+		pause->tx_pause = 1;
+}
+
+static int sun8i_emac_set_pauseparam(struct net_device *ndev,
+				     struct ethtool_pauseparam *pause)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	struct phy_device *phy = ndev->phydev;
+	int new_pause = 0;
+	int ret = 0;
+
+	if (pause->rx_pause)
+		new_pause |= EMAC_FLOW_RX;
+	if (pause->tx_pause)
+		new_pause |= EMAC_FLOW_TX;
+
+	priv->flow_ctrl = new_pause;
+	phy->autoneg = pause->autoneg;
+
+	if (phy->autoneg) {
+		if (netif_running(ndev))
+			ret = phy_start_aneg(phy);
+	} else {
+		sun8i_emac_flow_ctrl(priv, phy->duplex, priv->flow_ctrl);
+	}
+	return ret;
+}
+
+static void sun8i_emac_ethtool_get_ringparam(struct net_device *ndev,
+					     struct ethtool_ringparam *ring)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	ring->rx_pending = priv->nbdesc_rx;
+	ring->tx_pending = priv->nbdesc_tx;
+}
+
+static int sun8i_emac_ethtool_set_ringparam(struct net_device *ndev,
+					    struct ethtool_ringparam *ring)
+{
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	int err;
+
+	if (ring->rx_max_pending || ring->rx_mini_max_pending ||
+	    ring->rx_jumbo_max_pending || ring->rx_mini_pending ||
+	    ring->rx_jumbo_pending || ring->tx_max_pending)
+		return -EINVAL;
+
+	if (ring->tx_pending < MAX_SKB_FRAGS + 1) {
+		netdev_err(ndev, "The number of TX descriptors is too low");
+		return -EINVAL;
+	}
+
+	sun8i_emac_stop_tx(ndev);
+	sun8i_emac_stop_rx(ndev);
+
+	sun8i_emac_rx_clean(ndev);
+	sun8i_emac_tx_clean(ndev);
+
+	kfree(priv->rx_skb);
+	kfree(priv->txl);
+
+	dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+			  priv->dd_rx, priv->dd_rx_phy);
+	dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc),
+			  priv->dd_tx, priv->dd_tx_phy);
+
+	priv->nbdesc_rx = ring->rx_pending;
+	priv->nbdesc_tx = ring->tx_pending;
+	err = sun8i_emac_alloc_rings(ndev);
+	if (err) {
+		/* Fatal error, we cannot re start */
+		netdev_err(ndev, "Fail to allocate rings\n");
+		return -EFAULT;
+	}
+
+	sun8i_emac_start_rx(ndev);
+	sun8i_emac_start_tx(ndev);
+
+	netif_start_queue(ndev);
+
+	netdev_info(ndev, "Ring Param settings: rx: %d, tx %d\n",
+		    ring->rx_pending, ring->tx_pending);
+	return 0;
+}
+
+static const struct ethtool_ops sun8i_emac_ethtool_ops = {
+	.begin = sun8i_emac_check_if_running,
+	.get_settings = sun8i_emac_ethtool_get_settings,
+	.set_settings = sun8i_emac_ethtool_set_settings,
+	.get_link = ethtool_op_get_link,
+	.get_pauseparam = sun8i_emac_get_pauseparam,
+	.set_pauseparam = sun8i_emac_set_pauseparam,
+	.get_ethtool_stats = sun8i_emac_ethtool_stats,
+	.get_strings = sun8i_emac_ethtool_strings,
+	.get_sset_count = sun8i_emac_get_sset_count,
+	.get_drvinfo = sun8i_emac_ethtool_getdrvinfo,
+	.get_msglevel = sun8i_emac_ethtool_getmsglevel,
+	.set_msglevel = sun8i_emac_ethtool_setmsglevel,
+	.get_ringparam = sun8i_emac_ethtool_get_ringparam,
+	.set_ringparam = sun8i_emac_ethtool_set_ringparam,
+};
+
+static const struct net_device_ops sun8i_emac_netdev_ops = {
+	.ndo_init = sun8i_emac_init,
+	.ndo_open = sun8i_emac_open,
+	.ndo_start_xmit = sun8i_emac_xmit,
+	.ndo_stop = sun8i_emac_stop,
+	.ndo_change_mtu = sun8i_emac_change_mtu,
+	.ndo_set_features = sun8i_emac_set_features,
+	.ndo_set_rx_mode = sun8i_emac_set_rx_mode,
+	.ndo_tx_timeout = sun8i_emac_tx_timeout,
+	.ndo_do_ioctl = sun8i_emac_ioctl,
+	.ndo_set_mac_address = eth_mac_addr,
+};
+
+/* No locking in this function since it is guaranteed to be run once and
+ * do actions only done here:
+ * - Scheduling NAPI
+ * - Stopping interrupts
+ * - Updating stats
+ *
+ * Even when not enabled via EMAC_INT_EN, some interrupt could fire, so we need
+ * to handle all of them.
+ * Interrupts know to fire when not enabled are:
+ * - EMAC_TX_DMA_STOP_INT
+ * - EMAC_TX_BUF_UA_INT
+ * - EMAC_TX_EARLY_INT
+ * - EMAC_RX_BUF_UA_INT
+ * - EMAC_RX_EARLY_INT
+ */
+static irqreturn_t sun8i_emac_dma_interrupt(int irq, void *dev_id)
+{
+	struct net_device *ndev = dev_id;
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+	u32 v, u;
+
+	v = readl(priv->base + EMAC_INT_STA);
+
+	/* When this bit is asserted, a frame transmission is completed. */
+	if (v & EMAC_TX_INT) {
+		priv->estats.tx_int++;
+		writel(0, priv->base + EMAC_INT_EN);
+		napi_schedule(&priv->napi);
+	}
+
+	/* When this bit is asserted, the TX DMA FSM is stopped.
+	 * For the moment only a call to tx_timeout cause this interrupt
+	 * to fire.
+	 */
+	if (v & EMAC_TX_DMA_STOP_INT)
+		priv->estats.tx_dma_stop++;
+
+	/* When this asserted, the TX DMA can not acquire next TX descriptor
+	 * and TX DMA FSM is suspended.
+	 */
+	if (v & EMAC_TX_BUF_UA_INT) {
+		priv->estats.tx_dma_ua++;
+		writel(0, priv->base + EMAC_INT_EN);
+		napi_schedule(&priv->napi);
+	}
+
+	if (v & EMAC_TX_TIMEOUT_INT)
+		priv->estats.tx_timeout_int++;
+
+	if (v & EMAC_TX_UNDERFLOW_INT)
+		priv->estats.tx_underflow_int++;
+
+	/* When this bit asserted , the frame is transmitted to FIFO totally. */
+	if (v & EMAC_TX_EARLY_INT)
+		priv->estats.tx_early_int++;
+
+	/* When this bit is asserted, a frame reception is completed  */
+	if (v & EMAC_RX_INT) {
+		priv->estats.rx_int++;
+		writel(0, priv->base + EMAC_INT_EN);
+		napi_schedule(&priv->napi);
+	}
+
+	/* When this asserted, the RX DMA can not acquire next RX descriptor
+	 * and RX DMA FSM is suspended.
+	 */
+	if (v & EMAC_RX_BUF_UA_INT) {
+		u = readl(priv->base + EMAC_RX_CTL1);
+		writel(u | EMAC_RX_DMA_START, priv->base + EMAC_RX_CTL1);
+		priv->estats.rx_dma_ua++;
+	}
+
+	/* Same as TX DMA STOP, but never hit it */
+	if (v & EMAC_RX_DMA_STOP_INT)
+		priv->estats.rx_dma_stop++;
+
+	if (v & EMAC_RX_TIMEOUT_INT)
+		priv->estats.rx_timeout_int++;
+
+	if (v & EMAC_RX_OVERFLOW_INT)
+		priv->estats.rx_overflow_int++;
+
+	if (v & EMAC_RX_EARLY_INT)
+		priv->estats.rx_early_int++;
+
+	if (v & EMAC_RGMII_STA_INT)
+		priv->estats.rgmii_state_int++;
+
+	/* the datasheet state those register as read-only
+	 * but nothing work(freeze) without writing to it
+	 */
+	writel(v, priv->base + EMAC_INT_STA);
+
+	return IRQ_HANDLED;
+}
+
+static int sun8i_emac_probe(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct sun8i_emac_priv *priv;
+	struct net_device *ndev;
+	struct resource *res;
+	int ret;
+
+	ndev = alloc_etherdev(sizeof(*priv));
+	if (!ndev)
+		return -ENOMEM;
+
+	SET_NETDEV_DEV(ndev, &pdev->dev);
+	priv = netdev_priv(ndev);
+	platform_set_drvdata(pdev, ndev);
+
+	priv->variant = of_device_get_match_data(&pdev->dev);
+	if (!priv->variant) {
+		dev_err(&pdev->dev, "Missing sun8i-emac variant\n");
+		return -EINVAL;
+	}
+
+	priv->mdio_node = of_get_child_by_name(node, "mdio");
+	if (!priv->mdio_node) {
+		netdev_err(ndev, "Could not find a MDIO node\n");
+		return -EINVAL;
+	}
+
+	priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
+	if (!priv->phy_node) {
+		netdev_err(ndev, "No associated PHY\n");
+		return -EINVAL;
+	}
+
+	priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
+						       "syscon");
+	if (IS_ERR(priv->regmap)) {
+		ret = PTR_ERR(priv->regmap);
+		dev_err(&pdev->dev, "unable to map SYSCON:%d\n", ret);
+		return ret;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	priv->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(priv->base)) {
+		ret = PTR_ERR(priv->base);
+		dev_err(&pdev->dev, "Cannot request MMIO: %d\n", ret);
+		return ret;
+	}
+
+	priv->ahb_clk = devm_clk_get(&pdev->dev, "ahb");
+	if (IS_ERR(priv->ahb_clk)) {
+		ret = PTR_ERR(priv->ahb_clk);
+		dev_err(&pdev->dev, "Cannot get AHB clock err=%d\n", ret);
+		goto probe_err;
+	}
+
+	priv->rst_mac = devm_reset_control_get_optional(&pdev->dev, "ahb");
+	if (IS_ERR(priv->rst_mac)) {
+		ret = PTR_ERR(priv->rst_mac);
+		if (ret == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_info(&pdev->dev, "No MAC reset control found %d\n", ret);
+		priv->rst_mac = NULL;
+	}
+
+	priv->phy_interface = of_get_phy_mode(node);
+	if (priv->phy_interface < 0) {
+		netdev_err(ndev, "PHY interface mode node unspecified\n");
+		return priv->phy_interface;
+	}
+
+	switch (priv->phy_interface) {
+	case PHY_INTERFACE_MODE_MII:
+		if (!priv->variant->support_mii)
+			return -EINVAL;
+		break;
+	case PHY_INTERFACE_MODE_RMII:
+		if (!priv->variant->support_rmii)
+			return -EINVAL;
+		break;
+	case PHY_INTERFACE_MODE_RGMII:
+		if (!priv->variant->support_rgmii)
+			return -EINVAL;
+		break;
+	default:
+		netdev_err(ndev, "Unsupported interface mode: %s",
+			   phy_modes(priv->phy_interface));
+		return -EINVAL;
+	}
+
+	if (priv->phy_interface == priv->variant->internal_phy)
+		priv->use_internal_phy = true;
+
+	if (priv->use_internal_phy) {
+		priv->ephy_clk = of_clk_get(priv->phy_node, 0);
+		if (IS_ERR(priv->ephy_clk)) {
+			ret = PTR_ERR(priv->ephy_clk);
+			dev_err(&pdev->dev, "Cannot get EPHY clock err=%d\n",
+				ret);
+			goto probe_err;
+		}
+
+		priv->rst_ephy = of_reset_control_get(priv->phy_node, 0);
+		if (IS_ERR(priv->rst_ephy)) {
+			ret = PTR_ERR(priv->rst_ephy);
+			if (ret == -EPROBE_DEFER)
+				goto probe_err;
+			dev_info(&pdev->dev,
+				 "No EPHY reset control found %d\n", ret);
+			priv->rst_ephy = NULL;
+		}
+	}
+
+	/* Optional regulator for PHY */
+	priv->regulator = devm_regulator_get_optional(&pdev->dev, "phy");
+	if (IS_ERR(priv->regulator)) {
+		if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) {
+			ret = -EPROBE_DEFER;
+			goto probe_err;
+		}
+		dev_dbg(&pdev->dev, "no PHY regulator found\n");
+		priv->regulator = NULL;
+	} else {
+		dev_info(&pdev->dev, "PHY regulator found\n");
+	}
+
+	priv->irq = platform_get_irq(pdev, 0);
+	if (priv->irq < 0) {
+		ret = priv->irq;
+		dev_err(&pdev->dev, "Cannot claim IRQ: %d\n", ret);
+		goto probe_err;
+	}
+
+	spin_lock_init(&priv->tx_lock);
+
+	ndev->netdev_ops = &sun8i_emac_netdev_ops;
+	ndev->ethtool_ops = &sun8i_emac_ethtool_ops;
+
+	priv->ndev = ndev;
+	priv->dev = &pdev->dev;
+
+	ndev->hw_features = NETIF_F_SG | NETIF_F_HIGHDMA;
+	ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
+		NETIF_F_RXCSUM;
+	ndev->features |= ndev->hw_features;
+	ndev->hw_features |= NETIF_F_RXFCS;
+	ndev->hw_features |= NETIF_F_RXALL;
+	ndev->hw_features |= NETIF_F_LOOPBACK;
+	ndev->priv_flags |= IFF_UNICAST_FLT;
+
+	ndev->watchdog_timeo = msecs_to_jiffies(5000);
+	netif_carrier_off(ndev);
+
+	/* Benched on OPIPC with 100M, setting more than 256 does not give any
+	 * perf boost
+	 */
+	priv->nbdesc_rx = 128;
+	priv->nbdesc_tx = 256;
+
+	ret = register_netdev(ndev);
+	if (ret) {
+		dev_err(&pdev->dev, "ERROR: Register %s failed\n", ndev->name);
+		goto probe_err;
+	}
+
+	return 0;
+
+probe_err:
+	free_netdev(ndev);
+	return ret;
+}
+
+static int sun8i_emac_remove(struct platform_device *pdev)
+{
+	struct net_device *ndev = platform_get_drvdata(pdev);
+	struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+	unregister_netdev(ndev);
+
+	reset_control_put(priv->rst_ephy);
+
+	platform_set_drvdata(pdev, NULL);
+	free_netdev(ndev);
+
+	return 0;
+}
+
+static const struct of_device_id sun8i_emac_of_match_table[] = {
+	{ .compatible = "allwinner,sun8i-a83t-emac",
+	  .data = &emac_variant_a83t },
+	{ .compatible = "allwinner,sun8i-h3-emac",
+	  .data = &emac_variant_h3 },
+	{ .compatible = "allwinner,sun50i-a64-emac",
+	  .data = &emac_variant_a64 },
+	{}
+};
+MODULE_DEVICE_TABLE(of, sun8i_emac_of_match_table);
+
+static struct platform_driver sun8i_emac_driver = {
+	.probe          = sun8i_emac_probe,
+	.remove         = sun8i_emac_remove,
+	.driver         = {
+		.name           = "sun8i-emac",
+		.of_match_table	= sun8i_emac_of_match_table,
+	},
+};
+
+module_platform_driver(sun8i_emac_driver);
+
+MODULE_DESCRIPTION("sun8i Ethernet driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("LABBE Corentin <clabbe.montjoie@gmail.com");
+
Download as text