[ar7] refresh 2.6.32 patches
[15.05/openwrt.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 @@ -1111,9 +1118,13 @@ static int __devinit cpmac_probe(struct
25         struct cpmac_priv *priv;
26         struct net_device *dev;
27         struct plat_cpmac_data *pdata;
28 +       void __iomem *mii_reg;
29 +       u32 tmp;
30 +       unsigned external_mii = 0;
31  
32         pdata = pdev->dev.platform_data;
33  
34 +detect_again:
35         for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
36                 if (!(pdata->phy_mask & (1 << phy_id)))
37                         continue;
38 @@ -1122,12 +1133,43 @@ static int __devinit cpmac_probe(struct
39                 strncpy(mdio_bus_id, cpmac_mii->id, MII_BUS_ID_SIZE);
40                 break;
41         }
42 -       
43 -       if (phy_id == PHY_MAX_ADDR) {
44 -               dev_err(&pdev->dev, "no PHY present\n");
45 -               return -ENODEV;
46 +
47 +       if (phy_id < PHY_MAX_ADDR && !external_mii)
48 +               goto dev_alloc;
49 +
50 +       /* Now disable EPHY and enable MII */
51 +       dev_info(&pdev->dev, "trying external MII\n");
52 +       ar7_device_disable(AR7_RESET_BIT_EPHY);
53 +
54 +       mii_reg = ioremap(AR7_REGS_MII, 4);
55 +       if (!mii_reg) {
56 +               dev_err(&pdev->dev, "failed to iorenamp MII_SEL\n");
57 +               return -ENOMEM;
58         }
59  
60 +       tmp = readl(mii_reg);
61 +       tmp |= 1;
62 +       writel(tmp, mii_reg);
63 +       external_mii++;
64 +
65 +       if (external_mii == 1)
66 +               goto detect_again;
67 +
68 +       if (phy_id < PHY_MAX_ADDR)
69 +               goto dev_alloc;
70 +
71 +       /* This still does not work, so now we register a fixed phy */
72 +       dev_info(&pdev->dev, "using fixed PHY\n");
73 +       rc = fixed_phy_add(PHY_POLL, pdev->id, &fixed_phy_status);
74 +       if (rc && rc != -ENODEV) {
75 +               dev_err(&pdev->dev, "unable to register fixed PHY\n");
76 +               return rc;
77 +       }
78 +
79 +       strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); /* fixed phys bus */
80 +       phy_id = pdev->id;
81 +
82 +dev_alloc:
83         dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
84  
85         if (!dev) {
86 --- a/arch/mips/include/asm/mach-ar7/ar7.h
87 +++ b/arch/mips/include/asm/mach-ar7/ar7.h
88 @@ -41,6 +41,7 @@
89  #define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
90  #define AR7_REGS_VLYNQ0        (AR7_REGS_BASE + 0x1800)
91  #define AR7_REGS_DCL   (AR7_REGS_BASE + 0x1a00)
92 +#define AR7_REGS_MII   (AR7_REGS_BASE + 0x1a08)
93  #define AR7_REGS_VLYNQ1        (AR7_REGS_BASE + 0x1c00)
94  #define AR7_REGS_MDIO  (AR7_REGS_BASE + 0x1e00)
95  #define AR7_REGS_IRQ   (AR7_REGS_BASE + 0x2400)