2 * Atheros AR71xx built-in ethernet mac driver
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Based on Atheros' AG7100 driver
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
14 #include <linux/of_mdio.h>
17 static void ag71xx_phy_link_adjust(struct net_device
*dev
)
19 struct ag71xx
*ag
= netdev_priv(dev
);
20 struct phy_device
*phydev
= ag
->phy_dev
;
22 int status_change
= 0;
24 spin_lock_irqsave(&ag
->lock
, flags
);
27 if (ag
->duplex
!= phydev
->duplex
28 || ag
->speed
!= phydev
->speed
) {
33 if (phydev
->link
!= ag
->link
)
36 ag
->link
= phydev
->link
;
37 ag
->duplex
= phydev
->duplex
;
38 ag
->speed
= phydev
->speed
;
41 ag71xx_link_adjust(ag
);
43 spin_unlock_irqrestore(&ag
->lock
, flags
);
46 int ag71xx_phy_connect(struct ag71xx
*ag
)
48 struct device_node
*np
= ag
->pdev
->dev
.of_node
;
49 struct device_node
*phy_node
;
52 if (of_phy_is_fixed_link(np
)) {
53 ret
= of_phy_register_fixed_link(np
);
55 dev_err(&ag
->pdev
->dev
,
56 "Failed to register fixed PHY link: %d\n", ret
);
60 phy_node
= of_node_get(np
);
62 phy_node
= of_parse_phandle(np
, "phy-handle", 0);
66 dev_err(&ag
->pdev
->dev
,
67 "Could not find valid phy node\n");
71 ag
->phy_dev
= of_phy_connect(ag
->dev
, phy_node
, ag71xx_phy_link_adjust
,
74 of_node_put(phy_node
);
77 dev_err(&ag
->pdev
->dev
,
78 "Could not connect to PHY device. Deferring probe.\n");
82 dev_info(&ag
->pdev
->dev
, "connected to PHY at %s [uid=%08x, driver=%s]\n",
83 phydev_name(ag
->phy_dev
),
84 ag
->phy_dev
->phy_id
, ag
->phy_dev
->drv
->name
);
89 void ag71xx_phy_disconnect(struct ag71xx
*ag
)
91 phy_disconnect(ag
->phy_dev
);