backport r22727, r22728, r22770 and r22771
[openwrt/svn-archive/archive.git] / target / linux / ar7 / patches-2.6.32 / 972-cpmac_multi_probe.patch
1 --- a/drivers/net/cpmac.c
2 +++ b/drivers/net/cpmac.c
3 @@ -33,6 +33,7 @@
4 #include <linux/skbuff.h>
5 #include <linux/mii.h>
6 #include <linux/phy.h>
7 +#include <linux/phy_fixed.h>
8 #include <linux/platform_device.h>
9 #include <linux/dma-mapping.h>
10 #include <asm/gpio.h>
11 @@ -217,6 +218,12 @@ static void cpmac_hw_stop(struct net_dev
12 static int cpmac_stop(struct net_device *dev);
13 static int cpmac_open(struct net_device *dev);
14
15 +static struct fixed_phy_status fixed_phy_status = {
16 + .link = 1,
17 + .speed = 100,
18 + .duplex = 1,
19 +};
20 +
21 static void cpmac_dump_regs(struct net_device *dev)
22 {
23 int i;
24 @@ -1122,12 +1129,39 @@ static int __devinit cpmac_probe(struct
25 strncpy(mdio_bus_id, cpmac_mii->id, MII_BUS_ID_SIZE);
26 break;
27 }
28 -
29 - if (phy_id == PHY_MAX_ADDR) {
30 - dev_err(&pdev->dev, "no PHY present\n");
31 - return -ENODEV;
32 +
33 + if (phy_id < PHY_MAX_ADDR)
34 + goto dev_alloc;
35 +
36 + dev_info(&pdev->dev, "trying external MII\n");
37 + /* Now disable EPHY and enable MII */
38 + ar7_device_disable(AR7_RESET_BIT_EPHY);
39 + *(unsigned long*) ioremap(0x08611A08, 4) |= 0x00000001;
40 +
41 + for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
42 + if (!(pdata->phy_mask & (1 << phy_id)))
43 + continue;
44 + if (!cpmac_mii->phy_map[phy_id])
45 + continue;
46 + strncpy(mdio_bus_id, cpmac_mii->id, MII_BUS_ID_SIZE);
47 + break;
48 + }
49 +
50 + if (phy_id < PHY_MAX_ADDR)
51 + goto dev_alloc;
52 +
53 + /* This still does not work, so now we register a fixed phy */
54 + dev_info(&pdev->dev, "using fixed PHY\n");
55 + rc = fixed_phy_add(PHY_POLL, pdev->id, &fixed_phy_status);
56 + if (rc && rc != -ENODEV) {
57 + dev_err(&pdev->dev, "unable to register fixed PHY\n");
58 + return rc;
59 }
60
61 + strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); /* fixed phys bus */
62 + phy_id = pdev->id;
63 +
64 +dev_alloc:
65 dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
66
67 if (!dev) {