summaryrefslogtreecommitdiffstats
path: root/target/linux/ar7/patches-3.3/972-cpmac_fixup.patch
blob: 468c0d8c38e0a9f75e3104f60217ae900e09000d (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
--- a/arch/mips/ar7/platform.c
+++ b/arch/mips/ar7/platform.c
@@ -712,26 +712,23 @@ static int __init ar7_register_devices(v
 	}
 
 	if (ar7_has_high_cpmac()) {
+		cpmac_get_mac(0, cpmac_high_data.dev_addr);
+
 		res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
-		if (!res) {
-			cpmac_get_mac(1, cpmac_high_data.dev_addr);
+		if (!res)
+			pr_warning("unable to register fixed phy for cpmac-high: %d\n", res);
 
-			res = platform_device_register(&cpmac_high);
-			if (res)
-				pr_warning("unable to register cpmac-high: %d\n", res);
-		} else
-			pr_warning("unable to add cpmac-high phy: %d\n", res);
-	} else
+		res = platform_device_register(&cpmac_high);
+		if (res)
+			pr_warning("unable to register cpmac-high: %d\n", res);
+		cpmac_get_mac(1, cpmac_low_data.dev_addr);
+	} else {
 		cpmac_low_data.phy_mask = 0xffffffff;
-
-	res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
-	if (!res) {
 		cpmac_get_mac(0, cpmac_low_data.dev_addr);
-		res = platform_device_register(&cpmac_low);
-		if (res)
-			pr_warning("unable to register cpmac-low: %d\n", res);
-	} else
-		pr_warning("unable to add cpmac-low phy: %d\n", res);
+	}
+	res = platform_device_register(&cpmac_low);
+	if (res)
+		pr_warning("unable to register cpmac-low: %d\n", res);
 
 	detect_leds();
 	res = platform_device_register(&ar7_gpio_leds);
@@ -744,8 +741,10 @@ static int __init ar7_register_devices(v
 
 	/* Register watchdog only if enabled in hardware */
 	bootcr = ioremap_nocache(AR7_REGS_DCL, 4);
-	val = readl(bootcr);
-	iounmap(bootcr);
+	if (bootcr) {
+		val = readl(bootcr);
+		iounmap(bootcr);
+	}
 	if (val & AR7_WDT_HW_ENA) {
 		if (ar7_has_high_vlynq())
 			ar7_wdt_res.start = UR8_REGS_WDT;
--- a/arch/mips/include/asm/mach-ar7/ar7.h
+++ b/arch/mips/include/asm/mach-ar7/ar7.h
@@ -42,6 +42,7 @@
 #define AR7_REGS_PINSEL (AR7_REGS_BASE + 0x160C)
 #define AR7_REGS_VLYNQ0	(AR7_REGS_BASE + 0x1800)
 #define AR7_REGS_DCL	(AR7_REGS_BASE + 0x1a00)
+#define AR7_REGS_MII	(AR7_REGS_BASE + 0x1a08)
 #define AR7_REGS_VLYNQ1	(AR7_REGS_BASE + 0x1c00)
 #define AR7_REGS_MDIO	(AR7_REGS_BASE + 0x1e00)
 #define AR7_REGS_IRQ	(AR7_REGS_BASE + 0x2400)
--- a/drivers/net/ethernet/ti/cpmac.c
+++ b/drivers/net/ethernet/ti/cpmac.c
@@ -35,7 +35,6 @@
 #include <linux/skbuff.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
-#include <linux/phy_fixed.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/clk.h>
@@ -48,14 +47,11 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:cpmac");
 
 static int debug_level = 8;
-static int dumb_switch;
 
-/* Next 2 are only used in cpmac_probe, so it's pointless to change them */
+/* Next is only used in cpmac_probe, so it's pointless to change them */
 module_param(debug_level, int, 0444);
-module_param(dumb_switch, int, 0444);
 
 MODULE_PARM_DESC(debug_level, "Number of NETIF_MSG bits to enable");
-MODULE_PARM_DESC(dumb_switch, "Assume switch is not connected to MDIO bus");
 
 #define CPMAC_VERSION "0.5.2"
 /* frame size + 802.1q tag + FCS size */
@@ -674,9 +670,8 @@ static void cpmac_hw_start(struct net_de
 	for (i = 0; i < 8; i++)
 		cpmac_write(priv->regs, CPMAC_MAC_ADDR_LO(i), dev->dev_addr[5]);
 	cpmac_write(priv->regs, CPMAC_MAC_ADDR_MID, dev->dev_addr[4]);
-	cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, dev->dev_addr[0] |
-		    (dev->dev_addr[1] << 8) | (dev->dev_addr[2] << 16) |
-		    (dev->dev_addr[3] << 24));
+	cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, be32_to_cpu(*(u32 *)
+			dev->dev_addr));
 	cpmac_write(priv->regs, CPMAC_MAX_LENGTH, CPMAC_SKB_SIZE);
 	cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff);
 	cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff);
