From: Stas Sergeev <stsp@list.ru>
To: netdev@vger.kernel.org
Cc: Linux kernel <linux-kernel@vger.kernel.org>,
Stas Sergeev <stsp@users.sourceforge.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Grant Likely <grant.likely@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
devicetree@vger.kernel.org
Subject: [PATCH 4/6] of: add API for changing parameters of fixed link
Date: Fri, 27 Mar 2015 16:37:57 +0300 [thread overview]
Message-ID: <55155D35.1070703@list.ru> (raw)
In-Reply-To: <55155AFC.4050800@list.ru>
The following API is added:
- of_phy_fixed_link_set_link() allows to set link state (up/down)
- of_phy_fixed_link_set_speed() allows to set link speed
- of_phy_fixed_link_set_duplex() allows to enable/disable duplex
This API is needed when the MDIO-less link have some other means
of a status passing to MAC, for example with in-band data (SGMII).
MAC driver can then use that API to update the PHY status.
CC: Florian Fainelli <f.fainelli@gmail.com>
CC: Grant Likely <grant.likely@linaro.org>
CC: Rob Herring <robh+dt@kernel.org>
CC: netdev@vger.kernel.org
CC: devicetree@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Stas Sergeev <stsp@users.sourceforge.net>
---
drivers/of/of_mdio.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of_mdio.h | 17 +++++++++++
2 files changed, 89 insertions(+)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index b3dc1e6..ade2426 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -251,6 +251,69 @@ struct phy_device *of_phy_attach(struct net_device *dev,
EXPORT_SYMBOL(of_phy_attach);
#if defined(CONFIG_FIXED_PHY)
+struct fixed_link_data {
+ struct fixed_phy_status status;
+ struct fixed_phy_status changed;
+};
+
+static int of_phy_fixed_link_update(struct phy_device *phy,
+ struct fixed_phy_status *status)
+{
+ struct fixed_link_data *priv = phy->priv;
+
+ if (priv->changed.link) {
+ status->link = priv->status.link;
+ priv->changed.link = 0;
+ }
+ if (priv->changed.speed) {
+ status->speed = priv->status.speed;
+ priv->changed.speed = 0;
+ }
+ if (priv->changed.duplex) {
+ status->duplex = priv->status.duplex;
+ priv->changed.duplex = 0;
+ }
+ if (priv->changed.pause) {
+ status->pause = priv->status.pause;
+ priv->changed.pause = 0;
+ }
+ if (priv->changed.asym_pause) {
+ status->asym_pause = priv->status.asym_pause;
+ priv->changed.asym_pause = 0;
+ }
+ return 0;
+}
+
+int of_phy_fixed_link_set_link(struct phy_device *phy, int link)
+{
+ struct fixed_link_data *priv = phy->priv;
+
+ priv->status.link = link;
+ priv->changed.link = 1;
+ return 0;
+}
+EXPORT_SYMBOL(of_phy_fixed_link_set_link);
+
+int of_phy_fixed_link_set_speed(struct phy_device *phy, int speed)
+{
+ struct fixed_link_data *priv = phy->priv;
+
+ priv->status.speed = speed;
+ priv->changed.speed = 1;
+ return 0;
+}
+EXPORT_SYMBOL(of_phy_fixed_link_set_speed);
+
+int of_phy_fixed_link_set_duplex(struct phy_device *phy, int duplex)
+{
+ struct fixed_link_data *priv = phy->priv;
+
+ priv->status.duplex = duplex;
+ priv->changed.duplex = 1;
+ return 0;
+}
+EXPORT_SYMBOL(of_phy_fixed_link_set_duplex);
+
/*
* of_phy_is_fixed_link() and of_phy_register_fixed_link() must
* support two DT bindings:
@@ -287,6 +350,7 @@ int of_phy_register_fixed_link(struct device_node *np)
const __be32 *fixed_link_prop;
int len;
struct phy_device *phy;
+ struct fixed_link_data *priv;
/* New binding */
fixed_link_node = of_get_child_by_name(np, "fixed-link");
@@ -320,6 +384,14 @@ int of_phy_register_fixed_link(struct device_node *np)
}
}
+ priv = kmalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv) {
+ fixed_phy_unregister(phy);
+ return -ENOMEM;
+ }
+ memset(&priv->changed, 0, sizeof(priv->changed));
+ phy->priv = priv;
+ fixed_phy_set_link_update(phy, of_phy_fixed_link_update);
return 0;
}
EXPORT_SYMBOL(of_phy_register_fixed_link);
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index d449018..677adac 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -65,6 +65,9 @@ static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np)
#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_fixed_link_set_link(struct phy_device *phy, int link);
+extern int of_phy_fixed_link_set_speed(struct phy_device *phy, int speed);
+extern int of_phy_fixed_link_set_duplex(struct phy_device *phy, int duplex);
#else
static inline int of_phy_register_fixed_link(struct device_node *np)
{
@@ -74,6 +77,20 @@ static inline bool of_phy_is_fixed_link(struct device_node *np)
{
return false;
}
+static inline int of_phy_fixed_link_set_link(struct phy_device *phy, int link)
+{
+ return -ENOSYS;
+}
+static inline int of_phy_fixed_link_set_speed(struct phy_device *phy,
+ int speed)
+{
+ return -ENOSYS;
+}
+static inline int of_phy_fixed_link_set_duplex(struct phy_device *phy,
+ int duplex)
+{
+ return -ENOSYS;
+}
#endif
--
1.7.9.5
next prev parent reply other threads:[~2015-03-27 13:45 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 13:28 [PATCH 0/6] mvneta: SGMII-based in-band link state signaling Stas Sergeev
2015-03-27 13:31 ` PATCH 1/6] fixed_phy: pass phy_device instead of net_device to link_update() function Stas Sergeev
2015-03-27 13:33 ` [PATCH 2/6] fixed_phy: add fixed_phy_unregister() Stas Sergeev
2015-03-27 13:34 ` [PATCH 1/6] fixed_phy: pass phy_device instead of net_device to link_update() function Stas Sergeev
2015-03-27 13:35 ` [PATCH 3/6] of_mdio: restructure of_phy_register_fixed_link() for further modifications Stas Sergeev
2015-03-27 13:37 ` Stas Sergeev [this message]
2015-03-27 15:41 ` [PATCH 4/6] of: add API for changing parameters of fixed link Florian Fainelli
2015-03-27 16:07 ` Stas Sergeev
2015-03-27 16:21 ` Florian Fainelli
2015-03-27 16:39 ` Stas Sergeev
2015-03-27 17:15 ` Florian Fainelli
2015-03-27 17:31 ` Stas Sergeev
2015-03-30 14:39 ` Stas Sergeev
2015-03-30 16:06 ` Florian Fainelli
2015-03-30 17:04 ` Stas Sergeev
2015-03-31 17:11 ` Stas Sergeev
2015-03-27 13:39 ` [PATCH 0/6] mvneta: SGMII-based in-band link state signaling Andrew Lunn
2015-03-27 13:52 ` Stas Sergeev
2015-03-27 13:59 ` Andrew Lunn
2015-03-27 14:20 ` Stas Sergeev
2015-03-27 15:44 ` Florian Fainelli
2015-03-27 13:39 ` [PATCH 5/6] mvneta: implement " Stas Sergeev
2015-07-08 16:30 ` [5/6] " Sebastien Rannou
2015-07-08 16:51 ` Stas Sergeev
2015-07-09 9:03 ` Sebastien Rannou
2015-07-09 9:19 ` Thomas Petazzoni
2015-07-09 10:11 ` Stas Sergeev
2015-03-27 13:40 ` [PATCH 6/6] mvneta: port marvell's official in-band status enabling procedure Stas Sergeev
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=55155D35.1070703@list.ru \
--to=stsp@list.ru \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=stsp@users.sourceforge.net \
/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).