From: Bastien Curutchet <bastien.curutchet@bootlin.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>, Pavel Machek <pavel@ucw.cz>,
Lee Jones <lee@kernel.org>,
Richard Cochran <richardcochran@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Bastien Curutchet <bastien.curutchet@bootlin.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-leds@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
herve.codina@bootlin.com, maxime.chevallier@bootlin.com,
christophercordahi@nanometrics.ca
Subject: [PATCH v2 6/6] net: phy: DP83640: Add fiber mode enabling/disabling from device tree
Date: Tue, 27 Feb 2024 10:39:45 +0100 [thread overview]
Message-ID: <20240227093945.21525-7-bastien.curutchet@bootlin.com> (raw)
In-Reply-To: <20240227093945.21525-1-bastien.curutchet@bootlin.com>
The PHY is able to use copper or fiber. The fiber mode can be enabled or
disabled by hardware strap. If hardware strap is incorrect, PHY can't
establish link.
Add a DT attribute 'ti,fiber-mode' that can be use to override the
hardware strap configuration. If the property is not present, hardware
strap configuration is left as is.
Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
---
drivers/net/phy/dp83640.c | 55 +++++++++++++++++++++++++++++++++++
drivers/net/phy/dp83640_reg.h | 5 ++++
2 files changed, 60 insertions(+)
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index b371dea23937..886f2bc3710d 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -16,6 +16,7 @@
#include <linux/net_tstamp.h>
#include <linux/netdevice.h>
#include <linux/if_vlan.h>
+#include <linux/of.h>
#include <linux/phy.h>
#include <linux/ptp_classify.h>
#include <linux/ptp_clock_kernel.h>
@@ -141,6 +142,11 @@ struct dp83640_private {
/* queues of incoming and outgoing packets */
struct sk_buff_head rx_queue;
struct sk_buff_head tx_queue;
+
+#define FIBER_MODE_DEFAULT 0
+#define FIBER_MODE_ENABLE 1
+#define FIBER_MODE_DISABLE 2
+ int fiber;
};
struct dp83640_clock {
@@ -1141,6 +1147,17 @@ static int dp83640_config_init(struct phy_device *phydev)
val = phy_read(phydev, PCFCR) & ~PCF_EN;
phy_write(phydev, PCFCR, val);
+ if (dp83640->fiber != FIBER_MODE_DEFAULT) {
+ val = phy_read(phydev, PCSR) & ~FX_EN;
+ if (dp83640->fiber == FIBER_MODE_ENABLE)
+ val |= FX_EN;
+ phy_write(phydev, PCSR, val);
+
+ /* Write SOFT_RESET bit to ensure configuration */
+ val = phy_read(phydev, PHYCR2) | SOFT_RESET;
+ phy_write(phydev, PHYCR2, val);
+ }
+
return 0;
}
@@ -1440,6 +1457,39 @@ static int dp83640_ts_info(struct mii_timestamper *mii_ts,
return 0;
}
+#ifdef CONFIG_OF_MDIO
+static int dp83640_of_init(struct phy_device *phydev)
+{
+ struct dp83640_private *dp83640 = phydev->priv;
+ struct device *dev = &phydev->mdio.dev;
+ struct device_node *of_node = dev->of_node;
+ const char *fiber;
+ int ret;
+
+ if (of_property_present(of_node, "ti,fiber-mode")) {
+ ret = of_property_read_string(of_node, "ti,fiber-mode", &fiber);
+ if (ret)
+ return ret;
+
+ dp83640->fiber = FIBER_MODE_DEFAULT;
+ if (!strncmp(fiber, "enable", 6))
+ dp83640->fiber = FIBER_MODE_ENABLE;
+ else if (!strncmp(fiber, "disable", 7))
+ dp83640->fiber = FIBER_MODE_DISABLE;
+ else
+ return -EINVAL;
+ }
+
+ return 0;
+}
+#else
+static int dp83640_of_init(struct phy_device *phydev)
+{
+ dp83640->fiber = FIBER_MODE_DEFAULT;
+ return 0;
+}
+#endif /* CONFIG_OF_MDIO */
+
static int dp83640_probe(struct phy_device *phydev)
{
struct dp83640_clock *clock;
@@ -1472,6 +1522,10 @@ static int dp83640_probe(struct phy_device *phydev)
phydev->mii_ts = &dp83640->mii_ts;
phydev->priv = dp83640;
+ err = dp83640_of_init(phydev);
+ if (err < 0)
+ goto of_failed;
+
spin_lock_init(&dp83640->rx_lock);
skb_queue_head_init(&dp83640->rx_queue);
skb_queue_head_init(&dp83640->tx_queue);
@@ -1494,6 +1548,7 @@ static int dp83640_probe(struct phy_device *phydev)
no_register:
clock->chosen = NULL;
+of_failed:
kfree(dp83640);
no_memory:
dp83640_clock_put(clock);
diff --git a/drivers/net/phy/dp83640_reg.h b/drivers/net/phy/dp83640_reg.h
index b5adb8958c08..cbecf04da5a5 100644
--- a/drivers/net/phy/dp83640_reg.h
+++ b/drivers/net/phy/dp83640_reg.h
@@ -6,6 +6,7 @@
#define HAVE_DP83640_REGISTERS
/* #define PAGE0 0x0000 */
+#define PCSR 0x0016 /* PCS Configuration and Status Register */
#define LEDCR 0x0018 /* PHY Control Register */
#define PHYCR 0x0019 /* PHY Control Register */
#define PHYCR2 0x001c /* PHY Control Register 2 */
@@ -54,6 +55,9 @@
#define PTP_GPIOMON 0x001e /* PTP GPIO Monitor Register */
#define PTP_RXHASH 0x001f /* PTP Receive Hash Register */
+/* Bit definitions for the PCSR register */
+#define FX_EN BIT(6) /* Enable FX Fiber Mode */
+
/* Bit definitions for the LEDCR register */
#define DP83640_LED_DIS(x) BIT((x) + 9) /* Disable LED */
#define DP83640_LED_DRV(x) BIT((x) + 3) /* Force LED val to output */
@@ -64,6 +68,7 @@
#define LED_CNFG_1 BIT(6) /* LED configuration, bit 1 */
/* Bit definitions for the PHYCR2 register */
+#define SOFT_RESET BIT(9) /* Soft Reset */
#define BC_WRITE (1<<11) /* Broadcast Write Enable */
/* Bit definitions for the EDCR register */
--
2.43.0
next prev parent reply other threads:[~2024-02-27 9:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 9:39 [PATCH v2 0/6] net: phy: Add TI's DP83640 device tree binding Bastien Curutchet
2024-02-27 9:39 ` [PATCH v2 1/6] dt-bindings: net: Add bindings for PHY DP83640 Bastien Curutchet
2024-02-28 11:37 ` Conor Dooley
2024-02-27 9:39 ` [PATCH v2 2/6] leds: trigger: Create a new LED netdev trigger for collision Bastien Curutchet
2024-02-27 16:03 ` Andrew Lunn
2024-02-27 16:26 ` Russell King (Oracle)
2024-02-29 7:24 ` Bastien Curutchet
2024-02-29 15:17 ` Andrew Lunn
2024-02-29 16:58 ` Russell King (Oracle)
2024-02-27 9:39 ` [PATCH v2 3/6] net: phy: DP83640: Add LED handling Bastien Curutchet
2024-02-27 9:58 ` Maxime Chevallier
2024-02-27 10:50 ` Russell King (Oracle)
2024-02-28 15:04 ` Andrew Lunn
2024-02-29 7:28 ` Bastien Curutchet
2024-02-27 9:39 ` [PATCH v2 4/6] net: phy: DP83640: Add EDPD management Bastien Curutchet
2024-02-27 10:02 ` Maxime Chevallier
2024-02-27 9:39 ` [PATCH v2 5/6] net: phy: DP83640: Explicitly disabling PHY Control Frames Bastien Curutchet
2024-02-27 10:08 ` Maxime Chevallier
2024-02-27 9:39 ` Bastien Curutchet [this message]
2024-02-27 11:01 ` [PATCH v2 6/6] net: phy: DP83640: Add fiber mode enabling/disabling from device tree Russell King (Oracle)
2024-02-27 16:18 ` Andrew Lunn
2024-02-29 7:31 ` Bastien Curutchet
2024-02-29 15:23 ` Andrew Lunn
2024-03-01 10:37 ` Maxime Chevallier
2024-03-01 14:00 ` 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=20240227093945.21525-7-bastien.curutchet@bootlin.com \
--to=bastien.curutchet@bootlin.com \
--cc=andrew@lunn.ch \
--cc=christophercordahi@nanometrics.ca \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavel@ucw.cz \
--cc=richardcochran@gmail.com \
--cc=robh+dt@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
/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).