kernel: update 3.10 to 3.10.34
[openwrt.git] / target / linux / ar7 / patches-3.10 / 972-cpmac_fixup.patch
1 --- a/arch/mips/ar7/platform.c
2 +++ b/arch/mips/ar7/platform.c
3 @@ -712,26 +712,23 @@ static int __init ar7_register_devices(v
4         }
5  
6         if (ar7_has_high_cpmac()) {
7 +               cpmac_get_mac(0, cpmac_high_data.dev_addr);
8 +
9                 res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
10 -               if (!res) {
11 -                       cpmac_get_mac(1, cpmac_high_data.dev_addr);
12 +               if (!res)
13 +                       pr_warning("unable to register fixed phy for cpmac-high: %d\n", res);
14  
15 -                       res = platform_device_register(&cpmac_high);
16 -                       if (res)
17 -                               pr_warning("unable to register cpmac-high: %d\n", res);
18 -               } else
19 -                       pr_warning("unable to add cpmac-high phy: %d\n", res);
20 -       } else
21 +               res = platform_device_register(&cpmac_high);
22 +               if (res)
23 +                       pr_warning("unable to register cpmac-high: %d\n", res);
24 +               cpmac_get_mac(1, cpmac_low_data.dev_addr);
25 +       } else {
26                 cpmac_low_data.phy_mask = 0xffffffff;
27 -
28 -       res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
29 -       if (!res) {
30                 cpmac_get_mac(0, cpmac_low_data.dev_addr);
31 -               res = platform_device_register(&cpmac_low);
32 -               if (res)
33 -                       pr_warning("unable to register cpmac-low: %d\n", res);
34 -       } else
35 -               pr_warning("unable to add cpmac-low phy: %d\n", res);
36 +       }
37 +       res = platform_device_register(&cpmac_low);
38 +       if (res)
39 +               pr_warning("unable to register cpmac-low: %d\n", res);
40  
41         detect_leds();
42         res = platform_device_register(&ar7_gpio_leds);
43 --- a/arch/mips/include/asm/mach-ar7/ar7.h
44 +++ b/arch/mips/include/asm/mach-ar7/ar7.h
45 @@ -42,6 +42,7 @@
46  #define AR7_REGS_PINSEL (AR7_REGS_BASE + 0x160C)
47  #define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
48  #define AR7_REGS_DCL   (AR7_REGS_BASE + 0x1a00)
49 +#define AR7_REGS_MII   (AR7_REGS_BASE + 0x1a08)
50  #define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
51  #define AR7_REGS_MDIO  (AR7_REGS_BASE + 0x1e00)
52  #define AR7_REGS_IRQ   (AR7_REGS_BASE + 0x2400)
53 --- a/drivers/net/ethernet/ti/cpmac.c
54 +++ b/drivers/net/ethernet/ti/cpmac.c
55 @@ -35,7 +35,6 @@
56  #include <linux/skbuff.h>
57  #include <linux/mii.h>
58  #include <linux/phy.h>
59 -#include <linux/phy_fixed.h>
60  #include <linux/platform_device.h>
61  #include <linux/dma-mapping.h>
62  #include <linux/clk.h>
63 @@ -48,14 +47,11 @@ MODULE_LICENSE("GPL");
64  MODULE_ALIAS("platform:cpmac");
65  
66  static int debug_level = 8;
67 -static int dumb_switch;
68  
69 -/* Next 2 are only used in cpmac_probe, so it's pointless to change them */
70 +/* Next is only used in cpmac_probe, so it's pointless to change them */
71  module_param(debug_level, int, 0444);
72 -module_param(dumb_switch, int, 0444);
73  
74  MODULE_PARM_DESC(debug_level, "Number of NETIF_MSG bits to enable");
75 -MODULE_PARM_DESC(dumb_switch, "Assume switch is not connected to MDIO bus");
76  
77  #define CPMAC_VERSION "0.5.2"
78  /* frame size + 802.1q tag + FCS size */
79 @@ -674,9 +670,8 @@ static void cpmac_hw_start(struct net_de
80         for (i = 0; i < 8; i++)
81                 cpmac_write(priv->regs, CPMAC_MAC_ADDR_LO(i), dev->dev_addr[5]);
82         cpmac_write(priv->regs, CPMAC_MAC_ADDR_MID, dev->dev_addr[4]);
83 -       cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, dev->dev_addr[0] |
84 -                   (dev->dev_addr[1] << 8) | (dev->dev_addr[2] << 16) |
85 -                   (dev->dev_addr[3] << 24));
86 +       cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, be32_to_cpu(*(u32 *)
87 +                       dev->dev_addr));
88         cpmac_write(priv->regs, CPMAC_MAX_LENGTH, CPMAC_SKB_SIZE);
89         cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff);
90         cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff);
91 @@ -1120,25 +1115,19 @@ static int cpmac_probe(struct platform_d
92  
93         pdata = pdev->dev.platform_data;
94  
95 -       if (external_switch || dumb_switch) {
96 -               strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); /* fixed phys bus */
97 -               phy_id = pdev->id;
98 -       } else {
99 -               for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
100 -                       if (!(pdata->phy_mask & (1 << phy_id)))
101 -                               continue;
102 -                       if (!cpmac_mii->phy_map[phy_id])
103 -                               continue;
104 -                       strncpy(mdio_bus_id, cpmac_mii->id, MII_BUS_ID_SIZE);
105 -                       break;
106 -               }
107 +       for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
108 +               if (!(pdata->phy_mask & (1 << phy_id)))
109 +                       continue;
110 +               if (!cpmac_mii->phy_map[phy_id])
111 +                       continue;
112 +               strncpy(mdio_bus_id, cpmac_mii->id, MII_BUS_ID_SIZE);
113 +               break;
114         }
115  
116 -       if (phy_id == PHY_MAX_ADDR) {
117 -               dev_err(&pdev->dev, "no PHY present, falling back "
118 -                                       "to switch on MDIO bus 0\n");
119 -               strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); /* fixed phys bus */
120 +       if (phy_id == PHY_MAX_ADDR && pdev->id == 1) {
121 +               printk(KERN_ERR "cpmac: No PHY present, using fixed PHY\n");
122                 phy_id = pdev->id;
123 +               strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
124         }
125  
126         dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
127 @@ -1174,6 +1163,13 @@ static int cpmac_probe(struct platform_d
128         snprintf(priv->phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT,
129                                                 mdio_bus_id, phy_id);
130  
131 +       rc = register_netdev(dev);
132 +       if (rc) {
133 +               printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
134 +                      dev->name);
135 +               goto fail;
136 +       }
137 +
138         priv->phy = phy_connect(dev, priv->phy_name, cpmac_adjust_link,
139                                 PHY_INTERFACE_MODE_MII);
140  
141 @@ -1185,13 +1181,6 @@ static int cpmac_probe(struct platform_d
142                 goto fail;
143         }
144  
145 -       rc = register_netdev(dev);
146 -       if (rc) {
147 -               printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
148 -                      dev->name);
149 -               goto fail;
150 -       }
151 -
152         if (netif_msg_probe(priv)) {
153                 printk(KERN_INFO
154                        "cpmac: device %s (regs: %p, irq: %d, phy: %s, "
155 @@ -1224,6 +1213,7 @@ int cpmac_init(void)
156  {
157         u32 mask;
158         int i, res;
159 +       void __iomem *mii_reg;
160  
161         cpmac_mii = mdiobus_alloc();
162         if (cpmac_mii == NULL)
163 @@ -1247,31 +1237,51 @@ int cpmac_init(void)
164         ar7_gpio_disable(26);
165         ar7_gpio_disable(27);
166  
167 -       if (!ar7_is_titan()) {
168 +       if (ar7_is_titan()) {
169 +               ar7_device_reset(AR7_RESET_BIT_EPHY);
170 +               ar7_device_reset(TITAN_RESET_BIT_EPHY1);
171 +       } else {
172 +               ar7_device_reset(AR7_RESET_BIT_EPHY);
173                 ar7_device_reset(AR7_RESET_BIT_CPMAC_LO);
174                 ar7_device_reset(AR7_RESET_BIT_CPMAC_HI);
175         }
176 -       ar7_device_reset(AR7_RESET_BIT_EPHY);
177 -
178 -       if (ar7_is_titan())
179 -               ar7_device_reset(TITAN_RESET_BIT_EPHY1);
180  
181         cpmac_mii->reset(cpmac_mii);
182  
183         for (i = 0; i < 300; i++) {
184                 mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE);
185 +               mask &= ar7_is_titan()? ~(0x80000000 | 0x40000000) : ~(0x80000000);
186                 if (mask)
187                         break;
188                 else
189                         msleep(10);
190         }
191  
192 -       mask &= 0x7fffffff;
193         if (mask & (mask - 1)) {
194                 external_switch = 1;
195 -               mask = 0;
196 +               if (!ar7_has_high_cpmac()) {
197 +                       if (ar7_is_titan()) {
198 +                               ar7_device_disable(AR7_RESET_BIT_EPHY);
199 +                               ar7_device_disable(TITAN_RESET_BIT_EPHY1);
200 +                       } else
201 +                               ar7_device_disable(AR7_RESET_BIT_EPHY);
202 +
203 +                       //Titan remap might be different
204 +                       mii_reg = ioremap(AR7_REGS_MII, 4);
205 +                       if (mii_reg) {
206 +                               writel(readl(mii_reg) | 1, mii_reg);
207 +                               iounmap(mii_reg);
208 +                       }
209 +               }
210         }
211  
212 +       if (external_switch)
213 +               printk(KERN_INFO "EXTERNAL SWITCH!!!\n");
214 +       else if (mask)
215 +               printk(KERN_INFO "EXTERNAL PHY!!!\n");
216 +       else
217 +               printk(KERN_INFO "INTERNAL PHY!!!\n");
218 +
219         if (ar7_is_titan())
220                 cpmac_mii->phy_mask = ~(mask | 0x80000000 | 0x40000000);
221         else