From nobody Fri Oct 3 10:13:39 2025 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 B2E3F28DF0B; Tue, 2 Sep 2025 12:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756816897; cv=none; b=PkTtstD+IyRteAjxviuKQU+XJNsGTXwYN9lAEDIj8cuBfjNOdv8DjVqvH9qLwz7nvh0obUpASfAtHmjya/4qyN9/2HDtwxEYZKu0dHleXq8fdFCi/fxAtYq3O5nbLKG5dKgu+SeHZg6Z+ppNAWMYniWgsBIKjcxmpShBllyyIkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756816897; c=relaxed/simple; bh=sSJfDeCErHLMizbHbg7+od45H5c6ZYzDEqhMLgOvb6U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qlaWgcY87zjh4susLavNDJS0AvAMfXIm3fzaYKJbHJ4tDCbKMm3hDvvBDChKRKNUpSdoYFeBqovXp9hxSDVNiBD2yivqo3Vw1aAKdPOpoPhnSJN6y9JZxZM2bXB6yfaDCrYeXF/7p59EmEqicexI/bDs48NbyaQiHuiovfHNQe0= 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=HkwvRV+9; arc=none smtp.client-ip=68.232.154.123 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="HkwvRV+9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1756816895; x=1788352895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sSJfDeCErHLMizbHbg7+od45H5c6ZYzDEqhMLgOvb6U=; b=HkwvRV+9CuLBJGCiozZUk4rmmx78j+oDQPyT6k0d5Y3fe5aD0Mh1W03c cGfK0Ov242EzDY/q9M3aVwD0awX0kzb036XMcT2T5YszeZPi4GwkPL9RM ri7AWaPbS1ri2tCUjD1Aj0+Euyi3RjAP+T1W0LA2ba/bZUjWijtIkR3Bx 7pDAPiX2OBv2STrQepOq73NL1IJ+UBcS+QLaPA79kn4HFSmbqYqXyrK62 n4DxiyQFAZ488X+AZV4Cl13UfTOG8QL/891ldxbr7q5UdNVyKJJPYi3mb /Uytfsw5OK1H7Z89zJlJNgi6rWUMJP+xo7TdEq1Q6zYn576FcYSKfzosW w==; X-CSE-ConnectionGUID: uSbTBh14QEunAdjSx76qwQ== X-CSE-MsgGUID: iEtAVDooQd+SHnYaeuKS1Q== X-IronPort-AV: E=Sophos;i="6.18,230,1751266800"; d="scan'208";a="213345454" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Sep 2025 05:41:33 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) 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; Tue, 2 Sep 2025 05:41:31 -0700 Received: from DEN-DL-M31836.microchip.com (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.44 via Frontend Transport; Tue, 2 Sep 2025 05:41:29 -0700 From: Horatiu Vultur To: , , , , , , , , , CC: , , Horatiu Vultur Subject: [PATCH net-next v7 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once Date: Tue, 2 Sep 2025 14:18:31 +0200 Message-ID: <20250902121832.3258544-2-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250902121832.3258544-1-horatiu.vultur@microchip.com> References: <20250902121832.3258544-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" Introduce the function __lan8814_ptp_probe_once as this function will be used also by lan8842 driver which has a different number of GPIOs compared to lan8814. This change doesn't have any functional changes. Reviewed-by: Kory Maincent Signed-off-by: Horatiu Vultur --- 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..9a90818481320 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 *phyde= v) phydev->default_timestamp =3D true; } =20 -static int lan8814_ptp_probe_once(struct phy_device *phydev) +static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_n= ame, + int gpios) { struct lan8814_shared_priv *shared =3D phy_package_get_priv(phydev); =20 @@ -4250,18 +4251,18 @@ static int lan8814_ptp_probe_once(struct phy_device= *phydev) mutex_init(&shared->shared_lock); =20 shared->pin_config =3D devm_kmalloc_array(&phydev->mdio.dev, - LAN8814_PTP_GPIO_NUM, + gpios, sizeof(*shared->pin_config), GFP_KERNEL); if (!shared->pin_config) return -ENOMEM; =20 - for (int i =3D 0; i < LAN8814_PTP_GPIO_NUM; i++) { + for (int i =3D 0; i < gpios; i++) { struct ptp_pin_desc *ptp_pin =3D &shared->pin_config[i]; =20 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 =3D i; ptp_pin->func =3D PTP_PF_NONE; } @@ -4271,7 +4272,7 @@ static int lan8814_ptp_probe_once(struct phy_device *= phydev) shared->ptp_clock_info.max_adj =3D 31249999; shared->ptp_clock_info.n_alarm =3D 0; shared->ptp_clock_info.n_ext_ts =3D LAN8814_PTP_EXTTS_NUM; - shared->ptp_clock_info.n_pins =3D LAN8814_PTP_GPIO_NUM; + shared->ptp_clock_info.n_pins =3D gpios; shared->ptp_clock_info.pps =3D 0; shared->ptp_clock_info.supported_extts_flags =3D PTP_RISING_EDGE | PTP_FALLING_EDGE | @@ -4318,6 +4319,12 @@ static int lan8814_ptp_probe_once(struct phy_device = *phydev) return 0; } =20 +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; --=20 2.34.1 From nobody Fri Oct 3 10:13:39 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 D3F40296BC9; Tue, 2 Sep 2025 12:41:55 +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=1756816917; cv=none; b=HHIG1NzmQ3QX2gfHLczz7dGmN83dCOG+2K6c7SZVFWWKnTh4KV/1pCGYbs6frU5ddH/pkJpVjROv85bp4o/dIjGCCkazV/SOlgXlUooy85aZ5tC5NNpKMKZLEhQLjZR9BY8dybwB1EAxlm5FAPjD59kHuIWNub1SnYiKW+IKy+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756816917; c=relaxed/simple; bh=lX+g0a5RSCD79LRTrwVO4WqjJRxgYDuRvM69WaAPWQY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gFjnn+LP3eycryLziolo2phSZ91L4PTd3GBKSPIPrMoSPQR1KmCubFHlz1KX/E8k79XQDD14p1O91Fr+Dw06+V/5wj7b4QQh4jRfFpbXmx2M7wAE6tdNuen6O49TskKFugmM13ijN3I3bZrHzCTDYEVFv//QR89/0ACf4VAIvM0= 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=yh/bRW3w; 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="yh/bRW3w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1756816915; x=1788352915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lX+g0a5RSCD79LRTrwVO4WqjJRxgYDuRvM69WaAPWQY=; b=yh/bRW3whRpwkfY2iY7Zr3e9UZUJ+66ADAwV22T08XeL6yksD8B8rER4 8BQC99LokGfWaSC+rxdI5EQZ7I8kBAZkiweAJ5FpHcJCs/S6UZbaOLFXM dkuhXg3uFa0D3byW5SYY9zrxohs4WyI+w/YM74UMoMeGxurMLqlCWpIq/ zPUQWBIuB6fNWkSAp3R3Txx0ka+OzsYLoWVJybkWi2r3CyF+vAAQHYWle 2seW2yf5OvnGIupZEoDPT1dWLbA44HeKRoThlmND82zIYtoLGUhVqUv4e jkesMfkS6T4INyHCzrwIp5y3L/L9Ry+cj7yr7SvZ55MOnqwknZjyYfcos g==; X-CSE-ConnectionGUID: n529nplFT76mupMbXz70Mg== X-CSE-MsgGUID: sIYeAkv4Qm2jxBQ2vthD+Q== X-IronPort-AV: E=Sophos;i="6.18,230,1751266800"; d="scan'208";a="51628380" 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; 02 Sep 2025 05:41:54 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Tue, 2 Sep 2025 05:41:34 -0700 Received: from DEN-DL-M31836.microchip.com (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.44 via Frontend Transport; Tue, 2 Sep 2025 05:41:32 -0700 From: Horatiu Vultur To: , , , , , , , , , CC: , , Horatiu Vultur Subject: [PATCH net-next v7 2/2] net: phy: micrel: Add PTP support for lan8842 Date: Tue, 2 Sep 2025 14:18:32 +0200 Message-ID: <20250902121832.3258544-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250902121832.3258544-1-horatiu.vultur@microchip.com> References: <20250902121832.3258544-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 | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 9a90818481320..e403cbbcead5b 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -362,6 +362,8 @@ /* Delay used to get the second part from the LTC */ #define LAN8841_GET_SEC_LTC_DELAY (500 * NSEC_PER_MSEC) =20 +#define LAN8842_REV_8832 0x8832 + struct kszphy_hw_stat { const char *string; u8 reg; @@ -457,6 +459,8 @@ struct lan8842_phy_stats { =20 struct lan8842_priv { struct lan8842_phy_stats phy_stats; + struct kszphy_ptp_priv ptp_priv; + u16 rev; }; =20 static const struct kszphy_type lan8814_type =3D { @@ -5786,6 +5790,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 +5808,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); @@ -5817,6 +5833,43 @@ 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 + */ + ret =3D lanphy_read_page_reg(phydev, LAN8814_PAGE_COMMON_REGS, + LAN8842_SKU_REG); + if (ret < 0) + return ret; + + priv->rev =3D ret; + if (priv->rev =3D=3D LAN8842_REV_8832) + 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); + if (addr < 0) + return addr; + addr &=3D LAN8842_STRAP_REG_PHYADDR_MASK; + + ret =3D devm_phy_package_join(&phydev->mdio.dev, phydev, addr, + sizeof(struct lan8814_shared_priv)); + if (ret) + return ret; + + 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 +5949,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 +5991,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 therefore there is + * not need to check the PTP and GPIO interrupts + */ + if (priv->rev =3D=3D LAN8842_REV_8832) + 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