Skip to contentSkip to conversation

Broadcom PTP PHY support

PATCH Superseded Jonathan Lemon 2 participants 7 messages Jun 14, 2022 – Jun 15, 2022

Subsystems (4)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover Broadcom PTP PHY support

This adds PTP support for the Broadcom PHY BCM54210E (and the specific variant BCM54213PE that the rpi-5.15 branch uses).

This has only been tested on the RPI CM4, which has one port.

There are other Broadcom chips which may benefit from using the same framework here, although with different register sets.

v6->v7:
Fix Kconfig dependencies (Jakub)

v5->v6:
Fix calculations in bcm_ptp_adjtime_locked (Richard) Add bcm_ptp_stop (Florian)
Update framesync handling for better masking and restore Cleanup 1PPS perout function, remove unsync'd version Add 1PPS extts detection
Break out extts/perout into its own patch

v4->v5:
Reorder so bcm-phy-lib.h shows up first, fixing dependency issues. Use set_normalized_timespec for adjusting ns in adjtime Return upscaled config setting from hwtstamp

v3->v4:
Squash bcm-phy-lib.h and broadcom.c changes into one patch Reorder so the main patch shows up first.

v2->v3:
Rearrange patches so they apply in order
Use ERR_CAST

v1->v2:
Squash Kconfig into main patch
Move config checks into bcm-phy-lib.h
Fix delta_ns calculations in adjtime
Uppercase mode selector macros
Only use NSE_INIT when necessary
Remove the inserted Broadcom RX timestamp from the PTP packet
Add perout (chip generated) and fsync out (timer generated)
Remove PHY_ID_BCM54213PE special casing (needed for rpi tree)
---
CC: Andrew Lunn <[email protected]>
CC: Florian Fainelli <[email protected]>
CC: Richard Cochran <[email protected]>
CC: Lasse Johnsen <[email protected]>
CC: Heiner Kallweit <[email protected]>
CC: Russell King <[email protected]>
CC: "David S. Miller" <[email protected]>
CC: Eric Dumazet <[email protected]>
CC: Jakub Kicinski <[email protected]>
CC: Paolo Abeni <[email protected]>
CC: Broadcom internal kernel review list <[email protected]>
---

Jonathan Lemon (3):
net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib
net: phy: broadcom: Add PTP support for some Broadcom PHYs.
net: phy: Add support for 1PPS out and external timestamps

 drivers/net/phy/Kconfig       |   5 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/bcm-phy-lib.h |  19 +
 drivers/net/phy/bcm-phy-ptp.c | 945 ++++++++++++++++++++++++++++++++++
 drivers/net/phy/broadcom.c    |  33 +-
 5 files changed, 999 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/phy/bcm-phy-ptp.c
Signature · 1 line
2.34.3
#1 lore raw

PATCH v7 1/3 net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

Add 'struct bcm_ptp_private' to bcm54xx_phy_priv which points to an optional PTP structure attached to the PHY. This is allocated on probe if PHY PTP support is configured, and if the driver supports PTP for the specified PHY.

Add the bcm_ptp_probe(), bcm_ptp_config_init() and bcn_ptp_stop() API functions to the bcm-phy library.

---
 drivers/net/phy/bcm-phy-lib.h | 19 +++++++++++++++++++
 drivers/net/phy/broadcom.c    | 33 +++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 4 deletions(-)
drivers/net/phy/bcm-phy-lib.h +19 -0
index c3842f87c33b..9902fb182099 100644
@@ -87,4 +87,23 @@ int bcm_phy_cable_test_start_rdb(struct phy_device *phydev);
 int bcm_phy_cable_test_start(struct phy_device *phydev);
 int bcm_phy_cable_test_get_status(struct phy_device *phydev, bool *finished);
 
+#if IS_ENABLED(CONFIG_BCM_NET_PHYPTP)
+struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev);
+void bcm_ptp_config_init(struct phy_device *phydev);
+void bcm_ptp_stop(struct bcm_ptp_private *priv);
+#else
+static inline struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
+{
+	return NULL;
+}
+
+static inline void bcm_ptp_config_init(struct phy_device *phydev)
+{
+}
+
+static inline void bcm_ptp_stop(struct bcm_ptp_private *priv)
+{
+}
+#endif
+
 #endif /* _LINUX_BCM_PHY_LIB_H */
