1 /*
2  * Applied Micro X-Gene SoC Ethernet v2 Driver
3  *
4  * Copyright (c) 2017, Applied Micro Circuits Corporation
5  * Author(s): Iyappan Subramanian <isubramanian@apm.com>
6  *	      Keyur Chudgar <kchudgar@apm.com>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "main.h"
23 
24 void xge_wr_csr(struct xge_pdata *pdata, u32 offset, u32 val)
25 {
26 	void __iomem *addr = pdata->resources.base_addr + offset;
27 
28 	iowrite32(val, addr);
29 }
30 
31 u32 xge_rd_csr(struct xge_pdata *pdata, u32 offset)
32 {
33 	void __iomem *addr = pdata->resources.base_addr + offset;
34 
35 	return ioread32(addr);
36 }
37 
38 int xge_port_reset(struct net_device *ndev)
39 {
40 	struct xge_pdata *pdata = netdev_priv(ndev);
41 
42 	xge_wr_csr(pdata, ENET_SRST, 0x3);
43 	xge_wr_csr(pdata, ENET_SRST, 0x2);
44 	xge_wr_csr(pdata, ENET_SRST, 0x0);
45 
46 	xge_wr_csr(pdata, ENET_SHIM, DEVM_ARAUX_COH | DEVM_AWAUX_COH);
47 
48 	return 0;
49 }
50 
51 static void xge_traffic_resume(struct net_device *ndev)
52 {
53 	struct xge_pdata *pdata = netdev_priv(ndev);
54 
55 	xge_wr_csr(pdata, CFG_FORCE_LINK_STATUS_EN, 1);
56 	xge_wr_csr(pdata, FORCE_LINK_STATUS, 1);
57 
58 	xge_wr_csr(pdata, CFG_LINK_AGGR_RESUME, 1);
59 	xge_wr_csr(pdata, RX_DV_GATE_REG, 1);
60 }
61 
62 int xge_port_init(struct net_device *ndev)
63 {
64 	struct xge_pdata *pdata = netdev_priv(ndev);
65 
66 	pdata->phy_speed = SPEED_1000;
67 	xge_mac_init(pdata);
68 	xge_traffic_resume(ndev);
69 
70 	return 0;
71 }
72