aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ar7/patches-2.6.27/910-cpmac_fixed_phy.patch
blob: dd4bb76a35e964e1a594c4c80df353adf1f6161b (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
This is a hack to make cpmac work with the external switch on a DG834 v3; it
should also work on other similar routers. It has not been tested on hardware
with multiple cpmac devices or with no external switch. It may be safer to
move external_switch to pdata rather than trying to detect it, and to set
phy_mask correctly rather than moving the phy search loop.

--- a/drivers/net/cpmac.c	2008-11-11 06:18:24.000000000 +1100
+++ b/drivers/net/cpmac.c	2009-04-11 10:58:58.000000000 +1000
@@ -1124,8 +1124,8 @@
 
 static int __devinit cpmac_probe(struct platform_device *pdev)
 {
	int rc, phy_id;
-	char *mdio_bus_id = "0";
+	char mdio_bus_id[BUS_ID_SIZE];
 	struct resource *mem;
 	struct cpmac_priv *priv;
 	struct net_device *dev;
@@ -1134,22 +1134,23 @@
 
 	pdata = pdev->dev.platform_data;
 
-	for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
-		if (!(pdata->phy_mask & (1 << phy_id)))
-			continue;
-		if (!cpmac_mii.phy_map[phy_id])
-			continue;
-		break;
+	if (external_switch || dumb_switch) {
+		strncpy(mdio_bus_id, "0", BUS_ID_SIZE); /* fixed phys bus */
+		phy_id = pdev->id;
+	} else {
+		for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
+			if (!(pdata->phy_mask & (1 << phy_id)))
+				continue;
+			if (!cpmac_mii.phy_map[phy_id])
+				continue;
+			strncpy(mdio_bus_id, cpmac_mii.id, BUS_ID_SIZE);
+			break;
+		}
 	}
 
 	if (phy_id == PHY_MAX_ADDR) {
-		if (external_switch || dumb_switch) {
-			mdio_bus_id = 0; /* fixed phys bus */
-			phy_id = pdev->id;
-		} else {
-			dev_err(&pdev->dev, "no PHY present\n");
-			return -ENODEV;
-		}
+		dev_err(&pdev->dev, "no PHY present\n");
+		return -ENODEV;
 	}
 
 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
@@ -1189,9 +1190,11 @@
 	priv->ring_size = 64;
 	priv->msg_enable = netif_msg_init(debug_level, 0xff);
 	memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
+	
+	snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
 
-	priv->phy = phy_connect(dev, cpmac_mii.phy_map[phy_id]->dev.bus_id,
-				&cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
+	priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
+	 			PHY_INTERFACE_MODE_MII);
 	if (IS_ERR(priv->phy)) {
 		if (netif_msg_drv(priv))
 			printk(KERN_ERR "%s: Could not attach to PHY\n",
@@ -1250,11 +1253,11 @@
 
 	cpmac_mii.reset(&cpmac_mii);
 
-	for (i = 0; i < 300000; i++)
+	for (i = 0; i < 300; i++)
 		if ((mask = cpmac_read(cpmac_mii.priv, CPMAC_MDIO_ALIVE)))
 			break;
 		else
-			cpu_relax();
+			msleep(10);
 
 	mask &= 0x7fffffff;
 	if (mask & (mask - 1)) {
@@ -1267,7 +1270,7 @@
 	}
 
 	cpmac_mii.phy_mask = ~(mask | 0x80000000);
-	snprintf(cpmac_mii.id, MII_BUS_ID_SIZE, "0");
+	snprintf(cpmac_mii.id, MII_BUS_ID_SIZE, "1");
 
 	res = mdiobus_register(&cpmac_mii);
 	if (res)