From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>, Florian Fainelli <f.fainelli@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Subject: [RFC PATCH net-next 1/2] of: of_mdio: Factor out fixed-link parsing
Date: Sat, 12 Mar 2016 00:08:45 +0100 [thread overview]
Message-ID: <1457737726-23907-2-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1457737726-23907-1-git-send-email-andrew@lunn.ch>
Turn the parsing of the fixed link properties into a helper function,
and export it for others to use.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/of/of_mdio.c | 34 +++++++++++++++++++++-------------
include/linux/of_mdio.h | 11 ++++++++++-
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 5e7838290998..e9ad328174ff 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -397,6 +397,23 @@ bool of_phy_is_fixed_link(struct device_node *np)
}
EXPORT_SYMBOL(of_phy_is_fixed_link);
+int of_phy_parse_fixed_link(struct device_node *np,
+ struct fixed_phy_status *status,
+ int *link_gpio)
+{
+ status->link = 1;
+ status->duplex = of_property_read_bool(np, "full-duplex");
+ if (of_property_read_u32(np, "speed", &status->speed))
+ return -EINVAL;
+ status->pause = of_property_read_bool(np, "pause");
+ status->asym_pause = of_property_read_bool(np, "asym-pause");
+ *link_gpio = of_get_named_gpio_flags(np, "link-gpios", 0, NULL);
+ if (*link_gpio == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ return 0;
+}
+EXPORT_SYMBOL(of_phy_parse_fixed_link);
+
int of_phy_register_fixed_link(struct device_node *np)
{
struct fixed_phy_status status = {};
@@ -419,20 +436,11 @@ int of_phy_register_fixed_link(struct device_node *np)
/* New binding */
fixed_link_node = of_get_child_by_name(np, "fixed-link");
if (fixed_link_node) {
- status.link = 1;
- status.duplex = of_property_read_bool(fixed_link_node,
- "full-duplex");
- if (of_property_read_u32(fixed_link_node, "speed", &status.speed))
- return -EINVAL;
- status.pause = of_property_read_bool(fixed_link_node, "pause");
- status.asym_pause = of_property_read_bool(fixed_link_node,
- "asym-pause");
- link_gpio = of_get_named_gpio_flags(fixed_link_node,
- "link-gpios", 0, NULL);
+ err = of_phy_parse_fixed_link(fixed_link_node, &status,
+ &link_gpio);
of_node_put(fixed_link_node);
- if (link_gpio == -EPROBE_DEFER)
- return -EPROBE_DEFER;
-
+ if (err)
+ return err;
phy = fixed_phy_register(PHY_POLL, &status, link_gpio, np);
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
}
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index 8f2237eb3485..1286a76dbcf0 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -10,6 +10,7 @@
#define __LINUX_OF_MDIO_H
#include <linux/phy.h>
+#include <linux/phy_fixed.h>
#include <linux/of.h>
#ifdef CONFIG_OF
@@ -25,7 +26,6 @@ struct phy_device *of_phy_attach(struct net_device *dev,
extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
extern int of_mdio_parse_addr(struct device *dev, const struct device_node *np);
-
#else /* CONFIG_OF */
static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
{
@@ -72,6 +72,9 @@ static inline int of_mdio_parse_addr(struct device *dev,
#if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY)
extern int of_phy_register_fixed_link(struct device_node *np);
extern bool of_phy_is_fixed_link(struct device_node *np);
+extern int of_phy_parse_fixed_link(struct device_node *np,
+ struct fixed_phy_status *status,
+ int *link_gpio);
#else
static inline int of_phy_register_fixed_link(struct device_node *np)
{
@@ -81,6 +84,12 @@ static inline bool of_phy_is_fixed_link(struct device_node *np)
{
return false;
}
+static inline int of_phy_parse_fixed_link(struct device_node *np,
+ struct fixed_phy_status *status,
+ int *link_gpio)
+{
+ return -ENOSYS;
+}
#endif
--
2.7.0
next prev parent reply other threads:[~2016-03-11 23:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 23:08 [RFC PATCH net-next 0/2] DT MDIO bus of fixed phys Andrew Lunn
2016-03-11 23:08 ` Andrew Lunn [this message]
2016-03-11 23:08 ` [RFC PATCH net-next 2/2] phy: fixed-phy: Allow DT description of an MDIO bus and PHYs Andrew Lunn
2016-03-11 23:30 ` Florian Fainelli
2016-03-12 0:05 ` Andrew Lunn
2016-03-12 17:32 ` Andrew Lunn
2016-03-11 23:26 ` [RFC PATCH net-next 0/2] DT MDIO bus of fixed phys Florian Fainelli
2016-03-11 23:36 ` Andrew Lunn
2016-03-11 23:38 ` Florian Fainelli
2016-03-12 0:12 ` Andrew Lunn
2016-03-14 16:51 ` Florian Fainelli
2016-03-14 19:04 ` Andrew Lunn
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=1457737726-23907-2-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).