From nobody Fri Oct 3 21:55:28 2025 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DFBC27FD75; Mon, 25 Aug 2025 06:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756103927; cv=none; b=pbn9VvZbRuz3/VybGzsG03yRGOGmGM77IYNaDRLDywnoOMUBLFcw5cCmArh0BuS0BNAtqNBa0qGxPjzWLVpW7EW3xIGorxy6XJ6Xn84NP32mea8O9rUstUpEX25mHYwHmie+QwtjQMdT9YVihrNY2d6dUa3RXizeJEnhHoGnazw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756103927; c=relaxed/simple; bh=xiKME8Q1ehK0h9WWJdfHI/h43XFB1heAIQ6/W/digAw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sXz7Vjhlo4dfbkDUWJkVcVV817STFNqOUmyWbDbVHcKhaROpJQgN6Dt4z8QP9h/0MLFQ9by+tDy08D925zyLHIMlZzhQVyDBLX6dKW6wWwjPS9RtXjPzy0c3c3EbbbhzO999JvaAHaDoasWVWrqsjjnGpEvhGvns66In/rcAj0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=W+6LU6sI; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="W+6LU6sI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1756103925; x=1787639925; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xiKME8Q1ehK0h9WWJdfHI/h43XFB1heAIQ6/W/digAw=; b=W+6LU6sIu0Ei34l4aGcx+5nr2P4Y/VRVvc2oNZrCMU2BH4iCKMJJ01JE dEbQRS+cBlti6h+aO+xlc0UzF2Vr8x5dcS1LM9Z7fJQ3eHqZNAoMK9KUn oRgxipTroAFyU0O5O5lamrwuMlHWbi5HqmzQiAFLwfUF5LS9bPUEAdq2e LsBvo1KSdV5aX2fpKsf+zSRv6Zl330m2MJuAmhnwDYsrDjfebFU+zbBR0 8WgPY0uzP7G//9Qv5v1ofKlhm1zkJWbdQ3lbvQFsIEa1QOmbE6i48nC4r mcPCjM6d8fk6hs2fgCp890nqZb0jkC2pYtGa0BcWbUxV48+pJa8Bar/7g g==; X-CSE-ConnectionGUID: n5wPq2G4QemCTsKc4pEq5Q== X-CSE-MsgGUID: Xoh+8VY5Rtm9velhzq4eKA== X-IronPort-AV: E=Sophos;i="6.17,312,1747724400"; d="scan'208";a="51205891" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2025 23:38:44 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Sun, 24 Aug 2025 23:38:21 -0700 Received: from DEN-DL-M31836.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.44 via Frontend Transport; Sun, 24 Aug 2025 23:38:19 -0700 From: Horatiu Vultur To: , , , , , , , , CC: , , Horatiu Vultur Subject: [PATCH net-next v2 2/2] net: phy: micrel: Add PTP support for lan8842 Date: Mon, 25 Aug 2025 08:31:36 +0200 Message-ID: <20250825063136.2884640-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250825063136.2884640-1-horatiu.vultur@microchip.com> References: <20250825063136.2884640-1-horatiu.vultur@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- drivers/net/phy/micrel.c | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 42af075894bec..3792b54a26148 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -457,6 +457,9 @@ struct lan8842_phy_stats { =20 struct lan8842_priv { struct lan8842_phy_stats phy_stats; + int rev; + struct phy_device *phydev; + struct kszphy_ptp_priv ptp_priv; }; =20 static const struct kszphy_type lan8814_type =3D { @@ -5786,6 +5789,17 @@ static int ksz9131_resume(struct phy_device *phydev) return kszphy_resume(phydev); } =20 +#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; =20 priv =3D devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); @@ -5800,6 +5815,7 @@ static int lan8842_probe(struct phy_device *phydev) return -ENOMEM; =20 phydev->priv =3D priv; + priv->phydev =3D phydev; =20 /* 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; =20 + /* Revision lan8832 doesn't have support for PTP, therefore don't add + * any PTP clocks + */ + priv->rev =3D lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS, + LAN8842_SKU_REG); + if (priv->rev < 0) + return priv->rev; + if (priv->rev =3D=3D 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 =3D lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS, + LAN8842_STRAP_REG); + addr &=3D 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 =3D lan8842_ptp_probe_once(phydev); + if (ret) + return ret; + } + + lan8814_ptp_init(phydev); + return 0; } =20 @@ -5896,8 +5944,34 @@ static int lan8842_config_inband(struct phy_device *= phydev, unsigned int modes) enable ? LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA : 0); } =20 +static void lan8842_handle_ptp_interrupt(struct phy_device *phydev, u16 st= atus) +{ + struct kszphy_ptp_priv *ptp_priv; + struct lan8842_priv *priv; + + priv =3D phydev->priv; + ptp_priv =3D &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 =3D phydev->priv; int ret =3D IRQ_NONE; int irq_status; =20 @@ -5912,6 +5986,26 @@ static irqreturn_t lan8842_handle_interrupt(struct p= hy_device *phydev) ret =3D IRQ_HANDLED; } =20 + /* Phy revision lan8832 doesn't have support for PTP threrefore there is + * not need to check the PTP and GPIO interrupts + */ + if (priv->rev =3D=3D 0x8832) + goto out; + + while (true) { + irq_status =3D lanphy_read_page_reg(phydev, LAN8814_PAGE_PORT_REGS, + PTP_TSU_INT_STS); + if (!irq_status) + break; + + lan8842_handle_ptp_interrupt(phydev, irq_status); + ret =3D IRQ_HANDLED; + } + + if (!lan8814_handle_gpio_interrupt(phydev, irq_status)) + ret =3D IRQ_HANDLED; + +out: return ret; } =20 --=20 2.34.1