@@ -1121,25 +1116,19 @@ static int __devinit cpmac_probe(struct
 
 	pdata = pdev->dev.platform_data;
 
-	if (external_switch || dumb_switch) {
-		strncpy(mdio_bus_id, "fixed-0", MII_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, MII_BUS_ID_SIZE);
-			break;
-		}
+	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, MII_BUS_ID_SIZE);
+		break;
 	}
 
-	if (phy_id == PHY_MAX_ADDR) {
-		dev_err(&pdev->dev, "no PHY present, falling back "
-					"to switch on MDIO bus 0\n");
-		strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); /* fixed phys bus */
+	if (phy_id == PHY_MAX_ADDR && pdev->id == 1) {
+		printk(KERN_ERR "cpmac: No PHY present, using fixed PHY\n");
 		phy_id = pdev->id;
+		strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
 	}
 
 	dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
@@ -1178,6 +1167,13 @@ static int __devinit cpmac_probe(struct
 	snprintf(priv->phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT,
 						mdio_bus_id, phy_id);
 
+	rc = register_netdev(dev);
+	if (rc) {
+		printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
+		       dev->name);
+		goto fail;
+	}
+
 	priv->phy = phy_connect(dev, priv->phy_name, cpmac_adjust_link, 0,
 						PHY_INTERFACE_MODE_MII);
 
@@ -1189,13 +1185,6 @@ static int __devinit cpmac_probe(struct
 		goto fail;
 	}
 
-	rc = register_netdev(dev);
-	if (rc) {
-		printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
-		       dev->name);
-		goto fail;
-	}
-
 	if (netif_msg_probe(priv)) {
 		printk(KERN_INFO
 		       "cpmac: device %s (regs: %p, irq: %d, phy: %s, "
@@ -1228,6 +1217,7 @@ int __devinit cpmac_init(void)
 {
 	u32 mask;
 	int i, res;
+	void __iomem *mii_reg;
 
 	cpmac_mii = mdiobus_alloc();
 	if (cpmac_mii == NULL)
@@ -1251,31 +1241,51 @@ int __devinit cpmac_init(void)
 	ar7_gpio_disable(26);
 	ar7_gpio_disable(27);
 
-	if (!ar7_is_titan()) {
+	if (ar7_is_titan()) {
+		ar7_device_reset(AR7_RESET_BIT_EPHY);
+		ar7_device_reset(TITAN_RESET_BIT_EPHY1);
+	} else {
+		ar7_device_reset(AR7_RESET_BIT_EPHY);
 		ar7_device_reset(AR7_RESET_BIT_CPMAC_LO);
 		ar7_device_reset(AR7_RESET_BIT_CPMAC_HI);
 	}
-	ar7_device_reset(AR7_RESET_BIT_EPHY);
-
-	if (ar7_is_titan())
-		ar7_device_reset(TITAN_RESET_BIT_EPHY1);
 
 	cpmac_mii->reset(cpmac_mii);
 
 	for (i = 0; i < 300; i++) {
 		mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE);
+		mask &= ar7_is_titan()? ~(0x80000000 | 0x40000000) : ~(0x80000000);
 		if (mask)
 			break;
 		else
 			msleep(10);
 	}
 
-	mask &= 0x7fffffff;
 	if (mask & (mask - 1)) {
 		external_switch = 1;
-		mask = 0;
+		if (!ar7_has_high_cpmac()) {
+			if (ar7_is_titan()) {
+				ar7_device_disable(AR7_RESET_BIT_EPHY);
+				ar7_device_disable(TITAN_RESET_BIT_EPHY1);
+			} else
+				ar7_device_disable(AR7_RESET_BIT_EPHY);
+
+			//Titan remap might be different
+			mii_reg = ioremap(AR7_REGS_MII, 4);
+			if (mii_reg) {
+				writel(readl(mii_reg) | 1, mii_reg);
+				iounmap(mii_reg);
+			}
+		}
 	}
 
+	if (external_switch)
+		printk(KERN_INFO "EXTERNAL SWITCH!!!\n");
+	else if (mask)
+		printk(KERN_INFO "EXTERNAL PHY!!!\n");
+	else
+		printk(KERN_INFO "INTERNAL PHY!!!\n");
+
 	if (ar7_is_titan())
 		cpmac_mii->phy_mask = ~(mask | 0x80000000 | 0x40000000);
 	else