1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Applied Micro X-Gene SoC Ethernet v2 Driver
5 * Copyright (c) 2017, Applied Micro Circuits Corporation
6 * Author(s): Iyappan Subramanian <isubramanian@apm.com>
7 * Keyur Chudgar <kchudgar@apm.com>
12 void xge_mac_reset(struct xge_pdata
*pdata
)
14 xge_wr_csr(pdata
, MAC_CONFIG_1
, SOFT_RESET
);
15 xge_wr_csr(pdata
, MAC_CONFIG_1
, 0);
18 void xge_mac_set_speed(struct xge_pdata
*pdata
)
20 u32 icm0
, icm2
, ecm0
, mc2
;
23 icm0
= xge_rd_csr(pdata
, ICM_CONFIG0_REG_0
);
24 icm2
= xge_rd_csr(pdata
, ICM_CONFIG2_REG_0
);
25 ecm0
= xge_rd_csr(pdata
, ECM_CONFIG0_REG_0
);
26 rgmii
= xge_rd_csr(pdata
, RGMII_REG_0
);
27 mc2
= xge_rd_csr(pdata
, MAC_CONFIG_2
);
28 intf_ctrl
= xge_rd_csr(pdata
, INTERFACE_CONTROL
);
29 icm2
|= CFG_WAITASYNCRD_EN
;
31 switch (pdata
->phy_speed
) {
33 SET_REG_BITS(&mc2
, INTF_MODE
, 1);
34 SET_REG_BITS(&intf_ctrl
, HD_MODE
, 0);
35 SET_REG_BITS(&icm0
, CFG_MACMODE
, 0);
36 SET_REG_BITS(&icm2
, CFG_WAITASYNCRD
, 500);
37 SET_REG_BIT(&rgmii
, CFG_SPEED_125
, 0);
40 SET_REG_BITS(&mc2
, INTF_MODE
, 1);
41 SET_REG_BITS(&intf_ctrl
, HD_MODE
, 1);
42 SET_REG_BITS(&icm0
, CFG_MACMODE
, 1);
43 SET_REG_BITS(&icm2
, CFG_WAITASYNCRD
, 80);
44 SET_REG_BIT(&rgmii
, CFG_SPEED_125
, 0);
47 SET_REG_BITS(&mc2
, INTF_MODE
, 2);
48 SET_REG_BITS(&intf_ctrl
, HD_MODE
, 2);
49 SET_REG_BITS(&icm0
, CFG_MACMODE
, 2);
50 SET_REG_BITS(&icm2
, CFG_WAITASYNCRD
, 16);
51 SET_REG_BIT(&rgmii
, CFG_SPEED_125
, 1);
55 mc2
|= FULL_DUPLEX
| CRC_EN
| PAD_CRC
;
56 SET_REG_BITS(&ecm0
, CFG_WFIFOFULLTHR
, 0x32);
58 xge_wr_csr(pdata
, MAC_CONFIG_2
, mc2
);
59 xge_wr_csr(pdata
, INTERFACE_CONTROL
, intf_ctrl
);
60 xge_wr_csr(pdata
, RGMII_REG_0
, rgmii
);
61 xge_wr_csr(pdata
, ICM_CONFIG0_REG_0
, icm0
);
62 xge_wr_csr(pdata
, ICM_CONFIG2_REG_0
, icm2
);
63 xge_wr_csr(pdata
, ECM_CONFIG0_REG_0
, ecm0
);
66 void xge_mac_set_station_addr(struct xge_pdata
*pdata
)
68 u8
*dev_addr
= pdata
->ndev
->dev_addr
;
71 addr0
= (dev_addr
[3] << 24) | (dev_addr
[2] << 16) |
72 (dev_addr
[1] << 8) | dev_addr
[0];
73 addr1
= (dev_addr
[5] << 24) | (dev_addr
[4] << 16);
75 xge_wr_csr(pdata
, STATION_ADDR0
, addr0
);
76 xge_wr_csr(pdata
, STATION_ADDR1
, addr1
);
79 void xge_mac_init(struct xge_pdata
*pdata
)
82 xge_mac_set_speed(pdata
);
83 xge_mac_set_station_addr(pdata
);
86 void xge_mac_enable(struct xge_pdata
*pdata
)
90 data
= xge_rd_csr(pdata
, MAC_CONFIG_1
);
91 data
|= TX_EN
| RX_EN
;
92 xge_wr_csr(pdata
, MAC_CONFIG_1
, data
);
94 data
= xge_rd_csr(pdata
, MAC_CONFIG_1
);
97 void xge_mac_disable(struct xge_pdata
*pdata
)
101 data
= xge_rd_csr(pdata
, MAC_CONFIG_1
);
102 data
&= ~(TX_EN
| RX_EN
);
103 xge_wr_csr(pdata
, MAC_CONFIG_1
, data
);