From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 01/10] net: phy: factor out phy_device_attach function
Date: Wed, 21 May 2014 14:18:51 +0200 [thread overview]
Message-ID: <1400674740-6467-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1400674740-6467-1-git-send-email-s.hauer@pengutronix.de>
phy_device_connect combines searching for a phy with actually attaching
it to the ethernet device. Factor out a phy_device_attach function to
have a function for each purpose. This makes the logic of phy_device_connect
simpler.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/phy/phy.c | 99 +++++++++++++++++++++++++++++----------------------
1 file changed, 56 insertions(+), 43 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 879939d..a8a8a2c 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -260,12 +260,48 @@ int phy_register_device(struct phy_device* dev)
return ret;
}
+static int phy_device_attach(struct phy_device *phy, struct eth_device *edev,
+ void (*adjust_link) (struct eth_device *edev),
+ u32 flags, phy_interface_t interface)
+{
+ int ret;
+
+ if (phy->attached_dev)
+ return -EBUSY;
+
+ phy->interface = interface;
+ phy->dev_flags = flags;
+
+ if (!phy->registered) {
+ ret = phy_register_device(phy);
+ if (ret)
+ return ret;
+ }
+
+ edev->phydev = phy;
+ phy->attached_dev = edev;
+
+ ret = phy_init_hw(phy);
+ if (ret)
+ return ret;
+
+ /* Sanitize settings based on PHY capabilities */
+ if ((phy->supported & SUPPORTED_Autoneg) == 0)
+ phy->autoneg = AUTONEG_DISABLE;
+
+ phy_config_aneg(edev->phydev);
+
+ phy->adjust_link = adjust_link;
+
+ return 0;
+}
+
/* Automatically gets and returns the PHY device */
int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
void (*adjust_link) (struct eth_device *edev),
u32 flags, phy_interface_t interface)
{
- struct phy_device* dev = NULL;
+ struct phy_device *phy;
unsigned int i;
int ret = -EINVAL;
@@ -275,59 +311,36 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
}
if (addr >= 0) {
- dev = mdiobus_scan(bus, addr);
- if (IS_ERR(dev)) {
+ phy = mdiobus_scan(bus, addr);
+ if (IS_ERR(phy)) {
ret = -EIO;
- goto fail;
- }
- } else {
- for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
- /* skip masked out PHY addresses */
- if (bus->phy_mask & (1 << i))
- continue;
-
- dev = mdiobus_scan(bus, i);
- if (!IS_ERR(dev) && !dev->attached_dev)
- break;
+ goto out;
}
- if (IS_ERR(dev)) {
- ret = PTR_ERR(dev);
- goto fail;
- }
- }
-
- if (dev->attached_dev)
- return -EBUSY;
+ ret = phy_device_attach(phy, edev, adjust_link, flags, interface);
- dev->interface = interface;
- dev->dev_flags = flags;
-
- if (!dev->registered) {
- ret = phy_register_device(dev);
- if (ret)
- goto fail;
+ goto out;
}
- edev->phydev = dev;
- dev->attached_dev = edev;
+ for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+ /* skip masked out PHY addresses */
+ if (bus->phy_mask & (1 << i))
+ continue;
- ret = phy_init_hw(dev);
- if (ret)
- goto fail;
+ phy = mdiobus_scan(bus, i);
+ if (IS_ERR(phy))
+ continue;
- /* Sanitize settings based on PHY capabilities */
- if ((dev->supported & SUPPORTED_Autoneg) == 0)
- dev->autoneg = AUTONEG_DISABLE;
+ ret = phy_device_attach(phy, edev, adjust_link, flags, interface);
- phy_config_aneg(edev->phydev);
-
- dev->adjust_link = adjust_link;
+ goto out;
+ }
- return 0;
+ ret = -ENODEV;
+out:
+ if (ret)
+ puts("Unable to find a PHY (unknown ID?)\n");
-fail:
- puts("Unable to find a PHY (unknown ID?)\n");
return ret;
}
--
2.0.0.rc0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-05-21 12:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 12:18 [PATCH] devicetree support for ethernet phys Sascha Hauer
2014-05-21 12:18 ` Sascha Hauer [this message]
2014-05-21 12:18 ` [PATCH 02/10] net: phy: move setting of phy_map to phy_register_device Sascha Hauer
2014-05-21 12:18 ` [PATCH 03/10] net: phy: register phys specified in devicetree Sascha Hauer
2014-05-21 12:18 ` [PATCH 04/10] net: phy: Support finding a phy in the devicetree Sascha Hauer
2014-05-21 12:18 ` [PATCH 05/10] net: phy: Support limiting phy speed " Sascha Hauer
2014-05-21 12:28 ` Sebastian Hesselbarth
2014-05-21 12:18 ` [PATCH 06/10] net: orion-gbe: use transparent-to-driver of mdio functions Sascha Hauer
2014-05-21 12:29 ` Sebastian Hesselbarth
2014-05-22 20:09 ` Sebastian Hesselbarth
2014-08-02 17:44 ` Ezequiel Garcia
2014-08-04 18:42 ` Sascha Hauer
2014-05-21 12:18 ` [PATCH 07/10] net: phy: remove now unused of_phy_device_connect Sascha Hauer
2014-05-21 12:18 ` [PATCH 08/10] net: phy: genphy: always write MII_CTRL1000 when available Sascha Hauer
2014-05-21 12:18 ` [PATCH 09/10] net: phy: genphy: Make it work with of_set_phy_supported Sascha Hauer
2014-05-21 12:19 ` [PATCH 10/10] net: fec_imx: Add devicetree support for mdio bus Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400674740-6467-2-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox