6d1eb7bfbb61e870ce3cf7708837144be88aec8e
[openwrt/openwrt.git] / target / linux / ixp4xx / patches-4.4 / 205-npe_driver_separate_phy_functions.patch
1 From e3eab80fb5d0a7d7fdb0f2f231b27161d5ec3804 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sun, 30 Jun 2013 15:52:53 +0200
4 Subject: [PATCH 23/36] 205-npe_driver_separate_phy_functions.patch
5
6 ---
7 drivers/net/ethernet/xscale/ixp4xx_eth.c | 70 ++++++++++++++++++++++--------
8 1 file changed, 51 insertions(+), 19 deletions(-)
9
10 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
11 +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
12 @@ -589,6 +589,51 @@ static void ixp4xx_adjust_link(struct ne
13 dev->name, port->speed, port->duplex ? "full" : "half");
14 }
15
16 +static int ixp4xx_phy_connect(struct net_device *dev)
17 +{
18 + struct port *port = netdev_priv(dev);
19 + struct eth_plat_info *plat = port->plat;
20 + char phy_id[MII_BUS_ID_SIZE + 3];
21 +
22 + snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
23 + mdio_bus->id, plat->phy);
24 + port->phydev = phy_connect(dev, phy_id, &ixp4xx_adjust_link,
25 + PHY_INTERFACE_MODE_MII);
26 + if (IS_ERR(port->phydev)) {
27 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
28 + return PTR_ERR(port->phydev);
29 + }
30 +
31 + /* mask with MAC supported features */
32 + port->phydev->supported &= PHY_BASIC_FEATURES;
33 + port->phydev->advertising = port->phydev->supported;
34 +
35 + port->phydev->irq = PHY_POLL;
36 +
37 + return 0;
38 +}
39 +
40 +static void ixp4xx_phy_disconnect(struct net_device *dev)
41 +{
42 + struct port *port = netdev_priv(dev);
43 +
44 + phy_disconnect(port->phydev);
45 +}
46 +
47 +static void ixp4xx_phy_start(struct net_device *dev)
48 +{
49 + struct port *port = netdev_priv(dev);
50 +
51 + port->speed = 0; /* force "link up" message */
52 + phy_start(port->phydev);
53 +}
54 +
55 +static void ixp4xx_phy_stop(struct net_device *dev)
56 +{
57 + struct port *port = netdev_priv(dev);
58 +
59 + phy_stop(port->phydev);
60 +}
61
62 static inline void debug_pkt(struct net_device *dev, const char *func,
63 u8 *data, int len)
64 @@ -1259,8 +1304,7 @@ static int eth_open(struct net_device *d
65 return err;
66 }
67
68 - port->speed = 0; /* force "link up" message */
69 - phy_start(port->phydev);
70 + ixp4xx_phy_start(dev);
71
72 for (i = 0; i < ETH_ALEN; i++)
73 __raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
74 @@ -1381,7 +1425,7 @@ static int eth_close(struct net_device *
75 printk(KERN_CRIT "%s: unable to disable loopback\n",
76 dev->name);
77
78 - phy_stop(port->phydev);
79 + ixp4xx_phy_stop(dev);
80
81 if (!ports_open)
82 qmgr_disable_irq(TXDONE_QUEUE);
83 @@ -1407,7 +1451,6 @@ static int eth_init_one(struct platform_
84 struct net_device *dev;
85 struct eth_plat_info *plat = dev_get_platdata(&pdev->dev);
86 u32 regs_phys;
87 - char phy_id[MII_BUS_ID_SIZE + 3];
88 int err;
89
90 if (!(dev = alloc_etherdev(sizeof(struct port))))
91 @@ -1465,20 +1508,9 @@ static int eth_init_one(struct platform_
92 __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
93 udelay(50);
94
95 - snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
96 - mdio_bus->id, plat->phy);
97 - port->phydev = phy_connect(dev, phy_id, &ixp4xx_adjust_link,
98 - PHY_INTERFACE_MODE_MII);
99 - if (IS_ERR(port->phydev)) {
100 - err = PTR_ERR(port->phydev);
101 + err = ixp4xx_phy_connect(dev);
102 + if (err)
103 goto err_free_mem;
104 - }
105 -
106 - /* mask with MAC supported features */
107 - port->phydev->supported &= PHY_BASIC_FEATURES;
108 - port->phydev->advertising = port->phydev->supported;
109 -
110 - port->phydev->irq = PHY_POLL;
111
112 if ((err = register_netdev(dev)))
113 goto err_phy_dis;
114 @@ -1489,7 +1521,7 @@ static int eth_init_one(struct platform_
115 return 0;
116
117 err_phy_dis:
118 - phy_disconnect(port->phydev);
119 + ixp4xx_phy_disconnect(dev);
120 err_free_mem:
121 npe_port_tab[NPE_ID(port->id)] = NULL;
122 release_resource(port->mem_res);
123 @@ -1506,7 +1538,7 @@ static int eth_remove_one(struct platfor
124 struct port *port = netdev_priv(dev);
125
126 unregister_netdev(dev);
127 - phy_disconnect(port->phydev);
128 + ixp4xx_phy_disconnect(dev);
129 npe_port_tab[NPE_ID(port->id)] = NULL;
130 npe_release(port->npe);
131 release_resource(port->mem_res);