drivers/net/phy/broadcom.c +29 -4
index e36809aa6d30..876bc45ede60 100644
@@ -27,6 +27,11 @@ MODULE_DESCRIPTION("Broadcom PHY driver");
 MODULE_AUTHOR("Maciej W. Rozycki");
 MODULE_LICENSE("GPL");
 
+struct bcm54xx_phy_priv {
+	u64	*stats;
+	struct bcm_ptp_private *ptp;
+};
+
 static int bcm54xx_config_clock_delay(struct phy_device *phydev)
 {
 	int rc, val;
@@ -313,6 +318,22 @@ static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev)
 		bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, val);
 }
 
+static void bcm54xx_ptp_stop(struct phy_device *phydev)
+{
+	struct bcm54xx_phy_priv *priv = phydev->priv;
+
+	if (priv->ptp)
+		bcm_ptp_stop(priv->ptp);
+}
+
+static void bcm54xx_ptp_config_init(struct phy_device *phydev)
+{
+	struct bcm54xx_phy_priv *priv = phydev->priv;
+
+	if (priv->ptp)
+		bcm_ptp_config_init(phydev);
+}
+
 static int bcm54xx_config_init(struct phy_device *phydev)
 {
 	int reg, err, val;
@@ -390,6 +411,8 @@ static int bcm54xx_config_init(struct phy_device *phydev)
 		bcm_phy_write_exp(phydev, BCM_EXP_MULTICOLOR, val);
 	}
 
+	bcm54xx_ptp_config_init(phydev);
+
 	return 0;
 }
 
