* [PATCH net-next 0/2] net: phy: micrel: Add PTP support for lan8842
@ 2025-08-22 9:27 Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
0 siblings, 2 replies; 5+ messages in thread
From: Horatiu Vultur @ 2025-08-22 9:27 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran
Cc: netdev, Horatiu Vultur
The PTP block in lan8842 is the same as lan8814 so reuse all these
functions. The first patch of the series just does cosmetic changes such
that lan8842 can reuse the function lan8814_ptp_probe. There should not be
any functional changes here. While the second patch adds the PTP support
to lan8842.
Horatiu Vultur (2):
net: phy: micrel: Introduce function __lan8814_ptp_probe_once
net: phy: micrel: Add PTP support for lan8842
drivers/net/phy/micrel.c | 107 +++++++++++++++++++++++++++++++++++++--
1 file changed, 102 insertions(+), 5 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once
2025-08-22 9:27 [PATCH net-next 0/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
@ 2025-08-22 9:27 ` Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
1 sibling, 0 replies; 5+ messages in thread
From: Horatiu Vultur @ 2025-08-22 9:27 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran
Cc: netdev, Horatiu Vultur
Introduce the function __lan8814_ptp_probe_once as this function will be
used also by lan8842 driver. This change doesn't have any functional
changes.
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
drivers/net/phy/micrel.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 04bd744920b0d..42af075894bec 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -4242,7 +4242,8 @@ static void lan8814_ptp_init(struct phy_device *phydev)
phydev->default_timestamp = true;
}
-static int lan8814_ptp_probe_once(struct phy_device *phydev)
+static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name,
+ size_t gpios)
{
struct lan8814_shared_priv *shared = phy_package_get_priv(phydev);
@@ -4250,18 +4251,18 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
mutex_init(&shared->shared_lock);
shared->pin_config = devm_kmalloc_array(&phydev->mdio.dev,
- LAN8814_PTP_GPIO_NUM,
+ gpios,
sizeof(*shared->pin_config),
GFP_KERNEL);
if (!shared->pin_config)
return -ENOMEM;
- for (int i = 0; i < LAN8814_PTP_GPIO_NUM; i++) {
+ for (int i = 0; i < gpios; i++) {
struct ptp_pin_desc *ptp_pin = &shared->pin_config[i];
memset(ptp_pin, 0, sizeof(*ptp_pin));
snprintf(ptp_pin->name,
- sizeof(ptp_pin->name), "lan8814_ptp_pin_%02d", i);
+ sizeof(ptp_pin->name), "%s_%02d", pin_name, i);
ptp_pin->index = i;
ptp_pin->func = PTP_PF_NONE;
}
@@ -4271,7 +4272,7 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
shared->ptp_clock_info.max_adj = 31249999;
shared->ptp_clock_info.n_alarm = 0;
shared->ptp_clock_info.n_ext_ts = LAN8814_PTP_EXTTS_NUM;
- shared->ptp_clock_info.n_pins = LAN8814_PTP_GPIO_NUM;
+ shared->ptp_clock_info.n_pins = gpios;
shared->ptp_clock_info.pps = 0;
shared->ptp_clock_info.supported_extts_flags = PTP_RISING_EDGE |
PTP_FALLING_EDGE |
@@ -4318,6 +4319,12 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
return 0;
}
+static int lan8814_ptp_probe_once(struct phy_device *phydev)
+{
+ return __lan8814_ptp_probe_once(phydev, "lan8814_ptp_pin",
+ LAN8814_PTP_GPIO_NUM);
+}
+
static void lan8814_setup_led(struct phy_device *phydev, int val)
{
int temp;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842
2025-08-22 9:27 [PATCH net-next 0/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once Horatiu Vultur
@ 2025-08-22 9:27 ` Horatiu Vultur
2025-08-22 10:17 ` Parthiban.Veerasooran
1 sibling, 1 reply; 5+ messages in thread
From: Horatiu Vultur @ 2025-08-22 9:27 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran
Cc: netdev, Horatiu Vultur
It has the same PTP IP block as lan8814, only the number of GPIOs is
different, all the other functionality is the same. So reuse the same
functions as lan8814 for lan8842.
There is a revision of lan8842 called lan8832 which doesn't have the PTP
IP block. So make sure in that case the PTP is not initialized.
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
drivers/net/phy/micrel.c | 90 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 42af075894bec..87ed8cf09f8d2 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -457,6 +457,9 @@ struct lan8842_phy_stats {
struct lan8842_priv {
struct lan8842_phy_stats phy_stats;
+ int rev;
+ struct phy_device *phydev;
+ struct kszphy_ptp_priv ptp_priv;
};
static const struct kszphy_type lan8814_type = {
@@ -5786,6 +5789,17 @@ static int ksz9131_resume(struct phy_device *phydev)
return kszphy_resume(phydev);
}
+#define LAN8842_PTP_GPIO_NUM 16
+
+static int lan8842_ptp_probe_once(struct phy_device *phydev)
+{
+ return __lan8814_ptp_probe_once(phydev, "lan8842_ptp_pin",
+ LAN8842_PTP_GPIO_NUM);
+}
+
+#define LAN8842_STRAP_REG 0 /* 0x0 */
+#define LAN8842_STRAP_REG_PHYADDR_MASK GENMASK(4, 0)
+#define LAN8842_SKU_REG 11 /* 0x0b */
#define LAN8842_SELF_TEST 14 /* 0x0e */
#define LAN8842_SELF_TEST_RX_CNT_ENA BIT(8)
#define LAN8842_SELF_TEST_TX_CNT_ENA BIT(4)
@@ -5793,6 +5807,7 @@ static int ksz9131_resume(struct phy_device *phydev)
static int lan8842_probe(struct phy_device *phydev)
{
struct lan8842_priv *priv;
+ int addr;
int ret;
priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
@@ -5800,6 +5815,7 @@ static int lan8842_probe(struct phy_device *phydev)
return -ENOMEM;
phydev->priv = priv;
+ priv->phydev = phydev;
/* Similar to lan8814 this PHY has a pin which needs to be pulled down
* to enable to pass any traffic through it. Therefore use the same
@@ -5817,6 +5833,38 @@ static int lan8842_probe(struct phy_device *phydev)
if (ret < 0)
return ret;
+ /* Revision lan8832 doesn't have support for PTP, therefore don't add
+ * any PTP clocks
+ */
+ priv->rev = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS,
+ LAN8842_SKU_REG);
+ if (priv->rev < 0)
+ return priv->rev;
+ if (priv->rev == 0x8832)
+ return 0;
+
+ /* As the lan8814 and lan8842 has the same IP for the PTP block, the
+ * only difference is the number of the GPIOs, then make sure that the
+ * lan8842 initialized also the shared data pointer as this is used in
+ * all the PTP functions for lan8814. The lan8842 doesn't have multiple
+ * PHYs in the same package.
+ */
+ addr = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS,
+ LAN8842_STRAP_REG);
+ addr &= LAN8842_STRAP_REG_PHYADDR_MASK;
+ if (addr < 0)
+ return addr;
+
+ devm_phy_package_join(&phydev->mdio.dev, phydev, addr,
+ sizeof(struct lan8814_shared_priv));
+ if (phy_package_init_once(phydev)) {
+ ret = lan8842_ptp_probe_once(phydev);
+ if (ret)
+ return ret;
+ }
+
+ lan8814_ptp_init(phydev);
+
return 0;
}
@@ -5896,8 +5944,31 @@ static int lan8842_config_inband(struct phy_device *phydev, unsigned int modes)
enable ? LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA : 0);
}
+static void lan8842_handle_ptp_interrupt(struct phy_device *phydev, u16 status)
+{
+ struct lan8842_priv *priv = phydev->priv;
+ struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv;
+
+ if (status & PTP_TSU_INT_STS_PTP_TX_TS_EN_)
+ lan8814_get_tx_ts(ptp_priv);
+
+ if (status & PTP_TSU_INT_STS_PTP_RX_TS_EN_)
+ lan8814_get_rx_ts(ptp_priv);
+
+ if (status & PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_) {
+ lan8814_flush_fifo(phydev, true);
+ skb_queue_purge(&ptp_priv->tx_queue);
+ }
+
+ if (status & PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_) {
+ lan8814_flush_fifo(phydev, false);
+ skb_queue_purge(&ptp_priv->rx_queue);
+ }
+}
+
static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
{
+ struct lan8842_priv *priv = phydev->priv;
int ret = IRQ_NONE;
int irq_status;
@@ -5912,6 +5983,25 @@ static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
ret = IRQ_HANDLED;
}
+ /* Phy revision lan8832 doesn't have support for PTP threrefore there is
+ * not need to check the PTP and GPIO interrupts
+ */
+ if (priv->rev == 0x8832)
+ goto out;
+
+ while (true) {
+ irq_status = lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS);
+ if (!irq_status)
+ break;
+
+ lan8842_handle_ptp_interrupt(phydev, irq_status);
+ ret = IRQ_HANDLED;
+ }
+
+ if (!lan8814_handle_gpio_interrupt(phydev, irq_status))
+ ret = IRQ_HANDLED;
+
+out:
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842
2025-08-22 9:27 ` [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
@ 2025-08-22 10:17 ` Parthiban.Veerasooran
2025-08-25 6:04 ` Horatiu Vultur - M31836
0 siblings, 1 reply; 5+ messages in thread
From: Parthiban.Veerasooran @ 2025-08-22 10:17 UTC (permalink / raw)
To: Horatiu.Vultur, andrew, hkallweit1, linux, davem, edumazet, kuba,
pabeni, richardcochran
Cc: netdev
Hi Horatiu,
On 22/08/25 2:57 pm, Horatiu Vultur wrote:
> It has the same PTP IP block as lan8814, only the number of GPIOs is
> different, all the other functionality is the same. So reuse the same
> functions as lan8814 for lan8842.
> There is a revision of lan8842 called lan8832 which doesn't have the PTP
> IP block. So make sure in that case the PTP is not initialized.
>
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
> drivers/net/phy/micrel.c | 90 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 90 insertions(+)
>
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> index 42af075894bec..87ed8cf09f8d2 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -457,6 +457,9 @@ struct lan8842_phy_stats {
>
> struct lan8842_priv {
> struct lan8842_phy_stats phy_stats;
> + int rev;
> + struct phy_device *phydev;
> + struct kszphy_ptp_priv ptp_priv;
> };
>
> static const struct kszphy_type lan8814_type = {
> @@ -5786,6 +5789,17 @@ static int ksz9131_resume(struct phy_device *phydev)
> return kszphy_resume(phydev);
> }
>
> +#define LAN8842_PTP_GPIO_NUM 16
> +
> +static int lan8842_ptp_probe_once(struct phy_device *phydev)
> +{
> + return __lan8814_ptp_probe_once(phydev, "lan8842_ptp_pin",
> + LAN8842_PTP_GPIO_NUM);
> +}
> +
> +#define LAN8842_STRAP_REG 0 /* 0x0 */
> +#define LAN8842_STRAP_REG_PHYADDR_MASK GENMASK(4, 0)
> +#define LAN8842_SKU_REG 11 /* 0x0b */
> #define LAN8842_SELF_TEST 14 /* 0x0e */
> #define LAN8842_SELF_TEST_RX_CNT_ENA BIT(8)
> #define LAN8842_SELF_TEST_TX_CNT_ENA BIT(4)
> @@ -5793,6 +5807,7 @@ static int ksz9131_resume(struct phy_device *phydev)
> static int lan8842_probe(struct phy_device *phydev)
> {
> struct lan8842_priv *priv;
> + int addr;
> int ret;
>
> priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
> @@ -5800,6 +5815,7 @@ static int lan8842_probe(struct phy_device *phydev)
> return -ENOMEM;
>
> phydev->priv = priv;
> + priv->phydev = phydev;
>
> /* Similar to lan8814 this PHY has a pin which needs to be pulled down
> * to enable to pass any traffic through it. Therefore use the same
> @@ -5817,6 +5833,38 @@ static int lan8842_probe(struct phy_device *phydev)
> if (ret < 0)
> return ret;
>
> + /* Revision lan8832 doesn't have support for PTP, therefore don't add
> + * any PTP clocks
> + */
> + priv->rev = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS,
> + LAN8842_SKU_REG);
> + if (priv->rev < 0)
> + return priv->rev;
> + if (priv->rev == 0x8832)
> + return 0;
> +
> + /* As the lan8814 and lan8842 has the same IP for the PTP block, the
> + * only difference is the number of the GPIOs, then make sure that the
> + * lan8842 initialized also the shared data pointer as this is used in
> + * all the PTP functions for lan8814. The lan8842 doesn't have multiple
> + * PHYs in the same package.
> + */
> + addr = lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS,
> + LAN8842_STRAP_REG);
> + addr &= LAN8842_STRAP_REG_PHYADDR_MASK;
> + if (addr < 0)
> + return addr;
> +
> + devm_phy_package_join(&phydev->mdio.dev, phydev, addr,
> + sizeof(struct lan8814_shared_priv));
> + if (phy_package_init_once(phydev)) {
> + ret = lan8842_ptp_probe_once(phydev);
> + if (ret)
> + return ret;
> + }
> +
> + lan8814_ptp_init(phydev);
> +
> return 0;
> }
>
> @@ -5896,8 +5944,31 @@ static int lan8842_config_inband(struct phy_device *phydev, unsigned int modes)
> enable ? LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA : 0);
> }
>
> +static void lan8842_handle_ptp_interrupt(struct phy_device *phydev, u16 status)
> +{
> + struct lan8842_priv *priv = phydev->priv;
> + struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv;
Please follow reverse Christmas tree style.
Best regards,
Parthiban V
> +
> + if (status & PTP_TSU_INT_STS_PTP_TX_TS_EN_)
> + lan8814_get_tx_ts(ptp_priv);
> +
> + if (status & PTP_TSU_INT_STS_PTP_RX_TS_EN_)
> + lan8814_get_rx_ts(ptp_priv);
> +
> + if (status & PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_) {
> + lan8814_flush_fifo(phydev, true);
> + skb_queue_purge(&ptp_priv->tx_queue);
> + }
> +
> + if (status & PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_) {
> + lan8814_flush_fifo(phydev, false);
> + skb_queue_purge(&ptp_priv->rx_queue);
> + }
> +}
> +
> static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
> {
> + struct lan8842_priv *priv = phydev->priv;
> int ret = IRQ_NONE;
> int irq_status;
>
> @@ -5912,6 +5983,25 @@ static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
> ret = IRQ_HANDLED;
> }
>
> + /* Phy revision lan8832 doesn't have support for PTP threrefore there is
> + * not need to check the PTP and GPIO interrupts
> + */
> + if (priv->rev == 0x8832)
> + goto out;
> +
> + while (true) {
> + irq_status = lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS);
> + if (!irq_status)
> + break;
> +
> + lan8842_handle_ptp_interrupt(phydev, irq_status);
> + ret = IRQ_HANDLED;
> + }
> +
> + if (!lan8814_handle_gpio_interrupt(phydev, irq_status))
> + ret = IRQ_HANDLED;
> +
> +out:
> return ret;
> }
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842
2025-08-22 10:17 ` Parthiban.Veerasooran
@ 2025-08-25 6:04 ` Horatiu Vultur - M31836
0 siblings, 0 replies; 5+ messages in thread
From: Horatiu Vultur - M31836 @ 2025-08-25 6:04 UTC (permalink / raw)
To: Parthiban Veerasooran - I17164
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, richardcochran@gmail.com,
netdev@vger.kernel.org
The 08/22/2025 10:17, Parthiban Veerasooran - I17164 wrote:
> Hi Horatiu,
Hi Parthiban,
>
> > +static void lan8842_handle_ptp_interrupt(struct phy_device *phydev, u16 status)
> > +{
> > + struct lan8842_priv *priv = phydev->priv;
> > + struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv;
> Please follow reverse Christmas tree style.
That is a goot catch. I will update it in the next version. Thanks.
>
> Best regards,
> Parthiban V
> > +
> > + if (status & PTP_TSU_INT_STS_PTP_TX_TS_EN_)
> > + lan8814_get_tx_ts(ptp_priv);
> > +
> > + if (status & PTP_TSU_INT_STS_PTP_RX_TS_EN_)
> > + lan8814_get_rx_ts(ptp_priv);
> > +
> > + if (status & PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_) {
> > + lan8814_flush_fifo(phydev, true);
> > + skb_queue_purge(&ptp_priv->tx_queue);
> > + }
> > +
> > + if (status & PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_) {
> > + lan8814_flush_fifo(phydev, false);
> > + skb_queue_purge(&ptp_priv->rx_queue);
> > + }
> > +}
> > +
> > static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
> > {
> > + struct lan8842_priv *priv = phydev->priv;
> > int ret = IRQ_NONE;
> > int irq_status;
> >
> > @@ -5912,6 +5983,25 @@ static irqreturn_t lan8842_handle_interrupt(struct phy_device *phydev)
> > ret = IRQ_HANDLED;
> > }
> >
> > + /* Phy revision lan8832 doesn't have support for PTP threrefore there is
> > + * not need to check the PTP and GPIO interrupts
> > + */
> > + if (priv->rev == 0x8832)
> > + goto out;
> > +
> > + while (true) {
> > + irq_status = lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS);
> > + if (!irq_status)
> > + break;
> > +
> > + lan8842_handle_ptp_interrupt(phydev, irq_status);
> > + ret = IRQ_HANDLED;
> > + }
> > +
> > + if (!lan8814_handle_gpio_interrupt(phydev, irq_status))
> > + ret = IRQ_HANDLED;
> > +
> > +out:
> > return ret;
> > }
> >
>
--
/Horatiu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-25 6:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 9:27 [PATCH net-next 0/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once Horatiu Vultur
2025-08-22 9:27 ` [PATCH net-next 2/2] net: phy: micrel: Add PTP support for lan8842 Horatiu Vultur
2025-08-22 10:17 ` Parthiban.Veerasooran
2025-08-25 6:04 ` Horatiu Vultur - M31836
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).