11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
281ccd0caSIyappan Subramanian /*
381ccd0caSIyappan Subramanian * Applied Micro X-Gene SoC Ethernet v2 Driver
481ccd0caSIyappan Subramanian *
581ccd0caSIyappan Subramanian * Copyright (c) 2017, Applied Micro Circuits Corporation
681ccd0caSIyappan Subramanian * Author(s): Iyappan Subramanian <isubramanian@apm.com>
781ccd0caSIyappan Subramanian * Keyur Chudgar <kchudgar@apm.com>
881ccd0caSIyappan Subramanian */
981ccd0caSIyappan Subramanian
1081ccd0caSIyappan Subramanian #include "main.h"
1181ccd0caSIyappan Subramanian
xge_mac_reset(struct xge_pdata * pdata)1281ccd0caSIyappan Subramanian void xge_mac_reset(struct xge_pdata *pdata)
1381ccd0caSIyappan Subramanian {
1481ccd0caSIyappan Subramanian xge_wr_csr(pdata, MAC_CONFIG_1, SOFT_RESET);
1581ccd0caSIyappan Subramanian xge_wr_csr(pdata, MAC_CONFIG_1, 0);
1681ccd0caSIyappan Subramanian }
1781ccd0caSIyappan Subramanian
xge_mac_set_speed(struct xge_pdata * pdata)18ea8ab16aSIyappan Subramanian void xge_mac_set_speed(struct xge_pdata *pdata)
1981ccd0caSIyappan Subramanian {
2081ccd0caSIyappan Subramanian u32 icm0, icm2, ecm0, mc2;
2181ccd0caSIyappan Subramanian u32 intf_ctrl, rgmii;
2281ccd0caSIyappan Subramanian
2381ccd0caSIyappan Subramanian icm0 = xge_rd_csr(pdata, ICM_CONFIG0_REG_0);
2481ccd0caSIyappan Subramanian icm2 = xge_rd_csr(pdata, ICM_CONFIG2_REG_0);
2581ccd0caSIyappan Subramanian ecm0 = xge_rd_csr(pdata, ECM_CONFIG0_REG_0);
2681ccd0caSIyappan Subramanian rgmii = xge_rd_csr(pdata, RGMII_REG_0);
2781ccd0caSIyappan Subramanian mc2 = xge_rd_csr(pdata, MAC_CONFIG_2);
2881ccd0caSIyappan Subramanian intf_ctrl = xge_rd_csr(pdata, INTERFACE_CONTROL);
2981ccd0caSIyappan Subramanian icm2 |= CFG_WAITASYNCRD_EN;
3081ccd0caSIyappan Subramanian
3181ccd0caSIyappan Subramanian switch (pdata->phy_speed) {
3281ccd0caSIyappan Subramanian case SPEED_10:
3381ccd0caSIyappan Subramanian SET_REG_BITS(&mc2, INTF_MODE, 1);
3481ccd0caSIyappan Subramanian SET_REG_BITS(&intf_ctrl, HD_MODE, 0);
3581ccd0caSIyappan Subramanian SET_REG_BITS(&icm0, CFG_MACMODE, 0);
3681ccd0caSIyappan Subramanian SET_REG_BITS(&icm2, CFG_WAITASYNCRD, 500);
3781ccd0caSIyappan Subramanian SET_REG_BIT(&rgmii, CFG_SPEED_125, 0);
3881ccd0caSIyappan Subramanian break;
3981ccd0caSIyappan Subramanian case SPEED_100:
4081ccd0caSIyappan Subramanian SET_REG_BITS(&mc2, INTF_MODE, 1);
4181ccd0caSIyappan Subramanian SET_REG_BITS(&intf_ctrl, HD_MODE, 1);
4281ccd0caSIyappan Subramanian SET_REG_BITS(&icm0, CFG_MACMODE, 1);
4381ccd0caSIyappan Subramanian SET_REG_BITS(&icm2, CFG_WAITASYNCRD, 80);
4481ccd0caSIyappan Subramanian SET_REG_BIT(&rgmii, CFG_SPEED_125, 0);
4581ccd0caSIyappan Subramanian break;
4681ccd0caSIyappan Subramanian default:
4781ccd0caSIyappan Subramanian SET_REG_BITS(&mc2, INTF_MODE, 2);
4881ccd0caSIyappan Subramanian SET_REG_BITS(&intf_ctrl, HD_MODE, 2);
4981ccd0caSIyappan Subramanian SET_REG_BITS(&icm0, CFG_MACMODE, 2);
5081ccd0caSIyappan Subramanian SET_REG_BITS(&icm2, CFG_WAITASYNCRD, 16);
5181ccd0caSIyappan Subramanian SET_REG_BIT(&rgmii, CFG_SPEED_125, 1);
5281ccd0caSIyappan Subramanian break;
5381ccd0caSIyappan Subramanian }
5481ccd0caSIyappan Subramanian
5581ccd0caSIyappan Subramanian mc2 |= FULL_DUPLEX | CRC_EN | PAD_CRC;
5681ccd0caSIyappan Subramanian SET_REG_BITS(&ecm0, CFG_WFIFOFULLTHR, 0x32);
5781ccd0caSIyappan Subramanian
5881ccd0caSIyappan Subramanian xge_wr_csr(pdata, MAC_CONFIG_2, mc2);
5981ccd0caSIyappan Subramanian xge_wr_csr(pdata, INTERFACE_CONTROL, intf_ctrl);
6081ccd0caSIyappan Subramanian xge_wr_csr(pdata, RGMII_REG_0, rgmii);
6181ccd0caSIyappan Subramanian xge_wr_csr(pdata, ICM_CONFIG0_REG_0, icm0);
6281ccd0caSIyappan Subramanian xge_wr_csr(pdata, ICM_CONFIG2_REG_0, icm2);
6381ccd0caSIyappan Subramanian xge_wr_csr(pdata, ECM_CONFIG0_REG_0, ecm0);
6481ccd0caSIyappan Subramanian }
6581ccd0caSIyappan Subramanian
xge_mac_set_station_addr(struct xge_pdata * pdata)6681ccd0caSIyappan Subramanian void xge_mac_set_station_addr(struct xge_pdata *pdata)
6781ccd0caSIyappan Subramanian {
68*76660757SJakub Kicinski const u8 *dev_addr = pdata->ndev->dev_addr;
6970dbd9b2SIyappan Subramanian u32 addr0, addr1;
7081ccd0caSIyappan Subramanian
7181ccd0caSIyappan Subramanian addr0 = (dev_addr[3] << 24) | (dev_addr[2] << 16) |
7281ccd0caSIyappan Subramanian (dev_addr[1] << 8) | dev_addr[0];
7381ccd0caSIyappan Subramanian addr1 = (dev_addr[5] << 24) | (dev_addr[4] << 16);
7481ccd0caSIyappan Subramanian
7581ccd0caSIyappan Subramanian xge_wr_csr(pdata, STATION_ADDR0, addr0);
7681ccd0caSIyappan Subramanian xge_wr_csr(pdata, STATION_ADDR1, addr1);
7781ccd0caSIyappan Subramanian }
7881ccd0caSIyappan Subramanian
xge_mac_init(struct xge_pdata * pdata)7981ccd0caSIyappan Subramanian void xge_mac_init(struct xge_pdata *pdata)
8081ccd0caSIyappan Subramanian {
8181ccd0caSIyappan Subramanian xge_mac_reset(pdata);
8281ccd0caSIyappan Subramanian xge_mac_set_speed(pdata);
8381ccd0caSIyappan Subramanian xge_mac_set_station_addr(pdata);
8481ccd0caSIyappan Subramanian }
8581ccd0caSIyappan Subramanian
xge_mac_enable(struct xge_pdata * pdata)8681ccd0caSIyappan Subramanian void xge_mac_enable(struct xge_pdata *pdata)
8781ccd0caSIyappan Subramanian {
8881ccd0caSIyappan Subramanian u32 data;
8981ccd0caSIyappan Subramanian
9081ccd0caSIyappan Subramanian data = xge_rd_csr(pdata, MAC_CONFIG_1);
9181ccd0caSIyappan Subramanian data |= TX_EN | RX_EN;
9281ccd0caSIyappan Subramanian xge_wr_csr(pdata, MAC_CONFIG_1, data);
9381ccd0caSIyappan Subramanian
9481ccd0caSIyappan Subramanian data = xge_rd_csr(pdata, MAC_CONFIG_1);
9581ccd0caSIyappan Subramanian }
9681ccd0caSIyappan Subramanian
xge_mac_disable(struct xge_pdata * pdata)9781ccd0caSIyappan Subramanian void xge_mac_disable(struct xge_pdata *pdata)
9881ccd0caSIyappan Subramanian {
9981ccd0caSIyappan Subramanian u32 data;
10081ccd0caSIyappan Subramanian
10181ccd0caSIyappan Subramanian data = xge_rd_csr(pdata, MAC_CONFIG_1);
10281ccd0caSIyappan Subramanian data &= ~(TX_EN | RX_EN);
10381ccd0caSIyappan Subramanian xge_wr_csr(pdata, MAC_CONFIG_1, data);
10481ccd0caSIyappan Subramanian }
105