@@ -418,6 +441,8 @@ static int bcm54xx_suspend(struct phy_device *phydev)
 {
 	int ret;
 
+	bcm54xx_ptp_stop(phydev);
+
 	/* We cannot use a read/modify/write here otherwise the PHY gets into
 	 * a bad state where its LEDs keep flashing, thus defeating the purpose
 	 * of low power mode.
@@ -741,10 +766,6 @@ static irqreturn_t brcm_fet_handle_interrupt(struct phy_device *phydev)
 	return IRQ_HANDLED;
 }
 
-struct bcm54xx_phy_priv {
-	u64	*stats;
-};
-
 static int bcm54xx_phy_probe(struct phy_device *phydev)
 {
 	struct bcm54xx_phy_priv *priv;
@@ -761,6 +782,10 @@ static int bcm54xx_phy_probe(struct phy_device *phydev)
 	if (!priv->stats)
 		return -ENOMEM;
 
+	priv->ptp = bcm_ptp_probe(phydev);
+	if (IS_ERR(priv->ptp))
+		return PTR_ERR(priv->ptp);
+
 	return 0;
 }
 
Signature · 1 line
2.34.3
#2 lore raw

PATCH v7 2/3 net: phy: broadcom: Add PTP support for some Broadcom PHYs.

In reply to Jonathan Lemon

This adds PTP support for BCM54210E Broadcom PHYs, in particular, the BCM54213PE, as used in the Rasperry PI CM4. It has only been tested on that hardware.

---
 drivers/net/phy/Kconfig       |   5 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/bcm-phy-ptp.c | 718 ++++++++++++++++++++++++++++++++++
 3 files changed, 724 insertions(+)
 create mode 100644 drivers/net/phy/bcm-phy-ptp.c
drivers/net/phy/Kconfig +5 -0
index 9fee639ee5c8..2f299ef26a27 100644
@@ -104,6 +104,7 @@ config AX88796B_PHY
 config BROADCOM_PHY
 	tristate "Broadcom 54XX PHYs"
 	select BCM_NET_PHYLIB
+	select BCM_NET_PHYPTP if NETWORK_PHY_TIMESTAMPING
 	help
 	  Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464,
 	  BCM5481, BCM54810 and BCM5482 PHYs.
@@ -160,6 +161,10 @@ config BCM_CYGNUS_PHY
 config BCM_NET_PHYLIB
 	tristate
 
+config BCM_NET_PHYPTP
+	tristate
+	depends on PTP_1588_CLOCK_OPTIONAL
+
 config CICADA_PHY
 	tristate "Cicada PHYs"
 	help
drivers/net/phy/Makefile +1 -0
index b12b1d86fc99..f7138d3c896b 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_BCM84881_PHY)	+= bcm84881.o
 obj-$(CONFIG_BCM87XX_PHY)	+= bcm87xx.o
 obj-$(CONFIG_BCM_CYGNUS_PHY)	+= bcm-cygnus.o
 obj-$(CONFIG_BCM_NET_PHYLIB)	+= bcm-phy-lib.o
+obj-$(CONFIG_BCM_NET_PHYPTP)	+= bcm-phy-ptp.o
 obj-$(CONFIG_BROADCOM_PHY)	+= broadcom.o
 obj-$(CONFIG_CICADA_PHY)	+= cicada.o
 obj-$(CONFIG_CORTINA_PHY)	+= cortina.o
drivers/net/phy/bcm-phy-ptp.c new file +718 -0

718 lines not on this page · raw message

Signature · 1 line
2.34.3
Reviewed-by on v7 2/3
#3 lore raw

Re: [PATCH net-next v7 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.

Quoted 6 lines · Jonathan Lemon

This adds PTP support for BCM54210E Broadcom PHYs, in particular, the BCM54213PE, as used in the Rasperry PI CM4. It has only been tested on that hardware.

Signature · 1 line
Florian
#4 lore raw

PATCH v7 3/3 net: phy: Add support for 1PPS out and external timestamps

In reply to Jonathan Lemon

The perout function is used to generate a 1PPS signal, synchronized to the PHC. This is accomplished by a using the hardware oneshot functionality, which is reset by a timer.

The external timestamp function is set up for a 1PPS input pulse, and uses a timer to poll for temestamps.

Both functions use the SYNC_OUT/SYNC_IN1 pin, so cannot run simultaneously.

---
 drivers/net/phy/bcm-phy-ptp.c | 227 ++++++++++++++++++++++++++++++++++
 1 file changed, 227 insertions(+)
drivers/net/phy/bcm-phy-ptp.c +227 -0
index 6f462c232e9e..cd8dab4d4e10 100644
@@ -80,6 +80,8 @@
 #define SYNC_OUT_1		0x0879
 #define SYNC_OUT_2		0x087a
 
+#define SYNC_IN_DIVIDER		0x087b
+
 #define SYNOUT_TS_0		0x087c
 #define SYNOUT_TS_1		0x087d
 #define SYNOUT_TS_2		0x087e
@@ -89,6 +91,7 @@
 #define  NSE_CAPTURE_EN			BIT(13)
 #define  NSE_INIT			BIT(12)
 #define  NSE_CPU_FRAMESYNC		BIT(5)
+#define  NSE_SYNC1_FRAMESYNC		BIT(3)
 #define  NSE_FRAMESYNC_MASK		GENMASK(5, 2)
 #define  NSE_PEROUT_EN			BIT(1)
 #define  NSE_ONESHOT_EN			BIT(0)
@@ -128,11 +131,14 @@ struct bcm_ptp_private {
 	struct mii_timestamper mii_ts;
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_info;
+	struct ptp_pin_desc pin;
 	struct mutex mutex;
 	struct sk_buff_head tx_queue;
 	int tx_type;
 	bool hwts_rx;
 	u16 nse_ctrl;
+	bool pin_active;
+	struct delayed_work pin_work;
 };
 
 struct bcm_ptp_skb_cb {
@@ -511,6 +517,216 @@ static long bcm_ptp_do_aux_work(struct ptp_clock_info *info)
 	return reschedule ? 1 : -1;
 }
 
+static int bcm_ptp_cancel_func(struct bcm_ptp_private *priv)
+{
+	if (priv->pin_active) {
+		priv->pin_active = false;
+		priv->nse_ctrl &= ~(NSE_SYNC_OUT_MASK | NSE_SYNC1_FRAMESYNC |
+				    NSE_CAPTURE_EN);
+		bcm_phy_write_exp(priv->phydev, NSE_CTRL, priv->nse_ctrl);
+		cancel_delayed_work_sync(&priv->pin_work);
+	}
+	return 0;
+}
+
+static void bcm_ptp_perout_work(struct work_struct *pin_work)
+{
+	struct bcm_ptp_private *priv =
+		container_of(pin_work, struct bcm_ptp_private, pin_work.work);
+	struct phy_device *phydev = priv->phydev;
+	struct timespec64 ts;
+	u64 ns, next;
+	u16 ctrl;
+
+	mutex_lock(&priv->mutex);
+
+	/* no longer running */
+	if (!priv->pin_active) {
+		mutex_unlock(&priv->mutex);
+		return;
+	}
+
+	bcm_ptp_framesync_ts(phydev, NULL, &ts, priv->nse_ctrl);
+
+	/* this is 1PPS only */
+	next = NSEC_PER_SEC - ts.tv_nsec;
+	ts.tv_sec += next < NSEC_PER_MSEC ? 2 : 1;
+	ts.tv_nsec = 0;
+
+	ns = timespec64_to_ns(&ts);
+
+	/* force 0->1 transition for ONESHOT */
+	ctrl = bcm_ptp_framesync_disable(phydev,
+					 priv->nse_ctrl & ~NSE_ONESHOT_EN);
+
+	bcm_phy_write_exp(phydev, SYNOUT_TS_0, ns & 0xfff0);
+	bcm_phy_write_exp(phydev, SYNOUT_TS_1, ns >> 16);
+	bcm_phy_write_exp(phydev, SYNOUT_TS_2, ns >> 32);
+
+	/* load values on next framesync */
+	bcm_phy_write_exp(phydev, SHADOW_LOAD, SYNC_OUT_LOAD);
+
+	bcm_ptp_framesync(phydev, ctrl | NSE_ONESHOT_EN | NSE_INIT);
+
+	priv->nse_ctrl |= NSE_ONESHOT_EN;
+	bcm_ptp_framesync_restore(phydev, priv->nse_ctrl);
+
+	mutex_unlock(&priv->mutex);
+
+	next = next + NSEC_PER_MSEC;
+	schedule_delayed_work(&priv->pin_work, nsecs_to_jiffies(next));
+}
+
+static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv,
+				 struct ptp_perout_request *req, int on)
+{
+	struct phy_device *phydev = priv->phydev;
+	u64 period, pulse;
+	u16 val;
+
+	if (!on)
+		return bcm_ptp_cancel_func(priv);
+
+	/* 1PPS */
+	if (req->period.sec != 1 || req->period.nsec != 0)
+		return -EINVAL;
+	period = BCM_MAX_PERIOD_8NS;	/* write nonzero value */
+
+	if (req->flags & PTP_PEROUT_PHASE)
+		return -EOPNOTSUPP;
+
+	if (req->flags & PTP_PEROUT_DUTY_CYCLE)
+		pulse = ktime_to_ns(ktime_set(req->on.sec, req->on.nsec));
+	else
+		pulse = (u64)BCM_MAX_PULSE_8NS << 3;
+
+	/* convert to 8ns units */
+	pulse >>= 3;
+
+	if (!pulse)
+		return -EINVAL;
+
+	if (pulse > period)
+		return -EINVAL;
+
+	if (pulse > BCM_MAX_PULSE_8NS)
+		return -EINVAL;
+
+	bcm_phy_write_exp(phydev, SYNC_OUT_0, period);
+
+	val = ((pulse & 0x3) << 14) | ((period >> 16) & 0x3fff);
+	bcm_phy_write_exp(phydev, SYNC_OUT_1, val);
+
+	val = ((pulse >> 2) & 0x7f) | (pulse << 7);
+	bcm_phy_write_exp(phydev, SYNC_OUT_2, val);
+
+	if (priv->pin_active)
+		cancel_delayed_work_sync(&priv->pin_work);
+
+	priv->pin_active = true;
+	INIT_DELAYED_WORK(&priv->pin_work, bcm_ptp_perout_work);
+	schedule_delayed_work(&priv->pin_work, 0);
+
+	return 0;
+}
+
+static void bcm_ptp_extts_work(struct work_struct *pin_work)
+{
+	struct bcm_ptp_private *priv =
+		container_of(pin_work, struct bcm_ptp_private, pin_work.work);
+	struct phy_device *phydev = priv->phydev;
+	struct ptp_clock_event event;
+	struct timespec64 ts;
+	u16 reg;
+
+	mutex_lock(&priv->mutex);
+
+	/* no longer running */
+	if (!priv->pin_active) {
+		mutex_unlock(&priv->mutex);
+		return;
+	}
+
+	reg = bcm_phy_read_exp(phydev, INTR_STATUS);
+	if ((reg & INTC_FSYNC) == 0)
+		goto out;
+
+	bcm_ptp_get_framesync_ts(phydev, &ts);
+
+	event.index = 0;
+	event.type = PTP_CLOCK_EXTTS;
+	event.timestamp = timespec64_to_ns(&ts);
+	ptp_clock_event(priv->ptp_clock, &event);
+
+out:
+	mutex_unlock(&priv->mutex);
+	schedule_delayed_work(&priv->pin_work, HZ / 4);
+}
+
+static int bcm_ptp_extts_locked(struct bcm_ptp_private *priv, int on)
+{
+	struct phy_device *phydev = priv->phydev;
+
+	if (!on)
+		return bcm_ptp_cancel_func(priv);
+
+	if (priv->pin_active)
+		cancel_delayed_work_sync(&priv->pin_work);
+
+	bcm_ptp_framesync_disable(phydev, priv->nse_ctrl);
+
+	priv->nse_ctrl |= NSE_SYNC1_FRAMESYNC | NSE_CAPTURE_EN;
+
+	bcm_ptp_framesync_restore(phydev, priv->nse_ctrl);
+
+	priv->pin_active = true;
+	INIT_DELAYED_WORK(&priv->pin_work, bcm_ptp_extts_work);
+	schedule_delayed_work(&priv->pin_work, 0);
+
+	return 0;
+}
+
+static int bcm_ptp_enable(struct ptp_clock_info *info,
+			  struct ptp_clock_request *rq, int on)
+{
+	struct bcm_ptp_private *priv = ptp2priv(info);
+	int err = -EBUSY;
+
+	mutex_lock(&priv->mutex);
+
+	switch (rq->type) {
+	case PTP_CLK_REQ_PEROUT:
+		if (priv->pin.func == PTP_PF_PEROUT)
+			err = bcm_ptp_perout_locked(priv, &rq->perout, on);
+		break;
+	case PTP_CLK_REQ_EXTTS:
+		if (priv->pin.func == PTP_PF_EXTTS)
+			err = bcm_ptp_extts_locked(priv, on);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+
+	mutex_unlock(&priv->mutex);
+
+	return err;
+}
+
+static int bcm_ptp_verify(struct ptp_clock_info *info, unsigned int pin,
+			  enum ptp_pin_function func, unsigned int chan)
+{
+	switch (func) {
+	case PTP_PF_NONE:
+	case PTP_PF_EXTTS:
+	case PTP_PF_PEROUT:
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+	return 0;
+}
+
 static const struct ptp_clock_info bcm_ptp_clock_info = {
 	.owner		= THIS_MODULE,
 	.name		= KBUILD_MODNAME,
@@ -519,7 +735,12 @@ static const struct ptp_clock_info bcm_ptp_clock_info = {
 	.settime64	= bcm_ptp_settime,
 	.adjtime	= bcm_ptp_adjtime,
 	.adjfine	= bcm_ptp_adjfine,
+	.enable		= bcm_ptp_enable,
+	.verify		= bcm_ptp_verify,
 	.do_aux_work	= bcm_ptp_do_aux_work,
+	.n_pins		= 1,
+	.n_per_out	= 1,
+	.n_ext_ts	= 1,
 };
 
 static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
@@ -648,6 +869,7 @@ static int bcm_ptp_ts_info(struct mii_timestamper *mii_ts,
 void bcm_ptp_stop(struct bcm_ptp_private *priv)
 {
 	ptp_cancel_worker_sync(priv->ptp_clock);
+	bcm_ptp_cancel_func(priv);
 }
 EXPORT_SYMBOL_GPL(bcm_ptp_stop);
 
@@ -667,6 +889,8 @@ void bcm_ptp_config_init(struct phy_device *phydev)
 
 	/* always allow FREQ_LOAD on framesync */
 	bcm_phy_write_exp(phydev, SHADOW_CTRL, FREQ_LOAD);
+
+	bcm_phy_write_exp(phydev, SYNC_IN_DIVIDER, 1);
 }
 EXPORT_SYMBOL_GPL(bcm_ptp_config_init);
 
@@ -703,6 +927,9 @@ struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
 
 	priv->ptp_info = bcm_ptp_clock_info;
 
+	snprintf(priv->pin.name, sizeof(priv->pin.name), "SYNC_OUT");
+	priv->ptp_info.pin_config = &priv->pin;
+
 	clock = ptp_clock_register(&priv->ptp_info, &phydev->mdio.dev);
 	if (IS_ERR(clock))
 		return ERR_CAST(clock);
Signature · 1 line
2.34.3
#5 lore raw

Re: [PATCH net-next v7 3/3] net: phy: Add support for 1PPS out and external timestamps

Quoted 7 lines · Jonathan Lemon

The perout function is used to generate a 1PPS signal, synchronized to the PHC. This is accomplished by a using the hardware oneshot functionality, which is reset by a timer.

The external timestamp function is set up for a 1PPS input pulse, and uses a timer to poll for temestamps.

Quoted 7 lines

Both functions use the SYNC_OUT/SYNC_IN1 pin, so cannot run simultaneously.

Not sure whether we could apply just patch 1 and 2 and leave this one aside as I do see a few things that IMHO would be worth updating before merging this one, more on the stylistic aspect though, so you be the judge.

Quoted 1 line

---

[snip]

drivers/net/phy/bcm-phy-ptp.c static long bcm_ptp_do_aux_work(struct ptp_clock_info *info) · line 528

Quoted 9 lines
drivers/net/phy/bcm-phy-ptp.c +9 -0
+static int bcm_ptp_cancel_func(struct bcm_ptp_private *priv)
+{
+	if (priv->pin_active) {
+		priv->pin_active = false;
+		priv->nse_ctrl &= ~(NSE_SYNC_OUT_MASK | NSE_SYNC1_FRAMESYNC |
+				    NSE_CAPTURE_EN);
+		bcm_phy_write_exp(priv->phydev, NSE_CTRL, priv->nse_ctrl);
+		cancel_delayed_work_sync(&priv->pin_work);
+	}

Missing newline and you should consider reducing the indentation.

Quoted 19 lines
drivers/net/phy/bcm-phy-ptp.c +19 -0
+	return 0;
+}
+
+static void bcm_ptp_perout_work(struct work_struct *pin_work)
+{
+	struct bcm_ptp_private *priv =
+		container_of(pin_work, struct bcm_ptp_private, pin_work.work);
+	struct phy_device *phydev = priv->phydev;
+	struct timespec64 ts;
+	u64 ns, next;
+	u16 ctrl;
+
+	mutex_lock(&priv->mutex);
+
+	/* no longer running */
+	if (!priv->pin_active) {
+		mutex_unlock(&priv->mutex);
+		return;
+	}

[snip]

drivers/net/phy/bcm-phy-ptp.c static long bcm_ptp_do_aux_work(struct ptp_clock_info *info) · line 613

Quoted 8 lines
drivers/net/phy/bcm-phy-ptp.c +8 -0
+	if (!pulse)
+		return -EINVAL;
+
+	if (pulse > period)
+		return -EINVAL;
+
+	if (pulse > BCM_MAX_PULSE_8NS)
+		return -EINVAL;

Consider combining all of these into a single line?

Signature · 1 line
Florian
#6 lore raw

Re: [PATCH net-next v7 3/3] net: phy: Add support for 1PPS out and external timestamps

Quoted 11 lines · Florian Fainelli
Quoted 10 lines · Jonathan Lemon

The perout function is used to generate a 1PPS signal, synchronized to the PHC. This is accomplished by a using the hardware oneshot functionality, which is reset by a timer.

The external timestamp function is set up for a 1PPS input pulse, and uses a timer to poll for temestamps.

Both functions use the SYNC_OUT/SYNC_IN1 pin, so cannot run simultaneously.

Quoted 8 lines
Quoted 4 lines

Not sure whether we could apply just patch 1 and 2 and leave this one aside as I do see a few things that IMHO would be worth updating before merging this one, more on the stylistic aspect though, so you be the judge.

If you feel strongly about it, I can spin up some style fixes.

Personally, I prefer the simpler statements, and the compiler will likely generate the same code.

Signature · 1 line
Jonathan