Broadcom PTP PHY support
Subsystems (4)
v6 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.
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 | 10 + 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, 1004 insertions(+), 4 deletions(-) create mode 100644 drivers/net/phy/bcm-phy-ptp.c
Signature · 1 line
2.34.3
PATCH v6 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
@@ -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
@@ -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
PATCH v6 2/3 net: phy: broadcom: Add PTP support for some Broadcom PHYs.
In reply to Jonathan LemonThis 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 | 10 + drivers/net/phy/Makefile | 1 + drivers/net/phy/bcm-phy-ptp.c | 718 ++++++++++++++++++++++++++++++++++ 3 files changed, 729 insertions(+) create mode 100644 drivers/net/phy/bcm-phy-ptp.c
drivers/net/phy/Kconfig +10 -0
@@ -108,6 +108,16 @@ config BROADCOM_PHY Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464, BCM5481, BCM54810 and BCM5482 PHYs. +config BCM_NET_PHYPTP + tristate "Broadcom PHY PTP support" + depends on NETWORK_PHY_TIMESTAMPING + depends on PHYLIB + depends on PTP_1588_CLOCK + depends on BROADCOM_PHY + depends on NET_PTP_CLASSIFY + help + Supports PTP timestamping for certain Broadcom PHYs. + config BCM54140_PHY tristate "Broadcom BCM54140 PHY" depends on PHYLIB
drivers/net/phy/Makefile +1 -0
@@ -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
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 3 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.
...
drivers/net/phy/bcm-phy-ptp.c line 517
Quoted 4 lines
drivers/net/phy/bcm-phy-ptp.c new file +4
-0+static const struct ptp_clock_info bcm_ptp_clock_info = { + .owner =THIS_MODULE , + .name =KBUILD_MODNAME , + .max_adj =100000000 ,
Does this really work? See below.
drivers/net/phy/bcm-phy-ptp.c line 523
Quoted 6 lines
drivers/net/phy/bcm-phy-ptp.c new file +6
-0+ .gettimex64 = bcm_ptp_gettimex, + .settime64 = bcm_ptp_settime, + .adjtime = bcm_ptp_adjtime, + .adjfine = bcm_ptp_adjfine, + .do_aux_work = bcm_ptp_do_aux_work, +};
On another phy from the same (?) family (541xx), I found that the synch becomes unstable when slewing more than:
port->caps.max_adj = 62500,
Thanks,
Richard
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 24 lines · Richard Cochran
Quoted 3 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.
...
drivers/net/phy/bcm-phy-ptp.c line 517
Quoted 4 lines
drivers/net/phy/bcm-phy-ptp.c new file +4
-0+static const struct ptp_clock_info bcm_ptp_clock_info = { + .owner =THIS_MODULE , + .name =KBUILD_MODNAME , + .max_adj =100000000 ,Does this really work? See below.
drivers/net/phy/bcm-phy-ptp.c line 523
Quoted 6 lines
drivers/net/phy/bcm-phy-ptp.c new file +6
-0+ .gettimex64 = bcm_ptp_gettimex, + .settime64 = bcm_ptp_settime, + .adjtime = bcm_ptp_adjtime, + .adjfine = bcm_ptp_adjfine, + .do_aux_work = bcm_ptp_do_aux_work, +};On another phy from the same (?) family (541xx), I found that the synch becomes unstable when slewing more than:
Quoted 1 line
port->caps.max_adj = 62500,
The 100000000 value I probably copied from elsewhere.
For testing, I’ve been running ts2phc and ptp4l, and haven’t noticed any problems - but may have just been lucky.
Do you have a stress test to verify one way or the other? —
Jonathan
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 1 line · Jonathan Lemon
Do you have a stress test to verify one way or the other?
You can set a large freq. offset on the server. For example
phc_ctl eth0 -- freq 500000
for 500 ppm and see what the client does.
Thanks,
Richard
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 8 lines · Richard Cochran
Quoted 1 line · Jonathan Lemon
Do you have a stress test to verify one way or the other?
You can set a large freq. offset on the server. For example
phc_ctl eth0 -- freq 500000for 500 ppm and see what the client does.
Server:
phc_ctl /dev/ptp0 -- freq 60000000
Client (cm4):
ptp4l[252648.584]: rms 5 max 5 freq -59995478 +/- 5 ptp4l[252649.584]: rms 2 max 2 freq -59995476 +/- 1 delay 165 +/- 0 ptp4l[252650.585]: rms 3 max 3 freq -59995475 +/- 1 delay 165 +/- 0
Flipping client and server roles still works, (up to the 62499999 limit for the igb adapter I'm using on the other end of the cm4 link.)
Looking at the math, the adjustment in bcm_ptp_adjfine() can be up to 0x7fffffff, as this is added to a 0x8000000 base.
So:
(0x7fffffff * 15625) >> 9 == 65535999969 scaled ppm
(65535999969 * 125) >> 13 == 999999999 ppb
Seems like the 100000000 ppb max value is in range?
Signature · 1 line
Jonathan
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 1 line · Jonathan Lemon
Seems like the 100000000 ppb max value is in range?
Sounds good. Appreciate the follow up!
Thanks,
Richard
Jakub Kicinski
maintainerRe: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
In reply to Jonathan Lemondrivers/net/phy/Kconfig config BROADCOM_PHY · line 119
Quoted 9 lines · On Wed, 8 Jun 2022 13:44:50 -0700 Jonathan Lemon wrote:
drivers/net/phy/Kconfig +9
-0+config BCM_NET_PHYPTP + tristate "Broadcom PHY PTP support" + depends on NETWORK_PHY_TIMESTAMPING + depends on PHYLIB + depends on PTP_1588_CLOCK + depends on BROADCOM_PHY + depends on NET_PTP_CLASSIFY + help + Supports PTP timestamping for certain Broadcom PHYs.
This will not prevent:
CONFIG_BCM_NET_PHYLIB=yCONFIG_BCM_NET_PHYPTP=m
which fails to link:
ld: vmlinux.o: in function `bcm54xx_phy_probe':
broadcom.c:(.text+0x155dd6a): undefined reference to `bcm_ptp_probe'
ld: vmlinux.o: in function `bcm54xx_suspend':
broadcom.c:(.text+0x155e203): undefined reference to `bcm_ptp_stop'
ld: vmlinux.o: in function `bcm54xx_config_init':
broadcom.c:(.text+0x155e8a6): undefined reference to `bcm_ptp_config_init'
Can we always build PTP support in when NETWORK_PHY_TIMESTAMPING is selected? Without adding an extra Kconfig, do:
+ifeq ($(CONFIG_NETWORK_PHY_TIMESTAMPING),)
obj-$(CONFIG_BCM_NET_PHYLIB) += bcm-phy-lib.o
+else
+obj-$(CONFIG_BCM_NET_PHYLIB) += bcm-phy-lib.o bcm-phy-ptp.o
+endif
or some form thereof ?
Re: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 34 lines · Jakub Kicinski
Review
Quoted 9 lines · On Wed, 8 Jun 2022 13:44:50 -0700 Jonathan Lemon wrote:
(quoted diff) +9
-0+config BCM_NET_PHYPTP + tristate "Broadcom PHY PTP support" + depends on NETWORK_PHY_TIMESTAMPING + depends on PHYLIB + depends on PTP_1588_CLOCK + depends on BROADCOM_PHY + depends on NET_PTP_CLASSIFY + help + Supports PTP timestamping for certain Broadcom PHYs.This will not prevent:
CONFIG_BCM_NET_PHYLIB=yCONFIG_BCM_NET_PHYPTP=mwhich fails to link:
ld: vmlinux.o: in function `bcm54xx_phy_probe':
broadcom.c:(.text+0x155dd6a): undefined reference to `bcm_ptp_probe'
ld: vmlinux.o: in function `bcm54xx_suspend':
broadcom.c:(.text+0x155e203): undefined reference to `bcm_ptp_stop'
ld: vmlinux.o: in function `bcm54xx_config_init':
broadcom.c:(.text+0x155e8a6): undefined reference to `bcm_ptp_config_init'Can we always build PTP support in when
NETWORK_PHY_TIMESTAMPINGis selected? Without adding an extraKconfig, do:(quoted diff) +4
-0+ifeq ($(CONFIG_NETWORK_PHY_TIMESTAMPING),) obj-$(CONFIG_BCM_NET_PHYLIB) += bcm-phy-lib.o +else +obj-$(CONFIG_BCM_NET_PHYLIB) += bcm-phy-lib.o bcm-phy-ptp.o +endif
Quoted 1 line
or some form thereof ?
How about this? Seems to work for my testing. If this is ok, I'll spin up (hopefully the last) patch on Monday.
drivers/net/phy/Kconfig +5 -0
@@ -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
Jakub Kicinski
maintainerRe: [PATCH net-next v6 2/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 2 lines · On Sat, 11 Jun 2022 14:33:55 -0700 Jonathan Lemon wrote:
How about this? Seems to work for my testing. If this is ok, I'll spin up (hopefully the last) patch on Monday.
LGTM!
PATCH v6 3/3 net: phy: Add support for 1PPS out and external timestamps
In reply to Jonathan LemonThe 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
@@ -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
Re: [PATCH net-next v6 3/3] net: phy: Add support for 1PPS out and external timestamps
Quoted 3 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.
Is this now really in sync with the PHC?
(previously there was talk about it being random phase/frequency)
Thanks,
Richard
Re: [PATCH net-next v6 3/3] net: phy: Add support for 1PPS out and external timestamps
Quoted 8 lines · Richard Cochran
Quoted 3 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.
Is this now really in sync with the PHC?
(previously there was talk about it being random phase/frequency)
Yes - I removed that function.
In the current code, the target time is loaded into the registers, and the hw generates an output when the PHC matches the target. —
Jonathan
Quoted 7 lines · Jonathan Lemon
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.
For the series: