aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ixp4xx/patches-4.1/205-npe_driver_separate_phy_functions.patch
blob: 6d1eb7bfbb61e870ce3cf7708837144be88aec8e (plain)
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
From e3eab80fb5d0a7d7fdb0f2f231b27161d5ec3804 Mon Sep 17 00:00:00 2001
From: Jonas Gorski <jogo@openwrt.org>
Date: Sun, 30 Jun 2013 15:52:53 +0200
Subject: [PATCH 23/36] 205-npe_driver_separate_phy_functions.patch

---
 drivers/net/ethernet/xscale/ixp4xx_eth.c |   70 ++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 19 deletions(-)

--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -589,6 +589,51 @@ static void ixp4xx_adjust_link(struct ne
 	       dev->name, port->speed, port->duplex ? "full" : "half");
 }
 
+static int ixp4xx_phy_connect(struct net_device *dev)
+{
+	struct port *port = netdev_priv(dev);
+	struct eth_plat_info *plat = port->plat;
+	char phy_id[MII_BUS_ID_SIZE + 3];
+
+	snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
+		mdio_bus->id, plat->phy);
+	port->phydev = phy_connect(dev, phy_id, &ixp4xx_adjust_link,
+				   PHY_INTERFACE_MODE_MII);
+	if (IS_ERR(port->phydev)) {
+		printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
+		return PTR_ERR(port->phydev);
+	}
+
+	/* mask with MAC supported features */
+	port->phydev->supported &= PHY_BASIC_FEATURES;
+	port->phydev->advertising = port->phydev->supported;
+
+	port->phydev->irq = PHY_POLL;
+
+	return 0;
+}
+
+static void ixp4xx_phy_disconnect(struct net_device *dev)
+{
+	struct port *port = netdev_priv(dev);
+
+	phy_disconnect(port->phydev);
+}
+
+static void ixp4xx_phy_start(struct net_device *dev)
+{
+	struct port *port = netdev_priv(dev);
+
+	port->speed = 0;	/* force "link up" message */
+	phy_start(port->phydev);
+}
+
+static void ixp4xx_phy_stop(struct net_device *dev)
+{
+	struct port *port = netdev_priv(dev);
+
+	phy_stop(port->phydev);
+}
 
 static inline void debug_pkt(struct net_device *dev, const char *func,
 			     u8 *data, int len)
@@ -1259,8 +1304,7 @@ static int eth_open(struct net_device *d
 		return err;
 	}
 
-	port->speed = 0;	/* force "link up" message */
-	phy_start(port->phydev);
+	ixp4xx_phy_start(dev);
 
 	for (i = 0; i < ETH_ALEN; i++)
 		__raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
@@ -1381,7 +1425,7 @@ static int eth_close(struct net_device *
 		printk(KERN_CRIT "%s: unable to disable loopback\n",
 		       dev->name);
 
-	phy_stop(port->phydev);
+	ixp4xx_phy_stop(dev);
 
 	if (!ports_open)
 		qmgr_disable_irq(TXDONE_QUEUE);
@@ -1407,7 +1451,6 @@ static int eth_init_one(struct platform_
 	struct net_device *dev;
 	struct eth_plat_info *plat = dev_get_platdata(&pdev->dev);
 	u32 regs_phys;
-	char phy_id[MII_BUS_ID_SIZE + 3];
 	int err;
 
 	if (!(dev = alloc_etherdev(sizeof(struct port))))
@@ -1465,20 +1508,9 @@ static int eth_init_one(struct platform_
 	__raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
 	udelay(50);
 
-	snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
-		mdio_bus->id, plat->phy);
-	port->phydev = phy_connect(dev, phy_id, &ixp4xx_adjust_link,
-				   PHY_INTERFACE_MODE_MII);
-	if (IS_ERR(port->phydev)) {
-		err = PTR_ERR(port->phydev);
+	err = ixp4xx_phy_connect(dev);
+	if (err)
 		goto err_free_mem;
-	}
-
-	/* mask with MAC supported features */
-	port->phydev->supported &= PHY_BASIC_FEATURES;
-	port->phydev->advertising = port->phydev->supported;
-
-	port->phydev->irq = PHY_POLL;
 
 	if ((err = register_netdev(dev)))
 		goto err_phy_dis;
@@ -1489,7 +1521,7 @@ static int eth_init_one(struct platform_
 	return 0;
 
 err_phy_dis:
-	phy_disconnect(port->phydev);
+	ixp4xx_phy_disconnect(dev);
 err_free_mem:
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	release_resource(port->mem_res);
@@ -1506,7 +1538,7 @@ static int eth_remove_one(struct platfor
 	struct port *port = netdev_priv(dev);
 
 	unregister_netdev(dev);
-	phy_disconnect(port->phydev);
+	ixp4xx_phy_disconnect(dev);
 	npe_port_tab[NPE_ID(port->id)] = NULL;
 	npe_release(port->npe);
 	release_resource(port->mem_res);