From: Sekhar Nori <nsekhar@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] drivers: net: cpsw: add support to update phy address
Date: Thu, 23 Aug 2018 17:11:29 +0530 [thread overview]
Message-ID: <20180823114131.8684-2-nsekhar@ti.com> (raw)
In-Reply-To: <20180823114131.8684-1-nsekhar@ti.com>
On some boards using TI CPSW, it may be possible that
PHY address was not latched correctly, and the actual
address that the phy responds on is different from that
set in device-tree. For example, see this problem report
on beaglebone black:
https://groups.google.com/d/msg/beagleboard/9mctrG26Mc8/1FuI_i5KW10J
Add support to check for this condition and use the
detected phy address when its safe to do so.
Also, add a public API that exposes the phy address of
a given slave. This can be used to update device-tree that
is passed to Linux kernel.
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
---
drivers/net/cpsw.c | 29 +++++++++++++++++++++++++++++
include/cpsw.h | 1 +
2 files changed, 30 insertions(+)
diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
index c31695eba9dd..8e2a48cfd678 100644
--- a/drivers/net/cpsw.c
+++ b/drivers/net/cpsw.c
@@ -1008,6 +1008,25 @@ static int cpsw_phy_init(struct cpsw_priv *priv, struct cpsw_slave *slave)
return 1;
}
+static void cpsw_phy_addr_update(struct cpsw_priv *priv)
+{
+ struct cpsw_platform_data *data = &priv->data;
+ u16 alive = mdio_regs->alive & GENMASK(15, 0);
+ int active = data->active_slave;
+ int new_addr = ffs(alive) - 1;
+
+ /*
+ * If there is only one phy alive and its address does not match
+ * that of active slave, then phy address can safely be updated.
+ */
+ if (hweight16(alive) == 1 &&
+ data->slave_data[active].phy_addr != new_addr) {
+ printf("Updated phy address for CPSW#%d, old: %d, new: %d\n",
+ active, data->slave_data[active].phy_addr, new_addr);
+ data->slave_data[active].phy_addr = new_addr;
+ }
+}
+
int _cpsw_register(struct cpsw_priv *priv)
{
struct cpsw_slave *slave;
@@ -1034,6 +1053,9 @@ int _cpsw_register(struct cpsw_priv *priv)
}
cpsw_mdio_init(priv->dev->name, data->mdio_base, data->mdio_div);
+
+ cpsw_phy_addr_update(priv);
+
priv->bus = miiphy_get_dev_by_name(priv->dev->name);
for_active_slave(slave, priv)
cpsw_phy_init(priv, slave);
@@ -1458,6 +1480,13 @@ static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
return 0;
}
+int cpsw_get_slave_phy_addr(struct udevice *dev, int slave)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+ struct cpsw_platform_data *data = &priv->data;
+
+ return data->slave_data[slave].phy_addr;
+}
static const struct udevice_id cpsw_eth_ids[] = {
{ .compatible = "ti,cpsw" },
diff --git a/include/cpsw.h b/include/cpsw.h
index f135e7bfe0cc..9f8ce8850f51 100644
--- a/include/cpsw.h
+++ b/include/cpsw.h
@@ -54,5 +54,6 @@ struct cpsw_platform_data {
int cpsw_register(struct cpsw_platform_data *data);
int ti_cm_get_macid(struct udevice *dev, int slave, u8 *mac_addr);
+int cpsw_get_slave_phy_addr(struct udevice *dev, int slave);
#endif /* _CPSW_H_ */
--
2.16.2
next prev parent reply other threads:[~2018-08-23 11:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 11:41 [U-Boot] [PATCH 0/3] Fix for rare beaglebone ethernet failures Sekhar Nori
2018-08-23 11:41 ` Sekhar Nori [this message]
2018-08-24 14:13 ` [U-Boot] [PATCH 1/3] drivers: net: cpsw: add support to update phy address Tom Rini
2018-09-26 12:48 ` [U-Boot] [U-Boot, " Tom Rini
2018-08-23 11:41 ` [U-Boot] [PATCH 2/3] board: ti: am335x: add support to fixup " Sekhar Nori
2018-08-24 14:13 ` Tom Rini
2018-09-26 12:48 ` [U-Boot] [U-Boot, " Tom Rini
2018-08-23 11:41 ` [U-Boot] [PATCH 3/3] configs: am335x_evm: enable OF_BOARD_SETUP Sekhar Nori
2018-08-24 14:13 ` Tom Rini
2018-09-26 12:48 ` [U-Boot] [U-Boot, " Tom Rini
2018-08-24 16:37 ` [U-Boot] [PATCH 0/3] Fix for rare beaglebone ethernet failures Grygorii Strashko
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=20180823114131.8684-2-nsekhar@ti.com \
--to=nsekhar@ti.com \
--cc=u-boot@lists.denx.de \
/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